AudioPulse.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // libtgvoip is free and unencumbered public domain software.
  3. // For more information, see http://unlicense.org or the UNLICENSE file
  4. // you should have received with this source code distribution.
  5. //
  6. #ifndef LIBTGVOIP_PULSEAUDIOLOADER_H
  7. #define LIBTGVOIP_PULSEAUDIOLOADER_H
  8. #include <string>
  9. #include <functional>
  10. #include <pulse/pulseaudio.h>
  11. #include "../../audio/AudioIO.h"
  12. #include "AudioInputPulse.h"
  13. #include "AudioOutputPulse.h"
  14. #define DECLARE_DL_FUNCTION(name) static typeof(name)* _import_##name
  15. namespace tgvoip{
  16. namespace audio{
  17. class AudioPulse : public AudioIO{
  18. public:
  19. AudioPulse(std::string inputDevice, std::string outputDevice);
  20. virtual ~AudioPulse();
  21. virtual AudioInput* GetInput();
  22. virtual AudioOutput* GetOutput();
  23. static bool Load();
  24. static bool DoOneOperation(std::function<pa_operation*(pa_context*)> f);
  25. DECLARE_DL_FUNCTION(pa_threaded_mainloop_new);
  26. DECLARE_DL_FUNCTION(pa_threaded_mainloop_get_api);
  27. DECLARE_DL_FUNCTION(pa_context_new);
  28. DECLARE_DL_FUNCTION(pa_context_new_with_proplist);
  29. DECLARE_DL_FUNCTION(pa_context_set_state_callback);
  30. DECLARE_DL_FUNCTION(pa_threaded_mainloop_lock);
  31. DECLARE_DL_FUNCTION(pa_threaded_mainloop_unlock);
  32. DECLARE_DL_FUNCTION(pa_threaded_mainloop_start);
  33. DECLARE_DL_FUNCTION(pa_context_connect);
  34. DECLARE_DL_FUNCTION(pa_context_get_state);
  35. DECLARE_DL_FUNCTION(pa_threaded_mainloop_wait);
  36. DECLARE_DL_FUNCTION(pa_stream_new_with_proplist);
  37. DECLARE_DL_FUNCTION(pa_stream_set_state_callback);
  38. DECLARE_DL_FUNCTION(pa_stream_set_write_callback);
  39. DECLARE_DL_FUNCTION(pa_stream_connect_playback);
  40. DECLARE_DL_FUNCTION(pa_operation_unref);
  41. DECLARE_DL_FUNCTION(pa_stream_cork);
  42. DECLARE_DL_FUNCTION(pa_threaded_mainloop_stop);
  43. DECLARE_DL_FUNCTION(pa_stream_disconnect);
  44. DECLARE_DL_FUNCTION(pa_stream_unref);
  45. DECLARE_DL_FUNCTION(pa_context_disconnect);
  46. DECLARE_DL_FUNCTION(pa_context_unref);
  47. DECLARE_DL_FUNCTION(pa_threaded_mainloop_free);
  48. DECLARE_DL_FUNCTION(pa_threaded_mainloop_signal);
  49. DECLARE_DL_FUNCTION(pa_stream_begin_write);
  50. DECLARE_DL_FUNCTION(pa_stream_write);
  51. DECLARE_DL_FUNCTION(pa_stream_get_state);
  52. DECLARE_DL_FUNCTION(pa_strerror);
  53. DECLARE_DL_FUNCTION(pa_stream_set_read_callback);
  54. DECLARE_DL_FUNCTION(pa_stream_connect_record);
  55. DECLARE_DL_FUNCTION(pa_stream_peek);
  56. DECLARE_DL_FUNCTION(pa_stream_drop);
  57. DECLARE_DL_FUNCTION(pa_mainloop_new);
  58. DECLARE_DL_FUNCTION(pa_mainloop_get_api);
  59. DECLARE_DL_FUNCTION(pa_mainloop_iterate);
  60. DECLARE_DL_FUNCTION(pa_mainloop_free);
  61. DECLARE_DL_FUNCTION(pa_context_get_sink_info_list);
  62. DECLARE_DL_FUNCTION(pa_context_get_source_info_list);
  63. DECLARE_DL_FUNCTION(pa_operation_get_state);
  64. DECLARE_DL_FUNCTION(pa_proplist_new);
  65. DECLARE_DL_FUNCTION(pa_proplist_sets);
  66. DECLARE_DL_FUNCTION(pa_proplist_free);
  67. DECLARE_DL_FUNCTION(pa_stream_get_latency);
  68. private:
  69. static void* lib;
  70. static bool loaded;
  71. AudioInputPulse* input=NULL;
  72. AudioOutputPulse* output=NULL;
  73. pa_threaded_mainloop* mainloop;
  74. pa_mainloop_api* mainloopApi;
  75. pa_context* context;
  76. bool isLocked=false;
  77. bool didStart=false;
  78. };
  79. }
  80. }
  81. #undef DECLARE_DL_FUNCTION
  82. #endif // LIBTGVOIP_PULSEAUDIOLOADER_H