History

Made changes requested by reviewer

Fixed missing copyright headers. Fixed exceeding 120 columns. Fixed #include Fixed if conditional style. Fixed C++ reference symbol placement.

Marcus Llewellyn committed 6 years ago

Commit 24669c91 parent f23dfc74 files · +102 −32Browse files

Showing the changes to plugins/opusCodec/src/OpusEncoder.cpp (1 of 4 files). Show all

Unified · Split

plugins/opusCodec/src/OpusEncoder.cpp+50−20
@@ -1,9 +1,18 @@
1//
2// OpusCodecManager.h
3// plugins/opusCodec/src
4//
5// Copyright 2020 Dale Glass
6//
7// Distributed under the Apache License, Version 2.0.
8// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9//
1 10
2#include <PerfStat.h>11#include <PerfStat.h>
3#include <QtCore/QLoggingCategory>12#include <QtCore/QLoggingCategory>
13#include <opus/opus.h>
4 14
5#include "OpusEncoder.h"15#include "OpusEncoder.h"
6#include "opus/opus.h"
7 16
8static QLoggingCategory encoder("AthenaOpusEncoder");17static QLoggingCategory encoder("AthenaOpusEncoder");
9 18
@@ -68,7 +77,8 @@ void AthenaOpusEncoder::encode(const QByteArray& decodedBuffer, QByteArray& enco · 58 unmodified lines
68 encodedBuffer.resize( decodedBuffer.size() );77 encodedBuffer.resize( decodedBuffer.size() );
69 int frame_size = decodedBuffer.length()/ _opus_channels / static_cast<int>(sizeof(opus_int16));78 int frame_size = decodedBuffer.length()/ _opus_channels / static_cast<int>(sizeof(opus_int16));
70 79
71 int bytes = opus_encode(_encoder, reinterpret_cast<const opus_int16*>(decodedBuffer.constData()), frame_size, reinterpret_cast<unsigned char*>(encodedBuffer.data()), encodedBuffer.size() );80 int bytes = opus_encode(_encoder, reinterpret_cast<const opus_int16*>(decodedBuffer.constData()), frame_size,
81 reinterpret_cast<unsigned char*>(encodedBuffer.data()), encodedBuffer.size() );
72 82
73 if ( bytes >= 0 ) {83 if ( bytes >= 0 ) {
74 //qCDebug(encoder) << "Encoded " << decodedBuffer.length() << " bytes into " << bytes << " opus bytes";84 //qCDebug(encoder) << "Encoded " << decodedBuffer.length() << " bytes into " << bytes << " opus bytes";
@@ -76,7 +86,8 @@ void AthenaOpusEncoder::encode(const QByteArray& decodedBuffer, QByteArray& enco · 1 unmodified line
76 } else {86 } else {
77 encodedBuffer.resize(0);87 encodedBuffer.resize(0);
78 88
79 qCWarning(encoder) << "Error when encoding " << decodedBuffer.length() << " bytes of audio: " << error_to_string(bytes);89 qCWarning(encoder) << "Error when encoding " << decodedBuffer.length() << " bytes of audio: "
90 << error_to_string(bytes);
80 }91 }
81 92
82}93}
@@ -94,8 +105,9 @@ void AthenaOpusEncoder::setComplexity(int complexity) · 11 unmodified lines
94 assert(_encoder);105 assert(_encoder);
95 int ret = opus_encoder_ctl(_encoder, OPUS_SET_COMPLEXITY(complexity));106 int ret = opus_encoder_ctl(_encoder, OPUS_SET_COMPLEXITY(complexity));
96 107
97 if ( ret != OPUS_OK )108 if (ret != OPUS_OK) {
98 qCWarning(encoder) << "Error when setting complexity to " << complexity << ": " << error_to_string(ret);109 qCWarning(encoder) << "Error when setting complexity to " << complexity << ": " << error_to_string(ret);
110 }
99}111}
100 112
101int AthenaOpusEncoder::getBitrate() const113int AthenaOpusEncoder::getBitrate() const
@@ -110,8 +122,10 @@ void AthenaOpusEncoder::setBitrate(int bitrate) · 8 unmodified lines
110{122{
111 assert(_encoder);123 assert(_encoder);
112 int ret = opus_encoder_ctl(_encoder, OPUS_SET_BITRATE(bitrate));124 int ret = opus_encoder_ctl(_encoder, OPUS_SET_BITRATE(bitrate));
113 if ( ret != OPUS_OK )125
126 if (ret != OPUS_OK) {
114 qCWarning(encoder) << "Error when setting bitrate to " << bitrate << ": " << error_to_string(ret);127 qCWarning(encoder) << "Error when setting bitrate to " << bitrate << ": " << error_to_string(ret);
128 }
115}129}
116 130
117int AthenaOpusEncoder::getVBR() const131int AthenaOpusEncoder::getVBR() const
@@ -126,8 +140,10 @@ void AthenaOpusEncoder::setVBR(int vbr) · 8 unmodified lines
126{140{
127 assert(_encoder);141 assert(_encoder);
128 int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR(vbr));142 int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR(vbr));
129 if ( ret != OPUS_OK )143
144 if (ret != OPUS_OK) {
130 qCWarning(encoder) << "Error when setting VBR to " << vbr << ": " << error_to_string(ret);145 qCWarning(encoder) << "Error when setting VBR to " << vbr << ": " << error_to_string(ret);
146 }
131}147}
132 148
133int AthenaOpusEncoder::getVBRConstraint() const149int AthenaOpusEncoder::getVBRConstraint() const
@@ -142,8 +158,10 @@ void AthenaOpusEncoder::setVBRConstraint(int vbr_const) · 8 unmodified lines
142{158{
143 assert(_encoder);159 assert(_encoder);
144 int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR_CONSTRAINT(vbr_const));160 int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR_CONSTRAINT(vbr_const));
145 if ( ret != OPUS_OK )161
162 if (ret != OPUS_OK) {
146 qCWarning(encoder) << "Error when setting VBR constraint to " << vbr_const << ": " << error_to_string(ret);163 qCWarning(encoder) << "Error when setting VBR constraint to " << vbr_const << ": " << error_to_string(ret);
164 }
147}165}
148 166
149int AthenaOpusEncoder::getMaxBandwidth() const167int AthenaOpusEncoder::getMaxBandwidth() const
@@ -158,8 +176,10 @@ void AthenaOpusEncoder::setMaxBandwidth(int maxbw) · 8 unmodified lines
158{176{
159 assert(_encoder);177 assert(_encoder);
160 int ret = opus_encoder_ctl(_encoder, OPUS_SET_MAX_BANDWIDTH(maxbw));178 int ret = opus_encoder_ctl(_encoder, OPUS_SET_MAX_BANDWIDTH(maxbw));
161 if ( ret != OPUS_OK )179
180 if (ret != OPUS_OK) {
162 qCWarning(encoder) << "Error when setting max bandwidth to " << maxbw << ": " << error_to_string(ret);181 qCWarning(encoder) << "Error when setting max bandwidth to " << maxbw << ": " << error_to_string(ret);
182 }
163}183}
164 184
165int AthenaOpusEncoder::getBandwidth() const185int AthenaOpusEncoder::getBandwidth() const
@@ -174,8 +194,10 @@ void AthenaOpusEncoder::setBandwidth(int bw) · 8 unmodified lines
174{194{
175 assert(_encoder);195 assert(_encoder);
176 int ret = opus_encoder_ctl(_encoder, OPUS_SET_BANDWIDTH(bw));196 int ret = opus_encoder_ctl(_encoder, OPUS_SET_BANDWIDTH(bw));
177 if ( ret != OPUS_OK )197
198 if (ret != OPUS_OK) {
178 qCWarning(encoder) << "Error when setting bandwidth to " << bw << ": " << error_to_string(ret);199 qCWarning(encoder) << "Error when setting bandwidth to " << bw << ": " << error_to_string(ret);
200 }
179}201}
180 202
181int AthenaOpusEncoder::getSignal() const203int AthenaOpusEncoder::getSignal() const
@@ -190,8 +212,10 @@ void AthenaOpusEncoder::setSignal(int signal) · 8 unmodified lines
190{212{
191 assert(_encoder);213 assert(_encoder);
192 int ret = opus_encoder_ctl(_encoder, OPUS_SET_SIGNAL(signal));214 int ret = opus_encoder_ctl(_encoder, OPUS_SET_SIGNAL(signal));
193 if ( ret != OPUS_OK )215
216 if (ret != OPUS_OK) {
194 qCWarning(encoder) << "Error when setting signal to " << signal << ": " << error_to_string(ret);217 qCWarning(encoder) << "Error when setting signal to " << signal << ": " << error_to_string(ret);
218 }
195}219}
196 220
197int AthenaOpusEncoder::getApplication() const221int AthenaOpusEncoder::getApplication() const
@@ -202,12 +226,14 @@ int AthenaOpusEncoder::getApplication() const · 4 unmodified lines
202 return ret;226 return ret;
203}227}
204 228
205void AthenaOpusEncoder::setApplication(int app)229void AthenaOpusEncoder::setApplication(int application)
206{230{
207 assert(_encoder);231 assert(_encoder);
208 int ret = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(app));232 int ret = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(application));
209 if ( ret != OPUS_OK )233
210 qCWarning(encoder) << "Error when setting application to " << app << ": " << error_to_string(ret);234 if (ret != OPUS_OK) {
235 qCWarning(encoder) << "Error when setting application to " << application << ": " << error_to_string(ret);
236 }
211}237}
212 238
213int AthenaOpusEncoder::getLookahead() const239int AthenaOpusEncoder::getLookahead() const
@@ -230,8 +256,10 @@ void AthenaOpusEncoder::setInbandFEC(int fec) · 16 unmodified lines
230{256{
231 assert(_encoder);257 assert(_encoder);
232 int ret = opus_encoder_ctl(_encoder, OPUS_SET_INBAND_FEC(fec));258 int ret = opus_encoder_ctl(_encoder, OPUS_SET_INBAND_FEC(fec));
233 if ( ret != OPUS_OK )259
260 if (ret != OPUS_OK) {
234 qCWarning(encoder) << "Error when setting inband FEC to " << fec << ": " << error_to_string(ret);261 qCWarning(encoder) << "Error when setting inband FEC to " << fec << ": " << error_to_string(ret);
262 }
235}263}
236 264
237int AthenaOpusEncoder::getExpectedPacketLossPercent() const265int AthenaOpusEncoder::getExpectedPacketLossPercent() const
@@ -246,8 +274,10 @@ void AthenaOpusEncoder::setExpectedPacketLossPercent(int perc) · 8 unmodified lines
246{274{
247 assert(_encoder);275 assert(_encoder);
248 int ret = opus_encoder_ctl(_encoder, OPUS_SET_PACKET_LOSS_PERC(perc));276 int ret = opus_encoder_ctl(_encoder, OPUS_SET_PACKET_LOSS_PERC(perc));
249 if ( ret != OPUS_OK )277
278 if (ret != OPUS_OK) {
250 qCWarning(encoder) << "Error when setting loss percent to " << perc << ": " << error_to_string(ret);279 qCWarning(encoder) << "Error when setting loss percent to " << perc << ": " << error_to_string(ret);
280 }
251}281}
252 282
253int AthenaOpusEncoder::getDTX() const283int AthenaOpusEncoder::getDTX() const
@@ -262,8 +292,8 @@ void AthenaOpusEncoder::setDTX(int dtx) · 8 unmodified lines
262{292{
263 assert(_encoder);293 assert(_encoder);
264 int ret = opus_encoder_ctl(_encoder, OPUS_SET_DTX(dtx));294 int ret = opus_encoder_ctl(_encoder, OPUS_SET_DTX(dtx));
265 if ( ret != OPUS_OK )
266 qCWarning(encoder) << "Error when setting DTX to " << dtx << ": " << error_to_string(ret);
267}
268
269 295
296 if (ret != OPUS_OK) {
297 qCWarning(encoder) << "Error when setting DTX to " << dtx << ": " << error_to_string(ret);
298 }
299}