Commit 62eec401 authored by nfullagar@google.com's avatar nfullagar@google.com

Add audio buffer size notification to NaCl proxy.

BUG=http://code.google.com/p/chromium/issues/detail?id=120837
TEST=variuos nacl audio samples


Review URL: http://codereview.chromium.org/10165016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133502 0039d316-1c4b-4281-b951-d872f2087c98
parent c00e6859
...@@ -24,11 +24,30 @@ ...@@ -24,11 +24,30 @@
namespace ppapi_proxy { namespace ppapi_proxy {
namespace { namespace {
// round size up to next 64k // Round size up to next 64k; required for NaCl's version of mmap().
size_t ceil64k(size_t n) { size_t ceil64k(size_t n) {
return (n + 0xFFFF) & (~0xFFFF); return (n + 0xFFFF) & (~0xFFFF);
} }
// The following two functions (TotalSharedMemorySizeInBytes,
// SetActualDataSizeInBytes) are copied & similar to audio_util.cc.
uint32_t TotalSharedMemorySizeInBytes(size_t packet_size) {
// Need to reserve extra 4 bytes for size of data.
return ceil64k(packet_size + sizeof(uint32_t));
}
void SetActualDataSizeInBytes(void* audio_buffer,
uint32_t buffer_size_in_bytes,
uint32_t actual_size_in_bytes) {
char* end = static_cast<char*>(audio_buffer) + buffer_size_in_bytes;
DCHECK(0 == (reinterpret_cast<size_t>(end) & 3));
volatile uint32_t* end32 = reinterpret_cast<volatile uint32_t*>(end);
// Set actual data size at the end of the buffer.
__sync_synchronize();
*end32 = actual_size_in_bytes;
}
} // namespace } // namespace
PluginAudio::PluginAudio() : PluginAudio::PluginAudio() :
...@@ -52,7 +71,7 @@ PluginAudio::~PluginAudio() { ...@@ -52,7 +71,7 @@ PluginAudio::~PluginAudio() {
GetInterface()->StopPlayback(resource_); GetInterface()->StopPlayback(resource_);
// Unmap the shared memory buffer, if present. // Unmap the shared memory buffer, if present.
if (shm_buffer_) { if (shm_buffer_) {
munmap(shm_buffer_, ceil64k(shm_size_)); munmap(shm_buffer_, TotalSharedMemorySizeInBytes(shm_size_));
shm_buffer_ = NULL; shm_buffer_ = NULL;
shm_size_ = 0; shm_size_ = 0;
} }
...@@ -79,15 +98,20 @@ void PluginAudio::AudioThread(void* self) { ...@@ -79,15 +98,20 @@ void PluginAudio::AudioThread(void* self) {
DebugPrintf("PluginAudio::AudioThread: self=%p\n", self); DebugPrintf("PluginAudio::AudioThread: self=%p\n", self);
while (true) { while (true) {
int32_t sync_value; int32_t sync_value;
// block on socket read // Block on socket read.
ssize_t r = read(audio->socket_, &sync_value, sizeof(sync_value)); ssize_t r = read(audio->socket_, &sync_value, sizeof(sync_value));
// StopPlayback() will send a value of -1 over the sync_socket // StopPlayback() will send a value of -1 over the sync_socket.
if ((sizeof(sync_value) != r) || (-1 == sync_value)) if ((sizeof(sync_value) != r) || (-1 == sync_value))
break; break;
// invoke user callback, get next buffer of audio data // Invoke user callback, get next buffer of audio data.
audio->user_callback_(audio->shm_buffer_, audio->user_callback_(audio->shm_buffer_,
audio->shm_size_, audio->shm_size_,
audio->user_data_); audio->user_data_);
// Signal audio backend by writing buffer length at end of buffer.
// (Note: NaCl applications will always write the entire buffer.)
SetActualDataSizeInBytes(audio->shm_buffer_,
audio->shm_size_,
audio->shm_size_);
} }
} }
...@@ -99,7 +123,7 @@ void PluginAudio::StreamCreated(NaClSrpcImcDescType socket, ...@@ -99,7 +123,7 @@ void PluginAudio::StreamCreated(NaClSrpcImcDescType socket,
shm_ = shm; shm_ = shm;
shm_size_ = shm_size; shm_size_ = shm_size;
shm_buffer_ = mmap(NULL, shm_buffer_ = mmap(NULL,
ceil64k(shm_size), TotalSharedMemorySizeInBytes(shm_size),
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_SHARED, MAP_SHARED,
shm, shm,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment