From 71c232e8df105dd00c006d96ea227329337c66af Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Wed, 19 Aug 2020 22:18:37 +0000 Subject: [PATCH] Bug 1652884 - Make MediaPipelineTransmit listen for track enabled state changes from the graph. r=jib Previously it listened for them on main thread, as notified by the MediaStreamTrack it was transmitting directly. With this patch it listens for them through the TrackListener in the graph, and will get notified when any track prior to the MediaStreamTrack's main track in the graph changes enabled state as well. Depends on D86926. Differential Revision: https://phabricator.services.mozilla.com/D86931 --- .../src/mediapipeline/MediaPipeline.cpp | 51 +++---------------- .../src/mediapipeline/MediaPipeline.h | 4 -- 2 files changed, 6 insertions(+), 49 deletions(-) diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp index 03a631461afc..395005b6eafa 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -724,11 +724,11 @@ class MediaPipelineTransmit::PipelineListener ->SendVideoFrame(aVideoFrame); } - void SetTrackEnabled(MediaStreamTrack* aTrack, bool aEnabled); - // Implement MediaTrackListener void NotifyQueuedChanges(MediaTrackGraph* aGraph, TrackTime aOffset, const MediaSegment& aQueuedMedia) override; + void NotifyEnabledStateChanged(MediaTrackGraph* aGraph, + bool aEnabled) override; // Implement DirectMediaTrackListener void NotifyRealtimeTrackData(MediaTrackGraph* aGraph, TrackTime aOffset, @@ -753,29 +753,6 @@ class MediaPipelineTransmit::PipelineListener bool mDirectConnect; }; -// MediaStreamTrackConsumer inherits from SupportsWeakPtr, which is -// main-thread-only. -class MediaPipelineTransmit::PipelineListenerTrackConsumer - : public MediaStreamTrackConsumer { - virtual ~PipelineListenerTrackConsumer() { MOZ_ASSERT(NS_IsMainThread()); } - - const RefPtr mListener; - - public: - NS_INLINE_DECL_REFCOUNTING(PipelineListenerTrackConsumer) - - explicit PipelineListenerTrackConsumer(RefPtr aListener) - : mListener(std::move(aListener)) { - MOZ_ASSERT(NS_IsMainThread()); - } - - // Implement MediaStreamTrackConsumer - void NotifyEnabledChanged(MediaStreamTrack* aTrack, bool aEnabled) override { - MOZ_ASSERT(NS_IsMainThread()); - mListener->SetTrackEnabled(aTrack, aEnabled); - } -}; - // Implements VideoConverterListener for MediaPipeline. // // We pass converted frames on to MediaPipelineTransmit::PipelineListener @@ -822,10 +799,6 @@ MediaPipelineTransmit::MediaPipelineTransmit( std::move(aConduit)), mIsVideo(aIsVideo), mListener(new PipelineListener(mConduit)), - mTrackConsumer( - MakeAndAddRef>( - "MediaPipelineTransmit::mTrackConsumer", - MakeAndAddRef(mListener))), mFeeder(aIsVideo ? MakeAndAddRef(mListener) : nullptr), // For video we send frames to an // async VideoFrameConverter that @@ -935,10 +908,10 @@ void MediaPipelineTransmit::Start() { mSendTrack->Resume(); + mSendTrack->AddListener(mListener); if (mSendTrack->mType == MediaSegment::VIDEO) { mSendTrack->AddDirectListener(mListener); } - mSendTrack->AddListener(mListener); } bool MediaPipelineTransmit::IsVideo() const { return mIsVideo; } @@ -978,10 +951,7 @@ void MediaPipelineTransmit::UpdateSinkIdentity_m( void MediaPipelineTransmit::DetachMedia() { ASSERT_ON_THREAD(mMainThread); MOZ_ASSERT(!mTransmitting); - if (mDomTrack) { - mDomTrack->RemoveConsumer(mTrackConsumer); - mDomTrack = nullptr; - } + mDomTrack = nullptr; if (mSendPort) { mSendPort->Destroy(); mSendPort = nullptr; @@ -1036,9 +1006,6 @@ nsresult MediaPipelineTransmit::SetTrack(RefPtr aDomTrack) { (mConduit->type() == MediaSessionConduit::AUDIO ? "audio" : "video"))); } - if (mDomTrack) { - mDomTrack->RemoveConsumer(mTrackConsumer); - } if (mSendPort) { mSendPort->Destroy(); mSendPort = nullptr; @@ -1076,10 +1043,6 @@ nsresult MediaPipelineTransmit::SetTrack(RefPtr aDomTrack) { } mSendPort = mSendTrack->AllocateInputPort(mDomTrack->GetTrack()); } - mDomTrack->AddConsumer(mTrackConsumer); - if (mConverter) { - mConverter->SetTrackEnabled(mDomTrack->Enabled()); - } } return NS_OK; @@ -1210,13 +1173,11 @@ void MediaPipelineTransmit::PipelineListener::NotifyQueuedChanges( NewData(aQueuedMedia, rate); } -void MediaPipelineTransmit::PipelineListener::SetTrackEnabled( - MediaStreamTrack* aTrack, bool aEnabled) { - MOZ_ASSERT(NS_IsMainThread()); +void MediaPipelineTransmit::PipelineListener::NotifyEnabledStateChanged( + MediaTrackGraph* aGraph, bool aEnabled) { if (mConduit->type() != MediaSessionConduit::VIDEO) { return; } - MOZ_ASSERT(mConverter); mConverter->SetTrackEnabled(aEnabled); } diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h index b6d687125f8b..484a4431cec7 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h @@ -310,7 +310,6 @@ class MediaPipelineTransmit : public MediaPipeline { // Separate classes to allow ref counting class PipelineListener; - class PipelineListenerTrackConsumer; class VideoFrameFeeder; protected: @@ -323,9 +322,6 @@ class MediaPipelineTransmit : public MediaPipeline { const bool mIsVideo; const RefPtr mListener; - // Listens for changes in enabled state on the attached MediaStreamTrack, and - // notifies mListener. - const nsMainThreadPtrHandle mTrackConsumer; const RefPtr mFeeder; RefPtr mAudioProcessing; RefPtr mConverter;