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

Unified Diff: media/renderers/audio_renderer_impl.cc

Issue 1027553002: Change the TimeSource interface to return wallclock time for video. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment. Created 5 years, 9 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/renderers/audio_renderer_impl.cc
diff --git a/media/renderers/audio_renderer_impl.cc b/media/renderers/audio_renderer_impl.cc
index 74ef1d249526e694db66df69135315b062108fbc..000e5238f452a83df1734d942daec1863863f9eb 100644
--- a/media/renderers/audio_renderer_impl.cc
+++ b/media/renderers/audio_renderer_impl.cc
@@ -166,15 +166,29 @@ base::TimeDelta AudioRendererImpl::CurrentMediaTime() {
return current_media_time;
}
-base::TimeDelta AudioRendererImpl::CurrentMediaTimeForSyncingVideo() {
- DVLOG(3) << __FUNCTION__;
-
+base::TimeTicks AudioRendererImpl::GetWallclockTimeForMediaTime(
+ base::TimeDelta time) {
base::AutoLock auto_lock(lock_);
- if (last_render_ticks_.is_null())
- return audio_clock_->front_timestamp();
+ if (last_render_ticks_.is_null() || playback_rate_ == 0.0)
+ return base::TimeTicks();
+
+ base::TimeDelta base_time;
+ if (time < audio_clock_->front_timestamp()) {
+ // TODO(dalecurtis): This will estimate using the wrong playback rate, if it
+ // has changed recently... Is this actually a problem?
xhwang 2015/03/23 22:20:14 scherkus showed me how time could go backwards in
DaleCurtis 2015/03/25 00:31:45 If someone is rapidly oscillating the playback rat
xhwang 2015/03/25 04:10:50 Just OCC, when time goes backwards, could we rende
+ base_time = audio_clock_->front_timestamp();
+ } else if (time > audio_clock_->back_timestamp()) {
+ base_time = audio_clock_->back_timestamp();
+ } else {
+ // No need to estimate time, so return the actual wallclock time.
+ return last_render_ticks_ + audio_clock_->TimeUntilPlayback(time);
+ }
- return audio_clock_->TimestampSinceWriting(base::TimeTicks::Now() -
- last_render_ticks_);
+ // In practice, most calls will be estimates given the relatively small window
+ // in which clients can get the actual time.
+ return last_render_ticks_ + audio_clock_->TimeUntilPlayback(base_time) +
+ base::TimeDelta::FromMicroseconds((time - base_time).InMicroseconds() /
+ playback_rate_);
}
TimeSource* AudioRendererImpl::GetTimeSource() {

Powered by Google App Engine
This is Rietveld 408576698