OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppb_audio_proxy.h" | 5 #include "ppapi/proxy/ppb_audio_proxy.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/threading/simple_thread.h" | 8 #include "base/threading/simple_thread.h" |
9 #include "media/audio/shared_memory_util.h" | |
10 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/c/ppb_audio.h" | 10 #include "ppapi/c/ppb_audio.h" |
12 #include "ppapi/c/ppb_audio_config.h" | 11 #include "ppapi/c/ppb_audio_config.h" |
13 #include "ppapi/c/ppb_var.h" | 12 #include "ppapi/c/ppb_var.h" |
14 #include "ppapi/proxy/enter_proxy.h" | 13 #include "ppapi/proxy/enter_proxy.h" |
15 #include "ppapi/proxy/plugin_dispatcher.h" | 14 #include "ppapi/proxy/plugin_dispatcher.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
17 #include "ppapi/shared_impl/api_id.h" | 16 #include "ppapi/shared_impl/api_id.h" |
18 #include "ppapi/shared_impl/platform_file.h" | 17 #include "ppapi/shared_impl/platform_file.h" |
19 #include "ppapi/shared_impl/ppapi_globals.h" | 18 #include "ppapi/shared_impl/ppapi_globals.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 &shared_memory, | 254 &shared_memory, |
256 &audio_buffer_length); | 255 &audio_buffer_length); |
257 } | 256 } |
258 | 257 |
259 // Send all the values, even on error. This simplifies some of our cleanup | 258 // Send all the values, even on error. This simplifies some of our cleanup |
260 // code since the handles will be in the other process and could be | 259 // code since the handles will be in the other process and could be |
261 // inconvenient to clean up. Our IPC code will automatically handle this for | 260 // inconvenient to clean up. Our IPC code will automatically handle this for |
262 // us, as long as the remote side always closes the handles it receives | 261 // us, as long as the remote side always closes the handles it receives |
263 // (in OnMsgNotifyAudioStreamCreated), even in the failure case. | 262 // (in OnMsgNotifyAudioStreamCreated), even in the failure case. |
264 SerializedHandle fd_wrapper(SerializedHandle::SOCKET, socket_handle); | 263 SerializedHandle fd_wrapper(SerializedHandle::SOCKET, socket_handle); |
265 | 264 SerializedHandle handle_wrapper(shared_memory, audio_buffer_length); |
266 // Note that we must call TotalSharedMemorySizeInBytes because | |
267 // Audio allocates extra space in shared memory for book-keeping, so the | |
268 // actual size of the shared memory buffer is larger than audio_buffer_length. | |
269 // When sending to NaCl, NaClIPCAdapter expects this size to match the size | |
270 // of the full shared memory buffer. | |
271 SerializedHandle handle_wrapper( | |
272 shared_memory, | |
273 media::TotalSharedMemorySizeInBytes(audio_buffer_length)); | |
274 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated( | 265 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated( |
275 API_ID_PPB_AUDIO, resource, result_code, fd_wrapper, handle_wrapper)); | 266 API_ID_PPB_AUDIO, resource, result_code, fd_wrapper, handle_wrapper)); |
276 } | 267 } |
277 | 268 |
278 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( | 269 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( |
279 const HostResource& resource, | 270 const HostResource& resource, |
280 IPC::PlatformFileForTransit* foreign_socket_handle, | 271 IPC::PlatformFileForTransit* foreign_socket_handle, |
281 base::SharedMemoryHandle* foreign_shared_memory_handle, | 272 base::SharedMemoryHandle* foreign_shared_memory_handle, |
282 uint32_t* shared_memory_length) { | 273 uint32_t* shared_memory_length) { |
283 // Get the audio interface which will give us the handles. | 274 // Get the audio interface which will give us the handles. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 if (enter.failed() || result_code != PP_OK) { | 317 if (enter.failed() || result_code != PP_OK) { |
327 // The caller may still have given us these handles in the failure case. | 318 // The caller may still have given us these handles in the failure case. |
328 // The easiest way to clean these up is to just put them in the objects | 319 // The easiest way to clean these up is to just put them in the objects |
329 // and then close them. This failure case is not performance critical. | 320 // and then close them. This failure case is not performance critical. |
330 base::SyncSocket temp_socket( | 321 base::SyncSocket temp_socket( |
331 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor())); | 322 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor())); |
332 base::SharedMemory temp_mem(handle.shmem(), false); | 323 base::SharedMemory temp_mem(handle.shmem(), false); |
333 } else { | 324 } else { |
334 EnterResourceNoLock<PPB_AudioConfig_API> config( | 325 EnterResourceNoLock<PPB_AudioConfig_API> config( |
335 static_cast<Audio*>(enter.object())->GetCurrentConfig(), true); | 326 static_cast<Audio*>(enter.object())->GetCurrentConfig(), true); |
336 // See the comment above about how we must call | |
337 // TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here, | |
338 // we must call PacketSizeInBytes to get back the size of the audio buffer, | |
339 // excluding the bytes that audio uses for book-keeping. | |
340 static_cast<Audio*>(enter.object())->SetStreamInfo( | 327 static_cast<Audio*>(enter.object())->SetStreamInfo( |
341 enter.resource()->pp_instance(), handle.shmem(), | 328 enter.resource()->pp_instance(), handle.shmem(), handle.size(), |
342 media::PacketSizeInBytes(handle.size()), | |
343 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()), | 329 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()), |
344 config.object()->GetSampleRate(), | 330 config.object()->GetSampleRate(), |
345 config.object()->GetSampleFrameCount()); | 331 config.object()->GetSampleFrameCount()); |
346 } | 332 } |
347 } | 333 } |
348 | 334 |
349 } // namespace proxy | 335 } // namespace proxy |
350 } // namespace ppapi | 336 } // namespace ppapi |
OLD | NEW |