codec2: Avoid sending input done event for incomplete work
- In cases where single input buffer can produce multiple
outputs, any work done event triggers input done event in
surface mode and does not wait for input buffer done event
from component. This can make producer to overwrite graphic
buffer that is still being processesed by codec leading to
corruption in output.
- Added check to not send input done event to surface if output
buffer flag is set to FLAG_INCOMPLETE
Bug: 174725323
Test: cts/media/device-small
Change-Id: I1164bf5c61e3fce346e51a57620ee68914a517ec
diff --git a/media/codec2/sfplugin/CCodec.cpp b/media/codec2/sfplugin/CCodec.cpp
index b47e546..a883652 100644
--- a/media/codec2/sfplugin/CCodec.cpp
+++ b/media/codec2/sfplugin/CCodec.cpp
@@ -2264,7 +2264,12 @@
}
}
if (config->mInputSurface) {
- config->mInputSurface->onInputBufferDone(work->input.ordinal.frameIndex);
+ if (work->worklets.empty()
+ || !work->worklets.back()
+ || (work->worklets.back()->output.flags
+ & C2FrameData::FLAG_INCOMPLETE) == 0) {
+ config->mInputSurface->onInputBufferDone(work->input.ordinal.frameIndex);
+ }
}
if (initDataWatcher.hasChanged()) {
initData = initDataWatcher.update();