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 "content/renderer/pepper_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper_plugin_delegate_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 virtual bool StopPlayback() OVERRIDE; | 189 virtual bool StopPlayback() OVERRIDE; |
190 virtual void ShutDown() OVERRIDE; | 190 virtual void ShutDown() OVERRIDE; |
191 | 191 |
192 private: | 192 private: |
193 // I/O thread backends to above functions. | 193 // I/O thread backends to above functions. |
194 void InitializeOnIOThread(const AudioParameters& params); | 194 void InitializeOnIOThread(const AudioParameters& params); |
195 void StartPlaybackOnIOThread(); | 195 void StartPlaybackOnIOThread(); |
196 void StopPlaybackOnIOThread(); | 196 void StopPlaybackOnIOThread(); |
197 void ShutDownOnIOThread(); | 197 void ShutDownOnIOThread(); |
198 | 198 |
199 virtual void OnRequestPacket(AudioBuffersState buffers_state) OVERRIDE { | |
200 LOG(FATAL) << "Should never get OnRequestPacket in PlatformAudioImpl"; | |
201 } | |
202 | |
203 virtual void OnStateChanged(AudioStreamState state) OVERRIDE {} | 199 virtual void OnStateChanged(AudioStreamState state) OVERRIDE {} |
204 | 200 |
205 virtual void OnCreated(base::SharedMemoryHandle handle, | 201 virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
206 uint32 length) OVERRIDE { | 202 base::SyncSocket::Handle socket_handle, |
207 LOG(FATAL) << "Should never get OnCreated in PlatformAudioImpl"; | 203 uint32 length) OVERRIDE; |
208 } | |
209 | |
210 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, | |
211 base::SyncSocket::Handle socket_handle, | |
212 uint32 length) OVERRIDE; | |
213 | |
214 virtual void OnVolume(double volume) OVERRIDE {} | |
215 | 204 |
216 // The client to notify when the stream is created. THIS MUST ONLY BE | 205 // The client to notify when the stream is created. THIS MUST ONLY BE |
217 // ACCESSED ON THE MAIN THREAD. | 206 // ACCESSED ON THE MAIN THREAD. |
218 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_; | 207 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_; |
219 | 208 |
220 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE | 209 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE |
221 // I/O thread except to send messages and get the message loop. | 210 // I/O thread except to send messages and get the message loop. |
222 scoped_refptr<AudioMessageFilter> filter_; | 211 scoped_refptr<AudioMessageFilter> filter_; |
223 | 212 |
224 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD | 213 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // Called on the main thread to stop all audio callbacks. We must only change | 266 // Called on the main thread to stop all audio callbacks. We must only change |
278 // the client on the main thread, and the delegates from the I/O thread. | 267 // the client on the main thread, and the delegates from the I/O thread. |
279 client_ = NULL; | 268 client_ = NULL; |
280 ChildProcess::current()->io_message_loop()->PostTask( | 269 ChildProcess::current()->io_message_loop()->PostTask( |
281 FROM_HERE, | 270 FROM_HERE, |
282 base::Bind(&PlatformAudioImpl::ShutDownOnIOThread, this)); | 271 base::Bind(&PlatformAudioImpl::ShutDownOnIOThread, this)); |
283 } | 272 } |
284 | 273 |
285 void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) { | 274 void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) { |
286 stream_id_ = filter_->AddDelegate(this); | 275 stream_id_ = filter_->AddDelegate(this); |
287 filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params, true)); | 276 filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params)); |
288 } | 277 } |
289 | 278 |
290 void PlatformAudioImpl::StartPlaybackOnIOThread() { | 279 void PlatformAudioImpl::StartPlaybackOnIOThread() { |
291 if (stream_id_) | 280 if (stream_id_) |
292 filter_->Send(new AudioHostMsg_PlayStream(stream_id_)); | 281 filter_->Send(new AudioHostMsg_PlayStream(stream_id_)); |
293 } | 282 } |
294 | 283 |
295 void PlatformAudioImpl::StopPlaybackOnIOThread() { | 284 void PlatformAudioImpl::StopPlaybackOnIOThread() { |
296 if (stream_id_) | 285 if (stream_id_) |
297 filter_->Send(new AudioHostMsg_PauseStream(stream_id_)); | 286 filter_->Send(new AudioHostMsg_PauseStream(stream_id_)); |
298 } | 287 } |
299 | 288 |
300 void PlatformAudioImpl::ShutDownOnIOThread() { | 289 void PlatformAudioImpl::ShutDownOnIOThread() { |
301 // Make sure we don't call shutdown more than once. | 290 // Make sure we don't call shutdown more than once. |
302 if (!stream_id_) | 291 if (!stream_id_) |
303 return; | 292 return; |
304 | 293 |
305 filter_->Send(new AudioHostMsg_CloseStream(stream_id_)); | 294 filter_->Send(new AudioHostMsg_CloseStream(stream_id_)); |
306 filter_->RemoveDelegate(stream_id_); | 295 filter_->RemoveDelegate(stream_id_); |
307 stream_id_ = 0; | 296 stream_id_ = 0; |
308 | 297 |
309 Release(); // Release for the delegate, balances out the reference taken in | 298 Release(); // Release for the delegate, balances out the reference taken in |
310 // PepperPluginDelegateImpl::CreateAudio. | 299 // PepperPluginDelegateImpl::CreateAudio. |
311 } | 300 } |
312 | 301 |
313 void PlatformAudioImpl::OnLowLatencyCreated( | 302 void PlatformAudioImpl::OnStreamCreated( |
314 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, | 303 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, |
315 uint32 length) { | 304 uint32 length) { |
316 #if defined(OS_WIN) | 305 #if defined(OS_WIN) |
317 DCHECK(handle); | 306 DCHECK(handle); |
318 DCHECK(socket_handle); | 307 DCHECK(socket_handle); |
319 #else | 308 #else |
320 DCHECK_NE(-1, handle.fd); | 309 DCHECK_NE(-1, handle.fd); |
321 DCHECK_NE(-1, socket_handle); | 310 DCHECK_NE(-1, socket_handle); |
322 #endif | 311 #endif |
323 DCHECK(length); | 312 DCHECK(length); |
324 | 313 |
325 if (base::MessageLoopProxy::current() == main_message_loop_proxy_) { | 314 if (base::MessageLoopProxy::current() == main_message_loop_proxy_) { |
326 // Must dereference the client only on the main thread. Shutdown may have | 315 // Must dereference the client only on the main thread. Shutdown may have |
327 // occurred while the request was in-flight, so we need to NULL check. | 316 // occurred while the request was in-flight, so we need to NULL check. |
328 if (client_) | 317 if (client_) |
329 client_->StreamCreated(handle, length, socket_handle); | 318 client_->StreamCreated(handle, length, socket_handle); |
330 } else { | 319 } else { |
331 main_message_loop_proxy_->PostTask(FROM_HERE, | 320 main_message_loop_proxy_->PostTask(FROM_HERE, |
332 base::Bind(&PlatformAudioImpl::OnLowLatencyCreated, this, handle, | 321 base::Bind(&PlatformAudioImpl::OnStreamCreated, this, handle, |
333 socket_handle, length)); | 322 socket_handle, length)); |
334 } | 323 } |
335 } | 324 } |
336 | 325 |
337 class PlatformAudioInputImpl | 326 class PlatformAudioInputImpl |
338 : public webkit::ppapi::PluginDelegate::PlatformAudioInput, | 327 : public webkit::ppapi::PluginDelegate::PlatformAudioInput, |
339 public AudioInputMessageFilter::Delegate, | 328 public AudioInputMessageFilter::Delegate, |
340 public base::RefCountedThreadSafe<PlatformAudioInputImpl> { | 329 public base::RefCountedThreadSafe<PlatformAudioInputImpl> { |
341 public: | 330 public: |
342 PlatformAudioInputImpl() | 331 PlatformAudioInputImpl() |
(...skipping 1765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 void PepperPluginDelegateImpl::UnSetAndDeleteLockTargetAdapter( | 2097 void PepperPluginDelegateImpl::UnSetAndDeleteLockTargetAdapter( |
2109 webkit::ppapi::PluginInstance* instance) { | 2098 webkit::ppapi::PluginInstance* instance) { |
2110 LockTargetMap::iterator it = mouse_lock_instances_.find(instance); | 2099 LockTargetMap::iterator it = mouse_lock_instances_.find(instance); |
2111 if (it != mouse_lock_instances_.end()) { | 2100 if (it != mouse_lock_instances_.end()) { |
2112 MouseLockDispatcher::LockTarget* target = it->second; | 2101 MouseLockDispatcher::LockTarget* target = it->second; |
2113 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(target); | 2102 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(target); |
2114 delete target; | 2103 delete target; |
2115 mouse_lock_instances_.erase(it); | 2104 mouse_lock_instances_.erase(it); |
2116 } | 2105 } |
2117 } | 2106 } |
OLD | NEW |