Remove some unused files
This commit is contained in:
parent
6119c05d7d
commit
ecb8817972
@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 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 "api/audio_codecs/audio_decoder.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include "rtc_base/buffer.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/sanitizer.h"
|
||||
#include "rtc_base/trace_event.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
class OldStyleEncodedFrame final : public AudioDecoder::EncodedAudioFrame {
|
||||
public:
|
||||
OldStyleEncodedFrame(AudioDecoder* decoder, rtc::Buffer&& payload)
|
||||
: decoder_(decoder), payload_(std::move(payload)) {}
|
||||
|
||||
size_t Duration() const override {
|
||||
const int ret = decoder_->PacketDuration(payload_.data(), payload_.size());
|
||||
return ret < 0 ? 0 : static_cast<size_t>(ret);
|
||||
}
|
||||
|
||||
std::optional<DecodeResult> Decode(
|
||||
rtc::ArrayView<int16_t> decoded) const override {
|
||||
auto speech_type = AudioDecoder::kSpeech;
|
||||
const int ret = decoder_->Decode(
|
||||
payload_.data(), payload_.size(), decoder_->SampleRateHz(),
|
||||
decoded.size() * sizeof(int16_t), decoded.data(), &speech_type);
|
||||
return ret < 0 ? std::nullopt
|
||||
: std::optional<DecodeResult>(
|
||||
{static_cast<size_t>(ret), speech_type});
|
||||
}
|
||||
|
||||
private:
|
||||
AudioDecoder* const decoder_;
|
||||
const rtc::Buffer payload_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool AudioDecoder::EncodedAudioFrame::IsDtxPacket() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
AudioDecoder::ParseResult::ParseResult() = default;
|
||||
AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default;
|
||||
AudioDecoder::ParseResult::ParseResult(uint32_t timestamp,
|
||||
int priority,
|
||||
std::unique_ptr<EncodedAudioFrame> frame)
|
||||
: timestamp(timestamp), priority(priority), frame(std::move(frame)) {
|
||||
RTC_DCHECK_GE(priority, 0);
|
||||
}
|
||||
|
||||
AudioDecoder::ParseResult::~ParseResult() = default;
|
||||
|
||||
AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=(
|
||||
ParseResult&& b) = default;
|
||||
|
||||
std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload(
|
||||
rtc::Buffer&& payload,
|
||||
uint32_t timestamp) {
|
||||
std::vector<ParseResult> results;
|
||||
std::unique_ptr<EncodedAudioFrame> frame(
|
||||
new OldStyleEncodedFrame(this, std::move(payload)));
|
||||
results.emplace_back(timestamp, 0, std::move(frame));
|
||||
return results;
|
||||
}
|
||||
|
||||
int AudioDecoder::Decode(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
size_t max_decoded_bytes,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
TRACE_EVENT0("webrtc", "AudioDecoder::Decode");
|
||||
rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len));
|
||||
int duration = PacketDuration(encoded, encoded_len);
|
||||
if (duration >= 0 &&
|
||||
duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
|
||||
return -1;
|
||||
}
|
||||
return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
|
||||
speech_type);
|
||||
}
|
||||
|
||||
int AudioDecoder::DecodeRedundant(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
size_t max_decoded_bytes,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
TRACE_EVENT0("webrtc", "AudioDecoder::DecodeRedundant");
|
||||
rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len));
|
||||
int duration = PacketDurationRedundant(encoded, encoded_len);
|
||||
if (duration >= 0 &&
|
||||
duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
|
||||
return -1;
|
||||
}
|
||||
return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded,
|
||||
speech_type);
|
||||
}
|
||||
|
||||
int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
|
||||
speech_type);
|
||||
}
|
||||
|
||||
bool AudioDecoder::HasDecodePlc() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO(bugs.webrtc.org/9676): Remove default implementation.
|
||||
void AudioDecoder::GeneratePlc(size_t /*requested_samples_per_channel*/,
|
||||
rtc::BufferT<int16_t>* /*concealment_audio*/) {}
|
||||
|
||||
int AudioDecoder::ErrorCode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AudioDecoder::PacketDuration(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
return kNotImplemented;
|
||||
}
|
||||
|
||||
int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
return kNotImplemented;
|
||||
}
|
||||
|
||||
bool AudioDecoder::PacketHasFec(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) {
|
||||
switch (type) {
|
||||
case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech.
|
||||
case 1:
|
||||
return kSpeech;
|
||||
case 2:
|
||||
return kComfortNoise;
|
||||
default:
|
||||
RTC_DCHECK_NOTREACHED();
|
||||
return kSpeech;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr int AudioDecoder::kMaxNumberOfChannels;
|
||||
} // namespace webrtc
|
@ -1,195 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 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 API_AUDIO_CODECS_AUDIO_DECODER_H_
|
||||
#define API_AUDIO_CODECS_AUDIO_DECODER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include "rtc_base/buffer.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class AudioDecoder {
|
||||
public:
|
||||
enum SpeechType {
|
||||
kSpeech = 1,
|
||||
kComfortNoise = 2,
|
||||
};
|
||||
|
||||
// Used by PacketDuration below. Save the value -1 for errors.
|
||||
enum { kNotImplemented = -2 };
|
||||
|
||||
AudioDecoder() = default;
|
||||
virtual ~AudioDecoder() = default;
|
||||
|
||||
AudioDecoder(const AudioDecoder&) = delete;
|
||||
AudioDecoder& operator=(const AudioDecoder&) = delete;
|
||||
|
||||
class EncodedAudioFrame {
|
||||
public:
|
||||
struct DecodeResult {
|
||||
size_t num_decoded_samples;
|
||||
SpeechType speech_type;
|
||||
};
|
||||
|
||||
virtual ~EncodedAudioFrame() = default;
|
||||
|
||||
// Returns the duration in samples-per-channel of this audio frame.
|
||||
// If no duration can be ascertained, returns zero.
|
||||
virtual size_t Duration() const = 0;
|
||||
|
||||
// Returns true if this packet contains DTX.
|
||||
virtual bool IsDtxPacket() const;
|
||||
|
||||
// Decodes this frame of audio and writes the result in `decoded`.
|
||||
// `decoded` must be large enough to store as many samples as indicated by a
|
||||
// call to Duration() . On success, returns an std::optional containing the
|
||||
// total number of samples across all channels, as well as whether the
|
||||
// decoder produced comfort noise or speech. On failure, returns an empty
|
||||
// std::optional. Decode may be called at most once per frame object.
|
||||
virtual std::optional<DecodeResult> Decode(
|
||||
rtc::ArrayView<int16_t> decoded) const = 0;
|
||||
};
|
||||
|
||||
struct ParseResult {
|
||||
ParseResult();
|
||||
ParseResult(uint32_t timestamp,
|
||||
int priority,
|
||||
std::unique_ptr<EncodedAudioFrame> frame);
|
||||
ParseResult(ParseResult&& b);
|
||||
~ParseResult();
|
||||
|
||||
ParseResult& operator=(ParseResult&& b);
|
||||
|
||||
// The timestamp of the frame is in samples per channel.
|
||||
uint32_t timestamp;
|
||||
// The relative priority of the frame compared to other frames of the same
|
||||
// payload and the same timeframe. A higher value means a lower priority.
|
||||
// The highest priority is zero - negative values are not allowed.
|
||||
int priority;
|
||||
std::unique_ptr<EncodedAudioFrame> frame;
|
||||
};
|
||||
|
||||
// Let the decoder parse this payload and prepare zero or more decodable
|
||||
// frames. Each frame must be between 10 ms and 120 ms long. The caller must
|
||||
// ensure that the AudioDecoder object outlives any frame objects returned by
|
||||
// this call. The decoder is free to swap or move the data from the `payload`
|
||||
// buffer. `timestamp` is the input timestamp, in samples, corresponding to
|
||||
// the start of the payload.
|
||||
virtual std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
|
||||
uint32_t timestamp);
|
||||
|
||||
// TODO(bugs.webrtc.org/10098): The Decode and DecodeRedundant methods are
|
||||
// obsolete; callers should call ParsePayload instead. For now, subclasses
|
||||
// must still implement DecodeInternal.
|
||||
|
||||
// Decodes `encode_len` bytes from `encoded` and writes the result in
|
||||
// `decoded`. The maximum bytes allowed to be written into `decoded` is
|
||||
// `max_decoded_bytes`. Returns the total number of samples across all
|
||||
// channels. If the decoder produced comfort noise, `speech_type`
|
||||
// is set to kComfortNoise, otherwise it is kSpeech. The desired output
|
||||
// sample rate is provided in `sample_rate_hz`, which must be valid for the
|
||||
// codec at hand.
|
||||
int Decode(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
size_t max_decoded_bytes,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type);
|
||||
|
||||
// Same as Decode(), but interfaces to the decoders redundant decode function.
|
||||
// The default implementation simply calls the regular Decode() method.
|
||||
int DecodeRedundant(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
size_t max_decoded_bytes,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type);
|
||||
|
||||
// Indicates if the decoder implements the DecodePlc method.
|
||||
virtual bool HasDecodePlc() const;
|
||||
|
||||
// Calls the packet-loss concealment of the decoder to update the state after
|
||||
// one or several lost packets. The caller has to make sure that the
|
||||
// memory allocated in `decoded` should accommodate `num_frames` frames.
|
||||
virtual size_t DecodePlc(size_t num_frames, int16_t* decoded);
|
||||
|
||||
// Asks the decoder to generate packet-loss concealment and append it to the
|
||||
// end of `concealment_audio`. The concealment audio should be in
|
||||
// channel-interleaved format, with as many channels as the last decoded
|
||||
// packet produced. The implementation must produce at least
|
||||
// requested_samples_per_channel, or nothing at all. This is a signal to the
|
||||
// caller to conceal the loss with other means. If the implementation provides
|
||||
// concealment samples, it is also responsible for "stitching" it together
|
||||
// with the decoded audio on either side of the concealment.
|
||||
// Note: The default implementation of GeneratePlc will be deleted soon. All
|
||||
// implementations must provide their own, which can be a simple as a no-op.
|
||||
// TODO(bugs.webrtc.org/9676): Remove default implementation.
|
||||
virtual void GeneratePlc(size_t requested_samples_per_channel,
|
||||
rtc::BufferT<int16_t>* concealment_audio);
|
||||
|
||||
// Resets the decoder state (empty buffers etc.).
|
||||
virtual void Reset() = 0;
|
||||
|
||||
// Returns the last error code from the decoder.
|
||||
virtual int ErrorCode();
|
||||
|
||||
// Returns the duration in samples-per-channel of the payload in `encoded`
|
||||
// which is `encoded_len` bytes long. Returns kNotImplemented if no duration
|
||||
// estimate is available, or -1 in case of an error.
|
||||
virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len) const;
|
||||
|
||||
// Returns the duration in samples-per-channel of the redandant payload in
|
||||
// `encoded` which is `encoded_len` bytes long. Returns kNotImplemented if no
|
||||
// duration estimate is available, or -1 in case of an error.
|
||||
virtual int PacketDurationRedundant(const uint8_t* encoded,
|
||||
size_t encoded_len) const;
|
||||
|
||||
// Detects whether a packet has forward error correction. The packet is
|
||||
// comprised of the samples in `encoded` which is `encoded_len` bytes long.
|
||||
// Returns true if the packet has FEC and false otherwise.
|
||||
virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const;
|
||||
|
||||
// Returns the actual sample rate of the decoder's output. This value may not
|
||||
// change during the lifetime of the decoder.
|
||||
virtual int SampleRateHz() const = 0;
|
||||
|
||||
// The number of channels in the decoder's output. This value may not change
|
||||
// during the lifetime of the decoder.
|
||||
virtual size_t Channels() const = 0;
|
||||
|
||||
// The maximum number of audio channels supported by WebRTC decoders.
|
||||
static constexpr int kMaxNumberOfChannels = 24;
|
||||
|
||||
protected:
|
||||
static SpeechType ConvertSpeechType(int16_t type);
|
||||
|
||||
virtual int DecodeInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) = 0;
|
||||
|
||||
virtual int DecodeRedundantInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // API_AUDIO_CODECS_AUDIO_DECODER_H_
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
* 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 "api/audio_codecs/audio_encoder.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include "api/call/bitrate_allocation.h"
|
||||
#include "rtc_base/buffer.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/trace_event.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ANAStats::ANAStats() = default;
|
||||
ANAStats::~ANAStats() = default;
|
||||
ANAStats::ANAStats(const ANAStats&) = default;
|
||||
|
||||
AudioEncoder::EncodedInfo::EncodedInfo() = default;
|
||||
AudioEncoder::EncodedInfo::EncodedInfo(const EncodedInfo&) = default;
|
||||
AudioEncoder::EncodedInfo::EncodedInfo(EncodedInfo&&) = default;
|
||||
AudioEncoder::EncodedInfo::~EncodedInfo() = default;
|
||||
AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(
|
||||
const EncodedInfo&) = default;
|
||||
AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(EncodedInfo&&) =
|
||||
default;
|
||||
|
||||
int AudioEncoder::RtpTimestampRateHz() const {
|
||||
return SampleRateHz();
|
||||
}
|
||||
|
||||
AudioEncoder::EncodedInfo AudioEncoder::Encode(
|
||||
uint32_t rtp_timestamp,
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
rtc::Buffer* encoded) {
|
||||
TRACE_EVENT0("webrtc", "AudioEncoder::Encode");
|
||||
RTC_CHECK_EQ(audio.size(),
|
||||
static_cast<size_t>(NumChannels() * SampleRateHz() / 100));
|
||||
|
||||
const size_t old_size = encoded->size();
|
||||
EncodedInfo info = EncodeImpl(rtp_timestamp, audio, encoded);
|
||||
RTC_CHECK_EQ(encoded->size() - old_size, info.encoded_bytes);
|
||||
return info;
|
||||
}
|
||||
|
||||
bool AudioEncoder::SetFec(bool enable) {
|
||||
return !enable;
|
||||
}
|
||||
|
||||
bool AudioEncoder::SetDtx(bool enable) {
|
||||
return !enable;
|
||||
}
|
||||
|
||||
bool AudioEncoder::GetDtx() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AudioEncoder::SetApplication(Application application) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {}
|
||||
|
||||
void AudioEncoder::SetTargetBitrate(int target_bps) {}
|
||||
|
||||
rtc::ArrayView<std::unique_ptr<AudioEncoder>>
|
||||
AudioEncoder::ReclaimContainedEncoders() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AudioEncoder::EnableAudioNetworkAdaptor(const std::string& config_string,
|
||||
RtcEventLog* event_log) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void AudioEncoder::DisableAudioNetworkAdaptor() {}
|
||||
|
||||
void AudioEncoder::OnReceivedUplinkPacketLossFraction(
|
||||
float uplink_packet_loss_fraction) {}
|
||||
|
||||
void AudioEncoder::OnReceivedUplinkRecoverablePacketLossFraction(
|
||||
float uplink_recoverable_packet_loss_fraction) {
|
||||
RTC_DCHECK_NOTREACHED();
|
||||
}
|
||||
|
||||
void AudioEncoder::OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) {
|
||||
OnReceivedUplinkBandwidth(target_audio_bitrate_bps, std::nullopt);
|
||||
}
|
||||
|
||||
void AudioEncoder::OnReceivedUplinkBandwidth(
|
||||
int target_audio_bitrate_bps,
|
||||
std::optional<int64_t> bwe_period_ms) {}
|
||||
|
||||
void AudioEncoder::OnReceivedUplinkAllocation(BitrateAllocationUpdate update) {
|
||||
OnReceivedUplinkBandwidth(update.target_bitrate.bps(),
|
||||
update.bwe_period.ms());
|
||||
}
|
||||
|
||||
void AudioEncoder::OnReceivedRtt(int rtt_ms) {}
|
||||
|
||||
void AudioEncoder::OnReceivedOverhead(size_t overhead_bytes_per_packet) {}
|
||||
|
||||
void AudioEncoder::SetReceiverFrameLengthRange(int min_frame_length_ms,
|
||||
int max_frame_length_ms) {}
|
||||
|
||||
ANAStats AudioEncoder::GetANAStats() const {
|
||||
return ANAStats();
|
||||
}
|
||||
|
||||
constexpr int AudioEncoder::kMaxNumberOfChannels;
|
||||
} // namespace webrtc
|
@ -1,271 +0,0 @@
|
||||
/*
|
||||
* 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 API_AUDIO_CODECS_AUDIO_ENCODER_H_
|
||||
#define API_AUDIO_CODECS_AUDIO_ENCODER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "api/array_view.h"
|
||||
#include "api/call/bitrate_allocation.h"
|
||||
#include "api/units/data_rate.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/buffer.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class RtcEventLog;
|
||||
|
||||
// Statistics related to Audio Network Adaptation.
|
||||
struct ANAStats {
|
||||
ANAStats();
|
||||
ANAStats(const ANAStats&);
|
||||
~ANAStats();
|
||||
// Number of actions taken by the ANA bitrate controller since the start of
|
||||
// the call. If this value is not set, it indicates that the bitrate
|
||||
// controller is disabled.
|
||||
std::optional<uint32_t> bitrate_action_counter;
|
||||
// Number of actions taken by the ANA channel controller since the start of
|
||||
// the call. If this value is not set, it indicates that the channel
|
||||
// controller is disabled.
|
||||
std::optional<uint32_t> channel_action_counter;
|
||||
// Number of actions taken by the ANA DTX controller since the start of the
|
||||
// call. If this value is not set, it indicates that the DTX controller is
|
||||
// disabled.
|
||||
std::optional<uint32_t> dtx_action_counter;
|
||||
// Number of actions taken by the ANA FEC controller since the start of the
|
||||
// call. If this value is not set, it indicates that the FEC controller is
|
||||
// disabled.
|
||||
std::optional<uint32_t> fec_action_counter;
|
||||
// Number of times the ANA frame length controller decided to increase the
|
||||
// frame length since the start of the call. If this value is not set, it
|
||||
// indicates that the frame length controller is disabled.
|
||||
std::optional<uint32_t> frame_length_increase_counter;
|
||||
// Number of times the ANA frame length controller decided to decrease the
|
||||
// frame length since the start of the call. If this value is not set, it
|
||||
// indicates that the frame length controller is disabled.
|
||||
std::optional<uint32_t> frame_length_decrease_counter;
|
||||
// The uplink packet loss fractions as set by the ANA FEC controller. If this
|
||||
// value is not set, it indicates that the ANA FEC controller is not active.
|
||||
std::optional<float> uplink_packet_loss_fraction;
|
||||
};
|
||||
|
||||
// This is the interface class for encoders in AudioCoding module. Each codec
|
||||
// type must have an implementation of this class.
|
||||
class AudioEncoder {
|
||||
public:
|
||||
// Used for UMA logging of codec usage. The same codecs, with the
|
||||
// same values, must be listed in
|
||||
// src/tools/metrics/histograms/histograms.xml in chromium to log
|
||||
// correct values.
|
||||
enum class CodecType {
|
||||
kOther = 0, // Codec not specified, and/or not listed in this enum
|
||||
kOpus = 1,
|
||||
kIsac = 2,
|
||||
kPcmA = 3,
|
||||
kPcmU = 4,
|
||||
kG722 = 5,
|
||||
kIlbc = 6,
|
||||
|
||||
// Number of histogram bins in the UMA logging of codec types. The
|
||||
// total number of different codecs that are logged cannot exceed this
|
||||
// number.
|
||||
kMaxLoggedAudioCodecTypes
|
||||
};
|
||||
|
||||
struct EncodedInfoLeaf {
|
||||
size_t encoded_bytes = 0;
|
||||
uint32_t encoded_timestamp = 0;
|
||||
int payload_type = 0;
|
||||
bool send_even_if_empty = false;
|
||||
bool speech = true;
|
||||
CodecType encoder_type = CodecType::kOther;
|
||||
};
|
||||
|
||||
// This is the main struct for auxiliary encoding information. Each encoded
|
||||
// packet should be accompanied by one EncodedInfo struct, containing the
|
||||
// total number of `encoded_bytes`, the `encoded_timestamp` and the
|
||||
// `payload_type`. If the packet contains redundant encodings, the `redundant`
|
||||
// vector will be populated with EncodedInfoLeaf structs. Each struct in the
|
||||
// vector represents one encoding; the order of structs in the vector is the
|
||||
// same as the order in which the actual payloads are written to the byte
|
||||
// stream. When EncoderInfoLeaf structs are present in the vector, the main
|
||||
// struct's `encoded_bytes` will be the sum of all the `encoded_bytes` in the
|
||||
// vector.
|
||||
struct EncodedInfo : public EncodedInfoLeaf {
|
||||
EncodedInfo();
|
||||
EncodedInfo(const EncodedInfo&);
|
||||
EncodedInfo(EncodedInfo&&);
|
||||
~EncodedInfo();
|
||||
EncodedInfo& operator=(const EncodedInfo&);
|
||||
EncodedInfo& operator=(EncodedInfo&&);
|
||||
|
||||
std::vector<EncodedInfoLeaf> redundant;
|
||||
};
|
||||
|
||||
virtual ~AudioEncoder() = default;
|
||||
|
||||
// Returns the input sample rate in Hz and the number of input channels.
|
||||
// These are constants set at instantiation time.
|
||||
virtual int SampleRateHz() const = 0;
|
||||
virtual size_t NumChannels() const = 0;
|
||||
|
||||
// Returns the rate at which the RTP timestamps are updated. The default
|
||||
// implementation returns SampleRateHz().
|
||||
virtual int RtpTimestampRateHz() const;
|
||||
|
||||
// Returns the number of 10 ms frames the encoder will put in the next
|
||||
// packet. This value may only change when Encode() outputs a packet; i.e.,
|
||||
// the encoder may vary the number of 10 ms frames from packet to packet, but
|
||||
// it must decide the length of the next packet no later than when outputting
|
||||
// the preceding packet.
|
||||
virtual size_t Num10MsFramesInNextPacket() const = 0;
|
||||
|
||||
// Returns the maximum value that can be returned by
|
||||
// Num10MsFramesInNextPacket().
|
||||
virtual size_t Max10MsFramesInAPacket() const = 0;
|
||||
|
||||
// Returns the current target bitrate in bits/s. The value -1 means that the
|
||||
// codec adapts the target automatically, and a current target cannot be
|
||||
// provided.
|
||||
virtual int GetTargetBitrate() const = 0;
|
||||
|
||||
// Accepts one 10 ms block of input audio (i.e., SampleRateHz() / 100 *
|
||||
// NumChannels() samples). Multi-channel audio must be sample-interleaved.
|
||||
// The encoder appends zero or more bytes of output to `encoded` and returns
|
||||
// additional encoding information. Encode() checks some preconditions, calls
|
||||
// EncodeImpl() which does the actual work, and then checks some
|
||||
// postconditions.
|
||||
EncodedInfo Encode(uint32_t rtp_timestamp,
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
rtc::Buffer* encoded);
|
||||
|
||||
// Resets the encoder to its starting state, discarding any input that has
|
||||
// been fed to the encoder but not yet emitted in a packet.
|
||||
virtual void Reset() = 0;
|
||||
|
||||
// Enables or disables codec-internal FEC (forward error correction). Returns
|
||||
// true if the codec was able to comply. The default implementation returns
|
||||
// true when asked to disable FEC and false when asked to enable it (meaning
|
||||
// that FEC isn't supported).
|
||||
virtual bool SetFec(bool enable);
|
||||
|
||||
// Enables or disables codec-internal VAD/DTX. Returns true if the codec was
|
||||
// able to comply. The default implementation returns true when asked to
|
||||
// disable DTX and false when asked to enable it (meaning that DTX isn't
|
||||
// supported).
|
||||
virtual bool SetDtx(bool enable);
|
||||
|
||||
// Returns the status of codec-internal DTX. The default implementation always
|
||||
// returns false.
|
||||
virtual bool GetDtx() const;
|
||||
|
||||
// Sets the application mode. Returns true if the codec was able to comply.
|
||||
// The default implementation just returns false.
|
||||
enum class Application { kSpeech, kAudio };
|
||||
virtual bool SetApplication(Application application);
|
||||
|
||||
// Tells the encoder about the highest sample rate the decoder is expected to
|
||||
// use when decoding the bitstream. The encoder would typically use this
|
||||
// information to adjust the quality of the encoding. The default
|
||||
// implementation does nothing.
|
||||
virtual void SetMaxPlaybackRate(int frequency_hz);
|
||||
|
||||
// Tells the encoder what average bitrate we'd like it to produce. The
|
||||
// encoder is free to adjust or disregard the given bitrate (the default
|
||||
// implementation does the latter).
|
||||
ABSL_DEPRECATED("Use OnReceivedTargetAudioBitrate instead")
|
||||
virtual void SetTargetBitrate(int target_bps);
|
||||
|
||||
// Causes this encoder to let go of any other encoders it contains, and
|
||||
// returns a pointer to an array where they are stored (which is required to
|
||||
// live as long as this encoder). Unless the returned array is empty, you may
|
||||
// not call any methods on this encoder afterwards, except for the
|
||||
// destructor. The default implementation just returns an empty array.
|
||||
// NOTE: This method is subject to change. Do not call or override it.
|
||||
virtual rtc::ArrayView<std::unique_ptr<AudioEncoder>>
|
||||
ReclaimContainedEncoders();
|
||||
|
||||
// Enables audio network adaptor. Returns true if successful.
|
||||
virtual bool EnableAudioNetworkAdaptor(const std::string& config_string,
|
||||
RtcEventLog* event_log);
|
||||
|
||||
// Disables audio network adaptor.
|
||||
virtual void DisableAudioNetworkAdaptor();
|
||||
|
||||
// Provides uplink packet loss fraction to this encoder to allow it to adapt.
|
||||
// `uplink_packet_loss_fraction` is in the range [0.0, 1.0].
|
||||
virtual void OnReceivedUplinkPacketLossFraction(
|
||||
float uplink_packet_loss_fraction);
|
||||
|
||||
ABSL_DEPRECATED("")
|
||||
virtual void OnReceivedUplinkRecoverablePacketLossFraction(
|
||||
float uplink_recoverable_packet_loss_fraction);
|
||||
|
||||
// Provides target audio bitrate to this encoder to allow it to adapt.
|
||||
virtual void OnReceivedTargetAudioBitrate(int target_bps);
|
||||
|
||||
// Provides target audio bitrate and corresponding probing interval of
|
||||
// the bandwidth estimator to this encoder to allow it to adapt.
|
||||
virtual void OnReceivedUplinkBandwidth(int target_audio_bitrate_bps,
|
||||
std::optional<int64_t> bwe_period_ms);
|
||||
|
||||
// Provides target audio bitrate and corresponding probing interval of
|
||||
// the bandwidth estimator to this encoder to allow it to adapt.
|
||||
virtual void OnReceivedUplinkAllocation(BitrateAllocationUpdate update);
|
||||
|
||||
// Provides RTT to this encoder to allow it to adapt.
|
||||
virtual void OnReceivedRtt(int rtt_ms);
|
||||
|
||||
// Provides overhead to this encoder to adapt. The overhead is the number of
|
||||
// bytes that will be added to each packet the encoder generates.
|
||||
virtual void OnReceivedOverhead(size_t overhead_bytes_per_packet);
|
||||
|
||||
// To allow encoder to adapt its frame length, it must be provided the frame
|
||||
// length range that receivers can accept.
|
||||
virtual void SetReceiverFrameLengthRange(int min_frame_length_ms,
|
||||
int max_frame_length_ms);
|
||||
|
||||
// Get statistics related to audio network adaptation.
|
||||
virtual ANAStats GetANAStats() const;
|
||||
|
||||
// The range of frame lengths that are supported or nullopt if there's no such
|
||||
// information. This is used together with the bitrate range to calculate the
|
||||
// full bitrate range, including overhead.
|
||||
virtual std::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange()
|
||||
const = 0;
|
||||
|
||||
// The range of payload bitrates that are supported. This is used together
|
||||
// with the frame length range to calculate the full bitrate range, including
|
||||
// overhead.
|
||||
virtual std::optional<std::pair<DataRate, DataRate>> GetBitrateRange() const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// The maximum number of audio channels supported by WebRTC encoders.
|
||||
static constexpr int kMaxNumberOfChannels = 24;
|
||||
|
||||
protected:
|
||||
// Subclasses implement this to perform the actual encoding. Called by
|
||||
// Encode().
|
||||
virtual EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
rtc::Buffer* encoded) = 0;
|
||||
};
|
||||
} // namespace webrtc
|
||||
#endif // API_AUDIO_CODECS_AUDIO_ENCODER_H_
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 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 API_CALL_BITRATE_ALLOCATION_H_
|
||||
#define API_CALL_BITRATE_ALLOCATION_H_
|
||||
|
||||
#include "api/units/data_rate.h"
|
||||
#include "api/units/time_delta.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// BitrateAllocationUpdate provides information to allocated streams about their
|
||||
// bitrate allocation. It originates from the BitrateAllocater class and is
|
||||
// propagated from there.
|
||||
struct BitrateAllocationUpdate {
|
||||
// The allocated target bitrate. Media streams should produce this amount of
|
||||
// data. (Note that this may include packet overhead depending on
|
||||
// configuration.)
|
||||
DataRate target_bitrate = DataRate::Zero();
|
||||
// The allocated part of the estimated link capacity. This is more stable than
|
||||
// the target as it is based on the underlying link capacity estimate. This
|
||||
// should be used to change encoder configuration when the cost of change is
|
||||
// high.
|
||||
DataRate stable_target_bitrate = DataRate::Zero();
|
||||
// Predicted packet loss ratio.
|
||||
double packet_loss_ratio = 0;
|
||||
// Predicted round trip time.
|
||||
TimeDelta round_trip_time = TimeDelta::PlusInfinity();
|
||||
// `bwe_period` is deprecated, use `stable_target_bitrate` allocation instead.
|
||||
TimeDelta bwe_period = TimeDelta::PlusInfinity();
|
||||
// Congestion window pushback bitrate reduction fraction. Used in
|
||||
// VideoStreamEncoder to reduce the bitrate by the given fraction
|
||||
// by dropping frames.
|
||||
double cwnd_reduce_ratio = 0;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // API_CALL_BITRATE_ALLOCATION_H_
|
@ -4,13 +4,9 @@ api_sources = [
|
||||
'audio/audio_processing_statistics.cc',
|
||||
'audio/channel_layout.cc',
|
||||
'audio/echo_canceller3_config.cc',
|
||||
'audio_codecs/audio_decoder.cc',
|
||||
'audio_codecs/audio_encoder.cc',
|
||||
'rtp_headers.cc',
|
||||
'rtp_packet_info.cc',
|
||||
'task_queue/task_queue_base.cc',
|
||||
'units/data_rate.cc',
|
||||
'units/data_size.cc',
|
||||
'units/frequency.cc',
|
||||
'units/time_delta.cc',
|
||||
'units/timestamp.cc',
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 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 "api/units/data_rate.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
std::string ToString(DataRate value) {
|
||||
char buf[64];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
if (value.IsPlusInfinity()) {
|
||||
sb << "+inf bps";
|
||||
} else if (value.IsMinusInfinity()) {
|
||||
sb << "-inf bps";
|
||||
} else {
|
||||
if (value.bps() == 0 || value.bps() % 1000 != 0) {
|
||||
sb << value.bps() << " bps";
|
||||
} else {
|
||||
sb << value.kbps() << " kbps";
|
||||
}
|
||||
}
|
||||
return sb.str();
|
||||
}
|
||||
} // namespace webrtc
|
@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 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 API_UNITS_DATA_RATE_H_
|
||||
#define API_UNITS_DATA_RATE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "api/units/data_size.h"
|
||||
#include "api/units/frequency.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
#include "rtc_base/units/unit_base.h" // IWYU pragma: export
|
||||
|
||||
namespace webrtc {
|
||||
// DataRate is a class that represents a given data rate. This can be used to
|
||||
// represent bandwidth, encoding bitrate, etc. The internal storage is bits per
|
||||
// second (bps).
|
||||
class DataRate final : public rtc_units_impl::RelativeUnit<DataRate> {
|
||||
public:
|
||||
template <typename T>
|
||||
static constexpr DataRate BitsPerSec(T value) {
|
||||
static_assert(std::is_arithmetic<T>::value, "");
|
||||
return FromValue(value);
|
||||
}
|
||||
template <typename T>
|
||||
static constexpr DataRate BytesPerSec(T value) {
|
||||
static_assert(std::is_arithmetic<T>::value, "");
|
||||
return FromFraction(8, value);
|
||||
}
|
||||
template <typename T>
|
||||
static constexpr DataRate KilobitsPerSec(T value) {
|
||||
static_assert(std::is_arithmetic<T>::value, "");
|
||||
return FromFraction(1000, value);
|
||||
}
|
||||
static constexpr DataRate Infinity() { return PlusInfinity(); }
|
||||
|
||||
DataRate() = delete;
|
||||
|
||||
template <typename Sink>
|
||||
friend void AbslStringify(Sink& sink, DataRate value);
|
||||
|
||||
template <typename T = int64_t>
|
||||
constexpr T bps() const {
|
||||
return ToValue<T>();
|
||||
}
|
||||
template <typename T = int64_t>
|
||||
constexpr T bytes_per_sec() const {
|
||||
return ToFraction<8, T>();
|
||||
}
|
||||
template <typename T = int64_t>
|
||||
constexpr T kbps() const {
|
||||
return ToFraction<1000, T>();
|
||||
}
|
||||
constexpr int64_t bps_or(int64_t fallback_value) const {
|
||||
return ToValueOr(fallback_value);
|
||||
}
|
||||
constexpr int64_t kbps_or(int64_t fallback_value) const {
|
||||
return ToFractionOr<1000>(fallback_value);
|
||||
}
|
||||
|
||||
private:
|
||||
// Bits per second used internally to simplify debugging by making the value
|
||||
// more recognizable.
|
||||
friend class rtc_units_impl::UnitBase<DataRate>;
|
||||
using RelativeUnit::RelativeUnit;
|
||||
static constexpr bool one_sided = true;
|
||||
};
|
||||
|
||||
namespace data_rate_impl {
|
||||
inline constexpr int64_t Microbits(const DataSize& size) {
|
||||
constexpr int64_t kMaxBeforeConversion =
|
||||
std::numeric_limits<int64_t>::max() / 8000000;
|
||||
RTC_DCHECK_LE(size.bytes(), kMaxBeforeConversion)
|
||||
<< "size is too large to be expressed in microbits";
|
||||
return size.bytes() * 8000000;
|
||||
}
|
||||
|
||||
inline constexpr int64_t MillibytePerSec(const DataRate& size) {
|
||||
constexpr int64_t kMaxBeforeConversion =
|
||||
std::numeric_limits<int64_t>::max() / (1000 / 8);
|
||||
RTC_DCHECK_LE(size.bps(), kMaxBeforeConversion)
|
||||
<< "rate is too large to be expressed in microbytes per second";
|
||||
return size.bps() * (1000 / 8);
|
||||
}
|
||||
} // namespace data_rate_impl
|
||||
|
||||
inline constexpr DataRate operator/(const DataSize size,
|
||||
const TimeDelta duration) {
|
||||
return DataRate::BitsPerSec(data_rate_impl::Microbits(size) / duration.us());
|
||||
}
|
||||
inline constexpr TimeDelta operator/(const DataSize size, const DataRate rate) {
|
||||
return TimeDelta::Micros(data_rate_impl::Microbits(size) / rate.bps());
|
||||
}
|
||||
inline constexpr DataSize operator*(const DataRate rate,
|
||||
const TimeDelta duration) {
|
||||
int64_t microbits = rate.bps() * duration.us();
|
||||
return DataSize::Bytes((microbits + 4000000) / 8000000);
|
||||
}
|
||||
inline constexpr DataSize operator*(const TimeDelta duration,
|
||||
const DataRate rate) {
|
||||
return rate * duration;
|
||||
}
|
||||
|
||||
inline constexpr DataSize operator/(const DataRate rate,
|
||||
const Frequency frequency) {
|
||||
int64_t millihertz = frequency.millihertz<int64_t>();
|
||||
// Note that the value is truncated here reather than rounded, potentially
|
||||
// introducing an error of .5 bytes if rounding were expected.
|
||||
return DataSize::Bytes(data_rate_impl::MillibytePerSec(rate) / millihertz);
|
||||
}
|
||||
inline constexpr Frequency operator/(const DataRate rate, const DataSize size) {
|
||||
return Frequency::MilliHertz(data_rate_impl::MillibytePerSec(rate) /
|
||||
size.bytes());
|
||||
}
|
||||
inline constexpr DataRate operator*(const DataSize size,
|
||||
const Frequency frequency) {
|
||||
RTC_DCHECK(frequency.IsZero() ||
|
||||
size.bytes() <= std::numeric_limits<int64_t>::max() / 8 /
|
||||
frequency.millihertz<int64_t>());
|
||||
int64_t millibits_per_second =
|
||||
size.bytes() * 8 * frequency.millihertz<int64_t>();
|
||||
return DataRate::BitsPerSec((millibits_per_second + 500) / 1000);
|
||||
}
|
||||
inline constexpr DataRate operator*(const Frequency frequency,
|
||||
const DataSize size) {
|
||||
return size * frequency;
|
||||
}
|
||||
|
||||
RTC_EXPORT std::string ToString(DataRate value);
|
||||
inline std::string ToLogString(DataRate value) {
|
||||
return ToString(value);
|
||||
}
|
||||
|
||||
template <typename Sink>
|
||||
void AbslStringify(Sink& sink, DataRate value) {
|
||||
sink.Append(ToString(value));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // API_UNITS_DATA_RATE_H_
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 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 "api/units/data_size.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
std::string ToString(DataSize value) {
|
||||
char buf[64];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
if (value.IsPlusInfinity()) {
|
||||
sb << "+inf bytes";
|
||||
} else if (value.IsMinusInfinity()) {
|
||||
sb << "-inf bytes";
|
||||
} else {
|
||||
sb << value.bytes() << " bytes";
|
||||
}
|
||||
return sb.str();
|
||||
}
|
||||
} // namespace webrtc
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 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 API_UNITS_DATA_SIZE_H_
|
||||
#define API_UNITS_DATA_SIZE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
#include "rtc_base/units/unit_base.h" // IWYU pragma: export
|
||||
|
||||
namespace webrtc {
|
||||
// DataSize is a class represeting a count of bytes.
|
||||
class DataSize final : public rtc_units_impl::RelativeUnit<DataSize> {
|
||||
public:
|
||||
template <typename T>
|
||||
static constexpr DataSize Bytes(T value) {
|
||||
static_assert(std::is_arithmetic<T>::value, "");
|
||||
return FromValue(value);
|
||||
}
|
||||
static constexpr DataSize Infinity() { return PlusInfinity(); }
|
||||
|
||||
DataSize() = delete;
|
||||
|
||||
template <typename Sink>
|
||||
friend void AbslStringify(Sink& sink, DataSize value);
|
||||
|
||||
template <typename T = int64_t>
|
||||
constexpr T bytes() const {
|
||||
return ToValue<T>();
|
||||
}
|
||||
|
||||
constexpr int64_t bytes_or(int64_t fallback_value) const {
|
||||
return ToValueOr(fallback_value);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class rtc_units_impl::UnitBase<DataSize>;
|
||||
using RelativeUnit::RelativeUnit;
|
||||
static constexpr bool one_sided = true;
|
||||
};
|
||||
|
||||
RTC_EXPORT std::string ToString(DataSize value);
|
||||
inline std::string ToLogString(DataSize value) {
|
||||
return ToString(value);
|
||||
}
|
||||
|
||||
template <typename Sink>
|
||||
void AbslStringify(Sink& sink, DataSize value) {
|
||||
sink.Append(ToString(value));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // API_UNITS_DATA_SIZE_H_
|
@ -4,8 +4,6 @@ common_audio_sources = [
|
||||
'channel_buffer.cc',
|
||||
'fir_filter_c.cc',
|
||||
'fir_filter_factory.cc',
|
||||
'real_fourier.cc',
|
||||
'real_fourier_ooura.cc',
|
||||
'resampler/push_resampler.cc',
|
||||
'resampler/push_sinc_resampler.cc',
|
||||
'resampler/resampler.cc',
|
||||
@ -55,7 +53,6 @@ common_audio_sources = [
|
||||
'vad/vad_gmm.c',
|
||||
'vad/vad_sp.c',
|
||||
'vad/webrtc_vad.c',
|
||||
'window_generator.cc',
|
||||
]
|
||||
|
||||
arch_libs = []
|
||||
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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 "common_audio/real_fourier.h"
|
||||
|
||||
#include "common_audio/real_fourier_ooura.h"
|
||||
#include "common_audio/signal_processing/include/signal_processing_library.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
using std::complex;
|
||||
|
||||
const size_t RealFourier::kFftBufferAlignment = 32;
|
||||
|
||||
std::unique_ptr<RealFourier> RealFourier::Create(int fft_order) {
|
||||
return std::unique_ptr<RealFourier>(new RealFourierOoura(fft_order));
|
||||
}
|
||||
|
||||
int RealFourier::FftOrder(size_t length) {
|
||||
RTC_CHECK_GT(length, 0U);
|
||||
return WebRtcSpl_GetSizeInBits(static_cast<uint32_t>(length - 1));
|
||||
}
|
||||
|
||||
size_t RealFourier::FftLength(int order) {
|
||||
RTC_CHECK_GE(order, 0);
|
||||
return size_t{1} << order;
|
||||
}
|
||||
|
||||
size_t RealFourier::ComplexLength(int order) {
|
||||
return FftLength(order) / 2 + 1;
|
||||
}
|
||||
|
||||
RealFourier::fft_real_scoper RealFourier::AllocRealBuffer(int count) {
|
||||
return fft_real_scoper(static_cast<float*>(
|
||||
AlignedMalloc(sizeof(float) * count, kFftBufferAlignment)));
|
||||
}
|
||||
|
||||
RealFourier::fft_cplx_scoper RealFourier::AllocCplxBuffer(int count) {
|
||||
return fft_cplx_scoper(static_cast<complex<float>*>(
|
||||
AlignedMalloc(sizeof(complex<float>) * count, kFftBufferAlignment)));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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 COMMON_AUDIO_REAL_FOURIER_H_
|
||||
#define COMMON_AUDIO_REAL_FOURIER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <complex>
|
||||
#include <memory>
|
||||
|
||||
#include "rtc_base/memory/aligned_malloc.h"
|
||||
|
||||
// Uniform interface class for the real DFT and its inverse, for power-of-2
|
||||
// input lengths. Also contains helper functions for buffer allocation, taking
|
||||
// care of any memory alignment requirements the underlying library might have.
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class RealFourier {
|
||||
public:
|
||||
// Shorthand typenames for the scopers used by the buffer allocation helpers.
|
||||
typedef std::unique_ptr<float[], AlignedFreeDeleter> fft_real_scoper;
|
||||
typedef std::unique_ptr<std::complex<float>[], AlignedFreeDeleter>
|
||||
fft_cplx_scoper;
|
||||
|
||||
// The alignment required for all input and output buffers, in bytes.
|
||||
static const size_t kFftBufferAlignment;
|
||||
|
||||
// Construct a wrapper instance for the given input order, which must be
|
||||
// between 1 and kMaxFftOrder, inclusively.
|
||||
static std::unique_ptr<RealFourier> Create(int fft_order);
|
||||
virtual ~RealFourier() {}
|
||||
|
||||
// Helper to compute the smallest FFT order (a power of 2) which will contain
|
||||
// the given input length.
|
||||
static int FftOrder(size_t length);
|
||||
|
||||
// Helper to compute the input length from the FFT order.
|
||||
static size_t FftLength(int order);
|
||||
|
||||
// Helper to compute the exact length, in complex floats, of the transform
|
||||
// output (i.e. |2^order / 2 + 1|).
|
||||
static size_t ComplexLength(int order);
|
||||
|
||||
// Buffer allocation helpers. The buffers are large enough to hold `count`
|
||||
// floats/complexes and suitably aligned for use by the implementation.
|
||||
// The returned scopers are set up with proper deleters; the caller owns
|
||||
// the allocated memory.
|
||||
static fft_real_scoper AllocRealBuffer(int count);
|
||||
static fft_cplx_scoper AllocCplxBuffer(int count);
|
||||
|
||||
// Main forward transform interface. The output array need only be big
|
||||
// enough for |2^order / 2 + 1| elements - the conjugate pairs are not
|
||||
// returned. Input and output must be properly aligned (e.g. through
|
||||
// AllocRealBuffer and AllocCplxBuffer) and input length must be
|
||||
// |2^order| (same as given at construction time).
|
||||
virtual void Forward(const float* src, std::complex<float>* dest) const = 0;
|
||||
|
||||
// Inverse transform. Same input format as output above, conjugate pairs
|
||||
// not needed.
|
||||
virtual void Inverse(const std::complex<float>* src, float* dest) const = 0;
|
||||
|
||||
virtual int order() const = 0;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // COMMON_AUDIO_REAL_FOURIER_H_
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* 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 "common_audio/real_fourier_ooura.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "common_audio/third_party/ooura/fft_size_256/fft4g.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
using std::complex;
|
||||
|
||||
namespace {
|
||||
|
||||
void Conjugate(complex<float>* array, size_t complex_length) {
|
||||
std::for_each(array, array + complex_length,
|
||||
[=](complex<float>& v) { v = std::conj(v); });
|
||||
}
|
||||
|
||||
size_t ComputeWorkIpSize(size_t fft_length) {
|
||||
return static_cast<size_t>(
|
||||
2 + std::ceil(std::sqrt(static_cast<float>(fft_length))));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
RealFourierOoura::RealFourierOoura(int fft_order)
|
||||
: order_(fft_order),
|
||||
length_(FftLength(order_)),
|
||||
complex_length_(ComplexLength(order_)),
|
||||
// Zero-initializing work_ip_ will cause rdft to initialize these work
|
||||
// arrays on the first call.
|
||||
work_ip_(new size_t[ComputeWorkIpSize(length_)]()),
|
||||
work_w_(new float[complex_length_]()) {
|
||||
RTC_CHECK_GE(fft_order, 1);
|
||||
}
|
||||
|
||||
RealFourierOoura::~RealFourierOoura() = default;
|
||||
|
||||
void RealFourierOoura::Forward(const float* src, complex<float>* dest) const {
|
||||
{
|
||||
// This cast is well-defined since C++11. See "Non-static data members" at:
|
||||
// http://en.cppreference.com/w/cpp/numeric/complex
|
||||
auto* dest_float = reinterpret_cast<float*>(dest);
|
||||
std::copy(src, src + length_, dest_float);
|
||||
WebRtc_rdft(length_, 1, dest_float, work_ip_.get(), work_w_.get());
|
||||
}
|
||||
|
||||
// Ooura places real[n/2] in imag[0].
|
||||
dest[complex_length_ - 1] = complex<float>(dest[0].imag(), 0.0f);
|
||||
dest[0] = complex<float>(dest[0].real(), 0.0f);
|
||||
// Ooura returns the conjugate of the usual Fourier definition.
|
||||
Conjugate(dest, complex_length_);
|
||||
}
|
||||
|
||||
void RealFourierOoura::Inverse(const complex<float>* src, float* dest) const {
|
||||
{
|
||||
auto* dest_complex = reinterpret_cast<complex<float>*>(dest);
|
||||
// The real output array is shorter than the input complex array by one
|
||||
// complex element.
|
||||
const size_t dest_complex_length = complex_length_ - 1;
|
||||
std::copy(src, src + dest_complex_length, dest_complex);
|
||||
// Restore Ooura's conjugate definition.
|
||||
Conjugate(dest_complex, dest_complex_length);
|
||||
// Restore real[n/2] to imag[0].
|
||||
dest_complex[0] =
|
||||
complex<float>(dest_complex[0].real(), src[complex_length_ - 1].real());
|
||||
}
|
||||
|
||||
WebRtc_rdft(length_, -1, dest, work_ip_.get(), work_w_.get());
|
||||
|
||||
// Ooura returns a scaled version.
|
||||
const float scale = 2.0f / length_;
|
||||
std::for_each(dest, dest + length_, [scale](float& v) { v *= scale; });
|
||||
}
|
||||
|
||||
int RealFourierOoura::order() const {
|
||||
return order_;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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 COMMON_AUDIO_REAL_FOURIER_OOURA_H_
|
||||
#define COMMON_AUDIO_REAL_FOURIER_OOURA_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <complex>
|
||||
#include <memory>
|
||||
|
||||
#include "common_audio/real_fourier.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class RealFourierOoura : public RealFourier {
|
||||
public:
|
||||
explicit RealFourierOoura(int fft_order);
|
||||
~RealFourierOoura() override;
|
||||
|
||||
void Forward(const float* src, std::complex<float>* dest) const override;
|
||||
void Inverse(const std::complex<float>* src, float* dest) const override;
|
||||
|
||||
int order() const override;
|
||||
|
||||
private:
|
||||
const int order_;
|
||||
const size_t length_;
|
||||
const size_t complex_length_;
|
||||
// These are work arrays for Ooura. The names are based on the comments in
|
||||
// common_audio/third_party/ooura/fft_size_256/fft4g.cc.
|
||||
const std::unique_ptr<size_t[]> work_ip_;
|
||||
const std::unique_ptr<float[]> work_w_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // COMMON_AUDIO_REAL_FOURIER_OOURA_H_
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 WEBRTC_COMMON_AUDIO_REAL_FOURIER_OPENMAX_H_
|
||||
#define WEBRTC_COMMON_AUDIO_REAL_FOURIER_OPENMAX_H_
|
||||
|
||||
#include <complex>
|
||||
|
||||
#include "webrtc/common_audio/real_fourier.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class RealFourierOpenmax : public RealFourier {
|
||||
public:
|
||||
explicit RealFourierOpenmax(int fft_order);
|
||||
~RealFourierOpenmax() override;
|
||||
|
||||
void Forward(const float* src, std::complex<float>* dest) const override;
|
||||
void Inverse(const std::complex<float>* src, float* dest) const override;
|
||||
|
||||
int order() const override {
|
||||
return order_;
|
||||
}
|
||||
|
||||
private:
|
||||
// Basically a forward declare of OMXFFTSpec_R_F32. To get rid of the
|
||||
// dependency on openmax.
|
||||
typedef void OMXFFTSpec_R_F32_;
|
||||
const int order_;
|
||||
|
||||
OMXFFTSpec_R_F32_* const omx_spec_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_COMMON_AUDIO_REAL_FOURIER_OPENMAX_H_
|
||||
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "common_audio/window_generator.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
using std::complex;
|
||||
|
||||
namespace {
|
||||
|
||||
// Modified Bessel function of order 0 for complex inputs.
|
||||
complex<float> I0(complex<float> x) {
|
||||
complex<float> y = x / 3.75f;
|
||||
y *= y;
|
||||
return 1.0f + y * (3.5156229f +
|
||||
y * (3.0899424f +
|
||||
y * (1.2067492f +
|
||||
y * (0.2659732f +
|
||||
y * (0.360768e-1f + y * 0.45813e-2f)))));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
void WindowGenerator::Hanning(int length, float* window) {
|
||||
RTC_CHECK_GT(length, 1);
|
||||
RTC_CHECK(window != nullptr);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
window[i] =
|
||||
0.5f * (1 - cosf(2 * static_cast<float>(M_PI) * i / (length - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
void WindowGenerator::KaiserBesselDerived(float alpha,
|
||||
size_t length,
|
||||
float* window) {
|
||||
RTC_CHECK_GT(length, 1U);
|
||||
RTC_CHECK(window != nullptr);
|
||||
|
||||
const size_t half = (length + 1) / 2;
|
||||
float sum = 0.0f;
|
||||
|
||||
for (size_t i = 0; i <= half; ++i) {
|
||||
complex<float> r = (4.0f * i) / length - 1.0f;
|
||||
sum += I0(static_cast<float>(M_PI) * alpha * sqrt(1.0f - r * r)).real();
|
||||
window[i] = sum;
|
||||
}
|
||||
for (size_t i = length - 1; i >= half; --i) {
|
||||
window[length - i - 1] = sqrtf(window[length - i - 1] / sum);
|
||||
window[i] = window[length - i - 1];
|
||||
}
|
||||
if (length % 2 == 1) {
|
||||
window[half - 1] = sqrtf(window[half - 1] / sum);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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 COMMON_AUDIO_WINDOW_GENERATOR_H_
|
||||
#define COMMON_AUDIO_WINDOW_GENERATOR_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Helper class with generators for various signal transform windows.
|
||||
class WindowGenerator {
|
||||
public:
|
||||
WindowGenerator() = delete;
|
||||
WindowGenerator(const WindowGenerator&) = delete;
|
||||
WindowGenerator& operator=(const WindowGenerator&) = delete;
|
||||
|
||||
static void Hanning(int length, float* window);
|
||||
static void KaiserBesselDerived(float alpha, size_t length, float* window);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // COMMON_AUDIO_WINDOW_GENERATOR_H_
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 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.
|
||||
*/
|
||||
|
||||
// This file is for backwards compatibility only! Use
|
||||
// webrtc/api/audio_codecs/audio_decoder.h instead!
|
||||
// TODO(kwiberg): Remove it.
|
||||
|
||||
#ifndef MODULES_AUDIO_CODING_CODECS_AUDIO_DECODER_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_AUDIO_DECODER_H_
|
||||
|
||||
#include "api/audio_codecs/audio_decoder.h"
|
||||
|
||||
#endif // MODULES_AUDIO_CODING_CODECS_AUDIO_DECODER_H_
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 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.
|
||||
*/
|
||||
|
||||
// This file is for backwards compatibility only! Use
|
||||
// webrtc/api/audio_codecs/audio_encoder.h instead!
|
||||
// TODO(ossu): Remove it.
|
||||
|
||||
#ifndef MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_
|
||||
|
||||
#include "api/audio_codecs/audio_encoder.h"
|
||||
|
||||
#endif // MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_
|
@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 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 WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_INCLUDE_WEBRTC_CNG_H_
|
||||
#define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_INCLUDE_WEBRTC_CNG_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WEBRTC_CNG_MAX_LPC_ORDER 12
|
||||
#define WEBRTC_CNG_MAX_OUTSIZE_ORDER 640
|
||||
|
||||
/* Define Error codes. */
|
||||
|
||||
/* 6100 Encoder */
|
||||
#define CNG_ENCODER_NOT_INITIATED 6120
|
||||
#define CNG_DISALLOWED_LPC_ORDER 6130
|
||||
#define CNG_DISALLOWED_FRAME_SIZE 6140
|
||||
#define CNG_DISALLOWED_SAMPLING_FREQUENCY 6150
|
||||
/* 6200 Decoder */
|
||||
#define CNG_DECODER_NOT_INITIATED 6220
|
||||
|
||||
typedef struct WebRtcCngEncInst CNG_enc_inst;
|
||||
typedef struct WebRtcCngDecInst CNG_dec_inst;
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcCng_CreateEnc/Dec(...)
|
||||
*
|
||||
* These functions create an instance to the specified structure
|
||||
*
|
||||
* Input:
|
||||
* - XXX_inst : Pointer to created instance that should be created
|
||||
*
|
||||
* Return value : 0 - Ok
|
||||
* -1 - Error
|
||||
*/
|
||||
int16_t WebRtcCng_CreateEnc(CNG_enc_inst** cng_inst);
|
||||
int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcCng_InitEnc/Dec(...)
|
||||
*
|
||||
* This function initializes a instance
|
||||
*
|
||||
* Input:
|
||||
* - cng_inst : Instance that should be initialized
|
||||
*
|
||||
* - fs : 8000 for narrowband and 16000 for wideband
|
||||
* - interval : generate SID data every interval ms
|
||||
* - quality : Number of refl. coefs, maximum allowed is 12
|
||||
*
|
||||
* Output:
|
||||
* - cng_inst : Initialized instance
|
||||
*
|
||||
* Return value : 0 - Ok
|
||||
* -1 - Error
|
||||
*/
|
||||
|
||||
int WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, int fs, int16_t interval,
|
||||
int16_t quality);
|
||||
void WebRtcCng_InitDec(CNG_dec_inst* cng_inst);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcCng_FreeEnc/Dec(...)
|
||||
*
|
||||
* These functions frees the dynamic memory of a specified instance
|
||||
*
|
||||
* Input:
|
||||
* - cng_inst : Pointer to created instance that should be freed
|
||||
*
|
||||
* Return value : 0 - Ok
|
||||
* -1 - Error
|
||||
*/
|
||||
int16_t WebRtcCng_FreeEnc(CNG_enc_inst* cng_inst);
|
||||
int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcCng_Encode(...)
|
||||
*
|
||||
* These functions analyzes background noise
|
||||
*
|
||||
* Input:
|
||||
* - cng_inst : Pointer to created instance
|
||||
* - speech : Signal to be analyzed
|
||||
* - nrOfSamples : Size of speech vector
|
||||
* - forceSID : not zero to force SID frame and reset
|
||||
*
|
||||
* Output:
|
||||
* - bytesOut : Nr of bytes to transmit, might be 0
|
||||
*
|
||||
* Return value : 0 - Ok
|
||||
* -1 - Error
|
||||
*/
|
||||
int WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech,
|
||||
size_t nrOfSamples, uint8_t* SIDdata,
|
||||
size_t* bytesOut, int16_t forceSID);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcCng_UpdateSid(...)
|
||||
*
|
||||
* These functions updates the CN state, when a new SID packet arrives
|
||||
*
|
||||
* Input:
|
||||
* - cng_inst : Pointer to created instance that should be freed
|
||||
* - SID : SID packet, all headers removed
|
||||
* - length : Length in bytes of SID packet
|
||||
*
|
||||
* Return value : 0 - Ok
|
||||
* -1 - Error
|
||||
*/
|
||||
int16_t WebRtcCng_UpdateSid(CNG_dec_inst* cng_inst, uint8_t* SID,
|
||||
size_t length);
|
||||
|
||||
/****************************************************************************
|
||||
* WebRtcCng_Generate(...)
|
||||
*
|
||||
* These functions generates CN data when needed
|
||||
*
|
||||
* Input:
|
||||
* - cng_inst : Pointer to created instance that should be freed
|
||||
* - outData : pointer to area to write CN data
|
||||
* - nrOfSamples : How much data to generate
|
||||
* - new_period : >0 if a new period of CNG, will reset history
|
||||
*
|
||||
* Return value : 0 - Ok
|
||||
* -1 - Error
|
||||
*/
|
||||
int16_t WebRtcCng_Generate(CNG_dec_inst* cng_inst, int16_t* outData,
|
||||
size_t nrOfSamples, int16_t new_period);
|
||||
|
||||
/*****************************************************************************
|
||||
* WebRtcCng_GetErrorCodeEnc/Dec(...)
|
||||
*
|
||||
* This functions can be used to check the error code of a CNG instance. When
|
||||
* a function returns -1 a error code will be set for that instance. The
|
||||
* function below extract the code of the last error that occurred in the
|
||||
* specified instance.
|
||||
*
|
||||
* Input:
|
||||
* - CNG_inst : CNG enc/dec instance
|
||||
*
|
||||
* Return value : Error code
|
||||
*/
|
||||
int16_t WebRtcCng_GetErrorCodeEnc(CNG_enc_inst* cng_inst);
|
||||
int16_t WebRtcCng_GetErrorCodeDec(CNG_dec_inst* cng_inst);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_INCLUDE_WEBRTC_CNG_H_
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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_ISAC_AUDIO_DECODER_ISAC_T_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/audio_codecs/audio_decoder.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template <typename T>
|
||||
class AudioDecoderIsacT final : public AudioDecoder {
|
||||
public:
|
||||
struct Config {
|
||||
bool IsOk() const;
|
||||
int sample_rate_hz = 16000;
|
||||
};
|
||||
explicit AudioDecoderIsacT(const Config& config);
|
||||
virtual ~AudioDecoderIsacT() override;
|
||||
|
||||
bool HasDecodePlc() const override;
|
||||
size_t DecodePlc(size_t num_frames, int16_t* decoded) override;
|
||||
void Reset() override;
|
||||
int ErrorCode() override;
|
||||
int SampleRateHz() const override;
|
||||
size_t Channels() const override;
|
||||
int DecodeInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) override;
|
||||
|
||||
private:
|
||||
typename T::instance_type* isac_state_;
|
||||
int sample_rate_hz_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacT);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_H_
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* 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_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template <typename T>
|
||||
bool AudioDecoderIsacT<T>::Config::IsOk() const {
|
||||
return (sample_rate_hz == 16000 || sample_rate_hz == 32000);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AudioDecoderIsacT<T>::AudioDecoderIsacT(const Config& config)
|
||||
: sample_rate_hz_(config.sample_rate_hz) {
|
||||
RTC_CHECK(config.IsOk()) << "Unsupported sample rate "
|
||||
<< config.sample_rate_hz;
|
||||
RTC_CHECK_EQ(0, T::Create(&isac_state_));
|
||||
T::DecoderInit(isac_state_);
|
||||
RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz_));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AudioDecoderIsacT<T>::~AudioDecoderIsacT() {
|
||||
RTC_CHECK_EQ(0, T::Free(isac_state_));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
RTC_CHECK_EQ(sample_rate_hz_, sample_rate_hz);
|
||||
int16_t temp_type = 1; // Default is speech.
|
||||
int ret =
|
||||
T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type);
|
||||
*speech_type = ConvertSpeechType(temp_type);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool AudioDecoderIsacT<T>::HasDecodePlc() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t AudioDecoderIsacT<T>::DecodePlc(size_t num_frames, int16_t* decoded) {
|
||||
return T::DecodePlc(isac_state_, decoded, num_frames);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioDecoderIsacT<T>::Reset() {
|
||||
T::DecoderInit(isac_state_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int AudioDecoderIsacT<T>::ErrorCode() {
|
||||
return T::GetErrorCode(isac_state_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int AudioDecoderIsacT<T>::SampleRateHz() const {
|
||||
return sample_rate_hz_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t AudioDecoderIsacT<T>::Channels() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
|
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* 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_ISAC_AUDIO_ENCODER_ISAC_T_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/audio_codecs/audio_encoder.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
#include "system_wrappers/include/field_trial.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template <typename T>
|
||||
class AudioEncoderIsacT final : public AudioEncoder {
|
||||
public:
|
||||
// Allowed combinations of sample rate, frame size, and bit rate are
|
||||
// - 16000 Hz, 30 ms, 10000-32000 bps
|
||||
// - 16000 Hz, 60 ms, 10000-32000 bps
|
||||
// - 32000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support)
|
||||
struct Config {
|
||||
bool IsOk() const;
|
||||
int payload_type = 103;
|
||||
int sample_rate_hz = 16000;
|
||||
int frame_size_ms = 30;
|
||||
int bit_rate = kDefaultBitRate; // Limit on the short-term average bit
|
||||
// rate, in bits/s.
|
||||
int max_payload_size_bytes = -1;
|
||||
int max_bit_rate = -1;
|
||||
};
|
||||
|
||||
explicit AudioEncoderIsacT(const Config& config);
|
||||
~AudioEncoderIsacT() override;
|
||||
|
||||
int SampleRateHz() const override;
|
||||
size_t NumChannels() const override;
|
||||
size_t Num10MsFramesInNextPacket() const override;
|
||||
size_t Max10MsFramesInAPacket() const override;
|
||||
int GetTargetBitrate() const override;
|
||||
void SetTargetBitrate(int target_bps) override;
|
||||
void OnReceivedTargetAudioBitrate(int target_bps) override;
|
||||
void OnReceivedUplinkBandwidth(
|
||||
int target_audio_bitrate_bps,
|
||||
absl::optional<int64_t> bwe_period_ms) override;
|
||||
void OnReceivedUplinkAllocation(BitrateAllocationUpdate update) override;
|
||||
void OnReceivedOverhead(size_t overhead_bytes_per_packet) override;
|
||||
EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
rtc::Buffer* encoded) override;
|
||||
void Reset() override;
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange()
|
||||
const override;
|
||||
|
||||
private:
|
||||
// This value is taken from STREAM_SIZE_MAX_60 for iSAC float (60 ms) and
|
||||
// STREAM_MAXW16_60MS for iSAC fix (60 ms).
|
||||
static const size_t kSufficientEncodeBufferSizeBytes = 400;
|
||||
|
||||
static constexpr int kDefaultBitRate = 32000;
|
||||
static constexpr int kMinBitrateBps = 10000;
|
||||
static constexpr int MaxBitrateBps(int sample_rate_hz) {
|
||||
return sample_rate_hz == 32000 ? 56000 : 32000;
|
||||
}
|
||||
|
||||
void SetTargetBitrate(int target_bps, bool subtract_per_packet_overhead);
|
||||
|
||||
// Recreate the iSAC encoder instance with the given settings, and save them.
|
||||
void RecreateEncoderInstance(const Config& config);
|
||||
|
||||
Config config_;
|
||||
typename T::instance_type* isac_state_ = nullptr;
|
||||
|
||||
// Have we accepted input but not yet emitted it in a packet?
|
||||
bool packet_in_progress_ = false;
|
||||
|
||||
// Timestamp of the first input of the currently in-progress packet.
|
||||
uint32_t packet_timestamp_;
|
||||
|
||||
// Timestamp of the previously encoded packet.
|
||||
uint32_t last_encoded_timestamp_;
|
||||
|
||||
// Cache the value of the "WebRTC-SendSideBwe-WithOverhead" field trial.
|
||||
const bool send_side_bwe_with_overhead_ =
|
||||
field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead");
|
||||
|
||||
// When we send a packet, expect this many bytes of headers to be added to it.
|
||||
// Start out with a reasonable default that we can use until we receive a real
|
||||
// value.
|
||||
DataSize overhead_per_packet_ = DataSize::Bytes(28);
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderIsacT);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_
|
@ -1,219 +0,0 @@
|
||||
/*
|
||||
* 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_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/numerics/safe_minmax.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template <typename T>
|
||||
bool AudioEncoderIsacT<T>::Config::IsOk() const {
|
||||
if (max_bit_rate < 32000 && max_bit_rate != -1)
|
||||
return false;
|
||||
if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1)
|
||||
return false;
|
||||
|
||||
switch (sample_rate_hz) {
|
||||
case 16000:
|
||||
if (max_bit_rate > 53400)
|
||||
return false;
|
||||
if (max_payload_size_bytes > 400)
|
||||
return false;
|
||||
return (frame_size_ms == 30 || frame_size_ms == 60) &&
|
||||
(bit_rate == 0 || (bit_rate >= 10000 && bit_rate <= 32000));
|
||||
case 32000:
|
||||
if (max_bit_rate > 160000)
|
||||
return false;
|
||||
if (max_payload_size_bytes > 600)
|
||||
return false;
|
||||
return T::has_swb &&
|
||||
(frame_size_ms == 30 &&
|
||||
(bit_rate == 0 || (bit_rate >= 10000 && bit_rate <= 56000)));
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AudioEncoderIsacT<T>::AudioEncoderIsacT(const Config& config) {
|
||||
RecreateEncoderInstance(config);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AudioEncoderIsacT<T>::~AudioEncoderIsacT() {
|
||||
RTC_CHECK_EQ(0, T::Free(isac_state_));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int AudioEncoderIsacT<T>::SampleRateHz() const {
|
||||
return T::EncSampRate(isac_state_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t AudioEncoderIsacT<T>::NumChannels() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t AudioEncoderIsacT<T>::Num10MsFramesInNextPacket() const {
|
||||
const int samples_in_next_packet = T::GetNewFrameLen(isac_state_);
|
||||
return static_cast<size_t>(rtc::CheckedDivExact(
|
||||
samples_in_next_packet, rtc::CheckedDivExact(SampleRateHz(), 100)));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t AudioEncoderIsacT<T>::Max10MsFramesInAPacket() const {
|
||||
return 6; // iSAC puts at most 60 ms in a packet.
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int AudioEncoderIsacT<T>::GetTargetBitrate() const {
|
||||
return config_.bit_rate == 0 ? kDefaultBitRate : config_.bit_rate;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::SetTargetBitrate(int target_bps) {
|
||||
// Set target bitrate directly without subtracting per-packet overhead,
|
||||
// because that's what AudioEncoderOpus does.
|
||||
SetTargetBitrate(target_bps,
|
||||
/*subtract_per_packet_overhead=*/false);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::OnReceivedTargetAudioBitrate(int target_bps) {
|
||||
// Set target bitrate directly without subtracting per-packet overhead,
|
||||
// because that's what AudioEncoderOpus does.
|
||||
SetTargetBitrate(target_bps,
|
||||
/*subtract_per_packet_overhead=*/false);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::OnReceivedUplinkBandwidth(
|
||||
int target_audio_bitrate_bps,
|
||||
absl::optional<int64_t> /*bwe_period_ms*/) {
|
||||
// Set target bitrate, subtracting the per-packet overhead if
|
||||
// WebRTC-SendSideBwe-WithOverhead is enabled, because that's what
|
||||
// AudioEncoderOpus does.
|
||||
SetTargetBitrate(
|
||||
target_audio_bitrate_bps,
|
||||
/*subtract_per_packet_overhead=*/send_side_bwe_with_overhead_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::OnReceivedUplinkAllocation(
|
||||
BitrateAllocationUpdate update) {
|
||||
// Set target bitrate, subtracting the per-packet overhead if
|
||||
// WebRTC-SendSideBwe-WithOverhead is enabled, because that's what
|
||||
// AudioEncoderOpus does.
|
||||
SetTargetBitrate(
|
||||
update.target_bitrate.bps<int>(),
|
||||
/*subtract_per_packet_overhead=*/send_side_bwe_with_overhead_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::OnReceivedOverhead(
|
||||
size_t overhead_bytes_per_packet) {
|
||||
overhead_per_packet_ = DataSize::Bytes(overhead_bytes_per_packet);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AudioEncoder::EncodedInfo AudioEncoderIsacT<T>::EncodeImpl(
|
||||
uint32_t rtp_timestamp,
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
rtc::Buffer* encoded) {
|
||||
if (!packet_in_progress_) {
|
||||
// Starting a new packet; remember the timestamp for later.
|
||||
packet_in_progress_ = true;
|
||||
packet_timestamp_ = rtp_timestamp;
|
||||
}
|
||||
size_t encoded_bytes = encoded->AppendData(
|
||||
kSufficientEncodeBufferSizeBytes, [&](rtc::ArrayView<uint8_t> encoded) {
|
||||
int r = T::Encode(isac_state_, audio.data(), encoded.data());
|
||||
|
||||
RTC_CHECK_GE(r, 0) << "Encode failed (error code "
|
||||
<< T::GetErrorCode(isac_state_) << ")";
|
||||
|
||||
return static_cast<size_t>(r);
|
||||
});
|
||||
|
||||
if (encoded_bytes == 0)
|
||||
return EncodedInfo();
|
||||
|
||||
// Got enough input to produce a packet. Return the saved timestamp from
|
||||
// the first chunk of input that went into the packet.
|
||||
packet_in_progress_ = false;
|
||||
EncodedInfo info;
|
||||
info.encoded_bytes = encoded_bytes;
|
||||
info.encoded_timestamp = packet_timestamp_;
|
||||
info.payload_type = config_.payload_type;
|
||||
info.encoder_type = CodecType::kIsac;
|
||||
return info;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::Reset() {
|
||||
RecreateEncoderInstance(config_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>>
|
||||
AudioEncoderIsacT<T>::GetFrameLengthRange() const {
|
||||
return {{TimeDelta::Millis(config_.frame_size_ms),
|
||||
TimeDelta::Millis(config_.frame_size_ms)}};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::SetTargetBitrate(int target_bps,
|
||||
bool subtract_per_packet_overhead) {
|
||||
if (subtract_per_packet_overhead) {
|
||||
const DataRate overhead_rate =
|
||||
overhead_per_packet_ / TimeDelta::Millis(config_.frame_size_ms);
|
||||
target_bps -= overhead_rate.bps();
|
||||
}
|
||||
target_bps = rtc::SafeClamp(target_bps, kMinBitrateBps,
|
||||
MaxBitrateBps(config_.sample_rate_hz));
|
||||
int result = T::Control(isac_state_, target_bps, config_.frame_size_ms);
|
||||
RTC_DCHECK_EQ(result, 0);
|
||||
config_.bit_rate = target_bps;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::RecreateEncoderInstance(const Config& config) {
|
||||
RTC_CHECK(config.IsOk());
|
||||
packet_in_progress_ = false;
|
||||
if (isac_state_)
|
||||
RTC_CHECK_EQ(0, T::Free(isac_state_));
|
||||
RTC_CHECK_EQ(0, T::Create(&isac_state_));
|
||||
RTC_CHECK_EQ(0, T::EncoderInit(isac_state_, /*coding_mode=*/1));
|
||||
RTC_CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz));
|
||||
const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate;
|
||||
RTC_CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms));
|
||||
|
||||
if (config.max_payload_size_bytes != -1)
|
||||
RTC_CHECK_EQ(
|
||||
0, T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes));
|
||||
if (config.max_bit_rate != -1)
|
||||
RTC_CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate));
|
||||
|
||||
// Set the decoder sample rate even though we just use the encoder. This
|
||||
// doesn't appear to be necessary to produce a valid encoding, but without it
|
||||
// we get an encoding that isn't bit-for-bit identical with what a combined
|
||||
// encoder+decoder object produces.
|
||||
RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz));
|
||||
|
||||
config_ = config;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 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 RTC_BASE_IGNORE_WUNDEF_H_
|
||||
#define RTC_BASE_IGNORE_WUNDEF_H_
|
||||
|
||||
// If a header file uses #if on possibly undefined macros (and it's for some
|
||||
// reason not possible to just fix the header file), include it like this:
|
||||
//
|
||||
// RTC_PUSH_IGNORING_WUNDEF()
|
||||
// #include "misbehaving_header.h"
|
||||
// RTC_POP_IGNORING_WUNDEF()
|
||||
//
|
||||
// This will cause the compiler to not emit -Wundef warnings for that file.
|
||||
|
||||
#ifdef __clang__
|
||||
#define RTC_PUSH_IGNORING_WUNDEF() \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wundef\"")
|
||||
#define RTC_POP_IGNORING_WUNDEF() _Pragma("clang diagnostic pop")
|
||||
#else
|
||||
#define RTC_PUSH_IGNORING_WUNDEF()
|
||||
#define RTC_POP_IGNORING_WUNDEF()
|
||||
#endif // __clang__
|
||||
|
||||
#endif // RTC_BASE_IGNORE_WUNDEF_H_
|
@ -15,7 +15,6 @@ base_sources = [
|
||||
'string_utils.cc',
|
||||
'strings/string_builder.cc',
|
||||
'synchronization/sequence_checker_internal.cc',
|
||||
'synchronization/yield.cc',
|
||||
'synchronization/yield_policy.cc',
|
||||
'system/file_wrapper.cc',
|
||||
'system_time.cc',
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 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 "rtc_base/synchronization/yield.h"
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sched.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
void YieldCurrentThread() {
|
||||
// TODO(bugs.webrtc.org/11634): use dedicated OS functionality instead of
|
||||
// sleep for yielding.
|
||||
#if defined(WEBRTC_WIN)
|
||||
::Sleep(0);
|
||||
#elif defined(WEBRTC_MAC) && defined(RTC_USE_NATIVE_MUTEX_ON_MAC) && \
|
||||
!RTC_USE_NATIVE_MUTEX_ON_MAC
|
||||
sched_yield();
|
||||
#else
|
||||
static const struct timespec ts_null = {0};
|
||||
nanosleep(&ts_null, nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 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 RTC_BASE_SYNCHRONIZATION_YIELD_H_
|
||||
#define RTC_BASE_SYNCHRONIZATION_YIELD_H_
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Request rescheduling of threads.
|
||||
void YieldCurrentThread();
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // RTC_BASE_SYNCHRONIZATION_YIELD_H_
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 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 RTC_BASE_SYSTEM_UNUSED_H_
|
||||
#define RTC_BASE_SYSTEM_UNUSED_H_
|
||||
|
||||
// Prevent the compiler from warning about an unused variable. For example:
|
||||
// int result = DoSomething();
|
||||
// RTC_DCHECK(result == 17);
|
||||
// RTC_UNUSED(result);
|
||||
// Note: In most cases it is better to remove the unused variable rather than
|
||||
// suppressing the compiler warning.
|
||||
#ifndef RTC_UNUSED
|
||||
#ifdef __cplusplus
|
||||
#define RTC_UNUSED(x) static_cast<void>(x)
|
||||
#else
|
||||
#define RTC_UNUSED(x) (void)(x)
|
||||
#endif
|
||||
#endif // RTC_UNUSED
|
||||
|
||||
#endif // RTC_BASE_SYSTEM_UNUSED_H_
|
Loading…
x
Reference in New Issue
Block a user