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

Commit d33e319f authored by Sungtak Lee's avatar Sungtak Lee
Browse files

MediaMetadataRetriever: add static lock for image extraction

MediaMetadataRetriever binder service has a static lock in
MetadataRetrieverClient. The static lock serializes getFrameAtTime(),
getImageAtIndex(), getImageRectAtIndex() and getFrameAtIndex()
regardless of where the transaction being originated.

The static lock in the service side throttles image extraction not to
consume too much memory. But the static lock can cause to consume all
the binder thread pools and lead to starvation.

By adding a static lock to the client side(MediaMetadataRetriever),
image extraction from the same process will consume only one thread in
the thread pool.

Flag: EXEMPT bugfix
Bug: 359802236
Test: presubmit
Change-Id: I8476df2aac34506d7571b98e1c24aee8d74a7900
parent 6413b8bf
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -122,6 +122,10 @@ private:
    static sp<IMediaPlayerService>            sService;
    static sp<IMediaPlayerService>            sService;


    Mutex                                     mLock;
    Mutex                                     mLock;
    // Static lock was added to the client in order to consume at most
    // one service thread from image extraction requests of the same
    // client process(See also b/21277449).
    static Mutex                              sLock;
    sp<IMediaMetadataRetriever>               mRetriever;
    sp<IMediaMetadataRetriever>               mRetriever;


};
};
+6 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,8 @@ Mutex MediaMetadataRetriever::sServiceLock;
sp<IMediaPlayerService> MediaMetadataRetriever::sService;
sp<IMediaPlayerService> MediaMetadataRetriever::sService;
sp<MediaMetadataRetriever::DeathNotifier> MediaMetadataRetriever::sDeathNotifier;
sp<MediaMetadataRetriever::DeathNotifier> MediaMetadataRetriever::sDeathNotifier;


Mutex MediaMetadataRetriever::sLock;

const sp<IMediaPlayerService> MediaMetadataRetriever::getService()
const sp<IMediaPlayerService> MediaMetadataRetriever::getService()
{
{
    Mutex::Autolock lock(sServiceLock);
    Mutex::Autolock lock(sServiceLock);
@@ -143,6 +145,7 @@ sp<IMemory> MediaMetadataRetriever::getFrameAtTime(
    ALOGV("getFrameAtTime: time(%" PRId64 " us) option(%d) colorFormat(%d) metaOnly(%d)",
    ALOGV("getFrameAtTime: time(%" PRId64 " us) option(%d) colorFormat(%d) metaOnly(%d)",
            timeUs, option, colorFormat, metaOnly);
            timeUs, option, colorFormat, metaOnly);
    Mutex::Autolock _l(mLock);
    Mutex::Autolock _l(mLock);
    Mutex::Autolock _gLock(sLock);
    if (mRetriever == 0) {
    if (mRetriever == 0) {
        ALOGE("retriever is not initialized");
        ALOGE("retriever is not initialized");
        return NULL;
        return NULL;
@@ -155,6 +158,7 @@ sp<IMemory> MediaMetadataRetriever::getImageAtIndex(
    ALOGV("getImageAtIndex: index(%d) colorFormat(%d) metaOnly(%d) thumbnail(%d)",
    ALOGV("getImageAtIndex: index(%d) colorFormat(%d) metaOnly(%d) thumbnail(%d)",
            index, colorFormat, metaOnly, thumbnail);
            index, colorFormat, metaOnly, thumbnail);
    Mutex::Autolock _l(mLock);
    Mutex::Autolock _l(mLock);
    Mutex::Autolock _gLock(sLock);
    if (mRetriever == 0) {
    if (mRetriever == 0) {
        ALOGE("retriever is not initialized");
        ALOGE("retriever is not initialized");
        return NULL;
        return NULL;
@@ -167,6 +171,7 @@ sp<IMemory> MediaMetadataRetriever::getImageRectAtIndex(
    ALOGV("getImageRectAtIndex: index(%d) colorFormat(%d) rect {%d, %d, %d, %d}",
    ALOGV("getImageRectAtIndex: index(%d) colorFormat(%d) rect {%d, %d, %d, %d}",
            index, colorFormat, left, top, right, bottom);
            index, colorFormat, left, top, right, bottom);
    Mutex::Autolock _l(mLock);
    Mutex::Autolock _l(mLock);
    Mutex::Autolock _gLock(sLock);
    if (mRetriever == 0) {
    if (mRetriever == 0) {
        ALOGE("retriever is not initialized");
        ALOGE("retriever is not initialized");
        return NULL;
        return NULL;
@@ -180,6 +185,7 @@ sp<IMemory> MediaMetadataRetriever::getFrameAtIndex(
    ALOGV("getFrameAtIndex: index(%d), colorFormat(%d) metaOnly(%d)",
    ALOGV("getFrameAtIndex: index(%d), colorFormat(%d) metaOnly(%d)",
            index, colorFormat, metaOnly);
            index, colorFormat, metaOnly);
    Mutex::Autolock _l(mLock);
    Mutex::Autolock _l(mLock);
    Mutex::Autolock _gLock(sLock);
    if (mRetriever == 0) {
    if (mRetriever == 0) {
        ALOGE("retriever is not initialized");
        ALOGE("retriever is not initialized");
        return NULL;
        return NULL;