Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1926)

Unified Diff: ppapi/shared_impl/ppb_audio_shared.cc

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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(
« ppapi/shared_impl/ppb_audio_shared.h ('K') | « ppapi/shared_impl/ppb_audio_shared.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698