Showing the changes to plugins/opusCodec/src/OpusEncoder.cpp (1 of 4 files). Show all
Unified · Split
| @@ -16,40 +16,39 @@ · 15 unmodified lines | ||
| 16 | 16 | |
| 17 | 17 | static QLoggingCategory encoder("AthenaOpusEncoder"); |
| 18 | 18 | |
| 19 | −static QString error_to_string(int error) { | |
| 19 | +static QString errorToString(int error) { | |
| 20 | 20 | 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); | |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | |
| 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; | |
| 46 | 45 | |
| 47 | 46 | int error; |
| 48 | 47 | |
| 49 | 48 | _encoder = opus_encoder_create(sampleRate, numChannels, DEFAULT_APPLICATION, &error); |
| 50 | 49 | |
| 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); | |
| 53 | 52 | _encoder = nullptr; |
| 54 | 53 | return; |
| 55 | 54 | } |
| @@ -62,8 +61,7 @@ AthenaOpusEncoder::AthenaOpusEncoder(int sampleRate, int numChannels) · 6 unmodified lines | ||
| 62 | 61 | qCDebug(encoder) << "Opus encoder initialized, sampleRate = " << sampleRate << "; numChannels = " << numChannels; |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | −AthenaOpusEncoder::~AthenaOpusEncoder() | |
| 66 | −{ | |
| 64 | +AthenaOpusEncoder::~AthenaOpusEncoder() { | |
| 67 | 65 | opus_encoder_destroy(_encoder); |
| 68 | 66 | } |
| 69 | 67 | |
| @@ -75,225 +73,201 @@ void AthenaOpusEncoder::encode(const QByteArray& decodedBuffer, QByteArray& enco · 5 unmodified lines | ||
| 75 | 73 | assert(_encoder); |
| 76 | 74 | |
| 77 | 75 | 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)); | |
| 79 | 77 | |
| 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, | |
| 81 | 79 | reinterpret_cast<unsigned char*>(encodedBuffer.data()), encodedBuffer.size() ); |
| 82 | 80 | |
| 83 | − if ( bytes >= 0 ) { | |
| 84 | − //qCDebug(encoder) << "Encoded " << decodedBuffer.length() << " bytes into " << bytes << " opus bytes"; | |
| 81 | + if (bytes >= 0) { | |
| 85 | 82 | encodedBuffer.resize(bytes); |
| 86 | 83 | } else { |
| 87 | 84 | encodedBuffer.resize(0); |
| 88 | 85 | |
| 89 | 86 | qCWarning(encoder) << "Error when encoding " << decodedBuffer.length() << " bytes of audio: " |
| 90 | − << error_to_string(bytes); | |
| 87 | + << errorToString(bytes); | |
| 91 | 88 | } |
| 92 | 89 | |
| 93 | 90 | } |
| 94 | 91 | |
| 95 | −int AthenaOpusEncoder::getComplexity() const | |
| 96 | −{ | |
| 92 | +int AthenaOpusEncoder::getComplexity() const { | |
| 97 | 93 | 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; | |
| 101 | 97 | } |
| 102 | 98 | |
| 103 | −void AthenaOpusEncoder::setComplexity(int complexity) | |
| 104 | −{ | |
| 99 | +void AthenaOpusEncoder::setComplexity(int complexity) { | |
| 105 | 100 | assert(_encoder); |
| 106 | − int ret = opus_encoder_ctl(_encoder, OPUS_SET_COMPLEXITY(complexity)); | |
| 101 | + int returnValue = opus_encoder_ctl(_encoder, OPUS_SET_COMPLEXITY(complexity)); | |
| 107 | 102 | |
| 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); | |
| 110 | 105 | } |
| 111 | 106 | } |
| 112 | 107 | |
| 113 | −int AthenaOpusEncoder::getBitrate() const | |
| 114 | −{ | |
| 108 | +int AthenaOpusEncoder::getBitrate() const { | |
| 115 | 109 | 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; | |
| 119 | 113 | } |
| 120 | 114 | |
| 121 | −void AthenaOpusEncoder::setBitrate(int bitrate) | |
| 122 | −{ | |
| 115 | +void AthenaOpusEncoder::setBitrate(int bitrate) { | |
| 123 | 116 | assert(_encoder); |
| 124 | − int ret = opus_encoder_ctl(_encoder, OPUS_SET_BITRATE(bitrate)); | |
| 117 | + int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_BITRATE(bitrate)); | |
| 125 | 118 | |
| 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); | |
| 128 | 121 | } |
| 129 | 122 | } |
| 130 | 123 | |
| 131 | −int AthenaOpusEncoder::getVBR() const | |
| 132 | −{ | |
| 124 | +int AthenaOpusEncoder::getVBR() const { | |
| 133 | 125 | 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; | |
| 137 | 129 | } |
| 138 | 130 | |
| 139 | −void AthenaOpusEncoder::setVBR(int vbr) | |
| 140 | −{ | |
| 131 | +void AthenaOpusEncoder::setVBR(int vbr) { | |
| 141 | 132 | assert(_encoder); |
| 142 | − int ret = opus_encoder_ctl(_encoder, OPUS_SET_VBR(vbr)); | |
| 133 | + int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_VBR(vbr)); | |
| 143 | 134 | |
| 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); | |
| 146 | 137 | } |
| 147 | 138 | } |
| 148 | 139 | |
| 149 | −int AthenaOpusEncoder::getVBRConstraint() const | |
| 150 | −{ | |
| 140 | +int AthenaOpusEncoder::getVBRConstraint() const { | |
| 151 | 141 | 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; | |
| 155 | 145 | } |
| 156 | 146 | |
| 157 | −void AthenaOpusEncoder::setVBRConstraint(int vbr_const) | |
| 158 | −{ | |
| 147 | +void AthenaOpusEncoder::setVBRConstraint(int vbr_const) { | |
| 159 | 148 | 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)); | |
| 161 | 150 | |
| 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); | |
| 164 | 153 | } |
| 165 | 154 | } |
| 166 | 155 | |
| 167 | −int AthenaOpusEncoder::getMaxBandwidth() const | |
| 168 | −{ | |
| 156 | +int AthenaOpusEncoder::getMaxBandwidth() const { | |
| 169 | 157 | 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; | |
| 173 | 161 | } |
| 174 | 162 | |
| 175 | −void AthenaOpusEncoder::setMaxBandwidth(int maxbw) | |
| 176 | −{ | |
| 163 | +void AthenaOpusEncoder::setMaxBandwidth(int maxbw) { | |
| 177 | 164 | 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)); | |
| 179 | 166 | |
| 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); | |
| 182 | 169 | } |
| 183 | 170 | } |
| 184 | 171 | |
| 185 | −int AthenaOpusEncoder::getBandwidth() const | |
| 186 | −{ | |
| 172 | +int AthenaOpusEncoder::getBandwidth() const { | |
| 187 | 173 | 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; | |
| 191 | 177 | } |
| 192 | 178 | |
| 193 | −void AthenaOpusEncoder::setBandwidth(int bw) | |
| 194 | −{ | |
| 179 | +void AthenaOpusEncoder::setBandwidth(int bandwidth) { | |
| 195 | 180 | assert(_encoder); |
| 196 | − int ret = opus_encoder_ctl(_encoder, OPUS_SET_BANDWIDTH(bw)); | |
| 181 | + int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_BANDWIDTH(bandwidth)); | |
| 197 | 182 | |
| 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); | |
| 200 | 185 | } |
| 201 | 186 | } |
| 202 | 187 | |
| 203 | −int AthenaOpusEncoder::getSignal() const | |
| 204 | −{ | |
| 188 | +int AthenaOpusEncoder::getSignal() const { | |
| 205 | 189 | 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; | |
| 209 | 193 | } |
| 210 | 194 | |
| 211 | −void AthenaOpusEncoder::setSignal(int signal) | |
| 212 | −{ | |
| 195 | +void AthenaOpusEncoder::setSignal(int signal) { | |
| 213 | 196 | assert(_encoder); |
| 214 | − int ret = opus_encoder_ctl(_encoder, OPUS_SET_SIGNAL(signal)); | |
| 197 | + int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_SIGNAL(signal)); | |
| 215 | 198 | |
| 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); | |
| 218 | 201 | } |
| 219 | 202 | } |
| 220 | 203 | |
| 221 | −int AthenaOpusEncoder::getApplication() const | |
| 222 | −{ | |
| 204 | +int AthenaOpusEncoder::getApplication() const { | |
| 223 | 205 | 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; | |
| 227 | 209 | } |
| 228 | 210 | |
| 229 | −void AthenaOpusEncoder::setApplication(int application) | |
| 230 | −{ | |
| 211 | +void AthenaOpusEncoder::setApplication(int application) { | |
| 231 | 212 | assert(_encoder); |
| 232 | − int ret = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(application)); | |
| 213 | + int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_APPLICATION(application)); | |
| 233 | 214 | |
| 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); | |
| 236 | 217 | } |
| 237 | 218 | } |
| 238 | 219 | |
| 239 | −int AthenaOpusEncoder::getLookahead() const | |
| 240 | −{ | |
| 220 | +int AthenaOpusEncoder::getLookahead() const { | |
| 241 | 221 | 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; | |
| 245 | 225 | } |
| 246 | 226 | |
| 247 | −int AthenaOpusEncoder::getInbandFEC() const | |
| 248 | −{ | |
| 227 | +int AthenaOpusEncoder::getInbandFEC() const { | |
| 249 | 228 | 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; | |
| 253 | 232 | } |
| 254 | 233 | |
| 255 | −void AthenaOpusEncoder::setInbandFEC(int fec) | |
| 256 | −{ | |
| 234 | +void AthenaOpusEncoder::setInbandFEC(int fec) { | |
| 257 | 235 | 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)); | |
| 259 | 237 | |
| 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); | |
| 262 | 240 | } |
| 263 | 241 | } |
| 264 | 242 | |
| 265 | −int AthenaOpusEncoder::getExpectedPacketLossPercent() const | |
| 266 | −{ | |
| 243 | +int AthenaOpusEncoder::getExpectedPacketLossPercent() const { | |
| 267 | 244 | 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; | |
| 271 | 248 | } |
| 272 | 249 | |
| 273 | −void AthenaOpusEncoder::setExpectedPacketLossPercent(int perc) | |
| 274 | −{ | |
| 250 | +void AthenaOpusEncoder::setExpectedPacketLossPercentage(int percent) { | |
| 275 | 251 | 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)); | |
| 277 | 253 | |
| 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); | |
| 280 | 256 | } |
| 281 | 257 | } |
| 282 | 258 | |
| 283 | −int AthenaOpusEncoder::getDTX() const | |
| 284 | −{ | |
| 259 | +int AthenaOpusEncoder::getDTX() const { | |
| 285 | 260 | 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; | |
| 289 | 264 | } |
| 290 | 265 | |
| 291 | −void AthenaOpusEncoder::setDTX(int dtx) | |
| 292 | −{ | |
| 266 | +void AthenaOpusEncoder::setDTX(int dtx) { | |
| 293 | 267 | assert(_encoder); |
| 294 | − int ret = opus_encoder_ctl(_encoder, OPUS_SET_DTX(dtx)); | |
| 268 | + int errorCode = opus_encoder_ctl(_encoder, OPUS_SET_DTX(dtx)); | |
| 295 | 269 | |
| 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); | |
| 298 | 272 | } |
| 299 | 273 | } |