From d707fcb3e29707ca4a5935c294ef0b38eb5aba5f Mon Sep 17 00:00:00 2001 From: James Dong Date: Wed, 1 Sep 2010 18:48:35 -0700 Subject: Calculate audio media drift time from AudioSource The problem was that the time to receive an output buffer from an audio encoder is different because the encoder does not need to read from the source for all output buffers. This leads to large fluctuation in terms of wall clock duration between two neighboring audio sample outputs from the audio encoder. As a result, the media time for the video track after adjustment using the drifting changes wildly sometimes. This patch addresses this issue by only updating the media drift time when an audio source input buffer is read. the wall clock for the audio track is also calculated at the same time when the input audio buffer is read at AudioSource. bug - 2959800 Change-Id: I3174aa182f744784b540f0a7198524d4eee8bd7b --- media/libstagefright/codecs/amrnb/enc/AMRNBEncoder.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'media/libstagefright/codecs/amrnb') diff --git a/media/libstagefright/codecs/amrnb/enc/AMRNBEncoder.cpp b/media/libstagefright/codecs/amrnb/enc/AMRNBEncoder.cpp index c875426..dab1390 100644 --- a/media/libstagefright/codecs/amrnb/enc/AMRNBEncoder.cpp +++ b/media/libstagefright/codecs/amrnb/enc/AMRNBEncoder.cpp @@ -147,6 +147,8 @@ status_t AMRNBEncoder::read( int64_t seekTimeUs; ReadOptions::SeekMode mode; CHECK(options == NULL || !options->getSeekTo(&seekTimeUs, &mode)); + bool readFromSource = false; + int64_t wallClockTimeUs = 0; while (mNumInputSamples < kNumSamplesPerFrame) { if (mInputBuffer == NULL) { @@ -166,12 +168,16 @@ status_t AMRNBEncoder::read( size_t align = mInputBuffer->range_length() % sizeof(int16_t); CHECK_EQ(align, 0); + readFromSource = true; int64_t timeUs; + CHECK(mInputBuffer->meta_data()->findInt64(kKeyDriftTime, &timeUs)); + wallClockTimeUs = timeUs; if (mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs)) { mAnchorTimeUs = timeUs; - mNumFramesOutput = 0; } + } else { + readFromSource = false; } size_t copy = @@ -217,8 +223,14 @@ status_t AMRNBEncoder::read( buffer->set_range(0, res); // Each frame of 160 samples is 20ms long. + int64_t mediaTimeUs = mNumFramesOutput * 20000LL; buffer->meta_data()->setInt64( - kKeyTime, mAnchorTimeUs + mNumFramesOutput * 20000); + kKeyTime, mAnchorTimeUs + mediaTimeUs); + + if (readFromSource) { + buffer->meta_data()->setInt64(kKeyDriftTime, + mediaTimeUs - wallClockTimeUs); + } ++mNumFramesOutput; -- cgit v1.1