Skip to content

Commit

Permalink
Support audio output device enumeration and selection in PPAPI
Browse files Browse the repository at this point in the history
- Keep the current |PPB_Audio| interface unchanged
- Add a new dev interface: |PPB_AudioOutput_Dev|
- Implement |PPB_AudioOutput_Dev| using the typical HostResource
  implementations like |PPB_AudioInput_Dev|
- Add ppapi/proxy/audio_output_resource.h/cc etc. to implement
  |AudioOutputResource|
- Add content/renderer/pepper/pepper_audio_output_host.h/cc etc.
  to implement |PepperAudioOutputHost|
- Keep ppb_audio_proxy.h/cc, ppb_audio_shared.h/cc, ppb_audio_impl.h/cc
  unchanged, so that the current |PPB_Audio| will not be affected.
- Modify content/renderer/pepper/pepper_platform_audio_output.h/cc to
  accept both |AudioHelper| and |PepperAudioOutputHost| clients
- The way to implement |PepperAudioOutputHost| is borrowed from
  "media/audio/audio_output_device.cc" where audio output selection isi
  supported for javascript.
- Add necessary IPC message definitions for |PPB_AudioOutput_Dev|

BUG=701584
R= bbudge@chromium.org, tsepez@chromium.org, isherman@chromium.org

Review-Url: https://codereview.chromium.org/2755613002
Cr-Commit-Position: refs/heads/master@{#462889}
  • Loading branch information
xingzhang authored and Commit bot committed Apr 7, 2017
1 parent 26d2eea commit 3a2a470
Show file tree
Hide file tree
Showing 38 changed files with 2,409 additions and 17 deletions.
1 change: 1 addition & 0 deletions chrome/common/ppapi_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "build/build_config.h"
#include "ppapi/c/dev/ppb_audio_input_dev.h"
#include "ppapi/c/dev/ppb_audio_output_dev.h"
#include "ppapi/c/dev/ppb_buffer_dev.h"
#include "ppapi/c/dev/ppb_char_set_dev.h"
#include "ppapi/c/dev/ppb_crypto_dev.h"
Expand Down
4 changes: 4 additions & 0 deletions content/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ target(link_target_type, "renderer") {
"pepper/pepper_audio_encoder_host.h",
"pepper/pepper_audio_input_host.cc",
"pepper/pepper_audio_input_host.h",
"pepper/pepper_audio_output_host.cc",
"pepper/pepper_audio_output_host.h",
"pepper/pepper_broker.cc",
"pepper/pepper_broker.h",
"pepper/pepper_browser_connection.cc",
Expand Down Expand Up @@ -822,6 +824,8 @@ target(link_target_type, "renderer") {
"pepper/pepper_platform_audio_input.h",
"pepper/pepper_platform_audio_output.cc",
"pepper/pepper_platform_audio_output.h",
"pepper/pepper_platform_audio_output_dev.cc",
"pepper/pepper_platform_audio_output_dev.h",
"pepper/pepper_platform_camera_device.cc",
"pepper/pepper_platform_camera_device.h",
"pepper/pepper_platform_video_capture.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/pepper/pepper_audio_encoder_host.h"
#include "content/renderer/pepper/pepper_audio_input_host.h"
#include "content/renderer/pepper/pepper_audio_output_host.h"
#include "content/renderer/pepper/pepper_camera_device_host.h"
#include "content/renderer/pepper/pepper_compositor_host.h"
#include "content/renderer/pepper/pepper_file_chooser_host.h"
Expand Down Expand Up @@ -211,6 +212,9 @@ ContentRendererPepperHostFactory::CreateResourceHost(
case PpapiHostMsg_AudioInput_Create::ID:
return base::MakeUnique<PepperAudioInputHost>(host_, instance,
resource);
case PpapiHostMsg_AudioOutput_Create::ID:
return base::MakeUnique<PepperAudioOutputHost>(host_, instance,
resource);
case PpapiHostMsg_FileChooser_Create::ID:
return base::MakeUnique<PepperFileChooserHost>(host_, instance,
resource);
Expand Down
56 changes: 48 additions & 8 deletions content/renderer/pepper/pepper_audio_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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
14 changes: 13 additions & 1 deletion content/renderer/pepper/pepper_audio_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace content {

class PepperAudioOutputHost;
class PepperPluginInstanceImpl;
class PPB_Audio_Impl;

Expand All @@ -25,9 +26,11 @@ class PepperAudioController {

// Adds an audio instance to the controller.
void AddInstance(PPB_Audio_Impl* audio);
void AddInstance(PepperAudioOutputHost* audio_output);

// Removes an audio instance from the controller.
void RemoveInstance(PPB_Audio_Impl* audio);
void RemoveInstance(PepperAudioOutputHost* audio_output);

// Sets the volume of all audio instances.
void SetVolume(double volume);
Expand All @@ -42,9 +45,18 @@ class PepperAudioController {
// only be called when |ppb_audios_| turns from non-empty to empty.
void NotifyPlaybackStopsOnEmpty();

// All active audio instances.
// Helper functions to deal with the first and last audio instance.
void StartPlaybackIfFirstInstance();
void StopPlaybackIfLastInstance();

// All active audio instances that are using the old
// PPB_Audio interface.
std::set<PPB_Audio_Impl*> ppb_audios_;

// All active audio output instances that are using the new
// PPB_AudioOutput interface.
std::set<PepperAudioOutputHost*> audio_output_hosts_;

// The Pepper instance which this controller is for. Will be null after
// OnPepperInstanceDeleted() is called.
PepperPluginInstanceImpl* instance_;
Expand Down
Loading

0 comments on commit 3a2a470

Please sign in to comment.