diff options
author | Wei Jia <wjia@google.com> | 2015-04-23 00:19:04 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-04-23 00:19:05 +0000 |
commit | 1ac91ed2c67245ea5052182212463d3f0afe8b5a (patch) | |
tree | 2e4f2cd8b74e3f398029b17775668a79cbbafeb6 /media | |
parent | da408611e9390eefabc7a390be148528bbdd002f (diff) | |
parent | 80243639b0aa2c7c941c23c1aaeaa75de38c148c (diff) | |
download | frameworks_av-1ac91ed2c67245ea5052182212463d3f0afe8b5a.zip frameworks_av-1ac91ed2c67245ea5052182212463d3f0afe8b5a.tar.gz frameworks_av-1ac91ed2c67245ea5052182212463d3f0afe8b5a.tar.bz2 |
Merge "MediaSync: fix the optimization code path to reduce messages posted to drain video."
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; } |