Bug 1423241 - Move MediaPipeline from MediaStreamListener to MediaStreamTrackListener. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Fri, 23 Nov 2018 15:01:30 +0000
changeset 507049 fafb582ffcbc071acbc32dfe450be0df7ee84f23
parent 507048 e93cc0185c24c792da94717583a37b28ebcd24be
child 507050 926b591bb0cf53300f8ed17d6849644aa7626079
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [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 - Move MediaPipeline from MediaStreamListener to MediaStreamTrackListener. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D9104
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -1639,24 +1639,23 @@ MediaPipelineTransmit::PipelineListener:
 
 void
 MediaPipelineTransmit::PipelineListener::SetCurrentFrames(
   const VideoSegment& aSegment)
 {
   NewData(aSegment);
 }
 
-class GenericReceiveListener : public MediaStreamListener
+class GenericReceiveListener : public MediaStreamTrackListener
 {
 public:
   explicit GenericReceiveListener(dom::MediaStreamTrack* aTrack)
     : mTrack(aTrack)
     , mTrackId(aTrack->GetInputTrackId())
     , mSource(mTrack->GetInputStream()->AsSourceStream())
-    , mPlayedTicks(0)
     , mPrincipalHandle(PRINCIPAL_HANDLE_NONE)
     , mListening(false)
     , mMaybeTrackNeedsUnmute(true)
   {
     MOZ_RELEASE_ASSERT(mSource, "Must be used with a SourceMediaStream");
   }
 
   virtual ~GenericReceiveListener()
@@ -1679,17 +1678,17 @@ public:
     MOZ_LOG(gMediaPipelineLog, LogLevel::Debug,
             ("GenericReceiveListener added %s track %d (%p) to stream %p",
              mTrack->AsAudioStreamTrack() ? "audio" : "video",
              mTrackId,
              mTrack.get(),
              mSource.get()));
 
     mSource->AdvanceKnownTracksTime(STREAM_TIME_MAX);
-    mSource->AddListener(this);
+    mSource->AddTrackListener(this, mTrackId);
   }
 
   void AddSelf()
   {
     if (!mListening) {
       mListening = true;
       mSource->SetPullEnabled(true);
       mMaybeTrackNeedsUnmute = true;
@@ -1722,17 +1721,17 @@ public:
     }
   }
 
   void EndTrack()
   {
     MOZ_LOG(gMediaPipelineLog, LogLevel::Debug, ("GenericReceiveListener ending track"));
 
     // This breaks the cycle with the SourceMediaStream
-    mSource->RemoveListener(this);
+    mSource->RemoveTrackListener(this, mTrackId);
     mSource->EndTrack(mTrackId);
   }
 
   // Must be called on the main thread
   void SetPrincipalHandle_m(const PrincipalHandle& aPrincipalHandle)
   {
     class Message : public ControlMessage
     {
@@ -1763,17 +1762,16 @@ public:
   {
     mPrincipalHandle = aPrincipalHandle;
   }
 
 protected:
   RefPtr<dom::MediaStreamTrack> mTrack;
   const TrackID mTrackId;
   const RefPtr<SourceMediaStream> mSource;
-  TrackTicks mPlayedTicks;
   PrincipalHandle mPrincipalHandle;
   bool mListening;
   Atomic<bool> mMaybeTrackNeedsUnmute;
 };
 
 MediaPipelineReceive::MediaPipelineReceive(
     const std::string& aPc,
     MediaTransportBase* aTransportHandler,
@@ -1805,22 +1803,24 @@ public:
     // If the sampling rate is not-supported, we will use 48kHz instead.
     , mRate(static_cast<AudioSessionConduit*>(mConduit.get())
                 ->IsSamplingFreqSupported(mSource->GraphRate())
               ? mSource->GraphRate()
               : WEBRTC_MAX_SAMPLE_RATE)
     , mTaskQueue(
         new TaskQueue(GetMediaThreadPool(MediaThreadType::WEBRTC_DECODER),
                       "AudioPipelineListener"))
+    , mPlayedTicks(0)
   {
     AddTrackToSource(mRate);
   }
 
-  // Implement MediaStreamListener
+  // Implement MediaStreamTrackListener
   void NotifyPull(MediaStreamGraph* aGraph,
+                  StreamTime aEndOfAppendedData,
                   StreamTime aDesiredTime) override
   {
     NotifyPullImpl(aDesiredTime);
   }
 
 private:
   ~PipelineListener()
   {
@@ -1918,16 +1918,17 @@ private:
 
   RefPtr<MediaSessionConduit> mConduit;
   // This conduit's sampling rate. This is either 16, 32, 44.1 or 48kHz, and
   // tries to be the same as the graph rate. If the graph rate is higher than
   // 48kHz, mRate is capped to 48kHz. If mRate does not match the graph rate,
   // audio is resampled to the graph rate.
   const TrackRate mRate;
   const RefPtr<TaskQueue> mTaskQueue;
+  TrackTicks mPlayedTicks;
 };
 
 MediaPipelineReceiveAudio::MediaPipelineReceiveAudio(
   const std::string& aPc,
   MediaTransportBase* aTransportHandler,
   nsCOMPtr<nsIEventTarget> aMainThread,
   nsCOMPtr<nsIEventTarget> aStsThread,
   RefPtr<AudioSessionConduit> aConduit,
@@ -1996,39 +1997,33 @@ public:
     , mHeight(0)
     , mImageContainer(
         LayerManager::CreateImageContainer(ImageContainer::ASYNCHRONOUS))
     , mMutex("Video PipelineListener")
   {
     AddTrackToSource();
   }
 
-  // Implement MediaStreamListener
-  void NotifyPull(MediaStreamGraph* aGraph, StreamTime aDesiredTime) override
+  // Implement MediaStreamTrackListener
+  void NotifyPull(MediaStreamGraph* aGraph,
+                  StreamTime aEndOfAppendedData,
+                  StreamTime aDesiredTime) override
   {
     TRACE_AUDIO_CALLBACK_COMMENT("Track %i", mTrackId);
     MutexAutoLock lock(mMutex);
 
     RefPtr<Image> image = mImage;
-    StreamTime delta = aDesiredTime - mPlayedTicks;
+    StreamTime delta = aDesiredTime - aEndOfAppendedData;
+    MOZ_ASSERT(delta > 0);
 
-    // Don't append if we've already provided a frame that supposedly
-    // goes past the current aDesiredTime Doing so means a negative
-    // delta and thus messes up handling of the graph
-    if (delta > 0) {
-      VideoSegment segment;
-      IntSize size = image ? image->GetSize() : IntSize(mWidth, mHeight);
-      segment.AppendFrame(image.forget(), delta, size, mPrincipalHandle);
-      // Handle track not actually added yet or removed/finished
-      if (!mSource->AppendToTrack(mTrackId, &segment)) {
-        MOZ_LOG(gMediaPipelineLog, LogLevel::Error, ("AppendToTrack failed"));
-        return;
-      }
-      mPlayedTicks = aDesiredTime;
-    }
+    VideoSegment segment;
+    IntSize size = image ? image->GetSize() : IntSize(mWidth, mHeight);
+    segment.AppendFrame(image.forget(), delta, size, mPrincipalHandle);
+    DebugOnly<bool> appended = mSource->AppendToTrack(mTrackId, &segment);
+    MOZ_ASSERT(appended);
   }
 
   // Accessors for external writes from the renderer
   void FrameSizeChange(unsigned int aWidth,
                        unsigned int aHeight)
   {
     MutexAutoLock enter(mMutex);