OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/pepper/pepper_audio_controller.h" | 5 #include "content/renderer/pepper/pepper_audio_controller.h" |
6 | 6 |
7 #include "content/renderer/pepper/pepper_audio_output_host.h" | |
7 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 8 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
8 #include "content/renderer/pepper/ppb_audio_impl.h" | 9 #include "content/renderer/pepper/ppb_audio_impl.h" |
9 #include "content/renderer/render_frame_impl.h" | 10 #include "content/renderer/render_frame_impl.h" |
10 | 11 |
11 namespace content { | 12 namespace content { |
12 | 13 |
13 PepperAudioController::PepperAudioController( | 14 PepperAudioController::PepperAudioController( |
14 PepperPluginInstanceImpl* instance) | 15 PepperPluginInstanceImpl* instance) |
15 : instance_(instance) { | 16 : instance_(instance) { |
16 DCHECK(instance_); | 17 DCHECK(instance_); |
17 } | 18 } |
18 | 19 |
19 PepperAudioController::~PepperAudioController() { | 20 PepperAudioController::~PepperAudioController() { |
20 if (instance_) | 21 if (instance_) |
21 OnPepperInstanceDeleted(); | 22 OnPepperInstanceDeleted(); |
22 } | 23 } |
23 | 24 |
24 void PepperAudioController::AddInstance(PPB_Audio_Impl* audio) { | 25 void PepperAudioController::AddInstance(PPB_Audio_Impl* audio) { |
25 if (!instance_) | 26 if (!instance_) |
26 return; | 27 return; |
27 if (ppb_audios_.count(audio)) | 28 if (ppb_audios_.count(audio)) |
28 return; | 29 return; |
29 | 30 |
30 if (ppb_audios_.empty()) { | 31 StartPlaybackIfFirstInstance(); |
31 RenderFrameImpl* render_frame = instance_->render_frame(); | |
32 if (render_frame) | |
33 render_frame->PepperStartsPlayback(instance_); | |
34 } | |
35 | 32 |
36 ppb_audios_.insert(audio); | 33 ppb_audios_.insert(audio); |
37 } | 34 } |
38 | 35 |
36 void PepperAudioController::AddInstance(PepperAudioOutputHost* audio_output) { | |
37 if (!instance_) | |
38 return; | |
39 if (audio_output_hosts_.count(audio_output)) | |
40 return; | |
41 | |
42 StartPlaybackIfFirstInstance(); | |
43 | |
44 audio_output_hosts_.insert(audio_output); | |
45 } | |
46 | |
39 void PepperAudioController::RemoveInstance(PPB_Audio_Impl* audio) { | 47 void PepperAudioController::RemoveInstance(PPB_Audio_Impl* audio) { |
40 if (!instance_) | 48 if (!instance_) |
41 return; | 49 return; |
42 if (!ppb_audios_.count(audio)) | 50 if (!ppb_audios_.count(audio)) |
43 return; | 51 return; |
44 | 52 |
45 ppb_audios_.erase(audio); | 53 ppb_audios_.erase(audio); |
46 | 54 |
47 if (ppb_audios_.empty()) | 55 StopPlaybackIfLastInstance(); |
48 NotifyPlaybackStopsOnEmpty(); | 56 } |
57 | |
58 void PepperAudioController::RemoveInstance( | |
59 PepperAudioOutputHost* audio_output) { | |
60 if (!instance_) | |
61 return; | |
62 if (!audio_output_hosts_.count(audio_output)) | |
63 return; | |
64 | |
65 audio_output_hosts_.erase(audio_output); | |
66 | |
67 StopPlaybackIfLastInstance(); | |
49 } | 68 } |
50 | 69 |
51 void PepperAudioController::SetVolume(double volume) { | 70 void PepperAudioController::SetVolume(double volume) { |
52 if (!instance_) | 71 if (!instance_) |
53 return; | 72 return; |
54 | 73 |
55 for (auto* ppb_audio : ppb_audios_) | 74 for (auto* ppb_audio : ppb_audios_) |
56 ppb_audio->SetVolume(volume); | 75 ppb_audio->SetVolume(volume); |
76 | |
77 for (auto* audio_output_host : audio_output_hosts_) | |
78 audio_output_host->SetVolume(volume); | |
57 } | 79 } |
58 | 80 |
59 void PepperAudioController::OnPepperInstanceDeleted() { | 81 void PepperAudioController::OnPepperInstanceDeleted() { |
60 DCHECK(instance_); | 82 DCHECK(instance_); |
61 | 83 |
62 if (!ppb_audios_.empty()) | 84 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
| |
63 NotifyPlaybackStopsOnEmpty(); | |
64 | 85 |
65 ppb_audios_.clear(); | 86 ppb_audios_.clear(); |
87 audio_output_hosts_.clear(); | |
66 instance_ = nullptr; | 88 instance_ = nullptr; |
67 } | 89 } |
68 | 90 |
69 void PepperAudioController::NotifyPlaybackStopsOnEmpty() { | 91 void PepperAudioController::NotifyPlaybackStopsOnEmpty() { |
70 DCHECK(instance_); | 92 DCHECK(instance_); |
71 | 93 |
72 RenderFrameImpl* render_frame = instance_->render_frame(); | 94 RenderFrameImpl* render_frame = instance_->render_frame(); |
73 if (render_frame) | 95 if (render_frame) |
74 render_frame->PepperStopsPlayback(instance_); | 96 render_frame->PepperStopsPlayback(instance_); |
75 } | 97 } |
76 | 98 |
99 void PepperAudioController::StartPlaybackIfFirstInstance() { | |
100 if (instance_) | |
101 return; | |
bbudge
2017/03/31 00:24:59
DCHECK(instance_);
Rather than if - statement, be
Xing
2017/03/31 18:23:29
Done.
| |
102 | |
103 if (audio_output_hosts_.empty() && ppb_audios_.empty()) { | |
104 RenderFrameImpl* render_frame = instance_->render_frame(); | |
105 if (render_frame) | |
106 render_frame->PepperStartsPlayback(instance_); | |
107 } | |
108 } | |
109 | |
110 void PepperAudioController::StopPlaybackIfLastInstance() { | |
111 if (instance_) | |
112 return; | |
bbudge
2017/03/31 00:24:59
DCHECK(instance_)
Xing
2017/03/31 18:23:29
Done.
| |
113 | |
114 if (audio_output_hosts_.empty() && ppb_audios_.empty()) | |
115 NotifyPlaybackStopsOnEmpty(); | |
116 } | |
117 | |
77 } // namespace content | 118 } // namespace content |
OLD | NEW |