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..08627a779dc23792b8b8834c4f1e1fd455c8a089 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(); |
|
miu
2016/05/06 22:29:50
nit: Comment can go at end-of-line (like it was be
qiangchen
2016/05/10 22:36:53
Done.
|
| DCHECK_EQ(kEmpty, state_); |
| stream_ = diverting_to_stream_ ? |
| @@ -301,6 +302,17 @@ int AudioOutputController::OnMoreData(AudioBus* dest, |
| sync_reader_->UpdatePendingBytes( |
| total_bytes_delay + frames * params_.GetBytesPerFrame(), frames_skipped); |
| + if (!duplication_targets_.empty()) { |
| + const base::TimeTicks reference_time = |
| + base::TimeTicks::Now() + |
| + base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * |
| + total_bytes_delay / |
| + params_.GetBytesPerSecond()); |
| + for (AudioPushSink* target : duplication_targets_) { |
|
miu
2016/05/06 22:37:06
Oh, I just realized something critical here: This
DaleCurtis
2016/05/09 18:53:25
I'm more worried about what each target may do wit
qiangchen
2016/05/10 22:36:53
Thanks for suggestions.
After my investigation, w
|
| + target->OnData(*dest, reference_time); |
| + } |
| + } |
| + |
| if (will_monitor_audio_levels()) |
| power_monitor_.Scan(*dest, frames); |
| @@ -336,6 +348,7 @@ void AudioOutputController::DoStopCloseAndClearStream() { |
| StopStream(); |
| stream_->Close(); |
| + |
| if (stream_ == diverting_to_stream_) |
| diverting_to_stream_ = NULL; |
| stream_ = NULL; |
| @@ -392,6 +405,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 +444,28 @@ 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 (duplication_targets_.find(to_stream) != duplication_targets_.end()) |
| + return; |
| + |
| + duplication_targets_.insert(to_stream); |
| +} |
| + |
| +void AudioOutputController::DoStopDuplicating(AudioPushSink* to_stream) { |
| + DCHECK(message_loop_->BelongsToCurrentThread()); |
| + |
| + to_stream->Close(); |
| + if (state_ == kClosed) |
| + return; |
| + |
| + duplication_targets_.erase(to_stream); |
| +} |
| + |
| std::pair<float, bool> AudioOutputController::ReadCurrentPowerAndClip() { |
| DCHECK(will_monitor_audio_levels()); |
| return power_monitor_.ReadCurrentPowerAndClip(); |