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

Side by Side Diff: media/audio/linux/audio_manager_linux.cc

Issue 10952024: Adding pulseaudio input support to chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: switched to dynamic linking and addressed Andrew's comments. Created 7 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 | Annotate | Revision Log
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/linux/audio_manager_linux.h" 5 #include "media/audio/linux/audio_manager_linux.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/environment.h" 8 #include "base/environment.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/nix/xdg_util.h" 10 #include "base/nix/xdg_util.h"
11 #include "base/process_util.h" 11 #include "base/process_util.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "media/audio/audio_output_dispatcher.h" 13 #include "media/audio/audio_output_dispatcher.h"
14 #include "media/audio/audio_util.h" 14 #include "media/audio/audio_util.h"
15 #include "media/audio/linux/alsa_input.h" 15 #include "media/audio/linux/alsa_input.h"
16 #include "media/audio/linux/alsa_output.h" 16 #include "media/audio/linux/alsa_output.h"
17 #include "media/audio/linux/alsa_wrapper.h" 17 #include "media/audio/linux/alsa_wrapper.h"
18 #if defined(USE_PULSEAUDIO) 18 #if defined(USE_PULSEAUDIO)
19 #include "media/audio/pulse/pulse_output.h" 19 #include "media/audio/pulse/audio_manager_pulse.h"
20 #endif 20 #endif
21 #if defined(USE_CRAS) 21 #if defined(USE_CRAS)
22 #include "media/audio/linux/cras_input.h" 22 #include "media/audio/linux/cras_input.h"
23 #include "media/audio/linux/cras_output.h" 23 #include "media/audio/linux/cras_output.h"
24 #endif 24 #endif
25 #include "media/base/limits.h" 25 #include "media/base/limits.h"
26 #include "media/base/media_switches.h" 26 #include "media/base/media_switches.h"
27 27
28 namespace media { 28 namespace media {
29 29
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 296 }
297 297
298 AudioOutputStream* AudioManagerLinux::MakeOutputStream( 298 AudioOutputStream* AudioManagerLinux::MakeOutputStream(
299 const AudioParameters& params) { 299 const AudioParameters& params) {
300 #if defined(USE_CRAS) 300 #if defined(USE_CRAS)
301 if (UseCras()) { 301 if (UseCras()) {
302 return new CrasOutputStream(params, this); 302 return new CrasOutputStream(params, this);
303 } 303 }
304 #endif 304 #endif
305 305
306 #if defined(USE_PULSEAUDIO)
307 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) {
308 return new PulseAudioOutputStream(params, this);
309 }
310 #endif
311
312 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; 306 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice;
313 if (CommandLine::ForCurrentProcess()->HasSwitch( 307 if (CommandLine::ForCurrentProcess()->HasSwitch(
314 switches::kAlsaOutputDevice)) { 308 switches::kAlsaOutputDevice)) {
315 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 309 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
316 switches::kAlsaOutputDevice); 310 switches::kAlsaOutputDevice);
317 } 311 }
318 return new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this); 312 return new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this);
319 } 313 }
320 314
321 AudioInputStream* AudioManagerLinux::MakeInputStream( 315 AudioInputStream* AudioManagerLinux::MakeInputStream(
322 const AudioParameters& params, const std::string& device_id) { 316 const AudioParameters& params, const std::string& device_id) {
323 #if defined(USE_CRAS) 317 #if defined(USE_CRAS)
324 if (UseCras()) { 318 if (UseCras()) {
325 return new CrasInputStream(params, this); 319 return new CrasInputStream(params, this);
326 } 320 }
327 #endif 321 #endif
328 322
329 std::string device_name = (device_id == AudioManagerBase::kDefaultDeviceId) ? 323 std::string device_name = (device_id == AudioManagerBase::kDefaultDeviceId) ?
330 AlsaPcmInputStream::kAutoSelectDevice : device_id; 324 AlsaPcmInputStream::kAutoSelectDevice : device_id;
331 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { 325 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) {
332 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 326 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
333 switches::kAlsaInputDevice); 327 switches::kAlsaInputDevice);
334 } 328 }
335 329
336 return new AlsaPcmInputStream(this, device_name, params, wrapper_.get()); 330 return new AlsaPcmInputStream(this, device_name, params, wrapper_.get());
337 } 331 }
338 332
339 AudioManager* CreateAudioManager() { 333 AudioManager* CreateAudioManager() {
334 #if defined(USE_PULSEAUDIO)
DaleCurtis 2013/02/15 00:28:51 Can we just remove this #define now?
no longer working on chromium 2013/02/15 16:07:33 My plan is to remove the switch in another CL, aft
335 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) {
336 AudioManager* manager = AudioManagerPulse::Create();
337 if (manager)
338 return manager;
339 }
340 #endif
341
340 return new AudioManagerLinux(); 342 return new AudioManagerLinux();
341 } 343 }
342 344
343 AudioParameters AudioManagerLinux::GetPreferredLowLatencyOutputStreamParameters( 345 AudioParameters AudioManagerLinux::GetPreferredLowLatencyOutputStreamParameters(
344 const AudioParameters& input_params) { 346 const AudioParameters& input_params) {
345 // Since Linux doesn't actually have a low latency path the hardware buffer 347 // Since Linux doesn't actually have a low latency path the hardware buffer
346 // size is quite large in order to prevent glitches with general usage. Some 348 // size is quite large in order to prevent glitches with general usage. Some
347 // clients, such as WebRTC, have a more limited use case and work acceptably 349 // clients, such as WebRTC, have a more limited use case and work acceptably
348 // with a smaller buffer size. The check below allows clients which want to 350 // with a smaller buffer size. The check below allows clients which want to
349 // try a smaller buffer size on Linux to do so. 351 // try a smaller buffer size on Linux to do so.
350 int buffer_size = GetAudioHardwareBufferSize(); 352 int buffer_size = GetAudioHardwareBufferSize();
351 if (input_params.frames_per_buffer() < buffer_size) 353 if (input_params.frames_per_buffer() < buffer_size)
352 buffer_size = input_params.frames_per_buffer(); 354 buffer_size = input_params.frames_per_buffer();
353 355
354 // TODO(dalecurtis): This should include bits per channel and channel layout 356 // TODO(dalecurtis): This should include bits per channel and channel layout
355 // eventually. 357 // eventually.
356 return AudioParameters( 358 return AudioParameters(
357 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), 359 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(),
358 input_params.sample_rate(), 16, buffer_size); 360 input_params.sample_rate(), 16, buffer_size);
359 } 361 }
360 362
361 } // namespace media 363 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698