Chromium Code Reviews| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | |
| 15 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 16 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 19 #include "media/base/audio_timestamp_helper.h" | 20 #include "media/base/audio_timestamp_helper.h" |
| 20 | 21 |
| 21 using base::TimeDelta; | 22 using base::TimeDelta; |
| 22 | 23 |
| 23 namespace media { | 24 namespace media { |
| 24 | 25 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 CHECK_EQ(AudioManager::Get(), audio_manager_); | 101 CHECK_EQ(AudioManager::Get(), audio_manager_); |
| 101 message_loop_->PostTask( | 102 message_loop_->PostTask( |
| 102 FROM_HERE, | 103 FROM_HERE, |
| 103 base::BindOnce(&AudioOutputController::DoSetVolume, this, volume)); | 104 base::BindOnce(&AudioOutputController::DoSetVolume, this, volume)); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void AudioOutputController::DoCreate(bool is_for_device_change) { | 107 void AudioOutputController::DoCreate(bool is_for_device_change) { |
| 107 DCHECK(message_loop_->BelongsToCurrentThread()); | 108 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 108 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CreateTime"); | 109 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CreateTime"); |
| 109 TRACE_EVENT0("audio", "AudioOutputController::DoCreate"); | 110 TRACE_EVENT0("audio", "AudioOutputController::DoCreate"); |
| 111 handler_->OnLog(base::StringPrintf("AOC::DoCreate (for device change: %s)", | |
|
Max Morin
2017/05/29 08:12:53
I think we should consider having a common logging
ossu-chromium
2017/05/29 14:19:43
It should be possible to grep for these lines from
Max Morin
2017/05/29 14:25:44
Sounds good.
| |
| 112 is_for_device_change ? "yes" : "no")); | |
| 110 | 113 |
| 111 // Close() can be called before DoCreate() is executed. | 114 // Close() can be called before DoCreate() is executed. |
| 112 if (state_ == kClosed) | 115 if (state_ == kClosed) |
| 113 return; | 116 return; |
| 114 | 117 |
| 115 DoStopCloseAndClearStream(); // Calls RemoveOutputDeviceChangeListener(). | 118 DoStopCloseAndClearStream(); // Calls RemoveOutputDeviceChangeListener(). |
| 116 DCHECK_EQ(kEmpty, state_); | 119 DCHECK_EQ(kEmpty, state_); |
| 117 | 120 |
| 118 stream_ = diverting_to_stream_ ? | 121 stream_ = diverting_to_stream_ ? |
| 119 diverting_to_stream_ : | 122 diverting_to_stream_ : |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 144 | 147 |
| 145 // And then report we have been created if we haven't done so already. | 148 // And then report we have been created if we haven't done so already. |
| 146 if (!is_for_device_change) | 149 if (!is_for_device_change) |
| 147 handler_->OnControllerCreated(); | 150 handler_->OnControllerCreated(); |
| 148 } | 151 } |
| 149 | 152 |
| 150 void AudioOutputController::DoPlay() { | 153 void AudioOutputController::DoPlay() { |
| 151 DCHECK(message_loop_->BelongsToCurrentThread()); | 154 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 152 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime"); | 155 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime"); |
| 153 TRACE_EVENT0("audio", "AudioOutputController::DoPlay"); | 156 TRACE_EVENT0("audio", "AudioOutputController::DoPlay"); |
| 157 handler_->OnLog("AOC::DoPlay"); | |
| 154 | 158 |
| 155 // We can start from created or paused state. | 159 // We can start from created or paused state. |
| 156 if (state_ != kCreated && state_ != kPaused) | 160 if (state_ != kCreated && state_ != kPaused) |
| 157 return; | 161 return; |
| 158 | 162 |
| 159 // Ask for first packet. | 163 // Ask for first packet. |
| 160 sync_reader_->RequestMoreData(base::TimeDelta(), base::TimeTicks(), 0); | 164 sync_reader_->RequestMoreData(base::TimeDelta(), base::TimeTicks(), 0); |
| 161 | 165 |
| 162 state_ = kPlaying; | 166 state_ = kPlaying; |
| 163 | 167 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 194 power_monitor_.Reset(); | 198 power_monitor_.Reset(); |
| 195 | 199 |
| 196 state_ = kPaused; | 200 state_ = kPaused; |
| 197 } | 201 } |
| 198 } | 202 } |
| 199 | 203 |
| 200 void AudioOutputController::DoPause() { | 204 void AudioOutputController::DoPause() { |
| 201 DCHECK(message_loop_->BelongsToCurrentThread()); | 205 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 202 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PauseTime"); | 206 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PauseTime"); |
| 203 TRACE_EVENT0("audio", "AudioOutputController::DoPause"); | 207 TRACE_EVENT0("audio", "AudioOutputController::DoPause"); |
| 208 handler_->OnLog("AOC::DoPause"); | |
| 204 | 209 |
| 205 StopStream(); | 210 StopStream(); |
| 206 | 211 |
| 207 if (state_ != kPaused) | 212 if (state_ != kPaused) |
| 208 return; | 213 return; |
| 209 | 214 |
| 210 // Let the renderer know we've stopped. Necessary to let PPAPI clients know | 215 // Let the renderer know we've stopped. Necessary to let PPAPI clients know |
| 211 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have | 216 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have |
| 212 // a better way to know when it should exit PPB_Audio_Shared::Run(). | 217 // a better way to know when it should exit PPB_Audio_Shared::Run(). |
| 213 sync_reader_->RequestMoreData(base::TimeDelta::Max(), base::TimeTicks(), 0); | 218 sync_reader_->RequestMoreData(base::TimeDelta::Max(), base::TimeTicks(), 0); |
| 214 | 219 |
| 215 handler_->OnControllerPaused(); | 220 handler_->OnControllerPaused(); |
| 216 } | 221 } |
| 217 | 222 |
| 218 void AudioOutputController::DoClose() { | 223 void AudioOutputController::DoClose() { |
| 219 DCHECK(message_loop_->BelongsToCurrentThread()); | 224 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 220 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime"); | 225 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime"); |
| 221 TRACE_EVENT0("audio", "AudioOutputController::DoClose"); | 226 TRACE_EVENT0("audio", "AudioOutputController::DoClose"); |
| 227 handler_->OnLog("AOC::DoClose"); | |
| 222 | 228 |
| 223 if (state_ != kClosed) { | 229 if (state_ != kClosed) { |
| 224 DoStopCloseAndClearStream(); | 230 DoStopCloseAndClearStream(); |
| 225 sync_reader_->Close(); | 231 sync_reader_->Close(); |
| 226 state_ = kClosed; | 232 state_ = kClosed; |
| 227 } | 233 } |
| 228 } | 234 } |
| 229 | 235 |
| 230 void AudioOutputController::DoSetVolume(double volume) { | 236 void AudioOutputController::DoSetVolume(double volume) { |
| 231 DCHECK(message_loop_->BelongsToCurrentThread()); | 237 DCHECK(message_loop_->BelongsToCurrentThread()); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 } | 352 } |
| 347 | 353 |
| 348 state_ = kEmpty; | 354 state_ = kEmpty; |
| 349 } | 355 } |
| 350 | 356 |
| 351 void AudioOutputController::OnDeviceChange() { | 357 void AudioOutputController::OnDeviceChange() { |
| 352 DCHECK(message_loop_->BelongsToCurrentThread()); | 358 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 353 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.DeviceChangeTime"); | 359 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.DeviceChangeTime"); |
| 354 TRACE_EVENT0("audio", "AudioOutputController::OnDeviceChange"); | 360 TRACE_EVENT0("audio", "AudioOutputController::OnDeviceChange"); |
| 355 | 361 |
| 362 auto state_to_string = [](State state) { | |
| 363 switch (state) { | |
| 364 case AudioOutputController::kEmpty: | |
| 365 return "empty"; | |
| 366 case AudioOutputController::kCreated: | |
| 367 return "created"; | |
| 368 case AudioOutputController::kPlaying: | |
| 369 return "playing"; | |
| 370 case AudioOutputController::kPaused: | |
| 371 return "paused"; | |
| 372 case AudioOutputController::kClosed: | |
| 373 return "closed"; | |
| 374 case AudioOutputController::kError: | |
| 375 return "error"; | |
| 376 }; | |
| 377 return "unknown"; | |
| 378 }; | |
| 379 | |
| 380 handler_->OnLog(base::StringPrintf("AOC::OnDeviceChange while in state: %s", | |
| 381 state_to_string(state_))); | |
| 382 | |
| 356 // TODO(dalecurtis): Notify the renderer side that a device change has | 383 // TODO(dalecurtis): Notify the renderer side that a device change has |
| 357 // occurred. Currently querying the hardware information here will lead to | 384 // occurred. Currently querying the hardware information here will lead to |
| 358 // crashes on OSX. See http://crbug.com/158170. | 385 // crashes on OSX. See http://crbug.com/158170. |
| 359 | 386 |
| 360 // Recreate the stream (DoCreate() will first shut down an existing stream). | 387 // Recreate the stream (DoCreate() will first shut down an existing stream). |
| 361 // Exit if we ran into an error. | 388 // Exit if we ran into an error. |
| 362 const State original_state = state_; | 389 const State original_state = state_; |
| 363 DoCreate(true); | 390 DoCreate(true); |
| 364 if (!stream_ || state_ == kError) | 391 if (!stream_ || state_ == kError) |
| 365 return; | 392 return; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 DCHECK(message_loop_->BelongsToCurrentThread()); | 490 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 464 | 491 |
| 465 // If we should be playing and we haven't, that's a wedge. | 492 // If we should be playing and we haven't, that's a wedge. |
| 466 if (state_ == kPlaying) { | 493 if (state_ == kPlaying) { |
| 467 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 494 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
| 468 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 495 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
| 469 } | 496 } |
| 470 } | 497 } |
| 471 | 498 |
| 472 } // namespace media | 499 } // namespace media |
| OLD | NEW |