| 6 |
| 7 | #ifndef LIBTGVOIP_AUDIOINPUTPULSE_H |
| 8 | #define LIBTGVOIP_AUDIOINPUTPULSE_H |
| 9 |
| 10 | #include "../../threading.h" |
| 11 | #include "../../audio/AudioInput.h" |
| 12 |
| 13 | #include <pulse/pulseaudio.h> |
| 14 |
| 15 | #define DECLARE_DL_FUNCTION(name) typeof(name)* _import_##name |
| 16 |
| 17 | namespace tgvoip |
| 18 | { |
| 19 |
| 20 | namespace audio |
| 21 | { |
| 22 |
| 23 | class AudioInputPulse : public AudioInput |
| 24 | { |
| 25 | public: |
| 26 | AudioInputPulse(pa_context* context, pa_threaded_mainloop* mainloop, std::string devID); |
| 27 | virtual ~AudioInputPulse(); |
| 28 | virtual void Start(); |
| 29 | virtual void Stop(); |
| 30 | virtual bool IsRecording(); |
| 31 | virtual void SetCurrentDevice(std::string devID); |
| 32 | static bool EnumerateDevices(std::vector<AudioInputDevice>& devs); |
| 33 |
| 34 | private: |
| 35 | pa_threaded_mainloop* m_mainloop; |
| 36 | pa_context* m_context; |
| 37 | pa_stream* m_stream = nullptr; |
| 38 |
| 39 | std::size_t m_remainingDataSize = 0; |
| 40 | std::uint8_t m_remainingData[960 * 8 * 2]; |
| 41 |
| 42 | bool m_isRecording = false; |
| 43 | bool m_isConnected = false; |
| 44 | bool m_didStart = false; |
| 45 | bool m_isLocked = false; |
| 46 |
| 47 | static void StreamStateCallback(pa_stream* s, void* arg); |
| 48 | static void StreamReadCallback(pa_stream* stream, std::size_t requestedBytes, void* userdata); |
| 49 | void StreamReadCallback(pa_stream* stream, std::size_t requestedBytes); |
| 50 | pa_stream* CreateAndInitStream(); |
| 51 | }; |
| 52 |
| 53 | } // namespace audio |
| 54 |
| 55 | } // namespace tgvoip |
| 56 |
| 57 | #undef DECLARE_DL_FUNCTION |
| 58 |
| 59 | #endif // LIBTGVOIP_AUDIOINPUTPULSE_H |
| 60 |