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

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

Issue 1992203002: Use "application default" audio device as default PulseAudio device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge fix. 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/audio_device_description.h" 10 #include "media/audio/audio_device_description.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 PulseAudioInputStream::~PulseAudioInputStream() { 46 PulseAudioInputStream::~PulseAudioInputStream() {
47 // All internal structures should already have been freed in Close(), 47 // All internal structures should already have been freed in Close(),
48 // which calls AudioManagerPulse::Release which deletes this object. 48 // which calls AudioManagerPulse::Release which deletes this object.
49 DCHECK(!handle_); 49 DCHECK(!handle_);
50 } 50 }
51 51
52 bool PulseAudioInputStream::Open() { 52 bool PulseAudioInputStream::Open() {
53 DCHECK(thread_checker_.CalledOnValidThread()); 53 DCHECK(thread_checker_.CalledOnValidThread());
54 AutoPulseLock auto_lock(pa_mainloop_); 54 AutoPulseLock auto_lock(pa_mainloop_);
55 std::string device_name_to_use = device_name_;
56 if (device_name_ == AudioDeviceDescription::kDefaultDeviceId) {
57 GetSystemDefaultInputDevice();
58 device_name_to_use = default_system_device_name_;
59 }
60
61 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_, 55 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_,
62 device_name_to_use, &StreamNotifyCallback, 56 device_name_, &StreamNotifyCallback, this)) {
63 this)) {
64 return false; 57 return false;
65 } 58 }
66 59
67 DCHECK(handle_); 60 DCHECK(handle_);
68 61
69 return true; 62 return true;
70 } 63 }
71 64
72 void PulseAudioInputStream::Start(AudioInputCallback* callback) { 65 void PulseAudioInputStream::Start(AudioInputCallback* callback) {
73 DCHECK(thread_checker_.CalledOnValidThread()); 66 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 reinterpret_cast<PulseAudioInputStream*>(user_data); 262 reinterpret_cast<PulseAudioInputStream*>(user_data);
270 263
271 if (s && stream->callback_ && 264 if (s && stream->callback_ &&
272 pa_stream_get_state(s) == PA_STREAM_FAILED) { 265 pa_stream_get_state(s) == PA_STREAM_FAILED) {
273 stream->callback_->OnError(stream); 266 stream->callback_->OnError(stream);
274 } 267 }
275 268
276 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0); 269 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0);
277 } 270 }
278 271
279 // static, used by pa_context_get_server_info.
280 void PulseAudioInputStream::GetSystemDefaultInputDeviceCallback(
281 pa_context* context,
282 const pa_server_info* info,
283 void* user_data) {
284 media::PulseAudioInputStream* stream =
285 static_cast<media::PulseAudioInputStream*>(user_data);
286 stream->default_system_device_name_ = info->default_source_name;
287 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0);
288 }
289
290 void PulseAudioInputStream::GetSystemDefaultInputDevice() {
291 DCHECK(pa_mainloop_);
292 DCHECK(pa_context_);
293 pa_operation* operation = pa_context_get_server_info(
294 pa_context_, PulseAudioInputStream::GetSystemDefaultInputDeviceCallback,
295 this);
296 WaitForOperationCompletion(pa_mainloop_, operation);
297 }
298
299 void PulseAudioInputStream::ReadData() { 272 void PulseAudioInputStream::ReadData() {
300 uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes( 273 uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes(
301 handle_, params_.sample_rate(), params_.GetBytesPerFrame()); 274 handle_, params_.sample_rate(), params_.GetBytesPerFrame());
302 275
303 // Update the AGC volume level once every second. Note that, 276 // Update the AGC volume level once every second. Note that,
304 // |volume| is also updated each time SetVolume() is called 277 // |volume| is also updated each time SetVolume() is called
305 // through IPC by the render-side AGC. 278 // through IPC by the render-side AGC.
306 // We disregard the |normalized_volume| from GetAgcVolume() 279 // We disregard the |normalized_volume| from GetAgcVolume()
307 // and use the value calculated by |volume_|. 280 // and use the value calculated by |volume_|.
308 double normalized_volume = 0.0; 281 double normalized_volume = 0.0;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 return false; 327 return false;
355 328
356 size_t index = pa_stream_get_device_index(handle_); 329 size_t index = pa_stream_get_device_index(handle_);
357 pa_operation* operation = 330 pa_operation* operation =
358 pa_context_get_source_info_by_index(pa_context_, index, callback, this); 331 pa_context_get_source_info_by_index(pa_context_, index, callback, this);
359 WaitForOperationCompletion(pa_mainloop_, operation); 332 WaitForOperationCompletion(pa_mainloop_, operation);
360 return true; 333 return true;
361 } 334 }
362 335
363 } // namespace media 336 } // 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