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