2013-01-29 12:09:21 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-06-09 08:10:28 +00:00
|
|
|
#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_INTERFACE_AUDIO_DECODER_H_
|
|
|
|
|
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_INTERFACE_AUDIO_DECODER_H_
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
#include <stdlib.h> // NULL
|
|
|
|
|
|
2014-05-21 21:18:46 +00:00
|
|
|
#include "webrtc/base/constructormagic.h"
|
2014-11-06 07:54:31 +00:00
|
|
|
#include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// This is the interface class for decoders in NetEQ. Each codec type will have
|
|
|
|
|
// and implementation of this class.
|
|
|
|
|
class AudioDecoder {
|
|
|
|
|
public:
|
|
|
|
|
enum SpeechType {
|
|
|
|
|
kSpeech = 1,
|
|
|
|
|
kComfortNoise = 2
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Used by PacketDuration below. Save the value -1 for errors.
|
|
|
|
|
enum { kNotImplemented = -2 };
|
|
|
|
|
|
2015-03-18 09:47:08 +00:00
|
|
|
AudioDecoder() = default;
|
|
|
|
|
virtual ~AudioDecoder() = default;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Decodes |encode_len| bytes from |encoded| and writes the result in
|
2015-03-16 12:30:37 +00:00
|
|
|
// |decoded|. The maximum bytes allowed to be written into |decoded| is
|
2015-05-25 13:49:37 +02:00
|
|
|
// |max_decoded_bytes|. Returns the total number of samples across all
|
|
|
|
|
// channels. If the decoder produced comfort noise, |speech_type|
|
2015-02-25 10:02:29 +00:00
|
|
|
// is set to kComfortNoise, otherwise it is kSpeech. The desired output
|
|
|
|
|
// sample rate is provided in |sample_rate_hz|, which must be valid for the
|
|
|
|
|
// codec at hand.
|
|
|
|
|
virtual int Decode(const uint8_t* encoded,
|
|
|
|
|
size_t encoded_len,
|
|
|
|
|
int sample_rate_hz,
|
2015-03-16 12:30:37 +00:00
|
|
|
size_t max_decoded_bytes,
|
2015-02-25 10:02:29 +00:00
|
|
|
int16_t* decoded,
|
2015-03-16 12:30:37 +00:00
|
|
|
SpeechType* speech_type);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Same as Decode(), but interfaces to the decoders redundant decode function.
|
|
|
|
|
// The default implementation simply calls the regular Decode() method.
|
2015-02-25 10:02:29 +00:00
|
|
|
virtual int DecodeRedundant(const uint8_t* encoded,
|
|
|
|
|
size_t encoded_len,
|
|
|
|
|
int sample_rate_hz,
|
2015-03-16 12:30:37 +00:00
|
|
|
size_t max_decoded_bytes,
|
2015-02-25 10:02:29 +00:00
|
|
|
int16_t* decoded,
|
|
|
|
|
SpeechType* speech_type);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Indicates if the decoder implements the DecodePlc method.
|
2013-07-31 15:54:00 +00:00
|
|
|
virtual bool HasDecodePlc() const;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Calls the packet-loss concealment of the decoder to update the state after
|
|
|
|
|
// one or several lost packets.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
virtual size_t DecodePlc(size_t num_frames, int16_t* decoded);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-08-27 15:22:11 +02:00
|
|
|
// Resets the decoder state (empty buffers etc.).
|
|
|
|
|
virtual void Reset() = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Notifies the decoder of an incoming packet to NetEQ.
|
|
|
|
|
virtual int IncomingPacket(const uint8_t* payload,
|
|
|
|
|
size_t payload_len,
|
|
|
|
|
uint16_t rtp_sequence_number,
|
|
|
|
|
uint32_t rtp_timestamp,
|
2013-07-31 15:54:00 +00:00
|
|
|
uint32_t arrival_timestamp);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Returns the last error code from the decoder.
|
2013-07-31 15:54:00 +00:00
|
|
|
virtual int ErrorCode();
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-05-25 13:49:37 +02:00
|
|
|
// Returns the duration in samples-per-channel of the payload in |encoded|
|
|
|
|
|
// which is |encoded_len| bytes long. Returns kNotImplemented if no duration
|
|
|
|
|
// estimate is available, or -1 in case of an error.
|
2015-02-13 14:01:54 +00:00
|
|
|
virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len) const;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-05-25 13:49:37 +02:00
|
|
|
// Returns the duration in samples-per-channel of the redandant payload in
|
|
|
|
|
// |encoded| which is |encoded_len| bytes long. Returns kNotImplemented if no
|
|
|
|
|
// duration estimate is available, or -1 in case of an error.
|
2014-03-21 12:07:40 +00:00
|
|
|
virtual int PacketDurationRedundant(const uint8_t* encoded,
|
|
|
|
|
size_t encoded_len) const;
|
|
|
|
|
|
|
|
|
|
// Detects whether a packet has forward error correction. The packet is
|
|
|
|
|
// comprised of the samples in |encoded| which is |encoded_len| bytes long.
|
|
|
|
|
// Returns true if the packet has FEC and false otherwise.
|
|
|
|
|
virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const;
|
|
|
|
|
|
2014-11-06 07:54:31 +00:00
|
|
|
// If this is a CNG decoder, return the underlying CNG_dec_inst*. If this
|
|
|
|
|
// isn't a CNG decoder, don't call this method.
|
|
|
|
|
virtual CNG_dec_inst* CngDecoderInstance();
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-03-18 09:47:08 +00:00
|
|
|
virtual size_t Channels() const = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
static SpeechType ConvertSpeechType(int16_t type);
|
|
|
|
|
|
2015-03-16 12:30:37 +00:00
|
|
|
virtual int DecodeInternal(const uint8_t* encoded,
|
|
|
|
|
size_t encoded_len,
|
|
|
|
|
int sample_rate_hz,
|
|
|
|
|
int16_t* decoded,
|
|
|
|
|
SpeechType* speech_type);
|
|
|
|
|
|
|
|
|
|
virtual int DecodeRedundantInternal(const uint8_t* encoded,
|
|
|
|
|
size_t encoded_len,
|
|
|
|
|
int sample_rate_hz,
|
|
|
|
|
int16_t* decoded,
|
|
|
|
|
SpeechType* speech_type);
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
private:
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder);
|
2013-01-29 12:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
2014-06-09 08:10:28 +00:00
|
|
|
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INTERFACE_AUDIO_DECODER_H_
|