Bug 1170958 - Add input stream and track as args to NotifyQueuedTrackChanges. r=roc
☠☠ backed out by 277eb06d67b5 ☠ ☠
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 25 Sep 2015 23:23:17 +0800
changeset 264425 2106eccec79b991466e59a9e5ab9e8ce9bfc63b2
parent 264424 26835118aa4656dae04d8dda48180c9ff25e46f9
child 264426 ad206925c84a82d21db31e13a14267e9952adfb0
push id65623
push userpehrsons@gmail.com
push dateFri, 25 Sep 2015 15:29:17 +0000
treeherdermozilla-inbound@f0f33a8ef14c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1170958
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/media/DOMMediaStream.cpp
dom/media/MediaStreamGraph.h
dom/media/encoder/MediaEncoder.cpp
dom/media/encoder/MediaEncoder.h
dom/media/imagecapture/CaptureTask.cpp
dom/media/imagecapture/CaptureTask.h
dom/media/webspeech/recognition/SpeechStreamListener.cpp
dom/media/webspeech/recognition/SpeechStreamListener.h
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
media/webrtc/signaling/test/FakeMediaStreams.h
media/webrtc/signaling/test/FakeMediaStreamsImpl.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3048,17 +3048,19 @@ public:
       size = mInitialSize;
     }
     nsRefPtr<HTMLMediaElement> deathGrip = mElement;
     mElement->UpdateInitialMediaSize(size);
   }
   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) ||
         aQueuedMedia.GetType() != MediaSegment::VIDEO) {
       return;
     }
     const VideoSegment& video = static_cast<const VideoSegment&>(aQueuedMedia);
     for (VideoSegment::ConstChunkIterator c(video); !c.IsEnded(); c.Next()) {
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -36,18 +36,20 @@ public:
   // Main thread only
   void Forget() { mStream = nullptr; }
   DOMMediaStream* GetStream() { return mStream; }
 
   class TrackChange : public nsRunnable {
   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)
     {
     }
 
     NS_IMETHOD Run()
     {
       NS_ASSERTION(NS_IsMainThread(), "main thread only");
 
       DOMMediaStream* stream = mListener->GetStream();
@@ -77,34 +79,38 @@ public:
       return NS_OK;
     }
 
     StreamTime mEndTime;
     nsRefPtr<StreamListener> mListener;
     TrackID mID;
     uint32_t mEvents;
     MediaSegment::Type mType;
+    nsRefPtr<MediaStream> mInputStream;
+    TrackID mInputTrackID;
   };
 
   /**
    * Notify that changes to one of the stream tracks have been queued.
    * 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).
    * aQueuedMedia can be null if there is no output.
    */
   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<TrackChange> runnable =
         new TrackChange(this, aID, aTrackOffset, aTrackEvents,
-                        aQueuedMedia.GetType());
+                        aQueuedMedia.GetType(), aInputStream, aInputTrackID);
       aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
     }
   }
 
   class TracksCreatedRunnable : public nsRunnable {
   public:
     explicit TracksCreatedRunnable(StreamListener* aListener)
       : mListener(aListener)
--- a/dom/media/MediaStreamGraph.h
+++ b/dom/media/MediaStreamGraph.h
@@ -156,21 +156,26 @@ public:
     TRACK_EVENT_CREATED = 0x01,
     TRACK_EVENT_ENDED = 0x02
   };
   /**
    * Notify that changes to one of the stream tracks have been queued.
    * 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.
    * This is to ensure that tracks added atomically to MediaStreamGraph
    * are also notified of atomically to MediaStreamListeners.
    */
   virtual void NotifyFinishedTrackCreation(MediaStreamGraph* aGraph) {}
 };
