henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 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 | |
henrik.lundin@webrtc.org | 9c55f0f | 2014-06-09 08:10:28 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_INTERFACE_AUDIO_DECODER_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_INTERFACE_AUDIO_DECODER_H_ |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 13 | |
| 14 | #include <stdlib.h> // NULL |
| 15 | |
henrike@webrtc.org | 88fbb2d | 2014-05-21 21:18:46 +0000 | [diff] [blame] | 16 | #include "webrtc/base/constructormagic.h" |
kwiberg@webrtc.org | 8b2058e | 2014-11-06 07:54:31 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 18 | #include "webrtc/typedefs.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 22 | // This is the interface class for decoders in NetEQ. Each codec type will have |
| 23 | // and implementation of this class. |
| 24 | class AudioDecoder { |
| 25 | public: |
| 26 | enum SpeechType { |
| 27 | kSpeech = 1, |
| 28 | kComfortNoise = 2 |
| 29 | }; |
| 30 | |
| 31 | // Used by PacketDuration below. Save the value -1 for errors. |
| 32 | enum { kNotImplemented = -2 }; |
| 33 | |
kwiberg@webrtc.org | 8b2058e | 2014-11-06 07:54:31 +0000 | [diff] [blame] | 34 | AudioDecoder() : channels_(1) {} |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 35 | virtual ~AudioDecoder() {} |
| 36 | |
| 37 | // Decodes |encode_len| bytes from |encoded| and writes the result in |
minyue@webrtc.org | ecbe0aa | 2013-08-12 06:48:09 +0000 | [diff] [blame] | 38 | // |decoded|. The number of samples from all channels produced is in |
| 39 | // the return value. If the decoder produced comfort noise, |speech_type| |
henrik.lundin@webrtc.org | 903182b | 2015-02-24 21:17:50 +0000 | [diff] [blame] | 40 | // is set to kComfortNoise, otherwise it is kSpeech. |
| 41 | virtual int Decode(const uint8_t* encoded, size_t encoded_len, |
| 42 | int16_t* decoded, SpeechType* speech_type) = 0; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 43 | |
| 44 | // Same as Decode(), but interfaces to the decoders redundant decode function. |
| 45 | // The default implementation simply calls the regular Decode() method. |
henrik.lundin@webrtc.org | 903182b | 2015-02-24 21:17:50 +0000 | [diff] [blame] | 46 | virtual int DecodeRedundant(const uint8_t* encoded, size_t encoded_len, |
| 47 | int16_t* decoded, SpeechType* speech_type); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 48 | |
| 49 | // Indicates if the decoder implements the DecodePlc method. |
pbos@webrtc.org | 2d1a55c | 2013-07-31 15:54:00 +0000 | [diff] [blame] | 50 | virtual bool HasDecodePlc() const; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 51 | |
| 52 | // Calls the packet-loss concealment of the decoder to update the state after |
| 53 | // one or several lost packets. |
pbos@webrtc.org | 2d1a55c | 2013-07-31 15:54:00 +0000 | [diff] [blame] | 54 | virtual int DecodePlc(int num_frames, int16_t* decoded); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 55 | |
| 56 | // Initializes the decoder. |
| 57 | virtual int Init() = 0; |
| 58 | |
| 59 | // Notifies the decoder of an incoming packet to NetEQ. |
| 60 | virtual int IncomingPacket(const uint8_t* payload, |
| 61 | size_t payload_len, |
| 62 | uint16_t rtp_sequence_number, |
| 63 | uint32_t rtp_timestamp, |
pbos@webrtc.org | 2d1a55c | 2013-07-31 15:54:00 +0000 | [diff] [blame] | 64 | uint32_t arrival_timestamp); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 65 | |
| 66 | // Returns the last error code from the decoder. |
pbos@webrtc.org | 2d1a55c | 2013-07-31 15:54:00 +0000 | [diff] [blame] | 67 | virtual int ErrorCode(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 68 | |
| 69 | // Returns the duration in samples of the payload in |encoded| which is |
| 70 | // |encoded_len| bytes long. Returns kNotImplemented if no duration estimate |
| 71 | // is available, or -1 in case of an error. |
minyue@webrtc.org | a8cc344 | 2015-02-13 14:01:54 +0000 | [diff] [blame] | 72 | virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len) const; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 73 | |
minyue@webrtc.org | b28bfa7 | 2014-03-21 12:07:40 +0000 | [diff] [blame] | 74 | // Returns the duration in samples of the redandant payload in |encoded| which |
| 75 | // is |encoded_len| bytes long. Returns kNotImplemented if no duration |
| 76 | // estimate is available, or -1 in case of an error. |
| 77 | virtual int PacketDurationRedundant(const uint8_t* encoded, |
| 78 | size_t encoded_len) const; |
| 79 | |
| 80 | // Detects whether a packet has forward error correction. The packet is |
| 81 | // comprised of the samples in |encoded| which is |encoded_len| bytes long. |
| 82 | // Returns true if the packet has FEC and false otherwise. |
| 83 | virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const; |
| 84 | |
kwiberg@webrtc.org | 8b2058e | 2014-11-06 07:54:31 +0000 | [diff] [blame] | 85 | // If this is a CNG decoder, return the underlying CNG_dec_inst*. If this |
| 86 | // isn't a CNG decoder, don't call this method. |
| 87 | virtual CNG_dec_inst* CngDecoderInstance(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 88 | |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 89 | size_t channels() const { return channels_; } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 90 | |
| 91 | protected: |
| 92 | static SpeechType ConvertSpeechType(int16_t type); |
| 93 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 94 | size_t channels_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 95 | |
| 96 | private: |
| 97 | DISALLOW_COPY_AND_ASSIGN(AudioDecoder); |
| 98 | }; |
| 99 | |
| 100 | } // namespace webrtc |
henrik.lundin@webrtc.org | 9c55f0f | 2014-06-09 08:10:28 +0000 | [diff] [blame] | 101 | #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INTERFACE_AUDIO_DECODER_H_ |