Bug 1408294 - Assert that NotifyPull produces data. r?padenot draft
authorAndreas Pehrson <pehrsons@mozilla.com>
Tue, 05 Dec 2017 14:34:08 +0100
changeset 717219 d916e038f6479dc84a76312426b889d201490bf6
parent 717218 597c06c891bd32b7f2e0a396a5bb1fc6fa89ed06
child 717220 36f1b3bf6cb9ed170c1df043119bf4d010a975a1
push id94604
push userbmo:apehrson@mozilla.com
push dateMon, 08 Jan 2018 14:02:37 +0000
reviewerspadenot
bugs1408294
milestone59.0a1
Bug 1408294 - Assert that NotifyPull produces data. r?padenot MozReview-Commit-ID: CtC8A83iJgg
dom/media/MediaManager.cpp
dom/media/MediaStreamGraph.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -3728,16 +3728,20 @@ SourceListener::Remove()
   }
 
   LOG(("SourceListener %p removed on purpose, mFinished = %d", this, (int) mFinished));
   mRemoved = true; // RemoveListener is async, avoid races
   mWindowListener = nullptr;
 
   // If it's destroyed, don't call - listener will be removed and we'll be notified!
   if (!mStream->IsDestroyed()) {
+    // We disable pulling before removing so we don't risk having live tracks
+    // without a listener attached - that wouldn't produce data and would be
+    // illegal to the graph.
+    mStream->SetPullEnabled(false);
     mStream->RemoveListener(this);
   }
 }
 
 void
 SourceListener::StopTrack(TrackID aTrackID)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread");
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1183,16 +1183,39 @@ MediaStreamGraphImpl::UpdateGraph(GraphT
              stream,
              MediaTimeToSeconds(stream->GetTracksEnd()),
              MediaTimeToSeconds(endTime)));
         // Data can't be added to a finished stream, so underruns are irrelevant.
         stream->mStartBlocking = std::min(endTime, aEndBlockingDecisions);
       }
     } else {
       stream->mStartBlocking = WillUnderrun(stream, aEndBlockingDecisions);
+
+      SourceMediaStream* s = stream->AsSourceStream();
+      if (s && s->mPullEnabled) {
+        for (StreamTracks::TrackIter i(s->mTracks); !i.IsEnded(); i.Next()) {
+          if (i->IsEnded()) {
+            continue;
+          }
+          if (i->GetEnd() < stream->GraphTimeToStreamTime(aEndBlockingDecisions)) {
+            LOG(LogLevel::Error,
+                ("SourceMediaStream %p track %u (%s) is live and pulled, but wasn't fed "
+                 "enough data. Listeners=%zu. Track-end=%f, Iteration-end=%f",
+                 stream,
+                 i->GetID(),
+                 (i->GetType() == MediaSegment::AUDIO ? "audio" : "video"),
+                 stream->mListeners.Length(),
+                 MediaTimeToSeconds(i->GetEnd()),
+                 MediaTimeToSeconds(stream->GraphTimeToStreamTime(aEndBlockingDecisions))));
+            MOZ_DIAGNOSTIC_ASSERT(false,
+                                  "A non-finished SourceMediaStream wasn't fed "
+                                  "enough data by NotifyPull");
+          }
+        }
+      }
     }
   }
 
   for (MediaStream* stream : mSuspendedStreams) {
     stream->mStartBlocking = mStateComputedTime;
   }
 
   // The loop is woken up so soon that IterationEnd() barely advances and we