Bug 1509548 - Remove the concept of a known tracks time from MediaStreamGraph. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Thu, 29 Nov 2018 17:37:06 +0000
changeset 507972 1d1b47e235375f3a52faafe37a2e560a98c5b51f
parent 507971 f988af9437f591cc5c7d3917ba370e2edc82d1a6
child 507973 8a064f0dbb2f09c589514f71b06e37ed36362cd1
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
bugs1509548
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 1509548 - Remove the concept of a known tracks time from MediaStreamGraph. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D12923
dom/media/AudioCaptureStream.cpp
dom/media/CanvasCaptureMediaStream.cpp
dom/media/MediaManager.cpp
dom/media/MediaStreamGraph.cpp
dom/media/MediaStreamGraph.h
dom/media/StreamTracks.cpp
dom/media/StreamTracks.h
dom/media/TrackUnionStream.cpp
dom/media/mediasink/DecodedStream.cpp
dom/media/mediasink/DecodedStream.h
dom/media/webaudio/AudioNodeStream.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/dom/media/AudioCaptureStream.cpp
+++ b/dom/media/AudioCaptureStream.cpp
@@ -103,19 +103,16 @@ void AudioCaptureStream::ProcessInput(Gr
           }
         }
         toMix.Mix(mMixer, MONO, Graph()->GraphRate());
       }
     }
     // This calls MixerCallback below
     mMixer.FinishMixing();
   }
-
-  // Regardless of the status of the input tracks, we go foward.
-  mTracks.AdvanceKnownTracksTime(GraphTimeToStreamTimeWithBlocking((aTo)));
 }
 
 void AudioCaptureStream::MixerCallback(AudioDataValue* aMixedBuffer,
                                        AudioSampleFormat aFormat,
                                        uint32_t aChannels, uint32_t aFrames,
                                        uint32_t aSampleRate) {
   AutoTArray<nsTArray<AudioDataValue>, MONO> output;
   AutoTArray<const AudioDataValue*, MONO> bufferPtrs;
--- a/dom/media/CanvasCaptureMediaStream.cpp
+++ b/dom/media/CanvasCaptureMediaStream.cpp
@@ -110,17 +110,16 @@ OutputStreamDriver::OutputStreamDriver(S
     : FrameCaptureListener(),
       mSourceStream(aSourceStream),
       mTrackListener(
           new TrackListener(aTrackId, aPrincipalHandle, aSourceStream)) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mSourceStream);
   mSourceStream->AddTrack(aTrackId, new VideoSegment());
   mSourceStream->AddTrackListener(mTrackListener, aTrackId);
-  mSourceStream->AdvanceKnownTracksTime(STREAM_TIME_MAX);
   mSourceStream->SetPullEnabled(true);
 
   // All CanvasCaptureMediaStreams shall at least get one frame.
   mFrameCaptureRequested = true;
 }
 
 OutputStreamDriver::~OutputStreamDriver() {
   MOZ_ASSERT(NS_IsMainThread());
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -4189,17 +4189,16 @@ RefPtr<SourceListener::InitPromise> Sour
                 MakeRefPtr<MediaMgrError>(MediaMgrError::Name::AbortError, log),
                 __func__);
             return;
           }
         }
 
         // Start() queued the tracks to be added synchronously to avoid races
         stream->FinishAddTracks();
-        stream->AdvanceKnownTracksTime(STREAM_TIME_MAX);
         LOG(("started all sources"));
 
         aHolder.Resolve(true, __func__);
       });
 
   return init->Then(
       GetMainThreadSerialEventTarget(), __func__,
       [self = RefPtr<SourceListener>(this), this]() {
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1959,17 +1959,16 @@ void MediaStream::FinishOnGraphThread() 
             ("MediaStream %p will finish, but track %d has not ended.", this,
              track->GetID()));
         NS_ASSERTION(false, "Finished stream cannot contain live track");
       }
     }
   }
 #endif
   mFinished = true;
