Introduce dchecked_cast, and start using it
It's the faster, less strict cousin of checked_cast.
BUG=none
Review-Url: https://codereview.webrtc.org/2714063002
Cr-Commit-Position: refs/heads/master@{#16958}
diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
index 09a3296..786cb84 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
@@ -199,7 +199,7 @@
}
RTC_DCHECK_EQ(
audio_frame->sample_rate_hz_,
- rtc::checked_cast<int>(audio_frame->samples_per_channel_ * 100));
+ rtc::dchecked_cast<int>(audio_frame->samples_per_channel_ * 100));
SetAudioFrameActivityAndType(vad_->enabled(), LastOutputType(),
last_vad_activity_, audio_frame);
last_vad_activity_ = audio_frame->vad_activity_;
@@ -826,7 +826,7 @@
if (packet_length_samples != decision_logic_->packet_length_samples()) {
decision_logic_->set_packet_length_samples(packet_length_samples);
delay_manager_->SetPacketAudioLength(
- rtc::checked_cast<int>((1000 * packet_length_samples) / fs_hz_));
+ rtc::dchecked_cast<int>((1000 * packet_length_samples) / fs_hz_));
}
}
@@ -1131,7 +1131,7 @@
last_mode_ == kModePreemptiveExpandLowEnergy) {
// Subtract (samples_left + output_size_samples_) from sampleMemory.
decision_logic_->AddSampleMemory(
- -(samples_left + rtc::checked_cast<int>(output_size_samples_)));
+ -(samples_left + rtc::dchecked_cast<int>(output_size_samples_)));
}
// Check if it is time to play a DTMF event.
@@ -1157,11 +1157,9 @@
// Check if we already have enough samples in the |sync_buffer_|. If so,
// change decision to normal, unless the decision was merge, accelerate, or
// preemptive expand.
- if (samples_left >= rtc::checked_cast<int>(output_size_samples_) &&
- *operation != kMerge &&
- *operation != kAccelerate &&
- *operation != kFastAccelerate &&
- *operation != kPreemptiveExpand) {
+ if (samples_left >= rtc::dchecked_cast<int>(output_size_samples_) &&
+ *operation != kMerge && *operation != kAccelerate &&
+ *operation != kFastAccelerate && *operation != kPreemptiveExpand) {
*operation = kNormal;
return 0;
}
@@ -1454,7 +1452,7 @@
return 0;
}
- while (*decoded_length < rtc::checked_cast<int>(output_size_samples_)) {
+ while (*decoded_length < rtc::dchecked_cast<int>(output_size_samples_)) {
const int length = decoder->Decode(
nullptr, 0, fs_hz_,
(decoded_buffer_length_ - *decoded_length) * sizeof(int16_t),
@@ -1500,7 +1498,7 @@
const auto& result = *opt_result;
*speech_type = result.speech_type;
if (result.num_decoded_samples > 0) {
- *decoded_length += rtc::checked_cast<int>(result.num_decoded_samples);
+ *decoded_length += rtc::dchecked_cast<int>(result.num_decoded_samples);
// Update |decoder_frame_length_| with number of samples per channel.
decoder_frame_length_ =
result.num_decoded_samples / decoder->Channels();
@@ -1513,7 +1511,7 @@
packet_list->clear();
break;
}
- if (*decoded_length > rtc::checked_cast<int>(decoded_buffer_length_)) {
+ if (*decoded_length > rtc::dchecked_cast<int>(decoded_buffer_length_)) {
// Guard against overflow.
LOG(LS_WARNING) << "Decoded too much.";
packet_list->clear();
@@ -1986,7 +1984,8 @@
packet_duration = packet->frame->Duration();
// TODO(ossu): Is this the correct way to track Opus FEC packets?
if (packet->priority.codec_level > 0) {
- stats_.SecondaryDecodedSamples(rtc::checked_cast<int>(packet_duration));
+ stats_.SecondaryDecodedSamples(
+ rtc::dchecked_cast<int>(packet_duration));
}
} else if (!has_cng_packet) {
LOG(LS_WARNING) << "Unknown payload type "
@@ -2029,7 +2028,7 @@
packet_buffer_->DiscardAllOldPackets(timestamp_);
}
- return rtc::checked_cast<int>(extracted_samples);
+ return rtc::dchecked_cast<int>(extracted_samples);
}
void NetEqImpl::UpdatePlcComponents(int fs_hz, size_t channels) {