Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(731)

Side by Side Diff: content/renderer/pepper/pepper_platform_audio_input_impl.cc

Issue 10790121: First step towards moving AudioDevice from content/ to media/audio. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: relaxing the notreached back to log(error) since nacl tests will otherwise fail Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "content/common/child_process.h" 11 #include "content/common/child_process.h"
12 #include "content/common/media/audio_messages.h" 12 #include "content/common/media/audio_messages.h"
13 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" 13 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
14 #include "content/renderer/render_thread_impl.h" 14 #include "content/renderer/render_thread_impl.h"
15 #include "media/audio/audio_manager_base.h" 15 #include "media/audio/audio_manager_base.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 // static 19 // static
20 PepperPlatformAudioInputImpl* PepperPlatformAudioInputImpl::Create( 20 PepperPlatformAudioInputImpl* PepperPlatformAudioInputImpl::Create(
21 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, 21 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
22 const std::string& device_id, 22 const std::string& device_id,
23 int sample_rate, 23 int sample_rate,
24 int frames_per_buffer, 24 int frames_per_buffer,
25 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client) { 25 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client) {
26 scoped_refptr<PepperPlatformAudioInputImpl> audio_input( 26 scoped_refptr<PepperPlatformAudioInputImpl> audio_input(
27 new PepperPlatformAudioInputImpl); 27 new PepperPlatformAudioInputImpl());
28 if (audio_input->Initialize(plugin_delegate, device_id, sample_rate, 28 if (audio_input->Initialize(plugin_delegate, device_id, sample_rate,
29 frames_per_buffer, client)) { 29 frames_per_buffer, client)) {
30 // Balanced by Release invoked in 30 // Balanced by Release invoked in
31 // PepperPlatformAudioInputImpl::ShutDownOnIOThread(). 31 // PepperPlatformAudioInputImpl::ShutDownOnIOThread().
32 return audio_input.release(); 32 return audio_input.release();
33 } 33 }
34 return NULL; 34 return NULL;
35 } 35 }
36 36
37 void PepperPlatformAudioInputImpl::StartCapture() { 37 void PepperPlatformAudioInputImpl::StartCapture() {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } else { 90 } else {
91 // Clean up the handles. 91 // Clean up the handles.
92 base::SyncSocket temp_socket(socket_handle); 92 base::SyncSocket temp_socket(socket_handle);
93 base::SharedMemory temp_shared_memory(handle, false); 93 base::SharedMemory temp_shared_memory(handle, false);
94 } 94 }
95 } 95 }
96 } 96 }
97 97
98 void PepperPlatformAudioInputImpl::OnVolume(double volume) {} 98 void PepperPlatformAudioInputImpl::OnVolume(double volume) {}
99 99
100 void PepperPlatformAudioInputImpl::OnStateChanged(AudioStreamState state) {} 100 void PepperPlatformAudioInputImpl::OnStateChanged(
101 media::AudioInputDeviceIPCDelegate::State state) {
102 }
101 103
102 void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string& device_id) { 104 void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string& device_id) {
103 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> 105 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
104 BelongsToCurrentThread()); 106 BelongsToCurrentThread());
105 107
106 if (shutdown_called_) 108 if (shutdown_called_)
107 return; 109 return;
108 110
109 if (device_id.empty()) { 111 if (device_id.empty()) {
110 main_message_loop_proxy_->PostTask( 112 main_message_loop_proxy_->PostTask(
111 FROM_HERE, 113 FROM_HERE,
112 base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed, 114 base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed,
113 this)); 115 this));
114 } else { 116 } else {
115 // We will be notified by OnStreamCreated(). 117 // We will be notified by OnStreamCreated().
116 filter_->Send(new AudioInputHostMsg_CreateStream(stream_id_, params_, 118 ipc_->CreateStream(stream_id_, params_, device_id, false);
117 device_id, false));
118 } 119 }
119 } 120 }
120 121
122 void PepperPlatformAudioInputImpl::OnIPCClosed() {
123 ipc_ = NULL;
scherkus (not reviewing) 2012/07/24 17:57:48 null deref if stream_id != 0?
tommi (sloooow) - chröme 2012/07/25 13:46:17 See other comment. I didn't want to add reference
124 }
125
121 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { 126 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() {
122 // Make sure we have been shut down. Warning: this may happen on the I/O 127 // Make sure we have been shut down. Warning: this may happen on the I/O
123 // thread! 128 // thread!
124 // Although these members should be accessed on a specific thread (either the 129 // Although these members should be accessed on a specific thread (either the
125 // main thread or the I/O thread), it should be fine to examine their value 130 // main thread or the I/O thread), it should be fine to examine their value
126 // here. 131 // here.
127 DCHECK_EQ(0, stream_id_); 132 DCHECK_EQ(0, stream_id_);
128 DCHECK(!client_); 133 DCHECK(!client_);
129 DCHECK(label_.empty()); 134 DCHECK(label_.empty());
130 DCHECK(shutdown_called_); 135 DCHECK(shutdown_called_);
131 } 136 }
132 137
133 PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl() 138 PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl()
134 : client_(NULL), 139 : client_(NULL),
135 stream_id_(0), 140 stream_id_(0),
136 main_message_loop_proxy_(base::MessageLoopProxy::current()), 141 main_message_loop_proxy_(base::MessageLoopProxy::current()),
137 shutdown_called_(false) { 142 shutdown_called_(false) {
138 filter_ = RenderThreadImpl::current()->audio_input_message_filter(); 143 ipc_ = RenderThreadImpl::current()->audio_input_message_filter();
139 } 144 }
140 145
141 bool PepperPlatformAudioInputImpl::Initialize( 146 bool PepperPlatformAudioInputImpl::Initialize(
142 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, 147 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
143 const std::string& device_id, 148 const std::string& device_id,
144 int sample_rate, 149 int sample_rate,
145 int frames_per_buffer, 150 int frames_per_buffer,
146 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client) { 151 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client) {
147 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); 152 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
148 153
(...skipping 24 matching lines...) Expand all
173 178
174 void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) { 179 void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) {
175 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> 180 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
176 BelongsToCurrentThread()); 181 BelongsToCurrentThread());
177 182
178 if (shutdown_called_) 183 if (shutdown_called_)
179 return; 184 return;
180 185
181 // Make sure we don't call init more than once. 186 // Make sure we don't call init more than once.
182 DCHECK_EQ(0, stream_id_); 187 DCHECK_EQ(0, stream_id_);
183 stream_id_ = filter_->AddDelegate(this); 188 stream_id_ = ipc_->AddDelegate(this);
184 DCHECK_NE(0, stream_id_); 189 DCHECK_NE(0, stream_id_);
185 190
186 if (!session_id) { 191 if (!session_id) {
187 // We will be notified by OnStreamCreated(). 192 // We will be notified by OnStreamCreated().
188 filter_->Send(new AudioInputHostMsg_CreateStream( 193 ipc_->CreateStream(stream_id_, params_,
189 stream_id_, params_, 194 media::AudioManagerBase::kDefaultDeviceId, false);
190 media::AudioManagerBase::kDefaultDeviceId, false));
191 } else { 195 } else {
192 // We will be notified by OnDeviceReady(). 196 // We will be notified by OnDeviceReady().
193 filter_->Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id)); 197 ipc_->StartDevice(stream_id_, session_id);
194 } 198 }
195 } 199 }
196 200
197 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { 201 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() {
198 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> 202 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
199 BelongsToCurrentThread()); 203 BelongsToCurrentThread());
200 204
201 if (stream_id_) 205 if (stream_id_)
202 filter_->Send(new AudioInputHostMsg_RecordStream(stream_id_)); 206 ipc_->RecordStream(stream_id_);
203 } 207 }
204 208
205 void PepperPlatformAudioInputImpl::StopCaptureOnIOThread() { 209 void PepperPlatformAudioInputImpl::StopCaptureOnIOThread() {
206 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> 210 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
207 BelongsToCurrentThread()); 211 BelongsToCurrentThread());
208 212
209 // TODO(yzshen): We cannot re-start capturing if the stream is closed. 213 // TODO(yzshen): We cannot re-start capturing if the stream is closed.
210 if (stream_id_) 214 if (stream_id_)
211 filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_)); 215 ipc_->CloseStream(stream_id_);
212 } 216 }
213 217
214 void PepperPlatformAudioInputImpl::ShutDownOnIOThread() { 218 void PepperPlatformAudioInputImpl::ShutDownOnIOThread() {
215 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> 219 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
216 BelongsToCurrentThread()); 220 BelongsToCurrentThread());
217 221
218 // Make sure we don't call shutdown more than once. 222 // Make sure we don't call shutdown more than once.
219 if (shutdown_called_) 223 if (shutdown_called_)
220 return; 224 return;
221 shutdown_called_ = true; 225 shutdown_called_ = true;
222 226
223 if (stream_id_) { 227 if (stream_id_) {
224 filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_)); 228 ipc_->CloseStream(stream_id_);
225 filter_->RemoveDelegate(stream_id_); 229 ipc_->RemoveDelegate(stream_id_);
226 stream_id_ = 0; 230 stream_id_ = 0;
227 } 231 }
228 232
229 main_message_loop_proxy_->PostTask( 233 main_message_loop_proxy_->PostTask(
230 FROM_HERE, 234 FROM_HERE,
231 base::Bind(&PepperPlatformAudioInputImpl::CloseDevice, this)); 235 base::Bind(&PepperPlatformAudioInputImpl::CloseDevice, this));
232 236
233 Release(); // Release for the delegate, balances out the reference taken in 237 Release(); // Release for the delegate, balances out the reference taken in
234 // PepperPluginDelegateImpl::CreateAudioInput. 238 // PepperPluginDelegateImpl::CreateAudioInput.
235 } 239 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 273 }
270 274
271 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { 275 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() {
272 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); 276 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
273 277
274 if (client_) 278 if (client_)
275 client_->StreamCreationFailed(); 279 client_->StreamCreationFailed();
276 } 280 }
277 281
278 } // namespace content 282 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698