-  mTracks.AdvanceKnownTracksTime(STREAM_TIME_MAX);
 
   // Let the MSG knows that this stream can be destroyed if necessary to avoid
   // unnecessarily processing it in the future.
   GraphImpl()->SetStreamOrderDirty();
 }
 
 StreamTracks::Track* MediaStream::FindTrack(TrackID aID) const {
   return mTracks.FindTrack(aID);
@@ -2455,17 +2454,16 @@ void MediaStream::AddMainThreadListener(
 
   nsCOMPtr<nsIRunnable> runnable = new NotifyRunnable(this);
   GraphImpl()->Dispatch(runnable.forget());
 }
 
 SourceMediaStream::SourceMediaStream()
     : MediaStream(),
       mMutex("mozilla::media::SourceMediaStream"),
-      mUpdateKnownTracksTime(0),
       mPullEnabled(false),
       mFinishPending(false) {}
 
 nsresult SourceMediaStream::OpenAudioInput(CubebUtils::AudioDeviceID aID,
                                            AudioDataListener* aListener) {
   MOZ_ASSERT(GraphImpl());
   mInputListener = aListener;
   return GraphImpl()->OpenAudioInput(aID, aListener);
@@ -2597,19 +2595,16 @@ void SourceMediaStream::ExtractPendingIn
       data->mEndOfFlushedData += data->mData->GetDuration();
       dest->AppendFrom(data->mData);
     }
     if (data->mCommands & SourceMediaStream::TRACK_END) {
       mTracks.FindTrack(data->mID)->SetEnded();
       mUpdateTracks.RemoveElementAt(i);
     }
   }
-  if (!mFinished) {
-    mTracks.AdvanceKnownTracksTime(mUpdateKnownTracksTime);
-  }
 
   if (mTracks.GetEnd() > 0) {
     mHasCurrentData = true;
   }
 
   if (finished) {
     FinishOnGraphThread();
   }
@@ -2841,25 +2836,16 @@ void SourceMediaStream::EndTrack(TrackID
   if (track) {
     track->mCommands |= TrackEventCommand::TRACK_EVENT_ENDED;
   }
   if (auto graph = GraphImpl()) {
     graph->EnsureNextIteration();
   }
 }
 
-void SourceMediaStream::AdvanceKnownTracksTime(StreamTime aKnownTime) {
-  MutexAutoLock lock(mMutex);
-  MOZ_ASSERT(aKnownTime >= mUpdateKnownTracksTime);
-  mUpdateKnownTracksTime = aKnownTime;
-  if (auto graph = GraphImpl()) {
-    graph->EnsureNextIteration();
-  }
-}
-
 void SourceMediaStream::FinishPendingWithLockHeld() {
   mMutex.AssertCurrentThreadOwns();
   mFinishPending = true;
   if (auto graph = GraphImpl()) {
     graph->EnsureNextIteration();
   }
 }
 
--- a/dom/media/MediaStreamGraph.h
+++ b/dom/media/MediaStreamGraph.h
@@ -693,19 +693,18 @@ class SourceMediaStream : public MediaSt
    * Extract any state updates pending in the stream, and apply them.
    */
   void ExtractPendingInput(GraphTime aCurrentTime);
 
   enum {
     ADDTRACK_QUEUED = 0x01  // Queue track add until FinishAddTracks()
   };
   /**
-   * Add a new track to the stream starting at the stream's current time
-   * (which must be greater than or equal to the last time passed to
-   * AdvanceKnownTracksTime). Takes ownership of aSegment.
+   * Add a new track to the stream starting at the stream's current time.
+   * Takes ownership of aSegment.
    */
   void AddTrack(TrackID aID, MediaSegment* aSegment, uint32_t aFlags = 0) {
     AddTrackInternal(aID, GraphRate(), aSegment, aFlags);
   }
 
   /**
    * Like AddTrack, but resamples audio from aRate to the graph rate.
    */
