summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/pepper_devices.cc
diff options
context:
space:
mode:
authorneb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-08 21:08:19 +0000
committerneb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-08 21:08:19 +0000
commit7d74aaab9390a7502dac835ddcd2a5175224702e (patch)
tree4baccf95f53be95803724bce220436bacf5ccce0 /chrome/renderer/pepper_devices.cc
parent22c379ac0a813d0b3e0fd34819aad2d3e48c39b7 (diff)
downloadchromium_src-7d74aaab9390a7502dac835ddcd2a5175224702e.zip
chromium_src-7d74aaab9390a7502dac835ddcd2a5175224702e.tar.gz
chromium_src-7d74aaab9390a7502dac835ddcd2a5175224702e.tar.bz2
Implement low-latency audio on Pepper.
BUG=28292 TEST=none Review URL: http://codereview.chromium.org/577019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38392 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/pepper_devices.cc')
-rw-r--r--chrome/renderer/pepper_devices.cc72
1 files changed, 63 insertions, 9 deletions
diff --git a/chrome/renderer/pepper_devices.cc b/chrome/renderer/pepper_devices.cc
index 3b14d16..4a831f4 100644
--- a/chrome/renderer/pepper_devices.cc
+++ b/chrome/renderer/pepper_devices.cc
@@ -98,14 +98,18 @@ AudioDeviceContext::~AudioDeviceContext() {
}
}
-NPError AudioDeviceContext::Initialize(
- AudioMessageFilter* filter, const NPDeviceContextAudioConfig* config,
- NPDeviceContextAudio* context) {
- filter_ = filter;
- context_= context;
+NPError AudioDeviceContext::Initialize(AudioMessageFilter* filter,
+ const NPDeviceContextAudioConfig* config,
+ NPDeviceContextAudio* context) {
+ DCHECK(filter);
// Make sure we don't call init more than once.
DCHECK_EQ(0, stream_id_);
- stream_id_ = filter_->AddDelegate(this);
+
+ if (!config || !context) {
+ return NPERR_INVALID_PARAM;
+ }
+ filter_ = filter;
+ context_= context;
ViewHostMsg_Audio_CreateStream_Params params;
params.format = AudioManager::AUDIO_PCM_LINEAR;
@@ -133,6 +137,7 @@ NPError AudioDeviceContext::Initialize(
config->sampleFrameCount << "Hz, " << params.bits_per_sample <<
" bits, " << config->outputChannelMap << "channels";
+ stream_id_ = filter_->AddDelegate(this);
filter->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params));
return NPERR_NO_ERROR;
}
@@ -143,13 +148,17 @@ void AudioDeviceContext::OnDestroy() {
filter_->RemoveDelegate(stream_id_);
filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_));
stream_id_ = 0;
+ if (audio_thread_.get()) {
+ socket_->Close();
+ audio_thread_->Join();
+ }
}
void AudioDeviceContext::OnRequestPacket(
uint32 bytes_in_buffer, const base::Time& message_timestamp) {
- context_->config.callback(context_);
+ FireAudioCallback();
filter_->Send(new ViewHostMsg_NotifyAudioPacketReady(0, stream_id_,
- shared_memory_size_));
+ shared_memory_size_));
}
void AudioDeviceContext::OnStateChanged(
@@ -158,15 +167,60 @@ void AudioDeviceContext::OnStateChanged(
void AudioDeviceContext::OnCreated(
base::SharedMemoryHandle handle, uint32 length) {
+#if defined(OS_WIN)
+ DCHECK(handle);
+#else
+ DCHECK_NE(-1, handle.fd);
+#endif
+ DCHECK(length);
+ DCHECK(context_);
+
+ shared_memory_.reset(new base::SharedMemory(handle, false));
+ shared_memory_->Map(length);
+ shared_memory_size_ = length;
+
+ context_->outBuffer = shared_memory_->memory();
+ FireAudioCallback();
+ filter_->Send(new ViewHostMsg_PlayAudioStream(0, stream_id_));
+}
+
+void AudioDeviceContext::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);
+ DCHECK(context_);
+ DCHECK(!audio_thread_.get());
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
+ socket_.reset(new base::SyncSocket(socket_handle));
+ if (context_->config.callback) {
+ FireAudioCallback();
+ audio_thread_.reset(
+ new base::DelegateSimpleThread(this, "plugin_audio_thread"));
+ audio_thread_->Start();
+ }
filter_->Send(new ViewHostMsg_PlayAudioStream(0, stream_id_));
}
void AudioDeviceContext::OnVolume(double volume) {
}
+void AudioDeviceContext::Run() {
+ int pending_data;
+ while (sizeof(pending_data) == socket_->Receive(&pending_data,
+ sizeof(pending_data)) &&
+ pending_data >= 0) {
+ FireAudioCallback();
+ }
+}
+