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