MumbleCommunicator.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "MumbleCommunicator.hpp"
  2. #include <cstring>
  3. #include <functional>
  4. namespace mumble {
  5. class MumlibCallback : public mumlib::BasicCallback {
  6. public:
  7. std::shared_ptr<mumlib::Mumlib> mum;
  8. MumbleCommunicator *communicator;
  9. virtual void audio(
  10. int target,
  11. int sessionId,
  12. int sequenceNumber,
  13. int16_t *pcm_data,
  14. uint32_t pcm_data_size) override {
  15. communicator->onIncomingPcmSamples(sessionId, sequenceNumber, pcm_data, pcm_data_size);
  16. }
  17. virtual void channelState(
  18. std::string name,
  19. int32_t channel_id,
  20. int32_t parent,
  21. std::string description,
  22. std::vector<uint32_t> links,
  23. std::vector<uint32_t> inks_add,
  24. std::vector<uint32_t> links_remove,
  25. bool temporary,
  26. int32_t position) override {
  27. communicator->onIncomingChannelState(name, channel_id);
  28. }
  29. virtual void serverSync(
  30. std::string welcome_text,
  31. int32_t session,
  32. int32_t max_bandwidth,
  33. int64_t permissions) override {
  34. communicator->onServerSync();
  35. };
  36. };
  37. }
  38. mumble::MumbleCommunicator::MumbleCommunicator(boost::asio::io_service &ioService)
  39. : ioService(ioService),
  40. logger(log4cpp::Category::getInstance("MumbleCommunicator")) {
  41. }
  42. void mumble::MumbleCommunicator::connect(
  43. std::string user,
  44. std::string password,
  45. std::string host,
  46. int port) {
  47. callback.reset(new MumlibCallback());
  48. mum.reset(new mumlib::Mumlib(*callback, ioService));
  49. callback->communicator = this;
  50. callback->mum = mum;
  51. mum->connect(host, port, user, password);
  52. }
  53. void mumble::MumbleCommunicator::sendPcmSamples(int16_t *samples, unsigned int length) {
  54. mum->sendAudioData(samples, length);
  55. }
  56. mumble::MumbleCommunicator::~MumbleCommunicator() {
  57. mum->disconnect();
  58. }
  59. void mumble::MumbleCommunicator::sendTextMessage(std::string message) {
  60. mum->sendTextMessage(message);
  61. }
  62. void mumble::MumbleCommunicator::joinChannel(int channel_id) {
  63. mum->joinChannel(channel_id);
  64. }