tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

audio_decoder_g722.h (3287B)


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