1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_AUDIO_ALSA_AUDIO_MANAGER_ALSA_H_ 6 #define MEDIA_AUDIO_ALSA_AUDIO_MANAGER_ALSA_H_ 7 8 #include <string> 9 #include "base/compiler_specific.h" 10 #include "base/memory/ref_counted.h" 11 #include "base/threading/thread.h" 12 #include "media/audio/audio_manager_base.h" 13 14 namespace media { 15 16 class AlsaWrapper; 17 18 class MEDIA_EXPORT AudioManagerAlsa : public AudioManagerBase { 19 public: 20 AudioManagerAlsa(AudioLogFactory* audio_log_factory); 21 22 static void ShowLinuxAudioInputSettings(); 23 24 // Implementation of AudioManager. 25 virtual bool HasAudioOutputDevices() OVERRIDE; 26 virtual bool HasAudioInputDevices() OVERRIDE; 27 virtual void ShowAudioInputSettings() OVERRIDE; 28 virtual void GetAudioInputDeviceNames( 29 AudioDeviceNames* device_names) OVERRIDE; 30 virtual void GetAudioOutputDeviceNames( 31 AudioDeviceNames* device_names) OVERRIDE; 32 virtual AudioParameters GetInputStreamParameters( 33 const std::string& device_id) OVERRIDE; 34 35 // Implementation of AudioManagerBase. 36 virtual AudioOutputStream* MakeLinearOutputStream( 37 const AudioParameters& params) OVERRIDE; 38 virtual AudioOutputStream* MakeLowLatencyOutputStream( 39 const AudioParameters& params, 40 const std::string& device_id, 41 const std::string& input_device_id) OVERRIDE; 42 virtual AudioInputStream* MakeLinearInputStream( 43 const AudioParameters& params, const std::string& device_id) OVERRIDE; 44 virtual AudioInputStream* MakeLowLatencyInputStream( 45 const AudioParameters& params, const std::string& device_id) OVERRIDE; 46 47 protected: 48 virtual ~AudioManagerAlsa(); 49 50 virtual AudioParameters GetPreferredOutputStreamParameters( 51 const std::string& output_device_id, 52 const AudioParameters& input_params) OVERRIDE; 53 54 private: 55 enum StreamType { 56 kStreamPlayback = 0, 57 kStreamCapture, 58 }; 59 60 // Gets a list of available ALSA devices. 61 void GetAlsaAudioDevices(StreamType type, 62 media::AudioDeviceNames* device_names); 63 64 // Gets the ALSA devices' names and ids that support streams of the 65 // given type. 66 void GetAlsaDevicesInfo(StreamType type, 67 void** hint, 68 media::AudioDeviceNames* device_names); 69 70 // Checks if the specific ALSA device is available. 71 static bool IsAlsaDeviceAvailable(StreamType type, 72 const char* device_name); 73 74 static const char* UnwantedDeviceTypeWhenEnumerating( 75 StreamType wanted_type); 76 77 // Returns true if a device is present for the given stream type. 78 bool HasAnyAlsaAudioDevice(StreamType stream); 79 80 // Called by MakeLinearOutputStream and MakeLowLatencyOutputStream. 81 AudioOutputStream* MakeOutputStream(const AudioParameters& params); 82 83 // Called by MakeLinearInputStream and MakeLowLatencyInputStream. 84 AudioInputStream* MakeInputStream(const AudioParameters& params, 85 const std::string& device_id); 86 87 scoped_ptr<AlsaWrapper> wrapper_; 88 89 DISALLOW_COPY_AND_ASSIGN(AudioManagerAlsa); 90 }; 91 92 } // namespace media 93 94 #endif // MEDIA_AUDIO_ALSA_AUDIO_MANAGER_ALSA_H_ 95