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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (decoded_samples < 0) { | 352 if (decoded_samples < 0) { |
353 return -1; | 353 return -1; |
354 } | 354 } |
355 | 355 |
356 return decoded_samples; | 356 return decoded_samples; |
357 } | 357 } |
358 | 358 |
359 int WebRtcOpus_DurationEst(OpusDecInst* inst, | 359 int WebRtcOpus_DurationEst(OpusDecInst* inst, |
360 const uint8_t* payload, | 360 const uint8_t* payload, |
361 size_t payload_length_bytes) { | 361 size_t payload_length_bytes) { |
| 362 if (payload_length_bytes == 0) { |
| 363 // WebRtcOpus_Decode calls PLC when payload length is zero. So we return |
| 364 // PLC duration correspondingly. |
| 365 return WebRtcOpus_PlcDuration(inst); |
| 366 } |
| 367 |
362 int frames, samples; | 368 int frames, samples; |
363 frames = opus_packet_get_nb_frames(payload, (opus_int32)payload_length_bytes); | 369 frames = opus_packet_get_nb_frames(payload, (opus_int32)payload_length_bytes); |
364 if (frames < 0) { | 370 if (frames < 0) { |
365 /* Invalid payload data. */ | 371 /* Invalid payload data. */ |
366 return 0; | 372 return 0; |
367 } | 373 } |
368 samples = frames * opus_packet_get_samples_per_frame(payload, 48000); | 374 samples = frames * opus_packet_get_samples_per_frame(payload, 48000); |
369 if (samples < 120 || samples > 5760) { | 375 if (samples < 120 || samples > 5760) { |
370 /* Invalid payload duration. */ | 376 /* Invalid payload duration. */ |
371 return 0; | 377 return 0; |
372 } | 378 } |
373 return samples; | 379 return samples; |
374 } | 380 } |
375 | 381 |
| 382 int WebRtcOpus_PlcDuration(OpusDecInst* inst) { |
| 383 /* The number of samples we ask for is |number_of_lost_frames| times |
| 384 * |prev_decoded_samples_|. Limit the number of samples to maximum |
| 385 * |kWebRtcOpusMaxFrameSizePerChannel|. */ |
| 386 const int plc_samples = inst->prev_decoded_samples; |
| 387 return (plc_samples <= kWebRtcOpusMaxFrameSizePerChannel) ? |
| 388 plc_samples : kWebRtcOpusMaxFrameSizePerChannel; |
| 389 } |
| 390 |
376 int WebRtcOpus_FecDurationEst(const uint8_t* payload, | 391 int WebRtcOpus_FecDurationEst(const uint8_t* payload, |
377 size_t payload_length_bytes) { | 392 size_t payload_length_bytes) { |
378 int samples; | 393 int samples; |
379 if (WebRtcOpus_PacketHasFec(payload, payload_length_bytes) != 1) { | 394 if (WebRtcOpus_PacketHasFec(payload, payload_length_bytes) != 1) { |
380 return 0; | 395 return 0; |
381 } | 396 } |
382 | 397 |
383 samples = opus_packet_get_samples_per_frame(payload, 48000); | 398 samples = opus_packet_get_samples_per_frame(payload, 48000); |
384 if (samples < 480 || samples > 5760) { | 399 if (samples < 480 || samples > 5760) { |
385 /* Invalid payload duration. */ | 400 /* Invalid payload duration. */ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 return 0; | 452 return 0; |
438 } | 453 } |
439 | 454 |
440 for (n = 0; n < channels; n++) { | 455 for (n = 0; n < channels; n++) { |
441 if (frame_data[0][0] & (0x80 >> ((n + 1) * (frames + 1) - 1))) | 456 if (frame_data[0][0] & (0x80 >> ((n + 1) * (frames + 1) - 1))) |
442 return 1; | 457 return 1; |
443 } | 458 } |
444 | 459 |
445 return 0; | 460 return 0; |
446 } | 461 } |
OLD | NEW |