| 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-inl.h" |
| 12 #include "media/audio/audio_output_dispatcher.h" | 13 #include "media/audio/audio_output_dispatcher.h" |
| 13 #include "media/audio/fake_audio_input_stream.h" | 14 #include "media/audio/fake_audio_input_stream.h" |
| 14 #include "media/audio/fake_audio_output_stream.h" | 15 #include "media/audio/fake_audio_output_stream.h" |
| 15 #include "media/audio/linux/alsa_input.h" | 16 #include "media/audio/linux/alsa_input.h" |
| 16 #include "media/audio/linux/alsa_output.h" | 17 #include "media/audio/linux/alsa_output.h" |
| 17 #include "media/audio/linux/alsa_wrapper.h" | 18 #include "media/audio/linux/alsa_wrapper.h" |
| 18 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
| 19 #include "media/base/media_switches.h" | 20 #include "media/base/media_switches.h" |
| 20 | 21 |
| 21 // Maximum number of output streams that can be open simultaneously. | 22 // Maximum number of output streams that can be open simultaneously. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 101 |
| 101 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; | 102 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; |
| 102 if (CommandLine::ForCurrentProcess()->HasSwitch( | 103 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 103 switches::kAlsaOutputDevice)) { | 104 switches::kAlsaOutputDevice)) { |
| 104 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 105 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 105 switches::kAlsaOutputDevice); | 106 switches::kAlsaOutputDevice); |
| 106 } | 107 } |
| 107 AlsaPcmOutputStream* stream = | 108 AlsaPcmOutputStream* stream = |
| 108 new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this, | 109 new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this, |
| 109 GetMessageLoop()); | 110 GetMessageLoop()); |
| 110 | 111 active_streams_.insert(stream); |
| 111 base::AutoLock l(lock_); | |
| 112 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream); | |
| 113 return stream; | 112 return stream; |
| 114 } | 113 } |
| 115 | 114 |
| 116 AudioInputStream* AudioManagerLinux::MakeAudioInputStream( | 115 AudioInputStream* AudioManagerLinux::MakeAudioInputStream( |
| 117 AudioParameters params) { | 116 AudioParameters params) { |
| 118 if (!params.IsValid() || params.channels > kMaxInputChannels) | 117 if (!params.IsValid() || params.channels > kMaxInputChannels) |
| 119 return NULL; | 118 return NULL; |
| 120 | 119 |
| 121 if (params.format == AudioParameters::AUDIO_MOCK) { | 120 if (params.format == AudioParameters::AUDIO_MOCK) { |
| 122 return FakeAudioInputStream::MakeFakeStream(params); | 121 return FakeAudioInputStream::MakeFakeStream(params); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 146 // Make sure we stop the thread first. If we allow the default destructor to | 145 // Make sure we stop the thread first. If we allow the default destructor to |
| 147 // destroy the members, we may destroy audio streams before stopping the | 146 // destroy the members, we may destroy audio streams before stopping the |
| 148 // thread, resulting an unexpected behavior. | 147 // thread, resulting an unexpected behavior. |
| 149 // This way we make sure activities of the audio streams are all stopped | 148 // This way we make sure activities of the audio streams are all stopped |
| 150 // before we destroy them. | 149 // before we destroy them. |
| 151 audio_thread_.Stop(); | 150 audio_thread_.Stop(); |
| 152 | 151 |
| 153 // Free output dispatchers, closing all remaining open streams. | 152 // Free output dispatchers, closing all remaining open streams. |
| 154 output_dispatchers_.clear(); | 153 output_dispatchers_.clear(); |
| 155 | 154 |
| 156 active_streams_.clear(); | 155 // Delete all the streams. Have to do it manually, we don't have ScopedSet<>, |
| 156 // and we are not using ScopedVector<> because search there is slow. |
| 157 STLDeleteElements(&active_streams_); |
| 157 } | 158 } |
| 158 | 159 |
| 159 void AudioManagerLinux::Init() { | 160 void AudioManagerLinux::Init() { |
| 160 AudioManagerBase::Init(); | 161 AudioManagerBase::Init(); |
| 161 wrapper_.reset(new AlsaWrapper()); | 162 wrapper_.reset(new AlsaWrapper()); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void AudioManagerLinux::MuteAll() { | 165 void AudioManagerLinux::MuteAll() { |
| 165 NOTIMPLEMENTED(); | 166 NOTIMPLEMENTED(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void AudioManagerLinux::UnMuteAll() { | 169 void AudioManagerLinux::UnMuteAll() { |
| 169 NOTIMPLEMENTED(); | 170 NOTIMPLEMENTED(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 void AudioManagerLinux::ReleaseOutputStream(AlsaPcmOutputStream* stream) { | 173 void AudioManagerLinux::ReleaseOutputStream(AlsaPcmOutputStream* stream) { |
| 173 if (stream) { | 174 if (stream) { |
| 174 base::AutoLock l(lock_); | |
| 175 active_streams_.erase(stream); | 175 active_streams_.erase(stream); |
| 176 delete stream; |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 | 179 |
| 179 bool AudioManagerLinux::CanShowAudioInputSettings() { | 180 bool AudioManagerLinux::CanShowAudioInputSettings() { |
| 180 scoped_ptr<base::Environment> env(base::Environment::Create()); | 181 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 181 base::nix::DesktopEnvironment desktop = base::nix::GetDesktopEnvironment( | 182 base::nix::DesktopEnvironment desktop = base::nix::GetDesktopEnvironment( |
| 182 env.get()); | 183 env.get()); |
| 183 return (desktop == base::nix::DESKTOP_ENVIRONMENT_GNOME || | 184 return (desktop == base::nix::DESKTOP_ENVIRONMENT_GNOME || |
| 184 desktop == base::nix::DESKTOP_ENVIRONMENT_KDE3 || | 185 desktop == base::nix::DESKTOP_ENVIRONMENT_KDE3 || |
| 185 desktop == base::nix::DESKTOP_ENVIRONMENT_KDE4); | 186 desktop == base::nix::DESKTOP_ENVIRONMENT_KDE4); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return true; | 228 return true; |
| 228 } | 229 } |
| 229 | 230 |
| 230 return false; | 231 return false; |
| 231 } | 232 } |
| 232 | 233 |
| 233 // static | 234 // static |
| 234 AudioManager* AudioManager::CreateAudioManager() { | 235 AudioManager* AudioManager::CreateAudioManager() { |
| 235 return new AudioManagerLinux(); | 236 return new AudioManagerLinux(); |
| 236 } | 237 } |
| OLD | NEW |