From d9f2a41f28cd5ba54a45086107f0813267e94244 Mon Sep 17 00:00:00 2001 From: EKR Date: Sat, 5 Jan 2013 09:02:36 -0800 Subject: [PATCH] Bug 825611 - Have MediaPipeline deliver as much media as requested. r=jesup --- .../src/mediapipeline/MediaPipeline.cpp | 24 ++++--------------- .../src/mediapipeline/MediaPipeline.h | 2 +- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp index 9934bb8e22b6..aab80796a741 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -822,31 +822,15 @@ nsresult MediaPipelineReceiveAudio::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 samples = SharedBuffer::Create(1000); int samples_length; @@ -870,6 +854,8 @@ NotifyPull(MediaStreamGraph* graph, StreamTime total) { source_->AppendToTrack(1, // TODO(ekr@rtfm.com): Track ID &segment); + + played_ += 10; } } diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h index 1cf472f9be15..9570bb6394a6 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h @@ -371,7 +371,7 @@ class MediaPipelineReceiveAudio : public MediaPipelineReceive { private: SourceMediaStream *source_; RefPtr conduit_; - StreamTime played_; + uint64_t played_; // Amount of media played in milliseconds. }; RefPtr listener_;