| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/c/ppb_audio.h" | 10 #include "ppapi/c/ppb_audio.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 int32_t Audio::GetSyncSocket(int* sync_socket) { | 109 int32_t Audio::GetSyncSocket(int* sync_socket) { |
| 110 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | 110 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 111 } | 111 } |
| 112 | 112 |
| 113 int32_t Audio::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { | 113 int32_t Audio::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { |
| 114 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | 114 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 115 } | 115 } |
| 116 | 116 |
| 117 namespace { | 117 namespace { |
| 118 | 118 |
| 119 InterfaceProxy* CreateAudioProxy(Dispatcher* dispatcher, |
| 120 const void* target_interface) { |
| 121 return new PPB_Audio_Proxy(dispatcher, target_interface); |
| 122 } |
| 123 |
| 119 base::PlatformFile IntToPlatformFile(int32_t handle) { | 124 base::PlatformFile IntToPlatformFile(int32_t handle) { |
| 120 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, | 125 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, |
| 121 // those casts are ugly. | 126 // those casts are ugly. |
| 122 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
| 123 return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle)); | 128 return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle)); |
| 124 #elif defined(OS_POSIX) | 129 #elif defined(OS_POSIX) |
| 125 return handle; | 130 return handle; |
| 126 #else | 131 #else |
| 127 #error Not implemented. | 132 #error Not implemented. |
| 128 #endif | 133 #endif |
| 129 } | 134 } |
| 130 | 135 |
| 131 } // namespace | 136 } // namespace |
| 132 | 137 |
| 133 PPB_Audio_Proxy::PPB_Audio_Proxy(Dispatcher* dispatcher) | 138 PPB_Audio_Proxy::PPB_Audio_Proxy(Dispatcher* dispatcher, |
| 134 : InterfaceProxy(dispatcher), | 139 const void* target_interface) |
| 140 : InterfaceProxy(dispatcher, target_interface), |
| 135 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 141 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 136 } | 142 } |
| 137 | 143 |
| 138 PPB_Audio_Proxy::~PPB_Audio_Proxy() { | 144 PPB_Audio_Proxy::~PPB_Audio_Proxy() { |
| 139 } | 145 } |
| 140 | 146 |
| 141 // static | 147 // static |
| 148 const InterfaceProxy::Info* PPB_Audio_Proxy::GetInfo() { |
| 149 static const Info info = { |
| 150 thunk::GetPPB_Audio_Thunk(), |
| 151 PPB_AUDIO_INTERFACE, |
| 152 INTERFACE_ID_PPB_AUDIO, |
| 153 false, |
| 154 &CreateAudioProxy, |
| 155 }; |
| 156 return &info; |
| 157 } |
| 158 |
| 159 // static |
| 142 PP_Resource PPB_Audio_Proxy::CreateProxyResource( | 160 PP_Resource PPB_Audio_Proxy::CreateProxyResource( |
| 143 PP_Instance instance_id, | 161 PP_Instance instance_id, |
| 144 PP_Resource config_id, | 162 PP_Resource config_id, |
| 145 PPB_Audio_Callback audio_callback, | 163 PPB_Audio_Callback audio_callback, |
| 146 void* user_data) { | 164 void* user_data) { |
| 147 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); | 165 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 148 if (!dispatcher) | 166 if (!dispatcher) |
| 149 return 0; | 167 return 0; |
| 150 | 168 |
| 151 EnterResourceNoLock<PPB_AudioConfig_API> config(config_id, true); | 169 EnterResourceNoLock<PPB_AudioConfig_API> config(config_id, true); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 enter.SetResult(PP_ERROR_FAILED); | 235 enter.SetResult(PP_ERROR_FAILED); |
| 218 return; | 236 return; |
| 219 } | 237 } |
| 220 | 238 |
| 221 // Initiate opening the audio object. | 239 // Initiate opening the audio object. |
| 222 enter.SetResult(enter.object()->OpenTrusted(audio_config_res, | 240 enter.SetResult(enter.object()->OpenTrusted(audio_config_res, |
| 223 enter.callback())); | 241 enter.callback())); |
| 224 | 242 |
| 225 // Clean up the temporary audio config resource we made. | 243 // Clean up the temporary audio config resource we made. |
| 226 const PPB_Core* core = static_cast<const PPB_Core*>( | 244 const PPB_Core* core = static_cast<const PPB_Core*>( |
| 227 dispatcher()->local_get_interface()(PPB_CORE_INTERFACE)); | 245 dispatcher()->GetLocalInterface(PPB_CORE_INTERFACE)); |
| 228 core->ReleaseResource(audio_config_res); | 246 core->ReleaseResource(audio_config_res); |
| 229 } | 247 } |
| 230 | 248 |
| 231 void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id, | 249 void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id, |
| 232 bool play) { | 250 bool play) { |
| 233 EnterHostFromHostResource<PPB_Audio_API> enter(audio_id); | |
| 234 if (enter.failed()) | |
| 235 return; | |
| 236 if (play) | 251 if (play) |
| 237 enter.object()->StartPlayback(); | 252 ppb_audio_target()->StartPlayback(audio_id.host_resource()); |
| 238 else | 253 else |
| 239 enter.object()->StopPlayback(); | 254 ppb_audio_target()->StopPlayback(audio_id.host_resource()); |
| 240 } | 255 } |
| 241 | 256 |
| 242 // Processed in the plugin (message from host). | 257 // Processed in the plugin (message from host). |
| 243 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( | 258 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( |
| 244 const HostResource& audio_id, | 259 const HostResource& audio_id, |
| 245 int32_t result_code, | 260 int32_t result_code, |
| 246 IPC::PlatformFileForTransit socket_handle, | 261 IPC::PlatformFileForTransit socket_handle, |
| 247 base::SharedMemoryHandle handle, | 262 base::SharedMemoryHandle handle, |
| 248 uint32_t length) { | 263 uint32_t length) { |
| 249 EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); | 264 EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 INTERFACE_ID_PPB_AUDIO, resource, result_code, socket_handle, | 300 INTERFACE_ID_PPB_AUDIO, resource, result_code, socket_handle, |
| 286 shared_memory, shared_memory_length)); | 301 shared_memory, shared_memory_length)); |
| 287 } | 302 } |
| 288 | 303 |
| 289 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( | 304 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( |
| 290 const HostResource& resource, | 305 const HostResource& resource, |
| 291 IPC::PlatformFileForTransit* foreign_socket_handle, | 306 IPC::PlatformFileForTransit* foreign_socket_handle, |
| 292 base::SharedMemoryHandle* foreign_shared_memory_handle, | 307 base::SharedMemoryHandle* foreign_shared_memory_handle, |
| 293 uint32_t* shared_memory_length) { | 308 uint32_t* shared_memory_length) { |
| 294 // Get the audio interface which will give us the handles. | 309 // Get the audio interface which will give us the handles. |
| 295 EnterHostFromHostResource<PPB_Audio_API> enter(resource); | 310 EnterResourceNoLock<PPB_Audio_API> enter(resource.host_resource(), false); |
| 296 if (enter.failed()) | 311 if (enter.failed()) |
| 297 return PP_ERROR_NOINTERFACE; | 312 return PP_ERROR_NOINTERFACE; |
| 298 | 313 |
| 299 // Get the socket handle for signaling. | 314 // Get the socket handle for signaling. |
| 300 int32_t socket_handle; | 315 int32_t socket_handle; |
| 301 int32_t result = enter.object()->GetSyncSocket(&socket_handle); | 316 int32_t result = enter.object()->GetSyncSocket(&socket_handle); |
| 302 if (result != PP_OK) | 317 if (result != PP_OK) |
| 303 return result; | 318 return result; |
| 304 | 319 |
| 305 // socket_handle doesn't belong to us: don't close it. | 320 // socket_handle doesn't belong to us: don't close it. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 319 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( | 334 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( |
| 320 IntToPlatformFile(shared_memory_handle), false); | 335 IntToPlatformFile(shared_memory_handle), false); |
| 321 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) | 336 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
| 322 return PP_ERROR_FAILED; | 337 return PP_ERROR_FAILED; |
| 323 | 338 |
| 324 return PP_OK; | 339 return PP_OK; |
| 325 } | 340 } |
| 326 | 341 |
| 327 } // namespace proxy | 342 } // namespace proxy |
| 328 } // namespace ppapi | 343 } // namespace ppapi |
| OLD | NEW |