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

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

Issue 1998173002: Use "application default" audio device as default PulseAudio device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 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
60 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_, 54 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_,
61 device_name_to_use, &StreamNotifyCallback, 55 device_name_, &StreamNotifyCallback, this)) {
62 this)) {
63 return false; 56 return false;
64 } 57 }
65 58
66 DCHECK(handle_); 59 DCHECK(handle_);
67 60
68 return true; 61 return true;
69 } 62 }
70 63
71 void PulseAudioInputStream::Start(AudioInputCallback* callback) { 64 void PulseAudioInputStream::Start(AudioInputCallback* callback) {
72 DCHECK(thread_checker_.CalledOnValidThread()); 65 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 reinterpret_cast<PulseAudioInputStream*>(user_data); 261 reinterpret_cast<PulseAudioInputStream*>(user_data);
269 262
270 if (s && stream->callback_ && 263 if (s && stream->callback_ &&
271 pa_stream_get_state(s) == PA_STREAM_FAILED) { 264 pa_stream_get_state(s) == PA_STREAM_FAILED) {
272 stream->callback_->OnError(stream); 265 stream->callback_->OnError(stream);
273 } 266 }
274 267
275 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0); 268 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0);
276 } 269 }
277 270
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
298 void PulseAudioInputStream::ReadData() { 271 void PulseAudioInputStream::ReadData() {
299 uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes( 272 uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes(
300 handle_, params_.sample_rate(), params_.GetBytesPerFrame()); 273 handle_, params_.sample_rate(), params_.GetBytesPerFrame());
301 274
302 // Update the AGC volume level once every second. Note that, 275 // Update the AGC volume level once every second. Note that,
303 // |volume| is also updated each time SetVolume() is called 276 // |volume| is also updated each time SetVolume() is called
304 // through IPC by the render-side AGC. 277 // through IPC by the render-side AGC.
305 // We disregard the |normalized_volume| from GetAgcVolume() 278 // We disregard the |normalized_volume| from GetAgcVolume()
306 // and use the value calculated by |volume_|. 279 // and use the value calculated by |volume_|.
307 double normalized_volume = 0.0; 280 double normalized_volume = 0.0;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 return false; 326 return false;
354 327
355 size_t index = pa_stream_get_device_index(handle_); 328 size_t index = pa_stream_get_device_index(handle_);
356 pa_operation* operation = 329 pa_operation* operation =
357 pa_context_get_source_info_by_index(pa_context_, index, callback, this); 330 pa_context_get_source_info_by_index(pa_context_, index, callback, this);
358 WaitForOperationCompletion(pa_mainloop_, operation); 331 WaitForOperationCompletion(pa_mainloop_, operation);
359 return true; 332 return true;
360 } 333 }
361 334
362 } // namespace media 335 } // 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