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+//
110
211 #include <PerfStat.h>
312 #include <QtCore/QLoggingCategory>
13+#include <opus/opus.h>
414
515 #include "OpusEncoder.h"
6−#include "opus/opus.h"
716
817 static QLoggingCategory encoder("AthenaOpusEncoder");
918
@@ -68,7 +77,8 @@ void AthenaOpusEncoder::encode(const QByteArray& decodedBuffer, QByteArray& enco · 58 unmodified lines
6877 encodedBuffer.resize( decodedBuffer.size() );
6978 int frame_size = decodedBuffer.length()/ _opus_channels / static_cast<int>(sizeof(opus_int16));
7079
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() );
7282
7383 if ( bytes >= 0 ) {
7484 //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
7686 } else {
7787 encodedBuffer.resize(0);
7888
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);
8091 }
8192
8293 }
@@ -94,8 +105,9 @@ void AthenaOpusEncoder::setComplexity(int complexity) · 11 unmodified lines
94105 assert(_encoder);
95106 int ret = opus_encoder_ctl(_encoder, OPUS_SET_COMPLEXITY(complexity));
96107
97− if ( ret != OPUS_OK )
108+ if (ret != OPUS_OK) {
98109 qCWarning(encoder) << "Error when setting complexity to " << complexity << ": " << error_to_string(ret);
110+ }
99111 }
100112
101113 int AthenaOpusEncoder::getBitrate() const
@@ -110,8 +122,10 @@ void AthenaOpusEncoder::setBitrate(int bitrate) · 8 unmodified lines
110122 {
111123 assert(_encoder);
112124 int ret = opus_encoder_ctl(_encoder, OPUS_SET_BITRATE(bitrate));
113− if ( ret != OPUS_OK )
125+
126+ if (ret != OPUS_OK) {
114127 qCWarning(encoder) << "Error when setting bitrate to " << bitrate << ": " << error_to_string(ret);
128+ }
115129 }
116130
117131 int AthenaOpusEncoder::getVBR() const
@@ -126,8 +140,10 @@ void AthenaOpusEncoder::setVBR(int vbr) · 8 unmodified lines
126140 {
127141 assert(_encoder);
128142 int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR(vbr));
129− if ( ret != OPUS_OK )
143+
144+ if (ret != OPUS_OK) {
130145 qCWarning(encoder) << "Error when setting VBR to " << vbr << ": " << error_to_string(ret);
146+ }
131147 }
132148
133149 int AthenaOpusEncoder::getVBRConstraint() const
@@ -142,8 +158,10 @@ void AthenaOpusEncoder::setVBRConstraint(int vbr_const) · 8 unmodified lines
142158 {
143159 assert(_encoder);
144160 int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR_CONSTRAINT(vbr_const));
145− if ( ret != OPUS_OK )
161+
162+ if (ret != OPUS_OK) {
146163 qCWarning(encoder) << "Error when setting VBR constraint to " << vbr_const << ": " << error_to_string(ret);
164+ }
147165 }
148166
149167 int AthenaOpusEncoder::getMaxBandwidth() const
@@ -158,8 +176,10 @@ void AthenaOpusEncoder::setMaxBandwidth(int maxbw) · 8 unmodified lines
158176 {
159177 assert(_encoder);
160178 int ret = opus_encoder_ctl(_encoder, OPUS_SET_MAX_BANDWIDTH(maxbw));
161− if ( ret != OPUS_OK )
179+
180+ if (ret != OPUS_OK) {
162181 qCWarning(encoder) << "Error when setting max bandwidth to " << maxbw << ": " << error_to_string(ret);
182+ }
163183 }
164184
165185 int AthenaOpusEncoder::getBandwidth() const
@@ -174,8 +194,10 @@ void AthenaOpusEncoder::setBandwidth(int bw) · 8 unmodified lines
174194 {
175195 assert(_encoder);
176196 int ret = opus_encoder_ctl(_encoder, OPUS_SET_BANDWIDTH(bw));
177− if ( ret != OPUS_OK )
197+
198+ if (ret != OPUS_OK) {
178199 qCWarning(encoder) << "Error when setting bandwidth to " << bw << ": " << error_to_string(ret);
200+ }
179201 }
180202
181203 int AthenaOpusEncoder::getSignal() const
@@ -190,8 +212,10 @@ void AthenaOpusEncoder::setSignal(int signal) · 8 unmodified lines
190212 {
191213 assert(_encoder);
192214 int ret = opus_encoder_ctl(_encoder, OPUS_SET_SIGNAL(signal));
193− if ( ret != OPUS_OK )
215+
216+ if (ret != OPUS_OK) {
194217 qCWarning(encoder) << "Error when setting signal to " << signal << ": " << error_to_string(ret);
218+ }
195219 }
196220
197221 int AthenaOpusEncoder::getApplication() const
@@ -202,12 +226,14 @@ int AthenaOpusEncoder::getApplication() const · 4 unmodified lines
202226 return ret;
203227 }
204228
205−void AthenaOpusEncoder::setApplication(int app)
229+void AthenaOpusEncoder::setApplication(int application)
206230 {
207231 assert(_encoder);
208− int ret = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(app));
209− if ( ret != OPUS_OK )
210− qCWarning(encoder) << "Error when setting application to " << app << ": " << error_to_string(ret);
232+ int ret = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(application));
233+
234+ if (ret != OPUS_OK) {
235+ qCWarning(encoder) << "Error when setting application to " << application << ": " << error_to_string(ret);
236+ }
211237 }
212238
213239 int AthenaOpusEncoder::getLookahead() const
@@ -230,8 +256,10 @@ void AthenaOpusEncoder::setInbandFEC(int fec) · 16 unmodified lines
230256 {
231257 assert(_encoder);
232258 int ret = opus_encoder_ctl(_encoder, OPUS_SET_INBAND_FEC(fec));
233− if ( ret != OPUS_OK )
259+
260+ if (ret != OPUS_OK) {
234261 qCWarning(encoder) << "Error when setting inband FEC to " << fec << ": " << error_to_string(ret);
262+ }
235263 }
236264
237265 int AthenaOpusEncoder::getExpectedPacketLossPercent() const
@@ -246,8 +274,10 @@ void AthenaOpusEncoder::setExpectedPacketLossPercent(int perc) · 8 unmodified lines
246274 {
247275 assert(_encoder);
248276 int ret = opus_encoder_ctl(_encoder, OPUS_SET_PACKET_LOSS_PERC(perc));
249− if ( ret != OPUS_OK )
277+
278+ if (ret != OPUS_OK) {
250279 qCWarning(encoder) << "Error when setting loss percent to " << perc << ": " << error_to_string(ret);
280+ }
251281 }
252282
253283 int AthenaOpusEncoder::getDTX() const
@@ -262,8 +292,8 @@ void AthenaOpusEncoder::setDTX(int dtx) · 8 unmodified lines
262292 {
263293 assert(_encoder);
264294 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−
269295
296+ if (ret != OPUS_OK) {
297+ qCWarning(encoder) << "Error when setting DTX to " << dtx << ": " << error_to_string(ret);
298+ }
299+}