AudioOutputALSA.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_AUDIOOUTPUTALSA_H
  7. #define LIBTGVOIP_AUDIOOUTPUTALSA_H
  8. #include "../../audio/AudioOutput.h"
  9. #include "../../threading.h"
  10. #include <alsa/asoundlib.h>
  11. namespace tgvoip{
  12. namespace audio{
  13. class AudioOutputALSA : public AudioOutput{
  14. public:
  15. AudioOutputALSA(std::string devID);
  16. virtual ~AudioOutputALSA();
  17. virtual void Start();
  18. virtual void Stop();
  19. virtual bool IsPlaying();
  20. virtual void SetCurrentDevice(std::string devID);
  21. static void EnumerateDevices(std::vector<AudioOutputDevice>& devs);
  22. private:
  23. void RunThread();
  24. int (*_snd_pcm_open)(snd_pcm_t** pcm, const char* name, snd_pcm_stream_t stream, int mode);
  25. int (*_snd_pcm_set_params)(snd_pcm_t* pcm, snd_pcm_format_t format, snd_pcm_access_t access, unsigned int channels, unsigned int rate, int soft_resample, unsigned int latency);
  26. int (*_snd_pcm_close)(snd_pcm_t* pcm);
  27. snd_pcm_sframes_t (*_snd_pcm_writei)(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
  28. int (*_snd_pcm_recover)(snd_pcm_t* pcm, int err, int silent);
  29. const char* (*_snd_strerror)(int errnum);
  30. void* lib;
  31. snd_pcm_t* handle;
  32. Thread* thread;
  33. bool isPlaying;
  34. };
  35. }
  36. }
  37. #endif //LIBTGVOIP_AUDIOOUTPUTALSA_H