From fd65f91772ab8c644fc96d9cb0265ff6cc1a99e2 Mon Sep 17 00:00:00 2001 From: Harish Mahendrakar Date: Thu, 2 Apr 2020 05:45:05 +0530 Subject: [PATCH] C2SoftAvcDec: Fix interlaced input handling C2 plugin for avc decoder is now updated to appropriately handle both types of interlaced content, i.e. sent as one field per one input buffer and sent as two fields per one input - Allow bytes consumed to be returned as zero to handle dangling fields - Do not ignore trailing bytes after decode call as that data may contain next field - Ensure input buffer contains at least 4 bytes - After signalling new output delay, do not feed the input again Bug: 135146280 Bug: 152087140 Test: poc in bugs Test: atest android.media.cts.DecoderTest Change-Id: I1f6a12878eeebb604a16f8e9edcdf3d631ef5afc Merged-In: I1f6a12878eeebb604a16f8e9edcdf3d631ef5afc --- media/codec2/components/avc/C2SoftAvcDec.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/media/codec2/components/avc/C2SoftAvcDec.cpp b/media/codec2/components/avc/C2SoftAvcDec.cpp index 56813c48eb..d686eb1a0b 100644 --- a/media/codec2/components/avc/C2SoftAvcDec.cpp +++ b/media/codec2/components/avc/C2SoftAvcDec.cpp @@ -35,6 +35,7 @@ constexpr size_t kMinInputBufferSize = 2 * 1024 * 1024; constexpr char COMPONENT_NAME[] = "c2.android.avc.decoder"; constexpr uint32_t kDefaultOutputDelay = 8; constexpr uint32_t kMaxOutputDelay = 16; +constexpr uint32_t kMinInputBytes = 4; } // namespace class C2SoftAvcDec::IntfImpl : public SimpleInterface::BaseParams { @@ -817,7 +818,7 @@ void C2SoftAvcDec::process( inSize, (int)work->input.ordinal.timestamp.peeku(), (int)work->input.ordinal.frameIndex.peeku(), work->input.flags); size_t inPos = 0; - while (inPos < inSize) { + while (inPos < inSize && inSize - inPos >= kMinInputBytes) { if (C2_OK != ensureDecoderState(pool)) { mSignalledError = true; work->workletsProcessed = 1u; @@ -904,7 +905,6 @@ void C2SoftAvcDec::process( work->result = C2_CORRUPTED; return; } - continue; } if (0 < s_decode_op.u4_pic_wd && 0 < s_decode_op.u4_pic_ht) { if (mHeaderDecoded == false) { @@ -937,16 +937,7 @@ void C2SoftAvcDec::process( if (s_decode_op.u4_output_present) { finishWork(s_decode_op.u4_ts, work); } - if (0 == s_decode_op.u4_num_bytes_consumed) { - ALOGD("Bytes consumed is zero. Ignoring remaining bytes"); - break; - } inPos += s_decode_op.u4_num_bytes_consumed; - if (hasPicture && (inSize - inPos)) { - ALOGD("decoded frame in current access nal, ignoring further trailing bytes %d", - (int)inSize - (int)inPos); - break; - } } if (eos) { drainInternal(DRAIN_COMPONENT_WITH_EOS, pool, work);