From a37ebbc3c152f9e2ff6b1e1726cf6cd2ad4da8a0 Mon Sep 17 00:00:00 2001 From: "scherkus@chromium.org" Date: Thu, 21 May 2009 00:54:17 +0000 Subject: Don't update the clock if we don't have a reliable timestamp available. Turns out vorbis packets only have an accurate timestamp every second or so while the rest of the packets have a timestamp of zero. Problem was we were overwriting |last_fill_buffer_time_| with zeros and then updating the clock, effectively causing a ton of drift. Review URL: http://codereview.chromium.org/115593 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16561 0039d316-1c4b-4281-b951-d872f2087c98 --- media/filters/audio_renderer_base.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/media/filters/audio_renderer_base.cc b/media/filters/audio_renderer_base.cc index 28acd82..8466c2e 100644 --- a/media/filters/audio_renderer_base.cc +++ b/media/filters/audio_renderer_base.cc @@ -79,10 +79,14 @@ void AudioRendererBase::OnReadComplete(Buffer* buffer_in) { } } +// TODO(scherkus): clean up FillBuffer().. it's overly complex!! size_t AudioRendererBase::FillBuffer(uint8* dest, size_t dest_len, float rate) { - // Update the pipeline's time. - host_->SetTime(last_fill_buffer_time_); + // Update the pipeline's time if it was set last time. + if (last_fill_buffer_time_.InMicroseconds() > 0) { + host_->SetTime(last_fill_buffer_time_); + last_fill_buffer_time_ = base::TimeDelta(); + } size_t buffers_released = 0; size_t dest_written = 0; @@ -128,7 +132,9 @@ size_t AudioRendererBase::FillBuffer(uint8* dest, size_t dest_len, // Update the time. If this is the last buffer in the queue, we'll // drop out of the loop before len == 0, so we need to always update // the time here. - last_fill_buffer_time_ = buffer->GetTimestamp() + buffer->GetDuration(); + if (buffer->GetTimestamp().InMicroseconds() > 0) { + last_fill_buffer_time_ = buffer->GetTimestamp() + buffer->GetDuration(); + } // Dequeue the buffer. queue_.pop_front(); @@ -142,8 +148,11 @@ size_t AudioRendererBase::FillBuffer(uint8* dest, size_t dest_len, // Integer divide so multiply before divide to work properly. int64 us_written = (buffer->GetDuration().InMicroseconds() * data_offset_) / buffer->GetDataSize(); - last_fill_buffer_time_ = buffer->GetTimestamp() + - base::TimeDelta::FromMicroseconds(us_written); + + if (buffer->GetTimestamp().InMicroseconds() > 0) { + last_fill_buffer_time_ = buffer->GetTimestamp() + + base::TimeDelta::FromMicroseconds(us_written); + } } } -- cgit v1.1