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

Unified Diff: ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_audio.cc

Issue 10165016: Add audio buffer size notification to NaCl proxy.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698