OLD | NEW |
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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 void AudioOutputController::DoPlay() { | 166 void AudioOutputController::DoPlay() { |
167 DCHECK(message_loop_->BelongsToCurrentThread()); | 167 DCHECK(message_loop_->BelongsToCurrentThread()); |
168 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime"); | 168 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime"); |
169 TRACE_EVENT0("audio", "AudioOutputController::DoPlay"); | 169 TRACE_EVENT0("audio", "AudioOutputController::DoPlay"); |
170 | 170 |
171 // We can start from created or paused state. | 171 // We can start from created or paused state. |
172 if (state_ != kCreated && state_ != kPaused) | 172 if (state_ != kCreated && state_ != kPaused) |
173 return; | 173 return; |
174 | 174 |
175 // Ask for first packet. | 175 // Ask for first packet. |
176 sync_reader_->UpdatePendingBytes(0, 0); | 176 sync_reader_->UpdatePendingBytes(0, 0, AudioTimestamp()); |
177 | 177 |
178 state_ = kPlaying; | 178 state_ = kPlaying; |
179 | 179 |
180 stream_->Start(this); | 180 stream_->Start(this); |
181 | 181 |
182 // For UMA tracking purposes, start the wedge detection timer. This allows us | 182 // For UMA tracking purposes, start the wedge detection timer. This allows us |
183 // to record statistics about the number of wedged playbacks in the field. | 183 // to record statistics about the number of wedged playbacks in the field. |
184 // | 184 // |
185 // WedgeCheck() will look to see if |on_more_io_data_called_| is true after | 185 // WedgeCheck() will look to see if |on_more_io_data_called_| is true after |
186 // the timeout expires. Care must be taken to ensure the wedge check delay is | 186 // 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 Loading... |
219 TRACE_EVENT0("audio", "AudioOutputController::DoPause"); | 219 TRACE_EVENT0("audio", "AudioOutputController::DoPause"); |
220 | 220 |
221 StopStream(); | 221 StopStream(); |
222 | 222 |
223 if (state_ != kPaused) | 223 if (state_ != kPaused) |
224 return; | 224 return; |
225 | 225 |
226 // Let the renderer know we've stopped. Necessary to let PPAPI clients know | 226 // Let the renderer know we've stopped. Necessary to let PPAPI clients know |
227 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have | 227 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have |
228 // a better way to know when it should exit PPB_Audio_Shared::Run(). | 228 // a better way to know when it should exit PPB_Audio_Shared::Run(). |
229 sync_reader_->UpdatePendingBytes(std::numeric_limits<uint32_t>::max(), 0); | 229 sync_reader_->UpdatePendingBytes(std::numeric_limits<uint32_t>::max(), 0, |
| 230 AudioTimestamp()); |
230 | 231 |
231 handler_->OnPaused(); | 232 handler_->OnPaused(); |
232 } | 233 } |
233 | 234 |
234 void AudioOutputController::DoClose() { | 235 void AudioOutputController::DoClose() { |
235 DCHECK(message_loop_->BelongsToCurrentThread()); | 236 DCHECK(message_loop_->BelongsToCurrentThread()); |
236 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime"); | 237 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime"); |
237 TRACE_EVENT0("audio", "AudioOutputController::DoClose"); | 238 TRACE_EVENT0("audio", "AudioOutputController::DoClose"); |
238 | 239 |
239 if (state_ != kClosed) { | 240 if (state_ != kClosed) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 288 } |
288 | 289 |
289 void AudioOutputController::DoReportError() { | 290 void AudioOutputController::DoReportError() { |
290 DCHECK(message_loop_->BelongsToCurrentThread()); | 291 DCHECK(message_loop_->BelongsToCurrentThread()); |
291 if (state_ != kClosed) | 292 if (state_ != kClosed) |
292 handler_->OnError(); | 293 handler_->OnError(); |
293 } | 294 } |
294 | 295 |
295 int AudioOutputController::OnMoreData(AudioBus* dest, | 296 int AudioOutputController::OnMoreData(AudioBus* dest, |
296 uint32_t total_bytes_delay, | 297 uint32_t total_bytes_delay, |
297 uint32_t frames_skipped) { | 298 uint32_t frames_skipped, |
| 299 const AudioTimestamp& output_timestamp) { |
298 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); | 300 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); |
299 | 301 |
300 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() | 302 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() |
301 // may have already fired if OnMoreData() took an abnormal amount of time). | 303 // may have already fired if OnMoreData() took an abnormal amount of time). |
302 // Since this thread is the only writer of |on_more_io_data_called_| once the | 304 // Since this thread is the only writer of |on_more_io_data_called_| once the |
303 // thread starts, its safe to compare and then increment. | 305 // thread starts, its safe to compare and then increment. |
304 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) | 306 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) |
305 base::AtomicRefCountInc(&on_more_io_data_called_); | 307 base::AtomicRefCountInc(&on_more_io_data_called_); |
306 | 308 |
307 sync_reader_->Read(dest); | 309 sync_reader_->Read(dest); |
308 | 310 |
309 const int frames = dest->frames(); | 311 const int frames = dest->frames(); |
310 sync_reader_->UpdatePendingBytes( | 312 sync_reader_->UpdatePendingBytes( |
311 total_bytes_delay + frames * params_.GetBytesPerFrame(), frames_skipped); | 313 total_bytes_delay + frames * params_.GetBytesPerFrame(), frames_skipped, |
| 314 output_timestamp); |
312 | 315 |
313 bool need_to_duplicate = false; | 316 bool need_to_duplicate = false; |
314 { | 317 { |
315 base::AutoLock lock(duplication_targets_lock_); | 318 base::AutoLock lock(duplication_targets_lock_); |
316 need_to_duplicate = !duplication_targets_.empty(); | 319 need_to_duplicate = !duplication_targets_.empty(); |
317 } | 320 } |
318 if (need_to_duplicate) { | 321 if (need_to_duplicate) { |
319 const base::TimeTicks reference_time = | 322 const base::TimeTicks reference_time = |
320 base::TimeTicks::Now() + | 323 base::TimeTicks::Now() + |
321 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * | 324 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 DCHECK(message_loop_->BelongsToCurrentThread()); | 508 DCHECK(message_loop_->BelongsToCurrentThread()); |
506 | 509 |
507 // If we should be playing and we haven't, that's a wedge. | 510 // If we should be playing and we haven't, that's a wedge. |
508 if (state_ == kPlaying) { | 511 if (state_ == kPlaying) { |
509 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 512 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
510 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 513 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
511 } | 514 } |
512 } | 515 } |
513 | 516 |
514 } // namespace media | 517 } // namespace media |
OLD | NEW |