Chromium Code Reviews| 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 "media/audio/pulse/pulse_input.h" | 5 #include "media/audio/pulse/pulse_input.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/audio/pulse/audio_manager_pulse.h" | 10 #include "media/audio/pulse/audio_manager_pulse.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 DCHECK(context); | 41 DCHECK(context); |
| 42 CHECK(params_.IsValid()); | 42 CHECK(params_.IsValid()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 PulseAudioInputStream::~PulseAudioInputStream() { | 45 PulseAudioInputStream::~PulseAudioInputStream() { |
| 46 // All internal structures should already have been freed in Close(), | 46 // All internal structures should already have been freed in Close(), |
| 47 // which calls AudioManagerPulse::Release which deletes this object. | 47 // which calls AudioManagerPulse::Release which deletes this object. |
| 48 DCHECK(!handle_); | 48 DCHECK(!handle_); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // static, used by pa_context_get_server_info. | |
| 52 void PulseAudioInputStream::GetSystemDefaultInputDeviceCallback( | |
| 53 pa_context* context, | |
| 54 const pa_server_info* info, | |
| 55 void* user_data) { | |
| 56 PulseAudioInputStream* stream = | |
| 57 reinterpret_cast<PulseAudioInputStream*>(user_data); | |
| 58 stream->default_system_device_name_ = info->default_source_name; | |
|
Henrik Grunell
2016/03/09 00:49:17
Add setter function for |default_system_device_nam
rchtara
2016/03/09 16:16:09
Done.
| |
| 59 pa_threaded_mainloop* pa_mainloop = | |
| 60 static_cast<pa_threaded_mainloop*>(stream->pa_mainloop_); | |
|
Henrik Grunell
2016/03/09 00:49:17
It doesn't look like casting is needed here.
rchtara
2016/03/09 16:16:09
Done.
| |
| 61 pa_threaded_mainloop_signal(pa_mainloop, 0); | |
| 62 } | |
| 63 | |
| 64 void PulseAudioInputStream::GetSystemDefaultInputDevice() { | |
| 65 DCHECK(pa_mainloop_); | |
| 66 DCHECK(pa_context_); | |
| 67 pa_operation* operation = pa_context_get_server_info( | |
| 68 pa_context_, PulseAudioInputStream::GetSystemDefaultInputDeviceCallback, | |
| 69 this); | |
| 70 WaitForOperationCompletion(pa_mainloop_, operation); | |
| 71 } | |
| 72 | |
| 51 bool PulseAudioInputStream::Open() { | 73 bool PulseAudioInputStream::Open() { |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
| 53 AutoPulseLock auto_lock(pa_mainloop_); | 75 AutoPulseLock auto_lock(pa_mainloop_); |
| 76 std::string device_to_use_ = device_name_; | |
|
Henrik Grunell
2016/03/09 00:49:17
"device_to_use_" -> "device_name_to_use". (No trai
rchtara
2016/03/09 16:16:09
Done.
| |
| 77 if (device_name_ == AudioManagerBase::kDefaultDeviceId) { | |
| 78 GetSystemDefaultInputDevice(); | |
| 79 device_to_use_ = default_system_device_name_; | |
| 80 } | |
| 81 | |
| 54 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_, | 82 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_, |
| 55 device_name_, &StreamNotifyCallback, this)) { | 83 device_to_use_, &StreamNotifyCallback, this)) { |
| 56 return false; | 84 return false; |
| 57 } | 85 } |
| 58 | 86 |
| 59 DCHECK(handle_); | 87 DCHECK(handle_); |
| 60 | 88 |
| 61 return true; | 89 return true; |
| 62 } | 90 } |
| 63 | 91 |
| 64 void PulseAudioInputStream::Start(AudioInputCallback* callback) { | 92 void PulseAudioInputStream::Start(AudioInputCallback* callback) { |
| 65 DCHECK(thread_checker_.CalledOnValidThread()); | 93 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 return false; | 354 return false; |
| 327 | 355 |
| 328 size_t index = pa_stream_get_device_index(handle_); | 356 size_t index = pa_stream_get_device_index(handle_); |
| 329 pa_operation* operation = | 357 pa_operation* operation = |
| 330 pa_context_get_source_info_by_index(pa_context_, index, callback, this); | 358 pa_context_get_source_info_by_index(pa_context_, index, callback, this); |
| 331 WaitForOperationCompletion(pa_mainloop_, operation); | 359 WaitForOperationCompletion(pa_mainloop_, operation); |
| 332 return true; | 360 return true; |
| 333 } | 361 } |
| 334 | 362 |
| 335 } // namespace media | 363 } // namespace media |
| OLD | NEW |