CCodecBufferChannel: make sure the output buffers are reported in order
Bug: 275742376
Test: atest android.mediav2.cts.EncoderProfileLevelTest#testValidateProfileLevel
Change-Id: I653b0d8eac2f2d9c1a2a73f5cf2b0edd18c41fbf
diff --git a/media/codec2/sfplugin/CCodecBufferChannel.cpp b/media/codec2/sfplugin/CCodecBufferChannel.cpp
index da33b0d..593dbf3 100644
--- a/media/codec2/sfplugin/CCodecBufferChannel.cpp
+++ b/media/codec2/sfplugin/CCodecBufferChannel.cpp
@@ -2113,7 +2113,10 @@
outBuffer->meta()->setInt32("flags", BUFFER_FLAG_CODEC_CONFIG);
ALOGV("[%s] onWorkDone: csd index = %zu [%p]", mName, index, outBuffer.get());
- output.unlock();
+ // TRICKY: we want popped buffers reported in order, so sending
+ // the callback while holding the lock here. This assumes that
+ // onOutputBufferAvailable() does not block. onOutputBufferAvailable()
+ // callbacks are always sent with the Output lock held.
mCallback->onOutputBufferAvailable(index, outBuffer);
} else {
ALOGD("[%s] onWorkDone: unable to register csd", mName);
@@ -2203,7 +2206,10 @@
case OutputBuffers::DISCARD:
break;
case OutputBuffers::NOTIFY_CLIENT:
- output.unlock();
+ // TRICKY: we want popped buffers reported in order, so sending
+ // the callback while holding the lock here. This assumes that
+ // onOutputBufferAvailable() does not block. onOutputBufferAvailable()
+ // callbacks are always sent with the Output lock held.
mCallback->onOutputBufferAvailable(index, outBuffer);
break;
case OutputBuffers::REALLOCATE: