| Index: ppapi/proxy/ppb_audio_proxy.cc
|
| diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc
|
| index f60ac812127e96804d053ddf7ac1e5d76cc8014b..bc83be368a19e3b9f54dc272dab8d27c9a05ccd2 100644
|
| --- a/ppapi/proxy/ppb_audio_proxy.cc
|
| +++ b/ppapi/proxy/ppb_audio_proxy.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/compiler_specific.h"
|
| #include "base/threading/simple_thread.h"
|
| +#include "media/audio/shared_memory_util.h"
|
| #include "ppapi/c/pp_errors.h"
|
| #include "ppapi/c/ppb_audio.h"
|
| #include "ppapi/c/ppb_audio_config.h"
|
| @@ -238,13 +239,13 @@ void PPB_Audio_Proxy::AudioChannelConnected(
|
| IPC::PlatformFileForTransit socket_handle =
|
| IPC::InvalidPlatformFileForTransit();
|
| base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit();
|
| - uint32_t shared_memory_length = 0;
|
| + uint32_t audio_buffer_length = 0;
|
|
|
| int32_t result_code = result;
|
| if (result_code == PP_OK) {
|
| result_code = GetAudioConnectedHandles(resource, &socket_handle,
|
| &shared_memory,
|
| - &shared_memory_length);
|
| + &audio_buffer_length);
|
| }
|
|
|
| // Send all the values, even on error. This simplifies some of our cleanup
|
| @@ -252,9 +253,18 @@ void PPB_Audio_Proxy::AudioChannelConnected(
|
| // inconvenient to clean up. Our IPC code will automatically handle this for
|
| // us, as long as the remote side always closes the handles it receives
|
| // (in OnMsgNotifyAudioStreamCreated), even in the failure case.
|
| + ppapi::proxy::SerializedHandle fd_wrapper(socket_handle);
|
| +
|
| + // Note that we must call TotalSharedMemorySizeInBytes because
|
| + // Audio allocates extra space in shared memory for book-keeping, so the
|
| + // actual size of the shared memory buffer is larger than audio_buffer_length.
|
| + // When sending to NaCl, NaClIPCAdapter expects this size to match the size
|
| + // of the full shared memory buffer.
|
| + ppapi::proxy::SerializedHandle handle_wrapper(
|
| + shared_memory,
|
| + media::TotalSharedMemorySizeInBytes(audio_buffer_length));
|
| dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated(
|
| - API_ID_PPB_AUDIO, resource, result_code, socket_handle,
|
| - shared_memory, shared_memory_length));
|
| + API_ID_PPB_AUDIO, resource, result_code, fd_wrapper, handle_wrapper));
|
| }
|
|
|
| int32_t PPB_Audio_Proxy::GetAudioConnectedHandles(
|
| @@ -299,21 +309,27 @@ int32_t PPB_Audio_Proxy::GetAudioConnectedHandles(
|
| void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated(
|
| const HostResource& audio_id,
|
| int32_t result_code,
|
| - IPC::PlatformFileForTransit socket_handle,
|
| - base::SharedMemoryHandle handle,
|
| - uint32_t length) {
|
| + ppapi::proxy::SerializedHandle socket_handle,
|
| + ppapi::proxy::SerializedHandle handle) {
|
| + CHECK(socket_handle.is_socket());
|
| + CHECK(handle.is_shmem());
|
| EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id);
|
| if (enter.failed() || result_code != PP_OK) {
|
| // The caller may still have given us these handles in the failure case.
|
| // The easiest way to clean these up is to just put them in the objects
|
| // and then close them. This failure case is not performance critical.
|
| base::SyncSocket temp_socket(
|
| - IPC::PlatformFileForTransitToPlatformFile(socket_handle));
|
| - base::SharedMemory temp_mem(handle, false);
|
| + IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
|
| + base::SharedMemory temp_mem(handle.shmem(), false);
|
| } else {
|
| + // See the comment above about how we must call
|
| + // TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here,
|
| + // we must call PacketSizeInBytes to get back the size of the audio buffer,
|
| + // excluding the bytes that audio uses for book-keeping.
|
| static_cast<Audio*>(enter.object())->SetStreamInfo(
|
| - enter.resource()->pp_instance(), handle, length,
|
| - IPC::PlatformFileForTransitToPlatformFile(socket_handle));
|
| + enter.resource()->pp_instance(), handle.shmem(),
|
| + media::PacketSizeInBytes(handle.size()),
|
| + IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
|
| }
|
| }
|
|
|
|
|