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

Commit f158ff01 authored by Revathi Uddaraju's avatar Revathi Uddaraju Committed by Dongwon Kang
Browse files

libmedia: synchronize access to meta.

Assignment of IMediaSource::mMetaData of type sp<T> in
IMediaSource::getFormat() is not thread-safe and is found
to be causing stability issues.

Synchronize access to meta smart pointer to prevent potential
race condition.

Test: build
Bug: 123082419
Change-Id: I8a94d82d69f35307e5fab8174d752a847f47a2f2
parent 0435a4dc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ public:
        data.writeInterfaceToken(BpMediaSource::getInterfaceDescriptor());
        status_t ret = remote()->transact(GETFORMAT, data, &reply);
        if (ret == NO_ERROR) {
            AutoMutex _l(mLock);
            mMetaData = MetaData::createFromParcel(reply);
            return mMetaData;
        }
@@ -222,6 +223,8 @@ private:
    // NuPlayer passes pointers-to-metadata around, so we use this to keep the metadata alive
    // XXX: could we use this for caching, or does metadata change on the fly?
    sp<MetaData> mMetaData;
    // ensure synchronize access to mMetaData
    Mutex mLock;

    // Cache all IMemory objects received from MediaExtractor.
    // We gc IMemory objects that are no longer active (referenced by a MediaBuffer).