| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef MEDIA_AUDIO_LINUX_AUDIO_MANAGER_LINUX_H_ | 5 #ifndef MEDIA_AUDIO_PULSE_AUDIO_MANAGER_PULSE_H_ |
| 6 #define MEDIA_AUDIO_LINUX_AUDIO_MANAGER_LINUX_H_ | 6 #define MEDIA_AUDIO_PULSE_AUDIO_MANAGER_PULSE_H_ |
| 7 | 7 |
| 8 #include <pulse/pulseaudio.h> |
| 8 #include <string> | 9 #include <string> |
| 10 |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/threading/thread.h" | |
| 12 #include "media/audio/audio_manager_base.h" | 13 #include "media/audio/audio_manager_base.h" |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 | 16 |
| 16 class AlsaWrapper; | 17 class MEDIA_EXPORT AudioManagerPulse : public AudioManagerBase { |
| 18 public: |
| 19 AudioManagerPulse(); |
| 20 virtual ~AudioManagerPulse(); |
| 17 | 21 |
| 18 class MEDIA_EXPORT AudioManagerLinux : public AudioManagerBase { | 22 static AudioManager* Create(); |
| 19 public: | |
| 20 AudioManagerLinux(); | |
| 21 | 23 |
| 22 // Implementation of AudioManager. | 24 // Implementation of AudioManager. |
| 23 virtual bool HasAudioOutputDevices() OVERRIDE; | 25 virtual bool HasAudioOutputDevices() OVERRIDE; |
| 24 virtual bool HasAudioInputDevices() OVERRIDE; | 26 virtual bool HasAudioInputDevices() OVERRIDE; |
| 25 virtual bool CanShowAudioInputSettings() OVERRIDE; | 27 virtual bool CanShowAudioInputSettings() OVERRIDE; |
| 26 virtual void ShowAudioInputSettings() OVERRIDE; | 28 virtual void ShowAudioInputSettings() OVERRIDE; |
| 27 virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names) | 29 virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names) |
| 28 OVERRIDE; | 30 OVERRIDE; |
| 29 | 31 |
| 30 // Implementation of AudioManagerBase. | 32 // Implementation of AudioManagerBase. |
| 31 virtual AudioOutputStream* MakeLinearOutputStream( | 33 virtual AudioOutputStream* MakeLinearOutputStream( |
| 32 const AudioParameters& params) OVERRIDE; | 34 const AudioParameters& params) OVERRIDE; |
| 33 virtual AudioOutputStream* MakeLowLatencyOutputStream( | 35 virtual AudioOutputStream* MakeLowLatencyOutputStream( |
| 34 const AudioParameters& params) OVERRIDE; | 36 const AudioParameters& params) OVERRIDE; |
| 35 virtual AudioInputStream* MakeLinearInputStream( | 37 virtual AudioInputStream* MakeLinearInputStream( |
| 36 const AudioParameters& params, const std::string& device_id) OVERRIDE; | 38 const AudioParameters& params, const std::string& device_id) OVERRIDE; |
| 37 virtual AudioInputStream* MakeLowLatencyInputStream( | 39 virtual AudioInputStream* MakeLowLatencyInputStream( |
| 38 const AudioParameters& params, const std::string& device_id) OVERRIDE; | 40 const AudioParameters& params, const std::string& device_id) OVERRIDE; |
| 39 virtual AudioParameters GetPreferredLowLatencyOutputStreamParameters( | 41 virtual AudioParameters GetPreferredLowLatencyOutputStreamParameters( |
| 40 const AudioParameters& input_params) OVERRIDE; | 42 const AudioParameters& input_params) OVERRIDE; |
| 41 | 43 |
| 42 protected: | 44 int GetNativeSampleRate(); |
| 43 virtual ~AudioManagerLinux(); | |
| 44 | 45 |
| 45 private: | 46 private: |
| 46 enum StreamType { | 47 bool Init(); |
| 47 kStreamPlayback = 0, | 48 void Terminate(); |
| 48 kStreamCapture, | |
| 49 }; | |
| 50 | 49 |
| 51 // Returns true if cras should be used for input/output. | 50 // Callback to get the devices' info like names, used by GetInputDevices(). |
| 52 bool UseCras(); | 51 static void DevicesInfoCallback(pa_context* context, |
| 52 const pa_source_info* info, |
| 53 int error, void* user_data); |
| 53 | 54 |
| 54 // Gets a list of available cras input devices. | 55 // Callback to get the native sample rate of PulseAudio, used by |
| 55 void GetCrasAudioInputDevices(media::AudioDeviceNames* device_names); | 56 // GetNativeSampleRate(). |
| 56 | 57 static void SamplerateInfoCallback(pa_context* context, |
| 57 // Gets a list of available ALSA input devices. | 58 const pa_server_info* info, |
| 58 void GetAlsaAudioInputDevices(media::AudioDeviceNames* device_names); | 59 void* user_data); |
| 59 | |
| 60 // Gets the ALSA devices' names and ids. | |
| 61 void GetAlsaDevicesInfo(void** hint, media::AudioDeviceNames* device_names); | |
| 62 | |
| 63 // Checks if the specific ALSA device is available. | |
| 64 bool IsAlsaDeviceAvailable(const char* device_name); | |
| 65 | |
| 66 // Returns true if a device is present for the given stream type. | |
| 67 bool HasAnyAlsaAudioDevice(StreamType stream); | |
| 68 | 60 |
| 69 // Called by MakeLinearOutputStream and MakeLowLatencyOutputStream. | 61 // Called by MakeLinearOutputStream and MakeLowLatencyOutputStream. |
| 70 AudioOutputStream* MakeOutputStream(const AudioParameters& params); | 62 AudioOutputStream* MakeOutputStream(const AudioParameters& params); |
| 71 | 63 |
| 72 // Called by MakeLinearInputStream and MakeLowLatencyInputStream. | 64 // Called by MakeLinearInputStream and MakeLowLatencyInputStream. |
| 73 AudioInputStream* MakeInputStream(const AudioParameters& params, | 65 AudioInputStream* MakeInputStream(const AudioParameters& params, |
| 74 const std::string& device_id); | 66 const std::string& device_id); |
| 75 | 67 |
| 76 scoped_ptr<AlsaWrapper> wrapper_; | 68 pa_threaded_mainloop* input_mainloop_; |
| 69 pa_context* input_context_; |
| 70 AudioDeviceNames* devices_; |
| 71 int native_input_sample_rate_; |
| 77 | 72 |
| 78 DISALLOW_COPY_AND_ASSIGN(AudioManagerLinux); | 73 DISALLOW_COPY_AND_ASSIGN(AudioManagerPulse); |
| 79 }; | 74 }; |
| 80 | 75 |
| 81 } // namespace media | 76 } // namespace media |
| 82 | 77 |
| 83 #endif // MEDIA_AUDIO_LINUX_AUDIO_MANAGER_LINUX_H_ | 78 #endif // MEDIA_AUDIO_PULSE_AUDIO_MANAGER_PULSE_H_ |
| OLD | NEW |