Repo created
This commit is contained in:
parent
81b91f4139
commit
f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "modules/audio_coding/codecs/legacy_encoded_audio_frame.h"
|
||||
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
AudioDecoderPcm16B::AudioDecoderPcm16B(int sample_rate_hz, size_t num_channels)
|
||||
: sample_rate_hz_(sample_rate_hz), num_channels_(num_channels) {
|
||||
RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 ||
|
||||
sample_rate_hz == 32000 || sample_rate_hz == 48000)
|
||||
<< "Unsupported sample rate " << sample_rate_hz;
|
||||
RTC_DCHECK_GE(num_channels, 1);
|
||||
}
|
||||
|
||||
void AudioDecoderPcm16B::Reset() {}
|
||||
|
||||
int AudioDecoderPcm16B::SampleRateHz() const {
|
||||
return sample_rate_hz_;
|
||||
}
|
||||
|
||||
size_t AudioDecoderPcm16B::Channels() const {
|
||||
return num_channels_;
|
||||
}
|
||||
|
||||
int AudioDecoderPcm16B::DecodeInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
RTC_DCHECK_EQ(sample_rate_hz_, sample_rate_hz);
|
||||
// Adjust the encoded length down to ensure the same number of samples in each
|
||||
// channel.
|
||||
const size_t encoded_len_adjusted =
|
||||
PacketDuration(encoded, encoded_len) * 2 *
|
||||
Channels(); // 2 bytes per sample per channel
|
||||
size_t ret = WebRtcPcm16b_Decode(encoded, encoded_len_adjusted, decoded);
|
||||
*speech_type = ConvertSpeechType(1);
|
||||
return static_cast<int>(ret);
|
||||
}
|
||||
|
||||
std::vector<AudioDecoder::ParseResult> AudioDecoderPcm16B::ParsePayload(
|
||||
rtc::Buffer&& payload,
|
||||
uint32_t timestamp) {
|
||||
const int samples_per_ms = rtc::CheckedDivExact(sample_rate_hz_, 1000);
|
||||
return LegacyEncodedAudioFrame::SplitBySamples(
|
||||
this, std::move(payload), timestamp, samples_per_ms * 2 * num_channels_,
|
||||
samples_per_ms);
|
||||
}
|
||||
|
||||
int AudioDecoderPcm16B::PacketDuration(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
// Two encoded byte per sample per channel.
|
||||
return static_cast<int>(encoded_len / (2 * Channels()));
|
||||
}
|
||||
|
||||
int AudioDecoderPcm16B::PacketDurationRedundant(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
return PacketDuration(encoded, encoded_len);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_AUDIO_CODING_CODECS_PCM16B_AUDIO_DECODER_PCM16B_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_PCM16B_AUDIO_DECODER_PCM16B_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio_codecs/audio_decoder.h"
|
||||
#include "rtc_base/buffer.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class AudioDecoderPcm16B final : public AudioDecoder {
|
||||
public:
|
||||
AudioDecoderPcm16B(int sample_rate_hz, size_t num_channels);
|
||||
|
||||
AudioDecoderPcm16B(const AudioDecoderPcm16B&) = delete;
|
||||
AudioDecoderPcm16B& operator=(const AudioDecoderPcm16B&) = delete;
|
||||
|
||||
void Reset() override;
|
||||
std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
|
||||
uint32_t timestamp) override;
|
||||
int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
|
||||
int PacketDurationRedundant(const uint8_t* encoded,
|
||||
size_t encoded_len) const override;
|
||||
int SampleRateHz() const override;
|
||||
size_t Channels() const override;
|
||||
|
||||
protected:
|
||||
int DecodeInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) override;
|
||||
|
||||
private:
|
||||
const int sample_rate_hz_;
|
||||
const size_t num_channels_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_CODING_CODECS_PCM16B_AUDIO_DECODER_PCM16B_H_
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h"
|
||||
|
||||
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
size_t AudioEncoderPcm16B::EncodeCall(const int16_t* audio,
|
||||
size_t input_len,
|
||||
uint8_t* encoded) {
|
||||
return WebRtcPcm16b_Encode(audio, input_len, encoded);
|
||||
}
|
||||
|
||||
size_t AudioEncoderPcm16B::BytesPerSample() const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
AudioEncoder::CodecType AudioEncoderPcm16B::GetCodecType() const {
|
||||
return CodecType::kOther;
|
||||
}
|
||||
|
||||
bool AudioEncoderPcm16B::Config::IsOk() const {
|
||||
if ((sample_rate_hz != 8000) && (sample_rate_hz != 16000) &&
|
||||
(sample_rate_hz != 32000) && (sample_rate_hz != 48000))
|
||||
return false;
|
||||
return AudioEncoderPcm::Config::IsOk();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_AUDIO_CODING_CODECS_PCM16B_AUDIO_ENCODER_PCM16B_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_PCM16B_AUDIO_ENCODER_PCM16B_H_
|
||||
|
||||
#include "modules/audio_coding/codecs/g711/audio_encoder_pcm.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class AudioEncoderPcm16B final : public AudioEncoderPcm {
|
||||
public:
|
||||
struct Config : public AudioEncoderPcm::Config {
|
||||
public:
|
||||
Config() : AudioEncoderPcm::Config(107), sample_rate_hz(8000) {}
|
||||
bool IsOk() const;
|
||||
|
||||
int sample_rate_hz;
|
||||
};
|
||||
|
||||
explicit AudioEncoderPcm16B(const Config& config)
|
||||
: AudioEncoderPcm(config, config.sample_rate_hz) {}
|
||||
|
||||
AudioEncoderPcm16B(const AudioEncoderPcm16B&) = delete;
|
||||
AudioEncoderPcm16B& operator=(const AudioEncoderPcm16B&) = delete;
|
||||
|
||||
protected:
|
||||
size_t EncodeCall(const int16_t* audio,
|
||||
size_t input_len,
|
||||
uint8_t* encoded) override;
|
||||
|
||||
size_t BytesPerSample() const override;
|
||||
|
||||
AudioEncoder::CodecType GetCodecType() const override;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_CODING_CODECS_PCM16B_AUDIO_ENCODER_PCM16B_H_
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
|
||||
|
||||
size_t WebRtcPcm16b_Encode(const int16_t* speech,
|
||||
size_t len,
|
||||
uint8_t* encoded) {
|
||||
size_t i;
|
||||
for (i = 0; i < len; ++i) {
|
||||
uint16_t s = speech[i];
|
||||
encoded[2 * i] = s >> 8;
|
||||
encoded[2 * i + 1] = s;
|
||||
}
|
||||
return 2 * len;
|
||||
}
|
||||
|
||||
size_t WebRtcPcm16b_Decode(const uint8_t* encoded,
|
||||
size_t len,
|
||||
int16_t* speech) {
|
||||
size_t i;
|
||||
for (i = 0; i < len / 2; ++i)
|
||||
speech[i] = encoded[2 * i] << 8 | encoded[2 * i + 1];
|
||||
return len / 2;
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_AUDIO_CODING_CODECS_PCM16B_PCM16B_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_PCM16B_PCM16B_H_
|
||||
/*
|
||||
* Define the fixpoint numeric formats
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcPcm16b_Encode(...)
|
||||
*
|
||||
* "Encode" a sample vector to 16 bit linear (Encoded standard is big endian)
|
||||
*
|
||||
* Input:
|
||||
* - speech : Input speech vector
|
||||
* - len : Number of samples in speech vector
|
||||
*
|
||||
* Output:
|
||||
* - encoded : Encoded data vector (big endian 16 bit)
|
||||
*
|
||||
* Returned value : Length (in bytes) of coded data.
|
||||
* Always equal to twice the len input parameter.
|
||||
*/
|
||||
|
||||
size_t WebRtcPcm16b_Encode(const int16_t* speech, size_t len, uint8_t* encoded);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcPcm16b_Decode(...)
|
||||
*
|
||||
* "Decode" a vector to 16 bit linear (Encoded standard is big endian)
|
||||
*
|
||||
* Input:
|
||||
* - encoded : Encoded data vector (big endian 16 bit)
|
||||
* - len : Number of bytes in encoded
|
||||
*
|
||||
* Output:
|
||||
* - speech : Decoded speech vector
|
||||
*
|
||||
* Returned value : Samples in speech
|
||||
*/
|
||||
|
||||
size_t WebRtcPcm16b_Decode(const uint8_t* encoded, size_t len, int16_t* speech);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MODULES_AUDIO_CODING_CODECS_PCM16B_PCM16B_H_ */
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/audio_coding/codecs/pcm16b/pcm16b_common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
void Pcm16BAppendSupportedCodecSpecs(std::vector<AudioCodecSpec>* specs) {
|
||||
for (uint8_t num_channels : {1, 2}) {
|
||||
for (int sample_rate_hz : {8000, 16000, 32000}) {
|
||||
specs->push_back(
|
||||
{{"L16", sample_rate_hz, num_channels},
|
||||
{sample_rate_hz, num_channels, sample_rate_hz * num_channels * 16}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_AUDIO_CODING_CODECS_PCM16B_PCM16B_COMMON_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_PCM16B_PCM16B_COMMON_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio_codecs/audio_format.h"
|
||||
|
||||
namespace webrtc {
|
||||
void Pcm16BAppendSupportedCodecSpecs(std::vector<AudioCodecSpec>* specs);
|
||||
}
|
||||
|
||||
#endif // MODULES_AUDIO_CODING_CODECS_PCM16B_PCM16B_COMMON_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue