| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_PULSE_PULSE_INPUT_H_ | 5 #ifndef MEDIA_AUDIO_PULSE_PULSE_INPUT_H_ |
| 6 #define MEDIA_AUDIO_PULSE_PULSE_INPUT_H_ | 6 #define MEDIA_AUDIO_PULSE_PULSE_INPUT_H_ |
| 7 | 7 |
| 8 #include <pulse/pulseaudio.h> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 11 #include "media/audio/agc_audio_stream.h" | 12 #include "media/audio/agc_audio_stream.h" |
| 12 #include "media/audio/audio_device_name.h" | 13 #include "media/audio/audio_device_name.h" |
| 13 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
| 15 #include "media/base/audio_block_fifo.h" | 16 #include "media/base/audio_block_fifo.h" |
| 16 | 17 |
| 17 struct pa_context; | |
| 18 struct pa_source_info; | |
| 19 struct pa_stream; | |
| 20 struct pa_threaded_mainloop; | |
| 21 | |
| 22 namespace media { | 18 namespace media { |
| 23 | 19 |
| 24 class AudioManagerPulse; | 20 class AudioManagerPulse; |
| 25 | 21 |
| 26 class PulseAudioInputStream : public AgcAudioStream<AudioInputStream> { | 22 class PulseAudioInputStream : public AgcAudioStream<AudioInputStream> { |
| 27 public: | 23 public: |
| 28 PulseAudioInputStream(AudioManagerPulse* audio_manager, | 24 PulseAudioInputStream(AudioManagerPulse* audio_manager, |
| 29 const std::string& device_name, | 25 const std::string& device_name, |
| 30 const AudioParameters& params, | 26 const AudioParameters& params, |
| 31 pa_threaded_mainloop* mainloop, | 27 pa_threaded_mainloop* mainloop, |
| 32 pa_context* context); | 28 pa_context* context); |
| 33 | 29 |
| 34 virtual ~PulseAudioInputStream(); | 30 virtual ~PulseAudioInputStream(); |
| 35 | 31 |
| 36 // Implementation of AudioInputStream. | 32 // Implementation of AudioInputStream. |
| 37 virtual bool Open() override; | 33 virtual bool Open() override; |
| 38 virtual void Start(AudioInputCallback* callback) override; | 34 virtual void Start(AudioInputCallback* callback) override; |
| 39 virtual void Stop() override; | 35 virtual void Stop() override; |
| 40 virtual void Close() override; | 36 virtual void Close() override; |
| 41 virtual double GetMaxVolume() override; | 37 virtual double GetMaxVolume() override; |
| 42 virtual void SetVolume(double volume) override; | 38 virtual void SetVolume(double volume) override; |
| 43 virtual double GetVolume() override; | 39 virtual double GetVolume() override; |
| 40 virtual bool IsMuted() override; |
| 44 | 41 |
| 45 private: | 42 private: |
| 46 // PulseAudio Callbacks. | 43 // PulseAudio Callbacks. |
| 47 static void ReadCallback(pa_stream* handle, size_t length, void* user_data); | 44 static void ReadCallback(pa_stream* handle, size_t length, void* user_data); |
| 48 static void StreamNotifyCallback(pa_stream* stream, void* user_data); | 45 static void StreamNotifyCallback(pa_stream* stream, void* user_data); |
| 49 static void VolumeCallback(pa_context* context, const pa_source_info* info, | 46 static void VolumeCallback(pa_context* context, const pa_source_info* info, |
| 50 int error, void* user_data); | 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); |
| 51 | 52 |
| 52 // Helper for the ReadCallback. | 53 // Helper for the ReadCallback. |
| 53 void ReadData(); | 54 void ReadData(); |
| 54 | 55 |
| 56 // Utility method used by GetVolume() and IsMuted(). |
| 57 bool GetSourceInformation(pa_source_info_cb_t callback); |
| 58 |
| 55 AudioManagerPulse* audio_manager_; | 59 AudioManagerPulse* audio_manager_; |
| 56 AudioInputCallback* callback_; | 60 AudioInputCallback* callback_; |
| 57 std::string device_name_; | 61 std::string device_name_; |
| 58 AudioParameters params_; | 62 AudioParameters params_; |
| 59 int channels_; | 63 int channels_; |
| 60 double volume_; | 64 double volume_; |
| 61 bool stream_started_; | 65 bool stream_started_; |
| 62 | 66 |
| 67 // Set to true in IsMuted() if user has muted the selected microphone in the |
| 68 // sound settings UI. |
| 69 bool muted_; |
| 70 |
| 63 // Holds the data from the OS. | 71 // Holds the data from the OS. |
| 64 AudioBlockFifo fifo_; | 72 AudioBlockFifo fifo_; |
| 65 | 73 |
| 66 // PulseAudio API structs. | 74 // PulseAudio API structs. |
| 67 pa_threaded_mainloop* pa_mainloop_; // Weak. | 75 pa_threaded_mainloop* pa_mainloop_; // Weak. |
| 68 pa_context* pa_context_; // Weak. | 76 pa_context* pa_context_; // Weak. |
| 69 pa_stream* handle_; | 77 pa_stream* handle_; |
| 70 | 78 |
| 71 // Flag indicating the state of the context has been changed. | 79 // Flag indicating the state of the context has been changed. |
| 72 bool context_state_changed_; | 80 bool context_state_changed_; |
| 73 | 81 |
| 74 base::ThreadChecker thread_checker_; | 82 base::ThreadChecker thread_checker_; |
| 75 | 83 |
| 76 DISALLOW_COPY_AND_ASSIGN(PulseAudioInputStream); | 84 DISALLOW_COPY_AND_ASSIGN(PulseAudioInputStream); |
| 77 }; | 85 }; |
| 78 | 86 |
| 79 } // namespace media | 87 } // namespace media |
| 80 | 88 |
| 81 #endif // MEDIA_AUDIO_PULSE_PULSE_INPUT_H_ | 89 #endif // MEDIA_AUDIO_PULSE_PULSE_INPUT_H_ |
| OLD | NEW |