diff options
author | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-30 21:24:39 +0000 |
---|---|---|
committer | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-30 21:24:39 +0000 |
commit | 937df951109b543a70e5474ee12f20df7b52a8d5 (patch) | |
tree | 7689840b4951acd56c068b48c75fa8fb797525c3 /chrome | |
parent | a6550f16d87527b7963e7e827c64b64bddeaaef2 (diff) | |
download | chromium_src-937df951109b543a70e5474ee12f20df7b52a8d5.zip chromium_src-937df951109b543a70e5474ee12f20df7b52a8d5.tar.gz chromium_src-937df951109b543a70e5474ee12f20df7b52a8d5.tar.bz2 |
Pepper2 audio (trusted side) implementation. Still missing a synchronization for the callback setting, will be done soon.
BUG=none
TEST=test plugin plays music
Review URL: http://codereview.chromium.org/2962003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54383 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/renderer/pepper_devices.h | 3 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 126 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.h | 4 |
3 files changed, 131 insertions, 2 deletions
diff --git a/chrome/renderer/pepper_devices.h b/chrome/renderer/pepper_devices.h index a0652ae..0e30af4 100644 --- a/chrome/renderer/pepper_devices.h +++ b/chrome/renderer/pepper_devices.h @@ -97,7 +97,6 @@ class Graphics2DDeviceContext { class AudioDeviceContext : public AudioMessageFilter::Delegate, public base::DelegateSimpleThread::Delegate { public: - // TODO(neb): if plugin_delegate parameter is indeed unused, remove it explicit AudioDeviceContext() : stream_id_(0) { } virtual ~AudioDeviceContext(); @@ -121,13 +120,13 @@ class AudioDeviceContext : public AudioMessageFilter::Delegate, base::SyncSocket::Handle socket_handle, uint32 length); virtual void OnVolume(double volume); + virtual void OnDestroy(); // End of AudioMessageFilter::Delegate implementation // DelegateSimpleThread::Delegate implementation virtual void Run(); // End of DelegateSimpleThread::Delegate implementation - void OnDestroy(); void FireAudioCallback() { if (context_ && context_->config.callback) { context_->config.callback(context_); diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index 16a1b8f..4e9f917 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -5,7 +5,10 @@ #include "chrome/renderer/pepper_plugin_delegate_impl.h" #include "app/surface/transport_dib.h" +#include "base/logging.h" #include "base/scoped_ptr.h" +#include "chrome/common/render_messages.h" +#include "chrome/renderer/audio_message_filter.h" #include "chrome/renderer/render_view.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" @@ -42,6 +45,116 @@ class PlatformImage2DImpl : public pepper::PluginDelegate::PlatformImage2D { DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); }; +class PlatformAudioImpl + : public pepper::PluginDelegate::PlatformAudio, + public AudioMessageFilter::Delegate { + public: + explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) + : client_(NULL), filter_(filter), stream_id_(0) { + DCHECK(filter_); + } + + virtual ~PlatformAudioImpl() { + // Make sure we have been shut down. + DCHECK_EQ(0, stream_id_); + DCHECK(!client_); + } + + // Initialize this audio context. StreamCreated() will be called when the + // stream is created. + bool Initialize(uint32_t sample_rate, uint32_t sample_count, + pepper::PluginDelegate::PlatformAudio::Client* client); + + virtual bool StartPlayback() { + return filter_ && filter_->Send( + new ViewHostMsg_PlayAudioStream(0, stream_id_)); + } + + virtual bool StopPlayback() { + return filter_ && filter_->Send( + new ViewHostMsg_PauseAudioStream(0, stream_id_)); + } + + virtual void ShutDown(); + + private: + virtual void OnRequestPacket(uint32 bytes_in_buffer, + const base::Time& message_timestamp) { + LOG(FATAL) << "Should never get OnRequestPacket in PlatformAudioImpl"; + } + + virtual void OnStateChanged(const ViewMsg_AudioStreamState_Params& state) { } + + virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length) { + LOG(FATAL) << "Should never get OnCreated in PlatformAudioImpl"; + } + + virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, + base::SyncSocket::Handle socket_handle, + uint32 length); + + virtual void OnVolume(double volume) { } + + // The client to notify when the stream is created. + pepper::PluginDelegate::PlatformAudio::Client* client_; + // MessageFilter used to send/receive IPC. + scoped_refptr<AudioMessageFilter> filter_; + // Our ID on the MessageFilter. + int32 stream_id_; + + DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); +}; + +bool PlatformAudioImpl::Initialize( + uint32_t sample_rate, uint32_t sample_count, + pepper::PluginDelegate::PlatformAudio::Client* client) { + + DCHECK(client); + // Make sure we don't call init more than once. + DCHECK_EQ(0, stream_id_); + + client_ = client; + + ViewHostMsg_Audio_CreateStream_Params params; + params.format = AudioManager::AUDIO_PCM_LINEAR; + params.channels = 2; + params.sample_rate = sample_rate; + params.bits_per_sample = 16; + + params.packet_size = sample_count * params.channels * + (params.bits_per_sample >> 3); + + stream_id_ = filter_->AddDelegate(this); + return filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, + true)); +} + +void PlatformAudioImpl::OnLowLatencyCreated( + base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, + uint32 length) { +#if defined(OS_WIN) + DCHECK(handle); + DCHECK(socket_handle); +#else + DCHECK_NE(-1, handle.fd); + DCHECK_NE(-1, socket_handle); +#endif + DCHECK(length); + + client_->StreamCreated(handle, length, socket_handle); +} + +void PlatformAudioImpl::ShutDown() { + // Make sure we don't call shutdown more than once. + if (!stream_id_) { + return; + } + filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); + filter_->RemoveDelegate(stream_id_); + stream_id_ = 0; + client_ = NULL; +} + } // namespace PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) @@ -148,3 +261,16 @@ void PepperPluginDelegateImpl::DidChangeSelectedFindResult(int identifier, render_view_->reportFindInPageSelection( identifier, index + 1, WebKit::WebRect()); } + +pepper::PluginDelegate::PlatformAudio* PepperPluginDelegateImpl::CreateAudio( + uint32_t sample_rate, uint32_t sample_count, + pepper::PluginDelegate::PlatformAudio::Client* client) { + scoped_ptr<PlatformAudioImpl> audio( + new PlatformAudioImpl(render_view_->audio_message_filter())); + if (audio->Initialize(sample_rate, sample_count, client)) { + return audio.release(); + } else { + return NULL; + } +} + diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h index 856d741..5b208e9 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.h +++ b/chrome/renderer/pepper_plugin_delegate_impl.h @@ -33,6 +33,10 @@ class PepperPluginDelegateImpl // pepper::PluginDelegate implementation. virtual void InstanceCreated(pepper::PluginInstance* instance); virtual void InstanceDeleted(pepper::PluginInstance* instance); + virtual PlatformAudio* CreateAudio( + uint32_t sample_rate, + uint32_t sample_count, + pepper::PluginDelegate::PlatformAudio::Client* client); virtual PlatformImage2D* CreateImage2D(int width, int height); virtual void DidChangeNumberOfFindResults(int identifier, int total, |