| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/at_exit.h" | |
| 8 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 8 #include "base/logging.h" |
| 10 #include "media/audio/fake_audio_input_stream.h" | 9 #include "media/audio/fake_audio_input_stream.h" |
| 11 #include "media/audio/fake_audio_output_stream.h" | 10 #include "media/audio/fake_audio_output_stream.h" |
| 12 #include "media/audio/linux/alsa_output.h" | 11 #include "media/audio/linux/alsa_output.h" |
| 13 #include "media/audio/linux/alsa_wrapper.h" | 12 #include "media/audio/linux/alsa_wrapper.h" |
| 14 #include "media/base/media_switches.h" | 13 #include "media/base/media_switches.h" |
| 15 | 14 |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 AudioManagerLinux* g_audio_manager = NULL; | |
| 20 } // namespace | |
| 21 | |
| 22 // Implementation of AudioManager. | 15 // Implementation of AudioManager. |
| 23 bool AudioManagerLinux::HasAudioOutputDevices() { | 16 bool AudioManagerLinux::HasAudioOutputDevices() { |
| 24 // TODO(ajwong): Make this actually query audio devices. | 17 // TODO(ajwong): Make this actually query audio devices. |
| 25 return true; | 18 return true; |
| 26 } | 19 } |
| 27 | 20 |
| 28 bool AudioManagerLinux::HasAudioInputDevices() { | 21 bool AudioManagerLinux::HasAudioInputDevices() { |
| 29 // TODO(satish): implement. | 22 // TODO(satish): implement. |
| 30 return false; | 23 return false; |
| 31 } | 24 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 49 Format format, | 42 Format format, |
| 50 int channels, | 43 int channels, |
| 51 int sample_rate, | 44 int sample_rate, |
| 52 char bits_per_sample) { | 45 char bits_per_sample) { |
| 53 // Early return for testing hook. Do this before checking for | 46 // Early return for testing hook. Do this before checking for |
| 54 // |initialized_|. | 47 // |initialized_|. |
| 55 if (format == AudioManager::AUDIO_MOCK) { | 48 if (format == AudioManager::AUDIO_MOCK) { |
| 56 return FakeAudioOutputStream::MakeFakeStream(); | 49 return FakeAudioOutputStream::MakeFakeStream(); |
| 57 } | 50 } |
| 58 | 51 |
| 59 if (!initialized_) { | 52 if (!initialized()) { |
| 60 return NULL; | 53 return NULL; |
| 61 } | 54 } |
| 62 | 55 |
| 63 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; | 56 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; |
| 64 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaDevice)) { | 57 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaDevice)) { |
| 65 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 58 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 66 switches::kAlsaDevice); | 59 switches::kAlsaDevice); |
| 67 } | 60 } |
| 68 AlsaPcmOutputStream* stream = | 61 AlsaPcmOutputStream* stream = |
| 69 new AlsaPcmOutputStream(device_name, format, channels, sample_rate, | 62 new AlsaPcmOutputStream(device_name, format, channels, sample_rate, |
| 70 bits_per_sample, wrapper_.get(), this, | 63 bits_per_sample, wrapper_.get(), this, |
| 71 audio_thread_.message_loop()); | 64 GetMessageLoop()); |
| 72 | 65 |
| 73 AutoLock l(lock_); | 66 AutoLock l(lock_); |
| 74 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream); | 67 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream); |
| 75 return stream; | 68 return stream; |
| 76 } | 69 } |
| 77 | 70 |
| 78 AudioManagerLinux::AudioManagerLinux() | 71 AudioManagerLinux::AudioManagerLinux() { |
| 79 : audio_thread_("AudioThread"), | |
| 80 initialized_(false) { | |
| 81 } | 72 } |
| 82 | 73 |
| 83 AudioManagerLinux::~AudioManagerLinux() { | 74 AudioManagerLinux::~AudioManagerLinux() { |
| 84 // Make sure we stop the thread first. If we let the default destructor to | 75 // Make sure we stop the thread first. If we let the default destructor to |
| 85 // destruct the members, we may destroy audio streams before stopping the | 76 // destruct the members, we may destroy audio streams before stopping the |
| 86 // thread, resulting an unexpected behavior. | 77 // thread, resulting an unexpected behavior. |
| 87 // This way we make sure activities of the audio streams are all stopped | 78 // This way we make sure activities of the audio streams are all stopped |
| 88 // before we destroy them. | 79 // before we destroy them. |
| 89 audio_thread_.Stop(); | 80 audio_thread_.Stop(); |
| 90 active_streams_.clear(); | 81 active_streams_.clear(); |
| 91 } | 82 } |
| 92 | 83 |
| 93 void AudioManagerLinux::Init() { | 84 void AudioManagerLinux::Init() { |
| 94 initialized_ = audio_thread_.Start(); | 85 AudioManagerBase::Init(); |
| 95 wrapper_.reset(new AlsaWrapper()); | 86 wrapper_.reset(new AlsaWrapper()); |
| 96 } | 87 } |
| 97 | 88 |
| 98 void AudioManagerLinux::MuteAll() { | 89 void AudioManagerLinux::MuteAll() { |
| 99 NOTIMPLEMENTED(); | 90 NOTIMPLEMENTED(); |
| 100 } | 91 } |
| 101 | 92 |
| 102 void AudioManagerLinux::UnMuteAll() { | 93 void AudioManagerLinux::UnMuteAll() { |
| 103 NOTIMPLEMENTED(); | 94 NOTIMPLEMENTED(); |
| 104 } | 95 } |
| 105 | 96 |
| 106 void AudioManagerLinux::ReleaseOutputStream(AlsaPcmOutputStream* stream) { | 97 void AudioManagerLinux::ReleaseOutputStream(AlsaPcmOutputStream* stream) { |
| 107 if (stream) { | 98 if (stream) { |
| 108 AutoLock l(lock_); | 99 AutoLock l(lock_); |
| 109 active_streams_.erase(stream); | 100 active_streams_.erase(stream); |
| 110 } | 101 } |
| 111 } | 102 } |
| 112 | 103 |
| 113 // TODO(ajwong): Collapse this with the windows version. | 104 // static |
| 114 void DestroyAudioManagerLinux(void* not_used) { | 105 AudioManager* AudioManager::CreateAudioManager() { |
| 115 delete g_audio_manager; | 106 return new AudioManagerLinux(); |
| 116 g_audio_manager = NULL; | |
| 117 } | 107 } |
| 118 | |
| 119 AudioManager* AudioManager::GetAudioManager() { | |
| 120 if (!g_audio_manager) { | |
| 121 g_audio_manager = new AudioManagerLinux(); | |
| 122 g_audio_manager->Init(); | |
| 123 base::AtExitManager::RegisterCallback(&DestroyAudioManagerLinux, NULL); | |
| 124 } | |
| 125 return g_audio_manager; | |
| 126 } | |
| OLD | NEW |