MumbleCommunicator.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <mumlib.hpp>
  3. #include <log4cpp/Category.hh>
  4. #include <boost/noncopyable.hpp>
  5. #include <string>
  6. #include <stdexcept>
  7. namespace mumble {
  8. class Exception : public std::runtime_error {
  9. public:
  10. Exception(const char *message) : std::runtime_error(message) { }
  11. };
  12. class MumlibCallback;
  13. struct MumbleCommunicatorConfig {
  14. std::string user;
  15. std::string password;
  16. std::string host;
  17. int opusEncoderBitrate;
  18. int port = 0;
  19. };
  20. class MumbleCommunicator : boost::noncopyable {
  21. public:
  22. MumbleCommunicator(
  23. boost::asio::io_service &ioService);
  24. void connect(MumbleCommunicatorConfig &config);
  25. virtual ~MumbleCommunicator();
  26. void sendPcmSamples(int16_t *samples, unsigned int length);
  27. /**
  28. * This callback is called when communicator has received samples.
  29. * Arguments: session ID, sequence number, PCM samples, length of samples
  30. */
  31. std::function<void(int, int, int16_t *, int)> onIncomingPcmSamples;
  32. /**
  33. * This callback is called when a channel state message (e.g. Channel
  34. * information) is received. Arguments: channel_id, name
  35. */
  36. std::function<void(std::string, int)> onIncomingChannelState;
  37. std::function<void()> onServerSync;
  38. void sendTextMessage(std::string message);
  39. void joinChannel(int channel_id);
  40. private:
  41. boost::asio::io_service &ioService;
  42. log4cpp::Category &logger;
  43. mumlib::MumlibConfiguration mumConfig;
  44. std::shared_ptr<mumlib::Mumlib> mum;
  45. std::unique_ptr<MumlibCallback> callback;
  46. friend class MumlibCallback;
  47. };
  48. }