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

Side by Side Diff: ppapi/proxy/ppb_audio_proxy.cc

Issue 10912011: Change NaCl IPC PPAPI proxy startup to support a NaCl-Browser process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppapi_param_traits.cc ('k') | ppapi/proxy/serialized_structs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 9 #include "media/audio/shared_memory_util.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/ppb_audio.h" 11 #include "ppapi/c/ppb_audio.h"
12 #include "ppapi/c/ppb_audio_config.h" 12 #include "ppapi/c/ppb_audio_config.h"
13 #include "ppapi/c/ppb_var.h" 13 #include "ppapi/c/ppb_var.h"
14 #include "ppapi/c/trusted/ppb_audio_trusted.h" 14 #include "ppapi/c/trusted/ppb_audio_trusted.h"
15 #include "ppapi/proxy/enter_proxy.h" 15 #include "ppapi/proxy/enter_proxy.h"
16 #include "ppapi/proxy/plugin_dispatcher.h" 16 #include "ppapi/proxy/plugin_dispatcher.h"
17 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
18 #include "ppapi/shared_impl/api_id.h" 18 #include "ppapi/shared_impl/api_id.h"
19 #include "ppapi/shared_impl/platform_file.h" 19 #include "ppapi/shared_impl/platform_file.h"
20 #include "ppapi/shared_impl/ppapi_globals.h" 20 #include "ppapi/shared_impl/ppapi_globals.h"
21 #include "ppapi/shared_impl/ppb_audio_shared.h" 21 #include "ppapi/shared_impl/ppb_audio_shared.h"
22 #include "ppapi/shared_impl/resource.h" 22 #include "ppapi/shared_impl/resource.h"
23 #include "ppapi/thunk/ppb_audio_config_api.h" 23 #include "ppapi/thunk/ppb_audio_config_api.h"
24 #include "ppapi/thunk/enter.h" 24 #include "ppapi/thunk/enter.h"
25 #include "ppapi/thunk/resource_creation_api.h" 25 #include "ppapi/thunk/resource_creation_api.h"
26 #include "ppapi/thunk/thunk.h" 26 #include "ppapi/thunk/thunk.h"
27 27
28 using ppapi::IntToPlatformFile; 28 using ppapi::IntToPlatformFile;
29 using ppapi::proxy::SerializedHandle;
29 using ppapi::thunk::EnterResourceNoLock; 30 using ppapi::thunk::EnterResourceNoLock;
30 using ppapi::thunk::PPB_Audio_API; 31 using ppapi::thunk::PPB_Audio_API;
31 using ppapi::thunk::PPB_AudioConfig_API; 32 using ppapi::thunk::PPB_AudioConfig_API;
32 33
33 namespace ppapi { 34 namespace ppapi {
34 namespace proxy { 35 namespace proxy {
35 36
36 class Audio : public Resource, public PPB_Audio_Shared { 37 class Audio : public Resource, public PPB_Audio_Shared {
37 public: 38 public:
38 Audio(const HostResource& audio_id, 39 Audio(const HostResource& audio_id,
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 result_code = GetAudioConnectedHandles(resource, &socket_handle, 247 result_code = GetAudioConnectedHandles(resource, &socket_handle,
247 &shared_memory, 248 &shared_memory,
248 &audio_buffer_length); 249 &audio_buffer_length);
249 } 250 }
250 251
251 // Send all the values, even on error. This simplifies some of our cleanup 252 // Send all the values, even on error. This simplifies some of our cleanup
252 // code since the handles will be in the other process and could be 253 // code since the handles will be in the other process and could be
253 // inconvenient to clean up. Our IPC code will automatically handle this for 254 // inconvenient to clean up. Our IPC code will automatically handle this for
254 // us, as long as the remote side always closes the handles it receives 255 // us, as long as the remote side always closes the handles it receives
255 // (in OnMsgNotifyAudioStreamCreated), even in the failure case. 256 // (in OnMsgNotifyAudioStreamCreated), even in the failure case.
256 ppapi::proxy::SerializedHandle fd_wrapper(socket_handle); 257 SerializedHandle fd_wrapper(SerializedHandle::SOCKET, socket_handle);
257 258
258 // Note that we must call TotalSharedMemorySizeInBytes because 259 // Note that we must call TotalSharedMemorySizeInBytes because
259 // Audio allocates extra space in shared memory for book-keeping, so the 260 // Audio allocates extra space in shared memory for book-keeping, so the
260 // actual size of the shared memory buffer is larger than audio_buffer_length. 261 // actual size of the shared memory buffer is larger than audio_buffer_length.
261 // When sending to NaCl, NaClIPCAdapter expects this size to match the size 262 // When sending to NaCl, NaClIPCAdapter expects this size to match the size
262 // of the full shared memory buffer. 263 // of the full shared memory buffer.
263 ppapi::proxy::SerializedHandle handle_wrapper( 264 SerializedHandle handle_wrapper(
264 shared_memory, 265 shared_memory,
265 media::TotalSharedMemorySizeInBytes(audio_buffer_length)); 266 media::TotalSharedMemorySizeInBytes(audio_buffer_length));
266 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated( 267 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated(
267 API_ID_PPB_AUDIO, resource, result_code, fd_wrapper, handle_wrapper)); 268 API_ID_PPB_AUDIO, resource, result_code, fd_wrapper, handle_wrapper));
268 } 269 }
269 270
270 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( 271 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles(
271 const HostResource& resource, 272 const HostResource& resource,
272 IPC::PlatformFileForTransit* foreign_socket_handle, 273 IPC::PlatformFileForTransit* foreign_socket_handle,
273 base::SharedMemoryHandle* foreign_shared_memory_handle, 274 base::SharedMemoryHandle* foreign_shared_memory_handle,
(...skipping 28 matching lines...) Expand all
302 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) 303 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit())
303 return PP_ERROR_FAILED; 304 return PP_ERROR_FAILED;
304 305
305 return PP_OK; 306 return PP_OK;
306 } 307 }
307 308
308 // Processed in the plugin (message from host). 309 // Processed in the plugin (message from host).
309 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( 310 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated(
310 const HostResource& audio_id, 311 const HostResource& audio_id,
311 int32_t result_code, 312 int32_t result_code,
312 ppapi::proxy::SerializedHandle socket_handle, 313 SerializedHandle socket_handle,
313 ppapi::proxy::SerializedHandle handle) { 314 SerializedHandle handle) {
314 CHECK(socket_handle.is_socket()); 315 CHECK(socket_handle.is_socket());
315 CHECK(handle.is_shmem()); 316 CHECK(handle.is_shmem());
316 EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); 317 EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id);
317 if (enter.failed() || result_code != PP_OK) { 318 if (enter.failed() || result_code != PP_OK) {
318 // The caller may still have given us these handles in the failure case. 319 // The caller may still have given us these handles in the failure case.
319 // The easiest way to clean these up is to just put them in the objects 320 // The easiest way to clean these up is to just put them in the objects
320 // and then close them. This failure case is not performance critical. 321 // and then close them. This failure case is not performance critical.
321 base::SyncSocket temp_socket( 322 base::SyncSocket temp_socket(
322 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor())); 323 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
323 base::SharedMemory temp_mem(handle.shmem(), false); 324 base::SharedMemory temp_mem(handle.shmem(), false);
324 } else { 325 } else {
325 // See the comment above about how we must call 326 // See the comment above about how we must call
326 // TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here, 327 // TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here,
327 // we must call PacketSizeInBytes to get back the size of the audio buffer, 328 // we must call PacketSizeInBytes to get back the size of the audio buffer,
328 // excluding the bytes that audio uses for book-keeping. 329 // excluding the bytes that audio uses for book-keeping.
329 static_cast<Audio*>(enter.object())->SetStreamInfo( 330 static_cast<Audio*>(enter.object())->SetStreamInfo(
330 enter.resource()->pp_instance(), handle.shmem(), 331 enter.resource()->pp_instance(), handle.shmem(),
331 media::PacketSizeInBytes(handle.size()), 332 media::PacketSizeInBytes(handle.size()),
332 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor())); 333 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
333 } 334 }
334 } 335 }
335 336
336 } // namespace proxy 337 } // namespace proxy
337 } // namespace ppapi 338 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppapi_param_traits.cc ('k') | ppapi/proxy/serialized_structs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698