Bug 1040550 - Prevent MediaSource::SetDuration from being called outside the main thread. r=kinetik
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 28 Jul 2014 11:50:32 +1200
changeset 196495 8111090f94a6
parent 196494 d308a4e99f78
child 196496 22a61b3f1390
push id46890
push usercbook@mozilla.com
push dateTue, 29 Jul 2014 10:12:42 +0000
treeherdermozilla-inbound@8111090f94a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1040550
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 1040550 - Prevent MediaSource::SetDuration from being called outside the main thread. r=kinetik
content/media/mediasource/MediaSourceDecoder.cpp
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -226,16 +226,22 @@ private:
 
   MediaDecoderReader* GetVideoReader() {
     if (mActiveVideoDecoder == -1) {
       return nullptr;
     }
     return mDecoders[mActiveVideoDecoder]->GetReader();
   }
 
+  void SetMediaSourceDuration(double aDuration) {
+    MOZ_ASSERT(NS_IsMainThread());
+    ErrorResult dummy;
+    mMediaSource->SetDuration(aDuration, dummy);
+  }
+
   nsTArray<nsRefPtr<SubBufferDecoder>> mPendingDecoders;
   nsTArray<nsRefPtr<SubBufferDecoder>> mDecoders;
 
   int32_t mActiveVideoDecoder;
   int32_t mActiveAudioDecoder;
   dom::MediaSource* mMediaSource;
 };
 
@@ -580,18 +586,19 @@ MediaSourceReader::ReadMetadata(MediaInf
       maxDuration = std::max(maxDuration, mDecoders[i]->GetMediaDuration());
       MSE_DEBUG("%p: MSR::ReadMetadata audio decoder=%u maxDuration=%lld", this, i, maxDuration);
     }
   }
 
   if (maxDuration != -1) {
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
     mDecoder->SetMediaDuration(maxDuration);
-    ErrorResult dummy;
-    mMediaSource->SetDuration(maxDuration, dummy);
+    nsRefPtr<nsIRunnable> task (
+      NS_NewRunnableMethodWithArg<double>(this, &MediaSourceReader::SetMediaSourceDuration, maxDuration));
+    NS_DispatchToMainThread(task);
   }
 
   *aInfo = mInfo;
   *aTags = nullptr; // TODO: Handle metadata.
 
   return NS_OK;
 }