| 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" |
| 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/interface_id.h" | 14 #include "ppapi/proxy/interface_id.h" |
| 14 #include "ppapi/proxy/plugin_dispatcher.h" | 15 #include "ppapi/proxy/plugin_dispatcher.h" |
| 15 #include "ppapi/proxy/plugin_resource.h" | 16 #include "ppapi/proxy/plugin_resource.h" |
| 16 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
| 17 #include "ppapi/shared_impl/audio_impl.h" | 18 #include "ppapi/shared_impl/audio_impl.h" |
| 18 #include "ppapi/thunk/ppb_audio_config_api.h" | 19 #include "ppapi/thunk/ppb_audio_config_api.h" |
| 19 #include "ppapi/thunk/ppb_audio_trusted_api.h" | 20 #include "ppapi/thunk/ppb_audio_trusted_api.h" |
| 20 #include "ppapi/thunk/enter.h" | 21 #include "ppapi/thunk/enter.h" |
| 21 #include "ppapi/thunk/resource_creation_api.h" | 22 #include "ppapi/thunk/resource_creation_api.h" |
| 22 #include "ppapi/thunk/thunk.h" | 23 #include "ppapi/thunk/thunk.h" |
| 23 | 24 |
| 25 using ::ppapi::thunk::PPB_Audio_API; |
| 26 |
| 24 namespace pp { | 27 namespace pp { |
| 25 namespace proxy { | 28 namespace proxy { |
| 26 | 29 |
| 27 class Audio : public PluginResource, public ppapi::AudioImpl { | 30 class Audio : public PluginResource, public ppapi::AudioImpl { |
| 28 public: | 31 public: |
| 29 Audio(const HostResource& audio_id, | 32 Audio(const HostResource& audio_id, |
| 30 PP_Resource config_id, | 33 PP_Resource config_id, |
| 31 PPB_Audio_Callback callback, | 34 PPB_Audio_Callback callback, |
| 32 void* user_data); | 35 void* user_data); |
| 33 virtual ~Audio(); | 36 virtual ~Audio(); |
| 34 | 37 |
| 35 // ResourceObjectBase overrides. | 38 // ResourceObjectBase overrides. |
| 36 virtual ::ppapi::thunk::PPB_Audio_API* AsAudio_API(); | 39 virtual PPB_Audio_API* AsPPB_Audio_API(); |
| 37 | 40 |
| 38 // PPB_Audio_API implementation. | 41 // PPB_Audio_API implementation. |
| 39 virtual PP_Resource GetCurrentConfig() OVERRIDE; | 42 virtual PP_Resource GetCurrentConfig() OVERRIDE; |
| 40 virtual PP_Bool StartPlayback() OVERRIDE; | 43 virtual PP_Bool StartPlayback() OVERRIDE; |
| 41 virtual PP_Bool StopPlayback() OVERRIDE; | 44 virtual PP_Bool StopPlayback() OVERRIDE; |
| 42 | 45 |
| 43 private: | 46 private: |
| 44 // Owning reference to the current config object. This isn't actually used, | 47 // Owning reference to the current config object. This isn't actually used, |
| 45 // we just dish it out as requested by the plugin. | 48 // we just dish it out as requested by the plugin. |
| 46 PP_Resource config_; | 49 PP_Resource config_; |
| 47 | 50 |
| 48 DISALLOW_COPY_AND_ASSIGN(Audio); | 51 DISALLOW_COPY_AND_ASSIGN(Audio); |
| 49 }; | 52 }; |
| 50 | 53 |
| 51 Audio::Audio(const HostResource& audio_id, | 54 Audio::Audio(const HostResource& audio_id, |
| 52 PP_Resource config_id, | 55 PP_Resource config_id, |
| 53 PPB_Audio_Callback callback, | 56 PPB_Audio_Callback callback, |
| 54 void* user_data) | 57 void* user_data) |
| 55 : PluginResource(audio_id), | 58 : PluginResource(audio_id), |
| 56 config_(config_id) { | 59 config_(config_id) { |
| 57 SetCallback(callback, user_data); | 60 SetCallback(callback, user_data); |
| 58 PluginResourceTracker::GetInstance()->AddRefResource(config_); | 61 PluginResourceTracker::GetInstance()->AddRefResource(config_); |
| 59 } | 62 } |
| 60 | 63 |
| 61 Audio::~Audio() { | 64 Audio::~Audio() { |
| 62 PluginResourceTracker::GetInstance()->ReleaseResource(config_); | 65 PluginResourceTracker::GetInstance()->ReleaseResource(config_); |
| 63 } | 66 } |
| 64 | 67 |
| 65 ::ppapi::thunk::PPB_Audio_API* Audio::AsAudio_API() { | 68 PPB_Audio_API* Audio::AsPPB_Audio_API() { |
| 66 return this; | 69 return this; |
| 67 } | 70 } |
| 68 | 71 |
| 69 PP_Resource Audio::GetCurrentConfig() { | 72 PP_Resource Audio::GetCurrentConfig() { |
| 70 // AddRef for the caller. | 73 // AddRef for the caller. |
| 71 PluginResourceTracker::GetInstance()->AddRefResource(config_); | 74 PluginResourceTracker::GetInstance()->AddRefResource(config_); |
| 72 return config_; | 75 return config_; |
| 73 } | 76 } |
| 74 | 77 |
| 75 PP_Bool Audio::StartPlayback() { | 78 PP_Bool Audio::StartPlayback() { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 ppb_audio_target()->StopPlayback(audio_id.host_resource()); | 228 ppb_audio_target()->StopPlayback(audio_id.host_resource()); |
| 226 } | 229 } |
| 227 | 230 |
| 228 // Processed in the plugin (message from host). | 231 // Processed in the plugin (message from host). |
| 229 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( | 232 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( |
| 230 const HostResource& audio_id, | 233 const HostResource& audio_id, |
| 231 int32_t result_code, | 234 int32_t result_code, |
| 232 IPC::PlatformFileForTransit socket_handle, | 235 IPC::PlatformFileForTransit socket_handle, |
| 233 base::SharedMemoryHandle handle, | 236 base::SharedMemoryHandle handle, |
| 234 uint32_t length) { | 237 uint32_t length) { |
| 235 PP_Resource plugin_resource = | 238 EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); |
| 236 PluginResourceTracker::GetInstance()->PluginResourceForHostResource( | |
| 237 audio_id); | |
| 238 ppapi::thunk::EnterResource<ppapi::thunk::PPB_Audio_API> enter( | |
| 239 plugin_resource, false); | |
| 240 if (enter.failed() || result_code != PP_OK) { | 239 if (enter.failed() || result_code != PP_OK) { |
| 241 // The caller may still have given us these handles in the failure case. | 240 // The caller may still have given us these handles in the failure case. |
| 242 // The easiest way to clean these up is to just put them in the objects | 241 // The easiest way to clean these up is to just put them in the objects |
| 243 // and then close them. This failure case is not performance critical. | 242 // and then close them. This failure case is not performance critical. |
| 244 base::SyncSocket temp_socket( | 243 base::SyncSocket temp_socket( |
| 245 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | 244 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
| 246 base::SharedMemory temp_mem(handle, false); | 245 base::SharedMemory temp_mem(handle, false); |
| 247 return; | 246 } else { |
| 247 static_cast<Audio*>(enter.object())->SetStreamInfo( |
| 248 handle, length, |
| 249 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
| 248 } | 250 } |
| 249 Audio* audio = static_cast<Audio*>(enter.object()); | |
| 250 audio->SetStreamInfo( | |
| 251 handle, length, IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | |
| 252 } | 251 } |
| 253 | 252 |
| 254 void PPB_Audio_Proxy::AudioChannelConnected( | 253 void PPB_Audio_Proxy::AudioChannelConnected( |
| 255 int32_t result, | 254 int32_t result, |
| 256 const HostResource& resource) { | 255 const HostResource& resource) { |
| 257 IPC::PlatformFileForTransit socket_handle = | 256 IPC::PlatformFileForTransit socket_handle = |
| 258 IPC::InvalidPlatformFileForTransit(); | 257 IPC::InvalidPlatformFileForTransit(); |
| 259 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); | 258 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); |
| 260 uint32_t shared_memory_length = 0; | 259 uint32_t shared_memory_length = 0; |
| 261 | 260 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( | 309 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( |
| 311 IntToPlatformFile(shared_memory_handle), false); | 310 IntToPlatformFile(shared_memory_handle), false); |
| 312 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) | 311 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
| 313 return PP_ERROR_FAILED; | 312 return PP_ERROR_FAILED; |
| 314 | 313 |
| 315 return PP_OK; | 314 return PP_OK; |
| 316 } | 315 } |
| 317 | 316 |
| 318 } // namespace proxy | 317 } // namespace proxy |
| 319 } // namespace pp | 318 } // namespace pp |
| OLD | NEW |