From 24669c98f6d7c4870bc9a9d1614fbbfa01f74a9e Mon Sep 17 00:00:00 2001 From: Marcus Llewellyn Date: Wed, 15 Jan 2020 12:57:18 -0600 Subject: [PATCH] Made changes requested by reviewer Fixed missing copyright headers. Fixed exceeding 120 columns. Fixed #include Fixed if conditional style. Fixed C++ reference symbol placement. --- plugins/opusCodec/src/OpusDecoder.cpp | 40 +++++++++++---- plugins/opusCodec/src/OpusDecoder.h | 10 ++++ plugins/opusCodec/src/OpusEncoder.cpp | 70 +++++++++++++++++++-------- plugins/opusCodec/src/OpusEncoder.h | 14 +++++- 4 files changed, 102 insertions(+), 32 deletions(-) diff --git a/plugins/opusCodec/src/OpusDecoder.cpp b/plugins/opusCodec/src/OpusDecoder.cpp index b410ed9bd5..3e436c58e4 100644 --- a/plugins/opusCodec/src/OpusDecoder.cpp +++ b/plugins/opusCodec/src/OpusDecoder.cpp @@ -1,3 +1,13 @@ +// +// OpusCodecManager.h +// plugins/opusCodec/src +// +// Copyright 2020 Dale Glass +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + #include #include #include @@ -60,25 +70,30 @@ void AthenaOpusDecoder::decode(const QByteArray &encodedBuffer, QByteArray &deco PerformanceTimer perfTimer("AthenaOpusDecoder::decode"); // The audio system encodes and decodes always in fixed size chunks - int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast(sizeof(int16_t)) * _opus_num_channels; + int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast(sizeof(int16_t)) + * _opus_num_channels; decodedBuffer.resize( buffer_size ); int buffer_frames = decodedBuffer.size() / _opus_num_channels / static_cast(sizeof( opus_int16 )); - qCDebug(decoder) << "Opus decode: encodedBytes = " << encodedBuffer.length() << "; decodedBufferBytes = " << decodedBuffer.size() << "; frameCount = " << buffer_frames; - int decoded_frames = opus_decode( _decoder, reinterpret_cast(encodedBuffer.data()), encodedBuffer.length(), reinterpret_cast(decodedBuffer.data()), buffer_frames, 0 ); + qCDebug(decoder) << "Opus decode: encodedBytes = " << encodedBuffer.length() << "; decodedBufferBytes = " + << decodedBuffer.size() << "; frameCount = " << buffer_frames; + int decoded_frames = opus_decode( _decoder, reinterpret_cast(encodedBuffer.data()), + encodedBuffer.length(), reinterpret_cast(decodedBuffer.data()), buffer_frames, 0 ); if ( decoded_frames >= 0 ) { //qCDebug(decoder) << "Decoded " << decoded_frames << " Opus frames, " << buffer_frames << " expected"; if ( decoded_frames < buffer_frames ) { - qCWarning(decoder) << "Opus decoder returned " << decoded_frames << ", but " << buffer_frames << " were expected!"; + qCWarning(decoder) << "Opus decoder returned " << decoded_frames << ", but " << buffer_frames + << " were expected!"; int start = decoded_frames * static_cast(sizeof(int16_t)) * _opus_num_channels; memset( &decodedBuffer.data()[start], 0, static_cast(decodedBuffer.length() - start)); } else if ( decoded_frames > buffer_frames ) { // This should never happen - qCCritical(decoder) << "Opus decoder returned " << decoded_frames << ", but only " << buffer_frames << " were expected! Buffer overflow!?"; + qCCritical(decoder) << "Opus decoder returned " << decoded_frames << ", but only " << buffer_frames + << " were expected! Buffer overflow!?"; } } else { qCCritical(decoder) << "Failed to decode audio: " << error_to_string(decoded_frames); @@ -93,23 +108,28 @@ void AthenaOpusDecoder::lostFrame(QByteArray &decodedBuffer) PerformanceTimer perfTimer("AthenaOpusDecoder::lostFrame"); - int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast(sizeof(int16_t)) * _opus_num_channels; + int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast(sizeof(int16_t)) + * _opus_num_channels; decodedBuffer.resize( buffer_size ); int buffer_frames = decodedBuffer.size() / _opus_num_channels / static_cast(sizeof( opus_int16 )); - int decoded_frames = opus_decode( _decoder, nullptr, 0, reinterpret_cast(decodedBuffer.data()), buffer_frames, 1 ); + int decoded_frames = opus_decode( _decoder, nullptr, 0, reinterpret_cast(decodedBuffer.data()), + buffer_frames, 1 ); if ( decoded_frames >= 0 ) { - //qCDebug(decoder) << "Produced " << decoded_frames << " opus frames from a lost frame, " << buffer_frames << " expected"; + //qCDebug(decoder) << "Produced " << decoded_frames << " opus frames from a lost frame, " << buffer_frames + // << " expected"; if ( decoded_frames < buffer_frames ) { - qCWarning(decoder) << "Opus decoder returned " << decoded_frames << ", but " << buffer_frames << " were expected!"; + qCWarning(decoder) << "Opus decoder returned " << decoded_frames << ", but " << buffer_frames + << " were expected!"; int start = decoded_frames * static_cast(sizeof(int16_t)) * _opus_num_channels; memset( &decodedBuffer.data()[start], 0, static_cast(decodedBuffer.length() - start)); } else if ( decoded_frames > buffer_frames ) { // This should never happen - qCCritical(decoder) << "Opus decoder returned " << decoded_frames << ", but only " << buffer_frames << " were expected! Buffer overflow!?"; + qCCritical(decoder) << "Opus decoder returned " << decoded_frames << ", but only " << buffer_frames + << " were expected! Buffer overflow!?"; } } else { qCCritical(decoder) << "Failed to decode lost frame: " << error_to_string(decoded_frames); diff --git a/plugins/opusCodec/src/OpusDecoder.h b/plugins/opusCodec/src/OpusDecoder.h index 0aaadedc7a..01722fcc6c 100644 --- a/plugins/opusCodec/src/OpusDecoder.h +++ b/plugins/opusCodec/src/OpusDecoder.h @@ -1,3 +1,13 @@ +// +// OpusCodecManager.h +// plugins/opusCodec/src +// +// Copyright 2020 Dale Glass +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + #ifndef OPUSDECODER_H #define OPUSDECODER_H diff --git a/plugins/opusCodec/src/OpusEncoder.cpp b/plugins/opusCodec/src/OpusEncoder.cpp index 04af3121db..700164427e 100644 --- a/plugins/opusCodec/src/OpusEncoder.cpp +++ b/plugins/opusCodec/src/OpusEncoder.cpp @@ -1,9 +1,18 @@ +// +// OpusCodecManager.h +// plugins/opusCodec/src +// +// Copyright 2020 Dale Glass +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// #include #include +#include #include "OpusEncoder.h" -#include "opus/opus.h" static QLoggingCategory encoder("AthenaOpusEncoder"); @@ -68,7 +77,8 @@ void AthenaOpusEncoder::encode(const QByteArray& decodedBuffer, QByteArray& enco encodedBuffer.resize( decodedBuffer.size() ); int frame_size = decodedBuffer.length()/ _opus_channels / static_cast(sizeof(opus_int16)); - int bytes = opus_encode(_encoder, reinterpret_cast(decodedBuffer.constData()), frame_size, reinterpret_cast(encodedBuffer.data()), encodedBuffer.size() ); + int bytes = opus_encode(_encoder, reinterpret_cast(decodedBuffer.constData()), frame_size, + reinterpret_cast(encodedBuffer.data()), encodedBuffer.size() ); if ( bytes >= 0 ) { //qCDebug(encoder) << "Encoded " << decodedBuffer.length() << " bytes into " << bytes << " opus bytes"; @@ -76,7 +86,8 @@ void AthenaOpusEncoder::encode(const QByteArray& decodedBuffer, QByteArray& enco } else { encodedBuffer.resize(0); - qCWarning(encoder) << "Error when encoding " << decodedBuffer.length() << " bytes of audio: " << error_to_string(bytes); + qCWarning(encoder) << "Error when encoding " << decodedBuffer.length() << " bytes of audio: " + << error_to_string(bytes); } } @@ -94,8 +105,9 @@ void AthenaOpusEncoder::setComplexity(int complexity) assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_COMPLEXITY(complexity)); - if ( ret != OPUS_OK ) + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting complexity to " << complexity << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getBitrate() const @@ -110,8 +122,10 @@ void AthenaOpusEncoder::setBitrate(int bitrate) { assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_BITRATE(bitrate)); - if ( ret != OPUS_OK ) + + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting bitrate to " << bitrate << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getVBR() const @@ -126,8 +140,10 @@ void AthenaOpusEncoder::setVBR(int vbr) { assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR(vbr)); - if ( ret != OPUS_OK ) + + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting VBR to " << vbr << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getVBRConstraint() const @@ -142,8 +158,10 @@ void AthenaOpusEncoder::setVBRConstraint(int vbr_const) { assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR_CONSTRAINT(vbr_const)); - if ( ret != OPUS_OK ) + + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting VBR constraint to " << vbr_const << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getMaxBandwidth() const @@ -158,8 +176,10 @@ void AthenaOpusEncoder::setMaxBandwidth(int maxbw) { assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_MAX_BANDWIDTH(maxbw)); - if ( ret != OPUS_OK ) + + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting max bandwidth to " << maxbw << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getBandwidth() const @@ -174,8 +194,10 @@ void AthenaOpusEncoder::setBandwidth(int bw) { assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_BANDWIDTH(bw)); - if ( ret != OPUS_OK ) + + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting bandwidth to " << bw << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getSignal() const @@ -190,8 +212,10 @@ void AthenaOpusEncoder::setSignal(int signal) { assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_SIGNAL(signal)); - if ( ret != OPUS_OK ) + + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting signal to " << signal << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getApplication() const @@ -202,12 +226,14 @@ int AthenaOpusEncoder::getApplication() const return ret; } -void AthenaOpusEncoder::setApplication(int app) +void AthenaOpusEncoder::setApplication(int application) { assert(_encoder); - int ret = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(app)); - if ( ret != OPUS_OK ) - qCWarning(encoder) << "Error when setting application to " << app << ": " << error_to_string(ret); + int ret = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(application)); + + if (ret != OPUS_OK) { + qCWarning(encoder) << "Error when setting application to " << application << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getLookahead() const @@ -230,8 +256,10 @@ void AthenaOpusEncoder::setInbandFEC(int fec) { assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_INBAND_FEC(fec)); - if ( ret != OPUS_OK ) + + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting inband FEC to " << fec << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getExpectedPacketLossPercent() const @@ -246,8 +274,10 @@ void AthenaOpusEncoder::setExpectedPacketLossPercent(int perc) { assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_PACKET_LOSS_PERC(perc)); - if ( ret != OPUS_OK ) + + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting loss percent to " << perc << ": " << error_to_string(ret); + } } int AthenaOpusEncoder::getDTX() const @@ -262,8 +292,8 @@ void AthenaOpusEncoder::setDTX(int dtx) { assert(_encoder); int ret = opus_encoder_ctl(_encoder, OPUS_SET_DTX(dtx)); - if ( ret != OPUS_OK ) + + if (ret != OPUS_OK) { qCWarning(encoder) << "Error when setting DTX to " << dtx << ": " << error_to_string(ret); -} - - + } +} \ No newline at end of file diff --git a/plugins/opusCodec/src/OpusEncoder.h b/plugins/opusCodec/src/OpusEncoder.h index b456f76093..920423a96d 100644 --- a/plugins/opusCodec/src/OpusEncoder.h +++ b/plugins/opusCodec/src/OpusEncoder.h @@ -1,7 +1,17 @@ +// +// OpusCodecManager.h +// plugins/opusCodec/src +// +// Copyright 2020 Dale Glass +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + #ifndef OPUSENCODER_H #define OPUSENCODER_H #include -#include "opus/opus.h" +#include class AthenaOpusEncoder : public Encoder { @@ -61,7 +71,7 @@ private: int _opus_expected_loss = 0; - OpusEncoder *_encoder = nullptr; + OpusEncoder* _encoder = nullptr; };