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

Commit 6542f433 authored by Ray Essick's avatar Ray Essick Committed by Android (Google) Code Review
Browse files

Merge "Improve handling MediaCodec linkToDeath() resource manager" into rvc-dev

parents 23a3c612 d11e1606
Loading
Loading
Loading
Loading
+38 −2
Original line number Original line Diff line number Diff line
@@ -19,6 +19,8 @@
#define LOG_TAG "MediaCodec"
#define LOG_TAG "MediaCodec"
#include <utils/Log.h>
#include <utils/Log.h>


#include <set>

#include <inttypes.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdlib.h>


@@ -201,6 +203,10 @@ struct MediaCodec::ResourceManagerServiceProxy : public RefBase {
    // implements DeathRecipient
    // implements DeathRecipient
    static void BinderDiedCallback(void* cookie);
    static void BinderDiedCallback(void* cookie);
    void binderDied();
    void binderDied();
    static Mutex sLockCookies;
    static std::set<void*> sCookies;
    static void addCookie(void* cookie);
    static void removeCookie(void* cookie);


    void addResource(const MediaResourceParcel &resource);
    void addResource(const MediaResourceParcel &resource);
    void removeResource(const MediaResourceParcel &resource);
    void removeResource(const MediaResourceParcel &resource);
@@ -227,8 +233,15 @@ MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy(
}
}


MediaCodec::ResourceManagerServiceProxy::~ResourceManagerServiceProxy() {
MediaCodec::ResourceManagerServiceProxy::~ResourceManagerServiceProxy() {

    // remove the cookie, so any in-flight death notification will get dropped
    // by our handler.
    removeCookie(this);

    Mutex::Autolock _l(mLock);
    if (mService != nullptr) {
    if (mService != nullptr) {
        AIBinder_unlinkToDeath(mService->asBinder().get(), mDeathRecipient.get(), this);
        AIBinder_unlinkToDeath(mService->asBinder().get(), mDeathRecipient.get(), this);
        mService = nullptr;
    }
    }
}
}


@@ -240,14 +253,37 @@ void MediaCodec::ResourceManagerServiceProxy::init() {
        return;
        return;
    }
    }


    // so our handler will process the death notifications
    addCookie(this);

    // after this, require mLock whenever using mService
    AIBinder_linkToDeath(mService->asBinder().get(), mDeathRecipient.get(), this);
    AIBinder_linkToDeath(mService->asBinder().get(), mDeathRecipient.get(), this);
}
}


//static
Mutex MediaCodec::ResourceManagerServiceProxy::sLockCookies;
std::set<void*> MediaCodec::ResourceManagerServiceProxy::sCookies;

//static
void MediaCodec::ResourceManagerServiceProxy::addCookie(void* cookie) {
    Mutex::Autolock _l(sLockCookies);
    sCookies.insert(cookie);
}

//static
void MediaCodec::ResourceManagerServiceProxy::removeCookie(void* cookie) {
    Mutex::Autolock _l(sLockCookies);
    sCookies.erase(cookie);
}

//static
//static
void MediaCodec::ResourceManagerServiceProxy::BinderDiedCallback(void* cookie) {
void MediaCodec::ResourceManagerServiceProxy::BinderDiedCallback(void* cookie) {
    Mutex::Autolock _l(sLockCookies);
    if (sCookies.find(cookie) != sCookies.end()) {
        auto thiz = static_cast<ResourceManagerServiceProxy*>(cookie);
        auto thiz = static_cast<ResourceManagerServiceProxy*>(cookie);
        thiz->binderDied();
        thiz->binderDied();
    }
    }
}


void MediaCodec::ResourceManagerServiceProxy::binderDied() {
void MediaCodec::ResourceManagerServiceProxy::binderDied() {
    ALOGW("ResourceManagerService died.");
    ALOGW("ResourceManagerService died.");