Bug 1171311: P1. Add MediaDataDemuxer::IsThreadSafe() method. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 12 Jun 2015 09:26:57 +1000
changeset 279301 3f187a37e3e9b05a9accb9d00d6e77a6e7701d38
parent 279300 437700eb4d87c124642259c31ef6a38b74eb15c9
child 279302 3a6e7468b0e079074234f4ee7a879661820bbee6
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1171311
milestone41.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 1171311: P1. Add MediaDataDemuxer::IsThreadSafe() method. r=cpearce
dom/media/MediaDataDemuxer.h
dom/media/MediaFormatReader.cpp
--- a/dom/media/MediaDataDemuxer.h
+++ b/dom/media/MediaDataDemuxer.h
@@ -45,16 +45,24 @@ public:
   // Initializes the demuxer. Other methods cannot be called unless
   // initialization has completed and succeeded.
   // Typically a demuxer will wait to parse the metadata before resolving the
   // promise. The promise will be rejected with WAITING_FOR_DATA should
   // insufficient data be available at the time. Init() would have to be called
   // again to retry once more data has been received.
   virtual nsRefPtr<InitPromise> Init() = 0;
 
+  // MediaFormatReader ensures that calls to the MediaDataDemuxer are thread-safe.
+  // This is done by having multiple demuxers, created with Clone(), one per
+  // running thread.
+  // However, should the MediaDataDemuxer object guaranteed to be thread-safe
+  // such cloning is unecessary and only one demuxer will be used across
+  // all threads.
+  virtual bool IsThreadSafe() { return false; }
+
   // Clone the demuxer and return a new initialized demuxer.
   // This can only be called once Init() has succeeded.
   // The new demuxer can be immediately use to retrieve the track demuxers.
   virtual already_AddRefed<MediaDataDemuxer> Clone() const = 0;
 
   // Returns true if a aType track type is available.
   virtual bool HasTrackType(TrackInfo::TrackType aType) const = 0;
 
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -336,17 +336,21 @@ MediaFormatReader::OnDemuxerInitDone(nsr
   int64_t duration = std::max(videoDuration, audioDuration);
   if (duration != -1) {
     mInfo.mMetadataDuration = Some(TimeUnit::FromMicroseconds(duration));
   }
 
   mSeekable = mDemuxer->IsSeekable();
 
   // Create demuxer object for main thread.
-  mMainThreadDemuxer = mDemuxer->Clone();
+  if (mDemuxer->IsThreadSafe()) {
+    mMainThreadDemuxer = mDemuxer;
+  } else {
+    mMainThreadDemuxer = mDemuxer->Clone();
+  }
   if (!mMainThreadDemuxer) {
     mMetadataPromise.Reject(ReadMetadataFailureReason::METADATA_ERROR, __func__);
     NS_WARNING("Unable to clone current MediaDataDemuxer");
     return;
   }
   if (videoActive) {
     mVideoTrackDemuxer =
       mMainThreadDemuxer->GetTrackDemuxer(TrackInfo::kVideoTrack, 0);