| 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/pepper_platform_audio_input_impl.h" | 5 #include "content/renderer/pepper/pepper_platform_audio_input_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // the client on the main thread, and the delegates from the I/O thread. | 59 // the client on the main thread, and the delegates from the I/O thread. |
| 60 client_ = NULL; | 60 client_ = NULL; |
| 61 ChildProcess::current()->io_message_loop()->PostTask( | 61 ChildProcess::current()->io_message_loop()->PostTask( |
| 62 FROM_HERE, | 62 FROM_HERE, |
| 63 base::Bind(&PepperPlatformAudioInputImpl::ShutDownOnIOThread, this)); | 63 base::Bind(&PepperPlatformAudioInputImpl::ShutDownOnIOThread, this)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void PepperPlatformAudioInputImpl::OnStreamCreated( | 66 void PepperPlatformAudioInputImpl::OnStreamCreated( |
| 67 base::SharedMemoryHandle handle, | 67 base::SharedMemoryHandle handle, |
| 68 base::SyncSocket::Handle socket_handle, | 68 base::SyncSocket::Handle socket_handle, |
| 69 int length) { | 69 int length, |
| 70 int total_segments) { |
| 70 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
| 71 DCHECK(handle); | 72 DCHECK(handle); |
| 72 DCHECK(socket_handle); | 73 DCHECK(socket_handle); |
| 73 #else | 74 #else |
| 74 DCHECK_NE(-1, handle.fd); | 75 DCHECK_NE(-1, handle.fd); |
| 75 DCHECK_NE(-1, socket_handle); | 76 DCHECK_NE(-1, socket_handle); |
| 76 #endif | 77 #endif |
| 77 DCHECK(length); | 78 DCHECK(length); |
| 79 DCHECK_EQ(total_segments, 1); |
| 78 | 80 |
| 79 if (base::MessageLoopProxy::current() != main_message_loop_proxy_) { | 81 if (base::MessageLoopProxy::current() != main_message_loop_proxy_) { |
| 80 // No need to check |shutdown_called_| here. If shutdown has occurred, | 82 // No need to check |shutdown_called_| here. If shutdown has occurred, |
| 81 // |client_| will be NULL and the handles will be cleaned up on the main | 83 // |client_| will be NULL and the handles will be cleaned up on the main |
| 82 // thread. | 84 // thread. |
| 83 main_message_loop_proxy_->PostTask( | 85 main_message_loop_proxy_->PostTask( |
| 84 FROM_HERE, | 86 FROM_HERE, |
| 85 base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this, | 87 base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this, |
| 86 handle, socket_handle, length)); | 88 handle, socket_handle, length, total_segments)); |
| 87 } else { | 89 } else { |
| 88 // Must dereference the client only on the main thread. Shutdown may have | 90 // Must dereference the client only on the main thread. Shutdown may have |
| 89 // occurred while the request was in-flight, so we need to NULL check. | 91 // occurred while the request was in-flight, so we need to NULL check. |
| 90 if (client_) { | 92 if (client_) { |
| 91 client_->StreamCreated(handle, length, socket_handle); | 93 client_->StreamCreated(handle, length, socket_handle); |
| 92 } else { | 94 } else { |
| 93 // Clean up the handles. | 95 // Clean up the handles. |
| 94 base::SyncSocket temp_socket(socket_handle); | 96 base::SyncSocket temp_socket(socket_handle); |
| 95 base::SharedMemory temp_shared_memory(handle, false); | 97 base::SharedMemory temp_shared_memory(handle, false); |
| 96 } | 98 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 110 if (shutdown_called_) | 112 if (shutdown_called_) |
| 111 return; | 113 return; |
| 112 | 114 |
| 113 if (device_id.empty()) { | 115 if (device_id.empty()) { |
| 114 main_message_loop_proxy_->PostTask( | 116 main_message_loop_proxy_->PostTask( |
| 115 FROM_HERE, | 117 FROM_HERE, |
| 116 base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed, | 118 base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed, |
| 117 this)); | 119 this)); |
| 118 } else { | 120 } else { |
| 119 // We will be notified by OnStreamCreated(). | 121 // We will be notified by OnStreamCreated(). |
| 120 ipc_->CreateStream(stream_id_, params_, device_id, false); | 122 ipc_->CreateStream(stream_id_, params_, device_id, false, 1); |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 void PepperPlatformAudioInputImpl::OnIPCClosed() { | 126 void PepperPlatformAudioInputImpl::OnIPCClosed() { |
| 125 ipc_ = NULL; | 127 ipc_ = NULL; |
| 126 } | 128 } |
| 127 | 129 |
| 128 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { | 130 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { |
| 129 // Make sure we have been shut down. Warning: this may happen on the I/O | 131 // Make sure we have been shut down. Warning: this may happen on the I/O |
| 130 // thread! | 132 // thread! |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 return; | 191 return; |
| 190 | 192 |
| 191 // Make sure we don't call init more than once. | 193 // Make sure we don't call init more than once. |
| 192 DCHECK_EQ(0, stream_id_); | 194 DCHECK_EQ(0, stream_id_); |
| 193 stream_id_ = ipc_->AddDelegate(this); | 195 stream_id_ = ipc_->AddDelegate(this); |
| 194 DCHECK_NE(0, stream_id_); | 196 DCHECK_NE(0, stream_id_); |
| 195 | 197 |
| 196 if (!session_id) { | 198 if (!session_id) { |
| 197 // We will be notified by OnStreamCreated(). | 199 // We will be notified by OnStreamCreated(). |
| 198 ipc_->CreateStream(stream_id_, params_, | 200 ipc_->CreateStream(stream_id_, params_, |
| 199 media::AudioManagerBase::kDefaultDeviceId, false); | 201 media::AudioManagerBase::kDefaultDeviceId, false, 1); |
| 200 } else { | 202 } else { |
| 201 // We will be notified by OnDeviceReady(). | 203 // We will be notified by OnDeviceReady(). |
| 202 ipc_->StartDevice(stream_id_, session_id); | 204 ipc_->StartDevice(stream_id_, session_id); |
| 203 } | 205 } |
| 204 } | 206 } |
| 205 | 207 |
| 206 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { | 208 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { |
| 207 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> | 209 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
| 208 BelongsToCurrentThread()); | 210 BelongsToCurrentThread()); |
| 209 | 211 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 282 } |
| 281 | 283 |
| 282 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { | 284 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { |
| 283 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 285 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
| 284 | 286 |
| 285 if (client_) | 287 if (client_) |
| 286 client_->StreamCreationFailed(); | 288 client_->StreamCreationFailed(); |
| 287 } | 289 } |
| 288 | 290 |
| 289 } // namespace content | 291 } // namespace content |
| OLD | NEW |