| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst) { | 71 int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst) { |
| 72 if (inst) { | 72 if (inst) { |
| 73 opus_encoder_destroy(inst->encoder); | 73 opus_encoder_destroy(inst->encoder); |
| 74 free(inst); | 74 free(inst); |
| 75 return 0; | 75 return 0; |
| 76 } else { | 76 } else { |
| 77 return -1; | 77 return -1; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 int WebRtcOpus_Encode(OpusEncInst* inst, | 81 int16_t WebRtcOpus_Encode(OpusEncInst* inst, |
| 82 const int16_t* audio_in, | 82 const int16_t* audio_in, |
| 83 int16_t samples, | 83 int16_t samples, |
| 84 int16_t length_encoded_buffer, | 84 int16_t length_encoded_buffer, |
| 85 uint8_t* encoded) { | 85 uint8_t* encoded) { |
| 86 int res; | 86 int res; |
| 87 | 87 |
| 88 if (samples > 48 * kWebRtcOpusMaxEncodeFrameSizeMs) { | 88 if (samples > 48 * kWebRtcOpusMaxEncodeFrameSizeMs) { |
| 89 return -1; | 89 return -1; |
| 90 } | 90 } |
| 91 | 91 |
| 92 res = opus_encode(inst->encoder, | 92 res = opus_encode(inst->encoder, |
| 93 (const opus_int16*)audio_in, | 93 (const opus_int16*)audio_in, |
| 94 samples, | 94 samples, |
| 95 encoded, | 95 encoded, |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 (opus_int16*)decoded, frame_size, decode_fec); | 284 (opus_int16*)decoded, frame_size, decode_fec); |
| 285 | 285 |
| 286 if (res <= 0) | 286 if (res <= 0) |
| 287 return -1; | 287 return -1; |
| 288 | 288 |
| 289 *audio_type = DetermineAudioType(inst, encoded_bytes); | 289 *audio_type = DetermineAudioType(inst, encoded_bytes); |
| 290 | 290 |
| 291 return res; | 291 return res; |
| 292 } | 292 } |
| 293 | 293 |
| 294 int WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, | 294 int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, |
| 295 int16_t encoded_bytes, int16_t* decoded, | 295 int16_t encoded_bytes, int16_t* decoded, |
| 296 int16_t* audio_type) { | 296 int16_t* audio_type) { |
| 297 int decoded_samples; | 297 int decoded_samples; |
| 298 | 298 |
| 299 if (encoded_bytes == 0) { | 299 if (encoded_bytes == 0) { |
| 300 *audio_type = DetermineAudioType(inst, encoded_bytes); | 300 *audio_type = DetermineAudioType(inst, encoded_bytes); |
| 301 decoded_samples = WebRtcOpus_DecodePlc(inst, decoded, 1); | 301 decoded_samples = WebRtcOpus_DecodePlc(inst, decoded, 1); |
| 302 } else { | 302 } else { |
| 303 decoded_samples = DecodeNative(inst, | 303 decoded_samples = DecodeNative(inst, |
| 304 encoded, | 304 encoded, |
| 305 encoded_bytes, | 305 encoded_bytes, |
| 306 kWebRtcOpusMaxFrameSizePerChannel, | 306 kWebRtcOpusMaxFrameSizePerChannel, |
| 307 decoded, | 307 decoded, |
| 308 audio_type, | 308 audio_type, |
| 309 0); | 309 0); |
| 310 } | 310 } |
| 311 if (decoded_samples < 0) { | 311 if (decoded_samples < 0) { |
| 312 return -1; | 312 return -1; |
| 313 } | 313 } |
| 314 | 314 |
| 315 /* Update decoded sample memory, to be used by the PLC in case of losses. */ | 315 /* Update decoded sample memory, to be used by the PLC in case of losses. */ |
| 316 inst->prev_decoded_samples = decoded_samples; | 316 inst->prev_decoded_samples = decoded_samples; |
| 317 | 317 |
| 318 return decoded_samples; | 318 return decoded_samples; |
| 319 } | 319 } |
| 320 | 320 |
| 321 int WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, | 321 int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, |
| 322 int number_of_lost_frames) { | 322 int16_t number_of_lost_frames) { |
| 323 int16_t audio_type = 0; | 323 int16_t audio_type = 0; |
| 324 int decoded_samples; | 324 int decoded_samples; |
| 325 int plc_samples; | 325 int plc_samples; |
| 326 | 326 |
| 327 /* The number of samples we ask for is |number_of_lost_frames| times | 327 /* The number of samples we ask for is |number_of_lost_frames| times |
| 328 * |prev_decoded_samples_|. Limit the number of samples to maximum | 328 * |prev_decoded_samples_|. Limit the number of samples to maximum |
| 329 * |kWebRtcOpusMaxFrameSizePerChannel|. */ | 329 * |kWebRtcOpusMaxFrameSizePerChannel|. */ |
| 330 plc_samples = number_of_lost_frames * inst->prev_decoded_samples; | 330 plc_samples = number_of_lost_frames * inst->prev_decoded_samples; |
| 331 plc_samples = (plc_samples <= kWebRtcOpusMaxFrameSizePerChannel) ? | 331 plc_samples = (plc_samples <= kWebRtcOpusMaxFrameSizePerChannel) ? |
| 332 plc_samples : kWebRtcOpusMaxFrameSizePerChannel; | 332 plc_samples : kWebRtcOpusMaxFrameSizePerChannel; |
| 333 decoded_samples = DecodeNative(inst, NULL, 0, plc_samples, | 333 decoded_samples = DecodeNative(inst, NULL, 0, plc_samples, |
| 334 decoded, &audio_type, 0); | 334 decoded, &audio_type, 0); |
| 335 if (decoded_samples < 0) { | 335 if (decoded_samples < 0) { |
| 336 return -1; | 336 return -1; |
| 337 } | 337 } |
| 338 | 338 |
| 339 return decoded_samples; | 339 return decoded_samples; |
| 340 } | 340 } |
| 341 | 341 |
| 342 int WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, | 342 int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, |
| 343 int16_t encoded_bytes, int16_t* decoded, | 343 int16_t encoded_bytes, int16_t* decoded, |
| 344 int16_t* audio_type) { | 344 int16_t* audio_type) { |
| 345 int decoded_samples; | 345 int decoded_samples; |
| 346 int fec_samples; | 346 int fec_samples; |
| 347 | 347 |
| 348 if (WebRtcOpus_PacketHasFec(encoded, encoded_bytes) != 1) { | 348 if (WebRtcOpus_PacketHasFec(encoded, encoded_bytes) != 1) { |
| 349 return 0; | 349 return 0; |
| 350 } | 350 } |
| 351 | 351 |
| 352 fec_samples = opus_packet_get_samples_per_frame(encoded, 48000); | 352 fec_samples = opus_packet_get_samples_per_frame(encoded, 48000); |
| 353 | 353 |
| 354 decoded_samples = DecodeNative(inst, encoded, encoded_bytes, | 354 decoded_samples = DecodeNative(inst, encoded, encoded_bytes, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 return 0; | 441 return 0; |
| 442 } | 442 } |
| 443 | 443 |
| 444 for (n = 0; n < channels; n++) { | 444 for (n = 0; n < channels; n++) { |
| 445 if (frame_data[0][0] & (0x80 >> ((n + 1) * (frames + 1) - 1))) | 445 if (frame_data[0][0] & (0x80 >> ((n + 1) * (frames + 1) - 1))) |
| 446 return 1; | 446 return 1; |
| 447 } | 447 } |
| 448 | 448 |
| 449 return 0; | 449 return 0; |
| 450 } | 450 } |
| OLD | NEW |