• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PULSE_AUDIO_MANAGER_PULSE_H_
6 #define MEDIA_AUDIO_PULSE_AUDIO_MANAGER_PULSE_H_
7 
8 #include <pulse/pulseaudio.h>
9 #include <string>
10 
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "media/audio/audio_manager_base.h"
14 
15 namespace media {
16 
17 class MEDIA_EXPORT AudioManagerPulse : public AudioManagerBase {
18  public:
19   AudioManagerPulse(AudioLogFactory* audio_log_factory);
20   virtual ~AudioManagerPulse();
21 
22   static AudioManager* Create(AudioLogFactory* audio_log_factory);
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) OVERRIDE;
41   virtual AudioInputStream* MakeLinearInputStream(
42       const AudioParameters& params, const std::string& device_id) OVERRIDE;
43   virtual AudioInputStream* MakeLowLatencyInputStream(
44       const AudioParameters& params, const std::string& device_id) OVERRIDE;
45 
46  protected:
47   virtual AudioParameters GetPreferredOutputStreamParameters(
48       const std::string& output_device_id,
49       const AudioParameters& input_params) OVERRIDE;
50 
51  private:
52   bool Init();
53   void DestroyPulse();
54 
55   void GetAudioDeviceNames(bool input, media::AudioDeviceNames* device_names);
56 
57   // Callback to get the devices' info like names, used by GetInputDevices().
58   static void InputDevicesInfoCallback(pa_context* context,
59                                        const pa_source_info* info,
60                                        int error, void* user_data);
61   static void OutputDevicesInfoCallback(pa_context* context,
62                                         const pa_sink_info* info,
63                                         int error, void* user_data);
64 
65   // Callback to get the native sample rate of PulseAudio, used by
66   // GetNativeSampleRate().
67   static void SampleRateInfoCallback(pa_context* context,
68                                      const pa_server_info* info,
69                                      void* user_data);
70 
71   // Called by MakeLinearOutputStream and MakeLowLatencyOutputStream.
72   AudioOutputStream* MakeOutputStream(const AudioParameters& params,
73                                       const std::string& device_id);
74 
75   // Called by MakeLinearInputStream and MakeLowLatencyInputStream.
76   AudioInputStream* MakeInputStream(const AudioParameters& params,
77                                     const std::string& device_id);
78 
79   // Gets the native sample rate of Pulse.
80   int GetNativeSampleRate();
81 
82   pa_threaded_mainloop* input_mainloop_;
83   pa_context* input_context_;
84   AudioDeviceNames* devices_;
85   int native_input_sample_rate_;
86 
87   DISALLOW_COPY_AND_ASSIGN(AudioManagerPulse);
88 };
89 
90 }  // namespace media
91 
92 #endif  // MEDIA_AUDIO_PULSE_AUDIO_MANAGER_PULSE_H_
93