diff options
author | Lajos Molnar <lajos@google.com> | 2014-10-21 06:11:59 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-10-21 06:11:59 +0000 |
commit | e2a168b2ec3f96fe39d84e4f1553881efd691c38 (patch) | |
tree | b2ecc8e80d56de53b9706d54cf9c180155d16fc7 /media | |
parent | f5176d8ed28b77dd56eb1567f43bb73ebea9532b (diff) | |
parent | d5923409bbcbb22954a92c2b497ef4492d7cb6a5 (diff) | |
download | frameworks_av-e2a168b2ec3f96fe39d84e4f1553881efd691c38.zip frameworks_av-e2a168b2ec3f96fe39d84e4f1553881efd691c38.tar.gz frameworks_av-e2a168b2ec3f96fe39d84e4f1553881efd691c38.tar.bz2 |
am d5923409: mediaplayer: limit scheduling video frames into the future
* commit 'd5923409bbcbb22954a92c2b497ef4492d7cb6a5':
mediaplayer: limit scheduling video frames into the future
Diffstat (limited to 'media')
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp | 39 | ||||
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h | 5 |
2 files changed, 43 insertions, 1 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp index 46a2590..638d9bc 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp @@ -82,7 +82,9 @@ NuPlayer::Renderer::Renderer( mAudioRenderingStartGeneration(0), mAudioOffloadPauseTimeoutGeneration(0), mAudioOffloadTornDown(false), - mCurrentOffloadInfo(AUDIO_INFO_INITIALIZER) { + mCurrentOffloadInfo(AUDIO_INFO_INITIALIZER), + mTotalBuffersQueued(0), + mLastAudioBufferDrained(0) { readProperties(); } @@ -361,6 +363,19 @@ void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) { break; } + case kWhatPostDrainVideoQueue: + { + int32_t generation; + CHECK(msg->findInt32("generation", &generation)); + if (generation != mVideoQueueGeneration) { + break; + } + + mDrainVideoQueuePending = false; + postDrainVideoQueue(); + break; + } + case kWhatQueueBuffer: { onQueueBuffer(msg); @@ -580,6 +595,8 @@ bool NuPlayer::Renderer::onDrainAudioQueue() { while (numBytesAvailableToWrite > 0 && !mAudioQueue.empty()) { QueueEntry *entry = &*mAudioQueue.begin(); + mLastAudioBufferDrained = entry->mBufferOrdinal; + if (entry->mBuffer == NULL) { // EOS int64_t postEOSDelayUs = 0; @@ -716,6 +733,25 @@ void NuPlayer::Renderer::postDrainVideoQueue() { } else { realTimeUs = getRealTimeUs(mediaTimeUs, nowUs); } + + // Heuristics to handle situation when media time changed without a + // discontinuity. If we have not drained an audio buffer that was + // received after this buffer, repost in 10 msec. Otherwise repost + // in 500 msec. + delayUs = realTimeUs - nowUs; + if (delayUs > 500000) { + int64_t postDelayUs = 500000; + if (mHasAudio && (mLastAudioBufferDrained - entry.mBufferOrdinal) <= 0) { + postDelayUs = 10000; + } + msg->setWhat(kWhatPostDrainVideoQueue); + msg->post(postDelayUs); + mVideoScheduler->restart(); + ALOGI("possible video time jump of %dms, retrying in %dms", + (int)(delayUs / 1000), (int)(postDelayUs / 1000)); + mDrainVideoQueuePending = true; + return; + } } realTimeUs = mVideoScheduler->schedule(realTimeUs * 1000) / 1000; @@ -855,6 +891,7 @@ void NuPlayer::Renderer::onQueueBuffer(const sp<AMessage> &msg) { entry.mNotifyConsumed = notifyConsumed; entry.mOffset = 0; entry.mFinalResult = OK; + entry.mBufferOrdinal = ++mTotalBuffersQueued; if (audio) { Mutex::Autolock autoLock(mLock); diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h index 7079f85..b15a266 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h @@ -101,6 +101,7 @@ private: enum { kWhatDrainAudioQueue = 'draA', kWhatDrainVideoQueue = 'draV', + kWhatPostDrainVideoQueue = 'pDVQ', kWhatQueueBuffer = 'queB', kWhatQueueEOS = 'qEOS', kWhatFlush = 'flus', @@ -119,6 +120,7 @@ private: sp<AMessage> mNotifyConsumed; size_t mOffset; status_t mFinalResult; + int32_t mBufferOrdinal; }; static const int64_t kMinPositionUpdateDelayUs; @@ -169,6 +171,9 @@ private: bool mAudioOffloadTornDown; audio_offload_info_t mCurrentOffloadInfo; + int32_t mTotalBuffersQueued; + int32_t mLastAudioBufferDrained; + size_t fillAudioBuffer(void *buffer, size_t size); bool onDrainAudioQueue(); |