• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 namespace webrtc {
26 
27 class AudioDecoderMultiChannelOpusImpl final : public AudioDecoder {
28  public:
29   static std::unique_ptr<AudioDecoderMultiChannelOpusImpl> MakeAudioDecoder(
30       AudioDecoderMultiChannelOpusConfig config);
31 
32   ~AudioDecoderMultiChannelOpusImpl() override;
33 
34   AudioDecoderMultiChannelOpusImpl(const AudioDecoderMultiChannelOpusImpl&) =
35       delete;
36   AudioDecoderMultiChannelOpusImpl& operator=(
37       const AudioDecoderMultiChannelOpusImpl&) = delete;
38 
39   std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
40                                         uint32_t timestamp) override;
41   void Reset() override;
42   int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
43   int PacketDurationRedundant(const uint8_t* encoded,
44                               size_t encoded_len) const override;
45   bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const override;
46   int SampleRateHz() const override;
47   size_t Channels() const override;
48 
49   static absl::optional<AudioDecoderMultiChannelOpusConfig> SdpToConfig(
50       const SdpAudioFormat& format);
51 
52  protected:
53   int DecodeInternal(const uint8_t* encoded,
54                      size_t encoded_len,
55                      int sample_rate_hz,
56                      int16_t* decoded,
57                      SpeechType* speech_type) override;
58   int DecodeRedundantInternal(const uint8_t* encoded,
59                               size_t encoded_len,
60                               int sample_rate_hz,
61                               int16_t* decoded,
62                               SpeechType* speech_type) override;
63 
64  private:
65   AudioDecoderMultiChannelOpusImpl(OpusDecInst* dec_state,
66                                    AudioDecoderMultiChannelOpusConfig config);
67 
68   OpusDecInst* dec_state_;
69   const AudioDecoderMultiChannelOpusConfig config_;
70 };
71 
72 }  // namespace webrtc
73 
74 #endif  // MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_DECODER_MULTI_CHANNEL_OPUS_IMPL_H_
75