Bug 902197. Don't allow multiple MediaStreams to share the same DOMMediaStream wrapper. r=ehsan
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 07 Aug 2013 10:14:35 +1200
changeset 141615 0bf7876fd7932ed3f3e8f0a19e0057574c08d9e6
parent 141614 95ffea3d6908c9bf8826583dedaf90508b131be2
child 141616 91f4bd08f12b416f38b5bda9c9bee77a24b3253d
push id32157
push userrocallahan@mozilla.com
push dateWed, 07 Aug 2013 02:31:51 +0000
treeherdermozilla-inbound@91f4bd08f12b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs902197
milestone26.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 902197. Don't allow multiple MediaStreams to share the same DOMMediaStream wrapper. r=ehsan
content/media/MediaRecorder.cpp
content/media/MediaStreamGraph.cpp
content/media/MediaStreamGraph.h
--- a/content/media/MediaRecorder.cpp
+++ b/content/media/MediaRecorder.cpp
@@ -171,17 +171,17 @@ MediaRecorder::Start(const Optional<int3
     }
     mTimeSlice = aTimeSlice.Value();
   } else {
     mTimeSlice = 0;
   }
 
   // Create a TrackUnionStream to support Pause/Resume by using ChangeExplicitBlockerCount
   MediaStreamGraph* gm = mStream->GetStream()->Graph();
-  mTrackUnionStream = gm->CreateTrackUnionStream(mStream);
+  mTrackUnionStream = gm->CreateTrackUnionStream(nullptr);
   MOZ_ASSERT(mTrackUnionStream, "CreateTrackUnionStream failed");
 
   if (!CheckPrincipal()) {
     aResult.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return;
   }
 
   if (mEncodedBufferCache == nullptr) {
--- a/content/media/MediaStreamGraph.cpp
+++ b/content/media/MediaStreamGraph.cpp
@@ -1542,16 +1542,40 @@ MediaStreamGraphImpl::AppendMessage(Cont
   mCurrentTaskMessageQueue.AppendElement(aMessage);
   // Do not start running the non-realtime graph unless processing has
   // explicitly started.
   if (mRealtime || mNonRealtimeProcessing) {
     EnsureRunInStableState();
   }
 }
 
+MediaStream::MediaStream(DOMMediaStream* aWrapper)
+  : mBufferStartTime(0)
+  , mExplicitBlockerCount(0)
+  , mBlocked(false)
+  , mGraphUpdateIndices(0)
+  , mFinished(false)
+  , mNotifiedFinished(false)
+  , mNotifiedBlocked(false)
+  , mHasCurrentData(false)
+  , mNotifiedHasCurrentData(false)
+  , mWrapper(aWrapper)
+  , mMainThreadCurrentTime(0)
+  , mMainThreadFinished(false)
+  , mMainThreadDestroyed(false)
+  , mGraph(nullptr)
+{
+  MOZ_COUNT_CTOR(MediaStream);
+  // aWrapper should not already be connected to a MediaStream! It needs
+  // to be hooked up to this stream, and since this stream is only just
+  // being created now, aWrapper must not be connected to anything.
+  NS_ASSERTION(!aWrapper || !aWrapper->GetStream(),
+               "Wrapper already has another media stream hooked up to it!");
+}
+
 void
 MediaStream::Init()
 {
   MediaStreamGraphImpl* graph = GraphImpl();
   mBlocked.SetAtAndAfter(graph->mCurrentTime, true);
   mExplicitBlockerCount.SetAtAndAfter(graph->mCurrentTime, true);
   mExplicitBlockerCount.SetAtAndAfter(graph->mStateComputedTime, false);
 }
--- a/content/media/MediaStreamGraph.h
+++ b/content/media/MediaStreamGraph.h
@@ -258,34 +258,17 @@ struct AudioChunk;
  * collected via cycle collection. Destroy messages will be sent
  * for those objects in arbitrary order and the MediaStreamGraph has to be able
  * to handle this.
  */
 class MediaStream : public mozilla::LinkedListElement<MediaStream> {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaStream)
 
-  MediaStream(DOMMediaStream* aWrapper)
-    : mBufferStartTime(0)
-    , mExplicitBlockerCount(0)
-    , mBlocked(false)
-    , mGraphUpdateIndices(0)
-    , mFinished(false)
-    , mNotifiedFinished(false)
-    , mNotifiedBlocked(false)
-    , mHasCurrentData(false)
-    , mNotifiedHasCurrentData(false)
-    , mWrapper(aWrapper)
-    , mMainThreadCurrentTime(0)
-    , mMainThreadFinished(false)
-    , mMainThreadDestroyed(false)
-    , mGraph(nullptr)
-  {
-    MOZ_COUNT_CTOR(MediaStream);
-  }
+  MediaStream(DOMMediaStream* aWrapper);
   virtual ~MediaStream()
   {
     MOZ_COUNT_DTOR(MediaStream);
     NS_ASSERTION(mMainThreadDestroyed, "Should have been destroyed already");
     NS_ASSERTION(mMainThreadListeners.IsEmpty(),
                  "All main thread listeners should have been removed");
   }