summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/AudioSource.cpp
diff options
context:
space:
mode:
authorJames Dong <jdong@google.com>2010-09-01 18:48:35 -0700
committerJames Dong <jdong@google.com>2010-09-01 20:45:39 -0700
commitd707fcb3e29707ca4a5935c294ef0b38eb5aba5f (patch)
tree8f223d9d5656ba34a0fdfe2e7ee4992f7a0bf3e3 /media/libstagefright/AudioSource.cpp
parent9b93478fef2915a1d0cbb1fe17d2788ef8b5b230 (diff)
downloadframeworks_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/AudioSource.cpp')
-rw-r--r--media/libstagefright/AudioSource.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp
index bcae913..c2f79e8 100644
--- a/media/libstagefright/AudioSource.cpp
+++ b/media/libstagefright/AudioSource.cpp
@@ -84,6 +84,7 @@ status_t AudioSource::start(MetaData *params) {
mTrackMaxAmplitude = false;
mMaxAmplitude = 0;
+ mInitialReadTimeUs = 0;
mStartTimeUs = 0;
int64_t startTimeUs;
if (params && params->findInt64(kKeyTime, &startTimeUs)) {
@@ -210,6 +211,7 @@ status_t AudioSource::read(
return NO_INIT;
}
+ int64_t readTimeUs = systemTime() / 1000;
*out = NULL;
MediaBuffer *buffer;
@@ -223,9 +225,10 @@ status_t AudioSource::read(
if (numFramesRecorded == 0 && mPrevSampleTimeUs == 0) {
+ mInitialReadTimeUs = readTimeUs;
// Initial delay
if (mStartTimeUs > 0) {
- mStartTimeUs = systemTime() / 1000 - mStartTimeUs;
+ mStartTimeUs = readTimeUs - mStartTimeUs;
} else {
// Assume latency is constant.
mStartTimeUs += mRecord->latency() * 1000;
@@ -271,7 +274,10 @@ status_t AudioSource::read(
}
memset(buffer->data(), 0, numLostBytes);
buffer->set_range(0, numLostBytes);
- buffer->meta_data()->setInt64(kKeyTime, mPrevSampleTimeUs);
+ if (numFramesRecorded == 0) {
+ buffer->meta_data()->setInt64(kKeyTime, mStartTimeUs);
+ }
+ buffer->meta_data()->setInt64(kKeyDriftTime, readTimeUs - mInitialReadTimeUs);
mPrevSampleTimeUs = timestampUs;
*out = buffer;
return OK;
@@ -309,7 +315,10 @@ status_t AudioSource::read(
trackMaxAmplitude((int16_t *) buffer->data(), n >> 1);
}
- buffer->meta_data()->setInt64(kKeyTime, mPrevSampleTimeUs);
+ if (numFramesRecorded == 0) {
+ buffer->meta_data()->setInt64(kKeyTime, mStartTimeUs);
+ }
+ buffer->meta_data()->setInt64(kKeyDriftTime, readTimeUs - mInitialReadTimeUs);
CHECK(timestampUs > mPrevSampleTimeUs);
mPrevSampleTimeUs = timestampUs;
LOGV("initial delay: %lld, sample rate: %d, timestamp: %lld",