1 /*
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 #include "webrtc/base/trace_event.h"
17 
18 namespace webrtc {
19 
Decode(const uint8_t * encoded,size_t encoded_len,int sample_rate_hz,size_t max_decoded_bytes,int16_t * decoded,SpeechType * speech_type)20 int 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) {
23   TRACE_EVENT0("webrtc", "AudioDecoder::Decode");
24   int duration = PacketDuration(encoded, encoded_len);
25   if (duration >= 0 &&
26       duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
27     return -1;
28   }
29   return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
30                         speech_type);
31 }
32 
DecodeRedundant(const uint8_t * encoded,size_t encoded_len,int sample_rate_hz,size_t max_decoded_bytes,int16_t * decoded,SpeechType * speech_type)33 int 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) {
36   TRACE_EVENT0("webrtc", "AudioDecoder::DecodeRedundant");
37   int duration = PacketDurationRedundant(encoded, encoded_len);
38   if (duration >= 0 &&
39       duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
40     return -1;
41   }
42   return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded,
43                                  speech_type);
44 }
45 
DecodeRedundantInternal(const uint8_t * encoded,size_t encoded_len,int sample_rate_hz,int16_t * decoded,SpeechType * speech_type)46 int 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);
52 }
53 
HasDecodePlc() const54 bool AudioDecoder::HasDecodePlc() const { return false; }
55 
DecodePlc(size_t num_frames,int16_t * decoded)56 size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) {
57   return 0;
58 }
59 
IncomingPacket(const uint8_t * payload,size_t payload_len,uint16_t rtp_sequence_number,uint32_t rtp_timestamp,uint32_t arrival_timestamp)60 int 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 
ErrorCode()68 int AudioDecoder::ErrorCode() { return 0; }
69 
PacketDuration(const uint8_t * encoded,size_t encoded_len) const70 int AudioDecoder::PacketDuration(const uint8_t* encoded,
71                                  size_t encoded_len) const {
72   return kNotImplemented;
73 }
74 
PacketDurationRedundant(const uint8_t * encoded,size_t encoded_len) const75 int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded,
76                                           size_t encoded_len) const {
77   return kNotImplemented;
78 }
79 
PacketHasFec(const uint8_t * encoded,size_t encoded_len) const80 bool AudioDecoder::PacketHasFec(const uint8_t* encoded,
81                                 size_t encoded_len) const {
82   return false;
83 }
84 
CngDecoderInstance()85 CNG_dec_inst* AudioDecoder::CngDecoderInstance() {
86   FATAL() << "Not a CNG decoder";
87   return NULL;
88 }
89 
ConvertSpeechType(int16_t type)90 AudioDecoder::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
104