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

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, 10 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
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 30 matching lines...) Expand all
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::UseSystemDefaultInputDeviceCallback(
Henrik Grunell 2016/03/07 11:37:17 Since this function is only used in this cc file,
rchtara 2016/03/08 17:28:16 I tried to do that by making it friend with PulseA
Henrik Grunell 2016/03/09 00:49:16 I don't understand what the problem is. Is it acce
rchtara 2016/03/09 16:16:09 If we put the function UseSystemDefaultInputDevice
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->device_name_ = info->default_source_name;
Henrik Grunell 2016/03/07 11:37:17 Same here as for output (see that comment), add a
rchtara 2016/03/08 17:28:16 Done.
59 pa_threaded_mainloop* pa_mainloop =
60 static_cast<pa_threaded_mainloop*>(stream->pa_mainloop_);
61 pa_threaded_mainloop_signal(pa_mainloop, 0);
62 }
63
64 void PulseAudioInputStream::UseSystemDefaultInputDevice() {
65 DCHECK(pa_mainloop_);
66 DCHECK(pa_context_);
67 pa_operation* operation = pa_context_get_server_info(
68 pa_context_, PulseAudioInputStream::UseSystemDefaultInputDeviceCallback,
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
77 if (device_name_ == AudioManagerBase::kDefaultDeviceId) {
78 UseSystemDefaultInputDevice();
Henrik Grunell 2016/03/07 11:37:17 Should this function be called under the lock?
rchtara 2016/03/08 17:28:16 I'm not sure, it works even the lock is completely
79 }
80
54 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_, 81 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_,
55 device_name_, &StreamNotifyCallback, this)) { 82 device_name_, &StreamNotifyCallback, this)) {
56 return false; 83 return false;
57 } 84 }
58 85
59 DCHECK(handle_); 86 DCHECK(handle_);
60 87
61 return true; 88 return true;
62 } 89 }
63 90
(...skipping 262 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

Powered by Google App Engine
This is Rietveld 408576698