diff --git a/content/media/MediaStreamGraph.cpp b/content/media/MediaStreamGraph.cpp index 16c9ec6fd268..0e6d65e422b3 100644 --- a/content/media/MediaStreamGraph.cpp +++ b/content/media/MediaStreamGraph.cpp @@ -2471,6 +2471,32 @@ SourceMediaStream::NotifyDirectConsumers(TrackData *aTrack, } } +// These handle notifying all the listeners of an event +void +SourceMediaStream::NotifyListenersEventImpl(MediaStreamListener::MediaStreamGraphEvent aEvent) +{ + for (uint32_t j = 0; j < mListeners.Length(); ++j) { + MediaStreamListener* l = mListeners[j]; + l->NotifyEvent(GraphImpl(), aEvent); + } +} + +void +SourceMediaStream::NotifyListenersEvent(MediaStreamListener::MediaStreamGraphEvent aNewEvent) +{ + class Message : public ControlMessage { + public: + Message(SourceMediaStream* aStream, MediaStreamListener::MediaStreamGraphEvent aEvent) : + ControlMessage(aStream), mEvent(aEvent) {} + virtual void Run() + { + mStream->AsSourceStream()->NotifyListenersEventImpl(mEvent); + } + MediaStreamListener::MediaStreamGraphEvent mEvent; + }; + GraphImpl()->AppendMessage(new Message(this, aNewEvent)); +} + void SourceMediaStream::AddDirectListener(MediaStreamDirectListener* aListener) { @@ -2482,10 +2508,8 @@ SourceMediaStream::AddDirectListener(MediaStreamDirectListener* aListener) } if (wasEmpty) { - for (uint32_t j = 0; j < mListeners.Length(); ++j) { - MediaStreamListener* l = mListeners[j]; - l->NotifyEvent(GraphImpl(), MediaStreamListener::EVENT_HAS_DIRECT_LISTENERS); - } + // Async + NotifyListenersEvent(MediaStreamListener::EVENT_HAS_DIRECT_LISTENERS); } } @@ -2500,10 +2524,8 @@ SourceMediaStream::RemoveDirectListener(MediaStreamDirectListener* aListener) } if (isEmpty) { - for (uint32_t j = 0; j < mListeners.Length(); ++j) { - MediaStreamListener* l = mListeners[j]; - l->NotifyEvent(GraphImpl(), MediaStreamListener::EVENT_HAS_NO_DIRECT_LISTENERS); - } + // Async + NotifyListenersEvent(MediaStreamListener::EVENT_HAS_NO_DIRECT_LISTENERS); } } diff --git a/content/media/MediaStreamGraph.h b/content/media/MediaStreamGraph.h index 15f74f9cf8de..6d02d7bf8730 100644 --- a/content/media/MediaStreamGraph.h +++ b/content/media/MediaStreamGraph.h @@ -716,6 +716,13 @@ public: */ void SetPullEnabled(bool aEnabled); + /** + * These add/remove DirectListeners, which allow bypassing the graph and any + * synchronization delays for e.g. PeerConnection, which wants the data ASAP + * and lets the far-end handle sync and playout timing. + */ + void NotifyListenersEventImpl(MediaStreamListener::MediaStreamGraphEvent aEvent); + void NotifyListenersEvent(MediaStreamListener::MediaStreamGraphEvent aEvent); void AddDirectListener(MediaStreamDirectListener* aListener); void RemoveDirectListener(MediaStreamDirectListener* aListener);