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 // TODO(yzshen): Make use of circular buffer scheme. crbug.com/181449. |
| 80 DCHECK_EQ(1, total_segments); |
78 | 81 |
79 if (base::MessageLoopProxy::current() != main_message_loop_proxy_) { | 82 if (base::MessageLoopProxy::current() != main_message_loop_proxy_) { |
80 // No need to check |shutdown_called_| here. If shutdown has occurred, | 83 // 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 | 84 // |client_| will be NULL and the handles will be cleaned up on the main |
82 // thread. | 85 // thread. |
83 main_message_loop_proxy_->PostTask( | 86 main_message_loop_proxy_->PostTask( |
84 FROM_HERE, | 87 FROM_HERE, |
85 base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this, | 88 base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this, |
86 handle, socket_handle, length)); | 89 handle, socket_handle, length, total_segments)); |
87 } else { | 90 } else { |
88 // Must dereference the client only on the main thread. Shutdown may have | 91 // 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. | 92 // occurred while the request was in-flight, so we need to NULL check. |
90 if (client_) { | 93 if (client_) { |
91 client_->StreamCreated(handle, length, socket_handle); | 94 client_->StreamCreated(handle, length, socket_handle); |
92 } else { | 95 } else { |
93 // Clean up the handles. | 96 // Clean up the handles. |
94 base::SyncSocket temp_socket(socket_handle); | 97 base::SyncSocket temp_socket(socket_handle); |
95 base::SharedMemory temp_shared_memory(handle, false); | 98 base::SharedMemory temp_shared_memory(handle, false); |
96 } | 99 } |
(...skipping 13 matching lines...) Expand all Loading... |
110 if (shutdown_called_) | 113 if (shutdown_called_) |
111 return; | 114 return; |
112 | 115 |
113 if (device_id.empty()) { | 116 if (device_id.empty()) { |
114 main_message_loop_proxy_->PostTask( | 117 main_message_loop_proxy_->PostTask( |
115 FROM_HERE, | 118 FROM_HERE, |
116 base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed, | 119 base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed, |
117 this)); | 120 this)); |
118 } else { | 121 } else { |
119 // We will be notified by OnStreamCreated(). | 122 // We will be notified by OnStreamCreated(). |
120 ipc_->CreateStream(stream_id_, params_, device_id, false); | 123 ipc_->CreateStream(stream_id_, params_, device_id, false, 1); |
121 } | 124 } |
122 } | 125 } |
123 | 126 |
124 void PepperPlatformAudioInputImpl::OnIPCClosed() { | 127 void PepperPlatformAudioInputImpl::OnIPCClosed() { |
125 ipc_ = NULL; | 128 ipc_ = NULL; |
126 } | 129 } |
127 | 130 |
128 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { | 131 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { |
129 // Make sure we have been shut down. Warning: this may happen on the I/O | 132 // Make sure we have been shut down. Warning: this may happen on the I/O |
130 // thread! | 133 // thread! |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return; | 192 return; |
190 | 193 |
191 // Make sure we don't call init more than once. | 194 // Make sure we don't call init more than once. |
192 DCHECK_EQ(0, stream_id_); | 195 DCHECK_EQ(0, stream_id_); |
193 stream_id_ = ipc_->AddDelegate(this); | 196 stream_id_ = ipc_->AddDelegate(this); |
194 DCHECK_NE(0, stream_id_); | 197 DCHECK_NE(0, stream_id_); |
195 | 198 |
196 if (!session_id) { | 199 if (!session_id) { |
197 // We will be notified by OnStreamCreated(). | 200 // We will be notified by OnStreamCreated(). |
198 ipc_->CreateStream(stream_id_, params_, | 201 ipc_->CreateStream(stream_id_, params_, |
199 media::AudioManagerBase::kDefaultDeviceId, false); | 202 media::AudioManagerBase::kDefaultDeviceId, false, 1); |
200 } else { | 203 } else { |
201 // We will be notified by OnDeviceReady(). | 204 // We will be notified by OnDeviceReady(). |
202 ipc_->StartDevice(stream_id_, session_id); | 205 ipc_->StartDevice(stream_id_, session_id); |
203 } | 206 } |
204 } | 207 } |
205 | 208 |
206 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { | 209 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { |
207 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> | 210 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
208 BelongsToCurrentThread()); | 211 BelongsToCurrentThread()); |
209 | 212 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } | 283 } |
281 | 284 |
282 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { | 285 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { |
283 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 286 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
284 | 287 |
285 if (client_) | 288 if (client_) |
286 client_->StreamCreationFailed(); | 289 client_->StreamCreationFailed(); |
287 } | 290 } |
288 | 291 |
289 } // namespace content | 292 } // namespace content |
OLD | NEW |