| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "media/audio/fake_audio_output_stream.h" | 10 #include "media/audio/fake_audio_output_stream.h" |
| 10 #include "media/audio/linux/alsa_output.h" | 11 #include "media/audio/linux/alsa_output.h" |
| 11 #include "media/audio/linux/alsa_wrapper.h" | 12 #include "media/audio/linux/alsa_wrapper.h" |
| 13 #include "media/base/media_switches.h" |
| 14 |
| 12 | 15 |
| 13 namespace { | 16 namespace { |
| 14 AudioManagerLinux* g_audio_manager = NULL; | 17 AudioManagerLinux* g_audio_manager = NULL; |
| 15 } // namespace | 18 } // namespace |
| 16 | 19 |
| 17 // Implementation of AudioManager. | 20 // Implementation of AudioManager. |
| 18 bool AudioManagerLinux::HasAudioDevices() { | 21 bool AudioManagerLinux::HasAudioDevices() { |
| 19 // TODO(ajwong): Make this actually query audio devices. | 22 // TODO(ajwong): Make this actually query audio devices. |
| 20 return true; | 23 return true; |
| 21 } | 24 } |
| 22 | 25 |
| 23 AudioOutputStream* AudioManagerLinux::MakeAudioStream(Format format, | 26 AudioOutputStream* AudioManagerLinux::MakeAudioStream(Format format, |
| 24 int channels, | 27 int channels, |
| 25 int sample_rate, | 28 int sample_rate, |
| 26 char bits_per_sample) { | 29 char bits_per_sample) { |
| 27 // Early return for testing hook. Do this before checking for | 30 // Early return for testing hook. Do this before checking for |
| 28 // |initialized_|. | 31 // |initialized_|. |
| 29 if (format == AudioManager::AUDIO_MOCK) { | 32 if (format == AudioManager::AUDIO_MOCK) { |
| 30 return FakeAudioOutputStream::MakeFakeStream(); | 33 return FakeAudioOutputStream::MakeFakeStream(); |
| 31 } | 34 } |
| 32 | 35 |
| 33 if (!initialized_) { | 36 if (!initialized_) { |
| 34 return NULL; | 37 return NULL; |
| 35 } | 38 } |
| 36 | 39 |
| 37 // TODO(ajwong): Do we want to be able to configure the device? default | 40 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; |
| 38 // should work correctly for all mono/stereo, but not surround, which needs | 41 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaDevice)) { |
| 39 // surround40, surround51, etc. | 42 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 40 // | 43 switches::kAlsaDevice); |
| 41 // http://0pointer.de/blog/projects/guide-to-sound-apis.html | 44 } |
| 42 AlsaPcmOutputStream* stream = | 45 AlsaPcmOutputStream* stream = |
| 43 new AlsaPcmOutputStream(AlsaPcmOutputStream::kDefaultDevice, | 46 new AlsaPcmOutputStream(device_name, format, channels, sample_rate, |
| 44 format, channels, sample_rate, bits_per_sample, | 47 bits_per_sample, wrapper_.get(), this, |
| 45 wrapper_.get(), this, | |
| 46 audio_thread_.message_loop()); | 48 audio_thread_.message_loop()); |
| 47 | 49 |
| 48 AutoLock l(lock_); | 50 AutoLock l(lock_); |
| 49 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream); | 51 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream); |
| 50 return stream; | 52 return stream; |
| 51 } | 53 } |
| 52 | 54 |
| 53 AudioManagerLinux::AudioManagerLinux() | 55 AudioManagerLinux::AudioManagerLinux() |
| 54 : audio_thread_("AudioThread"), | 56 : audio_thread_("AudioThread"), |
| 55 initialized_(false) { | 57 initialized_(false) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 84 } | 86 } |
| 85 | 87 |
| 86 AudioManager* AudioManager::GetAudioManager() { | 88 AudioManager* AudioManager::GetAudioManager() { |
| 87 if (!g_audio_manager) { | 89 if (!g_audio_manager) { |
| 88 g_audio_manager = new AudioManagerLinux(); | 90 g_audio_manager = new AudioManagerLinux(); |
| 89 g_audio_manager->Init(); | 91 g_audio_manager->Init(); |
| 90 base::AtExitManager::RegisterCallback(&DestroyAudioManagerLinux, NULL); | 92 base::AtExitManager::RegisterCallback(&DestroyAudioManagerLinux, NULL); |
| 91 } | 93 } |
| 92 return g_audio_manager; | 94 return g_audio_manager; |
| 93 } | 95 } |
| OLD | NEW |