Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f6272577 authored by Ronghua Wu's avatar Ronghua Wu Committed by Android Git Automerger
Browse files

am f42d2eec: am 51390b48: Merge "mediaresourcemanager: add pid to...

am f42d2eec: am 51390b48: Merge "mediaresourcemanager: add pid to removeResource method" into mnc-dev

* commit 'f42d2eec':
  mediaresourcemanager: add pid to removeResource method
parents 21e7da52 f42d2eec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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,
+2 −2
Original line number Diff line number Diff line
@@ -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;
+4 −2
Original line number Diff line number Diff line
@@ -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);
@@ -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;

+10 −14
Original line number Diff line number Diff line
@@ -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();
}
@@ -108,7 +104,8 @@ private:
    DISALLOW_EVIL_CONSTRUCTORS(ResourceManagerClient);
};

MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy() {
MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy()
        : mPid(IPCThreadState::self()->getCallingPid()) {
}

MediaCodec::ResourceManagerServiceProxy::~ResourceManagerServiceProxy() {
@@ -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) {
@@ -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) {
@@ -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
@@ -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;
            }
        }
@@ -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;
            }
        }
@@ -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() {
@@ -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.
+14 −13
Original line number Diff line number Diff line
@@ -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