Chromium Code Reviews| 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/threading/simple_thread.h" | 7 #include "base/threading/simple_thread.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
|
cpu_(ooo_6.6-7.5)
2011/08/03 00:57:21
noticing it is not including compiler_specific.h f
| |
| 9 #include "ppapi/c/ppb_audio.h" | 9 #include "ppapi/c/ppb_audio.h" |
| 10 #include "ppapi/c/ppb_audio_config.h" | 10 #include "ppapi/c/ppb_audio_config.h" |
| 11 #include "ppapi/c/ppb_var.h" | 11 #include "ppapi/c/ppb_var.h" |
| 12 #include "ppapi/c/trusted/ppb_audio_trusted.h" | 12 #include "ppapi/c/trusted/ppb_audio_trusted.h" |
| 13 #include "ppapi/proxy/enter_proxy.h" | 13 #include "ppapi/proxy/enter_proxy.h" |
| 14 #include "ppapi/proxy/interface_id.h" | 14 #include "ppapi/proxy/interface_id.h" |
| 15 #include "ppapi/proxy/plugin_dispatcher.h" | 15 #include "ppapi/proxy/plugin_dispatcher.h" |
| 16 #include "ppapi/proxy/plugin_resource.h" | 16 #include "ppapi/proxy/plugin_resource.h" |
| 17 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
| 18 #include "ppapi/shared_impl/audio_impl.h" | 18 #include "ppapi/shared_impl/audio_impl.h" |
| 19 #include "ppapi/thunk/ppb_audio_config_api.h" | 19 #include "ppapi/thunk/ppb_audio_config_api.h" |
| 20 #include "ppapi/thunk/ppb_audio_trusted_api.h" | |
| 21 #include "ppapi/thunk/enter.h" | 20 #include "ppapi/thunk/enter.h" |
| 22 #include "ppapi/thunk/resource_creation_api.h" | 21 #include "ppapi/thunk/resource_creation_api.h" |
| 23 #include "ppapi/thunk/thunk.h" | 22 #include "ppapi/thunk/thunk.h" |
| 24 | 23 |
| 25 using ::ppapi::thunk::PPB_Audio_API; | 24 using ppapi::thunk::EnterResourceNoLock; |
| 25 using ppapi::thunk::PPB_Audio_API; | |
| 26 using ppapi::thunk::PPB_AudioConfig_API; | |
| 26 | 27 |
| 27 namespace pp { | 28 namespace pp { |
| 28 namespace proxy { | 29 namespace proxy { |
| 29 | 30 |
| 30 class Audio : public PluginResource, public ppapi::AudioImpl { | 31 class Audio : public PluginResource, public ppapi::AudioImpl { |
| 31 public: | 32 public: |
| 32 Audio(const HostResource& audio_id, | 33 Audio(const HostResource& audio_id, |
| 33 PP_Resource config_id, | 34 PP_Resource config_id, |
| 34 PPB_Audio_Callback callback, | 35 PPB_Audio_Callback callback, |
| 35 void* user_data); | 36 void* user_data); |
| 36 virtual ~Audio(); | 37 virtual ~Audio(); |
| 37 | 38 |
| 38 // ResourceObjectBase overrides. | 39 // ResourceObjectBase overrides. |
| 39 virtual PPB_Audio_API* AsPPB_Audio_API(); | 40 virtual PPB_Audio_API* AsPPB_Audio_API(); |
| 40 | 41 |
| 41 // PPB_Audio_API implementation. | 42 // PPB_Audio_API implementation. |
| 42 virtual PP_Resource GetCurrentConfig() OVERRIDE; | 43 virtual PP_Resource GetCurrentConfig() OVERRIDE; |
| 43 virtual PP_Bool StartPlayback() OVERRIDE; | 44 virtual PP_Bool StartPlayback() OVERRIDE; |
| 44 virtual PP_Bool StopPlayback() OVERRIDE; | 45 virtual PP_Bool StopPlayback() OVERRIDE; |
| 46 virtual int32_t OpenTrusted(PP_Resource config_id, | |
| 47 PP_CompletionCallback create_callback) OVERRIDE; | |
| 48 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; | |
| 49 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; | |
| 45 | 50 |
| 46 private: | 51 private: |
| 47 // Owning reference to the current config object. This isn't actually used, | 52 // Owning reference to the current config object. This isn't actually used, |
| 48 // we just dish it out as requested by the plugin. | 53 // we just dish it out as requested by the plugin. |
| 49 PP_Resource config_; | 54 PP_Resource config_; |
| 50 | 55 |
| 51 DISALLOW_COPY_AND_ASSIGN(Audio); | 56 DISALLOW_COPY_AND_ASSIGN(Audio); |
| 52 }; | 57 }; |
| 53 | 58 |
| 54 Audio::Audio(const HostResource& audio_id, | 59 Audio::Audio(const HostResource& audio_id, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 PP_Bool Audio::StopPlayback() { | 93 PP_Bool Audio::StopPlayback() { |
| 89 if (!playing()) | 94 if (!playing()) |
| 90 return PP_TRUE; | 95 return PP_TRUE; |
| 91 PluginDispatcher::GetForInstance(instance())->Send( | 96 PluginDispatcher::GetForInstance(instance())->Send( |
| 92 new PpapiHostMsg_PPBAudio_StartOrStop( | 97 new PpapiHostMsg_PPBAudio_StartOrStop( |
| 93 INTERFACE_ID_PPB_AUDIO, host_resource(), false)); | 98 INTERFACE_ID_PPB_AUDIO, host_resource(), false)); |
| 94 SetStopPlaybackState(); | 99 SetStopPlaybackState(); |
| 95 return PP_TRUE; | 100 return PP_TRUE; |
| 96 } | 101 } |
| 97 | 102 |
| 103 int32_t Audio::OpenTrusted(PP_Resource config_id, | |
| 104 PP_CompletionCallback create_callback) { | |
| 105 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | |
| 106 } | |
| 107 | |
| 108 int32_t Audio::GetSyncSocket(int* sync_socket) { | |
| 109 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | |
| 110 } | |
| 111 | |
| 112 int32_t Audio::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { | |
| 113 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | |
| 114 } | |
| 115 | |
| 98 namespace { | 116 namespace { |
| 99 | 117 |
| 100 InterfaceProxy* CreateAudioProxy(Dispatcher* dispatcher, | 118 InterfaceProxy* CreateAudioProxy(Dispatcher* dispatcher, |
| 101 const void* target_interface) { | 119 const void* target_interface) { |
| 102 return new PPB_Audio_Proxy(dispatcher, target_interface); | 120 return new PPB_Audio_Proxy(dispatcher, target_interface); |
| 103 } | 121 } |
| 104 | 122 |
| 105 base::PlatformFile IntToPlatformFile(int32_t handle) { | 123 base::PlatformFile IntToPlatformFile(int32_t handle) { |
| 106 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, | 124 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, |
| 107 // those casts are ugly. | 125 // those casts are ugly. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 // static | 158 // static |
| 141 PP_Resource PPB_Audio_Proxy::CreateProxyResource( | 159 PP_Resource PPB_Audio_Proxy::CreateProxyResource( |
| 142 PP_Instance instance_id, | 160 PP_Instance instance_id, |
| 143 PP_Resource config_id, | 161 PP_Resource config_id, |
| 144 PPB_Audio_Callback audio_callback, | 162 PPB_Audio_Callback audio_callback, |
| 145 void* user_data) { | 163 void* user_data) { |
| 146 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); | 164 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 147 if (!dispatcher) | 165 if (!dispatcher) |
| 148 return 0; | 166 return 0; |
| 149 | 167 |
| 150 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioConfig_API> | 168 EnterResourceNoLock<PPB_AudioConfig_API> config(config_id, true); |
| 151 config(config_id, true); | |
| 152 if (config.failed()) | 169 if (config.failed()) |
| 153 return 0; | 170 return 0; |
| 154 | 171 |
| 155 HostResource result; | 172 HostResource result; |
| 156 dispatcher->Send(new PpapiHostMsg_PPBAudio_Create( | 173 dispatcher->Send(new PpapiHostMsg_PPBAudio_Create( |
| 157 INTERFACE_ID_PPB_AUDIO, instance_id, | 174 INTERFACE_ID_PPB_AUDIO, instance_id, |
| 158 config.object()->GetSampleRate(), config.object()->GetSampleFrameCount(), | 175 config.object()->GetSampleRate(), config.object()->GetSampleFrameCount(), |
| 159 &result)); | 176 &result)); |
| 160 if (result.is_null()) | 177 if (result.is_null()) |
| 161 return 0; | 178 return 0; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 186 resource_creation(instance_id, true); | 203 resource_creation(instance_id, true); |
| 187 if (resource_creation.failed()) | 204 if (resource_creation.failed()) |
| 188 return; | 205 return; |
| 189 | 206 |
| 190 // Make the resource and get the API pointer to its trusted interface. | 207 // Make the resource and get the API pointer to its trusted interface. |
| 191 result->SetHostResource( | 208 result->SetHostResource( |
| 192 instance_id, | 209 instance_id, |
| 193 resource_creation.functions()->CreateAudioTrusted(instance_id)); | 210 resource_creation.functions()->CreateAudioTrusted(instance_id)); |
| 194 if (result->is_null()) | 211 if (result->is_null()) |
| 195 return; | 212 return; |
| 196 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioTrusted_API> | 213 |
| 197 trusted_audio(result->host_resource(), false); | 214 // At this point, we've set the result resource, and this is a sync request. |
| 198 if (trusted_audio.failed()) | 215 // Anything below this point must issue the AudioChannelConnected callback |
| 199 return; | 216 // to the browser. Since that's an async message, it will be issued back to |
| 217 // the plugin after the Create function returns (which is good because it | |
| 218 // would be weird to get a connected message with a failure code for a | |
| 219 // resource you haven't finished creating yet). | |
| 220 // | |
| 221 // The ...ForceCallback class will help ensure the callback is always called. | |
| 222 // All error cases must call SetResult on this class. | |
| 223 EnterHostFromHostResourceForceCallback<PPB_Audio_API> enter( | |
| 224 *result, callback_factory_, | |
| 225 &PPB_Audio_Proxy::AudioChannelConnected, *result); | |
| 226 if (enter.failed()) | |
| 227 return; // When enter fails, it will internally schedule the callback. | |
| 200 | 228 |
| 201 // Make an audio config object. | 229 // Make an audio config object. |
| 202 PP_Resource audio_config_res = | 230 PP_Resource audio_config_res = |
| 203 resource_creation.functions()->CreateAudioConfig( | 231 resource_creation.functions()->CreateAudioConfig( |
| 204 instance_id, static_cast<PP_AudioSampleRate>(sample_rate), | 232 instance_id, static_cast<PP_AudioSampleRate>(sample_rate), |
| 205 sample_frame_count); | 233 sample_frame_count); |
| 206 if (!audio_config_res) | 234 if (!audio_config_res) { |
| 235 enter.SetResult(PP_ERROR_FAILED); | |
| 207 return; | 236 return; |
| 237 } | |
| 208 | 238 |
| 209 // Initiate opening the audio object. | 239 // Initiate opening the audio object. |
| 210 CompletionCallback callback = callback_factory_.NewOptionalCallback( | 240 enter.SetResult(enter.object()->OpenTrusted(audio_config_res, |
| 211 &PPB_Audio_Proxy::AudioChannelConnected, *result); | 241 enter.callback())); |
| 212 int32_t open_error = trusted_audio.object()->OpenTrusted( | |
| 213 audio_config_res, callback.pp_completion_callback()); | |
| 214 if (open_error != PP_OK_COMPLETIONPENDING) | |
| 215 callback.Run(open_error); | |
| 216 | 242 |
| 217 // Clean up the temporary audio config resource we made. | 243 // Clean up the temporary audio config resource we made. |
| 218 const PPB_Core* core = static_cast<const PPB_Core*>( | 244 const PPB_Core* core = static_cast<const PPB_Core*>( |
| 219 dispatcher()->GetLocalInterface(PPB_CORE_INTERFACE)); | 245 dispatcher()->GetLocalInterface(PPB_CORE_INTERFACE)); |
| 220 core->ReleaseResource(audio_config_res); | 246 core->ReleaseResource(audio_config_res); |
| 221 } | 247 } |
| 222 | 248 |
| 223 void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id, | 249 void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id, |
| 224 bool play) { | 250 bool play) { |
| 225 if (play) | 251 if (play) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated( | 299 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated( |
| 274 INTERFACE_ID_PPB_AUDIO, resource, result_code, socket_handle, | 300 INTERFACE_ID_PPB_AUDIO, resource, result_code, socket_handle, |
| 275 shared_memory, shared_memory_length)); | 301 shared_memory, shared_memory_length)); |
| 276 } | 302 } |
| 277 | 303 |
| 278 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( | 304 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( |
| 279 const HostResource& resource, | 305 const HostResource& resource, |
| 280 IPC::PlatformFileForTransit* foreign_socket_handle, | 306 IPC::PlatformFileForTransit* foreign_socket_handle, |
| 281 base::SharedMemoryHandle* foreign_shared_memory_handle, | 307 base::SharedMemoryHandle* foreign_shared_memory_handle, |
| 282 uint32_t* shared_memory_length) { | 308 uint32_t* shared_memory_length) { |
| 283 // Get the trusted audio interface which will give us the handles. | 309 // Get the audio interface which will give us the handles. |
| 284 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioTrusted_API> | 310 EnterResourceNoLock<PPB_Audio_API> enter(resource.host_resource(), false); |
| 285 trusted_audio(resource.host_resource(), false); | 311 if (enter.failed()) |
| 286 if (trusted_audio.failed()) | |
| 287 return PP_ERROR_NOINTERFACE; | 312 return PP_ERROR_NOINTERFACE; |
| 288 | 313 |
| 289 // Get the socket handle for signaling. | 314 // Get the socket handle for signaling. |
| 290 int32_t socket_handle; | 315 int32_t socket_handle; |
| 291 int32_t result = trusted_audio.object()->GetSyncSocket(&socket_handle); | 316 int32_t result = enter.object()->GetSyncSocket(&socket_handle); |
| 292 if (result != PP_OK) | 317 if (result != PP_OK) |
| 293 return result; | 318 return result; |
| 294 | 319 |
| 295 // socket_handle doesn't belong to us: don't close it. | 320 // socket_handle doesn't belong to us: don't close it. |
| 296 *foreign_socket_handle = dispatcher()->ShareHandleWithRemote( | 321 *foreign_socket_handle = dispatcher()->ShareHandleWithRemote( |
| 297 IntToPlatformFile(socket_handle), false); | 322 IntToPlatformFile(socket_handle), false); |
| 298 if (*foreign_socket_handle == IPC::InvalidPlatformFileForTransit()) | 323 if (*foreign_socket_handle == IPC::InvalidPlatformFileForTransit()) |
| 299 return PP_ERROR_FAILED; | 324 return PP_ERROR_FAILED; |
| 300 | 325 |
| 301 // Get the shared memory for the buffer. | 326 // Get the shared memory for the buffer. |
| 302 int shared_memory_handle; | 327 int shared_memory_handle; |
| 303 result = trusted_audio.object()->GetSharedMemory(&shared_memory_handle, | 328 result = enter.object()->GetSharedMemory(&shared_memory_handle, |
| 304 shared_memory_length); | 329 shared_memory_length); |
| 305 if (result != PP_OK) | 330 if (result != PP_OK) |
| 306 return result; | 331 return result; |
| 307 | 332 |
| 308 // shared_memory_handle doesn't belong to us: don't close it. | 333 // shared_memory_handle doesn't belong to us: don't close it. |
| 309 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( | 334 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( |
| 310 IntToPlatformFile(shared_memory_handle), false); | 335 IntToPlatformFile(shared_memory_handle), false); |
| 311 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) | 336 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
| 312 return PP_ERROR_FAILED; | 337 return PP_ERROR_FAILED; |
| 313 | 338 |
| 314 return PP_OK; | 339 return PP_OK; |
| 315 } | 340 } |
| 316 | 341 |
| 317 } // namespace proxy | 342 } // namespace proxy |
| 318 } // namespace pp | 343 } // namespace pp |
| OLD | NEW |