Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_util.h" | 14 #include "media/audio/audio_util.h" |
| 15 | 15 |
| 16 static const char kDefaultDeviceUId[] = "default"; | |
|
scherkus (not reviewing)
2011/11/16 01:20:40
I don't see this used and it's also confusing with
no longer working on chromium
2011/11/16 17:45:48
Sorry, wrong code by mistake.
| |
| 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 Loading... | |
| 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 // Pass an empty string to indicate using default device. | |
| 132 std::string default_device_uid = ""; | |
| 129 Send(new AudioInputHostMsg_CreateStream(stream_id_, audio_parameters_, | 133 Send(new AudioInputHostMsg_CreateStream(stream_id_, audio_parameters_, |
| 130 true)); | 134 true, default_device_uid)); |
| 131 } else { | 135 } else { |
| 132 Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_)); | 136 Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_)); |
| 133 pending_device_ready_ = true; | 137 pending_device_ready_ = true; |
| 134 } | 138 } |
| 135 } | 139 } |
| 136 | 140 |
| 137 void AudioInputDevice::SetSessionIdOnIOThread(int session_id) { | 141 void AudioInputDevice::SetSessionIdOnIOThread(int session_id) { |
| 138 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); | 142 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); |
| 139 session_id_ = session_id; | 143 session_id_ = session_id; |
| 140 } | 144 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 break; | 243 break; |
| 240 case kAudioStreamError: | 244 case kAudioStreamError: |
| 241 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(kError)"; | 245 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(kError)"; |
| 242 break; | 246 break; |
| 243 default: | 247 default: |
| 244 NOTREACHED(); | 248 NOTREACHED(); |
| 245 break; | 249 break; |
| 246 } | 250 } |
| 247 } | 251 } |
| 248 | 252 |
| 249 void AudioInputDevice::OnDeviceReady(int index) { | 253 void AudioInputDevice::OnDeviceReady(const std::string& device_uid) { |
| 250 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); | 254 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); |
| 251 VLOG(1) << "OnDeviceReady (index=" << index << ")"; | 255 VLOG(1) << "OnDeviceReady (device_uid=" << device_uid << ")"; |
| 252 | 256 |
| 253 // Takes care of the case when Stop() is called before OnDeviceReady(). | 257 // Takes care of the case when Stop() is called before OnDeviceReady(). |
| 254 if (!pending_device_ready_) | 258 if (!pending_device_ready_) |
| 255 return; | 259 return; |
| 256 | 260 |
| 257 // -1 means no device has been started. | 261 // If AudioInputDeviceManager returns an empty string, it means no device |
| 258 if (index == -1) { | 262 // is ready for start. |
| 263 if (device_uid.empty()) { | |
| 259 filter_->RemoveDelegate(stream_id_); | 264 filter_->RemoveDelegate(stream_id_); |
| 260 stream_id_ = 0; | 265 stream_id_ = 0; |
| 261 } else { | 266 } else { |
| 262 Send(new AudioInputHostMsg_CreateStream( | 267 Send(new AudioInputHostMsg_CreateStream( |
| 263 stream_id_, audio_parameters_, true)); | 268 stream_id_, audio_parameters_, true, device_uid)); |
| 264 } | 269 } |
| 265 | 270 |
| 266 pending_device_ready_ = false; | 271 pending_device_ready_ = false; |
| 267 // Notify the client that the device has been started. | 272 // Notify the client that the device has been started. |
| 268 if (event_handler_) | 273 if (event_handler_) |
| 269 event_handler_->OnDeviceStarted(index); | 274 event_handler_->OnDeviceStarted(device_uid); |
| 270 } | 275 } |
| 271 | 276 |
| 272 void AudioInputDevice::Send(IPC::Message* message) { | 277 void AudioInputDevice::Send(IPC::Message* message) { |
| 273 filter_->Send(message); | 278 filter_->Send(message); |
| 274 } | 279 } |
| 275 | 280 |
| 276 // Our audio thread runs here. We receive captured audio samples on | 281 // Our audio thread runs here. We receive captured audio samples on |
| 277 // this thread. | 282 // this thread. |
| 278 void AudioInputDevice::Run() { | 283 void AudioInputDevice::Run() { |
| 279 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); | 284 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 bytes_per_sample, | 324 bytes_per_sample, |
| 320 number_of_frames); | 325 number_of_frames); |
| 321 } | 326 } |
| 322 | 327 |
| 323 // Deliver captured data to the client in floating point format | 328 // Deliver captured data to the client in floating point format |
| 324 // and update the audio-delay measurement. | 329 // and update the audio-delay measurement. |
| 325 callback_->Capture(audio_data_, | 330 callback_->Capture(audio_data_, |
| 326 number_of_frames, | 331 number_of_frames, |
| 327 audio_delay_milliseconds_); | 332 audio_delay_milliseconds_); |
| 328 } | 333 } |
| OLD | NEW |