xref: /aosp_15_r20/external/webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.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_G711_AUDIO_DECODER_PCM_H_
12 #define MODULES_AUDIO_CODING_CODECS_G711_AUDIO_DECODER_PCM_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 "rtc_base/buffer.h"
21 #include "rtc_base/checks.h"
22 
23 namespace webrtc {
24 
25 class AudioDecoderPcmU final : public AudioDecoder {
26  public:
AudioDecoderPcmU(size_t num_channels)27   explicit AudioDecoderPcmU(size_t num_channels) : num_channels_(num_channels) {
28     RTC_DCHECK_GE(num_channels, 1);
29   }
30 
31   AudioDecoderPcmU(const AudioDecoderPcmU&) = delete;
32   AudioDecoderPcmU& operator=(const AudioDecoderPcmU&) = delete;
33 
34   void Reset() override;
35   std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
36                                         uint32_t timestamp) override;
37   int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
38   int SampleRateHz() const override;
39   size_t Channels() const override;
40 
41  protected:
42   int DecodeInternal(const uint8_t* encoded,
43                      size_t encoded_len,
44                      int sample_rate_hz,
45                      int16_t* decoded,
46                      SpeechType* speech_type) override;
47 
48  private:
49   const size_t num_channels_;
50 };
51 
52 class AudioDecoderPcmA final : public AudioDecoder {
53  public:
AudioDecoderPcmA(size_t num_channels)54   explicit AudioDecoderPcmA(size_t num_channels) : num_channels_(num_channels) {
55     RTC_DCHECK_GE(num_channels, 1);
56   }
57 
58   AudioDecoderPcmA(const AudioDecoderPcmA&) = delete;
59   AudioDecoderPcmA& operator=(const AudioDecoderPcmA&) = delete;
60 
61   void Reset() override;
62   std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
63                                         uint32_t timestamp) override;
64   int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
65   int SampleRateHz() const override;
66   size_t Channels() const override;
67 
68  protected:
69   int DecodeInternal(const uint8_t* encoded,
70                      size_t encoded_len,
71                      int sample_rate_hz,
72                      int16_t* decoded,
73                      SpeechType* speech_type) override;
74 
75  private:
76   const size_t num_channels_;
77 };
78 
79 }  // namespace webrtc
80 
81 #endif  // MODULES_AUDIO_CODING_CODECS_G711_AUDIO_DECODER_PCM_H_
82