@@ -735,22 +734,16 @@ class SourceMediaStream : public MediaSt
   StreamTime GetEndOfAppendedData(TrackID aID);
   /**
    * Indicate that a track has ended. Do not do any more API calls
    * affecting this track.
    * Ignored if the track does not exist.
    */
   void EndTrack(TrackID aID);
   /**
-   * Indicate that no tracks will be added starting before time aKnownTime.
-   * aKnownTime must be >= its value at the last call to AdvanceKnownTracksTime.
-   */
-  void AdvanceKnownTracksTime(StreamTime aKnownTime);
-  void AdvanceKnownTracksTimeWithLockHeld(StreamTime aKnownTime);
-  /**
    * Indicate that this stream should enter the "finished" state. All tracks
    * must have been ended via EndTrack. The finish time of the stream is
    * when all tracks have ended.
    */
   void FinishPendingWithLockHeld();
   void FinishPending() {
     MutexAutoLock lock(mMutex);
     FinishPendingWithLockHeld();
@@ -862,17 +855,16 @@ class SourceMediaStream : public MediaSt
   // XXX Should really be a CubebUtils::AudioDeviceID, but they aren't
   // copyable (opaque pointers)
   RefPtr<AudioDataListener> mInputListener;
 
   // This must be acquired *before* MediaStreamGraphImpl's lock, if they are
   // held together.
   Mutex mMutex;
   // protected by mMutex
-  StreamTime mUpdateKnownTracksTime;
   // This time stamp will be updated in adding and blocked SourceMediaStream,
   // |AddStreamGraphThread| and |AdvanceTimeVaryingValuesToCurrentTime| in
   // particularly.
   TimeStamp mStreamTracksStartTimeStamp;
   nsTArray<TrackData> mUpdateTracks;
   nsTArray<TrackData> mPendingTracks;
   nsTArray<TrackBound<DirectMediaStreamTrackListener>> mDirectTrackListeners;
   bool mPullEnabled;
--- a/dom/media/StreamTracks.cpp
+++ b/dom/media/StreamTracks.cpp
@@ -10,18 +10,17 @@
 namespace mozilla {
 
 #ifdef DEBUG
 
 extern LazyLogModule gMediaStreamGraphLog;
 #define STREAM_LOG(type, msg) MOZ_LOG(gMediaStreamGraphLog, type, msg)
 
 void StreamTracks::DumpTrackInfo() const {
-  STREAM_LOG(LogLevel::Info,
-             ("DumpTracks: mTracksKnownTime %" PRId64, mTracksKnownTime));
+  STREAM_LOG(LogLevel::Info, ("Dumping StreamTracks"));
   for (uint32_t i = 0; i < mTracks.Length(); ++i) {
     Track* track = mTracks[i];
     if (track->IsEnded()) {
       STREAM_LOG(LogLevel::Info, ("Track[%d] %d: ended", i, track->GetID()));
     } else {
       STREAM_LOG(LogLevel::Info, ("Track[%d] %d: %" PRId64 "", i,
                                   track->GetID(), track->GetEnd()));
     }
--- a/dom/media/StreamTracks.h
+++ b/dom/media/StreamTracks.h
@@ -139,17 +139,16 @@ class StreamTracks {
     }
     bool LessThan(Track* aA, Track* aB) const {
       return aA->GetID() < aB->GetID();
     }
   };
 
   StreamTracks()
       : mGraphRate(0),
-        mTracksKnownTime(0),
         mForgottenTime(0),
         mTracksDirty(false)
 #ifdef DEBUG
         ,
         mGraphRateIsSet(false)
 #endif
   {
     MOZ_COUNT_CTOR(StreamTracks);
@@ -189,43 +188,29 @@ class StreamTracks {
    */
   Track& AddTrack(TrackID aID, StreamTime aStart, MediaSegment* aSegment) {
     NS_ASSERTION(!FindTrack(aID), "Track with this ID already exists");
 
     Track* track = new Track(aID, aStart, aSegment);
     mTracks.InsertElementSorted(track, CompareTracksByID());
     mTracksDirty = true;
 
-    if (mTracksKnownTime == STREAM_TIME_MAX) {
-      // There exists code like
-      // http://mxr.mozilla.org/mozilla-central/source/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp?rev=96b197deb91e&mark=1292-1297#1292
-      NS_WARNING(
-          "Adding track to StreamTracks that should have no more tracks");
-    } else {
-      // NS_ASSERTION(mTracksKnownTime <= aStart, "Start time too early");
-    }
     return *track;
   }
 
-  void AdvanceKnownTracksTime(StreamTime aKnownTime) {
-    NS_ASSERTION(aKnownTime >= mTracksKnownTime,
-                 "Can't move tracks-known time earlier");
-    mTracksKnownTime = aKnownTime;
-  }
-
   /**
    * The end time for the StreamTracks is the latest time for which we have
    * data for all tracks that haven't ended by that time.
    */
   StreamTime GetEnd() const;
 
   /**
-   * Returns the earliest time >= 0 at which all tracks have ended
-   * and all their data has been played out and no new tracks can be added,
-   * or STREAM_TIME_MAX if there is no such time.
+   * Returns the earliest time >= 0 at which all tracks have ended and all
+   * their data has been played out, or STREAM_TIME_MAX if there is no such
+   * time.
    */
   StreamTime GetAllTracksEnd() const;
 
 #ifdef DEBUG
   void DumpTrackInfo() const;
 #endif
 
   Track* FindTrack(TrackID aID) const;
@@ -294,19 +279,16 @@ class StreamTracks {
     }
 
     mTracksDirty = false;
     return true;
   }
 
  protected:
   TrackRate mGraphRate;  // StreamTime per second
-  // Any new tracks added will start at or after this time. In other words, the
-  // track list is complete and correct for all times less than this time.
-  StreamTime mTracksKnownTime;
   StreamTime mForgottenTime;
 
  private:
   // All known tracks for this StreamTracks
   nsTArray<nsAutoPtr<Track>> mTracks;
   bool mTracksDirty;
 
 #ifdef DEBUG
--- a/dom/media/TrackUnionStream.cpp
+++ b/dom/media/TrackUnionStream.cpp
@@ -138,18 +138,16 @@ void TrackUnionStream::ProcessInput(Grap
       mTrackMap.RemoveElementAt(i);
     }
   }
   if (allFinished && mAutofinish && (aFlags & ALLOW_FINISH)) {
     // All streams have finished and won't add any more tracks, and
     // all our tracks have actually finished and been removed from our map,
     // so we're finished now.
     FinishOnGraphThread();
-  } else {
-    mTracks.AdvanceKnownTracksTime(GraphTimeToStreamTimeWithBlocking(aTo));
   }
   if (allHaveCurrentData) {
     // We can make progress if we're not blocked
     mHasCurrentData = true;
   }
 }
 
 uint32_t TrackUnionStream::AddTrack(MediaInputPort* aPort,
--- a/dom/media/mediasink/DecodedStream.cpp
+++ b/dom/media/mediasink/DecodedStream.cpp
@@ -719,34 +719,27 @@ StreamTime DecodedStream::SentDuration()
 
   if (!mData) {
     return 0;
   }
 
   return std::max(mData->mStreamAudioWritten, mData->mStreamVideoWritten);
 }
 
-void DecodedStream::AdvanceTracks() {
-  AssertOwnerThread();
-
-  mData->mStream->AdvanceKnownTracksTime(mStreamTimeOffset + SentDuration());
-}
-
 void DecodedStream::SendData() {
   AssertOwnerThread();
   MOZ_ASSERT(mStartTime.isSome(), "Must be called after StartPlayback()");
 
   // Not yet created on the main thread. MDSM will try again later.
   if (!mData) {
     return;
   }
 
   SendAudio(mParams.mVolume, mSameOrigin, mPrincipalHandle);
   SendVideo(mSameOrigin, mPrincipalHandle);
-  AdvanceTracks();
 }
 
 TimeUnit DecodedStream::GetEndTime(TrackType aType) const {
   AssertOwnerThread();
   if (aType == TrackInfo::kAudioTrack && mInfo.HasAudio() && mData) {
     auto t = mStartTime.ref() +
              FramesToTimeUnit(mData->mAudioFramesWritten, mInfo.mAudio.mRate);
     if (t.IsValid()) {
--- a/dom/media/mediasink/DecodedStream.h
+++ b/dom/media/mediasink/DecodedStream.h
@@ -76,17 +76,16 @@ class DecodedStream : public media::Medi
   media::TimeUnit FromMicroseconds(int64_t aTime) {
     return media::TimeUnit::FromMicroseconds(aTime);
   }
   void DestroyData(UniquePtr<DecodedStreamData> aData);
   void SendAudio(double aVolume, bool aIsSameOrigin,
                  const PrincipalHandle& aPrincipalHandle);
   void SendVideo(bool aIsSameOrigin, const PrincipalHandle& aPrincipalHandle);
   StreamTime SentDuration();
-  void AdvanceTracks();
   void SendData();
   void NotifyOutput(int64_t aTime);
   void NotifyTrackEnd(StreamTime aEndTime);
 
   void AssertOwnerThread() const {
     MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   }
 
--- a/dom/media/webaudio/AudioNodeStream.cpp
+++ b/dom/media/webaudio/AudioNodeStream.cpp
@@ -557,19 +557,16 @@ void AudioNodeStream::ProduceOutputBefor
         DisabledTrackMode::ENABLED) {
       mLastChunks[0].SetNull(WEBAUDIO_BLOCK_SIZE);
     }
   }
 }
 
 void AudioNodeStream::AdvanceOutputSegment() {
   StreamTracks::Track* track = EnsureTrack(AUDIO_TRACK);
-  // No more tracks will be coming
-  mTracks.AdvanceKnownTracksTime(STREAM_TIME_MAX);
-
   AudioSegment* segment = track->Get<AudioSegment>();
 
   AudioChunk copyChunk = *mLastChunks[0].AsMutableChunk();
   AudioSegment tmpSegment;
   tmpSegment.AppendAndConsumeChunk(&copyChunk);
 
   for (TrackBound<MediaStreamTrackListener>& b : mTrackListeners) {
     // Notify MediaStreamTrackListeners.
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -1668,17 +1668,16 @@ 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->AddTrackListener(this, mTrackId);
   }
 
   void AddSelf()
   {
     if (!mListening) {
       mListening = true;
       mSource->SetPullEnabled(true);