Loading include/media/IResourceManagerService.h +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ public: const sp<IResourceManagerClient> client, const Vector<MediaResource> &resources) = 0; virtual void removeResource(int64_t clientId) = 0; virtual void removeResource(int pid, int64_t clientId) = 0; virtual bool reclaimResource( int callingPid, Loading include/media/stagefright/MediaCodec.h +2 −2 Original line number Diff line number Diff line Loading @@ -260,18 +260,18 @@ private: virtual void binderDied(const wp<IBinder>& /*who*/); void addResource( int pid, int64_t clientId, const sp<IResourceManagerClient> client, const Vector<MediaResource> &resources); void removeResource(int64_t clientId); bool reclaimResource(int callingPid, const Vector<MediaResource> &resources); bool reclaimResource(const Vector<MediaResource> &resources); private: Mutex mLock; sp<IResourceManagerService> mService; int mPid; }; State mState; Loading media/libmedia/IResourceManagerService.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -85,9 +85,10 @@ public: remote()->transact(ADD_RESOURCE, data, &reply); } virtual void removeResource(int64_t clientId) { virtual void removeResource(int pid, int64_t clientId) { Parcel data, reply; data.writeInterfaceToken(IResourceManagerService::getInterfaceDescriptor()); data.writeInt32(pid); data.writeInt64(clientId); remote()->transact(REMOVE_RESOURCE, data, &reply); Loading Loading @@ -139,8 +140,9 @@ status_t BnResourceManagerService::onTransact( case REMOVE_RESOURCE: { CHECK_INTERFACE(IResourceManagerService, data, reply); int pid = data.readInt32(); int64_t clientId = data.readInt64(); removeResource(clientId); removeResource(pid, clientId); return NO_ERROR; } break; Loading media/libstagefright/MediaCodec.cpp +10 −14 Original line number Diff line number Diff line Loading @@ -54,10 +54,6 @@ namespace android { static inline int getCallingPid() { return IPCThreadState::self()->getCallingPid(); } static int64_t getId(sp<IResourceManagerClient> client) { return (int64_t) client.get(); } Loading Loading @@ -108,7 +104,8 @@ private: DISALLOW_EVIL_CONSTRUCTORS(ResourceManagerClient); }; MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy() { MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy() : mPid(IPCThreadState::self()->getCallingPid()) { } MediaCodec::ResourceManagerServiceProxy::~ResourceManagerServiceProxy() { Loading @@ -135,7 +132,6 @@ void MediaCodec::ResourceManagerServiceProxy::binderDied(const wp<IBinder>& /*wh } void MediaCodec::ResourceManagerServiceProxy::addResource( int pid, int64_t clientId, const sp<IResourceManagerClient> client, const Vector<MediaResource> &resources) { Loading @@ -143,7 +139,7 @@ void MediaCodec::ResourceManagerServiceProxy::addResource( if (mService == NULL) { return; } mService->addResource(pid, clientId, client, resources); mService->addResource(mPid, clientId, client, resources); } void MediaCodec::ResourceManagerServiceProxy::removeResource(int64_t clientId) { Loading @@ -151,16 +147,16 @@ void MediaCodec::ResourceManagerServiceProxy::removeResource(int64_t clientId) { if (mService == NULL) { return; } mService->removeResource(clientId); mService->removeResource(mPid, clientId); } bool MediaCodec::ResourceManagerServiceProxy::reclaimResource( int callingPid, const Vector<MediaResource> &resources) { const Vector<MediaResource> &resources) { Mutex::Autolock _l(mLock); if (mService == NULL) { return false; } return mService->reclaimResource(callingPid, resources); return mService->reclaimResource(mPid, resources); } // static Loading Loading @@ -375,7 +371,7 @@ status_t MediaCodec::init(const AString &name, bool nameIsType, bool encoder) { for (int i = 0; i <= kMaxRetry; ++i) { if (i > 0) { // Don't try to reclaim resource for the first time. if (!mResourceManagerService->reclaimResource(getCallingPid(), resources)) { if (!mResourceManagerService->reclaimResource(resources)) { break; } } Loading Loading @@ -438,7 +434,7 @@ status_t MediaCodec::configure( for (int i = 0; i <= kMaxRetry; ++i) { if (i > 0) { // Don't try to reclaim resource for the first time. if (!mResourceManagerService->reclaimResource(getCallingPid(), resources)) { if (!mResourceManagerService->reclaimResource(resources)) { break; } } Loading Loading @@ -517,7 +513,7 @@ void MediaCodec::addResource(const String8 &type, const String8 &subtype, uint64 Vector<MediaResource> resources; resources.push_back(MediaResource(type, subtype, value)); mResourceManagerService->addResource( getCallingPid(), getId(mResourceManagerClient), mResourceManagerClient, resources); getId(mResourceManagerClient), mResourceManagerClient, resources); } status_t MediaCodec::start() { Loading @@ -535,7 +531,7 @@ status_t MediaCodec::start() { for (int i = 0; i <= kMaxRetry; ++i) { if (i > 0) { // Don't try to reclaim resource for the first time. if (!mResourceManagerService->reclaimResource(getCallingPid(), resources)) { if (!mResourceManagerService->reclaimResource(resources)) { break; } // Recover codec from previous error before retry start. Loading services/mediaresourcemanager/ResourceManagerService.cpp +14 −13 Original line number Diff line number Diff line Loading @@ -179,23 +179,24 @@ void ResourceManagerService::addResource( info.resources.appendVector(resources); } void ResourceManagerService::removeResource(int64_t clientId) { String8 log = String8::format("removeResource(%lld)", (long long) clientId); void ResourceManagerService::removeResource(int pid, int64_t clientId) { String8 log = String8::format( "removeResource(pid %d, clientId %lld)", pid, (long long) clientId); mServiceLog->add(log); Mutex::Autolock lock(mLock); ssize_t index = mMap.indexOfKey(pid); if (index < 0) { ALOGV("removeResource: didn't find pid %d for clientId %lld", pid, (long long) clientId); return; } bool found = false; for (size_t i = 0; i < mMap.size(); ++i) { ResourceInfos &infos = mMap.editValueAt(i); for (size_t j = 0; j < infos.size();) { ResourceInfos &infos = mMap.editValueAt(index); for (size_t j = 0; j < infos.size(); ++j) { if (infos[j].clientId == clientId) { j = infos.removeAt(j); found = true; } else { ++j; } } if (found) { break; } } Loading Loading
include/media/IResourceManagerService.h +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ public: const sp<IResourceManagerClient> client, const Vector<MediaResource> &resources) = 0; virtual void removeResource(int64_t clientId) = 0; virtual void removeResource(int pid, int64_t clientId) = 0; virtual bool reclaimResource( int callingPid, Loading
include/media/stagefright/MediaCodec.h +2 −2 Original line number Diff line number Diff line Loading @@ -260,18 +260,18 @@ private: virtual void binderDied(const wp<IBinder>& /*who*/); void addResource( int pid, int64_t clientId, const sp<IResourceManagerClient> client, const Vector<MediaResource> &resources); void removeResource(int64_t clientId); bool reclaimResource(int callingPid, const Vector<MediaResource> &resources); bool reclaimResource(const Vector<MediaResource> &resources); private: Mutex mLock; sp<IResourceManagerService> mService; int mPid; }; State mState; Loading
media/libmedia/IResourceManagerService.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -85,9 +85,10 @@ public: remote()->transact(ADD_RESOURCE, data, &reply); } virtual void removeResource(int64_t clientId) { virtual void removeResource(int pid, int64_t clientId) { Parcel data, reply; data.writeInterfaceToken(IResourceManagerService::getInterfaceDescriptor()); data.writeInt32(pid); data.writeInt64(clientId); remote()->transact(REMOVE_RESOURCE, data, &reply); Loading Loading @@ -139,8 +140,9 @@ status_t BnResourceManagerService::onTransact( case REMOVE_RESOURCE: { CHECK_INTERFACE(IResourceManagerService, data, reply); int pid = data.readInt32(); int64_t clientId = data.readInt64(); removeResource(clientId); removeResource(pid, clientId); return NO_ERROR; } break; Loading
media/libstagefright/MediaCodec.cpp +10 −14 Original line number Diff line number Diff line Loading @@ -54,10 +54,6 @@ namespace android { static inline int getCallingPid() { return IPCThreadState::self()->getCallingPid(); } static int64_t getId(sp<IResourceManagerClient> client) { return (int64_t) client.get(); } Loading Loading @@ -108,7 +104,8 @@ private: DISALLOW_EVIL_CONSTRUCTORS(ResourceManagerClient); }; MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy() { MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy() : mPid(IPCThreadState::self()->getCallingPid()) { } MediaCodec::ResourceManagerServiceProxy::~ResourceManagerServiceProxy() { Loading @@ -135,7 +132,6 @@ void MediaCodec::ResourceManagerServiceProxy::binderDied(const wp<IBinder>& /*wh } void MediaCodec::ResourceManagerServiceProxy::addResource( int pid, int64_t clientId, const sp<IResourceManagerClient> client, const Vector<MediaResource> &resources) { Loading @@ -143,7 +139,7 @@ void MediaCodec::ResourceManagerServiceProxy::addResource( if (mService == NULL) { return; } mService->addResource(pid, clientId, client, resources); mService->addResource(mPid, clientId, client, resources); } void MediaCodec::ResourceManagerServiceProxy::removeResource(int64_t clientId) { Loading @@ -151,16 +147,16 @@ void MediaCodec::ResourceManagerServiceProxy::removeResource(int64_t clientId) { if (mService == NULL) { return; } mService->removeResource(clientId); mService->removeResource(mPid, clientId); } bool MediaCodec::ResourceManagerServiceProxy::reclaimResource( int callingPid, const Vector<MediaResource> &resources) { const Vector<MediaResource> &resources) { Mutex::Autolock _l(mLock); if (mService == NULL) { return false; } return mService->reclaimResource(callingPid, resources); return mService->reclaimResource(mPid, resources); } // static Loading Loading @@ -375,7 +371,7 @@ status_t MediaCodec::init(const AString &name, bool nameIsType, bool encoder) { for (int i = 0; i <= kMaxRetry; ++i) { if (i > 0) { // Don't try to reclaim resource for the first time. if (!mResourceManagerService->reclaimResource(getCallingPid(), resources)) { if (!mResourceManagerService->reclaimResource(resources)) { break; } } Loading Loading @@ -438,7 +434,7 @@ status_t MediaCodec::configure( for (int i = 0; i <= kMaxRetry; ++i) { if (i > 0) { // Don't try to reclaim resource for the first time. if (!mResourceManagerService->reclaimResource(getCallingPid(), resources)) { if (!mResourceManagerService->reclaimResource(resources)) { break; } } Loading Loading @@ -517,7 +513,7 @@ void MediaCodec::addResource(const String8 &type, const String8 &subtype, uint64 Vector<MediaResource> resources; resources.push_back(MediaResource(type, subtype, value)); mResourceManagerService->addResource( getCallingPid(), getId(mResourceManagerClient), mResourceManagerClient, resources); getId(mResourceManagerClient), mResourceManagerClient, resources); } status_t MediaCodec::start() { Loading @@ -535,7 +531,7 @@ status_t MediaCodec::start() { for (int i = 0; i <= kMaxRetry; ++i) { if (i > 0) { // Don't try to reclaim resource for the first time. if (!mResourceManagerService->reclaimResource(getCallingPid(), resources)) { if (!mResourceManagerService->reclaimResource(resources)) { break; } // Recover codec from previous error before retry start. Loading
services/mediaresourcemanager/ResourceManagerService.cpp +14 −13 Original line number Diff line number Diff line Loading @@ -179,23 +179,24 @@ void ResourceManagerService::addResource( info.resources.appendVector(resources); } void ResourceManagerService::removeResource(int64_t clientId) { String8 log = String8::format("removeResource(%lld)", (long long) clientId); void ResourceManagerService::removeResource(int pid, int64_t clientId) { String8 log = String8::format( "removeResource(pid %d, clientId %lld)", pid, (long long) clientId); mServiceLog->add(log); Mutex::Autolock lock(mLock); ssize_t index = mMap.indexOfKey(pid); if (index < 0) { ALOGV("removeResource: didn't find pid %d for clientId %lld", pid, (long long) clientId); return; } bool found = false; for (size_t i = 0; i < mMap.size(); ++i) { ResourceInfos &infos = mMap.editValueAt(i); for (size_t j = 0; j < infos.size();) { ResourceInfos &infos = mMap.editValueAt(index); for (size_t j = 0; j < infos.size(); ++j) { if (infos[j].clientId == clientId) { j = infos.removeAt(j); found = true; } else { ++j; } } if (found) { break; } } Loading