Bug 1309886 - End received tracks when MediaPipelineReceive is detached. r=drno
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 13 Oct 2016 15:50:29 +0200
changeset 347498 227c9d7813e6f24ef6611ac7526d1e770432c6b0
parent 347497 47cf46bd3e3ebd91921def20038d2989d88d4a43
child 347499 4c3a3cf3d6adbce2b39c3e92b0ebee71aa7b43a3
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno
bugs1309886
milestone52.0a1
Bug 1309886 - End received tracks when MediaPipelineReceive is detached. r=drno MozReview-Commit-ID: 86kqjtMhulR
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -1902,16 +1902,21 @@ class GenericReceiveListener : public Me
 
   virtual ~GenericReceiveListener() {}
 
   void AddSelf()
   {
     AddListener(source_, this);
   }
 
+  void EndTrack()
+  {
+    source_->EndTrack(track_id_);
+  }
+
 #ifndef USE_FAKE_MEDIA_STREAMS
   // Must be called on the main thread
   void SetPrincipalHandle_m(const PrincipalHandle& principal_handle)
   {
     class Message : public ControlMessage
     {
     public:
       Message(GenericReceiveListener* listener,
@@ -1937,17 +1942,17 @@ class GenericReceiveListener : public Me
   void SetPrincipalHandle_msg(const PrincipalHandle& principal_handle)
   {
     principal_handle_ = principal_handle;
   }
 #endif // USE_FAKE_MEDIA_STREAMS
 
  protected:
   SourceMediaStream *source_;
-  TrackID track_id_;
+  const TrackID track_id_;
   TrackTicks played_ticks_;
   PrincipalHandle principal_handle_;
 };
 
 MediaPipelineReceive::MediaPipelineReceive(
     const std::string& pc,
     nsCOMPtr<nsIEventTarget> main_thread,
     nsCOMPtr<nsIEventTarget> sts_thread,
@@ -2099,17 +2104,18 @@ MediaPipelineReceiveAudio::MediaPipeline
                        stream, media_stream_track_id, level, conduit,
                        rtp_transport, rtcp_transport, filter),
   listener_(new PipelineListener(stream, numeric_track_id, conduit))
 {}
 
 void MediaPipelineReceiveAudio::DetachMedia()
 {
   ASSERT_ON_THREAD(main_thread_);
-  if (stream_) {
+  if (stream_ && listener_) {
+    listener_->EndTrack();
     stream_->RemoveListener(listener_);
     stream_ = nullptr;
   }
 }
 
 nsresult MediaPipelineReceiveAudio::Init() {
   ASSERT_ON_THREAD(main_thread_);
   MOZ_MTLOG(ML_DEBUG, __FUNCTION__);
@@ -2330,17 +2336,18 @@ void MediaPipelineReceiveVideo::DetachMe
 {
   ASSERT_ON_THREAD(main_thread_);
 
   // stop generating video and thus stop invoking the PipelineRenderer
   // and PipelineListener - the renderer has a raw ptr to the Pipeline to
   // avoid cycles, and the render callbacks are invoked from a different
   // thread so simple null-checks would cause TSAN bugs without locks.
   static_cast<VideoSessionConduit*>(conduit_.get())->DetachRenderer();
-  if (stream_) {
+  if (stream_ && listener_) {
+    listener_->EndTrack();
     stream_->RemoveListener(listener_);
     stream_ = nullptr;
   }
 }
 
 nsresult MediaPipelineReceiveVideo::Init() {
   ASSERT_ON_THREAD(main_thread_);
   MOZ_MTLOG(ML_DEBUG, __FUNCTION__);