Bug 1572627 record and use old mProcessedTime in Process() and PlayAudio() r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 21 Nov 2019 13:43:52 +0000
changeset 503382 f19f757691cfd3b36a228b0734dee0cb7a1a5372
parent 503381 d9b1730b8cb3dc48601abcd6c768a3c18aa62da0
child 503383 e1838026425e8ac7b2b204f16165d4232a0e26ca
push id36833
push userbtara@mozilla.com
push dateFri, 22 Nov 2019 21:40:53 +0000
treeherdermozilla-central@2c912e46295e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1572627
milestone72.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 1572627 record and use old mProcessedTime in Process() and PlayAudio() r=padenot so that mProcessedTime can be updated for each block processed. Differential Revision: https://phabricator.services.mozilla.com/D54082
dom/media/MediaTrackGraph.cpp
dom/media/MediaTrackGraphImpl.h
--- a/dom/media/MediaTrackGraph.cpp
+++ b/dom/media/MediaTrackGraph.cpp
@@ -520,35 +520,36 @@ void MediaTrackGraphImpl::UpdateTrackOrd
         ++orderedTrackCount;
       }
     }
   }
 
   MOZ_ASSERT(orderedTrackCount == mFirstCycleBreaker);
 }
 
-TrackTime MediaTrackGraphImpl::PlayAudio(const TrackKeyAndVolume& aTkv) {
+TrackTime MediaTrackGraphImpl::PlayAudio(const TrackKeyAndVolume& aTkv,
+                                         GraphTime aPlayedTime) {
   MOZ_ASSERT(OnGraphThread());
   MOZ_ASSERT(mRealtime, "Should only attempt to play audio in realtime mode");
 
   TrackTime ticksWritten = 0;
 
   ticksWritten = 0;
   MediaTrack* track = aTkv.mTrack;
   AudioSegment* audio = track->GetData<AudioSegment>();
   AudioSegment output;
 
-  TrackTime offset = track->GraphTimeToTrackTime(mProcessedTime);
+  TrackTime offset = track->GraphTimeToTrackTime(aPlayedTime);
 
   // We don't update Track->mTracksStartTime here to account for time spent
   // blocked. Instead, we'll update it in UpdateCurrentTimeForTracks after
   // the blocked period has completed. But we do need to make sure we play
   // from the right offsets in the track buffer, even if we've already
   // written silence for some amount of blocked time after the current time.
-  GraphTime t = mProcessedTime;
+  GraphTime t = aPlayedTime;
   while (t < mStateComputedTime) {
     bool blocked = t >= track->mStartBlocking;
     GraphTime end = blocked ? mStateComputedTime : track->mStartBlocking;
     NS_ASSERTION(end <= mStateComputedTime, "mStartBlocking is wrong!");
 
     // Check how many ticks of sound we can provide if we are blocked some
     // time in the middle of this cycle.
     TrackTime toWrite = end - t;
@@ -1212,16 +1213,17 @@ void MediaTrackGraphImpl::UpdateGraph(Gr
 
 void MediaTrackGraphImpl::Process() {
   TRACE_AUDIO_CALLBACK();
   MOZ_ASSERT(OnGraphThread());
   // Play track contents.
   bool allBlockedForever = true;
   // True when we've done ProcessInput for all processed tracks.
   bool doneAllProducing = false;
+  const GraphTime oldProcessedTime = mProcessedTime;
 
   mMixer.StartMixing();
 
   // Figure out what each track wants to do
   for (uint32_t i = 0; i < mTracks.Length(); ++i) {
     MediaTrack* track = mTracks[i];
     if (!doneAllProducing) {
       ProcessedMediaTrack* pt = track->AsProcessedTrack();
@@ -1249,29 +1251,29 @@ void MediaTrackGraphImpl::Process() {
                            ProcessedMediaTrack::ALLOW_END);
           // Assert that a live track produced enough data
           MOZ_ASSERT_IF(!track->mEnded,
                         track->GetEnd() >= GraphTimeToTrackTimeWithBlocking(
                                                track, mStateComputedTime));
         }
       }
     }
-    if (track->mStartBlocking > mProcessedTime) {
+    if (track->mStartBlocking > oldProcessedTime) {
       allBlockedForever = false;
     }
   }
 
   // This is the number of frames that are written to the output buffer, for
   // this iteration.
   TrackTime ticksPlayed = 0;
   // Only playback audio and video in real-time mode
   if (mRealtime) {
     if (CurrentDriver()->AsAudioCallbackDriver()) {
       for (auto& t : mAudioOutputs) {
-        TrackTime ticksPlayedForThisTrack = PlayAudio(t);
+        TrackTime ticksPlayedForThisTrack = PlayAudio(t, oldProcessedTime);
         if (ticksPlayed == 0) {
           ticksPlayed = ticksPlayedForThisTrack;
         } else {
           MOZ_ASSERT(!ticksPlayedForThisTrack ||
                          ticksPlayedForThisTrack == ticksPlayed,
                      "Each track should have the same number of frames.");
         }
       }
@@ -1280,17 +1282,17 @@ void MediaTrackGraphImpl::Process() {
 
   if (CurrentDriver()->AsAudioCallbackDriver()) {
     if (!ticksPlayed) {
       // Nothing was played, so the mixer doesn't know how many frames were
       // processed. We still tell it so AudioCallbackDriver knows how much has
       // been processed. (bug 1406027)
       mMixer.Mix(nullptr,
                  CurrentDriver()->AsAudioCallbackDriver()->OutputChannelCount(),
-                 mStateComputedTime - mProcessedTime, mSampleRate);
+                 mStateComputedTime - oldProcessedTime, mSampleRate);
     }
     mMixer.FinishMixing();
   }
 
   if (!allBlockedForever) {
     EnsureNextIteration();
   }
 }
--- a/dom/media/MediaTrackGraphImpl.h
+++ b/dom/media/MediaTrackGraphImpl.h
@@ -388,17 +388,17 @@ class MediaTrackGraphImpl : public Media
    * to the audio output track. Returns the number of frames played.
    */
 
   struct TrackKeyAndVolume {
     MediaTrack* mTrack;
     void* mKey;
     float mVolume;
   };
-  TrackTime PlayAudio(const TrackKeyAndVolume& aTkv);
+  TrackTime PlayAudio(const TrackKeyAndVolume& aTkv, GraphTime aPlayedTime);
   /* Runs off a message on the graph thread when something requests audio from
    * an input audio device of ID aID, and delivers the input audio frames to
    * aListener. */
   void OpenAudioInputImpl(CubebUtils::AudioDeviceID aID,
                           AudioDataListener* aListener);
   /* Called on the main thread when something requests audio from an input
    * audio device aID. */
   virtual nsresult OpenAudioInput(CubebUtils::AudioDeviceID aID,