History

More review fixes since I missed 66 of them.

Marcus Llewellyn committed 6 years ago

Commit 9a67ee11 parent 24669c94 files · +178 −212Browse files

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

Unified · Split

plugins/opusCodec/src/OpusEncoder.cpp+119−145
@@ -16,40 +16,39 @@ · 15 unmodified lines
1616
1717 static QLoggingCategory encoder("AthenaOpusEncoder");
1818
19−static QString error_to_string(int error) {
19+static QString errorToString(int error) {
2020 switch (error) {
21− case OPUS_OK:
22− return "OK";
23− case OPUS_BAD_ARG:
24− return "One or more invalid/out of range arguments.";
25− case OPUS_BUFFER_TOO_SMALL:
26− return "The mode struct passed is invalid.";
27− case OPUS_INTERNAL_ERROR:
28− return "An internal error was detected.";
29− case OPUS_INVALID_PACKET:
30− return "The compressed data passed is corrupted.";
31− case OPUS_UNIMPLEMENTED:
32− return "Invalid/unsupported request number.";
33− case OPUS_INVALID_STATE:
34− return "An encoder or decoder structure is invalid or already freed.";
35− default:
36− return QString("Unknown error code: %i").arg(error);
21+ case OPUS_OK:
22+ return "OK";
23+ case OPUS_BAD_ARG:
24+ return "One or more invalid/out of range arguments.";
25+ case OPUS_BUFFER_TOO_SMALL:
26+ return "The mode struct passed is invalid.";
27+ case OPUS_INTERNAL_ERROR:
28+ return "An internal error was detected.";
29+ case OPUS_INVALID_PACKET:
30+ return "The compressed data passed is corrupted.";
31+ case OPUS_UNIMPLEMENTED:
32+ return "Invalid/unsupported request number.";
33+ case OPUS_INVALID_STATE:
34+ return "An encoder or decoder structure is invalid or already freed.";
35+ default:
36+ return QString("Unknown error code: %i").arg(error);
3737 }
3838 }
3939
4040
4141
42−AthenaOpusEncoder::AthenaOpusEncoder(int sampleRate, int numChannels)
43−{
44− _opus_sample_rate = sampleRate;
45− _opus_channels = numChannels;
42+AthenaOpusEncoder::AthenaOpusEncoder(int sampleRate, int numChannels) {
43+ _opusSampleRate = sampleRate;
44+ _opusChannels = numChannels;
4645
4746 int error;
4847
4948 _encoder = opus_encoder_create(sampleRate, numChannels, DEFAULT_APPLICATION, &error);
5049
51− if ( error != OPUS_OK ) {
52− qCCritical(encoder) << "Failed to initialize Opus encoder: " << error_to_string(error);
50+ if (error != OPUS_OK) {
51+ qCCritical(encoder) << "Failed to initialize Opus encoder: " << errorToString(error);
5352 _encoder = nullptr;
5453 return;
5554 }
@@ -62,8 +61,7 @@ AthenaOpusEncoder::AthenaOpusEncoder(int sampleRate, int numChannels) · 6 unmodified lines
6261 qCDebug(encoder) << "Opus encoder initialized, sampleRate = " << sampleRate << "; numChannels = " << numChannels;
6362 }
6463
65−AthenaOpusEncoder::~AthenaOpusEncoder()
66−{
64+AthenaOpusEncoder::~AthenaOpusEncoder() {
6765 opus_encoder_destroy(_encoder);
6866 }
6967
@@ -75,225 +73,201 @@ void AthenaOpusEncoder::encode(const QByteArray& decodedBuffer, QByteArray& enco · 5 unmodified lines
7573 assert(_encoder);
7674
7775 encodedBuffer.resize( decodedBuffer.size() );
78− int frame_size = decodedBuffer.length()/ _opus_channels / static_cast<int>(sizeof(opus_int16));
76+ int frameSize = decodedBuffer.length()/ _opusChannels / static_cast<int>(sizeof(opus_int16));
7977
80− int bytes = opus_encode(_encoder, reinterpret_cast<const opus_int16*>(decodedBuffer.constData()), frame_size,
78+ int bytes = opus_encode(_encoder, reinterpret_cast<const opus_int16*>(decodedBuffer.constData()), frameSize,
8179 reinterpret_cast<unsigned char*>(encodedBuffer.data()), encodedBuffer.size() );
8280
83− if ( bytes >= 0 ) {
84− //qCDebug(encoder) << "Encoded " << decodedBuffer.length() << " bytes into " << bytes << " opus bytes";
81+ if (bytes >= 0) {
8582 encodedBuffer.resize(bytes);
8683 } else {
8784 encodedBuffer.resize(0);
8885
8986 qCWarning(encoder) << "Error when encoding " << decodedBuffer.length() << " bytes of audio: "
90− << error_to_string(bytes);
87+ << errorToString(bytes);
9188 }
9289
9390 }
9491
95−int AthenaOpusEncoder::getComplexity() const
96−{
92+int AthenaOpusEncoder::getComplexity() const {
9793 assert(_encoder);
98− int ret;
99− opus_encoder_ctl(_encoder, OPUS_GET_COMPLEXITY(&ret));
100− return ret;
94+ int returnValue;
95+ opus_encoder_ctl(_encoder, OPUS_GET_COMPLEXITY(&returnValue));
96+ return returnValue;
10197 }
10298
103−void AthenaOpusEncoder::setComplexity(int complexity)
104−{
99+void AthenaOpusEncoder::setComplexity(int complexity) {
105100 assert(_encoder);
106− int ret = opus_encoder_ctl(_encoder, OPUS_SET_COMPLEXITY(complexity));
101+ int returnValue = opus_encoder_ctl(_encoder, OPUS_SET_COMPLEXITY(complexity));
107102
108− if (ret != OPUS_OK) {
109− qCWarning(encoder) << "Error when setting complexity to " << complexity << ": " << error_to_string(ret);
103+ if (returnValue != OPUS_OK) {
104+ qCWarning(encoder) << "Error when setting complexity to " << complexity << ": " << errorToString(returnValue);
110105 }
111106 }
112107
113−int AthenaOpusEncoder::getBitrate() const
114−{
108+int AthenaOpusEncoder::getBitrate() const {
115109 assert(_encoder);
116− int ret;
117− opus_encoder_ctl(_encoder, OPUS_GET_BITRATE(&ret));
118− return ret;
110+ int returnValue;
111+ opus_encoder_ctl(_encoder, OPUS_GET_BITRATE(&returnValue));
112+ return returnValue;
119113 }
120114
121−void AthenaOpusEncoder::setBitrate(int bitrate)
122−{
115+void AthenaOpusEncoder::setBitrate(int bitrate) {
123116 assert(_encoder);
124− int ret = opus_encoder_ctl(_encoder, OPUS_SET_BITRATE(bitrate));
117+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_BITRATE(bitrate));
125118
126− if (ret != OPUS_OK) {
127− qCWarning(encoder) << "Error when setting bitrate to " << bitrate << ": " << error_to_string(ret);
119+ if (errorCode != OPUS_OK) {
120+ qCWarning(encoder) << "Error when setting bitrate to " << bitrate << ": " << errorToString(errorCode);
128121 }
129122 }
130123
131−int AthenaOpusEncoder::getVBR() const
132−{
124+int AthenaOpusEncoder::getVBR() const {
133125 assert(_encoder);
134− int ret;
135− opus_encoder_ctl(_encoder, OPUS_GET_VBR(&ret));
136− return ret;
126+ int returnValue;
127+ opus_encoder_ctl(_encoder, OPUS_GET_VBR(&returnValue));
128+ return returnValue;
137129 }
138130
139−void AthenaOpusEncoder::setVBR(int vbr)
140−{
131+void AthenaOpusEncoder::setVBR(int vbr) {
141132 assert(_encoder);
142− int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR(vbr));
133+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_VBR(vbr));
143134
144− if (ret != OPUS_OK) {
145− qCWarning(encoder) << "Error when setting VBR to " << vbr << ": " << error_to_string(ret);
135+ if (errorCode != OPUS_OK) {
136+ qCWarning(encoder) << "Error when setting VBR to " << vbr << ": " << errorToString(errorCode);
146137 }
147138 }
148139
149−int AthenaOpusEncoder::getVBRConstraint() const
150−{
140+int AthenaOpusEncoder::getVBRConstraint() const {
151141 assert(_encoder);
152− int ret;
153− opus_encoder_ctl(_encoder, OPUS_GET_VBR_CONSTRAINT(&ret));
154− return ret;
142+ int returnValue;
143+ opus_encoder_ctl(_encoder, OPUS_GET_VBR_CONSTRAINT(&returnValue));
144+ return returnValue;
155145 }
156146
157−void AthenaOpusEncoder::setVBRConstraint(int vbr_const)
158−{
147+void AthenaOpusEncoder::setVBRConstraint(int vbr_const) {
159148 assert(_encoder);
160− int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR_CONSTRAINT(vbr_const));
149+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_VBR_CONSTRAINT(vbr_const));
161150
162− if (ret != OPUS_OK) {
163− qCWarning(encoder) << "Error when setting VBR constraint to " << vbr_const << ": " << error_to_string(ret);
151+ if (errorCode != OPUS_OK) {
152+ qCWarning(encoder) << "Error when setting VBR constraint to " << vbr_const << ": " << errorToString(errorCode);
164153 }
165154 }
166155
167−int AthenaOpusEncoder::getMaxBandwidth() const
168−{
156+int AthenaOpusEncoder::getMaxBandwidth() const {
169157 assert(_encoder);
170− int ret;
171− opus_encoder_ctl(_encoder, OPUS_GET_MAX_BANDWIDTH(&ret));
172− return ret;
158+ int returnValue;
159+ opus_encoder_ctl(_encoder, OPUS_GET_MAX_BANDWIDTH(&returnValue));
160+ return returnValue;
173161 }
174162
175−void AthenaOpusEncoder::setMaxBandwidth(int maxbw)
176−{
163+void AthenaOpusEncoder::setMaxBandwidth(int maxbw) {
177164 assert(_encoder);
178− int ret = opus_encoder_ctl(_encoder, OPUS_SET_MAX_BANDWIDTH(maxbw));
165+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_MAX_BANDWIDTH(maxbw));
179166
180− if (ret != OPUS_OK) {
181− qCWarning(encoder) << "Error when setting max bandwidth to " << maxbw << ": " << error_to_string(ret);
167+ if (errorCode != OPUS_OK) {
168+ qCWarning(encoder) << "Error when setting max bandwidth to " << maxbw << ": " << errorToString(errorCode);
182169 }
183170 }
184171
185−int AthenaOpusEncoder::getBandwidth() const
186−{
172+int AthenaOpusEncoder::getBandwidth() const {
187173 assert(_encoder);
188− int ret;
189− opus_encoder_ctl(_encoder, OPUS_GET_BANDWIDTH(&ret));
190− return ret;
174+ int bandwidth;
175+ opus_encoder_ctl(_encoder, OPUS_GET_BANDWIDTH(&bandwidth));
176+ return bandwidth;
191177 }
192178
193−void AthenaOpusEncoder::setBandwidth(int bw)
194−{
179+void AthenaOpusEncoder::setBandwidth(int bandwidth) {
195180 assert(_encoder);
196− int ret = opus_encoder_ctl(_encoder, OPUS_SET_BANDWIDTH(bw));
181+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_BANDWIDTH(bandwidth));
197182
198− if (ret != OPUS_OK) {
199− qCWarning(encoder) << "Error when setting bandwidth to " << bw << ": " << error_to_string(ret);
183+ if (errorCode != OPUS_OK) {
184+ qCWarning(encoder) << "Error when setting bandwidth to " << bandwidth << ": " << errorToString(errorCode);
200185 }
201186 }
202187
203−int AthenaOpusEncoder::getSignal() const
204−{
188+int AthenaOpusEncoder::getSignal() const {
205189 assert(_encoder);
206− int ret;
207− opus_encoder_ctl(_encoder, OPUS_GET_SIGNAL(&ret));
208− return ret;
190+ int signal;
191+ opus_encoder_ctl(_encoder, OPUS_GET_SIGNAL(&signal));
192+ return signal;
209193 }
210194
211−void AthenaOpusEncoder::setSignal(int signal)
212−{
195+void AthenaOpusEncoder::setSignal(int signal) {
213196 assert(_encoder);
214− int ret = opus_encoder_ctl(_encoder, OPUS_SET_SIGNAL(signal));
197+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_SIGNAL(signal));
215198
216− if (ret != OPUS_OK) {
217− qCWarning(encoder) << "Error when setting signal to " << signal << ": " << error_to_string(ret);
199+ if (errorCode != OPUS_OK) {
200+ qCWarning(encoder) << "Error when setting signal to " << signal << ": " << errorToString(errorCode);
218201 }
219202 }
220203
221−int AthenaOpusEncoder::getApplication() const
222−{
204+int AthenaOpusEncoder::getApplication() const {
223205 assert(_encoder);
224− int ret;
225− opus_encoder_ctl(_encoder, OPUS_GET_APPLICATION(&ret));
226− return ret;
206+ int applicationValue;
207+ opus_encoder_ctl(_encoder, OPUS_GET_APPLICATION(&applicationValue));
208+ return applicationValue;
227209 }
228210
229−void AthenaOpusEncoder::setApplication(int application)
230−{
211+void AthenaOpusEncoder::setApplication(int application) {
231212 assert(_encoder);
232− int ret = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(application));
213+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(application));
233214
234− if (ret != OPUS_OK) {
235− qCWarning(encoder) << "Error when setting application to " << application << ": " << error_to_string(ret);
215+ if (errorCode != OPUS_OK) {
216+ qCWarning(encoder) << "Error when setting application to " << application << ": " << errorToString(errorCode);
236217 }
237218 }
238219
239−int AthenaOpusEncoder::getLookahead() const
240−{
220+int AthenaOpusEncoder::getLookahead() const {
241221 assert(_encoder);
242− int ret;
243− opus_encoder_ctl(_encoder, OPUS_GET_LOOKAHEAD(&ret));
244− return ret;
222+ int lookAhead;
223+ opus_encoder_ctl(_encoder, OPUS_GET_LOOKAHEAD(&lookAhead));
224+ return lookAhead;
245225 }
246226
247−int AthenaOpusEncoder::getInbandFEC() const
248−{
227+int AthenaOpusEncoder::getInbandFEC() const {
249228 assert(_encoder);
250− int ret;
251− opus_encoder_ctl(_encoder, OPUS_GET_INBAND_FEC(&ret));
252− return ret;
229+ int fec;
230+ opus_encoder_ctl(_encoder, OPUS_GET_INBAND_FEC(&fec));
231+ return fec;
253232 }
254233
255−void AthenaOpusEncoder::setInbandFEC(int fec)
256−{
234+void AthenaOpusEncoder::setInbandFEC(int fec) {
257235 assert(_encoder);
258− int ret = opus_encoder_ctl(_encoder, OPUS_SET_INBAND_FEC(fec));
236+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_INBAND_FEC(fec));
259237
260− if (ret != OPUS_OK) {
261− qCWarning(encoder) << "Error when setting inband FEC to " << fec << ": " << error_to_string(ret);
238+ if (errorCode != OPUS_OK) {
239+ qCWarning(encoder) << "Error when setting inband FEC to " << fec << ": " << errorToString(errorCode);
262240 }
263241 }
264242
265−int AthenaOpusEncoder::getExpectedPacketLossPercent() const
266−{
243+int AthenaOpusEncoder::getExpectedPacketLossPercent() const {
267244 assert(_encoder);
268− int ret;
269− opus_encoder_ctl(_encoder, OPUS_GET_PACKET_LOSS_PERC(&ret));
270− return ret;
245+ int lossPercentage;
246+ opus_encoder_ctl(_encoder, OPUS_GET_PACKET_LOSS_PERC(&lossPercentage));
247+ return lossPercentage;
271248 }
272249
273−void AthenaOpusEncoder::setExpectedPacketLossPercent(int perc)
274−{
250+void AthenaOpusEncoder::setExpectedPacketLossPercentage(int percent) {
275251 assert(_encoder);
276− int ret = opus_encoder_ctl(_encoder, OPUS_SET_PACKET_LOSS_PERC(perc));
252+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_PACKET_LOSS_PERC(percent));
277253
278− if (ret != OPUS_OK) {
279− qCWarning(encoder) << "Error when setting loss percent to " << perc << ": " << error_to_string(ret);
254+ if (errorCode != OPUS_OK) {
255+ qCWarning(encoder) << "Error when setting loss percent to " << percent << ": " << errorToString(errorCode);
280256 }
281257 }
282258
283−int AthenaOpusEncoder::getDTX() const
284−{
259+int AthenaOpusEncoder::getDTX() const {
285260 assert(_encoder);
286− int ret;
287− opus_encoder_ctl(_encoder, OPUS_GET_DTX(&ret));
288− return ret;
261+ int dtx;
262+ opus_encoder_ctl(_encoder, OPUS_GET_DTX(&dtx));
263+ return dtx;
289264 }
290265
291−void AthenaOpusEncoder::setDTX(int dtx)
292−{
266+void AthenaOpusEncoder::setDTX(int dtx) {
293267 assert(_encoder);
294− int ret = opus_encoder_ctl(_encoder, OPUS_SET_DTX(dtx));
268+ int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_DTX(dtx));
295269
296− if (ret != OPUS_OK) {
297− qCWarning(encoder) << "Error when setting DTX to " << dtx << ": " << error_to_string(ret);
270+ if (errorCode != OPUS_OK) {
271+ qCWarning(encoder) << "Error when setting DTX to " << dtx << ": " << errorToString(errorCode);
298272 }
299273 }