Skip to content

Commit

Permalink
initial multi-call support; improve channel joins
Browse files Browse the repository at this point in the history
  • Loading branch information
mrscotty committed May 27, 2017
1 parent 82015dc commit 993c5f3
Show file tree
Hide file tree
Showing 11 changed files with 474 additions and 103 deletions.
27 changes: 27 additions & 0 deletions MumbleChannelJoiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ using namespace std;

mumble::MumbleChannelJoiner::MumbleChannelJoiner(std::string channelNameRegex) : channelNameRegex(boost::regex(channelNameRegex)),
logger(log4cpp::Category::getInstance("MumbleChannelJoiner")){
//std::vector<ChannelEntry> *channels = new std::vector<ChannelEntry>();
}

std::vector<mumble::MumbleChannelJoiner::ChannelEntry> mumble::MumbleChannelJoiner::channels;

void mumble::MumbleChannelJoiner::checkChannel(std::string channel_name, int channel_id) {
boost::smatch s;
ChannelEntry ent;
logger.debug("Channel %s available (%d)", channel_name.c_str(), channel_id);

ent.name = channel_name;
ent.id = channel_id;

channels.push_back(ent);

if(boost::regex_match(channel_name, s, channelNameRegex)) {
this->channel_id = channel_id;
Expand All @@ -23,3 +31,22 @@ void mumble::MumbleChannelJoiner::maybeJoinChannel(mumble::MumbleCommunicator *m
}
}

/* This is a secondary channel-switching object that relys on updates to the
* class variable 'channels' for the channel list from the server.
*/
void mumble::MumbleChannelJoiner::findJoinChannel(mumble::MumbleCommunicator *mc) {
boost::smatch s;

int found = -1;

for(std::vector<ChannelEntry>::iterator it = channels.begin(); it != channels.end(); ++it) {
if(boost::regex_match(it->name, s, channelNameRegex)) {
found = it->id;
}
}

if(found > -1) {
mc->joinChannel(found);
}
}

9 changes: 9 additions & 0 deletions MumbleChannelJoiner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@
#include <boost/noncopyable.hpp>
#include <log4cpp/Category.hh>

#include <vector>
#include <string>
#include <boost/regex.hpp>
#include "MumbleCommunicator.hpp"

namespace mumble {
class MumbleChannelJoiner : boost::noncopyable {

struct ChannelEntry {
int id;
std::string name;
};

public:
MumbleChannelJoiner(std::string channelNameRegex);

void checkChannel(std::string channel_name, int channel_id);
void maybeJoinChannel(mumble::MumbleCommunicator *mc);
void findJoinChannel(mumble::MumbleCommunicator *mc);

private:
log4cpp::Category &logger;
boost::regex channelNameRegex;
int channel_id;
static std::vector<ChannelEntry> channels;
};
}
100 changes: 87 additions & 13 deletions MumbleCommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ namespace mumble {
std::shared_ptr<mumlib::Mumlib> mum;
MumbleCommunicator *communicator;

// called by Mumlib when receiving audio from mumble server
virtual void audio(
int target,
int sessionId,
int sequenceNumber,
int16_t *pcm_data,
uint32_t pcm_data_size) override {
communicator->onIncomingPcmSamples(sessionId, sequenceNumber, pcm_data, pcm_data_size);
communicator->onIncomingPcmSamples(communicator->callId, sessionId, sequenceNumber, pcm_data, pcm_data_size);
}

virtual void channelState(
Expand All @@ -39,6 +40,26 @@ namespace mumble {
communicator->onServerSync();
};

/*
virtual void onUserState(
int32_t session,
int32_t actor,
std::string name,
int32_t user_id,
int32_t channel_id,
int32_t mute,
int32_t deaf,
int32_t suppress,
int32_t self_mute,
int32_t self_deaf,
std::string comment,
int32_t priority_speaker,
int32_t recording
) override {
communicator->onUserState();
};
*/

};
}

Expand All @@ -60,8 +81,37 @@ void mumble::MumbleCommunicator::connect(MumbleCommunicatorConfig &config) {
callback->communicator = this;
callback->mum = mum;

mum->connect(config.host, config.port, config.user, config.password);
mum->self_deaf(1);
// IMPORTANT: comment these out when experimenting with onConnect
if ( ! MUM_DELAYED_CONNECT ) {
mum->connect(config.host, config.port, config.user, config.password);
if ( mumbleConf.autodeaf ) {
mum->sendUserState(mumlib::UserState::SELF_DEAF, true);
}
}
}

void mumble::MumbleCommunicator::onConnect() {
if ( MUM_DELAYED_CONNECT ) {
mum->connect(mumbleConf.host, mumbleConf.port, mumbleConf.user, mumbleConf.password);
}

if ( mumbleConf.comment.size() > 0 ) {
mum->sendUserState(mumlib::UserState::COMMENT, mumbleConf.comment);
}
if ( mumbleConf.autodeaf ) {
mum->sendUserState(mumlib::UserState::SELF_DEAF, true);
}
}

void mumble::MumbleCommunicator::onDisconnect() {
if ( MUM_DELAYED_CONNECT ) {
mum->disconnect();
} else {
}
}

void mumble::MumbleCommunicator::onCallerAuth() {
//onServerSync();
}

void mumble::MumbleCommunicator::sendPcmSamples(int16_t *samples, unsigned int length) {
Expand All @@ -76,21 +126,45 @@ void mumble::MumbleCommunicator::sendTextMessage(std::string message) {
mum->sendTextMessage(message);
}

/*
void mumble::MumbleCommunicator::onUserState(
int32_t session,
int32_t actor,
std::string name,
int32_t user_id,
int32_t channel_id,
int32_t mute,
int32_t deaf,
int32_t suppress,
int32_t self_mute,
int32_t self_deaf,
std::string comment,
int32_t priority_speaker,
int32_t recording) {
logger::notice("Entered onUserState(...)");
userState.mute = mute;
userState.deaf = deaf;
userState.suppress = suppress;
userState.self_mute = self_mute;
userState.self_deaf = self_deaf;
userState.priority_speaker = priority_speaker;
userState.recording = recording;
}
*/


void mumble::MumbleCommunicator::joinChannel(int channel_id) {
mum->joinChannel(channel_id);

if ( mumbleConf.autodeaf ) {
//mum->self_mute(1);
mum->self_deaf(1);
mum->sendUserState(mumlib::UserState::SELF_DEAF, true);
}
}

void mumble::MumbleCommunicator::mutedeaf(int status) {
if ( mumbleConf.autodeaf ) {
if ( status ) {
mum->self_deaf(status);
} else {
mum->self_mute(status);
}
}

void mumble::MumbleCommunicator::sendUserState(mumlib::UserState field, bool val) {
mum->sendUserState(field, val);
}

33 changes: 30 additions & 3 deletions MumbleCommunicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <string>
#include <stdexcept>

// 0 = mumble users connected at start; 1 = connect at dial-in
// TODO: fix mumlib::TransportException when this option is enabled
#define MUM_DELAYED_CONNECT 0

namespace mumble {

Expand All @@ -26,6 +29,20 @@ namespace mumble {
int opusEncoderBitrate;
int port = 0;
bool autodeaf;
std::string comment;
int max_calls = 1;
std::string authchan; // config.ini: channelAuthExpression
};

// This is the subset that is of interest to us
struct MumbleUserState {
int32_t mute;
int32_t deaf;
int32_t suppress;
int32_t self_mute;
int32_t self_deaf;
int32_t priority_speaker;
int32_t recording;
};

class MumbleCommunicator : boost::noncopyable {
Expand All @@ -34,16 +51,20 @@ namespace mumble {
boost::asio::io_service &ioService);

void connect(MumbleCommunicatorConfig &config);
void onConnect();
void onDisconnect();
void onCallerAuth();
//void onCallerUnauth();

virtual ~MumbleCommunicator();

void sendPcmSamples(int16_t *samples, unsigned int length);

/**
* This callback is called when communicator has received samples.
* Arguments: session ID, sequence number, PCM samples, length of samples
* Arguments: call ID, session ID, sequence number, PCM samples, length of samples
*/
std::function<void(int, int, int16_t *, int)> onIncomingPcmSamples;
std::function<void(int, int, int, int16_t *, int)> onIncomingPcmSamples;

/**
* This callback is called when a channel state message (e.g. Channel
Expand All @@ -53,11 +74,17 @@ namespace mumble {

std::function<void()> onServerSync;

std::function<void()> onUserState;

void sendTextMessage(std::string message);

void joinChannel(int channel_id);

void mutedeaf(int status);
void sendUserState(mumlib::UserState field, bool val);

MumbleUserState userState;

int callId;

private:
boost::asio::io_service &ioService;
Expand Down
Loading

0 comments on commit 993c5f3

Please sign in to comment.