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

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

Issue 10828023: PPAPI/NaCl: Make NaClIPCAdapter transfer handles more generally (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-add gyp files 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/ppb_audio_proxy.h ('k') | ppapi/proxy/ppb_buffer_proxy.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 "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_audio.h" 11 #include "ppapi/c/ppb_audio.h"
11 #include "ppapi/c/ppb_audio_config.h" 12 #include "ppapi/c/ppb_audio_config.h"
12 #include "ppapi/c/ppb_var.h" 13 #include "ppapi/c/ppb_var.h"
13 #include "ppapi/c/trusted/ppb_audio_trusted.h" 14 #include "ppapi/c/trusted/ppb_audio_trusted.h"
14 #include "ppapi/proxy/enter_proxy.h" 15 #include "ppapi/proxy/enter_proxy.h"
15 #include "ppapi/proxy/plugin_dispatcher.h" 16 #include "ppapi/proxy/plugin_dispatcher.h"
16 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/shared_impl/api_id.h" 18 #include "ppapi/shared_impl/api_id.h"
18 #include "ppapi/shared_impl/platform_file.h" 19 #include "ppapi/shared_impl/platform_file.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 else 232 else
232 enter.object()->StopPlayback(); 233 enter.object()->StopPlayback();
233 } 234 }
234 235
235 void PPB_Audio_Proxy::AudioChannelConnected( 236 void PPB_Audio_Proxy::AudioChannelConnected(
236 int32_t result, 237 int32_t result,
237 const HostResource& resource) { 238 const HostResource& resource) {
238 IPC::PlatformFileForTransit socket_handle = 239 IPC::PlatformFileForTransit socket_handle =
239 IPC::InvalidPlatformFileForTransit(); 240 IPC::InvalidPlatformFileForTransit();
240 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); 241 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit();
241 uint32_t shared_memory_length = 0; 242 uint32_t audio_buffer_length = 0;
242 243
243 int32_t result_code = result; 244 int32_t result_code = result;
244 if (result_code == PP_OK) { 245 if (result_code == PP_OK) {
245 result_code = GetAudioConnectedHandles(resource, &socket_handle, 246 result_code = GetAudioConnectedHandles(resource, &socket_handle,
246 &shared_memory, 247 &shared_memory,
247 &shared_memory_length); 248 &audio_buffer_length);
248 } 249 }
249 250
250 // Send all the values, even on error. This simplifies some of our cleanup 251 // Send all the values, even on error. This simplifies some of our cleanup
251 // code since the handles will be in the other process and could be 252 // code since the handles will be in the other process and could be
252 // inconvenient to clean up. Our IPC code will automatically handle this for 253 // inconvenient to clean up. Our IPC code will automatically handle this for
253 // us, as long as the remote side always closes the handles it receives 254 // us, as long as the remote side always closes the handles it receives
254 // (in OnMsgNotifyAudioStreamCreated), even in the failure case. 255 // (in OnMsgNotifyAudioStreamCreated), even in the failure case.
256 ppapi::proxy::SerializedHandle fd_wrapper(socket_handle);
257
258 // Note that we must call TotalSharedMemorySizeInBytes because
259 // 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 // When sending to NaCl, NaClIPCAdapter expects this size to match the size
262 // of the full shared memory buffer.
263 ppapi::proxy::SerializedHandle handle_wrapper(
264 shared_memory,
265 media::TotalSharedMemorySizeInBytes(audio_buffer_length));
255 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated( 266 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated(
256 API_ID_PPB_AUDIO, resource, result_code, socket_handle, 267 API_ID_PPB_AUDIO, resource, result_code, fd_wrapper, handle_wrapper));
257 shared_memory, shared_memory_length));
258 } 268 }
259 269
260 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( 270 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles(
261 const HostResource& resource, 271 const HostResource& resource,
262 IPC::PlatformFileForTransit* foreign_socket_handle, 272 IPC::PlatformFileForTransit* foreign_socket_handle,
263 base::SharedMemoryHandle* foreign_shared_memory_handle, 273 base::SharedMemoryHandle* foreign_shared_memory_handle,
264 uint32_t* shared_memory_length) { 274 uint32_t* shared_memory_length) {
265 // Get the audio interface which will give us the handles. 275 // Get the audio interface which will give us the handles.
266 EnterHostFromHostResource<PPB_Audio_API> enter(resource); 276 EnterHostFromHostResource<PPB_Audio_API> enter(resource);
267 if (enter.failed()) 277 if (enter.failed())
(...skipping 24 matching lines...) Expand all
292 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) 302 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit())
293 return PP_ERROR_FAILED; 303 return PP_ERROR_FAILED;
294 304
295 return PP_OK; 305 return PP_OK;
296 } 306 }
297 307
298 // Processed in the plugin (message from host). 308 // Processed in the plugin (message from host).
299 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( 309 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated(
300 const HostResource& audio_id, 310 const HostResource& audio_id,
301 int32_t result_code, 311 int32_t result_code,
302 IPC::PlatformFileForTransit socket_handle, 312 ppapi::proxy::SerializedHandle socket_handle,
303 base::SharedMemoryHandle handle, 313 ppapi::proxy::SerializedHandle handle) {
304 uint32_t length) { 314 CHECK(socket_handle.is_socket());
315 CHECK(handle.is_shmem());
305 EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); 316 EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id);
306 if (enter.failed() || result_code != PP_OK) { 317 if (enter.failed() || result_code != PP_OK) {
307 // 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.
308 // 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
309 // and then close them. This failure case is not performance critical. 320 // and then close them. This failure case is not performance critical.
310 base::SyncSocket temp_socket( 321 base::SyncSocket temp_socket(
311 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); 322 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
312 base::SharedMemory temp_mem(handle, false); 323 base::SharedMemory temp_mem(handle.shmem(), false);
313 } else { 324 } else {
325 // See the comment above about how we must call
326 // 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 // excluding the bytes that audio uses for book-keeping.
314 static_cast<Audio*>(enter.object())->SetStreamInfo( 329 static_cast<Audio*>(enter.object())->SetStreamInfo(
315 enter.resource()->pp_instance(), handle, length, 330 enter.resource()->pp_instance(), handle.shmem(),
316 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); 331 media::PacketSizeInBytes(handle.size()),
332 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
317 } 333 }
318 } 334 }
319 335
320 } // namespace proxy 336 } // namespace proxy
321 } // namespace ppapi 337 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_audio_proxy.h ('k') | ppapi/proxy/ppb_buffer_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698