OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/fake_audio_input_stream.h" | 14 #include "media/audio/fake_audio_input_stream.h" |
15 #include "media/audio/fake_audio_output_stream.h" | 15 #include "media/audio/fake_audio_output_stream.h" |
16 #include "media/audio/linux/alsa_input.h" | 16 #include "media/audio/linux/alsa_input.h" |
17 #include "media/audio/linux/alsa_output.h" | 17 #include "media/audio/linux/alsa_output.h" |
18 #include "media/audio/linux/alsa_wrapper.h" | 18 #include "media/audio/linux/alsa_wrapper.h" |
| 19 #include "media/audio/linux/pulse_output.h" |
19 #include "media/base/limits.h" | 20 #include "media/base/limits.h" |
20 #include "media/base/media_switches.h" | 21 #include "media/base/media_switches.h" |
21 | 22 |
22 // Maximum number of output streams that can be open simultaneously. | 23 // Maximum number of output streams that can be open simultaneously. |
23 static const size_t kMaxOutputStreams = 50; | 24 static const size_t kMaxOutputStreams = 50; |
24 | 25 |
25 static const int kMaxInputChannels = 2; | 26 static const int kMaxInputChannels = 2; |
26 | 27 |
27 // Since "default", "pulse" and "dmix" devices are virtual devices mapped to | 28 // Since "default", "pulse" and "dmix" devices are virtual devices mapped to |
28 // real devices, we remove them from the list to avoiding duplicate counting. | 29 // real devices, we remove them from the list to avoiding duplicate counting. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 93 |
93 if (!initialized()) { | 94 if (!initialized()) { |
94 return NULL; | 95 return NULL; |
95 } | 96 } |
96 | 97 |
97 // Don't allow opening more than |kMaxOutputStreams| streams. | 98 // Don't allow opening more than |kMaxOutputStreams| streams. |
98 if (active_streams_.size() >= kMaxOutputStreams) { | 99 if (active_streams_.size() >= kMaxOutputStreams) { |
99 return NULL; | 100 return NULL; |
100 } | 101 } |
101 | 102 |
102 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; | 103 AudioOutputStream* stream; |
103 if (CommandLine::ForCurrentProcess()->HasSwitch( | 104 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { |
104 switches::kAlsaOutputDevice)) { | 105 stream = new PulseAudioOutputStream(params, this); |
105 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 106 } else { |
106 switches::kAlsaOutputDevice); | 107 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; |
| 108 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 109 switches::kAlsaOutputDevice)) { |
| 110 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 111 switches::kAlsaOutputDevice); |
| 112 } |
| 113 stream = new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this, |
| 114 GetMessageLoop()); |
107 } | 115 } |
108 AlsaPcmOutputStream* stream = | |
109 new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this, | |
110 GetMessageLoop()); | |
111 active_streams_.insert(stream); | 116 active_streams_.insert(stream); |
112 return stream; | 117 return stream; |
113 } | 118 } |
114 | 119 |
115 AudioInputStream* AudioManagerLinux::MakeAudioInputStream( | 120 AudioInputStream* AudioManagerLinux::MakeAudioInputStream( |
116 const AudioParameters& params) { | 121 const AudioParameters& params) { |
117 if (!params.IsValid() || params.channels > kMaxInputChannels) | 122 if (!params.IsValid() || params.channels > kMaxInputChannels) |
118 return NULL; | 123 return NULL; |
119 | 124 |
120 if (params.format == AudioParameters::AUDIO_MOCK) { | 125 if (params.format == AudioParameters::AUDIO_MOCK) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 168 } |
164 | 169 |
165 void AudioManagerLinux::MuteAll() { | 170 void AudioManagerLinux::MuteAll() { |
166 NOTIMPLEMENTED(); | 171 NOTIMPLEMENTED(); |
167 } | 172 } |
168 | 173 |
169 void AudioManagerLinux::UnMuteAll() { | 174 void AudioManagerLinux::UnMuteAll() { |
170 NOTIMPLEMENTED(); | 175 NOTIMPLEMENTED(); |
171 } | 176 } |
172 | 177 |
173 void AudioManagerLinux::ReleaseOutputStream(AlsaPcmOutputStream* stream) { | 178 void AudioManagerLinux::ReleaseOutputStream(AudioOutputStream* stream) { |
174 if (stream) { | 179 if (stream) { |
175 active_streams_.erase(stream); | 180 active_streams_.erase(stream); |
176 delete stream; | 181 delete stream; |
177 } | 182 } |
178 } | 183 } |
179 | 184 |
180 bool AudioManagerLinux::CanShowAudioInputSettings() { | 185 bool AudioManagerLinux::CanShowAudioInputSettings() { |
181 scoped_ptr<base::Environment> env(base::Environment::Create()); | 186 scoped_ptr<base::Environment> env(base::Environment::Create()); |
182 base::nix::DesktopEnvironment desktop = base::nix::GetDesktopEnvironment( | 187 base::nix::DesktopEnvironment desktop = base::nix::GetDesktopEnvironment( |
183 env.get()); | 188 env.get()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return true; | 234 return true; |
230 } | 235 } |
231 | 236 |
232 return false; | 237 return false; |
233 } | 238 } |
234 | 239 |
235 // static | 240 // static |
236 AudioManager* AudioManager::CreateAudioManager() { | 241 AudioManager* AudioManager::CreateAudioManager() { |
237 return new AudioManagerLinux(); | 242 return new AudioManagerLinux(); |
238 } | 243 } |
OLD | NEW |