Chromium Code Reviews| Index: content/renderer/pepper/pepper_audio_controller.cc |
| diff --git a/content/renderer/pepper/pepper_audio_controller.cc b/content/renderer/pepper/pepper_audio_controller.cc |
| index 88d80f11bd02c441888e1403291875582f4b4e00..8abf3850200d2048be419b5b6543f69279c80ee2 100644 |
| --- a/content/renderer/pepper/pepper_audio_controller.cc |
| +++ b/content/renderer/pepper/pepper_audio_controller.cc |
| @@ -4,6 +4,7 @@ |
| #include "content/renderer/pepper/pepper_audio_controller.h" |
| +#include "content/renderer/pepper/pepper_audio_output_host.h" |
| #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| #include "content/renderer/pepper/ppb_audio_impl.h" |
| #include "content/renderer/render_frame_impl.h" |
| @@ -27,15 +28,22 @@ void PepperAudioController::AddInstance(PPB_Audio_Impl* audio) { |
| if (ppb_audios_.count(audio)) |
| return; |
| - if (ppb_audios_.empty()) { |
| - RenderFrameImpl* render_frame = instance_->render_frame(); |
| - if (render_frame) |
| - render_frame->PepperStartsPlayback(instance_); |
| - } |
| + StartPlaybackIfFirstInstance(); |
| ppb_audios_.insert(audio); |
| } |
| +void PepperAudioController::AddInstance(PepperAudioOutputHost* audio_output) { |
| + if (!instance_) |
| + return; |
| + if (audio_output_hosts_.count(audio_output)) |
| + return; |
| + |
| + StartPlaybackIfFirstInstance(); |
| + |
| + audio_output_hosts_.insert(audio_output); |
| +} |
| + |
| void PepperAudioController::RemoveInstance(PPB_Audio_Impl* audio) { |
| if (!instance_) |
| return; |
| @@ -44,8 +52,19 @@ void PepperAudioController::RemoveInstance(PPB_Audio_Impl* audio) { |
| ppb_audios_.erase(audio); |
| - if (ppb_audios_.empty()) |
| - NotifyPlaybackStopsOnEmpty(); |
| + StopPlaybackIfLastInstance(); |
| +} |
| + |
| +void PepperAudioController::RemoveInstance( |
| + PepperAudioOutputHost* audio_output) { |
| + if (!instance_) |
| + return; |
| + if (!audio_output_hosts_.count(audio_output)) |
| + return; |
| + |
| + audio_output_hosts_.erase(audio_output); |
| + |
| + StopPlaybackIfLastInstance(); |
| } |
| void PepperAudioController::SetVolume(double volume) { |
| @@ -54,15 +73,18 @@ void PepperAudioController::SetVolume(double volume) { |
| for (auto* ppb_audio : ppb_audios_) |
| ppb_audio->SetVolume(volume); |
| + |
| + for (auto* audio_output_host : audio_output_hosts_) |
| + audio_output_host->SetVolume(volume); |
| } |
| void PepperAudioController::OnPepperInstanceDeleted() { |
| DCHECK(instance_); |
| - if (!ppb_audios_.empty()) |
| - NotifyPlaybackStopsOnEmpty(); |
| + StopPlaybackIfLastInstance(); |
|
bbudge
2017/03/31 00:24:59
I'm sorry if I led you astray here, the original t
Xing
2017/03/31 18:23:29
It's totally my mistake, sorry about my careless c
|
| ppb_audios_.clear(); |
| + audio_output_hosts_.clear(); |
| instance_ = nullptr; |
| } |
| @@ -74,4 +96,23 @@ void PepperAudioController::NotifyPlaybackStopsOnEmpty() { |
| render_frame->PepperStopsPlayback(instance_); |
| } |
| +void PepperAudioController::StartPlaybackIfFirstInstance() { |
| + if (instance_) |
| + return; |
|
bbudge
2017/03/31 00:24:59
DCHECK(instance_);
Rather than if - statement, be
Xing
2017/03/31 18:23:29
Done.
|
| + |
| + if (audio_output_hosts_.empty() && ppb_audios_.empty()) { |
| + RenderFrameImpl* render_frame = instance_->render_frame(); |
| + if (render_frame) |
| + render_frame->PepperStartsPlayback(instance_); |
| + } |
| +} |
| + |
| +void PepperAudioController::StopPlaybackIfLastInstance() { |
| + if (instance_) |
| + return; |
|
bbudge
2017/03/31 00:24:59
DCHECK(instance_)
Xing
2017/03/31 18:23:29
Done.
|
| + |
| + if (audio_output_hosts_.empty() && ppb_audios_.empty()) |
| + NotifyPlaybackStopsOnEmpty(); |
| +} |
| + |
| } // namespace content |