AudioInputPulse.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_AUDIOINPUTPULSE_H
  7. #define LIBTGVOIP_AUDIOINPUTPULSE_H
  8. #include "../../audio/AudioInput.h"
  9. #include "../../threading.h"
  10. #include <pulse/pulseaudio.h>
  11. #define DECLARE_DL_FUNCTION(name) typeof(name)* _import_##name
  12. namespace tgvoip{
  13. namespace audio{
  14. class AudioInputPulse : public AudioInput{
  15. public:
  16. AudioInputPulse(pa_context* context, pa_threaded_mainloop* mainloop, std::string devID);
  17. virtual ~AudioInputPulse();
  18. virtual void Start();
  19. virtual void Stop();
  20. virtual bool IsRecording();
  21. virtual void SetCurrentDevice(std::string devID);
  22. static bool EnumerateDevices(std::vector<AudioInputDevice>& devs);
  23. private:
  24. static void StreamStateCallback(pa_stream* s, void* arg);
  25. static void StreamReadCallback(pa_stream* stream, size_t requested_bytes, void* userdata);
  26. void StreamReadCallback(pa_stream* stream, size_t requestedBytes);
  27. pa_stream* CreateAndInitStream();
  28. pa_threaded_mainloop* mainloop;
  29. pa_context* context;
  30. pa_stream* stream;
  31. bool isRecording;
  32. bool isConnected;
  33. bool didStart;
  34. bool isLocked;
  35. unsigned char remainingData[960*8*2];
  36. size_t remainingDataSize;
  37. };
  38. }
  39. }
  40. #undef DECLARE_DL_FUNCTION
  41. #endif //LIBTGVOIP_AUDIOINPUTPULSE_H