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

Side by Side Diff: media/audio/audio_output_controller.cc

Issue 1487983002: Forward the number of skipped frames by the OS in audio playout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Writing skipped frames to shared memory. Created 5 years 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
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/audio/audio_output_controller.h" 5 #include "media/audio/audio_output_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/numerics/safe_conversions.h" 9 #include "base/numerics/safe_conversions.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 void AudioOutputController::DoPlay() { 153 void AudioOutputController::DoPlay() {
154 DCHECK(message_loop_->BelongsToCurrentThread()); 154 DCHECK(message_loop_->BelongsToCurrentThread());
155 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime"); 155 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime");
156 TRACE_EVENT0("audio", "AudioOutputController::DoPlay"); 156 TRACE_EVENT0("audio", "AudioOutputController::DoPlay");
157 157
158 // We can start from created or paused state. 158 // We can start from created or paused state.
159 if (state_ != kCreated && state_ != kPaused) 159 if (state_ != kCreated && state_ != kPaused)
160 return; 160 return;
161 161
162 // Ask for first packet. 162 // Ask for first packet.
163 sync_reader_->UpdatePendingBytes(0); 163 sync_reader_->UpdatePendingBytes(0, 0);
164 164
165 state_ = kPlaying; 165 state_ = kPlaying;
166 166
167 stream_->Start(this); 167 stream_->Start(this);
168 168
169 // For UMA tracking purposes, start the wedge detection timer. This allows us 169 // For UMA tracking purposes, start the wedge detection timer. This allows us
170 // to record statistics about the number of wedged playbacks in the field. 170 // to record statistics about the number of wedged playbacks in the field.
171 // 171 //
172 // WedgeCheck() will look to see if |on_more_io_data_called_| is true after 172 // WedgeCheck() will look to see if |on_more_io_data_called_| is true after
173 // the timeout expires. Care must be taken to ensure the wedge check delay is 173 // the timeout expires. Care must be taken to ensure the wedge check delay is
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 TRACE_EVENT0("audio", "AudioOutputController::DoPause"); 206 TRACE_EVENT0("audio", "AudioOutputController::DoPause");
207 207
208 StopStream(); 208 StopStream();
209 209
210 if (state_ != kPaused) 210 if (state_ != kPaused)
211 return; 211 return;
212 212
213 // Let the renderer know we've stopped. Necessary to let PPAPI clients know 213 // Let the renderer know we've stopped. Necessary to let PPAPI clients know
214 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have 214 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have
215 // a better way to know when it should exit PPB_Audio_Shared::Run(). 215 // a better way to know when it should exit PPB_Audio_Shared::Run().
216 sync_reader_->UpdatePendingBytes(kuint32max); 216 sync_reader_->UpdatePendingBytes(kuint32max, 0);
217 217
218 handler_->OnPaused(); 218 handler_->OnPaused();
219 } 219 }
220 220
221 void AudioOutputController::DoClose() { 221 void AudioOutputController::DoClose() {
222 DCHECK(message_loop_->BelongsToCurrentThread()); 222 DCHECK(message_loop_->BelongsToCurrentThread());
223 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime"); 223 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime");
224 TRACE_EVENT0("audio", "AudioOutputController::DoClose"); 224 TRACE_EVENT0("audio", "AudioOutputController::DoClose");
225 225
226 if (state_ != kClosed) { 226 if (state_ != kClosed) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 OnDeviceChange(); 273 OnDeviceChange();
274 } 274 }
275 275
276 void AudioOutputController::DoReportError() { 276 void AudioOutputController::DoReportError() {
277 DCHECK(message_loop_->BelongsToCurrentThread()); 277 DCHECK(message_loop_->BelongsToCurrentThread());
278 if (state_ != kClosed) 278 if (state_ != kClosed)
279 handler_->OnError(); 279 handler_->OnError();
280 } 280 }
281 281
282 int AudioOutputController::OnMoreData(AudioBus* dest, 282 int AudioOutputController::OnMoreData(AudioBus* dest,
283 uint32 total_bytes_delay) { 283 uint32_t total_bytes_delay,
284 uint32_t frames_skipped) {
284 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); 285 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData");
285 286
286 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() 287 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck()
287 // may have already fired if OnMoreData() took an abnormal amount of time). 288 // may have already fired if OnMoreData() took an abnormal amount of time).
288 // Since this thread is the only writer of |on_more_io_data_called_| once the 289 // Since this thread is the only writer of |on_more_io_data_called_| once the
289 // thread starts, its safe to compare and then increment. 290 // thread starts, its safe to compare and then increment.
290 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) 291 if (base::AtomicRefCountIsZero(&on_more_io_data_called_))
291 base::AtomicRefCountInc(&on_more_io_data_called_); 292 base::AtomicRefCountInc(&on_more_io_data_called_);
292 293
293 sync_reader_->Read(dest); 294 sync_reader_->Read(dest);
294 295
295 const int frames = dest->frames(); 296 const int frames = dest->frames();
296 sync_reader_->UpdatePendingBytes(base::saturated_cast<uint32>( 297 sync_reader_->UpdatePendingBytes(
297 total_bytes_delay + frames * params_.GetBytesPerFrame())); 298 total_bytes_delay + frames * params_.GetBytesPerFrame(), frames_skipped);
298 299
299 if (will_monitor_audio_levels()) 300 if (will_monitor_audio_levels())
300 power_monitor_.Scan(*dest, frames); 301 power_monitor_.Scan(*dest, frames);
301 302
302 return frames; 303 return frames;
303 } 304 }
304 305
305 void AudioOutputController::OnError(AudioOutputStream* stream) { 306 void AudioOutputController::OnError(AudioOutputStream* stream) {
306 { 307 {
307 base::AutoLock auto_lock(error_lock_); 308 base::AutoLock auto_lock(error_lock_);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 DCHECK(message_loop_->BelongsToCurrentThread()); 424 DCHECK(message_loop_->BelongsToCurrentThread());
424 425
425 // If we should be playing and we haven't, that's a wedge. 426 // If we should be playing and we haven't, that's a wedge.
426 if (state_ == kPlaying) { 427 if (state_ == kPlaying) {
427 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", 428 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess",
428 base::AtomicRefCountIsOne(&on_more_io_data_called_)); 429 base::AtomicRefCountIsOne(&on_more_io_data_called_));
429 } 430 }
430 } 431 }
431 432
432 } // namespace media 433 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698