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_G722_AUDIO_DECODER_G722_H_ 12 #define MODULES_AUDIO_CODING_CODECS_G722_AUDIO_DECODER_G722_H_ 13 14 #include "api/audio_codecs/audio_decoder.h" 15 16 typedef struct WebRtcG722DecInst G722DecInst; 17 18 namespace webrtc { 19 20 class AudioDecoderG722Impl final : public AudioDecoder { 21 public: 22 AudioDecoderG722Impl(); 23 ~AudioDecoderG722Impl() override; 24 25 AudioDecoderG722Impl(const AudioDecoderG722Impl&) = delete; 26 AudioDecoderG722Impl& operator=(const AudioDecoderG722Impl&) = delete; 27 28 bool HasDecodePlc() const override; 29 void Reset() override; 30 std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload, 31 uint32_t timestamp) override; 32 int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override; 33 int SampleRateHz() const override; 34 size_t Channels() const override; 35 36 protected: 37 int DecodeInternal(const uint8_t* encoded, 38 size_t encoded_len, 39 int sample_rate_hz, 40 int16_t* decoded, 41 SpeechType* speech_type) override; 42 43 private: 44 G722DecInst* dec_state_; 45 }; 46 47 class AudioDecoderG722StereoImpl final : public AudioDecoder { 48 public: 49 AudioDecoderG722StereoImpl(); 50 ~AudioDecoderG722StereoImpl() override; 51 52 AudioDecoderG722StereoImpl(const AudioDecoderG722StereoImpl&) = delete; 53 AudioDecoderG722StereoImpl& operator=(const AudioDecoderG722StereoImpl&) = 54 delete; 55 56 void Reset() override; 57 std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload, 58 uint32_t timestamp) override; 59 int SampleRateHz() const override; 60 int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override; 61 size_t Channels() const override; 62 63 protected: 64 int DecodeInternal(const uint8_t* encoded, 65 size_t encoded_len, 66 int sample_rate_hz, 67 int16_t* decoded, 68 SpeechType* speech_type) override; 69 70 private: 71 // Splits the stereo-interleaved payload in `encoded` into separate payloads 72 // for left and right channels. The separated payloads are written to 73 // `encoded_deinterleaved`, which must hold at least `encoded_len` samples. 74 // The left channel starts at offset 0, while the right channel starts at 75 // offset encoded_len / 2 into `encoded_deinterleaved`. 76 void SplitStereoPacket(const uint8_t* encoded, 77 size_t encoded_len, 78 uint8_t* encoded_deinterleaved); 79 80 G722DecInst* dec_state_left_; 81 G722DecInst* dec_state_right_; 82 }; 83 84 } // namespace webrtc 85 86 #endif // MODULES_AUDIO_CODING_CODECS_G722_AUDIO_DECODER_G722_H_ 87