tor-browser

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

audio_decoder_pcm.cc (4106B)


      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 #include "modules/audio_coding/codecs/g711/audio_decoder_pcm.h"
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 #include <utility>
     16 #include <vector>
     17 
     18 #include "api/audio_codecs/audio_decoder.h"
     19 #include "modules/audio_coding/codecs/g711/g711_interface.h"
     20 #include "modules/audio_coding/codecs/legacy_encoded_audio_frame.h"
     21 #include "rtc_base/buffer.h"
     22 #include "rtc_base/checks.h"
     23 
     24 namespace webrtc {
     25 
     26 void AudioDecoderPcmU::Reset() {}
     27 
     28 std::vector<AudioDecoder::ParseResult> AudioDecoderPcmU::ParsePayload(
     29    Buffer&& payload,
     30    uint32_t timestamp) {
     31  return LegacyEncodedAudioFrame::SplitBySamples(
     32      this, std::move(payload), timestamp, 8 * num_channels_, 8);
     33 }
     34 
     35 int AudioDecoderPcmU::SampleRateHz() const {
     36  return 8000;
     37 }
     38 
     39 size_t AudioDecoderPcmU::Channels() const {
     40  return num_channels_;
     41 }
     42 
     43 int AudioDecoderPcmU::DecodeInternal(const uint8_t* encoded,
     44                                     size_t encoded_len,
     45                                     int sample_rate_hz,
     46                                     int16_t* decoded,
     47                                     SpeechType* speech_type) {
     48  RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz);
     49  // Adjust the encoded length down to ensure the same number of samples in each
     50  // channel.
     51  const size_t encoded_len_adjusted =
     52      PacketDuration(encoded, encoded_len) *
     53      Channels();         // 1 byte per sample per channel
     54  int16_t temp_type = 1;  // Default is speech.
     55  size_t ret =
     56      WebRtcG711_DecodeU(encoded, encoded_len_adjusted, decoded, &temp_type);
     57  *speech_type = ConvertSpeechType(temp_type);
     58  return static_cast<int>(ret);
     59 }
     60 
     61 int AudioDecoderPcmU::PacketDuration(const uint8_t* /* encoded */,
     62                                     size_t encoded_len) const {
     63  // One encoded byte per sample per channel.
     64  return static_cast<int>(encoded_len / Channels());
     65 }
     66 
     67 int AudioDecoderPcmU::PacketDurationRedundant(const uint8_t* encoded,
     68                                              size_t encoded_len) const {
     69  return PacketDuration(encoded, encoded_len);
     70 }
     71 
     72 void AudioDecoderPcmA::Reset() {}
     73 
     74 std::vector<AudioDecoder::ParseResult> AudioDecoderPcmA::ParsePayload(
     75    Buffer&& payload,
     76    uint32_t timestamp) {
     77  return LegacyEncodedAudioFrame::SplitBySamples(
     78      this, std::move(payload), timestamp, 8 * num_channels_, 8);
     79 }
     80 
     81 int AudioDecoderPcmA::SampleRateHz() const {
     82  return 8000;
     83 }
     84 
     85 size_t AudioDecoderPcmA::Channels() const {
     86  return num_channels_;
     87 }
     88 
     89 int AudioDecoderPcmA::DecodeInternal(const uint8_t* encoded,
     90                                     size_t encoded_len,
     91                                     int sample_rate_hz,
     92                                     int16_t* decoded,
     93                                     SpeechType* speech_type) {
     94  RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz);
     95  // Adjust the encoded length down to ensure the same number of samples in each
     96  // channel.
     97  const size_t encoded_len_adjusted =
     98      PacketDuration(encoded, encoded_len) *
     99      Channels();         // 1 byte per sample per channel
    100  int16_t temp_type = 1;  // Default is speech.
    101  size_t ret =
    102      WebRtcG711_DecodeA(encoded, encoded_len_adjusted, decoded, &temp_type);
    103  *speech_type = ConvertSpeechType(temp_type);
    104  return static_cast<int>(ret);
    105 }
    106 
    107 int AudioDecoderPcmA::PacketDuration(const uint8_t* /* encoded */,
    108                                     size_t encoded_len) const {
    109  // One encoded byte per sample per channel.
    110  return static_cast<int>(encoded_len / Channels());
    111 }
    112 
    113 int AudioDecoderPcmA::PacketDurationRedundant(const uint8_t* encoded,
    114                                              size_t encoded_len) const {
    115  return PacketDuration(encoded, encoded_len);
    116 }
    117 
    118 }  // namespace webrtc