xref: /aosp_15_r20/external/webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2015 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 #ifndef MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_DECODER_OPUS_H_
12 #define MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_DECODER_OPUS_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include <vector>
18 
19 #include "api/audio_codecs/audio_decoder.h"
20 #include "modules/audio_coding/codecs/opus/opus_interface.h"
21 #include "rtc_base/buffer.h"
22 
23 namespace webrtc {
24 
25 class AudioDecoderOpusImpl final : public AudioDecoder {
26  public:
27   explicit AudioDecoderOpusImpl(size_t num_channels,
28                                 int sample_rate_hz = 48000);
29   ~AudioDecoderOpusImpl() override;
30 
31   AudioDecoderOpusImpl(const AudioDecoderOpusImpl&) = delete;
32   AudioDecoderOpusImpl& operator=(const AudioDecoderOpusImpl&) = delete;
33 
34   std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
35                                         uint32_t timestamp) override;
36   void Reset() override;
37   int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
38   int PacketDurationRedundant(const uint8_t* encoded,
39                               size_t encoded_len) const override;
40   bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const override;
41   int SampleRateHz() const override;
42   size_t Channels() const override;
43 
44  protected:
45   int DecodeInternal(const uint8_t* encoded,
46                      size_t encoded_len,
47                      int sample_rate_hz,
48                      int16_t* decoded,
49                      SpeechType* speech_type) override;
50   int DecodeRedundantInternal(const uint8_t* encoded,
51                               size_t encoded_len,
52                               int sample_rate_hz,
53                               int16_t* decoded,
54                               SpeechType* speech_type) override;
55 
56  private:
57   OpusDecInst* dec_state_;
58   const size_t channels_;
59   const int sample_rate_hz_;
60 };
61 
62 }  // namespace webrtc
63 
64 #endif  // MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_DECODER_OPUS_H_
65