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

Side by Side Diff: media/renderers/audio_renderer_impl.cc

Issue 1136513004: Switch GetWallClockTime to using vectors for input and output. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « media/renderers/audio_renderer_impl.h ('k') | media/renderers/renderer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/renderers/audio_renderer_impl.h" 5 #include "media/renderers/audio_renderer_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 base::TimeDelta current_media_time; 159 base::TimeDelta current_media_time;
160 { 160 {
161 base::AutoLock auto_lock(lock_); 161 base::AutoLock auto_lock(lock_);
162 current_media_time = audio_clock_->front_timestamp(); 162 current_media_time = audio_clock_->front_timestamp();
163 } 163 }
164 164
165 DVLOG(2) << __FUNCTION__ << ": " << current_media_time; 165 DVLOG(2) << __FUNCTION__ << ": " << current_media_time;
166 return current_media_time; 166 return current_media_time;
167 } 167 }
168 168
169 base::TimeTicks AudioRendererImpl::GetWallClockTime(base::TimeDelta time) { 169 bool AudioRendererImpl::GetWallClockTime(
170 const std::vector<base::TimeDelta>& media_timestamps,
171 std::vector<base::TimeTicks>* wall_clock_times) {
170 base::AutoLock auto_lock(lock_); 172 base::AutoLock auto_lock(lock_);
171 if (last_render_ticks_.is_null() || playback_rate_ == 0.0) 173 if (last_render_ticks_.is_null() || !playback_rate_)
172 return base::TimeTicks(); 174 return false;
173 175
174 base::TimeDelta base_time; 176 DCHECK(wall_clock_times->empty());
175 if (time < audio_clock_->front_timestamp()) { 177 wall_clock_times->reserve(media_timestamps.size());
176 // See notes about |time| values less than |base_time| in TimeSource header. 178 for (const auto& media_timestamp : media_timestamps) {
177 base_time = audio_clock_->front_timestamp(); 179 base::TimeDelta base_time;
178 } else if (time > audio_clock_->back_timestamp()) { 180 if (media_timestamp < audio_clock_->front_timestamp()) {
179 base_time = audio_clock_->back_timestamp(); 181 // See notes about |media_time| values less than |base_time| in TimeSource
180 } else { 182 // header.
181 // No need to estimate time, so return the actual wallclock time. 183 base_time = audio_clock_->front_timestamp();
182 return last_render_ticks_ + audio_clock_->TimeUntilPlayback(time); 184 } else if (media_timestamp > audio_clock_->back_timestamp()) {
185 base_time = audio_clock_->back_timestamp();
186 } else {
187 // No need to estimate time, so return the actual wallclock time.
188 wall_clock_times->push_back(
189 last_render_ticks_ +
190 audio_clock_->TimeUntilPlayback(media_timestamp));
xhwang 2015/05/12 04:46:53 nit: will base_time = media_timestamp work? Or are
DaleCurtis 2015/05/12 05:35:42 It would, but I felt it was misleading to have the
191 continue;
192 }
193
194 // In practice, most calls will be estimates given the relatively small
195 // window in which clients can get the actual time.
196 wall_clock_times->push_back(
197 last_render_ticks_ + audio_clock_->TimeUntilPlayback(base_time) +
198 base::TimeDelta::FromMicroseconds(
199 (media_timestamp - base_time).InMicroseconds() / playback_rate_));
183 } 200 }
184 201 return true;
185 // In practice, most calls will be estimates given the relatively small window
186 // in which clients can get the actual time.
187 return last_render_ticks_ + audio_clock_->TimeUntilPlayback(base_time) +
188 base::TimeDelta::FromMicroseconds((time - base_time).InMicroseconds() /
189 playback_rate_);
190 } 202 }
191 203
192 TimeSource* AudioRendererImpl::GetTimeSource() { 204 TimeSource* AudioRendererImpl::GetTimeSource() {
193 return this; 205 return this;
194 } 206 }
195 207
196 void AudioRendererImpl::Flush(const base::Closure& callback) { 208 void AudioRendererImpl::Flush(const base::Closure& callback) {
197 DVLOG(1) << __FUNCTION__; 209 DVLOG(1) << __FUNCTION__;
198 DCHECK(task_runner_->BelongsToCurrentThread()); 210 DCHECK(task_runner_->BelongsToCurrentThread());
199 211
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 << buffering_state; 762 << buffering_state;
751 DCHECK_NE(buffering_state_, buffering_state); 763 DCHECK_NE(buffering_state_, buffering_state);
752 lock_.AssertAcquired(); 764 lock_.AssertAcquired();
753 buffering_state_ = buffering_state; 765 buffering_state_ = buffering_state;
754 766
755 task_runner_->PostTask(FROM_HERE, 767 task_runner_->PostTask(FROM_HERE,
756 base::Bind(buffering_state_cb_, buffering_state_)); 768 base::Bind(buffering_state_cb_, buffering_state_));
757 } 769 }
758 770
759 } // namespace media 771 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/audio_renderer_impl.h ('k') | media/renderers/renderer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698