Chromium Code Reviews| Index: media/audio/audio_output_controller.cc |
| diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc |
| index d780687d1b8415aee8f6223be8497905a80b8800..3b161fe82363e34530649f587264bc8ef098ab53 100644 |
| --- a/media/audio/audio_output_controller.cc |
| +++ b/media/audio/audio_output_controller.cc |
| @@ -119,7 +119,8 @@ void AudioOutputController::DoCreate(bool is_for_device_change) { |
| if (state_ == kClosed) |
| return; |
| - DoStopCloseAndClearStream(); // Calls RemoveOutputDeviceChangeListener(). |
| + // Calls RemoveOutputDeviceChangeListener(). |
| + DoStopCloseAndClearStream(is_for_device_change); |
| DCHECK_EQ(kEmpty, state_); |
| stream_ = diverting_to_stream_ ? |
| @@ -132,7 +133,7 @@ void AudioOutputController::DoCreate(bool is_for_device_change) { |
| } |
| if (!stream_->Open()) { |
| - DoStopCloseAndClearStream(); |
| + DoStopCloseAndClearStream(false); |
| state_ = kError; |
| handler_->OnError(); |
| return; |
| @@ -228,7 +229,7 @@ void AudioOutputController::DoClose() { |
| TRACE_EVENT0("audio", "AudioOutputController::DoClose"); |
| if (state_ != kClosed) { |
| - DoStopCloseAndClearStream(); |
| + DoStopCloseAndClearStream(false); |
| sync_reader_->Close(); |
| state_ = kClosed; |
| } |
| @@ -301,6 +302,14 @@ int AudioOutputController::OnMoreData(AudioBus* dest, |
| sync_reader_->UpdatePendingBytes( |
| total_bytes_delay + frames * params_.GetBytesPerFrame(), frames_skipped); |
| + const int64_t kMicrosecondsPerSecond = 1000000; |
|
miu
2016/05/02 20:06:13
Delete this line, and just use base::Time::kMicros
qiangchen
2016/05/03 16:58:23
Done.
|
| + const base::TimeTicks reference_time = |
|
miu
2016/05/02 20:06:13
Please wrap all these lines of code to avoid the c
qiangchen
2016/05/03 16:58:23
Done.
|
| + base::TimeTicks::Now() + base::TimeDelta::FromMicroseconds( |
| + kMicrosecondsPerSecond * total_bytes_delay / |
| + params_.GetBytesPerSecond()); |
| + for (auto& target : duplicating_targets_) |
|
miu
2016/05/02 20:06:13
The "auto&" doesn't help readability here. Please
qiangchen
2016/05/03 16:58:23
Done.
|
| + target->OnData(*dest, reference_time); |
| + |
| if (will_monitor_audio_levels()) |
| power_monitor_.Scan(*dest, frames); |
| @@ -319,7 +328,8 @@ void AudioOutputController::OnError(AudioOutputStream* stream) { |
| &AudioOutputController::DoReportError, this)); |
| } |
| -void AudioOutputController::DoStopCloseAndClearStream() { |
| +void AudioOutputController::DoStopCloseAndClearStream( |
| + bool is_for_device_change) { |
| DCHECK(message_loop_->BelongsToCurrentThread()); |
| // Allow calling unconditionally and bail if we don't have a stream_ to close. |
| @@ -336,6 +346,14 @@ void AudioOutputController::DoStopCloseAndClearStream() { |
| StopStream(); |
| stream_->Close(); |
| + |
| + // Only close duplicating streams when this is really a close class |
| + // For device change call, duplicating streams should remain unchanged. |
| + if (!is_for_device_change) { |
|
miu
2016/05/02 20:06:13
Looks like you don't need this at all. Let the gua
qiangchen
2016/05/03 16:58:23
Done.
|
| + for (auto& target : duplicating_targets_) |
| + target->Close(); |
| + } |
| + |
| if (stream_ == diverting_to_stream_) |
| diverting_to_stream_ = NULL; |
| stream_ = NULL; |
| @@ -392,6 +410,18 @@ void AudioOutputController::StopDiverting() { |
| FROM_HERE, base::Bind(&AudioOutputController::DoStopDiverting, this)); |
| } |
| +void AudioOutputController::StartDuplicating(AudioPushSink* sink) { |
| + message_loop_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AudioOutputController::DoStartDuplicating, this, sink)); |
| +} |
| + |
| +void AudioOutputController::StopDuplicating(AudioPushSink* sink) { |
| + message_loop_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AudioOutputController::DoStopDuplicating, this, sink)); |
| +} |
| + |
| void AudioOutputController::DoStartDiverting(AudioOutputStream* to_stream) { |
| DCHECK(message_loop_->BelongsToCurrentThread()); |
| @@ -419,6 +449,32 @@ void AudioOutputController::DoStopDiverting() { |
| DCHECK(!diverting_to_stream_); |
| } |
| +void AudioOutputController::DoStartDuplicating(AudioPushSink* to_stream) { |
| + DCHECK(message_loop_->BelongsToCurrentThread()); |
| + if (state_ == kClosed) |
| + return; |
| + |
| + // Already serving the stream. |
| + if (duplicating_targets_.find(to_stream) != duplicating_targets_.end()) |
| + return; |
| + |
| + duplicating_targets_.insert(to_stream); |
| +} |
| + |
| +void AudioOutputController::DoStopDuplicating(AudioPushSink* to_stream) { |
| + DCHECK(message_loop_->BelongsToCurrentThread()); |
| + |
| + if (state_ == kClosed) |
| + return; |
|
miu
2016/05/02 20:06:13
You should probably still call to_stream->Close()
qiangchen
2016/05/03 16:58:23
Done.
|
| + |
| + // No such stream. |
| + if (duplicating_targets_.find(to_stream) == duplicating_targets_.end()) |
| + return; |
| + |
| + duplicating_targets_.erase(to_stream); |
| + to_stream->Close(); |
| +} |
| + |
| std::pair<float, bool> AudioOutputController::ReadCurrentPowerAndClip() { |
| DCHECK(will_monitor_audio_levels()); |
| return power_monitor_.ReadCurrentPowerAndClip(); |