blob: 1ab2a7fec12e5e07726e19883974d708a7c4fd31 [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);
23 if (duration >= 0 && duration * sizeof(int16_t) > max_decoded_bytes) {
24 return -1;
25 }
26 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
27 speech_type);
28}
29
30int AudioDecoder::DecodeRedundant(const uint8_t* encoded, size_t encoded_len,
31 int sample_rate_hz, size_t max_decoded_bytes,
32 int16_t* decoded, SpeechType* speech_type) {
33 int duration = PacketDurationRedundant(encoded, encoded_len);
34 if (duration >= 0 && duration * sizeof(int16_t) > max_decoded_bytes) {
35 return -1;
36 }
37 return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded,
38 speech_type);
39}
40
41int AudioDecoder::DecodeInternal(const uint8_t* encoded, size_t encoded_len,
42 int sample_rate_hz, int16_t* decoded,
43 SpeechType* speech_type) {
44 return kNotImplemented;
45}
46
47int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded,
48 size_t encoded_len,
49 int sample_rate_hz, int16_t* decoded,
50 SpeechType* speech_type) {
51 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
52 speech_type);
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000053}
54
55bool AudioDecoder::HasDecodePlc() const { return false; }
56
57int AudioDecoder::DecodePlc(int num_frames, int16_t* decoded) { return -1; }
58
59int AudioDecoder::IncomingPacket(const uint8_t* payload,
60 size_t payload_len,
61 uint16_t rtp_sequence_number,
62 uint32_t rtp_timestamp,
63 uint32_t arrival_timestamp) {
64 return 0;
65}
66
67int AudioDecoder::ErrorCode() { return 0; }
68
minyue@webrtc.orga8cc3442015-02-13 14:01:54 +000069int AudioDecoder::PacketDuration(const uint8_t* encoded,
70 size_t encoded_len) const {
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000071 return kNotImplemented;
72}
73
74int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded,
75 size_t encoded_len) const {
76 return kNotImplemented;
77}
78
79bool AudioDecoder::PacketHasFec(const uint8_t* encoded,
80 size_t encoded_len) const {
81 return false;
82}
83
84CNG_dec_inst* AudioDecoder::CngDecoderInstance() {
85 FATAL() << "Not a CNG decoder";
86 return NULL;
87}
88
89AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) {
90 switch (type) {
91 case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech.
92 case 1:
93 return kSpeech;
94 case 2:
95 return kComfortNoise;
96 default:
97 assert(false);
98 return kSpeech;
99 }
100}
101
102} // namespace webrtc