Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_input.h" | |
| 19 #include "media/audio/pulse/pulse_output.h" | 20 #include "media/audio/pulse/pulse_output.h" |
| 20 #endif | 21 #endif |
| 21 #if defined(USE_CRAS) | 22 #if defined(USE_CRAS) |
| 22 #include "media/audio/linux/cras_input.h" | 23 #include "media/audio/linux/cras_input.h" |
| 23 #include "media/audio/linux/cras_output.h" | 24 #include "media/audio/linux/cras_output.h" |
| 24 #endif | 25 #endif |
| 25 #include "media/base/limits.h" | 26 #include "media/base/limits.h" |
| 26 #include "media/base/media_switches.h" | 27 #include "media/base/media_switches.h" |
| 27 | 28 |
| 28 namespace media { | 29 namespace media { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool AudioManagerLinux::HasAudioInputDevices() { | 57 bool AudioManagerLinux::HasAudioInputDevices() { |
| 57 if (UseCras()) | 58 if (UseCras()) |
| 58 return true; | 59 return true; |
| 59 | 60 |
| 60 return HasAnyAlsaAudioDevice(kStreamCapture); | 61 return HasAnyAlsaAudioDevice(kStreamCapture); |
| 61 } | 62 } |
| 62 | 63 |
| 63 AudioManagerLinux::AudioManagerLinux() | 64 AudioManagerLinux::AudioManagerLinux() |
| 64 : wrapper_(new AlsaWrapper()) { | 65 : wrapper_(new AlsaWrapper()) |
| 66 #if defined(USE_PULSEAUDIO) | |
|
DaleCurtis
2013/01/30 02:54:30
Construct in #if block inside constructor?
no longer working on chromium
2013/02/12 17:35:59
This code is removed.
| |
| 67 ,pulse_(new PulseInputObject()) | |
| 68 #endif | |
| 69 { | |
| 65 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 70 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| 71 #if defined(USE_PULSEAUDIO) | |
| 72 DVLOG(1) << "The availability of PulseAudio is " << pulse_->has_pulse(); | |
| 73 #endif | |
| 66 } | 74 } |
| 67 | 75 |
| 68 AudioManagerLinux::~AudioManagerLinux() { | 76 AudioManagerLinux::~AudioManagerLinux() { |
| 69 Shutdown(); | 77 Shutdown(); |
| 70 } | 78 } |
| 71 | 79 |
| 72 bool AudioManagerLinux::CanShowAudioInputSettings() { | 80 bool AudioManagerLinux::CanShowAudioInputSettings() { |
| 73 scoped_ptr<base::Environment> env(base::Environment::Create()); | 81 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 74 | 82 |
| 75 switch (base::nix::GetDesktopEnvironment(env.get())) { | 83 switch (base::nix::GetDesktopEnvironment(env.get())) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 } | 120 } |
| 113 | 121 |
| 114 void AudioManagerLinux::GetAudioInputDeviceNames( | 122 void AudioManagerLinux::GetAudioInputDeviceNames( |
| 115 media::AudioDeviceNames* device_names) { | 123 media::AudioDeviceNames* device_names) { |
| 116 DCHECK(device_names->empty()); | 124 DCHECK(device_names->empty()); |
| 117 if (UseCras()) { | 125 if (UseCras()) { |
| 118 GetCrasAudioInputDevices(device_names); | 126 GetCrasAudioInputDevices(device_names); |
| 119 return; | 127 return; |
| 120 } | 128 } |
| 121 | 129 |
| 130 #if defined(USE_PULSEAUDIO) | |
| 131 if (pulse_->has_pulse()) { | |
|
DaleCurtis
2013/01/30 02:54:30
Can this be done a la UseCras; i.e. no need for #i
no longer working on chromium
2013/02/12 17:35:59
Removed.
| |
| 132 pulse_->GetInputDevices(device_names); | |
| 133 return; | |
| 134 } | |
| 135 #endif | |
| 136 | |
| 122 GetAlsaAudioInputDevices(device_names); | 137 GetAlsaAudioInputDevices(device_names); |
| 123 } | 138 } |
| 124 | 139 |
| 125 bool AudioManagerLinux::UseCras() { | 140 bool AudioManagerLinux::UseCras() { |
| 126 #if defined(USE_CRAS) | 141 #if defined(USE_CRAS) |
| 127 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCras)) { | 142 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCras)) { |
| 128 return true; | 143 return true; |
| 129 } | 144 } |
| 130 #endif | 145 #endif |
| 131 return false; | 146 return false; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 AudioOutputStream* AudioManagerLinux::MakeOutputStream( | 313 AudioOutputStream* AudioManagerLinux::MakeOutputStream( |
| 299 const AudioParameters& params) { | 314 const AudioParameters& params) { |
| 300 #if defined(USE_CRAS) | 315 #if defined(USE_CRAS) |
| 301 if (UseCras()) { | 316 if (UseCras()) { |
| 302 return new CrasOutputStream(params, this); | 317 return new CrasOutputStream(params, this); |
| 303 } | 318 } |
| 304 #endif | 319 #endif |
| 305 | 320 |
| 306 #if defined(USE_PULSEAUDIO) | 321 #if defined(USE_PULSEAUDIO) |
| 307 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { | 322 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { |
| 308 return new PulseAudioOutputStream(params, this); | 323 return new PulseAudioOutputStream(params, this); |
|
DaleCurtis
2013/01/30 02:54:30
Indent is wrong.
no longer working on chromium
2013/02/12 17:35:59
Removed.
| |
| 309 } | 324 } |
| 310 #endif | 325 #endif |
| 311 | 326 |
| 312 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; | 327 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; |
| 313 if (CommandLine::ForCurrentProcess()->HasSwitch( | 328 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 314 switches::kAlsaOutputDevice)) { | 329 switches::kAlsaOutputDevice)) { |
| 315 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 330 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 316 switches::kAlsaOutputDevice); | 331 switches::kAlsaOutputDevice); |
| 317 } | 332 } |
| 318 return new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this); | 333 return new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this); |
| 319 } | 334 } |
| 320 | 335 |
| 321 AudioInputStream* AudioManagerLinux::MakeInputStream( | 336 AudioInputStream* AudioManagerLinux::MakeInputStream( |
| 322 const AudioParameters& params, const std::string& device_id) { | 337 const AudioParameters& params, const std::string& device_id) { |
| 323 #if defined(USE_CRAS) | 338 #if defined(USE_CRAS) |
| 324 if (UseCras()) { | 339 if (UseCras()) { |
| 325 return new CrasInputStream(params, this); | 340 return new CrasInputStream(params, this); |
| 326 } | 341 } |
| 327 #endif | 342 #endif |
| 328 | 343 |
| 344 #if defined(USE_PULSEAUDIO) | |
| 345 if (pulse_->has_pulse()) { | |
| 346 return new PulseAudioInputStream(this, device_id, params, | |
| 347 pulse_->mainloop(), pulse_->context()); | |
| 348 } | |
| 349 #endif | |
| 350 | |
| 329 std::string device_name = (device_id == AudioManagerBase::kDefaultDeviceId) ? | 351 std::string device_name = (device_id == AudioManagerBase::kDefaultDeviceId) ? |
| 330 AlsaPcmInputStream::kAutoSelectDevice : device_id; | 352 AlsaPcmInputStream::kAutoSelectDevice : device_id; |
| 331 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { | 353 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { |
| 332 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 354 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 333 switches::kAlsaInputDevice); | 355 switches::kAlsaInputDevice); |
| 334 } | 356 } |
| 335 | 357 |
| 336 return new AlsaPcmInputStream(this, device_name, params, wrapper_.get()); | 358 return new AlsaPcmInputStream(this, device_name, params, wrapper_.get()); |
| 337 } | 359 } |
| 338 | 360 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 352 buffer_size = input_params.frames_per_buffer(); | 374 buffer_size = input_params.frames_per_buffer(); |
| 353 | 375 |
| 354 // TODO(dalecurtis): This should include bits per channel and channel layout | 376 // TODO(dalecurtis): This should include bits per channel and channel layout |
| 355 // eventually. | 377 // eventually. |
| 356 return AudioParameters( | 378 return AudioParameters( |
| 357 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), | 379 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), |
| 358 input_params.sample_rate(), 16, buffer_size); | 380 input_params.sample_rate(), 16, buffer_size); |
| 359 } | 381 } |
| 360 | 382 |
| 361 } // namespace media | 383 } // namespace media |
| OLD | NEW |