Bug 1208371 - Add MediaStreamTrack::Graph(). r=jib
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:23 +0800
changeset 348416 06d9ea133491f1cb07dcef8afbf66c8b1cb4504f
parent 348415 ce9ca4390483f48ca5c561efa6f7335234d613d8
child 348417 e261fd0b3b9cab53ca92098b7f54a63b1864311d
push id14828
push userpehrsons@gmail.com
push dateThu, 07 Apr 2016 12:57:27 +0000
reviewersjib
bugs1208371
milestone48.0a1
Bug 1208371 - Add MediaStreamTrack::Graph(). r=jib MozReview-Commit-ID: 643Jvp98D9z
dom/media/DOMMediaStream.cpp
dom/media/MediaStreamTrack.cpp
dom/media/MediaStreamTrack.h
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -443,21 +443,18 @@ DOMMediaStream::Constructor(const Global
   }
 
   // Streams created from JS cannot have dynamically created tracks.
   MediaStreamTrackSourceGetter* getter = nullptr;
   RefPtr<DOMMediaStream> newStream = new DOMMediaStream(ownerWindow, getter);
 
   for (MediaStreamTrack& track : aTracks) {
     if (!newStream->GetPlaybackStream()) {
-      MOZ_RELEASE_ASSERT(track.GetStream());
-      MOZ_RELEASE_ASSERT(track.GetStream()->GetPlaybackStream());
-      MOZ_RELEASE_ASSERT(track.GetStream()->GetPlaybackStream()->Graph());
-      MediaStreamGraph* graph = track.GetStream()->GetPlaybackStream()->Graph();
-      newStream->InitPlaybackStreamCommon(graph);
+      MOZ_RELEASE_ASSERT(track.Graph());
+      newStream->InitPlaybackStreamCommon(track.Graph());
     }
     newStream->AddTrack(track);
   }
 
   if (!newStream->GetPlaybackStream()) {
     MOZ_ASSERT(aTracks.IsEmpty());
     MediaStreamGraph* graph =
       MediaStreamGraph::GetInstance(MediaStreamGraph::SYSTEM_THREAD_DRIVER,
@@ -523,22 +520,20 @@ DOMMediaStream::AddTrack(MediaStreamTrac
   MOZ_ASSERT(dest);
   if (!dest) {
     return;
   }
 
   LOG(LogLevel::Info, ("DOMMediaStream %p Adding track %p (from stream %p with ID %d)",
                        this, &aTrack, aTrack.GetStream(), aTrack.GetTrackID()));
 
-  if (mPlaybackStream->Graph() !=
-      aTrack.GetStream()->mPlaybackStream->Graph()) {
+  if (mPlaybackStream->Graph() != aTrack.Graph()) {
     NS_ASSERTION(false, "Cannot combine tracks from different MediaStreamGraphs");
     LOG(LogLevel::Error, ("DOMMediaStream %p Own MSG %p != aTrack's MSG %p",
-                         this, mPlaybackStream->Graph(),
-                         aTrack.GetStream()->mPlaybackStream->Graph()));
+                         this, mPlaybackStream->Graph(), aTrack.Graph()));
 
     nsAutoString trackId;
     aTrack.GetId(trackId);
     const char16_t* params[] = { trackId.get() };
     nsCOMPtr<nsPIDOMWindowInner> pWindow = GetParentObject();
     nsIDocument* document = pWindow ? pWindow->GetExtantDoc() : nullptr;
     nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
                                     NS_LITERAL_CSTRING("Media"),
--- a/dom/media/MediaStreamTrack.cpp
+++ b/dom/media/MediaStreamTrack.cpp
@@ -133,16 +133,22 @@ MediaStreamTrack::ApplyConstraints(const
 
     LOG(LogLevel::Info, ("MediaStreamTrack %p ApplyConstraints() with "
                          "constraints %s", this, NS_ConvertUTF16toUTF8(str).get()));
   }
 
   return GetStream()->ApplyConstraintsToTrack(mTrackID, aConstraints, aRv);
 }
 
+MediaStreamGraph*
+MediaStreamTrack::Graph()
+{
+  return GetOwnedStream()->Graph();
+}
+
 DOMMediaStream*
 MediaStreamTrack::GetInputDOMStream()
 {
   MediaStreamTrack* originalTrack =
     mOriginalTrack ? mOriginalTrack.get() : this;
   MOZ_RELEASE_ASSERT(originalTrack->GetStream());
   return originalTrack->GetStream();
 }
--- a/dom/media/MediaStreamTrack.h
+++ b/dom/media/MediaStreamTrack.h
@@ -12,16 +12,17 @@
 #include "StreamBuffer.h"
 #include "MediaTrackConstraints.h"
 
 namespace mozilla {
 
 class DOMMediaStream;
 class MediaEnginePhotoCallback;
 class MediaStream;
+class MediaStreamGraph;
 class ProcessedMediaStream;
 
 namespace dom {
 
 class AudioStreamTrack;
 class VideoStreamTrack;
 
 /**
@@ -178,16 +179,18 @@ public:
   void Stop();
   already_AddRefed<Promise>
   ApplyConstraints(const dom::MediaTrackConstraints& aConstraints, ErrorResult &aRv);
 
   bool Ended() const { return mEnded; }
   // Notifications from the MediaStreamGraph
   void NotifyEnded() { mEnded = true; }
 
+  MediaStreamGraph* Graph();
+
   MediaStreamTrackSource& GetSource() const
   {
     MOZ_RELEASE_ASSERT(mSource, "The track source is only removed on destruction");
     return *mSource;
   }
 
   // Webrtc allows the remote side to name tracks whatever it wants, and we
   // need to surface this to content.