Bug 1319445 - Switch to Add/RemoveVideoOutput for MediaPipelineTransmit with video. r=jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 10 Jan 2017 19:47:35 +0100
changeset 329102 0faa85ca0fcfde6982476917b2dd60ea5bec13e9
parent 329101 e7e9bc8280d2b96d10f844af4f30f566d0a7a560
child 329103 2b178635281a078716a54469a1824cfce7aa15e2
push id31198
push userkwierso@gmail.com
push dateThu, 12 Jan 2017 23:39:49 +0000
treeherdermozilla-central@721c28b39396 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1319445
milestone53.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 1319445 - Switch to Add/RemoveVideoOutput for MediaPipelineTransmit with video. r=jesup For audio we want to switch between direct/non-direct but video should always be direct. MozReview-Commit-ID: EX3dcXajvo9
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
media/webrtc/signaling/test/FakeMediaStreams.h
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -1463,24 +1463,30 @@ void MediaPipelineTransmit::AttachToTrac
   // With full duplex we don't risk having audio come in late to the MSG
   // so we won't need a direct listener.
   const bool enableDirectListener =
     !Preferences::GetBool("media.navigator.audio.full_duplex", false);
 #else
   const bool enableDirectListener = true;
 #endif
 
-  if (enableDirectListener) {
-    // Register the Listener directly with the source if we can.
-    // We also register it as a non-direct listener so we fall back to that
-    // if installing the direct listener fails. As a direct listener we get access
-    // to direct unqueued (and not resampled) data.
-    domtrack_->AddDirectListener(listener_);
+  if (domtrack_->AsAudioStreamTrack()) {
+    if (enableDirectListener) {
+      // Register the Listener directly with the source if we can.
+      // We also register it as a non-direct listener so we fall back to that
+      // if installing the direct listener fails. As a direct listener we get access
+      // to direct unqueued (and not resampled) data.
+      domtrack_->AddDirectListener(listener_);
+    }
+    domtrack_->AddListener(listener_);
+  } else if (VideoStreamTrack* video = domtrack_->AsVideoStreamTrack()) {
+    video->AddVideoOutput(listener_);
+  } else {
+    MOZ_ASSERT(false, "Unknown track type");
   }
-  domtrack_->AddListener(listener_);
 
 #ifndef MOZILLA_INTERNAL_API
   // this enables the unit tests that can't fiddle with principals and the like
   listener_->SetEnabled(true);
 #endif
 }
 
 bool
@@ -1518,18 +1524,24 @@ void MediaPipelineTransmit::UpdateSinkId
 }
 #endif
 
 void
 MediaPipelineTransmit::DetachMedia()
 {
   ASSERT_ON_THREAD(main_thread_);
   if (domtrack_) {
-    domtrack_->RemoveDirectListener(listener_);
-    domtrack_->RemoveListener(listener_);
+    if (domtrack_->AsAudioStreamTrack()) {
+      domtrack_->RemoveDirectListener(listener_);
+      domtrack_->RemoveListener(listener_);
+    } else if (VideoStreamTrack* video = domtrack_->AsVideoStreamTrack()) {
+      video->RemoveVideoOutput(listener_);
+    } else {
+      MOZ_ASSERT(false, "Unknown track type");
+    }
     domtrack_ = nullptr;
   }
   // Let the listener be destroyed with the pipeline (or later).
 }
 
 nsresult MediaPipelineTransmit::TransportReady_s(TransportInfo &info) {
   ASSERT_ON_THREAD(sts_thread_);
   // Call base ready function.
--- a/media/webrtc/signaling/test/FakeMediaStreams.h
+++ b/media/webrtc/signaling/test/FakeMediaStreams.h
@@ -403,43 +403,55 @@ public:
     std::ostringstream os;
     os << counter++;
     mID = os.str();
   }
 
   std::string GetId() const { return mID; }
   void AssignId(const std::string& id) { mID = id; }
   mozilla::MediaStreamGraphImpl* GraphImpl() { return nullptr; }
+  Fake_MediaStreamTrack* AsVideoStreamTrack()
+  {
+    return mIsVideo ? this : nullptr;
+  }
+  Fake_MediaStreamTrack* AsAudioStreamTrack()
+  {
+    return mIsVideo ? nullptr : this;
+  }
   const Fake_MediaStreamTrack* AsVideoStreamTrack() const
   {
-    return mIsVideo? this : nullptr;
+    return mIsVideo ? this : nullptr;
   }
   const Fake_MediaStreamTrack* AsAudioStreamTrack() const
   {
-    return mIsVideo? nullptr : this;
+    return mIsVideo ? nullptr : this;
   }
   uint32_t typeSize () const
   {
     return sizeof(Fake_MediaStreamTrack);
   }
   const char* typeName () const
   {
     return "Fake_MediaStreamTrack";
   }
   void AddListener(Fake_MediaStreamTrackListener *aListener);
   void RemoveListener(Fake_MediaStreamTrackListener *aListener);
   void AddDirectListener(Fake_DirectMediaStreamTrackListener *aListener)
   {
-    AddListener(aListener);
     aListener->NotifyDirectListenerInstalled(
       Fake_DirectMediaStreamTrackListener::InstallationResult::STREAM_NOT_SUPPORTED);
   }
-  void RemoveDirectListener(Fake_DirectMediaStreamTrackListener *aListener)
+  void RemoveDirectListener(Fake_DirectMediaStreamTrackListener *aListener) {}
+  void AddVideoOutput(Fake_MediaStreamVideoSink *aOutput)
   {
-    RemoveListener(aListener);
+    AddDirectListener(aOutput);
+  }
+  void RemoveVideoOutput(Fake_MediaStreamVideoSink *aOutput)
+  {
+    RemoveDirectListener(aOutput);
   }
 
   class PrincipalChangeObserver
   {
   public:
     virtual void PrincipalChanged(Fake_MediaStreamTrack* aMediaStreamTrack) = 0;
   };
   void AddPrincipalChangeObserver(void* ignoredObserver) {}
@@ -644,12 +656,13 @@ typedef Fake_MediaStreamTrackListener Me
 typedef Fake_DirectMediaStreamTrackListener DirectMediaStreamTrackListener;
 typedef Fake_DOMMediaStream DOMMediaStream;
 typedef Fake_DOMMediaStream DOMLocalMediaStream;
 typedef Fake_MediaStreamVideoSink MediaStreamVideoSink;
 
 namespace dom {
 typedef Fake_MediaStreamTrack MediaStreamTrack;
 typedef Fake_MediaStreamTrackSource MediaStreamTrackSource;
+typedef Fake_MediaStreamTrack VideoStreamTrack;
 }
 }
 
 #endif