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/browser/renderer_host/media/audio_input_device_manager.h" | |
| 10 #include "content/common/child_process.h" | 11 #include "content/common/child_process.h" |
| 11 #include "content/common/media/audio_messages.h" | 12 #include "content/common/media/audio_messages.h" |
| 12 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 13 #include "content/renderer/render_thread_impl.h" | 14 #include "content/renderer/render_thread_impl.h" |
| 14 #include "media/audio/audio_util.h" | 15 #include "media/audio/audio_util.h" |
| 15 | 16 |
| 17 static const char kDefaultDeviceUId[] = "default"; | |
|
tommi (sloooow) - chröme
2011/11/15 10:29:07
isn't this the definition of the global constant?
no longer working on chromium
2011/11/16 17:47:21
It has been removed.
| |
| 18 | |
| 16 AudioInputDevice::AudioInputDevice(size_t buffer_size, | 19 AudioInputDevice::AudioInputDevice(size_t buffer_size, |
| 17 int channels, | 20 int channels, |
| 18 double sample_rate, | 21 double sample_rate, |
| 19 CaptureCallback* callback, | 22 CaptureCallback* callback, |
| 20 CaptureEventHandler* event_handler) | 23 CaptureEventHandler* event_handler) |
| 21 : callback_(callback), | 24 : callback_(callback), |
| 22 event_handler_(event_handler), | 25 event_handler_(event_handler), |
| 23 audio_delay_milliseconds_(0), | 26 audio_delay_milliseconds_(0), |
| 24 volume_(1.0), | 27 volume_(1.0), |
| 25 stream_id_(0), | 28 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. | 122 // Make sure we don't call Start() more than once. |
| 120 DCHECK_EQ(0, stream_id_); | 123 DCHECK_EQ(0, stream_id_); |
| 121 if (stream_id_) | 124 if (stream_id_) |
| 122 return; | 125 return; |
| 123 | 126 |
| 124 stream_id_ = filter_->AddDelegate(this); | 127 stream_id_ = filter_->AddDelegate(this); |
| 125 // If |session_id_| is not specified, it will directly create the stream; | 128 // If |session_id_| is not specified, it will directly create the stream; |
| 126 // otherwise it will send a AudioInputHostMsg_StartDevice msg to the browser | 129 // otherwise it will send a AudioInputHostMsg_StartDevice msg to the browser |
| 127 // and create the stream when getting a OnDeviceReady() callback. | 130 // and create the stream when getting a OnDeviceReady() callback. |
| 128 if (!session_id_) { | 131 if (!session_id_) { |
| 132 // Pass an empty string to indicate using default device. | |
| 133 std::string default_device_uid = ""; | |
|
tommi (sloooow) - chröme
2011/11/15 10:29:07
skip the = "" part. (and uid -> id)
no longer working on chromium
2011/11/16 17:47:21
Done.
| |
| 129 Send(new AudioInputHostMsg_CreateStream(stream_id_, audio_parameters_, | 134 Send(new AudioInputHostMsg_CreateStream(stream_id_, audio_parameters_, |
| 130 true)); | 135 true, default_device_uid)); |
| 131 } else { | 136 } else { |
| 132 Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_)); | 137 Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_)); |
| 133 pending_device_ready_ = true; | 138 pending_device_ready_ = true; |
| 134 } | 139 } |
| 135 } | 140 } |
| 136 | 141 |
| 137 void AudioInputDevice::SetSessionIdOnIOThread(int session_id) { | 142 void AudioInputDevice::SetSessionIdOnIOThread(int session_id) { |
| 138 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); | 143 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); |
| 139 session_id_ = session_id; | 144 session_id_ = session_id; |
| 140 } | 145 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 break; | 244 break; |
| 240 case kAudioStreamError: | 245 case kAudioStreamError: |
| 241 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(kError)"; | 246 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(kError)"; |
| 242 break; | 247 break; |
| 243 default: | 248 default: |
| 244 NOTREACHED(); | 249 NOTREACHED(); |
| 245 break; | 250 break; |
| 246 } | 251 } |
| 247 } | 252 } |
| 248 | 253 |
| 249 void AudioInputDevice::OnDeviceReady(int index) { | 254 void AudioInputDevice::OnDeviceReady(const std::string& device_uid) { |
| 250 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); | 255 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); |
| 251 VLOG(1) << "OnDeviceReady (index=" << index << ")"; | 256 VLOG(1) << "OnDeviceReady (device_uid=" << device_uid << ")"; |
| 252 | 257 |
| 253 // Takes care of the case when Stop() is called before OnDeviceReady(). | 258 // Takes care of the case when Stop() is called before OnDeviceReady(). |
| 254 if (!pending_device_ready_) | 259 if (!pending_device_ready_) |
| 255 return; | 260 return; |
| 256 | 261 |
| 257 // -1 means no device has been started. | 262 if (device_uid == media_stream::AudioInputDeviceManager::kInvalidDeviceUId) { |
| 258 if (index == -1) { | |
| 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_uid)); |
| 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_uid); |
| 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 Loading... | |
| 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 } |
| OLD | NEW |