| Index: ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.cc
|
| ===================================================================
|
| --- ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.cc (revision 132818)
|
| +++ ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.cc (working copy)
|
| @@ -24,11 +24,30 @@
|
| namespace ppapi_proxy {
|
| 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) {
|
| 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
|
|
|
| PluginAudio::PluginAudio() :
|
| @@ -52,7 +71,7 @@
|
| GetInterface()->StopPlayback(resource_);
|
| // Unmap the shared memory buffer, if present.
|
| if (shm_buffer_) {
|
| - munmap(shm_buffer_, ceil64k(shm_size_));
|
| + munmap(shm_buffer_, TotalSharedMemorySizeInBytes(shm_size_));
|
| shm_buffer_ = NULL;
|
| shm_size_ = 0;
|
| }
|
| @@ -79,15 +98,20 @@
|
| DebugPrintf("PluginAudio::AudioThread: self=%p\n", self);
|
| while (true) {
|
| int32_t sync_value;
|
| - // block on socket read
|
| + // Block on socket read.
|
| 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))
|
| 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->shm_size_,
|
| 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 @@
|
| shm_ = shm;
|
| shm_size_ = shm_size;
|
| shm_buffer_ = mmap(NULL,
|
| - ceil64k(shm_size),
|
| + TotalSharedMemorySizeInBytes(shm_size),
|
| PROT_READ | PROT_WRITE,
|
| MAP_SHARED,
|
| shm,
|
|
|