Chromium Code Reviews| Index: media/audio/audio_output_controller.cc |
| =================================================================== |
| --- media/audio/audio_output_controller.cc (revision 104827) |
| +++ media/audio/audio_output_controller.cc (working copy) |
| @@ -13,6 +13,10 @@ |
| // Signal a pause in low-latency mode. |
| const int AudioOutputController::kPauseMark = -1; |
| +// Polling-related constants. |
| +const int AudioOutputController::kPollNumAttempts = 3; |
| +const int AudioOutputController::kPollPauseInMilliseconds = 3; |
| + |
| AudioOutputController::AudioOutputController(EventHandler* handler, |
| uint32 capacity, |
| SyncReader* sync_reader) |
| @@ -23,7 +27,8 @@ |
| buffer_(0, capacity), |
| pending_request_(false), |
| sync_reader_(sync_reader), |
| - message_loop_(NULL) { |
| + message_loop_(NULL), |
| + number_polling_attempts_left_(0) { |
| } |
| AudioOutputController::~AudioOutputController() { |
| @@ -173,6 +178,42 @@ |
| return; |
| state_ = kPlaying; |
| + if (LowLatencyMode()) { |
| + // Ask for first packet. |
| + sync_reader_->UpdatePendingBytes(0); |
| + |
| + // Cannot start stream immediately, should give renderer some time |
| + // to deliver data. |
| + number_polling_attempts_left_ = kPollNumAttempts; |
| + message_loop_->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&AudioOutputController::DoPollIfDataReady, this), |
| + kPollPauseInMilliseconds); |
| + } else |
| + StartStream(); |
| +} |
| + |
| +void AudioOutputController::DoPollIfDataReady() { |
|
acolwell GONE FROM CHROMIUM
2011/10/12 20:14:03
PollAndStartIfDataReady() might be a little more c
enal1
2011/10/13 00:39:22
Done.
|
| + DCHECK_EQ(message_loop_, MessageLoop::current()); |
| + |
| + // Being paranoic: do nothing if we were stopped/paused |
| + // after DoPlay() but before DoStartStream(). |
| + if (state_ != kPlaying) |
| + return; |
| + |
| + if (--number_polling_attempts_left_ == 0 || sync_reader_->DataReady()) |
| + StartStream(); |
| + else { |
| + message_loop_->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&AudioOutputController::DoPollIfDataReady, this), |
| + kPollPauseInMilliseconds); |
| + } |
| +} |
| + |
| +void AudioOutputController::StartStream() { |
| + DCHECK_EQ(message_loop_, MessageLoop::current()); |
| + |
| // We start the AudioOutputStream lazily. |
| stream_->Start(this); |