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

Unified 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 side-by-side diff with in-line comments
Download patch
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..759666ea3a7fb0718dfdc6714d805c1fb1e34d08 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,19 @@ 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())
+ if (!audio_output_hosts_.empty() || !ppb_audios_.empty())
NotifyPlaybackStopsOnEmpty();
ppb_audios_.clear();
+ audio_output_hosts_.clear();
instance_ = nullptr;
}
@@ -74,4 +97,21 @@ void PepperAudioController::NotifyPlaybackStopsOnEmpty() {
render_frame->PepperStopsPlayback(instance_);
}
+void PepperAudioController::StartPlaybackIfFirstInstance() {
+ DCHECK(instance_);
+
+ if (audio_output_hosts_.empty() && ppb_audios_.empty()) {
+ RenderFrameImpl* render_frame = instance_->render_frame();
+ if (render_frame)
+ render_frame->PepperStartsPlayback(instance_);
+ }
+}
+
+void PepperAudioController::StopPlaybackIfLastInstance() {
+ DCHECK(instance_);
+
+ if (audio_output_hosts_.empty() && ppb_audios_.empty())
+ NotifyPlaybackStopsOnEmpty();
+}
+
} // namespace content
« 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