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

Unified Diff: media/renderers/audio_renderer_impl.cc

Issue 2423903003: AudioRendererImpl: Don't advance time when rendering stops. (Closed)
Patch Set: feedback Created 4 years, 2 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
« 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 c653bfccbdcbe95ac2c3ba0a522a46b9ec607e66..66fe2b79609856ac85bd7896754f36f3920aa48c 100644
--- a/media/renderers/audio_renderer_impl.cc
+++ b/media/renderers/audio_renderer_impl.cc
@@ -57,6 +57,7 @@ AudioRendererImpl::AudioRendererImpl(
received_end_of_stream_(false),
rendered_end_of_stream_(false),
is_suspending_(false),
+ last_reported_media_time_(kNoTimestamp),
weak_factory_(this) {
audio_buffer_stream_->set_splice_observer(base::Bind(
&AudioRendererImpl::OnNewSpliceBuffer, weak_factory_.GetWeakPtr()));
@@ -171,11 +172,27 @@ void AudioRendererImpl::SetMediaTime(base::TimeDelta time) {
last_render_time_ = stop_rendering_time_ = base::TimeTicks();
first_packet_timestamp_ = kNoTimestamp;
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();
@@ -186,6 +203,7 @@ base::TimeDelta AudioRendererImpl::CurrentMediaTime() {
current_media_time = audio_clock_->back_timestamp();
}
+ last_reported_media_time_ = current_media_time;
return current_media_time;
}
@@ -430,6 +448,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