Add RTC_ prefix to (D)CHECKs and related macros.
We must remove dependency on Chromium, i.e. we can't use Chromium's base/logging.h. That means we need to define these macros in WebRTC also when doing Chromium builds. And this causes redefinition. Alternative solutions: * Check if we already have defined e.g. CHECK, and don't define them in that case. This makes us depend on include order in Chromium, which is not acceptable. * Don't allow using the macros in WebRTC headers. Error prone since if someone adds it there by mistake it may compile fine, but later break if a header in added or order is changed in Chromium. That will be confusing and hard to enforce. * Ensure that headers that are included by an embedder don't include our macros. This would require some heavy refactoring to be maintainable and enforcable. * Changes in Chromium for this is obviously not an option. BUG=chromium:468375 NOTRY=true Review URL: https://codereview.webrtc.org/1335923002 Cr-Commit-Position: refs/heads/master@{#9964}
This commit is contained in:
@ -26,11 +26,11 @@ AudioEncoder::EncodedInfo AudioEncoder::Encode(uint32_t rtp_timestamp,
|
||||
size_t num_samples_per_channel,
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded) {
|
||||
CHECK_EQ(num_samples_per_channel,
|
||||
static_cast<size_t>(SampleRateHz() / 100));
|
||||
RTC_CHECK_EQ(num_samples_per_channel,
|
||||
static_cast<size_t>(SampleRateHz() / 100));
|
||||
EncodedInfo info =
|
||||
EncodeInternal(rtp_timestamp, audio, max_encoded_bytes, encoded);
|
||||
CHECK_LE(info.encoded_bytes, max_encoded_bytes);
|
||||
RTC_CHECK_LE(info.encoded_bytes, max_encoded_bytes);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@ -24,9 +24,10 @@ rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> CreateCngInst(
|
||||
int sid_frame_interval_ms,
|
||||
int num_cng_coefficients) {
|
||||
rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> cng_inst;
|
||||
CHECK_EQ(0, WebRtcCng_CreateEnc(cng_inst.accept()));
|
||||
CHECK_EQ(0, WebRtcCng_InitEnc(cng_inst.get(), sample_rate_hz,
|
||||
sid_frame_interval_ms, num_cng_coefficients));
|
||||
RTC_CHECK_EQ(0, WebRtcCng_CreateEnc(cng_inst.accept()));
|
||||
RTC_CHECK_EQ(0,
|
||||
WebRtcCng_InitEnc(cng_inst.get(), sample_rate_hz,
|
||||
sid_frame_interval_ms, num_cng_coefficients));
|
||||
return cng_inst;
|
||||
}
|
||||
|
||||
@ -56,7 +57,7 @@ AudioEncoderCng::AudioEncoderCng(const Config& config)
|
||||
last_frame_active_(true),
|
||||
vad_(config.vad ? rtc_make_scoped_ptr(config.vad)
|
||||
: CreateVad(config.vad_mode)) {
|
||||
CHECK(config.IsOk()) << "Invalid configuration.";
|
||||
RTC_CHECK(config.IsOk()) << "Invalid configuration.";
|
||||
cng_inst_ = CreateCngInst(SampleRateHz(), sid_frame_interval_ms_,
|
||||
num_cng_coefficients_);
|
||||
}
|
||||
@ -99,10 +100,11 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal(
|
||||
const int16_t* audio,
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded) {
|
||||
CHECK_GE(max_encoded_bytes, static_cast<size_t>(num_cng_coefficients_ + 1));
|
||||
RTC_CHECK_GE(max_encoded_bytes,
|
||||
static_cast<size_t>(num_cng_coefficients_ + 1));
|
||||
const size_t samples_per_10ms_frame = SamplesPer10msFrame();
|
||||
CHECK_EQ(speech_buffer_.size(),
|
||||
rtp_timestamps_.size() * samples_per_10ms_frame);
|
||||
RTC_CHECK_EQ(speech_buffer_.size(),
|
||||
rtp_timestamps_.size() * samples_per_10ms_frame);
|
||||
rtp_timestamps_.push_back(rtp_timestamp);
|
||||
for (size_t i = 0; i < samples_per_10ms_frame; ++i) {
|
||||
speech_buffer_.push_back(audio[i]);
|
||||
@ -111,7 +113,7 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal(
|
||||
if (rtp_timestamps_.size() < frames_to_encode) {
|
||||
return EncodedInfo();
|
||||
}
|
||||
CHECK_LE(static_cast<int>(frames_to_encode * 10), kMaxFrameSizeMs)
|
||||
RTC_CHECK_LE(static_cast<int>(frames_to_encode * 10), kMaxFrameSizeMs)
|
||||
<< "Frame size cannot be larger than " << kMaxFrameSizeMs
|
||||
<< " ms when using VAD/CNG.";
|
||||
|
||||
@ -123,7 +125,7 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal(
|
||||
(frames_to_encode > 3 ? 3 : frames_to_encode);
|
||||
if (frames_to_encode == 4)
|
||||
blocks_in_first_vad_call = 2;
|
||||
CHECK_GE(frames_to_encode, blocks_in_first_vad_call);
|
||||
RTC_CHECK_GE(frames_to_encode, blocks_in_first_vad_call);
|
||||
const size_t blocks_in_second_vad_call =
|
||||
frames_to_encode - blocks_in_first_vad_call;
|
||||
|
||||
@ -206,7 +208,7 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodePassive(
|
||||
bool force_sid = last_frame_active_;
|
||||
bool output_produced = false;
|
||||
const size_t samples_per_10ms_frame = SamplesPer10msFrame();
|
||||
CHECK_GE(max_encoded_bytes, frames_to_encode * samples_per_10ms_frame);
|
||||
RTC_CHECK_GE(max_encoded_bytes, frames_to_encode * samples_per_10ms_frame);
|
||||
AudioEncoder::EncodedInfo info;
|
||||
for (size_t i = 0; i < frames_to_encode; ++i) {
|
||||
// It's important not to pass &info.encoded_bytes directly to
|
||||
@ -214,12 +216,13 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodePassive(
|
||||
// value, in which case we don't want to overwrite any value from an earlier
|
||||
// iteration.
|
||||
size_t encoded_bytes_tmp = 0;
|
||||
CHECK_GE(WebRtcCng_Encode(cng_inst_.get(),
|
||||
&speech_buffer_[i * samples_per_10ms_frame],
|
||||
samples_per_10ms_frame,
|
||||
encoded, &encoded_bytes_tmp, force_sid), 0);
|
||||
RTC_CHECK_GE(WebRtcCng_Encode(cng_inst_.get(),
|
||||
&speech_buffer_[i * samples_per_10ms_frame],
|
||||
samples_per_10ms_frame, encoded,
|
||||
&encoded_bytes_tmp, force_sid),
|
||||
0);
|
||||
if (encoded_bytes_tmp > 0) {
|
||||
CHECK(!output_produced);
|
||||
RTC_CHECK(!output_produced);
|
||||
info.encoded_bytes = encoded_bytes_tmp;
|
||||
output_produced = true;
|
||||
force_sid = false;
|
||||
@ -243,9 +246,10 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive(
|
||||
rtp_timestamps_.front(), &speech_buffer_[i * samples_per_10ms_frame],
|
||||
samples_per_10ms_frame, max_encoded_bytes, encoded);
|
||||
if (i + 1 == frames_to_encode) {
|
||||
CHECK_GT(info.encoded_bytes, 0u) << "Encoder didn't deliver data.";
|
||||
RTC_CHECK_GT(info.encoded_bytes, 0u) << "Encoder didn't deliver data.";
|
||||
} else {
|
||||
CHECK_EQ(info.encoded_bytes, 0u) << "Encoder delivered data too early.";
|
||||
RTC_CHECK_EQ(info.encoded_bytes, 0u)
|
||||
<< "Encoder delivered data too early.";
|
||||
}
|
||||
}
|
||||
return info;
|
||||
|
||||
@ -24,7 +24,7 @@ int16_t NumSamplesPerFrame(int num_channels,
|
||||
int frame_size_ms,
|
||||
int sample_rate_hz) {
|
||||
int samples_per_frame = num_channels * frame_size_ms * sample_rate_hz / 1000;
|
||||
CHECK_LE(samples_per_frame, std::numeric_limits<int16_t>::max())
|
||||
RTC_CHECK_LE(samples_per_frame, std::numeric_limits<int16_t>::max())
|
||||
<< "Frame size too large.";
|
||||
return static_cast<int16_t>(samples_per_frame);
|
||||
}
|
||||
@ -54,8 +54,8 @@ AudioEncoderPcm::AudioEncoderPcm(const Config& config, int sample_rate_hz)
|
||||
config.frame_size_ms,
|
||||
sample_rate_hz_)),
|
||||
first_timestamp_in_buffer_(0) {
|
||||
CHECK_GT(sample_rate_hz, 0) << "Sample rate must be larger than 0 Hz";
|
||||
CHECK_EQ(config.frame_size_ms % 10, 0)
|
||||
RTC_CHECK_GT(sample_rate_hz, 0) << "Sample rate must be larger than 0 Hz";
|
||||
RTC_CHECK_EQ(config.frame_size_ms % 10, 0)
|
||||
<< "Frame size must be an integer multiple of 10 ms.";
|
||||
speech_buffer_.reserve(full_frame_samples_);
|
||||
}
|
||||
@ -101,8 +101,8 @@ AudioEncoder::EncodedInfo AudioEncoderPcm::EncodeInternal(
|
||||
if (speech_buffer_.size() < full_frame_samples_) {
|
||||
return EncodedInfo();
|
||||
}
|
||||
CHECK_EQ(speech_buffer_.size(), full_frame_samples_);
|
||||
CHECK_GE(max_encoded_bytes, full_frame_samples_);
|
||||
RTC_CHECK_EQ(speech_buffer_.size(), full_frame_samples_);
|
||||
RTC_CHECK_GE(max_encoded_bytes, full_frame_samples_);
|
||||
EncodedInfo info;
|
||||
info.encoded_timestamp = first_timestamp_in_buffer_;
|
||||
info.payload_type = payload_type_;
|
||||
|
||||
@ -45,7 +45,7 @@ AudioEncoderG722::AudioEncoderG722(const Config& config)
|
||||
first_timestamp_in_buffer_(0),
|
||||
encoders_(new EncoderState[num_channels_]),
|
||||
interleave_buffer_(2 * num_channels_) {
|
||||
CHECK(config.IsOk());
|
||||
RTC_CHECK(config.IsOk());
|
||||
const size_t samples_per_channel =
|
||||
kSampleRateHz / 100 * num_10ms_frames_per_packet_;
|
||||
for (int i = 0; i < num_channels_; ++i) {
|
||||
@ -96,7 +96,7 @@ AudioEncoder::EncodedInfo AudioEncoderG722::EncodeInternal(
|
||||
const int16_t* audio,
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded) {
|
||||
CHECK_GE(max_encoded_bytes, MaxEncodedBytes());
|
||||
RTC_CHECK_GE(max_encoded_bytes, MaxEncodedBytes());
|
||||
|
||||
if (num_10ms_frames_buffered_ == 0)
|
||||
first_timestamp_in_buffer_ = rtp_timestamp;
|
||||
@ -113,14 +113,14 @@ AudioEncoder::EncodedInfo AudioEncoderG722::EncodeInternal(
|
||||
}
|
||||
|
||||
// Encode each channel separately.
|
||||
CHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_);
|
||||
RTC_CHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_);
|
||||
num_10ms_frames_buffered_ = 0;
|
||||
const size_t samples_per_channel = SamplesPerChannel();
|
||||
for (int i = 0; i < num_channels_; ++i) {
|
||||
const size_t encoded = WebRtcG722_Encode(
|
||||
encoders_[i].encoder, encoders_[i].speech_buffer.get(),
|
||||
samples_per_channel, encoders_[i].encoded_buffer.data());
|
||||
CHECK_EQ(encoded, samples_per_channel / 2);
|
||||
RTC_CHECK_EQ(encoded, samples_per_channel / 2);
|
||||
}
|
||||
|
||||
// Interleave the encoded bytes of the different channels. Each separate
|
||||
@ -146,15 +146,15 @@ AudioEncoder::EncodedInfo AudioEncoderG722::EncodeInternal(
|
||||
void AudioEncoderG722::Reset() {
|
||||
num_10ms_frames_buffered_ = 0;
|
||||
for (int i = 0; i < num_channels_; ++i)
|
||||
CHECK_EQ(0, WebRtcG722_EncoderInit(encoders_[i].encoder));
|
||||
RTC_CHECK_EQ(0, WebRtcG722_EncoderInit(encoders_[i].encoder));
|
||||
}
|
||||
|
||||
AudioEncoderG722::EncoderState::EncoderState() {
|
||||
CHECK_EQ(0, WebRtcG722_CreateEncoder(&encoder));
|
||||
RTC_CHECK_EQ(0, WebRtcG722_CreateEncoder(&encoder));
|
||||
}
|
||||
|
||||
AudioEncoderG722::EncoderState::~EncoderState() {
|
||||
CHECK_EQ(0, WebRtcG722_FreeEncoder(encoder));
|
||||
RTC_CHECK_EQ(0, WebRtcG722_FreeEncoder(encoder));
|
||||
}
|
||||
|
||||
size_t AudioEncoderG722::SamplesPerChannel() const {
|
||||
|
||||
@ -33,7 +33,7 @@ int AudioDecoderIlbc::DecodeInternal(const uint8_t* encoded,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
DCHECK_EQ(sample_rate_hz, 8000);
|
||||
RTC_DCHECK_EQ(sample_rate_hz, 8000);
|
||||
int16_t temp_type = 1; // Default is speech.
|
||||
int ret = WebRtcIlbcfix_Decode(dec_state_, encoded, encoded_len, decoded,
|
||||
&temp_type);
|
||||
|
||||
@ -53,7 +53,7 @@ AudioEncoderIlbc::AudioEncoderIlbc(const CodecInst& codec_inst)
|
||||
: AudioEncoderIlbc(CreateConfig(codec_inst)) {}
|
||||
|
||||
AudioEncoderIlbc::~AudioEncoderIlbc() {
|
||||
CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
|
||||
RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
|
||||
}
|
||||
|
||||
size_t AudioEncoderIlbc::MaxEncodedBytes() const {
|
||||
@ -94,7 +94,7 @@ AudioEncoder::EncodedInfo AudioEncoderIlbc::EncodeInternal(
|
||||
const int16_t* audio,
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded) {
|
||||
DCHECK_GE(max_encoded_bytes, RequiredOutputSizeBytes());
|
||||
RTC_DCHECK_GE(max_encoded_bytes, RequiredOutputSizeBytes());
|
||||
|
||||
// Save timestamp if starting a new packet.
|
||||
if (num_10ms_frames_buffered_ == 0)
|
||||
@ -112,17 +112,17 @@ AudioEncoder::EncodedInfo AudioEncoderIlbc::EncodeInternal(
|
||||
}
|
||||
|
||||
// Encode buffered input.
|
||||
DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_);
|
||||
RTC_DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_);
|
||||
num_10ms_frames_buffered_ = 0;
|
||||
const int output_len = WebRtcIlbcfix_Encode(
|
||||
encoder_,
|
||||
input_buffer_,
|
||||
kSampleRateHz / 100 * num_10ms_frames_per_packet_,
|
||||
encoded);
|
||||
CHECK_GE(output_len, 0);
|
||||
RTC_CHECK_GE(output_len, 0);
|
||||
EncodedInfo info;
|
||||
info.encoded_bytes = static_cast<size_t>(output_len);
|
||||
DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes());
|
||||
RTC_DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes());
|
||||
info.encoded_timestamp = first_timestamp_in_buffer_;
|
||||
info.payload_type = config_.payload_type;
|
||||
return info;
|
||||
@ -130,13 +130,13 @@ AudioEncoder::EncodedInfo AudioEncoderIlbc::EncodeInternal(
|
||||
|
||||
void AudioEncoderIlbc::Reset() {
|
||||
if (encoder_)
|
||||
CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
|
||||
CHECK(config_.IsOk());
|
||||
CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_));
|
||||
RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
|
||||
RTC_CHECK(config_.IsOk());
|
||||
RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_));
|
||||
const int encoder_frame_size_ms = config_.frame_size_ms > 30
|
||||
? config_.frame_size_ms / 2
|
||||
: config_.frame_size_ms;
|
||||
CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms));
|
||||
RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms));
|
||||
num_10ms_frames_buffered_ = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ AudioEncoderIsacT<T>::AudioEncoderIsacT(const CodecInst& codec_inst,
|
||||
|
||||
template <typename T>
|
||||
AudioEncoderIsacT<T>::~AudioEncoderIsacT() {
|
||||
CHECK_EQ(0, T::Free(isac_state_));
|
||||
RTC_CHECK_EQ(0, T::Free(isac_state_));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -132,12 +132,12 @@ AudioEncoder::EncodedInfo AudioEncoderIsacT<T>::EncodeInternal(
|
||||
T::SetBandwidthInfo(isac_state_, &bwinfo);
|
||||
}
|
||||
int r = T::Encode(isac_state_, audio, encoded);
|
||||
CHECK_GE(r, 0) << "Encode failed (error code " << T::GetErrorCode(isac_state_)
|
||||
<< ")";
|
||||
RTC_CHECK_GE(r, 0) << "Encode failed (error code "
|
||||
<< T::GetErrorCode(isac_state_) << ")";
|
||||
|
||||
// T::Encode doesn't allow us to tell it the size of the output
|
||||
// buffer. All we can do is check for an overrun after the fact.
|
||||
CHECK_LE(static_cast<size_t>(r), max_encoded_bytes);
|
||||
RTC_CHECK_LE(static_cast<size_t>(r), max_encoded_bytes);
|
||||
|
||||
if (r == 0)
|
||||
return EncodedInfo();
|
||||
@ -159,26 +159,26 @@ void AudioEncoderIsacT<T>::Reset() {
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::RecreateEncoderInstance(const Config& config) {
|
||||
CHECK(config.IsOk());
|
||||
RTC_CHECK(config.IsOk());
|
||||
packet_in_progress_ = false;
|
||||
bwinfo_ = config.bwinfo;
|
||||
if (isac_state_)
|
||||
CHECK_EQ(0, T::Free(isac_state_));
|
||||
CHECK_EQ(0, T::Create(&isac_state_));
|
||||
CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1));
|
||||
CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz));
|
||||
RTC_CHECK_EQ(0, T::Free(isac_state_));
|
||||
RTC_CHECK_EQ(0, T::Create(&isac_state_));
|
||||
RTC_CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 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;
|
||||
if (config.adaptive_mode) {
|
||||
CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, config.frame_size_ms,
|
||||
config.enforce_frame_size));
|
||||
RTC_CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, config.frame_size_ms,
|
||||
config.enforce_frame_size));
|
||||
} else {
|
||||
CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms));
|
||||
RTC_CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms));
|
||||
}
|
||||
if (config.max_payload_size_bytes != -1)
|
||||
CHECK_EQ(0,
|
||||
T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes));
|
||||
RTC_CHECK_EQ(
|
||||
0, T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes));
|
||||
if (config.max_bit_rate != -1)
|
||||
CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate));
|
||||
RTC_CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate));
|
||||
|
||||
// When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is
|
||||
// still set to 32000 Hz, since there is no full-band mode in the decoder.
|
||||
@ -188,7 +188,7 @@ void AudioEncoderIsacT<T>::RecreateEncoderInstance(const Config& config) {
|
||||
// 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.
|
||||
CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz));
|
||||
RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz));
|
||||
|
||||
config_ = config;
|
||||
}
|
||||
@ -200,7 +200,7 @@ AudioDecoderIsacT<T>::AudioDecoderIsacT()
|
||||
template <typename T>
|
||||
AudioDecoderIsacT<T>::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo)
|
||||
: bwinfo_(bwinfo), decoder_sample_rate_hz_(-1) {
|
||||
CHECK_EQ(0, T::Create(&isac_state_));
|
||||
RTC_CHECK_EQ(0, T::Create(&isac_state_));
|
||||
T::DecoderInit(isac_state_);
|
||||
if (bwinfo_) {
|
||||
IsacBandwidthInfo bi;
|
||||
@ -211,7 +211,7 @@ AudioDecoderIsacT<T>::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo)
|
||||
|
||||
template <typename T>
|
||||
AudioDecoderIsacT<T>::~AudioDecoderIsacT() {
|
||||
CHECK_EQ(0, T::Free(isac_state_));
|
||||
RTC_CHECK_EQ(0, T::Free(isac_state_));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -224,10 +224,10 @@ int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded,
|
||||
// in fact it outputs 32000 Hz. This is the iSAC fullband mode.
|
||||
if (sample_rate_hz == 48000)
|
||||
sample_rate_hz = 32000;
|
||||
CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000)
|
||||
RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000)
|
||||
<< "Unsupported sample rate " << sample_rate_hz;
|
||||
if (sample_rate_hz != decoder_sample_rate_hz_) {
|
||||
CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz));
|
||||
RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz));
|
||||
decoder_sample_rate_hz_ = sample_rate_hz;
|
||||
}
|
||||
int16_t temp_type = 1; // Default is speech.
|
||||
|
||||
@ -84,17 +84,17 @@ struct IsacFix {
|
||||
}
|
||||
static inline int16_t SetDecSampRate(instance_type* inst,
|
||||
uint16_t sample_rate_hz) {
|
||||
DCHECK_EQ(sample_rate_hz, kFixSampleRate);
|
||||
RTC_DCHECK_EQ(sample_rate_hz, kFixSampleRate);
|
||||
return 0;
|
||||
}
|
||||
static inline int16_t SetEncSampRate(instance_type* inst,
|
||||
uint16_t sample_rate_hz) {
|
||||
DCHECK_EQ(sample_rate_hz, kFixSampleRate);
|
||||
RTC_DCHECK_EQ(sample_rate_hz, kFixSampleRate);
|
||||
return 0;
|
||||
}
|
||||
static inline void SetEncSampRateInDecoder(instance_type* inst,
|
||||
uint16_t sample_rate_hz) {
|
||||
DCHECK_EQ(sample_rate_hz, kFixSampleRate);
|
||||
RTC_DCHECK_EQ(sample_rate_hz, kFixSampleRate);
|
||||
}
|
||||
static inline void SetInitialBweBottleneck(
|
||||
instance_type* inst,
|
||||
|
||||
@ -16,7 +16,7 @@ namespace webrtc {
|
||||
|
||||
AudioDecoderOpus::AudioDecoderOpus(size_t num_channels)
|
||||
: channels_(num_channels) {
|
||||
DCHECK(num_channels == 1 || num_channels == 2);
|
||||
RTC_DCHECK(num_channels == 1 || num_channels == 2);
|
||||
WebRtcOpus_DecoderCreate(&dec_state_, static_cast<int>(channels_));
|
||||
WebRtcOpus_DecoderInit(dec_state_);
|
||||
}
|
||||
@ -30,7 +30,7 @@ int AudioDecoderOpus::DecodeInternal(const uint8_t* encoded,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
DCHECK_EQ(sample_rate_hz, 48000);
|
||||
RTC_DCHECK_EQ(sample_rate_hz, 48000);
|
||||
int16_t temp_type = 1; // Default is speech.
|
||||
int ret =
|
||||
WebRtcOpus_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type);
|
||||
@ -51,7 +51,7 @@ int AudioDecoderOpus::DecodeRedundantInternal(const uint8_t* encoded,
|
||||
speech_type);
|
||||
}
|
||||
|
||||
DCHECK_EQ(sample_rate_hz, 48000);
|
||||
RTC_DCHECK_EQ(sample_rate_hz, 48000);
|
||||
int16_t temp_type = 1; // Default is speech.
|
||||
int ret = WebRtcOpus_DecodeFec(dec_state_, encoded, encoded_len, decoded,
|
||||
&temp_type);
|
||||
|
||||
@ -41,10 +41,10 @@ AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) {
|
||||
// a loss rate from below, a higher threshold is used than jumping to the same
|
||||
// level from above.
|
||||
double OptimizePacketLossRate(double new_loss_rate, double old_loss_rate) {
|
||||
DCHECK_GE(new_loss_rate, 0.0);
|
||||
DCHECK_LE(new_loss_rate, 1.0);
|
||||
DCHECK_GE(old_loss_rate, 0.0);
|
||||
DCHECK_LE(old_loss_rate, 1.0);
|
||||
RTC_DCHECK_GE(new_loss_rate, 0.0);
|
||||
RTC_DCHECK_LE(new_loss_rate, 1.0);
|
||||
RTC_DCHECK_GE(old_loss_rate, 0.0);
|
||||
RTC_DCHECK_LE(old_loss_rate, 1.0);
|
||||
const double kPacketLossRate20 = 0.20;
|
||||
const double kPacketLossRate10 = 0.10;
|
||||
const double kPacketLossRate5 = 0.05;
|
||||
@ -90,14 +90,14 @@ bool AudioEncoderOpus::Config::IsOk() const {
|
||||
|
||||
AudioEncoderOpus::AudioEncoderOpus(const Config& config)
|
||||
: packet_loss_rate_(0.0), inst_(nullptr) {
|
||||
CHECK(RecreateEncoderInstance(config));
|
||||
RTC_CHECK(RecreateEncoderInstance(config));
|
||||
}
|
||||
|
||||
AudioEncoderOpus::AudioEncoderOpus(const CodecInst& codec_inst)
|
||||
: AudioEncoderOpus(CreateConfig(codec_inst)) {}
|
||||
|
||||
AudioEncoderOpus::~AudioEncoderOpus() {
|
||||
CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
|
||||
}
|
||||
|
||||
size_t AudioEncoderOpus::MaxEncodedBytes() const {
|
||||
@ -143,14 +143,15 @@ AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal(
|
||||
(static_cast<size_t>(Num10msFramesPerPacket()) * SamplesPer10msFrame())) {
|
||||
return EncodedInfo();
|
||||
}
|
||||
CHECK_EQ(input_buffer_.size(), static_cast<size_t>(Num10msFramesPerPacket()) *
|
||||
SamplesPer10msFrame());
|
||||
RTC_CHECK_EQ(
|
||||
input_buffer_.size(),
|
||||
static_cast<size_t>(Num10msFramesPerPacket()) * SamplesPer10msFrame());
|
||||
int status = WebRtcOpus_Encode(
|
||||
inst_, &input_buffer_[0],
|
||||
rtc::CheckedDivExact(input_buffer_.size(),
|
||||
static_cast<size_t>(config_.num_channels)),
|
||||
rtc::saturated_cast<int16_t>(max_encoded_bytes), encoded);
|
||||
CHECK_GE(status, 0); // Fails only if fed invalid data.
|
||||
RTC_CHECK_GE(status, 0); // Fails only if fed invalid data.
|
||||
input_buffer_.clear();
|
||||
EncodedInfo info;
|
||||
info.encoded_bytes = static_cast<size_t>(status);
|
||||
@ -162,7 +163,7 @@ AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal(
|
||||
}
|
||||
|
||||
void AudioEncoderOpus::Reset() {
|
||||
CHECK(RecreateEncoderInstance(config_));
|
||||
RTC_CHECK(RecreateEncoderInstance(config_));
|
||||
}
|
||||
|
||||
bool AudioEncoderOpus::SetFec(bool enable) {
|
||||
@ -193,23 +194,24 @@ bool AudioEncoderOpus::SetApplication(Application application) {
|
||||
void AudioEncoderOpus::SetMaxPlaybackRate(int frequency_hz) {
|
||||
auto conf = config_;
|
||||
conf.max_playback_rate_hz = frequency_hz;
|
||||
CHECK(RecreateEncoderInstance(conf));
|
||||
RTC_CHECK(RecreateEncoderInstance(conf));
|
||||
}
|
||||
|
||||
void AudioEncoderOpus::SetProjectedPacketLossRate(double fraction) {
|
||||
double opt_loss_rate = OptimizePacketLossRate(fraction, packet_loss_rate_);
|
||||
if (packet_loss_rate_ != opt_loss_rate) {
|
||||
packet_loss_rate_ = opt_loss_rate;
|
||||
CHECK_EQ(0, WebRtcOpus_SetPacketLossRate(
|
||||
inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5)));
|
||||
RTC_CHECK_EQ(
|
||||
0, WebRtcOpus_SetPacketLossRate(
|
||||
inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5)));
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) {
|
||||
config_.bitrate_bps =
|
||||
std::max(std::min(bits_per_second, kMaxBitrateBps), kMinBitrateBps);
|
||||
DCHECK(config_.IsOk());
|
||||
CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.bitrate_bps));
|
||||
RTC_DCHECK(config_.IsOk());
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.bitrate_bps));
|
||||
}
|
||||
|
||||
int AudioEncoderOpus::Num10msFramesPerPacket() const {
|
||||
@ -227,27 +229,28 @@ bool AudioEncoderOpus::RecreateEncoderInstance(const Config& config) {
|
||||
if (!config.IsOk())
|
||||
return false;
|
||||
if (inst_)
|
||||
CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
|
||||
input_buffer_.clear();
|
||||
input_buffer_.reserve(Num10msFramesPerPacket() * SamplesPer10msFrame());
|
||||
CHECK_EQ(0, WebRtcOpus_EncoderCreate(&inst_, config.num_channels,
|
||||
config.application));
|
||||
CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config.bitrate_bps));
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_EncoderCreate(&inst_, config.num_channels,
|
||||
config.application));
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config.bitrate_bps));
|
||||
if (config.fec_enabled) {
|
||||
CHECK_EQ(0, WebRtcOpus_EnableFec(inst_));
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_EnableFec(inst_));
|
||||
} else {
|
||||
CHECK_EQ(0, WebRtcOpus_DisableFec(inst_));
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_DisableFec(inst_));
|
||||
}
|
||||
CHECK_EQ(0,
|
||||
WebRtcOpus_SetMaxPlaybackRate(inst_, config.max_playback_rate_hz));
|
||||
CHECK_EQ(0, WebRtcOpus_SetComplexity(inst_, config.complexity));
|
||||
RTC_CHECK_EQ(
|
||||
0, WebRtcOpus_SetMaxPlaybackRate(inst_, config.max_playback_rate_hz));
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_SetComplexity(inst_, config.complexity));
|
||||
if (config.dtx_enabled) {
|
||||
CHECK_EQ(0, WebRtcOpus_EnableDtx(inst_));
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_EnableDtx(inst_));
|
||||
} else {
|
||||
CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_));
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_));
|
||||
}
|
||||
CHECK_EQ(0, WebRtcOpus_SetPacketLossRate(
|
||||
inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5)));
|
||||
RTC_CHECK_EQ(0,
|
||||
WebRtcOpus_SetPacketLossRate(
|
||||
inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5)));
|
||||
config_ = config;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ namespace {
|
||||
// Returns a vector with the n evenly-spaced numbers a, a + (b - a)/(n - 1),
|
||||
// ..., b.
|
||||
std::vector<double> IntervalSteps(double a, double b, size_t n) {
|
||||
DCHECK_GT(n, 1u);
|
||||
RTC_DCHECK_GT(n, 1u);
|
||||
const double step = (b - a) / (n - 1);
|
||||
std::vector<double> points;
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
|
||||
@ -28,8 +28,8 @@ int AudioDecoderPcm16B::DecodeInternal(const uint8_t* encoded,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 ||
|
||||
sample_rate_hz == 32000 || sample_rate_hz == 48000)
|
||||
RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 ||
|
||||
sample_rate_hz == 32000 || sample_rate_hz == 48000)
|
||||
<< "Unsupported sample rate " << sample_rate_hz;
|
||||
size_t ret = WebRtcPcm16b_Decode(encoded, encoded_len, decoded);
|
||||
*speech_type = ConvertSpeechType(1);
|
||||
@ -44,7 +44,7 @@ int AudioDecoderPcm16B::PacketDuration(const uint8_t* encoded,
|
||||
|
||||
AudioDecoderPcm16BMultiCh::AudioDecoderPcm16BMultiCh(size_t num_channels)
|
||||
: channels_(num_channels) {
|
||||
DCHECK(num_channels > 0);
|
||||
RTC_DCHECK(num_channels > 0);
|
||||
}
|
||||
|
||||
size_t AudioDecoderPcm16BMultiCh::Channels() const {
|
||||
|
||||
@ -19,7 +19,7 @@ namespace webrtc {
|
||||
AudioEncoderCopyRed::AudioEncoderCopyRed(const Config& config)
|
||||
: speech_encoder_(config.speech_encoder),
|
||||
red_payload_type_(config.payload_type) {
|
||||
CHECK(speech_encoder_) << "Speech encoder not provided.";
|
||||
RTC_CHECK(speech_encoder_) << "Speech encoder not provided.";
|
||||
}
|
||||
|
||||
AudioEncoderCopyRed::~AudioEncoderCopyRed() = default;
|
||||
@ -60,26 +60,26 @@ AudioEncoder::EncodedInfo AudioEncoderCopyRed::EncodeInternal(
|
||||
EncodedInfo info = speech_encoder_->Encode(
|
||||
rtp_timestamp, audio, static_cast<size_t>(SampleRateHz() / 100),
|
||||
max_encoded_bytes, encoded);
|
||||
CHECK_GE(max_encoded_bytes,
|
||||
info.encoded_bytes + secondary_info_.encoded_bytes);
|
||||
CHECK(info.redundant.empty()) << "Cannot use nested redundant encoders.";
|
||||
RTC_CHECK_GE(max_encoded_bytes,
|
||||
info.encoded_bytes + secondary_info_.encoded_bytes);
|
||||
RTC_CHECK(info.redundant.empty()) << "Cannot use nested redundant encoders.";
|
||||
|
||||
if (info.encoded_bytes > 0) {
|
||||
// |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively
|
||||
// discarding the (empty) vector of redundant information. This is
|
||||
// intentional.
|
||||
info.redundant.push_back(info);
|
||||
DCHECK_EQ(info.redundant.size(), 1u);
|
||||
RTC_DCHECK_EQ(info.redundant.size(), 1u);
|
||||
if (secondary_info_.encoded_bytes > 0) {
|
||||
memcpy(&encoded[info.encoded_bytes], secondary_encoded_.data(),
|
||||
secondary_info_.encoded_bytes);
|
||||
info.redundant.push_back(secondary_info_);
|
||||
DCHECK_EQ(info.redundant.size(), 2u);
|
||||
RTC_DCHECK_EQ(info.redundant.size(), 2u);
|
||||
}
|
||||
// Save primary to secondary.
|
||||
secondary_encoded_.SetData(encoded, info.encoded_bytes);
|
||||
secondary_info_ = info;
|
||||
DCHECK_EQ(info.speech, info.redundant[0].speech);
|
||||
RTC_DCHECK_EQ(info.speech, info.redundant[0].speech);
|
||||
}
|
||||
// Update main EncodedInfo.
|
||||
info.payload_type = red_payload_type_;
|
||||
|
||||
@ -87,8 +87,8 @@ class MockEncodeHelper {
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded) {
|
||||
if (write_payload_) {
|
||||
CHECK(encoded);
|
||||
CHECK_LE(info_.encoded_bytes, max_encoded_bytes);
|
||||
RTC_CHECK(encoded);
|
||||
RTC_CHECK_LE(info_.encoded_bytes, max_encoded_bytes);
|
||||
memcpy(encoded, payload_, info_.encoded_bytes);
|
||||
}
|
||||
return info_;
|
||||
|
||||
Reference in New Issue
Block a user