| Index: webkit/plugins/ppapi/ppb_audio_impl.cc
|
| ===================================================================
|
| --- webkit/plugins/ppapi/ppb_audio_impl.cc (revision 0)
|
| +++ webkit/plugins/ppapi/ppb_audio_impl.cc (working copy)
|
| @@ -2,15 +2,17 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "webkit/glue/plugins/pepper_audio.h"
|
| +#include "webkit/plugins/ppapi/ppb_audio_impl.h"
|
|
|
| #include "base/logging.h"
|
| #include "ppapi/c/dev/ppb_audio_dev.h"
|
| #include "ppapi/c/dev/ppb_audio_trusted_dev.h"
|
| #include "ppapi/c/pp_completion_callback.h"
|
| -#include "webkit/glue/plugins/pepper_common.h"
|
| +#include "webkit/plugins/ppapi/common.h"
|
|
|
| -namespace pepper {
|
| +namespace webkit {
|
| +namespace plugins {
|
| +namespace ppapi {
|
|
|
| namespace {
|
|
|
| @@ -36,9 +38,8 @@
|
| if (RecommendSampleFrameCount(sample_frame_count) != sample_frame_count)
|
| return 0;
|
|
|
| - scoped_refptr<AudioConfig> config(new AudioConfig(module,
|
| - sample_rate,
|
| - sample_frame_count));
|
| + scoped_refptr<PPB_AudioConfig_Impl> config(
|
| + new PPB_AudioConfig_Impl(module, sample_rate, sample_frame_count));
|
| return config->GetReference();
|
| }
|
|
|
| @@ -53,17 +54,20 @@
|
| }
|
|
|
| PP_Bool IsAudioConfig(PP_Resource resource) {
|
| - scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(resource);
|
| + scoped_refptr<PPB_AudioConfig_Impl> config =
|
| + Resource::GetAs<PPB_AudioConfig_Impl>(resource);
|
| return BoolToPPBool(!!config);
|
| }
|
|
|
| PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) {
|
| - scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(config_id);
|
| + scoped_refptr<PPB_AudioConfig_Impl> config =
|
| + Resource::GetAs<PPB_AudioConfig_Impl>(config_id);
|
| return config ? config->sample_rate() : PP_AUDIOSAMPLERATE_NONE;
|
| }
|
|
|
| uint32_t GetSampleFrameCount(PP_Resource config_id) {
|
| - scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(config_id);
|
| + scoped_refptr<PPB_AudioConfig_Impl> config =
|
| + Resource::GetAs<PPB_AudioConfig_Impl>(config_id);
|
| return config ? config->sample_frame_count() : 0;
|
| }
|
|
|
| @@ -84,7 +88,8 @@
|
| return 0;
|
| if (!user_callback)
|
| return 0;
|
| - scoped_refptr<Audio> audio(new Audio(instance->module(), instance_id));
|
| + scoped_refptr<PPB_Audio_Impl> audio(
|
| + new PPB_Audio_Impl(instance->module(), instance_id));
|
| if (!audio->Init(instance->delegate(), config_id,
|
| user_callback, user_data))
|
| return 0;
|
| @@ -92,22 +97,25 @@
|
| }
|
|
|
| PP_Bool IsAudio(PP_Resource resource) {
|
| - scoped_refptr<Audio> audio = Resource::GetAs<Audio>(resource);
|
| + scoped_refptr<PPB_Audio_Impl> audio =
|
| + Resource::GetAs<PPB_Audio_Impl>(resource);
|
| return BoolToPPBool(!!audio);
|
| }
|
|
|
| PP_Resource GetCurrentConfig(PP_Resource audio_id) {
|
| - scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id);
|
| + scoped_refptr<PPB_Audio_Impl> audio = Resource::GetAs<PPB_Audio_Impl>(audio_id);
|
| return audio ? audio->GetCurrentConfig() : 0;
|
| }
|
|
|
| PP_Bool StartPlayback(PP_Resource audio_id) {
|
| - scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id);
|
| + scoped_refptr<PPB_Audio_Impl> audio =
|
| + Resource::GetAs<PPB_Audio_Impl>(audio_id);
|
| return audio ? BoolToPPBool(audio->StartPlayback()) : PP_FALSE;
|
| }
|
|
|
| PP_Bool StopPlayback(PP_Resource audio_id) {
|
| - scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id);
|
| + scoped_refptr<PPB_Audio_Impl> audio =
|
| + Resource::GetAs<PPB_Audio_Impl>(audio_id);
|
| return audio ? BoolToPPBool(audio->StopPlayback()) : PP_FALSE;
|
| }
|
|
|
| @@ -125,14 +133,15 @@
|
| PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
|
| if (!instance)
|
| return 0;
|
| - scoped_refptr<Audio> audio(new Audio(instance->module(), instance_id));
|
| + scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance->module(), instance_id));
|
| return audio->GetReference();
|
| }
|
|
|
| int32_t Open(PP_Resource audio_id,
|
| PP_Resource config_id,
|
| PP_CompletionCallback created) {
|
| - scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id);
|
| + scoped_refptr<PPB_Audio_Impl> audio =
|
| + Resource::GetAs<PPB_Audio_Impl>(audio_id);
|
| if (!audio)
|
| return PP_ERROR_BADRESOURCE;
|
| if (!created.func)
|
| @@ -145,7 +154,8 @@
|
| }
|
|
|
| int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) {
|
| - scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id);
|
| + scoped_refptr<PPB_Audio_Impl> audio =
|
| + Resource::GetAs<PPB_Audio_Impl>(audio_id);
|
| if (audio)
|
| return audio->GetSyncSocket(sync_socket);
|
| return PP_ERROR_BADRESOURCE;
|
| @@ -154,7 +164,8 @@
|
| int32_t GetSharedMemory(PP_Resource audio_id,
|
| int* shm_handle,
|
| uint32_t* shm_size) {
|
| - scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id);
|
| + scoped_refptr<PPB_Audio_Impl> audio =
|
| + Resource::GetAs<PPB_Audio_Impl>(audio_id);
|
| if (audio)
|
| return audio->GetSharedMemory(shm_handle, shm_size);
|
| return PP_ERROR_BADRESOURCE;
|
| @@ -169,21 +180,22 @@
|
|
|
| } // namespace
|
|
|
| -// AudioConfig -----------------------------------------------------------------
|
| +// PPB_AudioConfig_Impl --------------------------------------------------------
|
|
|
| -AudioConfig::AudioConfig(PluginModule* module,
|
| - PP_AudioSampleRate_Dev sample_rate,
|
| - uint32_t sample_frame_count)
|
| +PPB_AudioConfig_Impl::PPB_AudioConfig_Impl(
|
| + PluginModule* module,
|
| + PP_AudioSampleRate_Dev sample_rate,
|
| + uint32_t sample_frame_count)
|
| : Resource(module),
|
| sample_rate_(sample_rate),
|
| sample_frame_count_(sample_frame_count) {
|
| }
|
|
|
| -const PPB_AudioConfig_Dev* AudioConfig::GetInterface() {
|
| +const PPB_AudioConfig_Dev* PPB_AudioConfig_Impl::GetInterface() {
|
| return &ppb_audioconfig;
|
| }
|
|
|
| -size_t AudioConfig::BufferSize() {
|
| +size_t PPB_AudioConfig_Impl::BufferSize() {
|
| // TODO(audio): as more options become available, we'll need to
|
| // have additional code here to correctly calculate the size in
|
| // bytes of an audio buffer. For now, only support two channel
|
| @@ -193,13 +205,13 @@
|
| return static_cast<size_t>(sample_frame_count_ * kSizeOfSample * kChannels);
|
| }
|
|
|
| -AudioConfig* AudioConfig::AsAudioConfig() {
|
| +PPB_AudioConfig_Impl* PPB_AudioConfig_Impl::AsAudioConfig() {
|
| return this;
|
| }
|
|
|
| -// Audio -----------------------------------------------------------------------
|
| +// PPB_Audio_Impl --------------------------------------------------------------
|
|
|
| -Audio::Audio(PluginModule* module, PP_Instance instance_id)
|
| +PPB_Audio_Impl::PPB_Audio_Impl(PluginModule* module, PP_Instance instance_id)
|
| : Resource(module),
|
| pp_instance_(instance_id),
|
| audio_(NULL),
|
| @@ -207,7 +219,7 @@
|
| create_callback_ = PP_MakeCompletionCallback(NULL, NULL);
|
| }
|
|
|
| -Audio::~Audio() {
|
| +PPB_Audio_Impl::~PPB_Audio_Impl() {
|
| // Calling ShutDown() makes sure StreamCreated cannot be called anymore.
|
| audio_->ShutDown();
|
| audio_ = NULL;
|
| @@ -220,23 +232,23 @@
|
| }
|
| }
|
|
|
| -const PPB_Audio_Dev* Audio::GetInterface() {
|
| +const PPB_Audio_Dev* PPB_Audio_Impl::GetInterface() {
|
| return &ppb_audio;
|
| }
|
|
|
| -const PPB_AudioTrusted_Dev* Audio::GetTrustedInterface() {
|
| +const PPB_AudioTrusted_Dev* PPB_Audio_Impl::GetTrustedInterface() {
|
| return &ppb_audiotrusted;
|
| }
|
|
|
| -Audio* Audio::AsAudio() {
|
| +PPB_Audio_Impl* PPB_Audio_Impl::AsAudio() {
|
| return this;
|
| }
|
|
|
| -bool Audio::Init(PluginDelegate* plugin_delegate,
|
| - PP_Resource config_id,
|
| - PPB_Audio_Callback callback, void* user_data) {
|
| +bool PPB_Audio_Impl::Init(PluginDelegate* plugin_delegate,
|
| + PP_Resource config_id,
|
| + PPB_Audio_Callback callback, void* user_data) {
|
| CHECK(!audio_);
|
| - config_ = Resource::GetAs<AudioConfig>(config_id);
|
| + config_ = Resource::GetAs<PPB_AudioConfig_Impl>(config_id);
|
| if (!config_)
|
| return false;
|
| SetCallback(callback, user_data);
|
| @@ -248,18 +260,18 @@
|
| return audio_ != NULL;
|
| }
|
|
|
| -PP_Resource Audio::GetCurrentConfig() {
|
| +PP_Resource PPB_Audio_Impl::GetCurrentConfig() {
|
| return config_->GetReference();
|
| }
|
|
|
| -bool Audio::StartPlayback() {
|
| +bool PPB_Audio_Impl::StartPlayback() {
|
| if (playing())
|
| return true;
|
| SetStartPlaybackState();
|
| return audio_->StartPlayback();
|
| }
|
|
|
| -bool Audio::StopPlayback() {
|
| +bool PPB_Audio_Impl::StopPlayback() {
|
| if (!playing())
|
| return true;
|
| if (!audio_->StopPlayback())
|
| @@ -268,11 +280,11 @@
|
| return true;
|
| }
|
|
|
| -int32_t Audio::Open(PluginDelegate* plugin_delegate,
|
| - PP_Resource config_id,
|
| - PP_CompletionCallback create_callback) {
|
| +int32_t PPB_Audio_Impl::Open(PluginDelegate* plugin_delegate,
|
| + PP_Resource config_id,
|
| + PP_CompletionCallback create_callback) {
|
| DCHECK(!audio_);
|
| - config_ = Resource::GetAs<AudioConfig>(config_id);
|
| + config_ = Resource::GetAs<PPB_AudioConfig_Impl>(config_id);
|
| if (!config_)
|
| return PP_ERROR_BADRESOURCE;
|
|
|
| @@ -291,7 +303,7 @@
|
| return PP_ERROR_WOULDBLOCK;
|
| }
|
|
|
| -int32_t Audio::GetSyncSocket(int* sync_socket) {
|
| +int32_t PPB_Audio_Impl::GetSyncSocket(int* sync_socket) {
|
| if (socket_for_create_callback_.get()) {
|
| #if defined(OS_POSIX)
|
| *sync_socket = socket_for_create_callback_->handle();
|
| @@ -305,7 +317,7 @@
|
| return PP_ERROR_FAILED;
|
| }
|
|
|
| -int32_t Audio::GetSharedMemory(int* shm_handle, uint32_t* shm_size) {
|
| +int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, uint32_t* shm_size) {
|
| if (shared_memory_for_create_callback_.get()) {
|
| #if defined(OS_POSIX)
|
| *shm_handle = shared_memory_for_create_callback_->handle().fd;
|
| @@ -321,9 +333,10 @@
|
| return PP_ERROR_FAILED;
|
| }
|
|
|
| -void Audio::StreamCreated(base::SharedMemoryHandle shared_memory_handle,
|
| - size_t shared_memory_size,
|
| - base::SyncSocket::Handle socket_handle) {
|
| +void PPB_Audio_Impl::StreamCreated(
|
| + base::SharedMemoryHandle shared_memory_handle,
|
| + size_t shared_memory_size,
|
| + base::SyncSocket::Handle socket_handle) {
|
| if (create_callback_pending_) {
|
| // Trusted side of proxy can specify a callback to recieve handles. In
|
| // this case we don't need to map any data or start the thread since it
|
| @@ -348,4 +361,7 @@
|
| }
|
| }
|
|
|
| -} // namespace pepper
|
| +} // namespace ppapi
|
| +} // namespace plugins
|
| +} // namespace webkit
|
| +
|
|
|