| Index: ppapi/shared_impl/ppb_audio_shared.cc
|
| diff --git a/ppapi/shared_impl/ppb_audio_shared.cc b/ppapi/shared_impl/ppb_audio_shared.cc
|
| index 5cf30026cc7e2b84429bfe27bc445fdabacf0936..901fbc18dbe7f9f74e6bc03c8152895b08bbb73a 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(???): 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),
|
| + audio_buffer_size_(0) {
|
| }
|
|
|
| PPB_Audio_Shared::~PPB_Audio_Shared() {
|
| @@ -73,6 +78,15 @@ 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 {
|
| + // Deduce the frame count from the size using hard coded channel count.
|
| + audio_bus_ = media::AudioBus::WrapMemory(
|
| + kChannels, shared_memory_size_ / (sizeof(float) * kChannels),
|
| + shared_memory_.get());
|
| + // Setup integer audio buffer for user audio data.
|
| + audio_buffer_size_ =
|
| + audio_bus_->frames() * audio_bus_->channels() * kBytesPerSample;
|
| + audio_buffer_.reset(new uint8_t[audio_buffer_size_]);
|
| }
|
|
|
| StartThread();
|
| @@ -80,12 +94,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() || !audio_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(audio_buffer_.get(), 0, audio_buffer_size_);
|
| #if !defined(OS_NACL)
|
| DCHECK(!audio_thread_.get());
|
| audio_thread_.reset(new base::DelegateSimpleThread(
|
| @@ -140,12 +156,15 @@ void PPB_Audio_Shared::CallRun(void* self) {
|
|
|
| void PPB_Audio_Shared::Run() {
|
| int pending_data;
|
| - void* buffer = shared_memory_->memory();
|
|
|
| while (sizeof(pending_data) ==
|
| socket_->Receive(&pending_data, sizeof(pending_data)) &&
|
| pending_data != media::kPauseMark) {
|
| - callback_(buffer, shared_memory_size_, user_data_);
|
| + callback_(audio_buffer_.get(), audio_buffer_size_, user_data_);
|
| +
|
| + // Deinterleave the audio data into the shared memory as float.
|
| + audio_bus_->FromInterleaved(
|
| + audio_buffer_.get(), audio_bus_->frames(), kBytesPerSample);
|
|
|
| // Let the host know we are done.
|
| media::SetActualDataSizeInBytes(
|
|
|