blob: 08d101c5ae4355fd41beae0dbee6d628ea456b04 [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
Peter Kastingdce40cf2015-08-24 14:52:23 -070059size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) {
60 return 0;
61}
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000062
63int AudioDecoder::IncomingPacket(const uint8_t* payload,
64 size_t payload_len,
65 uint16_t rtp_sequence_number,
66 uint32_t rtp_timestamp,
67 uint32_t arrival_timestamp) {
68 return 0;
69}
70
71int AudioDecoder::ErrorCode() { return 0; }
72
minyue@webrtc.orga8cc3442015-02-13 14:01:54 +000073int AudioDecoder::PacketDuration(const uint8_t* encoded,
74 size_t encoded_len) const {
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000075 return kNotImplemented;
76}
77
78int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded,
79 size_t encoded_len) const {
80 return kNotImplemented;
81}
82
83bool AudioDecoder::PacketHasFec(const uint8_t* encoded,
84 size_t encoded_len) const {
85 return false;
86}
87
88CNG_dec_inst* AudioDecoder::CngDecoderInstance() {
89 FATAL() << "Not a CNG decoder";
90 return NULL;
91}
92
93AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) {
94 switch (type) {
95 case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech.
96 case 1:
97 return kSpeech;
98 case 2:
99 return kComfortNoise;
100 default:
101 assert(false);
102 return kSpeech;
103 }
104}
105
106} // namespace webrtc