Add option to set frame length in PJSIP. #14
This commit is contained in:
parent
a0e636a592
commit
c04ead2ff5
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/property_tree/ini_parser.hpp>
|
#include <boost/property_tree/ini_parser.hpp>
|
||||||
|
#include <boost/format.hpp>
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
using namespace config;
|
using namespace config;
|
||||||
|
|
||||||
@ -17,7 +16,8 @@ namespace config {
|
|||||||
try {
|
try {
|
||||||
return tree.get<TYPE>(property);
|
return tree.get<TYPE>(property);
|
||||||
} catch (boost::property_tree::ptree_bad_path) {
|
} 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ namespace sip {
|
|||||||
|
|
||||||
class _MumlibAudioMedia : public pj::AudioMedia {
|
class _MumlibAudioMedia : public pj::AudioMedia {
|
||||||
public:
|
public:
|
||||||
_MumlibAudioMedia(sip::PjsuaCommunicator &comm)
|
_MumlibAudioMedia(sip::PjsuaCommunicator &comm, int frameTimeLength)
|
||||||
: communicator(comm) {
|
: communicator(comm) {
|
||||||
createMediaPort();
|
createMediaPort(frameTimeLength);
|
||||||
registerMediaPort(&mediaPort);
|
registerMediaPort(&mediaPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,18 +62,26 @@ namespace sip {
|
|||||||
return communicator->mediaPortPutFrame(port, frame);
|
return communicator->mediaPortPutFrame(port, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createMediaPort() {
|
void createMediaPort(int frameTimeLength) {
|
||||||
|
|
||||||
auto name = pj_str((char *) "MumsiMediaPort");
|
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),
|
pj_status_t status = pjmedia_port_info_init(&(mediaPort.info),
|
||||||
&name,
|
&name,
|
||||||
PJMEDIA_SIG_CLASS_PORT_AUD('s', 'i'),
|
PJMEDIA_SIG_CLASS_PORT_AUD('s', 'i'),
|
||||||
SAMPLING_RATE,
|
SAMPLING_RATE,
|
||||||
1,
|
1,
|
||||||
16,
|
16,
|
||||||
SAMPLING_RATE * 20 /
|
SAMPLING_RATE * frameTimeLength / 1000);
|
||||||
1000); // todo recalculate to match mumble specs
|
|
||||||
|
|
||||||
if (status != PJ_SUCCESS) {
|
if (status != PJ_SUCCESS) {
|
||||||
throw sip::Exception("error while calling pjmedia_port_info_init()", status);
|
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")),
|
: logger(log4cpp::Category::getInstance("SipCommunicator")),
|
||||||
pjsuaLogger(log4cpp::Category::getInstance("Pjsua")),
|
pjsuaLogger(log4cpp::Category::getInstance("Pjsua")),
|
||||||
uriValidator(validator) {
|
uriValidator(validator) {
|
||||||
@ -232,7 +240,9 @@ sip::PjsuaCommunicator::PjsuaCommunicator(IncomingConnectionValidator &validator
|
|||||||
|
|
||||||
mixer.reset(new mixer::AudioFramesMixer(cachingPool.factory));
|
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(
|
void sip::PjsuaCommunicator::connect(
|
||||||
|
@ -29,6 +29,10 @@ namespace sip {
|
|||||||
mesg += title;
|
mesg += title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Exception(std::string title) : std::runtime_error(title) {
|
||||||
|
mesg += title;
|
||||||
|
}
|
||||||
|
|
||||||
Exception(const char *title, pj_status_t status) : std::runtime_error(title) {
|
Exception(const char *title, pj_status_t status) : std::runtime_error(title) {
|
||||||
char errorMsgBuffer[500];
|
char errorMsgBuffer[500];
|
||||||
pj_strerror(status, errorMsgBuffer, sizeof(errorMsgBuffer));
|
pj_strerror(status, errorMsgBuffer, sizeof(errorMsgBuffer));
|
||||||
@ -56,7 +60,7 @@ namespace sip {
|
|||||||
|
|
||||||
class PjsuaCommunicator : boost::noncopyable {
|
class PjsuaCommunicator : boost::noncopyable {
|
||||||
public:
|
public:
|
||||||
PjsuaCommunicator(IncomingConnectionValidator &validator);
|
PjsuaCommunicator(IncomingConnectionValidator &validator, int frameTimeLength);
|
||||||
|
|
||||||
void connect(
|
void connect(
|
||||||
std::string host,
|
std::string host,
|
||||||
|
@ -12,10 +12,17 @@ port = 5060
|
|||||||
user = mumsi
|
user = mumsi
|
||||||
password = foobar
|
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]
|
[mumble]
|
||||||
host = example.org
|
host = example.org
|
||||||
port = 64738
|
port = 64738
|
||||||
user = mumsi
|
user = mumsi
|
||||||
password = foobar
|
password = foobar
|
||||||
channelNameExpression =
|
channelNameExpression =
|
||||||
|
|
||||||
|
# Bitrate of Opus encoder in B/s
|
||||||
|
# Adjust it if you need to meet the specific bandwidth requirements of Murmur server
|
||||||
opusEncoderBitrate = 16000
|
opusEncoderBitrate = 16000
|
2
main.cpp
2
main.cpp
@ -48,7 +48,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
boost::asio::io_service ioService;
|
boost::asio::io_service ioService;
|
||||||
|
|
||||||
sip::PjsuaCommunicator pjsuaCommunicator(connectionValidator);
|
sip::PjsuaCommunicator pjsuaCommunicator(connectionValidator, conf.getInt("sip.frameLength"));
|
||||||
|
|
||||||
mumble::MumbleCommunicator mumbleCommunicator(ioService);
|
mumble::MumbleCommunicator mumbleCommunicator(ioService);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user