diff options
author | James Dong <jdong@google.com> | 2010-08-11 17:29:09 -0700 |
---|---|---|
committer | James Dong <jdong@google.com> | 2010-08-12 10:40:58 -0700 |
commit | 708ec39c21568e0c2aa3d20c681f0e14ee6134ad (patch) | |
tree | ab61c2cb58585b1692ffeb239be99d7b80bb27a1 | |
parent | 45cb3cfacf3b07ae3c5f15eba9bbbcd060cee261 (diff) | |
download | frameworks_base-708ec39c21568e0c2aa3d20c681f0e14ee6134ad.zip frameworks_base-708ec39c21568e0c2aa3d20c681f0e14ee6134ad.tar.gz frameworks_base-708ec39c21568e0c2aa3d20c681f0e14ee6134ad.tar.bz2 |
Don't send late frames to software encoders for encoding
o Document on what frames will be rejected and what frames will be accepted
Change-Id: I5a5d489ad3d2b50dbb40a0f6e01529312ce81c54
-rw-r--r-- | media/libstagefright/codecs/avc/enc/AVCEncoder.cpp | 16 | ||||
-rw-r--r-- | media/libstagefright/codecs/m4v_h263/enc/M4vH263Encoder.cpp | 13 | ||||
-rw-r--r-- | media/libstagefright/include/AVCEncoder.h | 1 | ||||
-rw-r--r-- | media/libstagefright/include/M4vH263Encoder.h | 1 |
4 files changed, 29 insertions, 2 deletions
diff --git a/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp b/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp index 6e74279..0d89e02 100644 --- a/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp +++ b/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp @@ -407,6 +407,22 @@ status_t AVCEncoder::read( CHECK(mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs)); outputBuffer->meta_data()->setInt64(kKeyTime, timeUs); + // When the timestamp of the current sample is the same as + // that of the previous sample, the encoding of the sample + // is bypassed, and the output length is set to 0. + if (mNumInputFrames >= 1 && mPrevTimestampUs == timeUs) { + // Frame arrives too late + mInputBuffer->release(); + mInputBuffer = NULL; + outputBuffer->set_range(0, 0); + *out = outputBuffer; + return OK; + } + + // Don't accept out-of-order samples + CHECK(mPrevTimestampUs < timeUs); + mPrevTimestampUs = timeUs; + AVCFrameIO videoInput; memset(&videoInput, 0, sizeof(videoInput)); videoInput.height = ((mVideoHeight + 15) >> 4) << 4; diff --git a/media/libstagefright/codecs/m4v_h263/enc/M4vH263Encoder.cpp b/media/libstagefright/codecs/m4v_h263/enc/M4vH263Encoder.cpp index 1bef0e9..5ea5859 100644 --- a/media/libstagefright/codecs/m4v_h263/enc/M4vH263Encoder.cpp +++ b/media/libstagefright/codecs/m4v_h263/enc/M4vH263Encoder.cpp @@ -306,8 +306,13 @@ status_t M4vH263Encoder::read( int64_t timeUs; CHECK(mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs)); - if (mNextModTimeUs > timeUs) { - LOGV("mNextModTimeUs %lld > timeUs %lld", mNextModTimeUs, timeUs); + + // When the timestamp of the current sample is the same as that + // of the previous sample, encoding of the current sample is + // bypassed, and the output length of the sample is set to 0 + if (mNumInputFrames >= 1 && + (mNextModTimeUs > timeUs || mPrevTimestampUs == timeUs)) { + // Frame arrives too late outputBuffer->set_range(0, 0); *out = outputBuffer; mInputBuffer->release(); @@ -315,6 +320,10 @@ status_t M4vH263Encoder::read( return OK; } + // Don't accept out-of-order samples + CHECK(mPrevTimestampUs < timeUs); + mPrevTimestampUs = timeUs; + // Color convert to OMX_COLOR_FormatYUV420Planar if necessary outputBuffer->meta_data()->setInt64(kKeyTime, timeUs); uint8_t *inPtr = (uint8_t *) mInputBuffer->data(); diff --git a/media/libstagefright/include/AVCEncoder.h b/media/libstagefright/include/AVCEncoder.h index 4fe2e30..83e1f97 100644 --- a/media/libstagefright/include/AVCEncoder.h +++ b/media/libstagefright/include/AVCEncoder.h @@ -64,6 +64,7 @@ private: int32_t mVideoBitRate; int32_t mVideoColorFormat; int64_t mNumInputFrames; + int64_t mPrevTimestampUs; status_t mInitCheck; bool mStarted; bool mSpsPpsHeaderReceived; diff --git a/media/libstagefright/include/M4vH263Encoder.h b/media/libstagefright/include/M4vH263Encoder.h index dd146f4..dbe9fd0 100644 --- a/media/libstagefright/include/M4vH263Encoder.h +++ b/media/libstagefright/include/M4vH263Encoder.h @@ -59,6 +59,7 @@ private: int32_t mVideoColorFormat; int64_t mNumInputFrames; int64_t mNextModTimeUs; + int64_t mPrevTimestampUs; status_t mInitCheck; bool mStarted; |