1 /*
2  *  Copyright (c) 2019 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_MULTI_CHANNEL_OPUS_IMPL_H_
12 #define MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_DECODER_MULTI_CHANNEL_OPUS_IMPL_H_
13 
14 #include <stddef.h>
15 
16 #include <memory>
17 #include <vector>
18 
19 #include "api/audio_codecs/audio_decoder.h"
20 #include "api/audio_codecs/audio_format.h"
21 #include "api/audio_codecs/opus/audio_decoder_multi_channel_opus_config.h"
22 #include "modules/audio_coding/codecs/opus/opus_interface.h"
23 #include "rtc_base/buffer.h"
24 #include "rtc_base/constructor_magic.h"
25 
26 namespace webrtc {
27 
28 class AudioDecoderMultiChannelOpusImpl final : public AudioDecoder {
29  public:
30   static std::unique_ptr<AudioDecoderMultiChannelOpusImpl> MakeAudioDecoder(
31       AudioDecoderMultiChannelOpusConfig config);
32 
33   ~AudioDecoderMultiChannelOpusImpl() override;
34 
35   std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
36                                         uint32_t timestamp) override;
37   void Reset() override;
38   int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
39   int PacketDurationRedundant(const uint8_t* encoded,
40                               size_t encoded_len) const override;
41   bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const override;
42   int SampleRateHz() const override;
43   size_t Channels() const override;
44 
45   static absl::optional<AudioDecoderMultiChannelOpusConfig> SdpToConfig(
46       const SdpAudioFormat& format);
47 
48  protected:
49   int DecodeInternal(const uint8_t* encoded,
50                      size_t encoded_len,
51                      int sample_rate_hz,
52                      int16_t* decoded,
53                      SpeechType* speech_type) override;
54   int DecodeRedundantInternal(const uint8_t* encoded,
55                               size_t encoded_len,
56                               int sample_rate_hz,
57                               int16_t* decoded,
58                               SpeechType* speech_type) override;
59 
60  private:
61   AudioDecoderMultiChannelOpusImpl(OpusDecInst* dec_state,
62                                    AudioDecoderMultiChannelOpusConfig config);
63 
64   OpusDecInst* dec_state_;
65   const AudioDecoderMultiChannelOpusConfig config_;
66   RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderMultiChannelOpusImpl);
67 };
68 
69 }  // namespace webrtc
70 
71 #endif  // MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_DECODER_MULTI_CHANNEL_OPUS_IMPL_H_
72