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

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

Issue 2239243002: Interpolate media time for mojo rendering pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moves media-time clamping to PipelineImpl Created 4 years, 3 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/audio_renderer_impl_unittest.cc » ('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 #include <stddef.h> 8 #include <stddef.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 DCHECK(task_runner_->BelongsToCurrentThread()); 170 DCHECK(task_runner_->BelongsToCurrentThread());
171 171
172 base::AutoLock auto_lock(lock_); 172 base::AutoLock auto_lock(lock_);
173 DCHECK(!rendering_); 173 DCHECK(!rendering_);
174 DCHECK_EQ(state_, kFlushed); 174 DCHECK_EQ(state_, kFlushed);
175 175
176 start_timestamp_ = time; 176 start_timestamp_ = time;
177 ended_timestamp_ = kInfiniteDuration; 177 ended_timestamp_ = kInfiniteDuration;
178 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); 178 last_render_time_ = stop_rendering_time_ = base::TimeTicks();
179 first_packet_timestamp_ = kNoTimestamp; 179 first_packet_timestamp_ = kNoTimestamp;
180 last_media_timestamp_ = base::TimeDelta();
181 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate())); 180 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate()));
182 } 181 }
183 182
184 base::TimeDelta AudioRendererImpl::CurrentMediaTime() { 183 base::TimeDelta AudioRendererImpl::CurrentMediaTime() {
185 base::AutoLock auto_lock(lock_); 184 base::AutoLock auto_lock(lock_);
186 185
187 // Return the current time based on the known extents of the rendered audio 186 // Return the current time based on the known extents of the rendered audio
188 // data plus an estimate based on the last time those values were calculated. 187 // data plus an estimate based on the last time those values were calculated.
189 base::TimeDelta current_media_time = audio_clock_->front_timestamp(); 188 base::TimeDelta current_media_time = audio_clock_->front_timestamp();
190 if (!last_render_time_.is_null()) { 189 if (!last_render_time_.is_null()) {
191 current_media_time += 190 current_media_time +=
192 (tick_clock_->NowTicks() - last_render_time_) * playback_rate_; 191 (tick_clock_->NowTicks() - last_render_time_) * playback_rate_;
193 if (current_media_time > audio_clock_->back_timestamp()) 192 if (current_media_time > audio_clock_->back_timestamp())
194 current_media_time = audio_clock_->back_timestamp(); 193 current_media_time = audio_clock_->back_timestamp();
195 } 194 }
196 195
197 // Clamp current media time to the last reported value, this prevents higher
198 // level clients from seeing time go backwards based on inaccurate or spurious
199 // delay values reported to the AudioClock.
200 //
201 // It is expected that such events are transient and will be recovered as
202 // rendering continues over time.
203 if (current_media_time < last_media_timestamp_) {
204 DVLOG(2) << __func__ << ": " << last_media_timestamp_
205 << " (clamped), actual: " << current_media_time;
206 return last_media_timestamp_;
207 }
208
209 DVLOG(2) << __func__ << ": " << current_media_time;
210 last_media_timestamp_ = current_media_time;
211 return current_media_time; 196 return current_media_time;
212 } 197 }
213 198
214 bool AudioRendererImpl::GetWallClockTimes( 199 bool AudioRendererImpl::GetWallClockTimes(
215 const std::vector<base::TimeDelta>& media_timestamps, 200 const std::vector<base::TimeDelta>& media_timestamps,
216 std::vector<base::TimeTicks>* wall_clock_times) { 201 std::vector<base::TimeTicks>* wall_clock_times) {
217 base::AutoLock auto_lock(lock_); 202 base::AutoLock auto_lock(lock_);
218 DCHECK(wall_clock_times->empty()); 203 DCHECK(wall_clock_times->empty());
219 204
220 // When playback is paused (rate is zero), assume a rate of 1.0. 205 // When playback is paused (rate is zero), assume a rate of 1.0.
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 DCHECK_NE(buffering_state_, buffering_state); 953 DCHECK_NE(buffering_state_, buffering_state);
969 lock_.AssertAcquired(); 954 lock_.AssertAcquired();
970 buffering_state_ = buffering_state; 955 buffering_state_ = buffering_state;
971 956
972 task_runner_->PostTask( 957 task_runner_->PostTask(
973 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, 958 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange,
974 weak_factory_.GetWeakPtr(), buffering_state_)); 959 weak_factory_.GetWeakPtr(), buffering_state_));
975 } 960 }
976 961
977 } // namespace media 962 } // namespace media
OLDNEW
« 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