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