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

Side by Side Diff: media/audio/pulse/pulse_input.cc

Issue 1711823004: Let default device in PulseAudio be the system default device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « media/audio/pulse/pulse_input.h ('k') | media/audio/pulse/pulse_output.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool PulseAudioInputStream::Open() { 51 bool PulseAudioInputStream::Open() {
52 DCHECK(thread_checker_.CalledOnValidThread()); 52 DCHECK(thread_checker_.CalledOnValidThread());
53 AutoPulseLock auto_lock(pa_mainloop_); 53 AutoPulseLock auto_lock(pa_mainloop_);
54 std::string device_name_to_use = device_name_;
55 if (device_name_ == AudioManagerBase::kDefaultDeviceId) {
56 GetSystemDefaultInputDevice();
57 device_name_to_use = default_system_device_name_;
58 }
59
54 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_, 60 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_,
55 device_name_, &StreamNotifyCallback, this)) { 61 device_name_to_use, &StreamNotifyCallback,
62 this)) {
56 return false; 63 return false;
57 } 64 }
58 65
59 DCHECK(handle_); 66 DCHECK(handle_);
60 67
61 return true; 68 return true;
62 } 69 }
63 70
64 void PulseAudioInputStream::Start(AudioInputCallback* callback) { 71 void PulseAudioInputStream::Start(AudioInputCallback* callback) {
65 DCHECK(thread_checker_.CalledOnValidThread()); 72 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 reinterpret_cast<PulseAudioInputStream*>(user_data); 268 reinterpret_cast<PulseAudioInputStream*>(user_data);
262 269
263 if (s && stream->callback_ && 270 if (s && stream->callback_ &&
264 pa_stream_get_state(s) == PA_STREAM_FAILED) { 271 pa_stream_get_state(s) == PA_STREAM_FAILED) {
265 stream->callback_->OnError(stream); 272 stream->callback_->OnError(stream);
266 } 273 }
267 274
268 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0); 275 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0);
269 } 276 }
270 277
278 // static, used by pa_context_get_server_info.
279 void PulseAudioInputStream::GetSystemDefaultInputDeviceCallback(
280 pa_context* context,
281 const pa_server_info* info,
282 void* user_data) {
283 media::PulseAudioInputStream* stream =
284 static_cast<media::PulseAudioInputStream*>(user_data);
285 stream->default_system_device_name_ = info->default_source_name;
286 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0);
287 }
288
289 void PulseAudioInputStream::GetSystemDefaultInputDevice() {
290 DCHECK(pa_mainloop_);
291 DCHECK(pa_context_);
292 pa_operation* operation = pa_context_get_server_info(
293 pa_context_, PulseAudioInputStream::GetSystemDefaultInputDeviceCallback,
294 this);
295 WaitForOperationCompletion(pa_mainloop_, operation);
296 }
297
271 void PulseAudioInputStream::ReadData() { 298 void PulseAudioInputStream::ReadData() {
272 uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes( 299 uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes(
273 handle_, params_.sample_rate(), params_.GetBytesPerFrame()); 300 handle_, params_.sample_rate(), params_.GetBytesPerFrame());
274 301
275 // Update the AGC volume level once every second. Note that, 302 // Update the AGC volume level once every second. Note that,
276 // |volume| is also updated each time SetVolume() is called 303 // |volume| is also updated each time SetVolume() is called
277 // through IPC by the render-side AGC. 304 // through IPC by the render-side AGC.
278 // We disregard the |normalized_volume| from GetAgcVolume() 305 // We disregard the |normalized_volume| from GetAgcVolume()
279 // and use the value calculated by |volume_|. 306 // and use the value calculated by |volume_|.
280 double normalized_volume = 0.0; 307 double normalized_volume = 0.0;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return false; 353 return false;
327 354
328 size_t index = pa_stream_get_device_index(handle_); 355 size_t index = pa_stream_get_device_index(handle_);
329 pa_operation* operation = 356 pa_operation* operation =
330 pa_context_get_source_info_by_index(pa_context_, index, callback, this); 357 pa_context_get_source_info_by_index(pa_context_, index, callback, this);
331 WaitForOperationCompletion(pa_mainloop_, operation); 358 WaitForOperationCompletion(pa_mainloop_, operation);
332 return true; 359 return true;
333 } 360 }
334 361
335 } // namespace media 362 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/pulse_input.h ('k') | media/audio/pulse/pulse_output.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698