From c405c5b4c1fb35726ea1dabd2dc3a03b7523da99 Mon Sep 17 00:00:00 2001 From: John Lin Date: Thu, 29 Oct 2015 21:14:00 +0100 Subject: [PATCH] Bug 1199809 - Don't schedule decoder I/O task when there will be more input. r=bwu --- .../platforms/gonk/GonkMediaDataDecoder.cpp | 30 +++++++++++-------- .../platforms/gonk/GonkMediaDataDecoder.h | 4 +-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp b/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp index 70492bf4bee8..fe526f736df8 100644 --- a/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp +++ b/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp @@ -137,8 +137,8 @@ GonkDecoderManager::Shutdown() return NS_OK; } -bool -GonkDecoderManager::HasQueuedSample() +size_t +GonkDecoderManager::NumQueuedSamples() { MutexAutoLock lock(mMutex); return mQueuedSamples.Length(); @@ -159,6 +159,8 @@ GonkDecoderManager::ProcessInput(bool aEndOfStream) mToDo->setInt32("input-eos", 1); } mDecoder->requestActivityNotification(mToDo); + } else if (aEndOfStream) { + mToDo->setInt32("input-eos", 1); } } else { GMDD_LOG("input processed: error#%d", rv); @@ -186,15 +188,9 @@ GonkDecoderManager::ProcessToDo(bool aEndOfStream) MOZ_ASSERT(mToDo.get() != nullptr); mToDo.clear(); - if (HasQueuedSample()) { - status_t pendingInput = ProcessQueuedSamples(); - if (pendingInput < 0) { - mDecodeCallback->Error(); - return; - } - if (!aEndOfStream && pendingInput <= MIN_QUEUED_SAMPLES) { - mDecodeCallback->InputExhausted(); - } + if (NumQueuedSamples() > 0 && ProcessQueuedSamples() < 0) { + mDecodeCallback->Error(); + return; } nsresult rv = NS_OK; @@ -226,8 +222,18 @@ GonkDecoderManager::ProcessToDo(bool aEndOfStream) } } - if (HasQueuedSample() || mWaitOutput.Length() > 0) { + if (!aEndOfStream && NumQueuedSamples() <= MIN_QUEUED_SAMPLES) { + mDecodeCallback->InputExhausted(); + // No need to shedule todo task this time because InputExhausted() will + // cause Input() to be invoked and do it for us. + return; + } + + if (NumQueuedSamples() || mWaitOutput.Length() > 0) { mToDo = new AMessage(kNotifyDecoderActivity, id()); + if (aEndOfStream) { + mToDo->setInt32("input-eos", 1); + } mDecoder->requestActivityNotification(mToDo); } } diff --git a/dom/media/platforms/gonk/GonkMediaDataDecoder.h b/dom/media/platforms/gonk/GonkMediaDataDecoder.h index 396822b331df..aafcb548289c 100644 --- a/dom/media/platforms/gonk/GonkMediaDataDecoder.h +++ b/dom/media/platforms/gonk/GonkMediaDataDecoder.h @@ -38,8 +38,8 @@ public: // Shutdown decoder and rejects the init promise. virtual nsresult Shutdown(); - // True if sample is queued. - bool HasQueuedSample(); + // How many samples are waiting for processing. + size_t NumQueuedSamples(); // Set callback for decoder events, such as requesting more input, // returning output, or reporting error.