From aa2fc050876aae305850aeedbd2c3e92d6cf197a Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Wed, 30 Sep 2015 09:31:53 +0800 Subject: [PATCH] Bug 1170958 - Add input stream and track as args to NotifyQueuedTrackChanges. r=roc This allows for tracking the input track of an added track (for ProcessedMediaStream tracks; SourceMediaStream tracks don't have input tracks) directly in the NotifyQueuedTrackChanges handler, which will be necessary for locking MediaInputPorts to specific tracks. --- dom/html/HTMLMediaElement.cpp | 4 +++- dom/media/DOMMediaStream.cpp | 12 +++++++++--- dom/media/MediaStreamGraph.h | 7 ++++++- dom/media/encoder/MediaEncoder.cpp | 4 +++- dom/media/encoder/MediaEncoder.h | 4 +++- dom/media/imagecapture/CaptureTask.cpp | 4 +++- dom/media/imagecapture/CaptureTask.h | 4 +++- .../webspeech/recognition/SpeechStreamListener.cpp | 4 +++- .../webspeech/recognition/SpeechStreamListener.h | 4 +++- .../signaling/src/mediapipeline/MediaPipeline.cpp | 4 +++- .../signaling/src/mediapipeline/MediaPipeline.h | 12 +++++++++--- media/webrtc/signaling/test/FakeMediaStreams.h | 5 ++++- media/webrtc/signaling/test/FakeMediaStreamsImpl.h | 4 +++- 13 files changed, 55 insertions(+), 17 deletions(-) diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index afa8a69badf..549098494e8 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -3053,7 +3053,9 @@ public: virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID, StreamTime aTrackOffset, uint32_t aTrackEvents, - const MediaSegment& aQueuedMedia) override + const MediaSegment& aQueuedMedia, + MediaStream* aInputStream, + TrackID aInputTrackID) override { MutexAutoLock lock(mMutex); if (mInitialSize != gfx::IntSize(0,0) || diff --git a/dom/media/DOMMediaStream.cpp b/dom/media/DOMMediaStream.cpp index cafe5f177c2..c1435435fd9 100644 --- a/dom/media/DOMMediaStream.cpp +++ b/dom/media/DOMMediaStream.cpp @@ -41,8 +41,10 @@ public: public: TrackChange(StreamListener* aListener, TrackID aID, StreamTime aTrackOffset, - uint32_t aEvents, MediaSegment::Type aType) + uint32_t aEvents, MediaSegment::Type aType, + MediaStream* aInputStream, TrackID aInputTrackID) : mListener(aListener), mID(aID), mEvents(aEvents), mType(aType) + , mInputStream(aInputStream), mInputTrackID(aInputTrackID) { } @@ -82,6 +84,8 @@ public: TrackID mID; uint32_t mEvents; MediaSegment::Type mType; + nsRefPtr mInputStream; + TrackID mInputTrackID; }; /** @@ -94,12 +98,14 @@ public: virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID, StreamTime aTrackOffset, uint32_t aTrackEvents, - const MediaSegment& aQueuedMedia) override + const MediaSegment& aQueuedMedia, + MediaStream* aInputStream, + TrackID aInputTrackID) override { if (aTrackEvents & (TRACK_EVENT_CREATED | TRACK_EVENT_ENDED)) { nsRefPtr runnable = new TrackChange(this, aID, aTrackOffset, aTrackEvents, - aQueuedMedia.GetType()); + aQueuedMedia.GetType(), aInputStream, aInputTrackID); aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget()); } } diff --git a/dom/media/MediaStreamGraph.h b/dom/media/MediaStreamGraph.h index 2dc01c49ab9..eae6320106e 100644 --- a/dom/media/MediaStreamGraph.h +++ b/dom/media/MediaStreamGraph.h @@ -164,11 +164,16 @@ public: * aTrackEvents can be any combination of TRACK_EVENT_CREATED and * TRACK_EVENT_ENDED. aQueuedMedia is the data being added to the track * at aTrackOffset (relative to the start of the stream). + * aInputStream and aInputTrackID will be set if the changes originated + * from an input stream's track. In practice they will only be used for + * ProcessedMediaStreams. */ virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID, StreamTime aTrackOffset, uint32_t aTrackEvents, - const MediaSegment& aQueuedMedia) {} + const MediaSegment& aQueuedMedia, + MediaStream* aInputStream = nullptr, + TrackID aInputTrackID = TRACK_INVALID) {} /** * Notify that all new tracks this iteration have been created. diff --git a/dom/media/encoder/MediaEncoder.cpp b/dom/media/encoder/MediaEncoder.cpp index 0c734f4f046..285468d475b 100644 --- a/dom/media/encoder/MediaEncoder.cpp +++ b/dom/media/encoder/MediaEncoder.cpp @@ -41,7 +41,9 @@ MediaEncoder::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID, StreamTime aTrackOffset, uint32_t aTrackEvents, - const MediaSegment& aQueuedMedia) + const MediaSegment& aQueuedMedia, + MediaStream* aInputStream, + TrackID aInputTrackID) { // Process the incoming raw track data from MediaStreamGraph, called on the // thread of MediaStreamGraph. diff --git a/dom/media/encoder/MediaEncoder.h b/dom/media/encoder/MediaEncoder.h index 94a3d6dc621..2922a3ad865 100644 --- a/dom/media/encoder/MediaEncoder.h +++ b/dom/media/encoder/MediaEncoder.h @@ -85,7 +85,9 @@ public : virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID, StreamTime aTrackOffset, uint32_t aTrackEvents, - const MediaSegment& aQueuedMedia) override; + const MediaSegment& aQueuedMedia, + MediaStream* aInputStream, + TrackID aInputTrackID) override; /** * Notified the stream is being removed. diff --git a/dom/media/imagecapture/CaptureTask.cpp b/dom/media/imagecapture/CaptureTask.cpp index 7acfca9c61b..118e8a3ec49 100644 --- a/dom/media/imagecapture/CaptureTask.cpp +++ b/dom/media/imagecapture/CaptureTask.cpp @@ -86,7 +86,9 @@ void CaptureTask::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID, StreamTime aTrackOffset, uint32_t aTrackEvents, - const MediaSegment& aQueuedMedia) + const MediaSegment& aQueuedMedia, + MediaStream* aInputStream, + TrackID aInputTrackID) { if (mImageGrabbedOrTrackEnd) { return; diff --git a/dom/media/imagecapture/CaptureTask.h b/dom/media/imagecapture/CaptureTask.h index 4920d8ee0f6..6128671422b 100644 --- a/dom/media/imagecapture/CaptureTask.h +++ b/dom/media/imagecapture/CaptureTask.h @@ -35,7 +35,9 @@ public: virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID, StreamTime aTrackOffset, uint32_t aTrackEvents, - const MediaSegment& aQueuedMedia) override; + const MediaSegment& aQueuedMedia, + MediaStream* aInputStream, + TrackID aInputTrackID) override; virtual void NotifyEvent(MediaStreamGraph* aGraph, MediaStreamGraphEvent aEvent) override; diff --git a/dom/media/webspeech/recognition/SpeechStreamListener.cpp b/dom/media/webspeech/recognition/SpeechStreamListener.cpp index 7120c5b7152..316c6f1b81e 100644 --- a/dom/media/webspeech/recognition/SpeechStreamListener.cpp +++ b/dom/media/webspeech/recognition/SpeechStreamListener.cpp @@ -33,7 +33,9 @@ SpeechStreamListener::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID, StreamTime aTrackOffset, uint32_t aTrackEvents, - const MediaSegment& aQueuedMedia) + const MediaSegment& aQueuedMedia, + MediaStream* aInputStream, + TrackID aInputTrackID) { AudioSegment* audio = const_cast( static_cast(&aQueuedMedia)); diff --git a/dom/media/webspeech/recognition/SpeechStreamListener.h b/dom/media/webspeech/recognition/SpeechStreamListener.h index 101c5eef910..83565531d32 100644 --- a/dom/media/webspeech/recognition/SpeechStreamListener.h +++ b/dom/media/webspeech/recognition/SpeechStreamListener.h @@ -27,7 +27,9 @@ public: virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID, StreamTime aTrackOffset, uint32_t aTrackEvents, - const MediaSegment& aQueuedMedia) override; + const MediaSegment& aQueuedMedia, + MediaStream* aInputStream, + TrackID aInputTrackID) override; virtual void NotifyEvent(MediaStreamGraph* aGraph, MediaStreamListener::MediaStreamGraphEvent event) override; diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp index 4cd5df0be83..ae0a3dba62c 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -868,7 +868,9 @@ void MediaPipelineTransmit::PipelineListener:: NotifyQueuedTrackChanges(MediaStreamGraph* graph, TrackID tid, StreamTime offset, uint32_t events, - const MediaSegment& queued_media) { + const MediaSegment& queued_media, + MediaStream* aInputStream, + TrackID aInputTrackID) { MOZ_MTLOG(ML_DEBUG, "MediaPipeline::NotifyQueuedTrackChanges()"); // ignore non-direct data if we're also getting direct data diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h index 1718ae7a2c9..90ba1b6690c 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h @@ -482,7 +482,9 @@ public: virtual void NotifyQueuedTrackChanges(MediaStreamGraph* graph, TrackID tid, StreamTime offset, uint32_t events, - const MediaSegment& queued_media) override; + const MediaSegment& queued_media, + MediaStream* input_stream, + TrackID input_tid) override; virtual void NotifyPull(MediaStreamGraph* aGraph, StreamTime aDesiredTime) override {} // Implement MediaStreamDirectListener @@ -629,7 +631,9 @@ class MediaPipelineReceiveAudio : public MediaPipelineReceive { virtual void NotifyQueuedTrackChanges(MediaStreamGraph* graph, TrackID tid, StreamTime offset, uint32_t events, - const MediaSegment& queued_media) override {} + const MediaSegment& queued_media, + MediaStream* input_stream, + TrackID input_tid) override {} virtual void NotifyPull(MediaStreamGraph* graph, StreamTime desired_time) override; private: @@ -725,7 +729,9 @@ class MediaPipelineReceiveVideo : public MediaPipelineReceive { virtual void NotifyQueuedTrackChanges(MediaStreamGraph* graph, TrackID tid, StreamTime offset, uint32_t events, - const MediaSegment& queued_media) override {} + const MediaSegment& queued_media, + MediaStream* input_stream, + TrackID input_tid) override {} virtual void NotifyPull(MediaStreamGraph* graph, StreamTime desired_time) override; // Accessors for external writes from the renderer diff --git a/media/webrtc/signaling/test/FakeMediaStreams.h b/media/webrtc/signaling/test/FakeMediaStreams.h index 33e5f7f24ca..4eec4188623 100644 --- a/media/webrtc/signaling/test/FakeMediaStreams.h +++ b/media/webrtc/signaling/test/FakeMediaStreams.h @@ -74,6 +74,7 @@ protected: virtual ~Fake_VideoSink() {} }; +class Fake_MediaStream; class Fake_SourceMediaStream; class Fake_MediaStreamListener @@ -85,7 +86,9 @@ public: virtual void NotifyQueuedTrackChanges(mozilla::MediaStreamGraph* aGraph, mozilla::TrackID aID, mozilla::StreamTime aTrackOffset, uint32_t aTrackEvents, - const mozilla::MediaSegment& aQueuedMedia) = 0; + const mozilla::MediaSegment& aQueuedMedia, + Fake_MediaStream* aInputStream, + mozilla::TrackID aInputTrackID) = 0; virtual void NotifyPull(mozilla::MediaStreamGraph* aGraph, mozilla::StreamTime aDesiredTime) = 0; NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Fake_MediaStreamListener) diff --git a/media/webrtc/signaling/test/FakeMediaStreamsImpl.h b/media/webrtc/signaling/test/FakeMediaStreamsImpl.h index ed288750420..2f1d2ac5534 100644 --- a/media/webrtc/signaling/test/FakeMediaStreamsImpl.h +++ b/media/webrtc/signaling/test/FakeMediaStreamsImpl.h @@ -116,7 +116,9 @@ void Fake_AudioStreamSource::Periodic() { 0, // TrackID 0, // Offset TODO(ekr@rtfm.com) fix 0, // ??? - segment); + segment, + nullptr, // Input stream + -1); // Input track id } }