diff options
author | James Dong <jdong@google.com> | 2010-09-01 18:48:35 -0700 |
---|---|---|
committer | James Dong <jdong@google.com> | 2010-09-01 20:45:39 -0700 |
commit | d707fcb3e29707ca4a5935c294ef0b38eb5aba5f (patch) | |
tree | 8f223d9d5656ba34a0fdfe2e7ee4992f7a0bf3e3 /media/libstagefright/codecs/aacenc | |
parent | 9b93478fef2915a1d0cbb1fe17d2788ef8b5b230 (diff) | |
download | frameworks_av-d707fcb3e29707ca4a5935c294ef0b38eb5aba5f.zip frameworks_av-d707fcb3e29707ca4a5935c294ef0b38eb5aba5f.tar.gz frameworks_av-d707fcb3e29707ca4a5935c294ef0b38eb5aba5f.tar.bz2 |
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
Diffstat (limited to 'media/libstagefright/codecs/aacenc')
-rw-r--r-- | media/libstagefright/codecs/aacenc/AACEncoder.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/media/libstagefright/codecs/aacenc/AACEncoder.cpp b/media/libstagefright/codecs/aacenc/AACEncoder.cpp index 052c354..c05e3e5 100644 --- a/media/libstagefright/codecs/aacenc/AACEncoder.cpp +++ b/media/libstagefright/codecs/aacenc/AACEncoder.cpp @@ -208,6 +208,8 @@ status_t AACEncoder::read( MediaBuffer *buffer; CHECK_EQ(mBufferGroup->acquire_buffer(&buffer), OK); uint8_t *outPtr = (uint8_t *)buffer->data(); + bool readFromSource = false; + int64_t wallClockTimeUs = 0; if (mFrameCount == 0) { memcpy(outPtr, mAudioSpecificConfigData, 2); @@ -238,9 +240,14 @@ status_t AACEncoder::read( CHECK_EQ(align, 0); int64_t timeUs; + CHECK(mInputBuffer->meta_data()->findInt64(kKeyDriftTime, &timeUs)); + wallClockTimeUs = timeUs; if (mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs)) { mAnchorTimeUs = timeUs; } + readFromSource = true; + } else { + readFromSource = false; } size_t copy = (kNumSamplesPerFrame - mNumInputSamples) * sizeof(int16_t); @@ -288,9 +295,13 @@ status_t AACEncoder::read( CHECK(outputData.Length != 0); buffer->set_range(0, outputData.Length); - int64_t timestampUs = ((mFrameCount - 1) * 1000000LL * kNumSamplesPerFrame) / mSampleRate; + int64_t mediaTimeUs = + ((mFrameCount - 1) * 1000000LL * kNumSamplesPerFrame) / mSampleRate; + buffer->meta_data()->setInt64(kKeyTime, mAnchorTimeUs + mediaTimeUs); + if (readFromSource) { + buffer->meta_data()->setInt64(kKeyDriftTime, mediaTimeUs - wallClockTimeUs); + } ++mFrameCount; - buffer->meta_data()->setInt64(kKeyTime, timestampUs); *out = buffer; return OK; |