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_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
};

View File

@ -26,7 +26,9 @@ namespace mumlib {
class Audio : boost::noncopyable {
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();

View File

@ -29,6 +29,6 @@ namespace mumlib {
private:
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);
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());
}

View File

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

View File

@ -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);
}