Loading media/libstagefright/MediaCodec.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -242,6 +242,9 @@ void MediaCodec::ResourceManagerServiceProxy::init() { } AIBinder_linkToDeath(mService->asBinder().get(), mDeathRecipient.get(), this); // Kill clients pending removal. mService->reclaimResourcesFromClientsPendingRemoval(mPid); } //static Loading services/mediaresourcemanager/ResourceManagerService.cpp +45 −7 Original line number Diff line number Diff line Loading @@ -670,13 +670,19 @@ Status ResourceManagerService::reclaimResource( } } if (clients.size() == 0) { *_aidl_return = reclaimInternal(clients); return Status::ok(); } bool ResourceManagerService::reclaimInternal( const Vector<std::shared_ptr<IResourceManagerClient>> &clients) { if (clients.size() == 0) { return false; } std::shared_ptr<IResourceManagerClient> failedClient; for (size_t i = 0; i < clients.size(); ++i) { log = String8::format("reclaimResource from client %p", clients[i].get()); String8 log = String8::format("reclaimResource from client %p", clients[i].get()); mServiceLog->add(log); bool success; Status status = clients[i]->reclaimResource(&success); Loading @@ -687,8 +693,7 @@ Status ResourceManagerService::reclaimResource( } if (failedClient == NULL) { *_aidl_return = true; return Status::ok(); return true; } { Loading @@ -713,7 +718,7 @@ Status ResourceManagerService::reclaimResource( } } return Status::ok(); return false; } Status ResourceManagerService::overridePid( Loading Loading @@ -853,6 +858,36 @@ Status ResourceManagerService::markClientForPendingRemoval(int32_t pid, int64_t return Status::ok(); } Status ResourceManagerService::reclaimResourcesFromClientsPendingRemoval(int32_t pid) { String8 log = String8::format("reclaimResourcesFromClientsPendingRemoval(pid %d)", pid); mServiceLog->add(log); Vector<std::shared_ptr<IResourceManagerClient>> clients; { Mutex::Autolock lock(mLock); if (!mProcessInfo->isValidPid(pid)) { ALOGE("Rejected reclaimResourcesFromClientsPendingRemoval call with invalid pid."); return Status::fromServiceSpecificError(BAD_VALUE); } for (MediaResource::Type type : {MediaResource::Type::kSecureCodec, MediaResource::Type::kNonSecureCodec, MediaResource::Type::kGraphicMemory, MediaResource::Type::kDrmSession}) { std::shared_ptr<IResourceManagerClient> client; if (getBiggestClient_l(pid, type, &client, true /* pendingRemovalOnly */)) { clients.add(client); break; } } } if (!clients.empty()) { reclaimInternal(clients); } return Status::ok(); } bool ResourceManagerService::getPriority_l(int pid, int* priority) { int newPid = pid; Loading Loading @@ -976,7 +1011,8 @@ bool ResourceManagerService::getBiggestClient_l( bool pendingRemovalOnly) { ssize_t index = mMap.indexOfKey(pid); if (index < 0) { ALOGE("getBiggestClient_l: can't find resource info for pid %d", pid); ALOGE_IF(!pendingRemovalOnly, "getBiggestClient_l: can't find resource info for pid %d", pid); return false; } Loading @@ -1000,7 +1036,9 @@ bool ResourceManagerService::getBiggestClient_l( } if (clientTemp == NULL) { ALOGE("getBiggestClient_l: can't find resource type %s for pid %d", asString(type), pid); ALOGE_IF(!pendingRemovalOnly, "getBiggestClient_l: can't find resource type %s for pid %d", asString(type), pid); return false; } Loading services/mediaresourcemanager/ResourceManagerService.h +7 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,8 @@ public: Status markClientForPendingRemoval(int32_t pid, int64_t clientId) override; Status reclaimResourcesFromClientsPendingRemoval(int32_t pid) override; Status removeResource(int pid, int64_t clientId, bool checkValid); private: Loading @@ -128,6 +130,11 @@ private: friend class DeathNotifier; friend class OverrideProcessInfoDeathNotifier; // Reclaims resources from |clients|. Returns true if reclaim succeeded // for all clients. bool reclaimInternal( const Vector<std::shared_ptr<IResourceManagerClient>> &clients); // Gets the list of all the clients who own the specified resource type. // Returns false if any client belongs to a process with higher priority than the // calling process. The clients will remain unchanged if returns false. Loading services/mediaresourcemanager/aidl/android/media/IResourceManagerService.aidl +7 −0 Original line number Diff line number Diff line Loading @@ -124,4 +124,11 @@ interface IResourceManagerService { * @param clientId clientId within the pid that will be removed. */ void markClientForPendingRemoval(int pid, long clientId); /** * Reclaim resources from clients pending removal, if any. * * @param pid pid from which resources will be reclaimed. */ void reclaimResourcesFromClientsPendingRemoval(int pid); } services/mediaresourcemanager/test/ResourceManagerService_test.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -340,6 +340,30 @@ public: // clean up client 3 which still left mService->removeClient(kTestPid2, getId(mTestClient3)); } { addResource(); mService->mSupportsSecureWithNonSecureCodec = true; mService->markClientForPendingRemoval(kTestPid2, getId(mTestClient2)); // client marked for pending removal got reclaimed EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(kTestPid2).isOk()); verifyClients(false /* c1 */, true /* c2 */, false /* c3 */); // No more clients marked for removal EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(kTestPid2).isOk()); verifyClients(false /* c1 */, false /* c2 */, false /* c3 */); mService->markClientForPendingRemoval(kTestPid2, getId(mTestClient3)); // client marked for pending removal got reclaimed EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(kTestPid2).isOk()); verifyClients(false /* c1 */, false /* c2 */, true /* c3 */); // clean up client 1 which still left mService->removeClient(kTestPid1, getId(mTestClient1)); } } void testRemoveClient() { Loading Loading
media/libstagefright/MediaCodec.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -242,6 +242,9 @@ void MediaCodec::ResourceManagerServiceProxy::init() { } AIBinder_linkToDeath(mService->asBinder().get(), mDeathRecipient.get(), this); // Kill clients pending removal. mService->reclaimResourcesFromClientsPendingRemoval(mPid); } //static Loading
services/mediaresourcemanager/ResourceManagerService.cpp +45 −7 Original line number Diff line number Diff line Loading @@ -670,13 +670,19 @@ Status ResourceManagerService::reclaimResource( } } if (clients.size() == 0) { *_aidl_return = reclaimInternal(clients); return Status::ok(); } bool ResourceManagerService::reclaimInternal( const Vector<std::shared_ptr<IResourceManagerClient>> &clients) { if (clients.size() == 0) { return false; } std::shared_ptr<IResourceManagerClient> failedClient; for (size_t i = 0; i < clients.size(); ++i) { log = String8::format("reclaimResource from client %p", clients[i].get()); String8 log = String8::format("reclaimResource from client %p", clients[i].get()); mServiceLog->add(log); bool success; Status status = clients[i]->reclaimResource(&success); Loading @@ -687,8 +693,7 @@ Status ResourceManagerService::reclaimResource( } if (failedClient == NULL) { *_aidl_return = true; return Status::ok(); return true; } { Loading @@ -713,7 +718,7 @@ Status ResourceManagerService::reclaimResource( } } return Status::ok(); return false; } Status ResourceManagerService::overridePid( Loading Loading @@ -853,6 +858,36 @@ Status ResourceManagerService::markClientForPendingRemoval(int32_t pid, int64_t return Status::ok(); } Status ResourceManagerService::reclaimResourcesFromClientsPendingRemoval(int32_t pid) { String8 log = String8::format("reclaimResourcesFromClientsPendingRemoval(pid %d)", pid); mServiceLog->add(log); Vector<std::shared_ptr<IResourceManagerClient>> clients; { Mutex::Autolock lock(mLock); if (!mProcessInfo->isValidPid(pid)) { ALOGE("Rejected reclaimResourcesFromClientsPendingRemoval call with invalid pid."); return Status::fromServiceSpecificError(BAD_VALUE); } for (MediaResource::Type type : {MediaResource::Type::kSecureCodec, MediaResource::Type::kNonSecureCodec, MediaResource::Type::kGraphicMemory, MediaResource::Type::kDrmSession}) { std::shared_ptr<IResourceManagerClient> client; if (getBiggestClient_l(pid, type, &client, true /* pendingRemovalOnly */)) { clients.add(client); break; } } } if (!clients.empty()) { reclaimInternal(clients); } return Status::ok(); } bool ResourceManagerService::getPriority_l(int pid, int* priority) { int newPid = pid; Loading Loading @@ -976,7 +1011,8 @@ bool ResourceManagerService::getBiggestClient_l( bool pendingRemovalOnly) { ssize_t index = mMap.indexOfKey(pid); if (index < 0) { ALOGE("getBiggestClient_l: can't find resource info for pid %d", pid); ALOGE_IF(!pendingRemovalOnly, "getBiggestClient_l: can't find resource info for pid %d", pid); return false; } Loading @@ -1000,7 +1036,9 @@ bool ResourceManagerService::getBiggestClient_l( } if (clientTemp == NULL) { ALOGE("getBiggestClient_l: can't find resource type %s for pid %d", asString(type), pid); ALOGE_IF(!pendingRemovalOnly, "getBiggestClient_l: can't find resource type %s for pid %d", asString(type), pid); return false; } Loading
services/mediaresourcemanager/ResourceManagerService.h +7 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,8 @@ public: Status markClientForPendingRemoval(int32_t pid, int64_t clientId) override; Status reclaimResourcesFromClientsPendingRemoval(int32_t pid) override; Status removeResource(int pid, int64_t clientId, bool checkValid); private: Loading @@ -128,6 +130,11 @@ private: friend class DeathNotifier; friend class OverrideProcessInfoDeathNotifier; // Reclaims resources from |clients|. Returns true if reclaim succeeded // for all clients. bool reclaimInternal( const Vector<std::shared_ptr<IResourceManagerClient>> &clients); // Gets the list of all the clients who own the specified resource type. // Returns false if any client belongs to a process with higher priority than the // calling process. The clients will remain unchanged if returns false. Loading
services/mediaresourcemanager/aidl/android/media/IResourceManagerService.aidl +7 −0 Original line number Diff line number Diff line Loading @@ -124,4 +124,11 @@ interface IResourceManagerService { * @param clientId clientId within the pid that will be removed. */ void markClientForPendingRemoval(int pid, long clientId); /** * Reclaim resources from clients pending removal, if any. * * @param pid pid from which resources will be reclaimed. */ void reclaimResourcesFromClientsPendingRemoval(int pid); }
services/mediaresourcemanager/test/ResourceManagerService_test.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -340,6 +340,30 @@ public: // clean up client 3 which still left mService->removeClient(kTestPid2, getId(mTestClient3)); } { addResource(); mService->mSupportsSecureWithNonSecureCodec = true; mService->markClientForPendingRemoval(kTestPid2, getId(mTestClient2)); // client marked for pending removal got reclaimed EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(kTestPid2).isOk()); verifyClients(false /* c1 */, true /* c2 */, false /* c3 */); // No more clients marked for removal EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(kTestPid2).isOk()); verifyClients(false /* c1 */, false /* c2 */, false /* c3 */); mService->markClientForPendingRemoval(kTestPid2, getId(mTestClient3)); // client marked for pending removal got reclaimed EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(kTestPid2).isOk()); verifyClients(false /* c1 */, false /* c2 */, true /* c3 */); // clean up client 1 which still left mService->removeClient(kTestPid1, getId(mTestClient1)); } } void testRemoveClient() { Loading