Bug 1423241 - Implement NotifyPull for MediaStreamTrackListener. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Fri, 23 Nov 2018 15:00:14 +0000
changeset 447820 f7fc271746a2e216d8a6dfbb97d256bf0e156f0b
parent 447819 acd70715684a851db640fae307c111cc6c6b1417
child 447821 12f6bb0888a2c9359758be3f62e06377c0ad1333
push id35090
push userbtara@mozilla.com
push dateFri, 23 Nov 2018 21:37:23 +0000
treeherdermozilla-central@2317749c5abf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1423241
milestone65.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 1423241 - Implement NotifyPull for MediaStreamTrackListener. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D12267
dom/media/MediaStreamGraph.cpp
dom/media/MediaStreamGraph.h
dom/media/MediaStreamListener.h
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -2624,16 +2624,31 @@ bool SourceMediaStream::PullNewData(Stre
   }
   for (uint32_t j = 0; j < mListeners.Length(); ++j) {
     MediaStreamListener* l = mListeners[j];
     {
       MutexAutoUnlock unlock(mMutex);
       l->NotifyPull(GraphImpl(), t);
     }
   }
+  for (const TrackData& track : mUpdateTracks) {
+    if (track.mCommands & TrackEventCommand::TRACK_EVENT_ENDED) {
+      continue;
+    }
+    current = track.mEndOfFlushedData + track.mData->GetDuration();
+    if (t <= current) {
+      continue;
+    }
+    MutexAutoUnlock unlock(mMutex);
+    for (TrackBound<MediaStreamTrackListener>& l : mTrackListeners) {
+      if (l.mTrackID == track.mID) {
+        l.mListener->NotifyPull(Graph(), current, t);
+      }
+    }
+  }
   return true;
 }
 
 void SourceMediaStream::ExtractPendingInput() {
   MutexAutoLock lock(mMutex);
 
   bool finished = mFinishPending;
   bool shouldNotifyTrackCreated = false;
--- a/dom/media/MediaStreamGraph.h
+++ b/dom/media/MediaStreamGraph.h
@@ -668,17 +668,17 @@ class SourceMediaStream : public MediaSt
   explicit SourceMediaStream();
 
   SourceMediaStream* AsSourceStream() override { return this; }
 
   // Main thread only
 
   /**
    * Enable or disable pulling. When pulling is enabled, NotifyPull
-   * gets called on MediaStreamListeners for this stream during the
+   * gets called on MediaStream/TrackListeners for this stream during the
    * MediaStreamGraph control loop. Pulling is initially disabled.
    * Due to unavoidable race conditions, after a call to SetPullEnabled(false)
    * it is still possible for a NotifyPull to occur.
    */
   void SetPullEnabled(bool aEnabled);
 
   // Users of audio inputs go through the stream so it can track when the
   // last stream referencing an input goes away, so it can close the cubeb
--- a/dom/media/MediaStreamListener.h
+++ b/dom/media/MediaStreamListener.h
@@ -142,16 +142,20 @@ class MediaStreamListener {
  *
  * If a listener is attached to a track that has already ended, we guarantee
  * to call NotifyEnded.
  */
 class MediaStreamTrackListener {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaStreamTrackListener)
 
  public:
+  virtual void NotifyPull(MediaStreamGraph* aGraph,
+                          StreamTime aEndOfAppendedData,
+                          StreamTime aDesiredTime) {}
+
   virtual void NotifyQueuedChanges(MediaStreamGraph* aGraph,
                                    StreamTime aTrackOffset,
                                    const MediaSegment& aQueuedMedia) {}
 
   virtual void NotifyPrincipalHandleChanged(
       MediaStreamGraph* aGraph, const PrincipalHandle& aNewPrincipalHandle) {}
 
   virtual void NotifyEnded() {}