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 void ShowAudioInputSettings() OVERRIDE; | 27 virtual void ShowAudioInputSettings() OVERRIDE; |
26 virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names) | 28 virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names) |
27 OVERRIDE; | 29 OVERRIDE; |
28 | 30 |
29 // Implementation of AudioManagerBase. | 31 // Implementation of AudioManagerBase. |
30 virtual AudioOutputStream* MakeLinearOutputStream( | 32 virtual AudioOutputStream* MakeLinearOutputStream( |
31 const AudioParameters& params) OVERRIDE; | 33 const AudioParameters& params) OVERRIDE; |
32 virtual AudioOutputStream* MakeLowLatencyOutputStream( | 34 virtual AudioOutputStream* MakeLowLatencyOutputStream( |
33 const AudioParameters& params) OVERRIDE; | 35 const AudioParameters& params) OVERRIDE; |
34 virtual AudioInputStream* MakeLinearInputStream( | 36 virtual AudioInputStream* MakeLinearInputStream( |
35 const AudioParameters& params, const std::string& device_id) OVERRIDE; | 37 const AudioParameters& params, const std::string& device_id) OVERRIDE; |
36 virtual AudioInputStream* MakeLowLatencyInputStream( | 38 virtual AudioInputStream* MakeLowLatencyInputStream( |
37 const AudioParameters& params, const std::string& device_id) OVERRIDE; | 39 const AudioParameters& params, const std::string& device_id) OVERRIDE; |
38 virtual AudioParameters GetPreferredLowLatencyOutputStreamParameters( | 40 virtual AudioParameters GetPreferredLowLatencyOutputStreamParameters( |
39 const AudioParameters& input_params) OVERRIDE; | 41 const AudioParameters& input_params) OVERRIDE; |
40 | 42 |
41 protected: | 43 int GetNativeSampleRate(); |
42 virtual ~AudioManagerLinux(); | |
43 | 44 |
44 private: | 45 private: |
45 enum StreamType { | 46 bool Init(); |
46 kStreamPlayback = 0, | 47 void DestroyPulse(); |
47 kStreamCapture, | |
48 }; | |
49 | 48 |
50 // Returns true if cras should be used for input/output. | 49 // Callback to get the devices' info like names, used by GetInputDevices(). |
51 bool UseCras(); | 50 static void DevicesInfoCallback(pa_context* context, |
| 51 const pa_source_info* info, |
| 52 int error, void* user_data); |
52 | 53 |
53 // Gets a list of available cras input devices. | 54 // Callback to get the native sample rate of PulseAudio, used by |
54 void GetCrasAudioInputDevices(media::AudioDeviceNames* device_names); | 55 // GetNativeSampleRate(). |
55 | 56 static void SampleRateInfoCallback(pa_context* context, |
56 // Gets a list of available ALSA input devices. | 57 const pa_server_info* info, |
57 void GetAlsaAudioInputDevices(media::AudioDeviceNames* device_names); | 58 void* user_data); |
58 | |
59 // Gets the ALSA devices' names and ids. | |
60 void GetAlsaDevicesInfo(void** hint, media::AudioDeviceNames* device_names); | |
61 | |
62 // Checks if the specific ALSA device is available. | |
63 bool IsAlsaDeviceAvailable(const char* device_name); | |
64 | |
65 // Returns true if a device is present for the given stream type. | |
66 bool HasAnyAlsaAudioDevice(StreamType stream); | |
67 | 59 |
68 // Called by MakeLinearOutputStream and MakeLowLatencyOutputStream. | 60 // Called by MakeLinearOutputStream and MakeLowLatencyOutputStream. |
69 AudioOutputStream* MakeOutputStream(const AudioParameters& params); | 61 AudioOutputStream* MakeOutputStream(const AudioParameters& params); |
70 | 62 |
71 // Called by MakeLinearInputStream and MakeLowLatencyInputStream. | 63 // Called by MakeLinearInputStream and MakeLowLatencyInputStream. |
72 AudioInputStream* MakeInputStream(const AudioParameters& params, | 64 AudioInputStream* MakeInputStream(const AudioParameters& params, |
73 const std::string& device_id); | 65 const std::string& device_id); |
74 | 66 |
75 scoped_ptr<AlsaWrapper> wrapper_; | 67 pa_threaded_mainloop* input_mainloop_; |
| 68 pa_context* input_context_; |
| 69 AudioDeviceNames* devices_; |
| 70 int native_input_sample_rate_; |
76 | 71 |
77 DISALLOW_COPY_AND_ASSIGN(AudioManagerLinux); | 72 DISALLOW_COPY_AND_ASSIGN(AudioManagerPulse); |
78 }; | 73 }; |
79 | 74 |
80 } // namespace media | 75 } // namespace media |
81 | 76 |
82 #endif // MEDIA_AUDIO_LINUX_AUDIO_MANAGER_LINUX_H_ | 77 #endif // MEDIA_AUDIO_PULSE_AUDIO_MANAGER_PULSE_H_ |
OLD | NEW |