Fixed missing copyright headers. Fixed exceeding 120 columns. Fixed #include Fixed if conditional style. Fixed C++ reference symbol placement.
Showing the changes to plugins/opusCodec/src/OpusEncoder.cpp (1 of 4 files). Show all
Unified · Split
| @@ -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 | 11 | #include <PerfStat.h> |
| 3 | 12 | #include <QtCore/QLoggingCategory> |
| 13 | +#include <opus/opus.h> | |
| 4 | 14 | |
| 5 | 15 | #include "OpusEncoder.h" |
| 6 | −#include "opus/opus.h" | |
| 7 | 16 | |
| 8 | 17 | static QLoggingCategory encoder("AthenaOpusEncoder"); |
| 9 | 18 | |
| @@ -68,7 +77,8 @@ void AthenaOpusEncoder::encode(const QByteArray& decodedBuffer, QByteArray& enco · 58 unmodified lines | ||
| 68 | 77 | encodedBuffer.resize( decodedBuffer.size() ); |
| 69 | 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 | 83 | if ( bytes >= 0 ) { |
| 74 | 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 | 86 | } else { |
| 77 | 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 | 105 | assert(_encoder); |
| 95 | 106 | int ret = opus_encoder_ctl(_encoder, OPUS_SET_COMPLEXITY(complexity)); |
| 96 | 107 | |
| 97 | − if ( ret != OPUS_OK ) | |
| 108 | + if (ret != OPUS_OK) { | |
| 98 | 109 | qCWarning(encoder) << "Error when setting complexity to " << complexity << ": " << error_to_string(ret); |
| 110 | + } | |
| 99 | 111 | } |
| 100 | 112 | |
| 101 | 113 | int AthenaOpusEncoder::getBitrate() const |
| @@ -110,8 +122,10 @@ void AthenaOpusEncoder::setBitrate(int bitrate) · 8 unmodified lines | ||
| 110 | 122 | { |
| 111 | 123 | assert(_encoder); |
| 112 | 124 | int ret = opus_encoder_ctl(_encoder, OPUS_SET_BITRATE(bitrate)); |
| 113 | − if ( ret != OPUS_OK ) | |
| 125 | + | |
| 126 | + if (ret != OPUS_OK) { | |
| 114 | 127 | qCWarning(encoder) << "Error when setting bitrate to " << bitrate << ": " << error_to_string(ret); |
| 128 | + } | |
| 115 | 129 | } |
| 116 | 130 | |
| 117 | 131 | int AthenaOpusEncoder::getVBR() const |
| @@ -126,8 +140,10 @@ void AthenaOpusEncoder::setVBR(int vbr) · 8 unmodified lines | ||
| 126 | 140 | { |
| 127 | 141 | assert(_encoder); |
| 128 | 142 | int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR(vbr)); |
| 129 | − if ( ret != OPUS_OK ) | |
| 143 | + | |
| 144 | + if (ret != OPUS_OK) { | |
| 130 | 145 | qCWarning(encoder) << "Error when setting VBR to " << vbr << ": " << error_to_string(ret); |
| 146 | + } | |
| 131 | 147 | } |
| 132 | 148 | |
| 133 | 149 | int AthenaOpusEncoder::getVBRConstraint() const |
| @@ -142,8 +158,10 @@ void AthenaOpusEncoder::setVBRConstraint(int vbr_const) · 8 unmodified lines | ||
| 142 | 158 | { |
| 143 | 159 | assert(_encoder); |
| 144 | 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 | 163 | qCWarning(encoder) << "Error when setting VBR constraint to " << vbr_const << ": " << error_to_string(ret); |
| 164 | + } | |
| 147 | 165 | } |
| 148 | 166 | |
| 149 | 167 | int AthenaOpusEncoder::getMaxBandwidth() const |
| @@ -158,8 +176,10 @@ void AthenaOpusEncoder::setMaxBandwidth(int maxbw) · 8 unmodified lines | ||
| 158 | 176 | { |
| 159 | 177 | assert(_encoder); |
| 160 | 178 | int ret = opus_encoder_ctl(_encoder, OPUS_SET_MAX_BANDWIDTH(maxbw)); |
| 161 | − if ( ret != OPUS_OK ) | |
| 179 | + | |
| 180 | + if (ret != OPUS_OK) { | |
| 162 | 181 | qCWarning(encoder) << "Error when setting max bandwidth to " << maxbw << ": " << error_to_string(ret); |
| 182 | + } | |
| 163 | 183 | } |
| 164 | 184 | |
| 165 | 185 | int AthenaOpusEncoder::getBandwidth() const |
| @@ -174,8 +194,10 @@ void AthenaOpusEncoder::setBandwidth(int bw) · 8 unmodified lines | ||
| 174 | 194 | { |
| 175 | 195 | assert(_encoder); |
| 176 | 196 | int ret = opus_encoder_ctl(_encoder, OPUS_SET_BANDWIDTH(bw)); |
| 177 | − if ( ret != OPUS_OK ) | |
| 197 | + | |
| 198 | + if (ret != OPUS_OK) { | |
| 178 | 199 | qCWarning(encoder) << "Error when setting bandwidth to " << bw << ": " << error_to_string(ret); |
| 200 | + } | |
| 179 | 201 | } |
| 180 | 202 | |
| 181 | 203 | int AthenaOpusEncoder::getSignal() const |
| @@ -190,8 +212,10 @@ void AthenaOpusEncoder::setSignal(int signal) · 8 unmodified lines | ||
| 190 | 212 | { |
| 191 | 213 | assert(_encoder); |
| 192 | 214 | int ret = opus_encoder_ctl(_encoder, OPUS_SET_SIGNAL(signal)); |
| 193 | − if ( ret != OPUS_OK ) | |
| 215 | + | |
| 216 | + if (ret != OPUS_OK) { | |
| 194 | 217 | qCWarning(encoder) << "Error when setting signal to " << signal << ": " << error_to_string(ret); |
| 218 | + } | |
| 195 | 219 | } |
| 196 | 220 | |
| 197 | 221 | int AthenaOpusEncoder::getApplication() const |
| @@ -202,12 +226,14 @@ int AthenaOpusEncoder::getApplication() const · 4 unmodified lines | ||
| 202 | 226 | return ret; |
| 203 | 227 | } |
| 204 | 228 | |
| 205 | −void AthenaOpusEncoder::setApplication(int app) | |
| 229 | +void AthenaOpusEncoder::setApplication(int application) | |
| 206 | 230 | { |
| 207 | 231 | 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 | + } | |
| 211 | 237 | } |
| 212 | 238 | |
| 213 | 239 | int AthenaOpusEncoder::getLookahead() const |
| @@ -230,8 +256,10 @@ void AthenaOpusEncoder::setInbandFEC(int fec) · 16 unmodified lines | ||
| 230 | 256 | { |
| 231 | 257 | assert(_encoder); |
| 232 | 258 | int ret = opus_encoder_ctl(_encoder, OPUS_SET_INBAND_FEC(fec)); |
| 233 | − if ( ret != OPUS_OK ) | |
| 259 | + | |
| 260 | + if (ret != OPUS_OK) { | |
| 234 | 261 | qCWarning(encoder) << "Error when setting inband FEC to " << fec << ": " << error_to_string(ret); |
| 262 | + } | |
| 235 | 263 | } |
| 236 | 264 | |
| 237 | 265 | int AthenaOpusEncoder::getExpectedPacketLossPercent() const |
| @@ -246,8 +274,10 @@ void AthenaOpusEncoder::setExpectedPacketLossPercent(int perc) · 8 unmodified lines | ||
| 246 | 274 | { |
| 247 | 275 | assert(_encoder); |
| 248 | 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 | 279 | qCWarning(encoder) << "Error when setting loss percent to " << perc << ": " << error_to_string(ret); |
| 280 | + } | |
| 251 | 281 | } |
| 252 | 282 | |
| 253 | 283 | int AthenaOpusEncoder::getDTX() const |
| @@ -262,8 +292,8 @@ void AthenaOpusEncoder::setDTX(int dtx) · 8 unmodified lines | ||
| 262 | 292 | { |
| 263 | 293 | assert(_encoder); |
| 264 | 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 | +} | |