| 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/trusted/ppb_audio_trusted.h" | 10 #include "ppapi/c/trusted/ppb_audio_trusted.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id, | 178 void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id, |
| 179 bool play) { | 179 bool play) { |
| 180 if (play) | 180 if (play) |
| 181 ppb_audio_target()->StartPlayback(audio_id.host_resource()); | 181 ppb_audio_target()->StartPlayback(audio_id.host_resource()); |
| 182 else | 182 else |
| 183 ppb_audio_target()->StopPlayback(audio_id.host_resource()); | 183 ppb_audio_target()->StopPlayback(audio_id.host_resource()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 // Processed in the plugin (message from host). | 186 // Processed in the plugin (message from host). |
| 187 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( | 187 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( |
| 188 const PPBAudio_NotifyAudioStreamCreated_Params& params) { | 188 const HostResource& audio_id, |
| 189 int32_t result_code, |
| 190 IPC::PlatformFileForTransit socket_handle, |
| 191 base::SharedMemoryHandle handle, |
| 192 uint32_t length) { |
| 189 PP_Resource plugin_resource = | 193 PP_Resource plugin_resource = |
| 190 PluginResourceTracker::GetInstance()->PluginResourceForHostResource( | 194 PluginResourceTracker::GetInstance()->PluginResourceForHostResource( |
| 191 params.audio_id); | 195 audio_id); |
| 192 Audio* object = plugin_resource ? | 196 Audio* object = plugin_resource ? |
| 193 PluginResource::GetAs<Audio>(plugin_resource) : NULL; | 197 PluginResource::GetAs<Audio>(plugin_resource) : NULL; |
| 194 if (!object || params.result_code != PP_OK) { | 198 if (!object || result_code != PP_OK) { |
| 195 // The caller may still have given us these handles in the failure case. | 199 // The caller may still have given us these handles in the failure case. |
| 196 // The easiest way to clean these up is to just put them in the objects | 200 // The easiest way to clean these up is to just put them in the objects |
| 197 // and then close them. This failure case is not performance critical. | 201 // and then close them. This failure case is not performance critical. |
| 198 base::SyncSocket temp_socket( | 202 base::SyncSocket temp_socket( |
| 199 IPC::PlatformFileForTransitToPlatformFile(params.socket_handle)); | 203 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
| 200 base::SharedMemory temp_mem(params.handle, false); | 204 base::SharedMemory temp_mem(handle, false); |
| 201 return; | 205 return; |
| 202 } | 206 } |
| 203 object->SetStreamInfo( | 207 object->SetStreamInfo( |
| 204 params.handle, params.length, | 208 handle, length, IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
| 205 IPC::PlatformFileForTransitToPlatformFile(params.socket_handle)); | |
| 206 } | 209 } |
| 207 | 210 |
| 208 void PPB_Audio_Proxy::AudioChannelConnected( | 211 void PPB_Audio_Proxy::AudioChannelConnected( |
| 209 int32_t result, | 212 int32_t result, |
| 210 const HostResource& resource) { | 213 const HostResource& resource) { |
| 211 IPC::PlatformFileForTransit socket_handle = | 214 IPC::PlatformFileForTransit socket_handle = |
| 212 IPC::InvalidPlatformFileForTransit(); | 215 IPC::InvalidPlatformFileForTransit(); |
| 213 #if defined(OS_WIN) | 216 #if defined(OS_WIN) |
| 214 base::SharedMemoryHandle shared_memory = NULL; | 217 base::SharedMemoryHandle shared_memory = NULL; |
| 215 #elif defined(OS_POSIX) | 218 #elif defined(OS_POSIX) |
| 216 base::SharedMemoryHandle shared_memory(-1, false); | 219 base::SharedMemoryHandle shared_memory(-1, false); |
| 217 #else | 220 #else |
| 218 #error Not implemented. | 221 #error Not implemented. |
| 219 #endif | 222 #endif |
| 220 uint32_t shared_memory_length = 0; | 223 uint32_t shared_memory_length = 0; |
| 221 | 224 |
| 222 int32_t result_code = result; | 225 int32_t result_code = result; |
| 223 if (result_code == PP_OK) { | 226 if (result_code == PP_OK) { |
| 224 result_code = GetAudioConnectedHandles(resource, &socket_handle, | 227 result_code = GetAudioConnectedHandles(resource, &socket_handle, |
| 225 &shared_memory, | 228 &shared_memory, |
| 226 &shared_memory_length); | 229 &shared_memory_length); |
| 227 } | 230 } |
| 228 | 231 |
| 229 // Send all the values, even on error. This simplifies some of our cleanup | 232 // Send all the values, even on error. This simplifies some of our cleanup |
| 230 // code since the handles will be in the other process and could be | 233 // code since the handles will be in the other process and could be |
| 231 // inconvenient to clean up. Our IPC code will automatically handle this for | 234 // inconvenient to clean up. Our IPC code will automatically handle this for |
| 232 // us, as long as the remote side always closes the handles it receives | 235 // us, as long as the remote side always closes the handles it receives |
| 233 // (in OnMsgNotifyAudioStreamCreated), even in the failure case. | 236 // (in OnMsgNotifyAudioStreamCreated), even in the failure case. |
| 234 PPBAudio_NotifyAudioStreamCreated_Params params; | |
| 235 params.audio_id = resource; | |
| 236 params.result_code = result; | |
| 237 params.socket_handle = socket_handle; | |
| 238 params.handle = shared_memory; | |
| 239 params.length = shared_memory_length; | |
| 240 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated( | 237 dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated( |
| 241 INTERFACE_ID_PPB_AUDIO, params)); | 238 INTERFACE_ID_PPB_AUDIO, resource, result_code, socket_handle, |
| 239 shared_memory, shared_memory_length)); |
| 242 } | 240 } |
| 243 | 241 |
| 244 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( | 242 int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( |
| 245 const HostResource& resource, | 243 const HostResource& resource, |
| 246 IPC::PlatformFileForTransit* foreign_socket_handle, | 244 IPC::PlatformFileForTransit* foreign_socket_handle, |
| 247 base::SharedMemoryHandle* foreign_shared_memory_handle, | 245 base::SharedMemoryHandle* foreign_shared_memory_handle, |
| 248 uint32_t* shared_memory_length) { | 246 uint32_t* shared_memory_length) { |
| 249 // Get the trusted audio interface which will give us the handles. | 247 // Get the trusted audio interface which will give us the handles. |
| 250 const PPB_AudioTrusted* audio_trusted = | 248 const PPB_AudioTrusted* audio_trusted = |
| 251 reinterpret_cast<const PPB_AudioTrusted*>( | 249 reinterpret_cast<const PPB_AudioTrusted*>( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 // close the source handle. | 294 // close the source handle. |
| 297 if (!shared_memory.GiveToProcess(dispatcher()->remote_process_handle(), | 295 if (!shared_memory.GiveToProcess(dispatcher()->remote_process_handle(), |
| 298 foreign_shared_memory_handle)) | 296 foreign_shared_memory_handle)) |
| 299 return PP_ERROR_FAILED; | 297 return PP_ERROR_FAILED; |
| 300 | 298 |
| 301 return PP_OK; | 299 return PP_OK; |
| 302 } | 300 } |
| 303 | 301 |
| 304 } // namespace proxy | 302 } // namespace proxy |
| 305 } // namespace pp | 303 } // namespace pp |
| OLD | NEW |