Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: media/filters/audio_renderer_impl.cc

Issue 256163005: Introduce AudioClock to improve playback delay calculations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/filters/audio_renderer_impl.cc
diff --git a/media/filters/audio_renderer_impl.cc b/media/filters/audio_renderer_impl.cc
index 4f71d3d81cc9d636e9d28b469ef75ba05d0f746e..b65b680b24143d244c88d8a5685ca11b88873b02 100644
--- a/media/filters/audio_renderer_impl.cc
+++ b/media/filters/audio_renderer_impl.cc
@@ -20,6 +20,7 @@
#include "media/base/audio_splicer.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/demuxer_stream.h"
+#include "media/filters/buffered_audio_tracker.h"
#include "media/filters/decrypting_demuxer_stream.h"
namespace media {
@@ -127,6 +128,7 @@ void AudioRendererImpl::DoPause_Locked() {
base::AutoUnlock auto_unlock(lock_);
sink_->Pause();
}
+ buffered_audio_tracker_->AudioCallbackFired(0);
sink_playing_ = false;
}
}
@@ -288,6 +290,9 @@ void AudioRendererImpl::Initialize(DemuxerStream* stream,
hardware_config_->GetHighLatencyBufferSize());
}
+ buffered_audio_tracker_.reset(
+ new BufferedAudioTracker(audio_parameters_.sample_rate()));
+
audio_buffer_stream_.Initialize(
stream,
statistics_cb,
@@ -566,25 +571,34 @@ int AudioRendererImpl::Render(AudioBus* audio_bus,
const int requested_frames = audio_bus->frames();
base::TimeDelta current_time = kNoTimestamp();
base::TimeDelta max_time = kNoTimestamp();
- base::TimeDelta playback_delay = base::TimeDelta::FromMilliseconds(
- audio_delay_milliseconds);
int frames_written = 0;
base::Closure underflow_cb;
{
base::AutoLock auto_lock(lock_);
+ // Convert milliseconds of delay into frames of delay.
+ buffered_audio_tracker_->AudioCallbackFired(static_cast<int>(
+ static_cast<float>(audio_delay_milliseconds) /
+ base::Time::kMillisecondsPerSecond * audio_parameters_.sample_rate()));
+
// Ensure Stop() hasn't destroyed our |algorithm_| on the pipeline thread.
- if (!algorithm_)
+ if (!algorithm_) {
+ buffered_audio_tracker_->WroteSilence(requested_frames);
scherkus (not reviewing) 2014/04/29 17:22:06 alternatively, we can delete buffered_audio_tracke
DaleCurtis 2014/04/29 17:55:54 I don't think you need to track this. algorithm_ s
return 0;
+ }
float playback_rate = algorithm_->playback_rate();
- if (playback_rate == 0)
+ if (playback_rate == 0) {
+ buffered_audio_tracker_->WroteSilence(requested_frames);
return 0;
+ }
// Mute audio by returning 0 when not playing.
- if (state_ != kPlaying)
+ if (state_ != kPlaying) {
+ buffered_audio_tracker_->WroteSilence(requested_frames);
return 0;
+ }
// We use the following conditions to determine end of playback:
// 1) Algorithm can not fill the audio callback buffer
@@ -627,9 +641,12 @@ int AudioRendererImpl::Render(AudioBus* audio_bus,
weak_factory_.GetWeakPtr()));
}
- // Adjust the delay according to playback rate.
- base::TimeDelta adjusted_playback_delay = base::TimeDelta::FromMicroseconds(
- ceil(playback_delay.InMicroseconds() * playback_rate));
+ // Update buffered audio stats.
+ base::TimeDelta playback_delay = buffered_audio_tracker_->BufferedTime();
+ if (frames_written > 0)
+ buffered_audio_tracker_->WroteAudio(frames_written, playback_rate);
+ if (frames_written < requested_frames)
+ buffered_audio_tracker_->WroteSilence(requested_frames - frames_written);
// The |audio_time_buffered_| is the ending timestamp of the last frame
// buffered at the audio device. |playback_delay| is the amount of time
@@ -637,7 +654,7 @@ int AudioRendererImpl::Render(AudioBus* audio_bus,
// difference.
if (audio_time_buffered_ != kNoTimestamp()) {
base::TimeDelta previous_time = current_time_;
- current_time_ = audio_time_buffered_ - adjusted_playback_delay;
+ current_time_ = audio_time_buffered_ - playback_delay;
// Time can change in one of two ways:
// 1) The time of the audio data at the audio device changed, or
@@ -659,8 +676,7 @@ int AudioRendererImpl::Render(AudioBus* audio_bus,
} else if (frames_written > 0) {
// Nothing has been buffered yet, so use the first buffer's timestamp.
DCHECK(time_before_filling != kNoTimestamp());
- current_time_ = current_time =
- time_before_filling - adjusted_playback_delay;
+ current_time_ = current_time = time_before_filling - playback_delay;
}
// The call to FillBuffer() on |algorithm_| has increased the amount of

Powered by Google App Engine
This is Rietveld 408576698