adding opus chanel in mumblib configuration

This commit is contained in:
Auzan 2018-03-29 09:53:47 +07:00
parent 7d64b05e3c
commit 429e1a54f7
6 changed files with 12 additions and 7 deletions

View File

@ -12,6 +12,7 @@ namespace mumlib {
constexpr int DEFAULT_OPUS_ENCODER_BITRATE = 16000; constexpr int DEFAULT_OPUS_ENCODER_BITRATE = 16000;
constexpr int DEFAULT_OPUS_SAMPLE_RATE = 48000; constexpr int DEFAULT_OPUS_SAMPLE_RATE = 48000;
constexpr int DEFAULT_OPUS_NUM_CHANNELS = 1;
using namespace std; using namespace std;
using namespace boost::asio; using namespace boost::asio;
@ -24,6 +25,7 @@ namespace mumlib {
struct MumlibConfiguration { struct MumlibConfiguration {
int opusEncoderBitrate = DEFAULT_OPUS_ENCODER_BITRATE; int opusEncoderBitrate = DEFAULT_OPUS_ENCODER_BITRATE;
int opusSampleRate = DEFAULT_OPUS_SAMPLE_RATE; int opusSampleRate = DEFAULT_OPUS_SAMPLE_RATE;
int opusChannels = DEFAULT_OPUS_NUM_CHANNELS;
// additional fields will be added in the future // additional fields will be added in the future
}; };

View File

@ -25,8 +25,10 @@ namespace mumlib {
}; };
class Audio : boost::noncopyable { class Audio : boost::noncopyable {
public: public:
Audio(int opusSampleRate, int opusEncoderBitrate); explicit Audio(int opusSampleRate=DEFAULT_OPUS_SAMPLE_RATE,
int opusEncoderBitrate=DEFAULT_OPUS_ENCODER_BITRATE,
int channels=DEFAULT_OPUS_NUM_CHANNELS);
virtual ~Audio(); virtual ~Audio();

View File

@ -29,6 +29,6 @@ namespace mumlib {
private: private:
const int64_t value; const int64_t value;
long parseVariant(const uint8_t *buffer); int64_t parseVariant(const uint8_t *buffer);
}; };
} }

View File

@ -4,7 +4,7 @@
static boost::posix_time::seconds RESET_SEQUENCE_NUMBER_INTERVAL(5); static boost::posix_time::seconds RESET_SEQUENCE_NUMBER_INTERVAL(5);
mumlib::Audio::Audio(int opusSampleRate, int opusEncoderBitrate) mumlib::Audio::Audio(int opusSampleRate, int opusEncoderBitrate, int channels)
: logger(log4cpp::Category::getInstance("mumlib.Audio")), : logger(log4cpp::Category::getInstance("mumlib.Audio")),
opusDecoder(nullptr), opusDecoder(nullptr),
opusEncoder(nullptr), opusEncoder(nullptr),
@ -13,12 +13,12 @@ mumlib::Audio::Audio(int opusSampleRate, int opusEncoderBitrate)
int error; int error;
this->sampleRate = opusSampleRate; this->sampleRate = opusSampleRate;
opusDecoder = opus_decoder_create(opusSampleRate, 1, &error); opusDecoder = opus_decoder_create(opusSampleRate, channels, &error);
if (error != OPUS_OK) { if (error != OPUS_OK) {
throw AudioException((boost::format("failed to initialize OPUS decoder: %s") % opus_strerror(error)).str()); throw AudioException((boost::format("failed to initialize OPUS decoder: %s") % opus_strerror(error)).str());
} }
opusEncoder = opus_encoder_create(opusSampleRate, 1, OPUS_APPLICATION_VOIP, &error); opusEncoder = opus_encoder_create(opusSampleRate, channels, OPUS_APPLICATION_VOIP, &error);
if (error != OPUS_OK) { if (error != OPUS_OK) {
throw AudioException((boost::format("failed to initialize OPUS encoder: %s") % opus_strerror(error)).str()); throw AudioException((boost::format("failed to initialize OPUS encoder: %s") % opus_strerror(error)).str());
} }

View File

@ -95,6 +95,7 @@ void mumlib::Transport::connect(
void mumlib::Transport::disconnect() { void mumlib::Transport::disconnect() {
pingTimer.cancel();
if (state != ConnectionState::NOT_CONNECTED) { if (state != ConnectionState::NOT_CONNECTED) {
boost::system::error_code errorCode; boost::system::error_code errorCode;

View File

@ -44,7 +44,7 @@ namespace mumlib {
externalIoService(true), externalIoService(true),
transport(ioService, boost::bind(&_Mumlib_Private::processIncomingTcpMessage, this, _1, _2, _3), transport(ioService, boost::bind(&_Mumlib_Private::processIncomingTcpMessage, this, _1, _2, _3),
boost::bind(&_Mumlib_Private::processAudioPacket, this, _1, _2, _3)), boost::bind(&_Mumlib_Private::processAudioPacket, this, _1, _2, _3)),
audio(configuration.opusSampleRate, configuration.opusEncoderBitrate) { audio(configuration.opusSampleRate, configuration.opusEncoderBitrate, configuration.opusChannels) {
audio.setOpusEncoderBitrate(configuration.opusEncoderBitrate); audio.setOpusEncoderBitrate(configuration.opusEncoderBitrate);
} }