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

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

Issue 1129323003: Allow callers of TimeSource::GetWallClockTime() to suspend time. (Closed) Base URL: http://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 base::TimeTicks AudioRendererImpl::GetWallClockTime(base::TimeDelta time,
170 base::AutoLock auto_lock(lock_); 170 int request_flags) {
171 if (last_render_ticks_.is_null() || playback_rate_ == 0.0) 171 if (request_flags & SUSPEND_TIME)
172 lock_.Acquire();
173
174 lock_.AssertAcquired();
175 if (last_render_ticks_.is_null() || playback_rate_ == 0.0) {
176 lock_.Release();
172 return base::TimeTicks(); 177 return base::TimeTicks();
178 }
173 179
174 base::TimeDelta base_time; 180 base::TimeDelta base_time;
175 if (time < audio_clock_->front_timestamp()) { 181 if (time < audio_clock_->front_timestamp()) {
176 // See notes about |time| values less than |base_time| in TimeSource header. 182 // See notes about |time| values less than |base_time| in TimeSource header.
177 base_time = audio_clock_->front_timestamp(); 183 base_time = audio_clock_->front_timestamp();
178 } else if (time > audio_clock_->back_timestamp()) { 184 } else if (time > audio_clock_->back_timestamp()) {
179 base_time = audio_clock_->back_timestamp(); 185 base_time = audio_clock_->back_timestamp();
180 } else { 186 } else {
181 // No need to estimate time, so return the actual wallclock time. 187 // No need to estimate time, so return the actual wallclock time.
182 return last_render_ticks_ + audio_clock_->TimeUntilPlayback(time); 188 const base::TimeTicks result =
189 last_render_ticks_ + audio_clock_->TimeUntilPlayback(time);
190
191 if (request_flags & RESUME_TIME)
192 lock_.Release();
193
194 return result;
183 } 195 }
184 196
185 // In practice, most calls will be estimates given the relatively small window 197 // In practice, most calls will be estimates given the relatively small window
186 // in which clients can get the actual time. 198 // in which clients can get the actual time.
187 return last_render_ticks_ + audio_clock_->TimeUntilPlayback(base_time) + 199 const base::TimeTicks result =
188 base::TimeDelta::FromMicroseconds((time - base_time).InMicroseconds() / 200 last_render_ticks_ + audio_clock_->TimeUntilPlayback(base_time) +
189 playback_rate_); 201 base::TimeDelta::FromMicroseconds((time - base_time).InMicroseconds() /
202 playback_rate_);
203
204 if (request_flags & RESUME_TIME)
205 lock_.Release();
206
207 return result;
190 } 208 }
191 209
192 TimeSource* AudioRendererImpl::GetTimeSource() { 210 TimeSource* AudioRendererImpl::GetTimeSource() {
193 return this; 211 return this;
194 } 212 }
195 213
196 void AudioRendererImpl::Flush(const base::Closure& callback) { 214 void AudioRendererImpl::Flush(const base::Closure& callback) {
197 DVLOG(1) << __FUNCTION__; 215 DVLOG(1) << __FUNCTION__;
198 DCHECK(task_runner_->BelongsToCurrentThread()); 216 DCHECK(task_runner_->BelongsToCurrentThread());
199 217
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 << buffering_state; 768 << buffering_state;
751 DCHECK_NE(buffering_state_, buffering_state); 769 DCHECK_NE(buffering_state_, buffering_state);
752 lock_.AssertAcquired(); 770 lock_.AssertAcquired();
753 buffering_state_ = buffering_state; 771 buffering_state_ = buffering_state;
754 772
755 task_runner_->PostTask(FROM_HERE, 773 task_runner_->PostTask(FROM_HERE,
756 base::Bind(buffering_state_cb_, buffering_state_)); 774 base::Bind(buffering_state_cb_, buffering_state_));
757 } 775 }
758 776
759 } // namespace media 777 } // 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