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

Side by Side Diff: content/renderer/media/audio_input_device.cc

Issue 8491044: Link things together and enable the device selection for linux and mac. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: tiny fix for the unittests on mac Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/media/audio_input_device.h" 5 #include "content/renderer/media/audio_input_device.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "content/common/child_process.h" 10 #include "content/common/child_process.h"
11 #include "content/common/media/audio_messages.h" 11 #include "content/common/media/audio_messages.h"
12 #include "content/common/view_messages.h" 12 #include "content/common/view_messages.h"
13 #include "content/renderer/render_thread_impl.h" 13 #include "content/renderer/render_thread_impl.h"
14 #include "media/audio/audio_manager_base.h"
14 #include "media/audio/audio_util.h" 15 #include "media/audio/audio_util.h"
15 16
jam 2011/11/21 16:39:23 nit: extra line
no longer working on chromium 2011/11/21 16:47:56 Done.
17
16 AudioInputDevice::AudioInputDevice(size_t buffer_size, 18 AudioInputDevice::AudioInputDevice(size_t buffer_size,
17 int channels, 19 int channels,
18 double sample_rate, 20 double sample_rate,
19 CaptureCallback* callback, 21 CaptureCallback* callback,
20 CaptureEventHandler* event_handler) 22 CaptureEventHandler* event_handler)
21 : callback_(callback), 23 : callback_(callback),
22 event_handler_(event_handler), 24 event_handler_(event_handler),
23 audio_delay_milliseconds_(0), 25 audio_delay_milliseconds_(0),
24 volume_(1.0), 26 volume_(1.0),
25 stream_id_(0), 27 stream_id_(0),
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // Make sure we don't call Start() more than once. 121 // Make sure we don't call Start() more than once.
120 DCHECK_EQ(0, stream_id_); 122 DCHECK_EQ(0, stream_id_);
121 if (stream_id_) 123 if (stream_id_)
122 return; 124 return;
123 125
124 stream_id_ = filter_->AddDelegate(this); 126 stream_id_ = filter_->AddDelegate(this);
125 // If |session_id_| is not specified, it will directly create the stream; 127 // If |session_id_| is not specified, it will directly create the stream;
126 // otherwise it will send a AudioInputHostMsg_StartDevice msg to the browser 128 // otherwise it will send a AudioInputHostMsg_StartDevice msg to the browser
127 // and create the stream when getting a OnDeviceReady() callback. 129 // and create the stream when getting a OnDeviceReady() callback.
128 if (!session_id_) { 130 if (!session_id_) {
131 std::string device_id = AudioManagerBase::kDefaultDeviceId;
129 Send(new AudioInputHostMsg_CreateStream(stream_id_, audio_parameters_, 132 Send(new AudioInputHostMsg_CreateStream(stream_id_, audio_parameters_,
130 true)); 133 true, device_id));
131 } else { 134 } else {
132 Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_)); 135 Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_));
133 pending_device_ready_ = true; 136 pending_device_ready_ = true;
134 } 137 }
135 } 138 }
136 139
137 void AudioInputDevice::SetSessionIdOnIOThread(int session_id) { 140 void AudioInputDevice::SetSessionIdOnIOThread(int session_id) {
138 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); 141 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
139 session_id_ = session_id; 142 session_id_ = session_id;
140 } 143 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 break; 242 break;
240 case kAudioStreamError: 243 case kAudioStreamError:
241 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(kError)"; 244 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(kError)";
242 break; 245 break;
243 default: 246 default:
244 NOTREACHED(); 247 NOTREACHED();
245 break; 248 break;
246 } 249 }
247 } 250 }
248 251
249 void AudioInputDevice::OnDeviceReady(int index) { 252 void AudioInputDevice::OnDeviceReady(const std::string& device_id) {
250 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); 253 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
251 VLOG(1) << "OnDeviceReady (index=" << index << ")"; 254 VLOG(1) << "OnDeviceReady (device_id=" << device_id << ")";
252 255
253 // Takes care of the case when Stop() is called before OnDeviceReady(). 256 // Takes care of the case when Stop() is called before OnDeviceReady().
254 if (!pending_device_ready_) 257 if (!pending_device_ready_)
255 return; 258 return;
256 259
257 // -1 means no device has been started. 260 // If AudioInputDeviceManager returns an empty string, it means no device
258 if (index == -1) { 261 // is ready for start.
262 if (device_id.empty()) {
259 filter_->RemoveDelegate(stream_id_); 263 filter_->RemoveDelegate(stream_id_);
260 stream_id_ = 0; 264 stream_id_ = 0;
261 } else { 265 } else {
262 Send(new AudioInputHostMsg_CreateStream( 266 Send(new AudioInputHostMsg_CreateStream(
263 stream_id_, audio_parameters_, true)); 267 stream_id_, audio_parameters_, true, device_id));
264 } 268 }
265 269
266 pending_device_ready_ = false; 270 pending_device_ready_ = false;
267 // Notify the client that the device has been started. 271 // Notify the client that the device has been started.
268 if (event_handler_) 272 if (event_handler_)
269 event_handler_->OnDeviceStarted(index); 273 event_handler_->OnDeviceStarted(device_id);
270 } 274 }
271 275
272 void AudioInputDevice::Send(IPC::Message* message) { 276 void AudioInputDevice::Send(IPC::Message* message) {
273 filter_->Send(message); 277 filter_->Send(message);
274 } 278 }
275 279
276 // Our audio thread runs here. We receive captured audio samples on 280 // Our audio thread runs here. We receive captured audio samples on
277 // this thread. 281 // this thread.
278 void AudioInputDevice::Run() { 282 void AudioInputDevice::Run() {
279 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); 283 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 bytes_per_sample, 323 bytes_per_sample,
320 number_of_frames); 324 number_of_frames);
321 } 325 }
322 326
323 // Deliver captured data to the client in floating point format 327 // Deliver captured data to the client in floating point format
324 // and update the audio-delay measurement. 328 // and update the audio-delay measurement.
325 callback_->Capture(audio_data_, 329 callback_->Capture(audio_data_,
326 number_of_frames, 330 number_of_frames,
327 audio_delay_milliseconds_); 331 audio_delay_milliseconds_);
328 } 332 }
OLDNEW
« no previous file with comments | « content/renderer/media/audio_input_device.h ('k') | content/renderer/media/audio_input_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698