Bug 778682. Part 1: Add NotifyHasCurrentData callback on StreamListener. r=jesup
authorRobert O'Callahan <robert@ocallahan.org>
Thu, 20 Sep 2012 12:47:51 +1200
changeset 107998 9d5d96d5978115aed94f380e23f9806d50b38b65
parent 107997 1d682c2055a4139901458c529f109697ddd83e01
child 107999 bd491a087614d218d4a402be7bf34d3d3930c060
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjesup
bugs778682
milestone18.0a1
Bug 778682. Part 1: Add NotifyHasCurrentData callback on StreamListener. r=jesup
content/media/MediaStreamGraph.cpp
content/media/MediaStreamGraph.h
--- a/content/media/MediaStreamGraph.cpp
+++ b/content/media/MediaStreamGraph.cpp
@@ -290,16 +290,20 @@ public:
    */
   GraphTime StreamTimeToGraphTime(MediaStream* aStream, StreamTime aTime,
                                   uint32_t aFlags = 0);
   /**
    * Get the current audio position of the stream's audio output.
    */
   GraphTime GetAudioPosition(MediaStream* aStream);
   /**
+   * Call NotifyHaveCurrentData on aStream's listeners.
+   */
+  void NotifyHasCurrentData(MediaStream* aStream);
+  /**
    * If aStream needs an audio stream but doesn't have one, create it.
    * If aStream doesn't need an audio stream but has one, destroy it.
    */
   void CreateOrDestroyAudioStreams(GraphTime aAudioOutputStartTime,
                                    MediaStream* aStream);
   /**
    * Queue audio (mix of stream audio and silence for blocked intervals)
    * to the audio output stream.
@@ -1102,16 +1106,26 @@ MediaStreamGraphImpl::RecomputeBlockingA
 
   for (uint32_t i = 0; i < aStreams.Length(); ++i) {
     MediaStream* stream = aStreams[i];
     stream->mBlocked.SetAtAndAfter(aTime, stream->mBlockInThisPhase);
   }
 }
 
 void
+MediaStreamGraphImpl::NotifyHasCurrentData(MediaStream* aStream)
+{
+  for (uint32_t j = 0; j < aStream->mListeners.Length(); ++j) {
+    MediaStreamListener* l = aStream->mListeners[j];
+    l->NotifyHasCurrentData(this,
+      GraphTimeToStreamTime(aStream, mCurrentTime) < aStream->mBuffer.GetEnd());
+  }
+}
+
+void
 MediaStreamGraphImpl::CreateOrDestroyAudioStreams(GraphTime aAudioOutputStartTime,
                                                   MediaStream* aStream)
 {
   nsAutoTArray<bool,2> audioOutputStreamsFound;
   for (uint32_t i = 0; i < aStream->mAudioOutputStreams.Length(); ++i) {
     audioOutputStreamsFound.AppendElement(false);
   }
 
@@ -1392,16 +1406,17 @@ MediaStreamGraphImpl::RunThread()
       MediaStream* stream = mStreams[i];
       ProcessedMediaStream* ps = stream->AsProcessedStream();
       if (ps && !ps->mFinished) {
         ps->ProduceOutput(prevComputedTime, mStateComputedTime);
         NS_ASSERTION(stream->mBuffer.GetEnd() >=
                      GraphTimeToStreamTime(stream, mStateComputedTime),
                      "Stream did not produce enough data");
       }
+      NotifyHasCurrentData(stream);
       CreateOrDestroyAudioStreams(prevComputedTime, stream);
       PlayAudio(stream, prevComputedTime, mStateComputedTime);
       audioStreamsActive += stream->mAudioOutputStreams.Length();
       PlayVideo(stream);
       SourceMediaStream* is = stream->AsSourceStream();
       if (is) {
         UpdateBufferSufficiencyState(is);
       }
--- a/content/media/MediaStreamGraph.h
+++ b/content/media/MediaStreamGraph.h
@@ -123,16 +123,22 @@ public:
   };
   /**
    * Notify that the blocking status of the stream changed. The initial state
    * is assumed to be BLOCKED.
    */
   virtual void NotifyBlockingChanged(MediaStreamGraph* aGraph, Blocking aBlocked) {}
 
   /**
+   * Notify that the stream has (or does not have) data in each track
+   * for the stream's current time.
+   */
+  virtual void NotifyHasCurrentData(MediaStreamGraph* aGraph, bool aHasCurrentData) {}
+
+  /**
    * Notify that the stream output is advancing.
    */
   virtual void NotifyOutput(MediaStreamGraph* aGraph) {}
 
   /**
    * Notify that the stream finished.
    */
   virtual void NotifyFinished(MediaStreamGraph* aGraph) {}