summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/MPEG4Writer.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/MPEG4Writer.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/MPEG4Writer.cpp')
-rw-r--r--media/libstagefright/MPEG4Writer.cpp29
1 files changed, 9 insertions, 20 deletions
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index a15b84e..af2b4c4 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -1430,9 +1430,6 @@ status_t MPEG4Writer::Track::threadEntry() {
int64_t previousPausedDurationUs = 0;
int64_t timestampUs;
- int64_t wallClockTimeUs = 0;
- int64_t lastWallClockTimeUs = 0;
-
sp<MetaData> meta_data;
bool collectStats = collectStatisticalData();
@@ -1542,14 +1539,15 @@ status_t MPEG4Writer::Track::threadEntry() {
// of neighboring samples. This in turn helps reduce the track header size,
// especially, the number of entries in the "stts" box.
if (mNumSamples > 1) {
- int64_t durationUs = timestampUs + mOwner->getDriftTimeUs() - lastTimestampUs;
+ int64_t currDriftTimeUs = mOwner->getDriftTimeUs();
+ int64_t durationUs = timestampUs + currDriftTimeUs - lastTimestampUs;
int64_t diffUs = (durationUs > lastDurationUs)
? durationUs - lastDurationUs
: lastDurationUs - durationUs;
if (diffUs <= 5000) { // XXX: Magic number 5ms
timestampUs = lastTimestampUs + lastDurationUs;
} else {
- timestampUs += mOwner->getDriftTimeUs();
+ timestampUs += currDriftTimeUs;
}
}
}
@@ -1557,12 +1555,6 @@ status_t MPEG4Writer::Track::threadEntry() {
if (mNumSamples > 1) {
if (timestampUs <= lastTimestampUs) {
LOGW("Frame arrives too late!");
-#if 0
- // Drop the late frame.
- copy->release();
- copy = NULL;
- continue;
-#else
// Don't drop the late frame, since dropping a frame may cause
// problems later during playback
@@ -1573,7 +1565,6 @@ status_t MPEG4Writer::Track::threadEntry() {
} else {
timestampUs = lastTimestampUs + (1000000LL + (mTimeScale >> 1)) / mTimeScale;
}
-#endif
}
}
@@ -1613,12 +1604,10 @@ status_t MPEG4Writer::Track::threadEntry() {
lastDurationTicks = currDurationTicks;
lastTimestampUs = timestampUs;
if (mIsRealTimeRecording && mIsAudio) {
- wallClockTimeUs = systemTime() / 1000;
- int64_t wallClockDurationUs = wallClockTimeUs - lastWallClockTimeUs;
- if (mNumSamples > 2) {
- mOwner->addDriftTimeUs(lastDurationUs - wallClockDurationUs);
+ int64_t driftTimeUs = 0;
+ if (meta_data->findInt64(kKeyDriftTime, &driftTimeUs)) {
+ mOwner->setDriftTimeUs(driftTimeUs);
}
- lastWallClockTimeUs = wallClockTimeUs;
}
if (isSync != 0) {
@@ -1851,10 +1840,10 @@ void MPEG4Writer::Track::logStatisticalData(bool isAudio) {
}
}
-void MPEG4Writer::addDriftTimeUs(int64_t driftTimeUs) {
- LOGV("addDriftTimeUs: %lld us", driftTimeUs);
+void MPEG4Writer::setDriftTimeUs(int64_t driftTimeUs) {
+ LOGV("setDriftTimeUs: %lld us", driftTimeUs);
Mutex::Autolock autolock(mLock);
- mDriftTimeUs += driftTimeUs;
+ mDriftTimeUs = driftTimeUs;
}
int64_t MPEG4Writer::getDriftTimeUs() {