summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authordalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-05 13:39:21 +0000
committerdalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-05 13:39:21 +0000
commitdfc48e4ce465db7e44e7cb7a4d2628958e1787a0 (patch)
treed387f8da52225eb08fe29d6bc17808d04739b26c /ppapi
parent42e66e5f9dc55b57bfc95f8a49836fba59ad0cba (diff)
downloadchromium_src-dfc48e4ce465db7e44e7cb7a4d2628958e1787a0.zip
chromium_src-dfc48e4ce465db7e44e7cb7a4d2628958e1787a0.tar.gz
chromium_src-dfc48e4ce465db7e44e7cb7a4d2628958e1787a0.tar.bz2
Switch OnMoreData() to use AudioBus.
As titled, with this change we're now piping float data around the pipeline from end to end. This change is in preparation for browser side channel remixing and resampling. As a consequence of this change the shared memory now represents the contents of an AudioBus object, which is essentially audio data in a float planar format. BUG=114700 TEST=Should be no audible change. Ran all existing tests. Compiled ran WebAudio/HTML5/WebRTC on all platforms and PPAPI on Linux. Review URL: https://chromiumcodereview.appspot.com/10832285 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154951 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/DEPS1
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.cc43
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.h6
-rw-r--r--ppapi/proxy/ppb_audio_proxy.cc5
-rw-r--r--ppapi/shared_impl/ppb_audio_shared.cc37
-rw-r--r--ppapi/shared_impl/ppb_audio_shared.h11
6 files changed, 89 insertions, 14 deletions
diff --git a/ppapi/DEPS b/ppapi/DEPS
index 81c1053..bab9452 100644
--- a/ppapi/DEPS
+++ b/ppapi/DEPS
@@ -1,4 +1,5 @@
include_rules = [
+ "+media",
"+third_party/skia",
"+third_party/WebKit/Source/WebKit/chromium/public",
]
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.cc
index 18558e6..d041b29 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.cc
@@ -12,6 +12,7 @@
#include "native_client/src/include/nacl_scoped_ptr.h"
#include "native_client/src/include/portability.h"
#include "native_client/src/shared/ppapi_proxy/plugin_globals.h"
+#include "native_client/src/shared/ppapi_proxy/plugin_ppb_audio_config.h"
#include "native_client/src/shared/ppapi_proxy/plugin_resource.h"
#include "native_client/src/shared/ppapi_proxy/utility.h"
#include "native_client/src/shared/srpc/nacl_srpc.h"
@@ -30,6 +31,10 @@ size_t ceil64k(size_t n) {
return (n + 0xFFFF) & (~0xFFFF);
}
+// Hard coded values from PepperPlatformAudioOutputImpl.
+// TODO(dalecurtis): PPAPI shouldn't hard code these values for all clients.
+enum { kChannels = 2, kBytesPerSample = 2 };
+
} // namespace
PluginAudio::PluginAudio() :
@@ -42,7 +47,8 @@ PluginAudio::PluginAudio() :
thread_id_(),
thread_active_(false),
user_callback_(NULL),
- user_data_(NULL) {
+ user_data_(NULL),
+ client_buffer_size_bytes_(0) {
DebugPrintf("PluginAudio::PluginAudio\n");
}
@@ -53,10 +59,13 @@ PluginAudio::~PluginAudio() {
GetInterface()->StopPlayback(resource_);
// Unmap the shared memory buffer, if present.
if (shm_buffer_) {
+ audio_bus_.reset();
+ client_buffer_.reset();
munmap(shm_buffer_,
ceil64k(media::TotalSharedMemorySizeInBytes(shm_size_)));
shm_buffer_ = NULL;
shm_size_ = 0;
+ client_buffer_size_bytes_ = 0;
}
// Close the handles.
if (shm_ != -1) {
@@ -79,6 +88,8 @@ bool PluginAudio::InitFromBrowserResource(PP_Resource resource) {
void PluginAudio::AudioThread(void* self) {
PluginAudio* audio = static_cast<PluginAudio*>(self);
DebugPrintf("PluginAudio::AudioThread: self=%p\n", self);
+ const int bytes_per_frame =
+ sizeof(*(audio->audio_bus_->channel(0))) * audio->audio_bus_->channels();
while (true) {
int32_t sync_value;
// Block on socket read.
@@ -87,14 +98,24 @@ void PluginAudio::AudioThread(void* self) {
if ((sizeof(sync_value) != r) || (-1 == sync_value))
break;
// Invoke user callback, get next buffer of audio data.
- audio->user_callback_(audio->shm_buffer_,
- audio->shm_size_,
+ audio->user_callback_(audio->client_buffer_.get(),
+ audio->client_buffer_size_bytes_,
audio->user_data_);
+
+ // Deinterleave the audio data into the shared memory as float.
+ audio->audio_bus_->FromInterleaved(
+ audio->client_buffer_.get(), audio->audio_bus_->frames(),
+ kBytesPerSample);
+
// Signal audio backend by writing buffer length at end of buffer.
// (Note: NaCl applications will always write the entire buffer.)
- media::SetActualDataSizeInBytes(audio->shm_buffer_,
- audio->shm_size_,
- audio->shm_size_);
+ // TODO(dalecurtis): Technically this is not the exact size. Due to channel
+ // padding for alignment, there may be more data available than this. We're
+ // relying on AudioSyncReader::Read() to parse this with that in mind.
+ // Rename these methods to Set/GetActualFrameCount().
+ media::SetActualDataSizeInBytes(
+ audio->shm_buffer_, audio->shm_size_,
+ audio->audio_bus_->frames() * bytes_per_frame);
}
}
@@ -112,6 +133,15 @@ void PluginAudio::StreamCreated(NaClSrpcImcDescType socket,
shm,
0);
if (MAP_FAILED != shm_buffer_) {
+ PP_Resource ac = GetInterface()->GetCurrentConfig(resource_);
+ int frames = PluginAudioConfig::GetInterface()->GetSampleFrameCount(ac);
+
+ audio_bus_ = media::AudioBus::WrapMemory(kChannels, frames, shm_buffer_);
+ // Setup integer audio buffer for user audio data.
+ client_buffer_size_bytes_ =
+ audio_bus_->frames() * audio_bus_->channels() * kBytesPerSample;
+ client_buffer_.reset(new uint8_t[client_buffer_size_bytes_]);
+
if (state() == AUDIO_PENDING) {
StartAudioThread();
} else {
@@ -126,6 +156,7 @@ bool PluginAudio::StartAudioThread() {
// clear contents of shm buffer before spinning up audio thread
DebugPrintf("PluginAudio::StartAudioThread\n");
memset(shm_buffer_, 0, shm_size_);
+ memset(client_buffer_.get(), 0, client_buffer_size_bytes_);
const struct PP_ThreadFunctions* thread_funcs = GetThreadCreator();
if (NULL == thread_funcs->thread_create ||
NULL == thread_funcs->thread_join) {
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.h
index 07d5a7d..28713d0 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.h
+++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.h
@@ -12,6 +12,7 @@
#include "native_client/src/include/ref_counted.h"
#include "native_client/src/shared/ppapi_proxy/plugin_resource.h"
#include "native_client/src/shared/srpc/nacl_srpc.h"
+#include "media/base/audio_bus.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/ppb_audio.h"
@@ -59,6 +60,11 @@ class PluginAudio : public PluginResource {
bool thread_active_;
PPB_Audio_Callback user_callback_;
void* user_data_;
+ // AudioBus for shuttling data across the shared memory.
+ scoped_ptr<media::AudioBus> audio_bus_;
+ // Internal buffer for client's integer audio data.
+ int client_buffer_size_bytes_;
+ scoped_array<uint8_t> client_buffer_;
IMPLEMENT_RESOURCE(PluginAudio);
NACL_DISALLOW_COPY_AND_ASSIGN(PluginAudio);
diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc
index 2bd5c89..2f91fc7 100644
--- a/ppapi/proxy/ppb_audio_proxy.cc
+++ b/ppapi/proxy/ppb_audio_proxy.cc
@@ -323,6 +323,8 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated(
IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
base::SharedMemory temp_mem(handle.shmem(), false);
} else {
+ EnterResourceNoLock<PPB_AudioConfig_API> config(
+ static_cast<Audio*>(enter.object())->GetCurrentConfig(), true);
// See the comment above about how we must call
// TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here,
// we must call PacketSizeInBytes to get back the size of the audio buffer,
@@ -330,7 +332,8 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated(
static_cast<Audio*>(enter.object())->SetStreamInfo(
enter.resource()->pp_instance(), handle.shmem(),
media::PacketSizeInBytes(handle.size()),
- IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
+ IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()),
+ config.object()->GetSampleFrameCount());
}
}
diff --git a/ppapi/shared_impl/ppb_audio_shared.cc b/ppapi/shared_impl/ppb_audio_shared.cc
index d131bb3..f275559 100644
--- a/ppapi/shared_impl/ppb_audio_shared.cc
+++ b/ppapi/shared_impl/ppb_audio_shared.cc
@@ -8,6 +8,10 @@
#include "media/audio/shared_memory_util.h"
#include "ppapi/shared_impl/ppapi_globals.h"
+// Hard coded values from PepperPlatformAudioOutputImpl.
+// TODO(dalecurtis): PPAPI shouldn't hard code these values for all clients.
+enum { kChannels = 2, kBytesPerSample = 2 };
+
namespace ppapi {
#if defined(OS_NACL)
@@ -25,7 +29,8 @@ PPB_Audio_Shared::PPB_Audio_Shared()
thread_active_(false),
#endif
callback_(NULL),
- user_data_(NULL) {
+ user_data_(NULL),
+ client_buffer_size_bytes_(0) {
}
PPB_Audio_Shared::~PPB_Audio_Shared() {
@@ -67,7 +72,8 @@ void PPB_Audio_Shared::SetStreamInfo(
PP_Instance instance,
base::SharedMemoryHandle shared_memory_handle,
size_t shared_memory_size,
- base::SyncSocket::Handle socket_handle) {
+ base::SyncSocket::Handle socket_handle,
+ int sample_frame_count) {
socket_.reset(new base::CancelableSyncSocket(socket_handle));
shared_memory_.reset(new base::SharedMemory(shared_memory_handle, false));
shared_memory_size_ = shared_memory_size;
@@ -76,6 +82,13 @@ void PPB_Audio_Shared::SetStreamInfo(
media::TotalSharedMemorySizeInBytes(shared_memory_size_))) {
PpapiGlobals::Get()->LogWithSource(instance, PP_LOGLEVEL_WARNING, "",
"Failed to map shared memory for PPB_Audio_Shared.");
+ } else {
+ audio_bus_ = media::AudioBus::WrapMemory(
+ kChannels, sample_frame_count, shared_memory_->memory());
+ // Setup integer audio buffer for user audio data.
+ client_buffer_size_bytes_ =
+ audio_bus_->frames() * audio_bus_->channels() * kBytesPerSample;
+ client_buffer_.reset(new uint8_t[client_buffer_size_bytes_]);
}
StartThread();
@@ -83,12 +96,14 @@ void PPB_Audio_Shared::SetStreamInfo(
void PPB_Audio_Shared::StartThread() {
// Don't start the thread unless all our state is set up correctly.
- if (!playing_ || !callback_ || !socket_.get() || !shared_memory_->memory())
+ if (!playing_ || !callback_ || !socket_.get() || !shared_memory_->memory() ||
+ !audio_bus_.get() || !client_buffer_.get())
return;
// Clear contents of shm buffer before starting audio thread. This will
// prevent a burst of static if for some reason the audio thread doesn't
// start up quickly enough.
memset(shared_memory_->memory(), 0, shared_memory_size_);
+ memset(client_buffer_.get(), 0, client_buffer_size_bytes_);
#if !defined(OS_NACL)
DCHECK(!audio_thread_.get());
audio_thread_.reset(new base::DelegateSimpleThread(
@@ -140,16 +155,26 @@ void PPB_Audio_Shared::CallRun(void* self) {
void PPB_Audio_Shared::Run() {
int pending_data;
- void* buffer = shared_memory_->memory();
+ const int bytes_per_frame =
+ sizeof(*audio_bus_->channel(0)) * audio_bus_->channels();
while (sizeof(pending_data) ==
socket_->Receive(&pending_data, sizeof(pending_data)) &&
pending_data != media::kPauseMark) {
- callback_(buffer, shared_memory_size_, user_data_);
+ callback_(client_buffer_.get(), client_buffer_size_bytes_, user_data_);
+
+ // Deinterleave the audio data into the shared memory as float.
+ audio_bus_->FromInterleaved(
+ client_buffer_.get(), audio_bus_->frames(), kBytesPerSample);
// Let the host know we are done.
+ // TODO(dalecurtis): Technically this is not the exact size. Due to channel
+ // padding for alignment, there may be more data available than this. We're
+ // relying on AudioSyncReader::Read() to parse this with that in mind.
+ // Rename these methods to Set/GetActualFrameCount().
media::SetActualDataSizeInBytes(
- shared_memory_.get(), shared_memory_size_, shared_memory_size_);
+ shared_memory_.get(), shared_memory_size_,
+ audio_bus_->frames() * bytes_per_frame);
}
}
diff --git a/ppapi/shared_impl/ppb_audio_shared.h b/ppapi/shared_impl/ppb_audio_shared.h
index ed3a5c2..0b6afd4 100644
--- a/ppapi/shared_impl/ppb_audio_shared.h
+++ b/ppapi/shared_impl/ppb_audio_shared.h
@@ -9,6 +9,7 @@
#include "base/shared_memory.h"
#include "base/sync_socket.h"
#include "base/threading/simple_thread.h"
+#include "media/base/audio_bus.h"
#include "ppapi/c/ppb_audio.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/thunk/ppb_audio_api.h"
@@ -53,7 +54,8 @@ class PPAPI_SHARED_EXPORT PPB_Audio_Shared
void SetStreamInfo(PP_Instance instance,
base::SharedMemoryHandle shared_memory_handle,
size_t shared_memory_size,
- base::SyncSocket::Handle socket_handle);
+ base::SyncSocket::Handle socket_handle,
+ int sample_frame_count);
#if defined(OS_NACL)
// NaCl has a special API for IRT code to create threads that can call back
@@ -102,6 +104,13 @@ class PPAPI_SHARED_EXPORT PPB_Audio_Shared
// User data pointer passed verbatim to the callback function.
void* user_data_;
+ // AudioBus for shuttling data across the shared memory.
+ scoped_ptr<media::AudioBus> audio_bus_;
+
+ // Internal buffer for client's integer audio data.
+ int client_buffer_size_bytes_;
+ scoped_array<uint8_t> client_buffer_;
+
DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared);
};