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_input_proxy.h" | 5 #include "ppapi/proxy/ppb_audio_input_proxy.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "media/audio/shared_memory_util.h" |
8 #include "ppapi/c/dev/ppb_audio_input_dev.h" | 9 #include "ppapi/c/dev/ppb_audio_input_dev.h" |
9 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/ppb_audio_config.h" | 11 #include "ppapi/c/ppb_audio_config.h" |
11 #include "ppapi/proxy/enter_proxy.h" | 12 #include "ppapi/proxy/enter_proxy.h" |
12 #include "ppapi/proxy/plugin_dispatcher.h" | 13 #include "ppapi/proxy/plugin_dispatcher.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
14 #include "ppapi/shared_impl/api_id.h" | 15 #include "ppapi/shared_impl/api_id.h" |
15 #include "ppapi/shared_impl/platform_file.h" | 16 #include "ppapi/shared_impl/platform_file.h" |
16 #include "ppapi/shared_impl/ppapi_globals.h" | 17 #include "ppapi/shared_impl/ppapi_globals.h" |
17 #include "ppapi/shared_impl/ppb_audio_input_shared.h" | 18 #include "ppapi/shared_impl/ppb_audio_input_shared.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); | 280 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); |
280 if (enter.succeeded()) { | 281 if (enter.succeeded()) { |
281 static_cast<AudioInput*>(enter.object())->OnEnumerateDevicesComplete( | 282 static_cast<AudioInput*>(enter.object())->OnEnumerateDevicesComplete( |
282 result, devices); | 283 result, devices); |
283 } | 284 } |
284 } | 285 } |
285 | 286 |
286 void PPB_AudioInput_Proxy::OnMsgOpenACK( | 287 void PPB_AudioInput_Proxy::OnMsgOpenACK( |
287 const HostResource& audio_input, | 288 const HostResource& audio_input, |
288 int32_t result, | 289 int32_t result, |
289 IPC::PlatformFileForTransit socket_handle, | 290 const ppapi::proxy::SerializedHandle& socket_handle, |
290 base::SharedMemoryHandle handle, | 291 const ppapi::proxy::SerializedHandle& handle) { |
291 uint32_t length) { | 292 CHECK(socket_handle.is_socket()); |
| 293 CHECK(handle.is_shmem()); |
292 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); | 294 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); |
293 if (enter.failed()) { | 295 if (enter.failed()) { |
294 // The caller may still have given us these handles in the failure case. | 296 // The caller may still have given us these handles in the failure case. |
295 // The easiest way to clean these up is to just put them in the objects | 297 // The easiest way to clean these up is to just put them in the objects |
296 // and then close them. This failure case is not performance critical. | 298 // and then close them. This failure case is not performance critical. |
297 base::SyncSocket temp_socket( | 299 base::SyncSocket temp_socket( |
298 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | 300 IPC::PlatformFileForTransitToPlatformFile( |
299 base::SharedMemory temp_mem(handle, false); | 301 socket_handle.descriptor())); |
| 302 base::SharedMemory temp_mem(handle.shmem(), false); |
300 } else { | 303 } else { |
| 304 // See the comment above about how we must call |
| 305 // TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here, |
| 306 // we must call PacketSizeInBytes to get back the size of the audio buffer, |
| 307 // excluding the bytes that audio uses for book-keeping. |
301 static_cast<AudioInput*>(enter.object())->OnOpenComplete( | 308 static_cast<AudioInput*>(enter.object())->OnOpenComplete( |
302 result, handle, length, | 309 result, handle.shmem(), media::PacketSizeInBytes(handle.size()), |
303 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | 310 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor())); |
304 } | 311 } |
305 } | 312 } |
306 | 313 |
307 void PPB_AudioInput_Proxy::EnumerateDevicesACKInHost( | 314 void PPB_AudioInput_Proxy::EnumerateDevicesACKInHost( |
308 int32_t result, | 315 int32_t result, |
309 const HostResource& audio_input) { | 316 const HostResource& audio_input) { |
310 EnterHostFromHostResource<PPB_AudioInput_API> enter(audio_input); | 317 EnterHostFromHostResource<PPB_AudioInput_API> enter(audio_input); |
311 dispatcher()->Send(new PpapiMsg_PPBAudioInput_EnumerateDevicesACK( | 318 dispatcher()->Send(new PpapiMsg_PPBAudioInput_EnumerateDevicesACK( |
312 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, | 319 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, |
313 enter.succeeded() && result == PP_OK ? | 320 enter.succeeded() && result == PP_OK ? |
314 enter.object()->GetDeviceRefData() : std::vector<DeviceRefData>())); | 321 enter.object()->GetDeviceRefData() : std::vector<DeviceRefData>())); |
315 } | 322 } |
316 | 323 |
317 void PPB_AudioInput_Proxy::OpenACKInHost(int32_t result, | 324 void PPB_AudioInput_Proxy::OpenACKInHost(int32_t result, |
318 const HostResource& audio_input) { | 325 const HostResource& audio_input) { |
319 IPC::PlatformFileForTransit socket_handle = | 326 ppapi::proxy::SerializedHandle socket_handle( |
320 IPC::InvalidPlatformFileForTransit(); | 327 ppapi::proxy::SerializedHandle::SOCKET); |
321 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); | 328 ppapi::proxy::SerializedHandle shared_memory( |
322 uint32_t shared_memory_length = 0; | 329 ppapi::proxy::SerializedHandle::SHARED_MEMORY); |
323 | 330 |
324 if (result == PP_OK) { | 331 if (result == PP_OK) { |
325 result = GetAudioInputConnectedHandles(audio_input, &socket_handle, | 332 IPC::PlatformFileForTransit temp_socket; |
326 &shared_memory, | 333 base::SharedMemoryHandle temp_shmem; |
327 &shared_memory_length); | 334 uint32_t audio_buffer_size; |
| 335 result = GetAudioInputConnectedHandles(audio_input, &temp_socket, |
| 336 &temp_shmem, &audio_buffer_size); |
| 337 if (result == PP_OK) { |
| 338 socket_handle.set_socket(temp_socket); |
| 339 // Note that we must call TotalSharedMemorySizeInBytes because |
| 340 // Audio allocates extra space in shared memory for book-keeping, so the |
| 341 // actual size of the shared memory buffer is larger than |
| 342 // audio_buffer_length. When sending to NaCl, NaClIPCAdapter expects this |
| 343 // size to match the size of the full shared memory buffer. |
| 344 shared_memory.set_shmem( |
| 345 temp_shmem, |
| 346 media::TotalSharedMemorySizeInBytes(audio_buffer_size)); |
| 347 } |
328 } | 348 } |
329 | 349 |
330 // Send all the values, even on error. This simplifies some of our cleanup | 350 // Send all the values, even on error. This simplifies some of our cleanup |
331 // code since the handles will be in the other process and could be | 351 // code since the handles will be in the other process and could be |
332 // inconvenient to clean up. Our IPC code will automatically handle this for | 352 // inconvenient to clean up. Our IPC code will automatically handle this for |
333 // us, as long as the remote side always closes the handles it receives | 353 // us, as long as the remote side always closes the handles it receives |
334 // (in OnMsgOpenACK), even in the failure case. | 354 // (in OnMsgOpenACK), even in the failure case. |
335 dispatcher()->Send(new PpapiMsg_PPBAudioInput_OpenACK( | 355 dispatcher()->Send(new PpapiMsg_PPBAudioInput_OpenACK( |
336 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, socket_handle, | 356 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, socket_handle, |
337 shared_memory, shared_memory_length)); | 357 shared_memory)); |
338 } | 358 } |
339 | 359 |
340 int32_t PPB_AudioInput_Proxy::GetAudioInputConnectedHandles( | 360 int32_t PPB_AudioInput_Proxy::GetAudioInputConnectedHandles( |
341 const HostResource& resource, | 361 const HostResource& resource, |
342 IPC::PlatformFileForTransit* foreign_socket_handle, | 362 IPC::PlatformFileForTransit* foreign_socket_handle, |
343 base::SharedMemoryHandle* foreign_shared_memory_handle, | 363 base::SharedMemoryHandle* foreign_shared_memory_handle, |
344 uint32_t* shared_memory_length) { | 364 uint32_t* shared_memory_length) { |
345 // Get the audio interface which will give us the handles. | 365 // Get the audio interface which will give us the handles. |
346 EnterHostFromHostResource<PPB_AudioInput_API> enter(resource); | 366 EnterHostFromHostResource<PPB_AudioInput_API> enter(resource); |
347 if (enter.failed()) | 367 if (enter.failed()) |
(...skipping 22 matching lines...) Expand all Loading... |
370 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( | 390 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( |
371 IntToPlatformFile(shared_memory_handle), false); | 391 IntToPlatformFile(shared_memory_handle), false); |
372 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) | 392 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
373 return PP_ERROR_FAILED; | 393 return PP_ERROR_FAILED; |
374 | 394 |
375 return PP_OK; | 395 return PP_OK; |
376 } | 396 } |
377 | 397 |
378 } // namespace proxy | 398 } // namespace proxy |
379 } // namespace ppapi | 399 } // namespace ppapi |
OLD | NEW |