Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: content/renderer/pepper/pepper_audio_controller.cc

Issue 2755613002: Support audio output device enumeration and selection in PPAPI (Closed)
Patch Set: Should not include local change to ppapi/generators/idl_outfile.py Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Starts playback iff this |PPB_Audio_Impl| object is the
32 // first instance.
33 if (audio_output_hosts_.empty() && ppb_audios_.empty()) {
31 RenderFrameImpl* render_frame = instance_->render_frame(); 34 RenderFrameImpl* render_frame = instance_->render_frame();
32 if (render_frame) 35 if (render_frame)
33 render_frame->PepperStartsPlayback(instance_); 36 render_frame->PepperStartsPlayback(instance_);
34 } 37 }
bbudge 2017/03/23 18:05:44 It might be worth extracting two helper methods, S
Xing 2017/03/29 21:14:32 Done.
35 38
36 ppb_audios_.insert(audio); 39 ppb_audios_.insert(audio);
37 } 40 }
38 41
42 void PepperAudioController::AddInstance(PepperAudioOutputHost* audio_output) {
43 if (!instance_)
44 return;
45 if (audio_output_hosts_.count(audio_output))
46 return;
47
48 // Starts playback iff this |PepperAudioOutputHost| object is the
49 // first instance.
50 if (audio_output_hosts_.empty() && ppb_audios_.empty()) {
51 RenderFrameImpl* render_frame = instance_->render_frame();
52 if (render_frame)
53 render_frame->PepperStartsPlayback(instance_);
54 }
55
56 audio_output_hosts_.insert(audio_output);
57 }
58
39 void PepperAudioController::RemoveInstance(PPB_Audio_Impl* audio) { 59 void PepperAudioController::RemoveInstance(PPB_Audio_Impl* audio) {
40 if (!instance_) 60 if (!instance_)
41 return; 61 return;
42 if (!ppb_audios_.count(audio)) 62 if (!ppb_audios_.count(audio))
43 return; 63 return;
44 64
45 ppb_audios_.erase(audio); 65 ppb_audios_.erase(audio);
46 66
47 if (ppb_audios_.empty()) 67 // Stops playback iff this |PPB_Audio_Impl| object is the
68 // last instance
69 if (audio_output_hosts_.empty() && ppb_audios_.empty())
48 NotifyPlaybackStopsOnEmpty(); 70 NotifyPlaybackStopsOnEmpty();
49 } 71 }
50 72
73 void PepperAudioController::RemoveInstance(
74 PepperAudioOutputHost* audio_output) {
75 if (!instance_)
76 return;
77 if (!audio_output_hosts_.count(audio_output))
78 return;
79
80 audio_output_hosts_.erase(audio_output);
81
82 // Stops playback iff this |PepperAudioOutputHost| object is the
83 // last instance
84 if (audio_output_hosts_.empty() && ppb_audios_.empty())
85 NotifyPlaybackStopsOnEmpty();
86 }
87
51 void PepperAudioController::SetVolume(double volume) { 88 void PepperAudioController::SetVolume(double volume) {
52 if (!instance_) 89 if (!instance_)
53 return; 90 return;
54 91
55 for (auto* ppb_audio : ppb_audios_) 92 for (auto* ppb_audio : ppb_audios_)
56 ppb_audio->SetVolume(volume); 93 ppb_audio->SetVolume(volume);
94
95 for (auto* audio_output_host : audio_output_hosts_)
96 audio_output_host->SetVolume(volume);
57 } 97 }
58 98
59 void PepperAudioController::OnPepperInstanceDeleted() { 99 void PepperAudioController::OnPepperInstanceDeleted() {
60 DCHECK(instance_); 100 DCHECK(instance_);
61 101
62 if (!ppb_audios_.empty()) 102 if (!audio_output_hosts_.empty() || !ppb_audios_.empty())
63 NotifyPlaybackStopsOnEmpty(); 103 NotifyPlaybackStopsOnEmpty();
64 104
65 ppb_audios_.clear(); 105 ppb_audios_.clear();
106 audio_output_hosts_.clear();
66 instance_ = nullptr; 107 instance_ = nullptr;
67 } 108 }
68 109
69 void PepperAudioController::NotifyPlaybackStopsOnEmpty() { 110 void PepperAudioController::NotifyPlaybackStopsOnEmpty() {
70 DCHECK(instance_); 111 DCHECK(instance_);
71 112
72 RenderFrameImpl* render_frame = instance_->render_frame(); 113 RenderFrameImpl* render_frame = instance_->render_frame();
73 if (render_frame) 114 if (render_frame)
74 render_frame->PepperStopsPlayback(instance_); 115 render_frame->PepperStopsPlayback(instance_);
75 } 116 }
76 117
77 } // namespace content 118 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698