--- a/dom/media/encoder/MediaEncoder.cpp
+++ b/dom/media/encoder/MediaEncoder.cpp
@@ -36,17 +36,19 @@ PRLogModuleInfo* gMediaEncoderLog;
 
 namespace mozilla {
 
 void
 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.
   if (mAudioEncoder && aQueuedMedia.GetType() == MediaSegment::AUDIO) {
     mAudioEncoder->NotifyQueuedTrackChanges(aGraph, aID,
                                             aTrackOffset, aTrackEvents,
                                             aQueuedMedia);
 
--- a/dom/media/encoder/MediaEncoder.h
+++ b/dom/media/encoder/MediaEncoder.h
@@ -80,17 +80,19 @@ public :
 
   /**
    * Notified by the control loop of MediaStreamGraph; aQueueMedia is the raw
    * track data in form of MediaSegment.
    */
   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.
    */
   virtual void NotifyEvent(MediaStreamGraph* aGraph,
                            MediaStreamListener::MediaStreamGraphEvent event) override;
 
   /**
--- a/dom/media/imagecapture/CaptureTask.cpp
+++ b/dom/media/imagecapture/CaptureTask.cpp
@@ -81,17 +81,19 @@ CaptureTask::PrincipalChanged(DOMMediaSt
   MOZ_ASSERT(NS_IsMainThread());
   mPrincipalChanged = true;
 }
 
 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;
   }
 
   if (aTrackEvents == MediaStreamListener::TRACK_EVENT_ENDED) {
     PostTrackEndEvent();
     return;
--- a/dom/media/imagecapture/CaptureTask.h
+++ b/dom/media/imagecapture/CaptureTask.h
@@ -30,17 +30,19 @@ class ImageCapture;
 class CaptureTask : public MediaStreamListener,
                     public DOMMediaStream::PrincipalChangeObserver
 {
 public:
   // MediaStreamListener methods.
   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;
 
   // DOMMediaStream::PrincipalChangeObserver method.
   virtual void PrincipalChanged(DOMMediaStream* aMediaStream) override;
 
   // CaptureTask methods.
--- a/dom/media/webspeech/recognition/SpeechStreamListener.cpp
+++ b/dom/media/webspeech/recognition/SpeechStreamListener.cpp
@@ -28,17 +28,19 @@ SpeechStreamListener::~SpeechStreamListe
                   static_cast<DOMEventTargetHelper*>(forgottenRecognition));
 }
 
 void
 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<AudioSegment*>(
     static_cast<const AudioSegment*>(&aQueuedMedia));
 
   AudioSegment::ChunkIterator iterator(*audio);
   while (!iterator.IsEnded()) {
     // Skip over-large chunks so we don't crash!
     if (iterator->GetDuration() > INT_MAX) {
--- a/dom/media/webspeech/recognition/SpeechStreamListener.h
+++ b/dom/media/webspeech/recognition/SpeechStreamListener.h
@@ -22,17 +22,19 @@ class SpeechStreamListener : public Medi
 {
 public:
   explicit SpeechStreamListener(SpeechRecognition* aRecognition);
   ~SpeechStreamListener();
 
   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;
 
 private:
   template<typename SampleFormatType>
   void ConvertAndDispatchAudioChunk(int aDuration, float aVolume, SampleFormatType* aData, TrackRate aTrackRate);
   nsRefPtr<SpeechRecognition> mRecognition;
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -863,17 +863,19 @@ NotifyRealtimeData(MediaStreamGraph* gra
 
   NewData(graph, tid, offset, events, media);
 }
 
 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
   if (!direct_connect_) {
     NewData(graph, tid, offset, events, queued_media);
   }
 }
 
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -477,17 +477,19 @@ public:
       MutexAutoLock lock(mMutex);
       return track_id_external_;
     }
 
     // Implement MediaStreamListener
     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
     virtual void NotifyRealtimeData(MediaStreamGraph* graph, TrackID tid,
                                     StreamTime offset,
                                     uint32_t events,
                                     const MediaSegment& media) override;
 
@@ -624,17 +626,19 @@ class MediaPipelineReceiveAudio : public
         MOZ_CRASH();
       }
     }
 
     // Implement MediaStreamListener
     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:
     RefPtr<MediaSessionConduit> conduit_;
   };
 
   RefPtr<PipelineListener> listener_;
 };
@@ -720,17 +724,19 @@ class MediaPipelineReceiveVideo : public
    public:
     PipelineListener(SourceMediaStream * source, TrackID track_id,
                      bool queue_track);
 
     // Implement MediaStreamListener
     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
     void FrameSizeChange(unsigned int width,
                          unsigned int height,
                          unsigned int number_of_streams) {
       ReentrantMonitorAutoEnter enter(monitor_);
 
--- a/media/webrtc/signaling/test/FakeMediaStreams.h
+++ b/media/webrtc/signaling/test/FakeMediaStreams.h
@@ -69,28 +69,31 @@ class Fake_VideoSink {
 public:
   Fake_VideoSink() {}
   virtual void SegmentReady(mozilla::MediaSegment* aSegment) = 0;
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Fake_VideoSink)
 protected:
   virtual ~Fake_VideoSink() {}
 };
 
+class Fake_MediaStream;
 class Fake_SourceMediaStream;
 
 class Fake_MediaStreamListener
 {
 protected:
   virtual ~Fake_MediaStreamListener() {}
 
 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)
 };
 
 class Fake_MediaStreamDirectListener : public Fake_MediaStreamListener
 {
 protected:
--- a/media/webrtc/signaling/test/FakeMediaStreamsImpl.h
+++ b/media/webrtc/signaling/test/FakeMediaStreamsImpl.h
@@ -111,17 +111,19 @@ void Fake_AudioStreamSource::Periodic() 
   segment.AppendFrames(samples.forget(), channels, AUDIO_BUFFER_SIZE);
 
   for(std::set<Fake_MediaStreamListener *>::iterator it = mListeners.begin();
        it != mListeners.end(); ++it) {
     (*it)->NotifyQueuedTrackChanges(nullptr, // Graph
                                     0, // TrackID
                                     0, // Offset TODO(ekr@rtfm.com) fix
                                     0, // ???
-                                    segment);
+                                    segment,
+                                    nullptr, // Input stream
+                                    -1);     // Input track id
   }
 }
 
 
 // Fake_MediaPeriodic
 NS_IMPL_ISUPPORTS(Fake_MediaPeriodic, nsITimerCallback)
 
 NS_IMETHODIMP