123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- #ifndef API_AUDIO_CODECS_AUDIO_DECODER_H_
- #define API_AUDIO_CODECS_AUDIO_DECODER_H_
- #include <stddef.h>
- #include <stdint.h>
- #include <memory>
- #include <vector>
- #include "absl/types/optional.h"
- #include "api/array_view.h"
- #include "rtc_base/buffer.h"
- #include "rtc_base/constructor_magic.h"
- namespace webrtc {
- class AudioDecoder {
- public:
- enum SpeechType {
- kSpeech = 1,
- kComfortNoise = 2,
- };
-
- enum { kNotImplemented = -2 };
- AudioDecoder() = default;
- virtual ~AudioDecoder() = default;
- class EncodedAudioFrame {
- public:
- struct DecodeResult {
- size_t num_decoded_samples;
- SpeechType speech_type;
- };
- virtual ~EncodedAudioFrame() = default;
-
-
- virtual size_t Duration() const = 0;
-
- virtual bool IsDtxPacket() const;
-
-
-
-
-
-
- virtual absl::optional<DecodeResult> Decode(
- rtc::ArrayView<int16_t> decoded) const = 0;
- };
- struct ParseResult {
- ParseResult();
- ParseResult(uint32_t timestamp,
- int priority,
- std::unique_ptr<EncodedAudioFrame> frame);
- ParseResult(ParseResult&& b);
- ~ParseResult();
- ParseResult& operator=(ParseResult&& b);
-
- uint32_t timestamp;
-
-
-
- int priority;
- std::unique_ptr<EncodedAudioFrame> frame;
- };
-
-
-
-
-
-
- virtual std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
- uint32_t timestamp);
-
-
-
-
-
-
-
-
-
-
- int Decode(const uint8_t* encoded,
- size_t encoded_len,
- int sample_rate_hz,
- size_t max_decoded_bytes,
- int16_t* decoded,
- SpeechType* speech_type);
-
-
- int DecodeRedundant(const uint8_t* encoded,
- size_t encoded_len,
- int sample_rate_hz,
- size_t max_decoded_bytes,
- int16_t* decoded,
- SpeechType* speech_type);
-
- virtual bool HasDecodePlc() const;
-
-
-
- virtual size_t DecodePlc(size_t num_frames, int16_t* decoded);
-
-
-
-
-
-
-
-
-
-
-
- virtual void GeneratePlc(size_t requested_samples_per_channel,
- rtc::BufferT<int16_t>* concealment_audio);
-
- virtual void Reset() = 0;
-
- virtual int ErrorCode();
-
-
-
- virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len) const;
-
-
-
- virtual int PacketDurationRedundant(const uint8_t* encoded,
- size_t encoded_len) const;
-
-
-
- virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const;
-
-
- virtual int SampleRateHz() const = 0;
-
-
- virtual size_t Channels() const = 0;
- protected:
- static SpeechType ConvertSpeechType(int16_t type);
- virtual int DecodeInternal(const uint8_t* encoded,
- size_t encoded_len,
- int sample_rate_hz,
- int16_t* decoded,
- SpeechType* speech_type) = 0;
- virtual int DecodeRedundantInternal(const uint8_t* encoded,
- size_t encoded_len,
- int sample_rate_hz,
- int16_t* decoded,
- SpeechType* speech_type);
- private:
- RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder);
- };
- }
- #endif
|