blob: d2984b97b0918d4081c5cf7dc5f403d532d799cc [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"
Peter Boströmd7b7ae82015-12-08 13:41:35 +010016#include "webrtc/base/trace_event.h"
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000017
18namespace webrtc {
19
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +000020int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len,
21 int sample_rate_hz, size_t max_decoded_bytes,
22 int16_t* decoded, SpeechType* speech_type) {
Peter Boströmd7b7ae82015-12-08 13:41:35 +010023 TRACE_EVENT0("webrtc", "AudioDecoder::Decode");
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +000024 int duration = PacketDuration(encoded, encoded_len);
Minyue323b1322015-05-25 13:49:37 +020025 if (duration >= 0 &&
26 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +000027 return -1;
28 }
29 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
30 speech_type);
31}
32
33int AudioDecoder::DecodeRedundant(const uint8_t* encoded, size_t encoded_len,
34 int sample_rate_hz, size_t max_decoded_bytes,
35 int16_t* decoded, SpeechType* speech_type) {
Peter Boströmd7b7ae82015-12-08 13:41:35 +010036 TRACE_EVENT0("webrtc", "AudioDecoder::DecodeRedundant");
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +000037 int duration = PacketDurationRedundant(encoded, encoded_len);
Minyue323b1322015-05-25 13:49:37 +020038 if (duration >= 0 &&
39 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +000040 return -1;
41 }
42 return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded,
43 speech_type);
44}
45
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +000046int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded,
47 size_t encoded_len,
48 int sample_rate_hz, int16_t* decoded,
49 SpeechType* speech_type) {
50 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
51 speech_type);
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000052}
53
54bool AudioDecoder::HasDecodePlc() const { return false; }
55
Peter Kastingdce40cf2015-08-24 14:52:23 -070056size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) {
57 return 0;
58}
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000059
60int AudioDecoder::IncomingPacket(const uint8_t* payload,
61 size_t payload_len,
62 uint16_t rtp_sequence_number,
63 uint32_t rtp_timestamp,
64 uint32_t arrival_timestamp) {
65 return 0;
66}
67
68int AudioDecoder::ErrorCode() { return 0; }
69
minyue@webrtc.orga8cc3442015-02-13 14:01:54 +000070int AudioDecoder::PacketDuration(const uint8_t* encoded,
71 size_t encoded_len) const {
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000072 return kNotImplemented;
73}
74
75int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded,
76 size_t encoded_len) const {
77 return kNotImplemented;
78}
79
80bool AudioDecoder::PacketHasFec(const uint8_t* encoded,
81 size_t encoded_len) const {
82 return false;
83}
84
85CNG_dec_inst* AudioDecoder::CngDecoderInstance() {
86 FATAL() << "Not a CNG decoder";
87 return NULL;
88}
89
90AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) {
91 switch (type) {
92 case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech.
93 case 1:
94 return kSpeech;
95 case 2:
96 return kComfortNoise;
97 default:
98 assert(false);
99 return kSpeech;
100 }
101}
102
103} // namespace webrtc