MumbleCommunicator.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. bool autodeaf;
  20. };
  21. class MumbleCommunicator : boost::noncopyable {
  22. public:
  23. MumbleCommunicator(
  24. boost::asio::io_service &ioService);
  25. void connect(MumbleCommunicatorConfig &config);
  26. virtual ~MumbleCommunicator();
  27. void sendPcmSamples(int16_t *samples, unsigned int length);
  28. /**
  29. * This callback is called when communicator has received samples.
  30. * Arguments: session ID, sequence number, PCM samples, length of samples
  31. */
  32. std::function<void(int, int, int16_t *, int)> onIncomingPcmSamples;
  33. /**
  34. * This callback is called when a channel state message (e.g. Channel
  35. * information) is received. Arguments: channel_id, name
  36. */
  37. std::function<void(std::string, int)> onIncomingChannelState;
  38. std::function<void()> onServerSync;
  39. void sendTextMessage(std::string message);
  40. void joinChannel(int channel_id);
  41. void mutedeaf(int status);
  42. private:
  43. boost::asio::io_service &ioService;
  44. log4cpp::Category &logger;
  45. MumbleCommunicatorConfig mumbleConf;
  46. mumlib::MumlibConfiguration mumConfig;
  47. std::shared_ptr<mumlib::Mumlib> mum;
  48. std::unique_ptr<MumlibCallback> callback;
  49. friend class MumlibCallback;
  50. };
  51. }