Bug 825611 - Have MediaPipeline deliver as much media as requested. r=jesup
authorEKR <ekr@rtfm.com>
Sat, 05 Jan 2013 09:02:36 -0800
changeset 117741 9958b17acc012ffa71cfe1740389269a01fd94ba
parent 117740 04557efa1fd92036b01a47205cab346c0e938979
child 117742 0b4ce0db7ecbc3ded6700ce9204fb4bc94896d67
push id24110
push userphilringnalda@gmail.com
push dateSat, 05 Jan 2013 23:57:49 +0000
treeherdermozilla-central@20d1a5916ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs825611
milestone20.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 825611 - Have MediaPipeline deliver as much media as requested. r=jesup
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -817,41 +817,25 @@ nsresult MediaPipelineReceiveAudio::Init
   description_ = pc_ + "| Receive audio";
 
   stream_->AddListener(listener_);
 
   return MediaPipelineReceive::Init();
 }
 
 void MediaPipelineReceiveAudio::PipelineListener::
-NotifyPull(MediaStreamGraph* graph, StreamTime total) {
+NotifyPull(MediaStreamGraph* graph, StreamTime desired_time) {
   MOZ_ASSERT(source_);
   if (!source_) {
     MOZ_MTLOG(PR_LOG_ERROR, "NotifyPull() called from a non-SourceMediaStream");
     return;
   }
 
-  // "total" is absolute stream time.
-  // StreamTime desired = total - played_;
-  played_ = total;
-  //double time_s = MediaTimeToSeconds(desired);
-
-  // Number of 10 ms samples we need
-  //int num_samples = ceil(time_s / .01f);
-
-  // Doesn't matter what was asked for, always give 160 samples per 10 ms.
-  int num_samples = 1;
-
-  MOZ_MTLOG(PR_LOG_DEBUG, "Asking for " << num_samples << "sample from Audio Conduit");
-
-  if (num_samples <= 0) {
-    return;
-  }
-
-  while (num_samples--) {
+  // This comparison is done in total time to avoid accumulated roundoff errors.
+  while (MillisecondsToMediaTime(played_) < desired_time) {
     // TODO(ekr@rtfm.com): Is there a way to avoid mallocating here?
     nsRefPtr<SharedBuffer> samples = SharedBuffer::Create(1000);
     int samples_length;
 
     MediaConduitErrorCode err =
         static_cast<AudioSessionConduit*>(conduit_.get())->GetAudioFrame(
             static_cast<int16_t *>(samples->Data()),
             16000,  // Sampling rate fixed at 16 kHz for now
@@ -865,16 +849,18 @@ NotifyPull(MediaStreamGraph* graph, Stre
 
     AudioSegment segment;
     segment.Init(1);
     segment.AppendFrames(samples.forget(), samples_length,
                          0, samples_length, AUDIO_FORMAT_S16);
 
     source_->AppendToTrack(1,  // TODO(ekr@rtfm.com): Track ID
                            &segment);
+
+    played_ += 10;
   }
 }
 
 nsresult MediaPipelineReceiveVideo::Init() {
   ASSERT_ON_THREAD(main_thread_);
   MOZ_MTLOG(PR_LOG_DEBUG, __FUNCTION__);
 
   description_ = pc_ + "| Receive video";
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -366,17 +366,17 @@ class MediaPipelineReceiveAudio : public
                                           TrackTicks offset,
                                           uint32_t events,
                                           const MediaSegment& queued_media) {}
     virtual void NotifyPull(MediaStreamGraph* aGraph, StreamTime aDesiredTime);
 
    private:
     SourceMediaStream *source_;
     RefPtr<MediaSessionConduit> conduit_;
-    StreamTime played_;
+    uint64_t played_;  // Amount of media played in milliseconds.
   };
 
   RefPtr<PipelineListener> listener_;
 };
 
 
 // A specialization of pipeline for reading from the network and
 // rendering video.