MumbleCommunicator.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef MUMSI_MUMBLECOMMUNICATOR_HPP
  2. #define MUMSI_MUMBLECOMMUNICATOR_HPP
  3. #include "ISamplesBuffer.hpp"
  4. extern "C" {
  5. #include "libmumble.h"
  6. }
  7. #include <string>
  8. #include <stdexcept>
  9. #include <opus.h>
  10. #include <log4cpp/Category.hh>
  11. #include <sndfile.hh>
  12. #include <thread>
  13. namespace mumble {
  14. constexpr unsigned int SAMPLE_RATE = 48000;
  15. class Exception : public std::runtime_error {
  16. public:
  17. Exception(const char *message) : std::runtime_error(message) { }
  18. };
  19. class MumbleCommunicator {
  20. public:
  21. MumbleCommunicator(
  22. ISamplesBuffer &samplesBuffer,
  23. std::string user,
  24. std::string password,
  25. std::string host,
  26. int port = 0);
  27. ~MumbleCommunicator();
  28. void loop();
  29. void senderThreadFunction();
  30. void receiveAudioFrameCallback(uint8_t *audio_data, uint32_t audio_data_size);
  31. private:
  32. log4cpp::Category &logger;
  33. ISamplesBuffer &samplesBuffer;
  34. std::unique_ptr<std::thread> senderThread;
  35. mumble_struct *mumble;
  36. OpusDecoder *opusDecoder;
  37. OpusEncoder *opusEncoder;
  38. int outgoingAudioSequenceNumber;
  39. SndfileHandle fileHandle;
  40. bool quit;
  41. };
  42. }
  43. #endif //MUMSI_MUMBLECOMMUNICATOR_HPP