• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 WEBRTC_MODULES_AUDIO_CODING_CODECS_G722_AUDIO_DECODER_G722_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_G722_AUDIO_DECODER_G722_H_
13 
14 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
15 
16 typedef struct WebRtcG722DecInst G722DecInst;
17 
18 namespace webrtc {
19 
20 class AudioDecoderG722 final : public AudioDecoder {
21  public:
22   AudioDecoderG722();
23   ~AudioDecoderG722() override;
24   bool HasDecodePlc() const override;
25   void Reset() override;
26   int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
27   size_t Channels() const override;
28 
29  protected:
30   int DecodeInternal(const uint8_t* encoded,
31                      size_t encoded_len,
32                      int sample_rate_hz,
33                      int16_t* decoded,
34                      SpeechType* speech_type) override;
35 
36  private:
37   G722DecInst* dec_state_;
38   RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722);
39 };
40 
41 class AudioDecoderG722Stereo final : public AudioDecoder {
42  public:
43   AudioDecoderG722Stereo();
44   ~AudioDecoderG722Stereo() override;
45   void Reset() override;
46 
47  protected:
48   int DecodeInternal(const uint8_t* encoded,
49                      size_t encoded_len,
50                      int sample_rate_hz,
51                      int16_t* decoded,
52                      SpeechType* speech_type) override;
53   size_t Channels() const override;
54 
55  private:
56   // Splits the stereo-interleaved payload in |encoded| into separate payloads
57   // for left and right channels. The separated payloads are written to
58   // |encoded_deinterleaved|, which must hold at least |encoded_len| samples.
59   // The left channel starts at offset 0, while the right channel starts at
60   // offset encoded_len / 2 into |encoded_deinterleaved|.
61   void SplitStereoPacket(const uint8_t* encoded,
62                          size_t encoded_len,
63                          uint8_t* encoded_deinterleaved);
64 
65   G722DecInst* dec_state_left_;
66   G722DecInst* dec_state_right_;
67   RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722Stereo);
68 };
69 
70 }  // namespace webrtc
71 
72 #endif  // WEBRTC_MODULES_AUDIO_CODING_CODECS_G722_AUDIO_DECODER_G722_H_
73