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

Commit 47352415 authored by Linus Nilsson's avatar Linus Nilsson
Browse files

Transcoder: Detect input/output frame count mismatch due to codec error

When setting operating rate for 4K videos the encoder will
silently drop frames but produce an EOS.
This commits adds a check after encoder EOS that logs a
warning if the number of output frames from the encoder is different
from the number of input frames to the decoder and throws an error
if no output frames are produced.

Bug: 175406816
Test: 4K unit test from ag/13237959
Change-Id: Ib58e26296160e9e4748d7562dca1034372e440ea
parent cbb06bde
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -396,6 +396,10 @@ void VideoTrackTranscoder::enqueueInputSample(int32_t bufferIndex) {
            mStatus = status;
            return;
        }

        if (mSampleInfo.size) {
            ++mInputFrameCount;
        }
    } else {
        LOG(DEBUG) << "EOS from source.";
        mEosFromSource = true;
@@ -445,6 +449,9 @@ void VideoTrackTranscoder::dequeueOutputSample(int32_t bufferIndex,
        sample->info.flags = bufferInfo.flags;
        sample->info.presentationTimeUs = bufferInfo.presentationTimeUs;

        if (bufferInfo.size > 0 && (bufferInfo.flags & SAMPLE_FLAG_CODEC_CONFIG) == 0) {
            ++mOutputFrameCount;
        }
        onOutputSampleAvailable(sample);

        mLastSampleWasSync = sample->info.flags & SAMPLE_FLAG_SYNC_SAMPLE;
@@ -456,6 +463,15 @@ void VideoTrackTranscoder::dequeueOutputSample(int32_t bufferIndex,
    if (bufferInfo.flags & AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM) {
        LOG(DEBUG) << "EOS from encoder.";
        mEosFromEncoder = true;

        if (mInputFrameCount != mOutputFrameCount) {
            LOG(WARNING) << "Input / Output frame count mismatch: " << mInputFrameCount << " vs "
                         << mOutputFrameCount;
            if (mInputFrameCount > 0 && mOutputFrameCount == 0) {
                LOG(ERROR) << "Encoder did not produce any output frames.";
                mStatus = AMEDIA_ERROR_UNKNOWN;
            }
        }
    }
}

+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <binder/ProcessState.h>
#include <fcntl.h>
#include <media/MediaTranscoder.h>

#include <iostream>

using namespace android;
+2 −0
Original line number Diff line number Diff line
@@ -99,6 +99,8 @@ private:
    std::shared_ptr<AMediaFormat> mActualOutputFormat;
    pid_t mPid;
    uid_t mUid;
    uint64_t mInputFrameCount = 0;
    uint64_t mOutputFrameCount = 0;
};

}  // namespace android