Loading drm/libmediadrm/DrmSessionManager.cpp +19 −5 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ namespace android { using aidl::android::media::MediaResourceParcel; using aidl::android::media::ClientInfoParcel; namespace { void ResourceManagerServiceDied(void* cookie) { Loading Loading @@ -137,7 +138,10 @@ void DrmSessionManager::addSession(int pid, static int64_t clientId = 0; mSessionMap[toStdVec(sessionId)] = (SessionInfo){pid, uid, clientId}; mService->addResource(pid, uid, clientId++, drm, toResourceVec(sessionId, INT64_MAX)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(pid), .uid = static_cast<int32_t>(uid), .id = clientId++}; mService->addResource(clientInfo, drm, toResourceVec(sessionId, INT64_MAX)); } void DrmSessionManager::useSession(const Vector<uint8_t> &sessionId) { Loading @@ -150,7 +154,10 @@ void DrmSessionManager::useSession(const Vector<uint8_t> &sessionId) { } auto info = it->second; mService->addResource(info.pid, info.uid, info.clientId, NULL, toResourceVec(sessionId, -1)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(info.pid), .uid = static_cast<int32_t>(info.uid), .id = info.clientId}; mService->addResource(clientInfo, NULL, toResourceVec(sessionId, -1)); } void DrmSessionManager::removeSession(const Vector<uint8_t> &sessionId) { Loading @@ -164,7 +171,10 @@ void DrmSessionManager::removeSession(const Vector<uint8_t> &sessionId) { auto info = it->second; // removeClient instead of removeSession because each client has only one session mService->removeClient(info.pid, info.clientId); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(info.pid), .uid = static_cast<int32_t>(info.uid), .id = info.clientId}; mService->removeClient(clientInfo); mSessionMap.erase(it); } Loading @@ -182,9 +192,13 @@ bool DrmSessionManager::reclaimSession(int callingPid) { // cannot update mSessionMap because we do not know which sessionId is reclaimed; // we rely on IResourceManagerClient to removeSession in reclaimResource Vector<uint8_t> dummy; Vector<uint8_t> placeHolder; bool success; ScopedAStatus status = service->reclaimResource(callingPid, toResourceVec(dummy, INT64_MAX), &success); uid_t uid = AIBinder_getCallingUid(); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(callingPid), .uid = static_cast<int32_t>(uid)}; ScopedAStatus status = service->reclaimResource( clientInfo, toResourceVec(placeHolder, INT64_MAX), &success); return status.isOk() && success; } Loading media/libstagefright/MediaCodec.cpp +46 −9 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ using Status = ::ndk::ScopedAStatus; using aidl::android::media::BnResourceManagerClient; using aidl::android::media::IResourceManagerClient; using aidl::android::media::IResourceManagerService; using aidl::android::media::ClientInfoParcel; // key for media statistics static const char *kCodecKeyName = "codec"; Loading Loading @@ -209,8 +210,8 @@ static const C2MemoryUsage kDefaultReadWriteUsage{ //////////////////////////////////////////////////////////////////////////////// struct ResourceManagerClient : public BnResourceManagerClient { explicit ResourceManagerClient(MediaCodec* codec, int32_t pid) : mMediaCodec(codec), mPid(pid) {} explicit ResourceManagerClient(MediaCodec* codec, int32_t pid, int32_t uid) : mMediaCodec(codec), mPid(pid), mUid(uid) {} Status reclaimResource(bool* _aidl_return) override { sp<MediaCodec> codec = mMediaCodec.promote(); Loading @@ -222,7 +223,10 @@ struct ResourceManagerClient : public BnResourceManagerClient { if (service == nullptr) { ALOGW("MediaCodec::ResourceManagerClient unable to find ResourceManagerService"); } service->removeClient(mPid, getId(this)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(this)}; service->removeClient(clientInfo); *_aidl_return = true; return Status::ok(); } Loading Loading @@ -260,6 +264,7 @@ struct ResourceManagerClient : public BnResourceManagerClient { private: wp<MediaCodec> mMediaCodec; int32_t mPid; int32_t mUid; DISALLOW_EVIL_CONSTRUCTORS(ResourceManagerClient); }; Loading @@ -285,10 +290,15 @@ struct MediaCodec::ResourceManagerServiceProxy : public RefBase { void markClientForPendingRemoval(); bool reclaimResource(const std::vector<MediaResourceParcel> &resources); inline void setCodecName(const char* name) { mCodecName = name; } private: Mutex mLock; pid_t mPid; uid_t mUid; std::string mCodecName; std::shared_ptr<IResourceManagerService> mService; std::shared_ptr<IResourceManagerClient> mClient; ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient; Loading Loading @@ -392,7 +402,11 @@ void MediaCodec::ResourceManagerServiceProxy::addResource( if (mService == nullptr) { return; } mService->addResource(mPid, mUid, getId(mClient), mClient, resources); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; mService->addResource(clientInfo, mClient, resources); } void MediaCodec::ResourceManagerServiceProxy::removeResource( Loading @@ -404,7 +418,11 @@ void MediaCodec::ResourceManagerServiceProxy::removeResource( if (mService == nullptr) { return; } mService->removeResource(mPid, getId(mClient), resources); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; mService->removeResource(clientInfo, resources); } void MediaCodec::ResourceManagerServiceProxy::removeClient() { Loading @@ -412,7 +430,11 @@ void MediaCodec::ResourceManagerServiceProxy::removeClient() { if (mService == nullptr) { return; } mService->removeClient(mPid, getId(mClient)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; mService->removeClient(clientInfo); } void MediaCodec::ResourceManagerServiceProxy::markClientForPendingRemoval() { Loading @@ -420,7 +442,11 @@ void MediaCodec::ResourceManagerServiceProxy::markClientForPendingRemoval() { if (mService == nullptr) { return; } mService->markClientForPendingRemoval(mPid, getId(mClient)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; mService->markClientForPendingRemoval(clientInfo); } bool MediaCodec::ResourceManagerServiceProxy::reclaimResource( Loading @@ -430,7 +456,11 @@ bool MediaCodec::ResourceManagerServiceProxy::reclaimResource( return false; } bool success; Status status = mService->reclaimResource(mPid, resources, &success); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; Status status = mService->reclaimResource(clientInfo, resources, &success); return status.isOk() && success; } Loading Loading @@ -835,7 +865,7 @@ MediaCodec::MediaCodec( mGetCodecBase(getCodecBase), mGetCodecInfo(getCodecInfo) { mResourceManagerProxy = new ResourceManagerServiceProxy(pid, uid, ::ndk::SharedRefBase::make<ResourceManagerClient>(this, pid)); ::ndk::SharedRefBase::make<ResourceManagerClient>(this, pid, uid)); if (!mGetCodecBase) { mGetCodecBase = [](const AString &name, const char *owner) { return GetCodecBase(name, owner); Loading Loading @@ -1606,6 +1636,11 @@ status_t MediaCodec::init(const AString &name) { std::vector<MediaResourceParcel> resources; resources.push_back(MediaResource::CodecResource(secureCodec, toMediaResourceSubType(mDomain))); // If the ComponentName is not set yet, use the name passed by the user. if (mComponentName.empty()) { mResourceManagerProxy->setCodecName(name.c_str()); } for (int i = 0; i <= kMaxRetry; ++i) { if (i > 0) { // Don't try to reclaim resource for the first time. Loading Loading @@ -3387,6 +3422,8 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { if (mComponentName.c_str()) { mediametrics_setCString(mMetricsHandle, kCodecCodec, mComponentName.c_str()); // Update the codec name. mResourceManagerProxy->setCodecName(mComponentName.c_str()); } const char *owner = mCodecInfo ? mCodecInfo->getOwnerName() : ""; Loading media/utils/ProcessInfo.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -40,11 +40,11 @@ bool ProcessInfo::getPriority(int pid, int* priority) { int32_t state; int32_t score = INVALID_ADJ; status_t err = service->getProcessStatesAndOomScoresFromPids(length, &pid, &state, &score); ALOGV("%s: pid:%d state:%d score:%d err:%d", __FUNCTION__, pid, state, score, err); if (err != OK) { ALOGE("getProcessStatesAndOomScoresFromPids failed"); return false; } ALOGV("pid %d state %d score %d", pid, state, score); if (score <= NATIVE_ADJ) { std::scoped_lock lock{mOverrideLock}; Loading services/mediaresourcemanager/Android.bp +12 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ filegroup { "aidl/android/media/MediaResourceSubType.aidl", "aidl/android/media/MediaResourceParcel.aidl", "aidl/android/media/MediaResourcePolicyParcel.aidl", "aidl/android/media/ClientInfoParcel.aidl", ], path: "aidl", } Loading Loading @@ -87,10 +88,15 @@ cc_library { "libbinder_ndk", "libutils", "liblog", "libstats_media_metrics", "libstatspull", "libstatssocket", "libprotobuf-cpp-lite", ], static_libs: [ "resourceobserver_aidl_interface-V1-ndk", "libplatformprotos", ], include_dirs: ["frameworks/av/include"], Loading @@ -101,4 +107,10 @@ cc_library { ], export_include_dirs: ["."], export_shared_lib_headers: [ "libstats_media_metrics", "libstatspull", "libstatssocket", ], } services/mediaresourcemanager/ResourceManagerService.cpp +207 −40 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
drm/libmediadrm/DrmSessionManager.cpp +19 −5 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ namespace android { using aidl::android::media::MediaResourceParcel; using aidl::android::media::ClientInfoParcel; namespace { void ResourceManagerServiceDied(void* cookie) { Loading Loading @@ -137,7 +138,10 @@ void DrmSessionManager::addSession(int pid, static int64_t clientId = 0; mSessionMap[toStdVec(sessionId)] = (SessionInfo){pid, uid, clientId}; mService->addResource(pid, uid, clientId++, drm, toResourceVec(sessionId, INT64_MAX)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(pid), .uid = static_cast<int32_t>(uid), .id = clientId++}; mService->addResource(clientInfo, drm, toResourceVec(sessionId, INT64_MAX)); } void DrmSessionManager::useSession(const Vector<uint8_t> &sessionId) { Loading @@ -150,7 +154,10 @@ void DrmSessionManager::useSession(const Vector<uint8_t> &sessionId) { } auto info = it->second; mService->addResource(info.pid, info.uid, info.clientId, NULL, toResourceVec(sessionId, -1)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(info.pid), .uid = static_cast<int32_t>(info.uid), .id = info.clientId}; mService->addResource(clientInfo, NULL, toResourceVec(sessionId, -1)); } void DrmSessionManager::removeSession(const Vector<uint8_t> &sessionId) { Loading @@ -164,7 +171,10 @@ void DrmSessionManager::removeSession(const Vector<uint8_t> &sessionId) { auto info = it->second; // removeClient instead of removeSession because each client has only one session mService->removeClient(info.pid, info.clientId); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(info.pid), .uid = static_cast<int32_t>(info.uid), .id = info.clientId}; mService->removeClient(clientInfo); mSessionMap.erase(it); } Loading @@ -182,9 +192,13 @@ bool DrmSessionManager::reclaimSession(int callingPid) { // cannot update mSessionMap because we do not know which sessionId is reclaimed; // we rely on IResourceManagerClient to removeSession in reclaimResource Vector<uint8_t> dummy; Vector<uint8_t> placeHolder; bool success; ScopedAStatus status = service->reclaimResource(callingPid, toResourceVec(dummy, INT64_MAX), &success); uid_t uid = AIBinder_getCallingUid(); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(callingPid), .uid = static_cast<int32_t>(uid)}; ScopedAStatus status = service->reclaimResource( clientInfo, toResourceVec(placeHolder, INT64_MAX), &success); return status.isOk() && success; } Loading
media/libstagefright/MediaCodec.cpp +46 −9 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ using Status = ::ndk::ScopedAStatus; using aidl::android::media::BnResourceManagerClient; using aidl::android::media::IResourceManagerClient; using aidl::android::media::IResourceManagerService; using aidl::android::media::ClientInfoParcel; // key for media statistics static const char *kCodecKeyName = "codec"; Loading Loading @@ -209,8 +210,8 @@ static const C2MemoryUsage kDefaultReadWriteUsage{ //////////////////////////////////////////////////////////////////////////////// struct ResourceManagerClient : public BnResourceManagerClient { explicit ResourceManagerClient(MediaCodec* codec, int32_t pid) : mMediaCodec(codec), mPid(pid) {} explicit ResourceManagerClient(MediaCodec* codec, int32_t pid, int32_t uid) : mMediaCodec(codec), mPid(pid), mUid(uid) {} Status reclaimResource(bool* _aidl_return) override { sp<MediaCodec> codec = mMediaCodec.promote(); Loading @@ -222,7 +223,10 @@ struct ResourceManagerClient : public BnResourceManagerClient { if (service == nullptr) { ALOGW("MediaCodec::ResourceManagerClient unable to find ResourceManagerService"); } service->removeClient(mPid, getId(this)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(this)}; service->removeClient(clientInfo); *_aidl_return = true; return Status::ok(); } Loading Loading @@ -260,6 +264,7 @@ struct ResourceManagerClient : public BnResourceManagerClient { private: wp<MediaCodec> mMediaCodec; int32_t mPid; int32_t mUid; DISALLOW_EVIL_CONSTRUCTORS(ResourceManagerClient); }; Loading @@ -285,10 +290,15 @@ struct MediaCodec::ResourceManagerServiceProxy : public RefBase { void markClientForPendingRemoval(); bool reclaimResource(const std::vector<MediaResourceParcel> &resources); inline void setCodecName(const char* name) { mCodecName = name; } private: Mutex mLock; pid_t mPid; uid_t mUid; std::string mCodecName; std::shared_ptr<IResourceManagerService> mService; std::shared_ptr<IResourceManagerClient> mClient; ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient; Loading Loading @@ -392,7 +402,11 @@ void MediaCodec::ResourceManagerServiceProxy::addResource( if (mService == nullptr) { return; } mService->addResource(mPid, mUid, getId(mClient), mClient, resources); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; mService->addResource(clientInfo, mClient, resources); } void MediaCodec::ResourceManagerServiceProxy::removeResource( Loading @@ -404,7 +418,11 @@ void MediaCodec::ResourceManagerServiceProxy::removeResource( if (mService == nullptr) { return; } mService->removeResource(mPid, getId(mClient), resources); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; mService->removeResource(clientInfo, resources); } void MediaCodec::ResourceManagerServiceProxy::removeClient() { Loading @@ -412,7 +430,11 @@ void MediaCodec::ResourceManagerServiceProxy::removeClient() { if (mService == nullptr) { return; } mService->removeClient(mPid, getId(mClient)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; mService->removeClient(clientInfo); } void MediaCodec::ResourceManagerServiceProxy::markClientForPendingRemoval() { Loading @@ -420,7 +442,11 @@ void MediaCodec::ResourceManagerServiceProxy::markClientForPendingRemoval() { if (mService == nullptr) { return; } mService->markClientForPendingRemoval(mPid, getId(mClient)); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; mService->markClientForPendingRemoval(clientInfo); } bool MediaCodec::ResourceManagerServiceProxy::reclaimResource( Loading @@ -430,7 +456,11 @@ bool MediaCodec::ResourceManagerServiceProxy::reclaimResource( return false; } bool success; Status status = mService->reclaimResource(mPid, resources, &success); ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid), .uid = static_cast<int32_t>(mUid), .id = getId(mClient), .name = mCodecName}; Status status = mService->reclaimResource(clientInfo, resources, &success); return status.isOk() && success; } Loading Loading @@ -835,7 +865,7 @@ MediaCodec::MediaCodec( mGetCodecBase(getCodecBase), mGetCodecInfo(getCodecInfo) { mResourceManagerProxy = new ResourceManagerServiceProxy(pid, uid, ::ndk::SharedRefBase::make<ResourceManagerClient>(this, pid)); ::ndk::SharedRefBase::make<ResourceManagerClient>(this, pid, uid)); if (!mGetCodecBase) { mGetCodecBase = [](const AString &name, const char *owner) { return GetCodecBase(name, owner); Loading Loading @@ -1606,6 +1636,11 @@ status_t MediaCodec::init(const AString &name) { std::vector<MediaResourceParcel> resources; resources.push_back(MediaResource::CodecResource(secureCodec, toMediaResourceSubType(mDomain))); // If the ComponentName is not set yet, use the name passed by the user. if (mComponentName.empty()) { mResourceManagerProxy->setCodecName(name.c_str()); } for (int i = 0; i <= kMaxRetry; ++i) { if (i > 0) { // Don't try to reclaim resource for the first time. Loading Loading @@ -3387,6 +3422,8 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { if (mComponentName.c_str()) { mediametrics_setCString(mMetricsHandle, kCodecCodec, mComponentName.c_str()); // Update the codec name. mResourceManagerProxy->setCodecName(mComponentName.c_str()); } const char *owner = mCodecInfo ? mCodecInfo->getOwnerName() : ""; Loading
media/utils/ProcessInfo.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -40,11 +40,11 @@ bool ProcessInfo::getPriority(int pid, int* priority) { int32_t state; int32_t score = INVALID_ADJ; status_t err = service->getProcessStatesAndOomScoresFromPids(length, &pid, &state, &score); ALOGV("%s: pid:%d state:%d score:%d err:%d", __FUNCTION__, pid, state, score, err); if (err != OK) { ALOGE("getProcessStatesAndOomScoresFromPids failed"); return false; } ALOGV("pid %d state %d score %d", pid, state, score); if (score <= NATIVE_ADJ) { std::scoped_lock lock{mOverrideLock}; Loading
services/mediaresourcemanager/Android.bp +12 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ filegroup { "aidl/android/media/MediaResourceSubType.aidl", "aidl/android/media/MediaResourceParcel.aidl", "aidl/android/media/MediaResourcePolicyParcel.aidl", "aidl/android/media/ClientInfoParcel.aidl", ], path: "aidl", } Loading Loading @@ -87,10 +88,15 @@ cc_library { "libbinder_ndk", "libutils", "liblog", "libstats_media_metrics", "libstatspull", "libstatssocket", "libprotobuf-cpp-lite", ], static_libs: [ "resourceobserver_aidl_interface-V1-ndk", "libplatformprotos", ], include_dirs: ["frameworks/av/include"], Loading @@ -101,4 +107,10 @@ cc_library { ], export_include_dirs: ["."], export_shared_lib_headers: [ "libstats_media_metrics", "libstatspull", "libstatssocket", ], }
services/mediaresourcemanager/ResourceManagerService.cpp +207 −40 File changed.Preview size limit exceeded, changes collapsed. Show changes