Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / audio / pulse / pulse_input.h
blobb21655b2fde506900aab094f6a023be83a2ea8aa
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>
9 #include <string>
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"
18 namespace media {
20 class AudioManagerPulse;
22 class PulseAudioInputStream : public AgcAudioStream<AudioInputStream> {
23 public:
24 PulseAudioInputStream(AudioManagerPulse* audio_manager,
25 const std::string& device_name,
26 const AudioParameters& params,
27 pa_threaded_mainloop* mainloop,
28 pa_context* context);
30 ~PulseAudioInputStream() override;
32 // Implementation of AudioInputStream.
33 bool Open() override;
34 void Start(AudioInputCallback* callback) override;
35 void Stop() override;
36 void Close() override;
37 double GetMaxVolume() override;
38 void SetVolume(double volume) override;
39 double GetVolume() override;
40 bool IsMuted() override;
42 private:
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,
50 int error,
51 void* user_data);
53 // Helper for the ReadCallback.
54 void ReadData();
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_;
63 int channels_;
64 double volume_;
65 bool stream_started_;
67 // Set to true in IsMuted() if user has muted the selected microphone in the
68 // sound settings UI.
69 bool muted_;
71 // Holds the data from the OS.
72 AudioBlockFifo fifo_;
74 // PulseAudio API structs.
75 pa_threaded_mainloop* pa_mainloop_; // Weak.
76 pa_context* pa_context_; // Weak.
77 pa_stream* handle_;
79 base::ThreadChecker thread_checker_;
81 DISALLOW_COPY_AND_ASSIGN(PulseAudioInputStream);
84 } // namespace media
86 #endif // MEDIA_AUDIO_PULSE_PULSE_INPUT_H_