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..98a466a7bb087dde201d63b932025904fdf27847 100644 |
| --- a/media/audio/audio_output_controller.cc |
| +++ b/media/audio/audio_output_controller.cc |
| @@ -301,6 +301,20 @@ int AudioOutputController::OnMoreData(AudioBus* dest, |
| sync_reader_->UpdatePendingBytes( |
| total_bytes_delay + frames * params_.GetBytesPerFrame(), frames_skipped); |
| + { |
| + base::AutoLock lock(duplication_targets_lock_); |
| + 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_) { |
| + target->OnData(*dest, reference_time); |
|
miu
2016/05/28 02:45:00
This is going to have the real-time audio thread e
qiangchen
2016/05/31 21:17:33
Done.
|
| + } |
| + } |
| + } |
| + |
| if (will_monitor_audio_levels()) |
| power_monitor_.Scan(*dest, frames); |
| @@ -336,6 +350,7 @@ void AudioOutputController::DoStopCloseAndClearStream() { |
| StopStream(); |
| stream_->Close(); |
| + |
| if (stream_ == diverting_to_stream_) |
| diverting_to_stream_ = NULL; |
| stream_ = NULL; |
| @@ -392,6 +407,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 +446,30 @@ void AudioOutputController::DoStopDiverting() { |
| DCHECK(!diverting_to_stream_); |
| } |
| +void AudioOutputController::DoStartDuplicating(AudioPushSink* to_stream) { |
| + DCHECK(message_loop_->BelongsToCurrentThread()); |
| + if (state_ == kClosed) |
| + return; |
| + |
| + base::AutoLock lock(duplication_targets_lock_); |
| + |
| + // Already serving the stream. |
| + if (duplication_targets_.find(to_stream) != duplication_targets_.end()) |
|
miu
2016/05/28 02:45:00
This isn't necessary since you're inserting into a
qiangchen
2016/05/31 21:17:33
Done.
|
| + return; |
| + |
| + duplication_targets_.insert(to_stream); |
| +} |
| + |
| +void AudioOutputController::DoStopDuplicating(AudioPushSink* to_stream) { |
| + DCHECK(message_loop_->BelongsToCurrentThread()); |
| + to_stream->Close(); |
| + if (state_ == kClosed) |
|
miu
2016/05/28 02:45:00
I'd suggest omitting this early return when state_
qiangchen
2016/05/31 21:17:33
Done.
|
| + return; |
| + |
| + base::AutoLock lock(duplication_targets_lock_); |
| + duplication_targets_.erase(to_stream); |
| +} |
| + |
| std::pair<float, bool> AudioOutputController::ReadCurrentPowerAndClip() { |
| DCHECK(will_monitor_audio_levels()); |
| return power_monitor_.ReadCurrentPowerAndClip(); |