diff --git a/dom/media/MediaStreamGraph.cpp b/dom/media/MediaStreamGraph.cpp index b0d0de1e5bcc..47034d303d31 100644 --- a/dom/media/MediaStreamGraph.cpp +++ b/dom/media/MediaStreamGraph.cpp @@ -23,6 +23,7 @@ #include "AudioNodeStream.h" #include "AudioNodeExternalInputStream.h" #include "MediaStreamListener.h" +#include "MediaStreamVideoSink.h" #include "mozilla/dom/AudioContextBinding.h" #include "mozilla/media/MediaUtils.h" #include @@ -2287,6 +2288,8 @@ MediaStream::AddVideoOutputImpl(already_AddRefed aSink, TrackBound* l = mVideoOutputs.AppendElement(); l->mListener = sink; l->mTrackID = aID; + + AddDirectTrackListenerImpl(sink.forget(), aID); } void @@ -2307,6 +2310,8 @@ MediaStream::RemoveVideoOutputImpl(MediaStreamVideoSink* aSink, mVideoOutputs.RemoveElementAt(i); } } + + RemoveDirectTrackListenerImpl(aSink, aID); } void @@ -2969,6 +2974,15 @@ SourceMediaStream::AddDirectTrackListenerImpl(already_AddRefedmData->GetType() == MediaSegment::VIDEO; } if (found && (isAudio || isVideo)) { + for (auto entry : mDirectTrackListeners) { + if (entry.mListener == listener && + (entry.mTrackID == TRACK_ANY || entry.mTrackID == aTrackID)) { + listener->NotifyDirectListenerInstalled( + DirectMediaStreamTrackListener::InstallationResult::ALREADY_EXISTS); + return; + } + } + TrackBound* sourceListener = mDirectTrackListeners.AppendElement(); sourceListener->mListener = listener; diff --git a/dom/media/MediaStreamListener.h b/dom/media/MediaStreamListener.h index 2036fa9be3da..9e6f9c6094f5 100644 --- a/dom/media/MediaStreamListener.h +++ b/dom/media/MediaStreamListener.h @@ -14,6 +14,7 @@ namespace mozilla { class AudioSegment; class MediaStream; class MediaStreamGraph; +class MediaStreamVideoSink; class VideoSegment; enum MediaStreamGraphEvent : uint32_t { @@ -245,6 +246,9 @@ public: * STREAM_NOT_SUPPORTED * While looking for the data source of this track, we found a MediaStream * that is not a SourceMediaStream or a TrackUnionStream. + * ALREADY_EXIST + * This DirectMediaStreamTrackListener already exists in the + * SourceMediaStream. * SUCCESS * Installation was successful and this listener will start receiving * NotifyRealtimeData on the next AppendToTrack(). @@ -253,11 +257,14 @@ public: TRACK_NOT_FOUND_AT_SOURCE, TRACK_TYPE_NOT_SUPPORTED, STREAM_NOT_SUPPORTED, + ALREADY_EXISTS, SUCCESS }; virtual void NotifyDirectListenerInstalled(InstallationResult aResult) {} virtual void NotifyDirectListenerUninstalled() {} + virtual MediaStreamVideoSink* AsMediaStreamVideoSink() { return nullptr; } + protected: virtual ~DirectMediaStreamTrackListener() {} diff --git a/dom/media/MediaStreamVideoSink.h b/dom/media/MediaStreamVideoSink.h index 344f99de7b13..0a4fd9b534c8 100644 --- a/dom/media/MediaStreamVideoSink.h +++ b/dom/media/MediaStreamVideoSink.h @@ -33,6 +33,8 @@ public: virtual VideoFrameContainer* AsVideoFrameContainer() { return nullptr; } virtual void Invalidate() {} + virtual MediaStreamVideoSink* AsMediaStreamVideoSink() override { return this; } + protected: virtual ~MediaStreamVideoSink() {}; };