diff --git a/Configuration.cpp b/Configuration.cpp index 4589d69..0c94a8a 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -2,8 +2,7 @@ #include #include - -#include +#include using namespace config; @@ -17,7 +16,8 @@ namespace config { try { return tree.get(property); } catch (boost::property_tree::ptree_bad_path) { - throw ConfigException(std::string(typeid(TYPE).name()) + " key \'" + property + "\' not found"); + throw ConfigException((boost::format("Configuration option '%s' (type: %s) not found.") + % property % typeid(TYPE).name()).str()); } } } diff --git a/PjsuaCommunicator.cpp b/PjsuaCommunicator.cpp index 91f0e1b..7a1e11e 100644 --- a/PjsuaCommunicator.cpp +++ b/PjsuaCommunicator.cpp @@ -38,9 +38,9 @@ namespace sip { class _MumlibAudioMedia : public pj::AudioMedia { public: - _MumlibAudioMedia(sip::PjsuaCommunicator &comm) + _MumlibAudioMedia(sip::PjsuaCommunicator &comm, int frameTimeLength) : communicator(comm) { - createMediaPort(); + createMediaPort(frameTimeLength); registerMediaPort(&mediaPort); } @@ -62,18 +62,26 @@ namespace sip { return communicator->mediaPortPutFrame(port, frame); } - void createMediaPort() { + void createMediaPort(int frameTimeLength) { auto name = pj_str((char *) "MumsiMediaPort"); + if (frameTimeLength != 10 + and frameTimeLength != 20 + and frameTimeLength != 40 + and frameTimeLength != 60) { + throw sip::Exception( + (boost::format("valid frame time length value: %d. valid values are: 10, 20, 40, 60") % + frameTimeLength).str()); + } + pj_status_t status = pjmedia_port_info_init(&(mediaPort.info), &name, PJMEDIA_SIG_CLASS_PORT_AUD('s', 'i'), SAMPLING_RATE, 1, 16, - SAMPLING_RATE * 20 / - 1000); // todo recalculate to match mumble specs + SAMPLING_RATE * frameTimeLength / 1000); if (status != PJ_SUCCESS) { throw sip::Exception("error while calling pjmedia_port_info_init()", status); @@ -208,7 +216,7 @@ namespace sip { } } -sip::PjsuaCommunicator::PjsuaCommunicator(IncomingConnectionValidator &validator) +sip::PjsuaCommunicator::PjsuaCommunicator(IncomingConnectionValidator &validator, int frameTimeLength) : logger(log4cpp::Category::getInstance("SipCommunicator")), pjsuaLogger(log4cpp::Category::getInstance("Pjsua")), uriValidator(validator) { @@ -232,7 +240,9 @@ sip::PjsuaCommunicator::PjsuaCommunicator(IncomingConnectionValidator &validator mixer.reset(new mixer::AudioFramesMixer(cachingPool.factory)); - media.reset(new _MumlibAudioMedia(*this)); + media.reset(new _MumlibAudioMedia(*this, frameTimeLength)); + + logger.info("Created Pjsua communicator with frame length %d ms.", frameTimeLength); } void sip::PjsuaCommunicator::connect( diff --git a/PjsuaCommunicator.hpp b/PjsuaCommunicator.hpp index 05a15fd..395fe5b 100644 --- a/PjsuaCommunicator.hpp +++ b/PjsuaCommunicator.hpp @@ -29,6 +29,10 @@ namespace sip { mesg += title; } + Exception(std::string title) : std::runtime_error(title) { + mesg += title; + } + Exception(const char *title, pj_status_t status) : std::runtime_error(title) { char errorMsgBuffer[500]; pj_strerror(status, errorMsgBuffer, sizeof(errorMsgBuffer)); @@ -56,7 +60,7 @@ namespace sip { class PjsuaCommunicator : boost::noncopyable { public: - PjsuaCommunicator(IncomingConnectionValidator &validator); + PjsuaCommunicator(IncomingConnectionValidator &validator, int frameTimeLength); void connect( std::string host, diff --git a/config.ini.example b/config.ini.example index 2831d05..5044909 100644 --- a/config.ini.example +++ b/config.ini.example @@ -12,10 +12,17 @@ port = 5060 user = mumsi password = foobar +# length of single voice frame in ms. Valid values are 10, 20, 40, 60 ms. +# Adjust it if you need to meet the specific bandwidth requirements of Murmur server +frameLength = 40 + [mumble] host = example.org port = 64738 user = mumsi password = foobar channelNameExpression = + +# Bitrate of Opus encoder in B/s +# Adjust it if you need to meet the specific bandwidth requirements of Murmur server opusEncoderBitrate = 16000 \ No newline at end of file diff --git a/main.cpp b/main.cpp index c6eabf6..bfd872a 100644 --- a/main.cpp +++ b/main.cpp @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) { boost::asio::io_service ioService; - sip::PjsuaCommunicator pjsuaCommunicator(connectionValidator); + sip::PjsuaCommunicator pjsuaCommunicator(connectionValidator, conf.getInt("sip.frameLength")); mumble::MumbleCommunicator mumbleCommunicator(ioService);