diff --git a/include/mumlib.hpp b/include/mumlib.hpp index af979a0..da0baf0 100644 --- a/include/mumlib.hpp +++ b/include/mumlib.hpp @@ -12,6 +12,7 @@ namespace mumlib { constexpr int DEFAULT_OPUS_ENCODER_BITRATE = 16000; constexpr int DEFAULT_OPUS_SAMPLE_RATE = 48000; + constexpr int DEFAULT_OPUS_NUM_CHANNELS = 1; using namespace std; using namespace boost::asio; @@ -24,6 +25,7 @@ namespace mumlib { struct MumlibConfiguration { int opusEncoderBitrate = DEFAULT_OPUS_ENCODER_BITRATE; int opusSampleRate = DEFAULT_OPUS_SAMPLE_RATE; + int opusChannels = DEFAULT_OPUS_NUM_CHANNELS; // additional fields will be added in the future }; diff --git a/include/mumlib/Audio.hpp b/include/mumlib/Audio.hpp index df3ed11..7e1433a 100644 --- a/include/mumlib/Audio.hpp +++ b/include/mumlib/Audio.hpp @@ -25,8 +25,10 @@ namespace mumlib { }; class Audio : boost::noncopyable { - public: - Audio(int opusSampleRate, int opusEncoderBitrate); + public: + explicit Audio(int opusSampleRate=DEFAULT_OPUS_SAMPLE_RATE, + int opusEncoderBitrate=DEFAULT_OPUS_ENCODER_BITRATE, + int channels=DEFAULT_OPUS_NUM_CHANNELS); virtual ~Audio(); diff --git a/include/mumlib/VarInt.hpp b/include/mumlib/VarInt.hpp index 5ebacce..7e301c7 100644 --- a/include/mumlib/VarInt.hpp +++ b/include/mumlib/VarInt.hpp @@ -29,6 +29,6 @@ namespace mumlib { private: const int64_t value; - long parseVariant(const uint8_t *buffer); + int64_t parseVariant(const uint8_t *buffer); }; } \ No newline at end of file diff --git a/src/Audio.cpp b/src/Audio.cpp index 384942d..2a0eac2 100644 --- a/src/Audio.cpp +++ b/src/Audio.cpp @@ -4,7 +4,7 @@ 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")), opusDecoder(nullptr), opusEncoder(nullptr), @@ -13,12 +13,12 @@ mumlib::Audio::Audio(int opusSampleRate, int opusEncoderBitrate) int error; this->sampleRate = opusSampleRate; - opusDecoder = opus_decoder_create(opusSampleRate, 1, &error); + opusDecoder = opus_decoder_create(opusSampleRate, channels, &error); if (error != OPUS_OK) { 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) { throw AudioException((boost::format("failed to initialize OPUS encoder: %s") % opus_strerror(error)).str()); } diff --git a/src/Transport.cpp b/src/Transport.cpp index e016f50..2c14e4d 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -95,6 +95,7 @@ void mumlib::Transport::connect( void mumlib::Transport::disconnect() { + pingTimer.cancel(); if (state != ConnectionState::NOT_CONNECTED) { boost::system::error_code errorCode; diff --git a/src/mumlib.cpp b/src/mumlib.cpp index 6f7038f..f289992 100644 --- a/src/mumlib.cpp +++ b/src/mumlib.cpp @@ -44,7 +44,7 @@ namespace mumlib { externalIoService(true), transport(ioService, boost::bind(&_Mumlib_Private::processIncomingTcpMessage, 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); }