Bug 1496281 - do not create audio stream if audio has ended. r=jya
authoralwu <alwu@mozilla.com>
Fri, 12 Oct 2018 22:23:40 +0000
changeset 499406 25bff27f9944c7bfea0372c2b6dc55e35977fb83
parent 499405 b8b3597d7702e4e6d7c3358f19384b49d8c220c0
child 499407 a5d9e6a7242dcb49be48adc839f071dd9a9a0316
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1496281
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1496281 - do not create audio stream if audio has ended. r=jya We should not init the audio steam when the audio queue is marked as finished. Differential Revision: https://phabricator.services.mozilla.com/D8031
dom/media/mediasink/AudioSink.cpp
--- a/dom/media/mediasink/AudioSink.cpp
+++ b/dom/media/mediasink/AudioSink.cpp
@@ -71,16 +71,21 @@ AudioSink::~AudioSink()
 {
 }
 
 nsresult
 AudioSink::Init(const PlaybackParams& aParams, RefPtr<GenericPromise>& aEndPromise)
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
 
+  if (mAudioQueue.IsFinished()) {
+    aEndPromise = GenericPromise::CreateAndResolve(true, __func__);
+    return NS_OK;
+  }
+
   mAudioQueueListener = mAudioQueue.PushEvent().Connect(
     mOwnerThread, this, &AudioSink::OnAudioPushed);
   mAudioQueueFinishListener = mAudioQueue.FinishEvent().Connect(
     mOwnerThread, this, &AudioSink::NotifyAudioNeeded);
   mProcessedQueueListener = mProcessedQueue.PopEvent().Connect(
     mOwnerThread, this, &AudioSink::OnAudioPopped);
 
   // To ensure at least one audio packet will be popped from AudioQueue and
@@ -126,19 +131,19 @@ AudioSink::HasUnplayedFrames()
          (mAudioStream && mAudioStream->GetPositionInFrames() + 1 < total);
 }
 
 void
 AudioSink::Shutdown()
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
 
-  mAudioQueueListener.Disconnect();
-  mAudioQueueFinishListener.Disconnect();
-  mProcessedQueueListener.Disconnect();
+  mAudioQueueListener.DisconnectIfExists();
+  mAudioQueueFinishListener.DisconnectIfExists();
+  mProcessedQueueListener.DisconnectIfExists();
 
   if (mAudioStream) {
     mAudioStream->Shutdown();
     mAudioStream = nullptr;
   }
   mProcessedQueue.Reset();
   mProcessedQueue.Finish();
   mEndPromise.ResolveIfExists(true, __func__);