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

Commit 901ca36b authored by Hangyu Kuang's avatar Hangyu Kuang
Browse files

media: Mediarecorder drops the mediabuffer with negative adjusted timestamp.

In some rare cases, mediabuffer's adjusted timestamp may become negative due to
the extra delay adjustment at the beginning of start/resume. Drop the buffer in
these cases.

Bug: 29165056
Change-Id: Id8f68c188e76c9c077d41ff9901452f5aeb02d2a
parent dbeeac03
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -648,6 +648,15 @@ status_t MediaCodecSource::feedEncoderInputBuffers() {
            CHECK(mbuf->meta_data()->findInt64(kKeyTime, &timeUs));
            timeUs += mInputBufferTimeOffsetUs;

            // Due to the extra delay adjustment at the beginning of start/resume,
            // the adjusted timeUs may be negative if MediaCodecSource goes into pause
            // state before feeding any buffers to the encoder. Drop the buffer in this
            // case.
            if (timeUs < 0) {
                mbuf->release();
                return OK;
            }

            // push decoding time for video, or drift time for audio
            if (mIsVideo) {
                mDecodingTimeQueue.push_back(timeUs);
@@ -832,9 +841,16 @@ void MediaCodecSource::onMessageReceived(const sp<AMessage> &msg) {
                        // Time offset is not applied at
                        // feedEncoderInputBuffer() in surface input case.
                        timeUs += mInputBufferTimeOffsetUs;
                        // GraphicBufferSource is supposed to discard samples
                        // queued before start, and offset timeUs by start time
                        CHECK_GE(timeUs, 0ll);

                        // Due to the extra delay adjustment at the beginning of
                        // start/resume, the adjusted timeUs may be negative if
                        // MediaCodecSource goes into pause state before feeding
                        // any buffers to the encoder. Drop the buffer in this case.
                        if (timeUs < 0) {
                            mEncoder->releaseOutputBuffer(index);
                            break;
                        }

                        // TODO:
                        // Decoding time for surface source is unavailable,
                        // use presentation time for now. May need to move