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

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

Codec2Client: Do not overlap setOutputSurface

setOutputSurface() can race between a normal surface change and a release
surface change. stopUseOutputSurface() may race with setOutputSurface().
Guarantee they run mutually exclusively.

Bug: 202903117
Test: atest android.media.cts.MediaCodecTest#testAsyncRelease
Test: atest android.media.decoder.cts.AdaptivePlaybackTest

Change-Id: Ia1262fccd0c96530f7b8f0056ea2c3acb448a1a2
parent c7da7a0f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1502,6 +1502,7 @@ c2_status_t Codec2Client::Component::setOutputSurface(
        igbp = new B2HGraphicBufferProducer2(surface);
    }

    std::scoped_lock lock(mOutputMutex);
    std::shared_ptr<SurfaceSyncObj> syncObj;

    if (!surface) {
@@ -1588,6 +1589,7 @@ void Codec2Client::Component::setOutputSurfaceMaxDequeueCount(

void Codec2Client::Component::stopUsingOutputSurface(
        C2BlockPool::local_id_t blockPoolId) {
    std::scoped_lock lock(mOutputMutex);
    mOutputBufferQueue->stop();
    Return<Status> transStatus = mBase1_0->setOutputSurface(
            static_cast<uint64_t>(blockPoolId), nullptr);
+5 −0
Original line number Diff line number Diff line
@@ -445,6 +445,11 @@ protected:
    struct OutputBufferQueue;
    std::unique_ptr<OutputBufferQueue> mOutputBufferQueue;

    // (b/202903117) Sometimes MediaCodec::setSurface races between normal
    // setSurface and setSurface with ReleaseSurface due to timing issues.
    // In order to prevent the race condition mutex is added.
    std::mutex mOutputMutex;

    static c2_status_t setDeathListener(
            const std::shared_ptr<Component>& component,
            const std::shared_ptr<Listener>& listener);