Bug 1059625 - Detach MediaSource upon decoder shutdown. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Thu, 28 Aug 2014 15:44:58 +1200
changeset 202308 8a69a71936ce6ae2e422fe9b2705f613a8238812
parent 202307 4eb947a2195370ad07145a7f925ceef50ed09020
child 202309 756ce4591f679db1c0511491b2fbb4d398f1f376
push id27395
push usercbook@mozilla.com
push dateFri, 29 Aug 2014 12:55:06 +0000
treeherdermozilla-central@5f66dd3d63f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1059625
milestone34.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 1059625 - Detach MediaSource upon decoder shutdown. r=cajbir
content/media/mediasource/MediaSource.cpp
content/media/mediasource/MediaSourceDecoder.cpp
--- a/content/media/mediasource/MediaSource.cpp
+++ b/content/media/mediasource/MediaSource.cpp
@@ -126,16 +126,19 @@ MediaSource::Constructor(const GlobalObj
   nsRefPtr<MediaSource> mediaSource = new MediaSource(window);
   return mediaSource.forget();
 }
 
 MediaSource::~MediaSource()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MSE_API("MediaSource(%p)::~MediaSource()", this);
+  if (mDecoder) {
+    mDecoder->DetachMediaSource();
+  }
 }
 
 SourceBufferList*
 MediaSource::SourceBuffers()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT_IF(mReadyState == MediaSourceReadyState::Closed, mSourceBuffers->IsEmpty());
   return mSourceBuffers;
@@ -306,35 +309,40 @@ bool
 MediaSource::Attach(MediaSourceDecoder* aDecoder)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MSE_DEBUG("MediaSource(%p)::Attach(aDecoder=%p) owner=%p", this, aDecoder, aDecoder->GetOwner());
   MOZ_ASSERT(aDecoder);
   if (mReadyState != MediaSourceReadyState::Closed) {
     return false;
   }
+  MOZ_ASSERT(!mDecoder);
   mDecoder = aDecoder;
   mDecoder->AttachMediaSource(this);
   SetReadyState(MediaSourceReadyState::Open);
   return true;
 }
 
 void
 MediaSource::Detach()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MSE_DEBUG("MediaSource(%p)::Detach() mDecoder=%p owner=%p",
-            this, mDecoder.get(), mDecoder->GetOwner());
-  MOZ_ASSERT(mDecoder);
+            this, mDecoder.get(), mDecoder ? mDecoder->GetOwner() : nullptr);
+  if (!mDecoder) {
+    MOZ_ASSERT(mReadyState == MediaSourceReadyState::Closed);
+    MOZ_ASSERT(mActiveSourceBuffers->IsEmpty() && mSourceBuffers->IsEmpty());
+    return;
+  }
   mDecoder->DetachMediaSource();
   mDecoder = nullptr;
+  SetReadyState(MediaSourceReadyState::Closed);
   mDuration = UnspecifiedNaN<double>();
   mActiveSourceBuffers->Clear();
   mSourceBuffers->Clear();
-  SetReadyState(MediaSourceReadyState::Closed);
 }
 
 void
 MediaSource::GetBuffered(TimeRanges* aBuffered)
 {
   MOZ_ASSERT(aBuffered->Length() == 0);
   if (mActiveSourceBuffers->IsEmpty()) {
     return;
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -88,18 +88,22 @@ MediaSourceDecoder::GetSeekable(dom::Tim
   }
   MSE_DEBUG("MediaSourceDecoder(%p)::GetSeekable ranges=%s", this, DumpTimeRanges(aSeekable).get());
   return NS_OK;
 }
 
 void
 MediaSourceDecoder::Shutdown()
 {
+  MSE_DEBUG("MediaSourceDecoder(%p)::Shutdown", this);
   MediaDecoder::Shutdown();
 
+  if (mMediaSource) {
+    mMediaSource->Detach();
+  }
   // Kick WaitForData out of its slumber.
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
   mon.NotifyAll();
 }
 
 /*static*/
 already_AddRefed<MediaResource>
 MediaSourceDecoder::CreateResource()