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
This commit is contained in:
Andreas Pehrson 2020-08-19 22:18:37 +00:00
parent 4ce501e4b4
commit 71c232e8df
2 changed files with 6 additions and 49 deletions

View File

@ -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<PipelineListener> mListener;
public:
NS_INLINE_DECL_REFCOUNTING(PipelineListenerTrackConsumer)
explicit PipelineListenerTrackConsumer(RefPtr<PipelineListener> 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<nsMainThreadPtrHolder<PipelineListenerTrackConsumer>>(
"MediaPipelineTransmit::mTrackConsumer",
MakeAndAddRef<PipelineListenerTrackConsumer>(mListener))),
mFeeder(aIsVideo ? MakeAndAddRef<VideoFrameFeeder>(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<MediaStreamTrack> 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<MediaStreamTrack> 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);
}

View File

@ -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<PipelineListener> mListener;
// Listens for changes in enabled state on the attached MediaStreamTrack, and
// notifies mListener.
const nsMainThreadPtrHandle<PipelineListenerTrackConsumer> mTrackConsumer;
const RefPtr<VideoFrameFeeder> mFeeder;
RefPtr<AudioProxyThread> mAudioProcessing;
RefPtr<VideoFrameConverter> mConverter;