| 6 |
| 7 | #ifndef LIBTGVOIP_PULSEAUDIOLOADER_H |
| 8 | #define LIBTGVOIP_PULSEAUDIOLOADER_H |
| 9 |
| 10 | #include "../../audio/AudioIO.h" |
| 11 | #include "AudioInputPulse.h" |
| 12 | #include "AudioOutputPulse.h" |
| 13 | #include <functional> |
| 14 | #include <pulse/pulseaudio.h> |
| 15 | #include <string> |
| 16 |
| 17 | #define DECLARE_DL_FUNCTION(name) static typeof(name)* _import_##name |
| 18 |
| 19 | namespace tgvoip |
| 20 | { |
| 21 |
| 22 | namespace audio |
| 23 | { |
| 24 |
| 25 | class AudioPulse : public AudioIO |
| 26 | { |
| 27 | public: |
| 28 | AudioPulse(std::string inputDevice, std::string outputDevice); |
| 29 | virtual ~AudioPulse(); |
| 30 | virtual AudioInput* GetInput(); |
| 31 | virtual AudioOutput* GetOutput(); |
| 32 |
| 33 | static bool Load(); |
| 34 | static bool DoOneOperation(std::function<pa_operation*(pa_context*)> f); |
| 35 |
| 36 | DECLARE_DL_FUNCTION(pa_threaded_mainloop_new); |
| 37 | DECLARE_DL_FUNCTION(pa_threaded_mainloop_get_api); |
| 38 | DECLARE_DL_FUNCTION(pa_context_new); |
| 39 | DECLARE_DL_FUNCTION(pa_context_new_with_proplist); |
| 40 | DECLARE_DL_FUNCTION(pa_context_set_state_callback); |
| 41 | DECLARE_DL_FUNCTION(pa_threaded_mainloop_lock); |
| 42 | DECLARE_DL_FUNCTION(pa_threaded_mainloop_unlock); |
| 43 | DECLARE_DL_FUNCTION(pa_threaded_mainloop_start); |
| 44 | DECLARE_DL_FUNCTION(pa_context_connect); |
| 45 | DECLARE_DL_FUNCTION(pa_context_get_state); |
| 46 | DECLARE_DL_FUNCTION(pa_threaded_mainloop_wait); |
| 47 | DECLARE_DL_FUNCTION(pa_stream_new_with_proplist); |
| 48 | DECLARE_DL_FUNCTION(pa_stream_set_state_callback); |
| 49 | DECLARE_DL_FUNCTION(pa_stream_set_write_callback); |
| 50 | DECLARE_DL_FUNCTION(pa_stream_connect_playback); |
| 51 | DECLARE_DL_FUNCTION(pa_operation_unref); |
| 52 | DECLARE_DL_FUNCTION(pa_stream_cork); |
| 53 | DECLARE_DL_FUNCTION(pa_threaded_mainloop_stop); |
| 54 | DECLARE_DL_FUNCTION(pa_stream_disconnect); |
| 55 | DECLARE_DL_FUNCTION(pa_stream_unref); |
| 56 | DECLARE_DL_FUNCTION(pa_context_disconnect); |
| 57 | DECLARE_DL_FUNCTION(pa_context_unref); |
| 58 | DECLARE_DL_FUNCTION(pa_threaded_mainloop_free); |
| 59 | DECLARE_DL_FUNCTION(pa_threaded_mainloop_signal); |
| 60 | DECLARE_DL_FUNCTION(pa_stream_begin_write); |
| 61 | DECLARE_DL_FUNCTION(pa_stream_write); |
| 62 | DECLARE_DL_FUNCTION(pa_stream_get_state); |
| 63 | DECLARE_DL_FUNCTION(pa_strerror); |
| 64 | DECLARE_DL_FUNCTION(pa_stream_set_read_callback); |
| 65 | DECLARE_DL_FUNCTION(pa_stream_connect_record); |
| 66 | DECLARE_DL_FUNCTION(pa_stream_peek); |
| 67 | DECLARE_DL_FUNCTION(pa_stream_drop); |
| 68 |
| 69 | DECLARE_DL_FUNCTION(pa_mainloop_new); |
| 70 | DECLARE_DL_FUNCTION(pa_mainloop_get_api); |
| 71 | DECLARE_DL_FUNCTION(pa_mainloop_iterate); |
| 72 | DECLARE_DL_FUNCTION(pa_mainloop_free); |
| 73 | DECLARE_DL_FUNCTION(pa_context_get_sink_info_list); |
| 74 | DECLARE_DL_FUNCTION(pa_context_get_source_info_list); |
| 75 | DECLARE_DL_FUNCTION(pa_operation_get_state); |
| 76 |
| 77 | DECLARE_DL_FUNCTION(pa_proplist_new); |
| 78 | DECLARE_DL_FUNCTION(pa_proplist_sets); |
| 79 | DECLARE_DL_FUNCTION(pa_proplist_free); |
| 80 |
| 81 | DECLARE_DL_FUNCTION(pa_stream_get_latency); |
| 82 |
| 83 | private: |
| 84 | static void* m_lib; |
| 85 | static bool m_loaded; |
| 86 | AudioInputPulse* m_input = nullptr; |
| 87 | AudioOutputPulse* m_output = nullptr; |
| 88 |
| 89 | pa_threaded_mainloop* m_mainloop; |
| 90 | pa_mainloop_api* m_mainloopApi; |
| 91 | pa_context* m_context; |
| 92 | bool m_isLocked = false; |
| 93 | bool m_didStart = false; |
| 94 | }; |
| 95 |
| 96 | } // namespace audio |
| 97 |
| 98 | } // namespace tgvoip |
| 99 |
| 100 | #undef DECLARE_DL_FUNCTION |
| 101 |
| 102 | #endif // LIBTGVOIP_PULSEAUDIOLOADER_H |
| 103 |