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

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: Fix format, Rebase Created 3 years, 8 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 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 if (!audio_output_hosts_.empty() || !ppb_audios_.empty())
63 NotifyPlaybackStopsOnEmpty(); 85 NotifyPlaybackStopsOnEmpty();
64 86
65 ppb_audios_.clear(); 87 ppb_audios_.clear();
88 audio_output_hosts_.clear();
66 instance_ = nullptr; 89 instance_ = nullptr;
67 } 90 }
68 91
69 void PepperAudioController::NotifyPlaybackStopsOnEmpty() { 92 void PepperAudioController::NotifyPlaybackStopsOnEmpty() {
70 DCHECK(instance_); 93 DCHECK(instance_);
71 94
72 RenderFrameImpl* render_frame = instance_->render_frame(); 95 RenderFrameImpl* render_frame = instance_->render_frame();
73 if (render_frame) 96 if (render_frame)
74 render_frame->PepperStopsPlayback(instance_); 97 render_frame->PepperStopsPlayback(instance_);
75 } 98 }
76 99
100 void PepperAudioController::StartPlaybackIfFirstInstance() {
101 DCHECK(instance_);
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 DCHECK(instance_);
112
113 if (audio_output_hosts_.empty() && ppb_audios_.empty())
114 NotifyPlaybackStopsOnEmpty();
115 }
116
77 } // namespace content 117 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_audio_controller.h ('k') | content/renderer/pepper/pepper_audio_output_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698