diff options
author | Wei Jia <wjia@google.com> | 2015-04-21 11:41:41 -0700 |
---|---|---|
committer | Wei Jia <wjia@google.com> | 2015-04-22 17:16:39 -0700 |
commit | 80243639b0aa2c7c941c23c1aaeaa75de38c148c (patch) | |
tree | af43a1ece287ffd9bbacefc8a7aa574e5b1458ea /media | |
parent | ea44f41bb142555e747cc11382296e94af99d312 (diff) | |
download | frameworks_av-80243639b0aa2c7c941c23c1aaeaa75de38c148c.zip frameworks_av-80243639b0aa2c7c941c23c1aaeaa75de38c148c.tar.gz frameworks_av-80243639b0aa2c7c941c23c1aaeaa75de38c148c.tar.bz2 |
MediaSync: fix the optimization code path to reduce messages posted to drain video.
Bug: 19666434
Change-Id: I195a896033855ab3bfa43791b3c99f66776b007a
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/MediaSync.cpp | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/media/libstagefright/MediaSync.cpp b/media/libstagefright/MediaSync.cpp index ec956c4..9c37a3d 100644 --- a/media/libstagefright/MediaSync.cpp +++ b/media/libstagefright/MediaSync.cpp @@ -195,13 +195,14 @@ status_t MediaSync::updateQueuedAudioData( int64_t numFrames = sizeInBytes / mAudioTrack->frameSize(); int64_t maxMediaTimeUs = presentationTimeUs + getDurationIfPlayedAtNativeSampleRate_l(numFrames); - mNumFramesWritten += numFrames; int64_t nowUs = ALooper::GetNowUs(); - int64_t nowMediaUs = maxMediaTimeUs + int64_t nowMediaUs = presentationTimeUs - getDurationIfPlayedAtNativeSampleRate_l(mNumFramesWritten) + getPlayedOutAudioDurationMedia_l(nowUs); + mNumFramesWritten += numFrames; + int64_t oldRealTime = -1; if (mNextBufferItemMediaUs != -1) { oldRealTime = getRealTime(mNextBufferItemMediaUs, nowUs); @@ -212,12 +213,13 @@ status_t MediaSync::updateQueuedAudioData( if (oldRealTime != -1) { int64_t newRealTime = getRealTime(mNextBufferItemMediaUs, nowUs); - if (newRealTime < oldRealTime) { - mNextBufferItemMediaUs = -1; - onDrainVideo_l(); + if (newRealTime >= oldRealTime) { + return OK; } } + mNextBufferItemMediaUs = -1; + onDrainVideo_l(); return OK; } @@ -316,12 +318,12 @@ void MediaSync::onDrainVideo_l() { return; } - int64_t nowUs = ALooper::GetNowUs(); - while (!mBufferItems.empty()) { + int64_t nowUs = ALooper::GetNowUs(); BufferItem *bufferItem = &*mBufferItems.begin(); int64_t itemMediaUs = bufferItem->mTimestamp / 1000; int64_t itemRealUs = getRealTime(itemMediaUs, nowUs); + if (itemRealUs <= nowUs) { if (mHasAudio) { if (nowUs - itemRealUs <= kMaxAllowedVideoLateTimeUs) { @@ -341,15 +343,13 @@ void MediaSync::onDrainVideo_l() { } mBufferItems.erase(mBufferItems.begin()); - - if (mBufferItems.empty()) { - mNextBufferItemMediaUs = -1; - } + mNextBufferItemMediaUs = -1; } else { if (mNextBufferItemMediaUs == -1 - || mNextBufferItemMediaUs != itemMediaUs) { + || mNextBufferItemMediaUs > itemMediaUs) { sp<AMessage> msg = new AMessage(kWhatDrainVideo, this); msg->post(itemRealUs - nowUs); + mNextBufferItemMediaUs = itemMediaUs; } break; } @@ -395,7 +395,9 @@ void MediaSync::onFrameAvailableFromInput() { } mBufferItems.push_back(bufferItem); - onDrainVideo_l(); + if (mBufferItems.size() == 1) { + onDrainVideo_l(); + } } void MediaSync::renderOneBufferItem_l( const BufferItem &bufferItem) { @@ -499,6 +501,20 @@ void MediaSync::onMessageReceived(const sp<AMessage> &msg) { case kWhatDrainVideo: { Mutex::Autolock lock(mMutex); + if (mNextBufferItemMediaUs != -1) { + int64_t nowUs = ALooper::GetNowUs(); + int64_t itemRealUs = getRealTime(mNextBufferItemMediaUs, nowUs); + + // The message could arrive earlier than expected due to + // various reasons, e.g., media clock has been changed because + // of new anchor time or playback rate. In such cases, the + // message needs to be re-posted. + if (itemRealUs > nowUs) { + msg->post(itemRealUs - nowUs); + break; + } + } + onDrainVideo_l(); break; } |