MumbleCommunicator.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. #include <mumlib.hpp>
  3. #include <log4cpp/Category.hh>
  4. #include <boost/noncopyable.hpp>
  5. #include <string>
  6. #include <stdexcept>
  7. // 0 = mumble users connected at start; 1 = connect at dial-in
  8. // TODO: fix mumlib::TransportException when this option is enabled
  9. #define MUM_DELAYED_CONNECT 0
  10. namespace mumble {
  11. class Exception : public std::runtime_error {
  12. public:
  13. Exception(const char *message) : std::runtime_error(message) { }
  14. };
  15. class MumlibCallback;
  16. struct MumbleCommunicatorConfig {
  17. std::string user;
  18. std::string password;
  19. std::string host;
  20. int opusEncoderBitrate;
  21. int port = 0;
  22. bool autodeaf;
  23. std::string comment;
  24. int max_calls = 1;
  25. std::string authchan; // config.ini: channelAuthExpression
  26. };
  27. // This is the subset that is of interest to us
  28. struct MumbleUserState {
  29. int32_t mute;
  30. int32_t deaf;
  31. int32_t suppress;
  32. int32_t self_mute;
  33. int32_t self_deaf;
  34. int32_t priority_speaker;
  35. int32_t recording;
  36. };
  37. class MumbleCommunicator : boost::noncopyable {
  38. public:
  39. MumbleCommunicator(
  40. boost::asio::io_service &ioService);
  41. void connect(MumbleCommunicatorConfig &config);
  42. void onConnect();
  43. void onDisconnect();
  44. void onCallerAuth();
  45. //void onCallerUnauth();
  46. virtual ~MumbleCommunicator();
  47. void sendPcmSamples(int16_t *samples, unsigned int length);
  48. /**
  49. * This callback is called when communicator has received samples.
  50. * Arguments: call ID, session ID, sequence number, PCM samples, length of samples
  51. */
  52. std::function<void(int, int, int, int16_t *, int)> onIncomingPcmSamples;
  53. /**
  54. * This callback is called when a channel state message (e.g. Channel
  55. * information) is received. Arguments: channel_id, name
  56. */
  57. std::function<void(std::string, int)> onIncomingChannelState;
  58. std::function<void()> onServerSync;
  59. std::function<void()> onUserState;
  60. void sendTextMessage(std::string message);
  61. void joinChannel(int channel_id);
  62. void sendUserState(mumlib::UserState field, bool val);
  63. MumbleUserState userState;
  64. int callId;
  65. private:
  66. boost::asio::io_service &ioService;
  67. log4cpp::Category &logger;
  68. MumbleCommunicatorConfig mumbleConf;
  69. mumlib::MumlibConfiguration mumConfig;
  70. std::shared_ptr<mumlib::Mumlib> mum;
  71. std::unique_ptr<MumlibCallback> callback;
  72. friend class MumlibCallback;
  73. };
  74. }