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 #include "rtc_base/constructor_magic.h"
23 
24 namespace webrtc {
25 
26 class AudioDecoderOpusImpl final : public AudioDecoder {
27  public:
28   explicit AudioDecoderOpusImpl(size_t num_channels,
29                                 int sample_rate_hz = 48000);
30   ~AudioDecoderOpusImpl() override;
31 
32   std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
33                                         uint32_t timestamp) override;
34   void Reset() override;
35   int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
36   int PacketDurationRedundant(const uint8_t* encoded,
37                               size_t encoded_len) const override;
38   bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const override;
39   int SampleRateHz() const override;
40   size_t Channels() const override;
41 
42  protected:
43   int DecodeInternal(const uint8_t* encoded,
44                      size_t encoded_len,
45                      int sample_rate_hz,
46                      int16_t* decoded,
47                      SpeechType* speech_type) override;
48   int DecodeRedundantInternal(const uint8_t* encoded,
49                               size_t encoded_len,
50                               int sample_rate_hz,
51                               int16_t* decoded,
52                               SpeechType* speech_type) override;
53 
54  private:
55   OpusDecInst* dec_state_;
56   const size_t channels_;
57   const int sample_rate_hz_;
58   RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderOpusImpl);
59 };
60 
61 }  // namespace webrtc
62 
63 #endif  // MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_DECODER_OPUS_H_
64