OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 if (result.is_null()) | 150 if (result.is_null()) |
151 return 0; | 151 return 0; |
152 | 152 |
153 return (new Audio(result, config_id, | 153 return (new Audio(result, config_id, |
154 audio_callback, user_data))->GetReference(); | 154 audio_callback, user_data))->GetReference(); |
155 } | 155 } |
156 | 156 |
157 bool PPB_Audio_Proxy::OnMessageReceived(const IPC::Message& msg) { | 157 bool PPB_Audio_Proxy::OnMessageReceived(const IPC::Message& msg) { |
158 bool handled = true; | 158 bool handled = true; |
159 IPC_BEGIN_MESSAGE_MAP(PPB_Audio_Proxy, msg) | 159 IPC_BEGIN_MESSAGE_MAP(PPB_Audio_Proxy, msg) |
| 160 // Don't build host side into NaCl IRT. |
| 161 #if !defined(OS_NACL) |
160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_Create, OnMsgCreate) | 162 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_Create, OnMsgCreate) |
161 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_StartOrStop, | 163 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_StartOrStop, |
162 OnMsgStartOrStop) | 164 OnMsgStartOrStop) |
| 165 #endif |
163 IPC_MESSAGE_HANDLER(PpapiMsg_PPBAudio_NotifyAudioStreamCreated, | 166 IPC_MESSAGE_HANDLER(PpapiMsg_PPBAudio_NotifyAudioStreamCreated, |
164 OnMsgNotifyAudioStreamCreated) | 167 OnMsgNotifyAudioStreamCreated) |
165 IPC_MESSAGE_UNHANDLED(handled = false) | 168 IPC_MESSAGE_UNHANDLED(handled = false) |
166 IPC_END_MESSAGE_MAP() | 169 IPC_END_MESSAGE_MAP() |
167 return handled; | 170 return handled; |
168 } | 171 } |
169 | 172 |
| 173 #if !defined(OS_NACL) |
170 void PPB_Audio_Proxy::OnMsgCreate(PP_Instance instance_id, | 174 void PPB_Audio_Proxy::OnMsgCreate(PP_Instance instance_id, |
171 int32_t sample_rate, | 175 int32_t sample_rate, |
172 uint32_t sample_frame_count, | 176 uint32_t sample_frame_count, |
173 HostResource* result) { | 177 HostResource* result) { |
174 thunk::EnterResourceCreation resource_creation(instance_id); | 178 thunk::EnterResourceCreation resource_creation(instance_id); |
175 if (resource_creation.failed()) | 179 if (resource_creation.failed()) |
176 return; | 180 return; |
177 | 181 |
178 // Make the resource and get the API pointer to its trusted interface. | 182 // Make the resource and get the API pointer to its trusted interface. |
179 result->SetHostResource( | 183 result->SetHostResource( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 bool play) { | 225 bool play) { |
222 EnterHostFromHostResource<PPB_Audio_API> enter(audio_id); | 226 EnterHostFromHostResource<PPB_Audio_API> enter(audio_id); |
223 if (enter.failed()) | 227 if (enter.failed()) |
224 return; | 228 return; |
225 if (play) | 229 if (play) |
226 enter.object()->StartPlayback(); | 230 enter.object()->StartPlayback(); |
227 else | 231 else |
228 enter.object()->StopPlayback(); | 232 enter.object()->StopPlayback(); |
229 } | 233 } |
230 | 234 |
231 // Processed in the plugin (message from host). | |
232 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( | |
233 const HostResource& audio_id, | |
234 int32_t result_code, | |
235 IPC::PlatformFileForTransit socket_handle, | |
236 base::SharedMemoryHandle handle, | |
237 uint32_t length) { | |
238 EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); | |
239 if (enter.failed() || result_code != PP_OK) { | |
240 // The caller may still have given us these handles in the failure case. | |
241 // The easiest way to clean these up is to just put them in the objects | |
242 // and then close them. This failure case is not performance critical. | |
243 base::SyncSocket temp_socket( | |
244 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | |
245 base::SharedMemory temp_mem(handle, false); | |
246 } else { | |
247 static_cast<Audio*>(enter.object())->SetStreamInfo( | |
248 enter.resource()->pp_instance(), handle, length, | |
249 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | |
250 } | |
251 } | |
252 | |
253 void PPB_Audio_Proxy::AudioChannelConnected( | 235 void PPB_Audio_Proxy::AudioChannelConnected( |
254 int32_t result, | 236 int32_t result, |
255 const HostResource& resource) { | 237 const HostResource& resource) { |
256 IPC::PlatformFileForTransit socket_handle = | 238 IPC::PlatformFileForTransit socket_handle = |
257 IPC::InvalidPlatformFileForTransit(); | 239 IPC::InvalidPlatformFileForTransit(); |
258 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); | 240 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); |
259 uint32_t shared_memory_length = 0; | 241 uint32_t shared_memory_length = 0; |
260 | 242 |
261 int32_t result_code = result; | 243 int32_t result_code = result; |
262 if (result_code == PP_OK) { | 244 if (result_code == PP_OK) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 return result; | 287 return result; |
306 | 288 |
307 // shared_memory_handle doesn't belong to us: don't close it. | 289 // shared_memory_handle doesn't belong to us: don't close it. |
308 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( | 290 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( |
309 IntToPlatformFile(shared_memory_handle), false); | 291 IntToPlatformFile(shared_memory_handle), false); |
310 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) | 292 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
311 return PP_ERROR_FAILED; | 293 return PP_ERROR_FAILED; |
312 | 294 |
313 return PP_OK; | 295 return PP_OK; |
314 } | 296 } |
| 297 #endif // !defined(OS_NACL) |
| 298 |
| 299 // Processed in the plugin (message from host). |
| 300 void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( |
| 301 const HostResource& audio_id, |
| 302 int32_t result_code, |
| 303 IPC::PlatformFileForTransit socket_handle, |
| 304 base::SharedMemoryHandle handle, |
| 305 uint32_t length) { |
| 306 EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); |
| 307 if (enter.failed() || result_code != PP_OK) { |
| 308 // The caller may still have given us these handles in the failure case. |
| 309 // The easiest way to clean these up is to just put them in the objects |
| 310 // and then close them. This failure case is not performance critical. |
| 311 base::SyncSocket temp_socket( |
| 312 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
| 313 base::SharedMemory temp_mem(handle, false); |
| 314 } else { |
| 315 static_cast<Audio*>(enter.object())->SetStreamInfo( |
| 316 enter.resource()->pp_instance(), handle, length, |
| 317 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
| 318 } |
| 319 } |
315 | 320 |
316 } // namespace proxy | 321 } // namespace proxy |
317 } // namespace ppapi | 322 } // namespace ppapi |
OLD | NEW |