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

Unified Diff: media/renderers/audio_renderer_impl.cc

Issue 2472183004: [TO 54] AudioRendererImpl: Don't advance time when rendering stops. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « media/renderers/audio_renderer_impl.h ('k') | media/renderers/audio_renderer_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/renderers/audio_renderer_impl.cc
diff --git a/media/renderers/audio_renderer_impl.cc b/media/renderers/audio_renderer_impl.cc
index ce94d751ce42fbe6eb1a3dcb845fe977734775f2..1349cb03b262f0ae931da431bf42d17053adf273 100644
--- a/media/renderers/audio_renderer_impl.cc
+++ b/media/renderers/audio_renderer_impl.cc
@@ -102,10 +102,12 @@ AudioRendererImpl::~AudioRendererImpl() {
void AudioRendererImpl::StartTicking() {
DVLOG(1) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
+
+ base::AutoLock auto_lock(lock_);
+
DCHECK(!rendering_);
rendering_ = true;
- base::AutoLock auto_lock(lock_);
// Wait for an eventual call to SetPlaybackRate() to start rendering.
if (playback_rate_ == 0) {
DCHECK(!sink_playing_);
@@ -132,10 +134,12 @@ void AudioRendererImpl::StartRendering_Locked() {
void AudioRendererImpl::StopTicking() {
DVLOG(1) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
+
+ base::AutoLock auto_lock(lock_);
+
DCHECK(rendering_);
rendering_ = false;
- base::AutoLock auto_lock(lock_);
// Rendering should have already been stopped with a zero playback rate.
if (playback_rate_ == 0) {
DCHECK(!sink_playing_);
@@ -172,11 +176,27 @@ void AudioRendererImpl::SetMediaTime(base::TimeDelta time) {
first_packet_timestamp_ = kNoTimestamp;
last_media_timestamp_ = base::TimeDelta();
audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate()));
+ last_reported_media_time_ = kNoTimestamp;
}
base::TimeDelta AudioRendererImpl::CurrentMediaTime() {
base::AutoLock auto_lock(lock_);
+ // Re-use last reported time if rendering has stopped to avoid confusing blink
+ // layer (avoid currentTime advancing after signaling buffer underflow).
+ // TODO(chcunningham): Do this in blink instead. Patching it here for now
+ // because HTMLMediaElement's currentTime is a mess.
+ if (!rendering_ && last_reported_media_time_ != kNoTimestamp) {
+ // If rendering stops, be sure to at least report the front time of the most
+ // recently rendered audio buffer.
+ if (last_reported_media_time_ < audio_clock_->front_timestamp())
+ last_reported_media_time_ = audio_clock_->front_timestamp();
+
+ DVLOG(3) << __func__ << " Returning cached time while rendering stopped:"
+ << last_reported_media_time_.InMicroseconds();
+ return last_reported_media_time_;
+ }
+
// Return the current time based on the known extents of the rendered audio
// data plus an estimate based on the last time those values were calculated.
base::TimeDelta current_media_time = audio_clock_->front_timestamp();
@@ -201,6 +221,7 @@ base::TimeDelta AudioRendererImpl::CurrentMediaTime() {
DVLOG(2) << __func__ << ": " << current_media_time;
last_media_timestamp_ = current_media_time;
+ last_reported_media_time_ = current_media_time;
return current_media_time;
}
@@ -445,6 +466,7 @@ void AudioRendererImpl::Initialize(DemuxerStream* stream,
audio_clock_.reset(
new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate()));
+ last_reported_media_time_ = kNoTimestamp;
audio_buffer_stream_->Initialize(
stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized,
« no previous file with comments | « media/renderers/audio_renderer_impl.h ('k') | media/renderers/audio_renderer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698