blob: 9e88f897a618f29cef215d587ae7093b3414f1fd [file] [log] [blame]
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
12
13#include <assert.h>
14
15#include "webrtc/base/checks.h"
16
17namespace webrtc {
18
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +000019int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len,
20 int sample_rate_hz, size_t max_decoded_bytes,
21 int16_t* decoded, SpeechType* speech_type) {
22 int duration = PacketDuration(encoded, encoded_len);
Minyue323b1322015-05-25 13:49:37 +020023 if (duration >= 0 &&
24 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +000025 return -1;
26 }
27 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
28 speech_type);
29}
30
31int AudioDecoder::DecodeRedundant(const uint8_t* encoded, size_t encoded_len,
32 int sample_rate_hz, size_t max_decoded_bytes,
33 int16_t* decoded, SpeechType* speech_type) {
34 int duration = PacketDurationRedundant(encoded, encoded_len);
Minyue323b1322015-05-25 13:49:37 +020035 if (duration >= 0 &&
36 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +000037 return -1;
38 }
39 return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded,
40 speech_type);
41}
42
43int AudioDecoder::DecodeInternal(const uint8_t* encoded, size_t encoded_len,
44 int sample_rate_hz, int16_t* decoded,
45 SpeechType* speech_type) {
46 return kNotImplemented;
47}
48
49int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded,
50 size_t encoded_len,
51 int sample_rate_hz, int16_t* decoded,
52 SpeechType* speech_type) {
53 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
54 speech_type);
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000055}
56
57bool AudioDecoder::HasDecodePlc() const { return false; }
58
59int AudioDecoder::DecodePlc(int num_frames, int16_t* decoded) { return -1; }
60
61int AudioDecoder::IncomingPacket(const uint8_t* payload,
62 size_t payload_len,
63 uint16_t rtp_sequence_number,
64 uint32_t rtp_timestamp,
65 uint32_t arrival_timestamp) {
66 return 0;
67}
68
69int AudioDecoder::ErrorCode() { return 0; }
70
minyue@webrtc.orga8cc3442015-02-13 14:01:54 +000071int AudioDecoder::PacketDuration(const uint8_t* encoded,
72 size_t encoded_len) const {
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000073 return kNotImplemented;
74}
75
76int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded,
77 size_t encoded_len) const {
78 return kNotImplemented;
79}
80
81bool AudioDecoder::PacketHasFec(const uint8_t* encoded,
82 size_t encoded_len) const {
83 return false;
84}
85
86CNG_dec_inst* AudioDecoder::CngDecoderInstance() {
87 FATAL() << "Not a CNG decoder";
88 return NULL;
89}
90
91AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) {
92 switch (type) {
93 case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech.
94 case 1:
95 return kSpeech;
96 case 2:
97 return kComfortNoise;
98 default:
99 assert(false);
100 return kSpeech;
101 }
102}
103
104} // namespace webrtc