1 // Copyright (c) 2012 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.
5 #ifndef MEDIA_AUDIO_PULSE_PULSE_INPUT_H_
6 #define MEDIA_AUDIO_PULSE_PULSE_INPUT_H_
8 #include <pulse/pulseaudio.h>
11 #include "base/threading/thread_checker.h"
12 #include "media/audio/agc_audio_stream.h"
13 #include "media/audio/audio_device_name.h"
14 #include "media/audio/audio_io.h"
15 #include "media/audio/audio_parameters.h"
16 #include "media/base/audio_block_fifo.h"
20 class AudioManagerPulse
;
22 class PulseAudioInputStream
: public AgcAudioStream
<AudioInputStream
> {
24 PulseAudioInputStream(AudioManagerPulse
* audio_manager
,
25 const std::string
& device_name
,
26 const AudioParameters
& params
,
27 pa_threaded_mainloop
* mainloop
,
30 ~PulseAudioInputStream() override
;
32 // Implementation of AudioInputStream.
34 void Start(AudioInputCallback
* callback
) override
;
36 void Close() override
;
37 double GetMaxVolume() override
;
38 void SetVolume(double volume
) override
;
39 double GetVolume() override
;
40 bool IsMuted() override
;
43 // PulseAudio Callbacks.
44 static void ReadCallback(pa_stream
* handle
, size_t length
, void* user_data
);
45 static void StreamNotifyCallback(pa_stream
* stream
, void* user_data
);
46 static void VolumeCallback(pa_context
* context
, const pa_source_info
* info
,
47 int error
, void* user_data
);
48 static void MuteCallback(pa_context
* context
,
49 const pa_source_info
* info
,
53 // Helper for the ReadCallback.
56 // Utility method used by GetVolume() and IsMuted().
57 bool GetSourceInformation(pa_source_info_cb_t callback
);
59 AudioManagerPulse
* audio_manager_
;
60 AudioInputCallback
* callback_
;
61 std::string device_name_
;
62 AudioParameters params_
;
67 // Set to true in IsMuted() if user has muted the selected microphone in the
71 // Holds the data from the OS.
74 // PulseAudio API structs.
75 pa_threaded_mainloop
* pa_mainloop_
; // Weak.
76 pa_context
* pa_context_
; // Weak.
79 base::ThreadChecker thread_checker_
;
81 DISALLOW_COPY_AND_ASSIGN(PulseAudioInputStream
);
86 #endif // MEDIA_AUDIO_PULSE_PULSE_INPUT_H_