diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 21:30:25 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 21:30:25 +0000 |
commit | 321ad87b01c1e040f3f121044f8c255ca5548b30 (patch) | |
tree | 50a7575b7ee9d0ec0498395a6557af7b74e6ecfd /chrome | |
parent | db2ff4b4607eb2a54b30ea9c4b8248e7a1cebfe5 (diff) | |
download | chromium_src-321ad87b01c1e040f3f121044f8c255ca5548b30.zip chromium_src-321ad87b01c1e040f3f121044f8c255ca5548b30.tar.gz chromium_src-321ad87b01c1e040f3f121044f8c255ca5548b30.tar.bz2 |
Working rudimentary audio in Pepper.
BUG=28292
TEST=none
Patch by neb@chromium.org
Original review: http://codereview.chromium.org/524006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36043 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.cc | 142 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.h | 54 |
2 files changed, 196 insertions, 0 deletions
diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc index 3680804..c5e93ad 100644 --- a/chrome/renderer/webplugin_delegate_pepper.cc +++ b/chrome/renderer/webplugin_delegate_pepper.cc @@ -564,6 +564,148 @@ NPError WebPluginDelegatePepper::Device3DMapBuffer( return NPERR_NO_ERROR; } +NPError WebPluginDelegatePepper::DeviceAudioQueryCapability(int32 capability, + int32* value) { + // TODO(neb,cpu) implement QueryCapability + return NPERR_GENERIC_ERROR; +} + +NPError WebPluginDelegatePepper::DeviceAudioQueryConfig( + const NPDeviceContextAudioConfig* request, + NPDeviceContextAudioConfig* obtain) { + // TODO(neb,cpu) implement QueryConfig + return NPERR_GENERIC_ERROR; +} + +NPError WebPluginDelegatePepper::DeviceAudioInitializeContext( + const NPDeviceContextAudioConfig* config, + NPDeviceContextAudio* context) { + + if (!render_view_) { + return NPERR_GENERIC_ERROR; + } + + scoped_refptr<AudioMessageFilter> filter = + render_view_->audio_message_filter(); + ViewHostMsg_Audio_CreateStream params; + + params.format = AudioManager::AUDIO_PCM_LINEAR; + params.channels = config->outputChannelMap; + params.sample_rate = config->sampleRate; + switch (config->sampleType) { + case NPAudioSampleTypeInt16: + params.bits_per_sample = 16; + break; + case NPAudioSampleTypeFloat32: + params.bits_per_sample = 32; + break; + default: + return NPERR_INVALID_PARAM; + } + + context->config = *config; + params.packet_size = config->sampleFrameCount * config->outputChannelMap + * (params.bits_per_sample >> 3); + LOG(INFO) << "Initializing Pepper Audio Context (" << + config->sampleFrameCount << "Hz, " << params.bits_per_sample << + " bits, " << config->outputChannelMap << "channels"; + + // TODO(neb): figure out if this number is grounded in reality + params.buffer_capacity = params.packet_size * 3; + + // TODO(neb): keep these guys tracked somewhere so we can delete them + // even if the plugin doesn't + AudioStream *audio = new AudioStream(this); + audio->Initialize(filter, params, context); + return NPERR_NO_ERROR; +} + +NPError WebPluginDelegatePepper::DeviceAudioSetStateContext( + NPDeviceContextAudio* context, + int32 state, + int32 value) { + // TODO(neb,cpu) implement SetStateContext + return NPERR_GENERIC_ERROR; +} + +NPError WebPluginDelegatePepper::DeviceAudioGetStateContext( + NPDeviceContextAudio* context, + int32 state, + int32* value) { + // TODO(neb,cpu) implement GetStateContext + return NPERR_GENERIC_ERROR; +} + +NPError WebPluginDelegatePepper::DeviceAudioFlushContext( + NPP id, + NPDeviceContextAudio* context, + NPDeviceFlushContextCallbackPtr callback, + void* user_data) { + // TODO(neb,cpu) implement FlushContext + return NPERR_GENERIC_ERROR; +} + +NPError WebPluginDelegatePepper::DeviceAudioDestroyContext( + NPDeviceContextAudio* context) { + if (!context || !context->privatePtr) { + return NPERR_INVALID_PARAM; + } + delete reinterpret_cast<AudioStream *>(context->privatePtr); + memset(context, 0, sizeof(NPDeviceContextAudio)); + return NPERR_NO_ERROR; +} + +WebPluginDelegatePepper::AudioStream::~AudioStream() { + if (stream_id_) { + OnDestroy(); + } +} + +void WebPluginDelegatePepper::AudioStream::Initialize( + AudioMessageFilter* filter, const ViewHostMsg_Audio_CreateStream& params, + NPDeviceContextAudio* context) { + filter_ = filter; + context_= context; + context_->privatePtr = this; + // Make sure we don't call init more than once. + DCHECK_EQ(0, stream_id_); + stream_id_ = filter_->AddDelegate(this); + filter->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params)); +} + +void WebPluginDelegatePepper::AudioStream::OnDestroy() { + // Make sure we don't call destroy more than once. + DCHECK_NE(0, stream_id_); + filter_->RemoveDelegate(stream_id_); + filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); + stream_id_ = 0; +} + +void WebPluginDelegatePepper::AudioStream::OnRequestPacket( + size_t bytes_in_buffer, const base::Time& message_timestamp) { + context_->config.callback(context_); + filter_->Send(new ViewHostMsg_NotifyAudioPacketReady(0, stream_id_, + shared_memory_size_)); +} + +void WebPluginDelegatePepper::AudioStream::OnStateChanged( + ViewMsg_AudioStreamState state) { +} + +void WebPluginDelegatePepper::AudioStream::OnCreated( + base::SharedMemoryHandle handle, size_t length) { + shared_memory_.reset(new base::SharedMemory(handle, false)); + shared_memory_->Map(length); + shared_memory_size_ = length; + + context_->outBuffer = shared_memory_->memory(); + // TODO(neb): call play after prefilling + filter_->Send(new ViewHostMsg_PlayAudioStream(0, stream_id_)); +} + +void WebPluginDelegatePepper::AudioStream::OnVolume(double volume) { +} + WebPluginDelegatePepper::WebPluginDelegatePepper( const base::WeakPtr<RenderView>& render_view, gfx::PluginWindowHandle containing_view, diff --git a/chrome/renderer/webplugin_delegate_pepper.h b/chrome/renderer/webplugin_delegate_pepper.h index 2e78500..d2da979 100644 --- a/chrome/renderer/webplugin_delegate_pepper.h +++ b/chrome/renderer/webplugin_delegate_pepper.h @@ -19,7 +19,9 @@ #include "base/scoped_ptr.h" #include "base/task.h" #include "base/weak_ptr.h" +#include "chrome/common/render_messages.h" #include "chrome/common/transport_dib.h" +#include "chrome/renderer/audio_message_filter.h" #include "chrome/renderer/render_view.h" #include "chrome/renderer/command_buffer_proxy.h" #include "skia/ext/platform_canvas.h" @@ -124,8 +126,60 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate { virtual NPError Device3DMapBuffer(NPDeviceContext3D* context, int32 id, NPDeviceBuffer* buffer); + + // WebPluginAudioDeviceDelegate implementation. + virtual NPError DeviceAudioQueryCapability(int32 capability, int32* value); + virtual NPError DeviceAudioQueryConfig( + const NPDeviceContextAudioConfig* request, + NPDeviceContextAudioConfig* obtain); + virtual NPError DeviceAudioInitializeContext( + const NPDeviceContextAudioConfig* config, + NPDeviceContextAudio* context); + virtual NPError DeviceAudioSetStateContext(NPDeviceContextAudio* context, + int32 state, int32 value); + virtual NPError DeviceAudioGetStateContext(NPDeviceContextAudio* context, + int32 state, int32* value); + virtual NPError DeviceAudioFlushContext( + NPP id, NPDeviceContextAudio* context, + NPDeviceFlushContextCallbackPtr callback, void* user_data); + virtual NPError DeviceAudioDestroyContext(NPDeviceContextAudio* context); + // End of WebPluginDelegate implementation. + // Each instance of AudioStream corresponds to one host stream (and one + // audio context). NPDeviceContextAudio contains a pointer to the context's + // stream as privatePtr. + class AudioStream : public AudioMessageFilter::Delegate { + public: + // TODO(neb): if plugin_delegate parameter is indeed unused, remove it + explicit AudioStream(WebPluginDelegatePepper* plugin_delegate) + : plugin_delegate_(plugin_delegate), stream_id_(0) { + } + virtual ~AudioStream(); + + void Initialize(AudioMessageFilter *filter, + const ViewHostMsg_Audio_CreateStream& params, + NPDeviceContextAudio* context); + + // AudioMessageFilter::Delegate implementation + virtual void OnRequestPacket(size_t bytes_in_buffer, + const base::Time& message_timestamp); + virtual void OnStateChanged(ViewMsg_AudioStreamState state); + virtual void OnCreated(base::SharedMemoryHandle handle, size_t length); + virtual void OnVolume(double volume); + // End of AudioMessageFilter::Delegate implementation + + private: + void OnDestroy(); + + NPDeviceContextAudio *context_; + WebPluginDelegatePepper* plugin_delegate_; + scoped_refptr<AudioMessageFilter> filter_; + int32 stream_id_; + scoped_ptr<base::SharedMemory> shared_memory_; + size_t shared_memory_size_; + }; + gfx::Rect GetRect() const { return window_rect_; } gfx::Rect GetClipRect() const { return clip_rect_; } |