diff --git a/api/audio/echo_canceller3_config.cc b/api/audio/echo_canceller3_config.cc index 0224c712b4..e00ff19bd6 100644 --- a/api/audio/echo_canceller3_config.cc +++ b/api/audio/echo_canceller3_config.cc @@ -18,7 +18,7 @@ namespace webrtc { namespace { bool Limit(float* value, float min, float max) { - float clamped = rtc::SafeClamp(*value, min, max); + float clamped = SafeClamp(*value, min, max); clamped = std::isfinite(clamped) ? clamped : min; bool res = *value == clamped; *value = clamped; @@ -26,14 +26,14 @@ bool Limit(float* value, float min, float max) { } bool Limit(size_t* value, size_t min, size_t max) { - size_t clamped = rtc::SafeClamp(*value, min, max); + size_t clamped = SafeClamp(*value, min, max); bool res = *value == clamped; *value = clamped; return res; } bool Limit(int* value, int min, int max) { - int clamped = rtc::SafeClamp(*value, min, max); + int clamped = SafeClamp(*value, min, max); bool res = *value == clamped; *value = clamped; return res; diff --git a/api/audio_codecs/L16/audio_encoder_L16.cc b/api/audio_codecs/L16/audio_encoder_L16.cc index 2010a90ce0..69fce6c3bd 100644 --- a/api/audio_codecs/L16/audio_encoder_L16.cc +++ b/api/audio_codecs/L16/audio_encoder_L16.cc @@ -45,7 +45,7 @@ std::optional AudioEncoderL16::SdpToConfig( if (ptime_iter != format.parameters.end()) { const auto ptime = StringToNumber(ptime_iter->second); if (ptime && *ptime > 0) { - config.frame_size_ms = rtc::SafeClamp(10 * (*ptime / 10), 10, 60); + config.frame_size_ms = SafeClamp(10 * (*ptime / 10), 10, 60); } } if (absl::EqualsIgnoreCase(format.name, "L16") && config.IsOk()) { diff --git a/api/audio_codecs/g711/audio_encoder_g711.cc b/api/audio_codecs/g711/audio_encoder_g711.cc index e36d2f9ca2..701f3c21da 100644 --- a/api/audio_codecs/g711/audio_encoder_g711.cc +++ b/api/audio_codecs/g711/audio_encoder_g711.cc @@ -46,7 +46,7 @@ std::optional AudioEncoderG711::SdpToConfig( if (ptime_iter != format.parameters.end()) { const auto ptime = StringToNumber(ptime_iter->second); if (ptime && *ptime > 0) { - config.frame_size_ms = rtc::SafeClamp(10 * (*ptime / 10), 10, 60); + config.frame_size_ms = SafeClamp(10 * (*ptime / 10), 10, 60); } } if (!config.IsOk()) { diff --git a/api/audio_codecs/g722/audio_encoder_g722.cc b/api/audio_codecs/g722/audio_encoder_g722.cc index 80387a1895..b3025c91db 100644 --- a/api/audio_codecs/g722/audio_encoder_g722.cc +++ b/api/audio_codecs/g722/audio_encoder_g722.cc @@ -46,7 +46,7 @@ std::optional AudioEncoderG722::SdpToConfig( auto ptime = StringToNumber(ptime_iter->second); if (ptime && *ptime > 0) { const int whole_packets = *ptime / 10; - config.frame_size_ms = rtc::SafeClamp(whole_packets * 10, 10, 60); + config.frame_size_ms = SafeClamp(whole_packets * 10, 10, 60); } } if (!config.IsOk()) { diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc index efeeef2ceb..9a09259c9c 100644 --- a/audio/channel_receive.cc +++ b/audio/channel_receive.cc @@ -1058,8 +1058,8 @@ bool ChannelReceive::SetMinimumPlayoutDelay(int delay_ms) { RTC_DCHECK_RUN_ON(&worker_thread_checker_); // Limit to range accepted by both VoE and ACM, so we're at least getting as // close as possible, instead of failing. - delay_ms = rtc::SafeClamp(delay_ms, kVoiceEngineMinMinPlayoutDelayMs, - kVoiceEngineMaxMinPlayoutDelayMs); + delay_ms = SafeClamp(delay_ms, kVoiceEngineMinMinPlayoutDelayMs, + kVoiceEngineMaxMinPlayoutDelayMs); if (!neteq_->SetMinimumDelay(delay_ms)) { RTC_DLOG(LS_ERROR) << "SetMinimumPlayoutDelay() failed to set min playout delay " diff --git a/call/bitrate_allocator.cc b/call/bitrate_allocator.cc index 1818b6746d..565af4248d 100644 --- a/call/bitrate_allocator.cc +++ b/call/bitrate_allocator.cc @@ -494,7 +494,7 @@ void BitrateAllocator::OnNetworkEstimateChanged(TargetTransferRate msg) { int loss_ratio_255 = msg.network_estimate.loss_rate_ratio * 255; last_fraction_loss_ = - rtc::dchecked_cast(rtc::SafeClamp(loss_ratio_255, 0, 255)); + rtc::dchecked_cast(SafeClamp(loss_ratio_255, 0, 255)); last_rtt_ = msg.network_estimate.round_trip_time.ms(); last_bwe_period_ms_ = msg.network_estimate.bwe_period.ms(); diff --git a/call/receive_time_calculator.cc b/call/receive_time_calculator.cc index e73e5ff86f..a7ac189f61 100644 --- a/call/receive_time_calculator.cc +++ b/call/receive_time_calculator.cc @@ -57,7 +57,7 @@ int64_t ReceiveTimeCalculator::ReconcileReceiveTimes(int64_t packet_time_us, int64_t safe_time_us) { int64_t stall_time_us = system_time_us - packet_time_us; if (total_system_time_passed_us_ < config_.stall_threshold->us()) { - stall_time_us = rtc::SafeMin(stall_time_us, config_.max_stall->us()); + stall_time_us = SafeMin(stall_time_us, config_.max_stall->us()); } int64_t corrected_time_us = safe_time_us - stall_time_us; @@ -107,8 +107,8 @@ int64_t ReceiveTimeCalculator::ReconcileReceiveTimes(int64_t packet_time_us, if (forward_clock_reset || obvious_backward_clock_reset || small_reset_during_stall_) { corrected_time_us = last_corrected_time_us_ + - rtc::SafeClamp(packet_time_delta_us, 0, - config_.max_packet_time_repair->us()); + SafeClamp(packet_time_delta_us, 0, + config_.max_packet_time_repair->us()); } } diff --git a/logging/rtc_event_log/rtc_event_log_impl.cc b/logging/rtc_event_log/rtc_event_log_impl.cc index 19746cfb1b..63cc0f7d9c 100644 --- a/logging/rtc_event_log/rtc_event_log_impl.cc +++ b/logging/rtc_event_log/rtc_event_log_impl.cc @@ -235,8 +235,8 @@ void RtcEventLogImpl::ScheduleOutput() { }; const int64_t now_ms = rtc::TimeMillis(); const int64_t time_since_output_ms = now_ms - last_output_ms_; - const int32_t delay = rtc::SafeClamp(output_period_ms_ - time_since_output_ms, - 0, output_period_ms_); + const int32_t delay = + SafeClamp(output_period_ms_ - time_since_output_ms, 0, output_period_ms_); task_queue_->PostDelayedTask(std::move(output_task), TimeDelta::Millis(delay)); } diff --git a/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/modules/audio_coding/codecs/opus/audio_encoder_opus.cc index 4bf81ff773..047df0daa5 100644 --- a/modules/audio_coding/codecs/opus/audio_encoder_opus.cc +++ b/modules/audio_coding/codecs/opus/audio_encoder_opus.cc @@ -733,9 +733,9 @@ void AudioEncoderOpusImpl::SetProjectedPacketLossRate(float fraction) { } void AudioEncoderOpusImpl::SetTargetBitrate(int bits_per_second) { - const int new_bitrate = rtc::SafeClamp( - bits_per_second, AudioEncoderOpusConfig::kMinBitrateBps, - AudioEncoderOpusConfig::kMaxBitrateBps); + const int new_bitrate = + SafeClamp(bits_per_second, AudioEncoderOpusConfig::kMinBitrateBps, + AudioEncoderOpusConfig::kMaxBitrateBps); if (config_.bitrate_bps && *config_.bitrate_bps != new_bitrate) { config_.bitrate_bps = new_bitrate; RTC_DCHECK(config_.IsOk()); diff --git a/modules/audio_coding/neteq/delay_constraints.cc b/modules/audio_coding/neteq/delay_constraints.cc index e493155e5b..16402189f2 100644 --- a/modules/audio_coding/neteq/delay_constraints.cc +++ b/modules/audio_coding/neteq/delay_constraints.cc @@ -100,7 +100,7 @@ void DelayConstraints::UpdateEffectiveMinimumDelay() { // Clamp `base_minimum_delay_ms_` into the range which can be effectively // used. const int base_minimum_delay_ms = - rtc::SafeClamp(base_minimum_delay_ms_, 0, MinimumDelayUpperBound()); + SafeClamp(base_minimum_delay_ms_, 0, MinimumDelayUpperBound()); effective_minimum_delay_ms_ = std::max(minimum_delay_ms_, base_minimum_delay_ms); } diff --git a/modules/audio_coding/neteq/merge.cc b/modules/audio_coding/neteq/merge.cc index 22cf6a7754..47742fef85 100644 --- a/modules/audio_coding/neteq/merge.cc +++ b/modules/audio_coding/neteq/merge.cc @@ -211,8 +211,8 @@ int16_t Merge::SignalScaling(const int16_t* input, size_t input_length, const int16_t* expanded_signal) const { // Adjust muting factor if new vector is more or less of the BGN energy. - const auto mod_input_length = rtc::SafeMin( - 64 * rtc::dchecked_cast(fs_mult_), input_length); + const auto mod_input_length = + SafeMin(64 * rtc::dchecked_cast(fs_mult_), input_length); const int16_t expanded_max = WebRtcSpl_MaxAbsValueW16(expanded_signal, mod_input_length); int32_t factor = diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc b/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc index bc631b1ce8..ac973bed8f 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc @@ -566,7 +566,7 @@ TEST_P(AdaptiveFirFilterMultiChannel, FilterAndAdapt) { e.begin(), [&](float a, float b) { return a - b * kScale; }); std::for_each(e.begin(), e.end(), - [](float& a) { a = rtc::SafeClamp(a, -32768.f, 32767.f); }); + [](float& a) { a = SafeClamp(a, -32768.f, 32767.f); }); fft.ZeroPaddedFft(e, Aec3Fft::Window::kRectangular, &E); for (auto& o : output) { for (size_t k = 0; k < kBlockSize; ++k) { diff --git a/modules/audio_processing/aec3/coarse_filter_update_gain_unittest.cc b/modules/audio_processing/aec3/coarse_filter_update_gain_unittest.cc index 0a54c9d5b4..afa4448104 100644 --- a/modules/audio_processing/aec3/coarse_filter_update_gain_unittest.cc +++ b/modules/audio_processing/aec3/coarse_filter_update_gain_unittest.cc @@ -100,7 +100,7 @@ void RunFilterUpdateTest(int num_blocks_to_process, e_coarse.begin(), [&](float a, float b) { return a - b * kScale; }); std::for_each(e_coarse.begin(), e_coarse.end(), - [](float& a) { a = rtc::SafeClamp(a, -32768.f, 32767.f); }); + [](float& a) { a = SafeClamp(a, -32768.f, 32767.f); }); fft.ZeroPaddedFft(e_coarse, Aec3Fft::Window::kRectangular, &E_coarse); std::array render_power; diff --git a/modules/audio_processing/aec3/echo_remover_metrics.cc b/modules/audio_processing/aec3/echo_remover_metrics.cc index 1e3a70ad38..aa13da9abd 100644 --- a/modules/audio_processing/aec3/echo_remover_metrics.cc +++ b/modules/audio_processing/aec3/echo_remover_metrics.cc @@ -149,7 +149,7 @@ int TransformDbMetricForReporting(bool negate, if (negate) { new_value = -new_value; } - return static_cast(rtc::SafeClamp(new_value, min_value, max_value)); + return static_cast(SafeClamp(new_value, min_value, max_value)); } } // namespace aec3 diff --git a/modules/audio_processing/aec3/refined_filter_update_gain_unittest.cc b/modules/audio_processing/aec3/refined_filter_update_gain_unittest.cc index 43f3f0bf20..e782db7829 100644 --- a/modules/audio_processing/aec3/refined_filter_update_gain_unittest.cc +++ b/modules/audio_processing/aec3/refined_filter_update_gain_unittest.cc @@ -162,7 +162,7 @@ void RunFilterUpdateTest(const Environment& env, e_refined.begin(), [&](float a, float b) { return a - b * kScale; }); std::for_each(e_refined.begin(), e_refined.end(), - [](float& a) { a = rtc::SafeClamp(a, -32768.f, 32767.f); }); + [](float& a) { a = SafeClamp(a, -32768.f, 32767.f); }); fft.ZeroPaddedFft(e_refined, Aec3Fft::Window::kRectangular, &E_refined); for (size_t k = 0; k < kBlockSize; ++k) { s[k] = kScale * s_scratch[k + kFftLengthBy2]; @@ -175,7 +175,7 @@ void RunFilterUpdateTest(const Environment& env, e_coarse.begin(), [&](float a, float b) { return a - b * kScale; }); std::for_each(e_coarse.begin(), e_coarse.end(), - [](float& a) { a = rtc::SafeClamp(a, -32768.f, 32767.f); }); + [](float& a) { a = SafeClamp(a, -32768.f, 32767.f); }); fft.ZeroPaddedFft(e_coarse, Aec3Fft::Window::kRectangular, &E_coarse); // Compute spectra for future use. diff --git a/modules/audio_processing/aec3/signal_dependent_erle_estimator.cc b/modules/audio_processing/aec3/signal_dependent_erle_estimator.cc index a5e77092a6..dbfca57db2 100644 --- a/modules/audio_processing/aec3/signal_dependent_erle_estimator.cc +++ b/modules/audio_processing/aec3/signal_dependent_erle_estimator.cc @@ -205,12 +205,12 @@ void SignalDependentErleEstimator::Update( float correction_factor = correction_factors_[ch][n_active_sections_[ch][k]] [band_to_subband_[k]]; - erle_[ch][k] = rtc::SafeClamp(average_erle[ch][k] * correction_factor, - min_erle_, max_erle_[band_to_subband_[k]]); + erle_[ch][k] = SafeClamp(average_erle[ch][k] * correction_factor, + min_erle_, max_erle_[band_to_subband_[k]]); if (use_onset_detection_) { - erle_onset_compensated_[ch][k] = rtc::SafeClamp( - average_erle_onset_compensated[ch][k] * correction_factor, - min_erle_, max_erle_[band_to_subband_[k]]); + erle_onset_compensated_[ch][k] = + SafeClamp(average_erle_onset_compensated[ch][k] * correction_factor, + min_erle_, max_erle_[band_to_subband_[k]]); } } } @@ -306,7 +306,7 @@ void SignalDependentErleEstimator::UpdateCorrectionFactors( alpha = static_cast(is_erle_updated[subband]) * alpha; erle_estimators_[ch][idx][subband] += alpha * (new_erle[subband] - erle_estimators_[ch][idx][subband]); - erle_estimators_[ch][idx][subband] = rtc::SafeClamp( + erle_estimators_[ch][idx][subband] = SafeClamp( erle_estimators_[ch][idx][subband], min_erle_, max_erle_[subband]); } @@ -317,8 +317,8 @@ void SignalDependentErleEstimator::UpdateCorrectionFactors( alpha = static_cast(is_erle_updated[subband]) * alpha; erle_ref_[ch][subband] += alpha * (new_erle[subband] - erle_ref_[ch][subband]); - erle_ref_[ch][subband] = rtc::SafeClamp(erle_ref_[ch][subband], - min_erle_, max_erle_[subband]); + erle_ref_[ch][subband] = + SafeClamp(erle_ref_[ch][subband], min_erle_, max_erle_[subband]); } for (size_t subband = 0; subband < kSubbands; ++subband) { diff --git a/modules/audio_processing/aec3/subband_erle_estimator.cc b/modules/audio_processing/aec3/subband_erle_estimator.cc index 8d3ff13e6e..e8a148987c 100644 --- a/modules/audio_processing/aec3/subband_erle_estimator.cc +++ b/modules/audio_processing/aec3/subband_erle_estimator.cc @@ -141,7 +141,7 @@ void SubbandErleEstimator::UpdateBands( if (!use_min_erle_during_onsets_) { float alpha = new_erle[k] < erle_during_onsets_[ch][k] ? 0.3f : 0.15f; - erle_during_onsets_[ch][k] = rtc::SafeClamp( + erle_during_onsets_[ch][k] = SafeClamp( erle_during_onsets_[ch][k] + alpha * (new_erle[k] - erle_during_onsets_[ch][k]), min_erle_, max_erle_[k]); @@ -159,8 +159,7 @@ void SubbandErleEstimator::UpdateBands( if (new_erle < erle) { alpha = low_render_energy ? 0.f : 0.1f; } - erle = - rtc::SafeClamp(erle + alpha * (new_erle - erle), min_erle, max_erle); + erle = SafeClamp(erle + alpha * (new_erle - erle), min_erle, max_erle); }; for (size_t k = 1; k < kFftLengthBy2; ++k) { diff --git a/modules/audio_processing/aec3/suppression_filter.cc b/modules/audio_processing/aec3/suppression_filter.cc index 83ded425d5..8e76f36df5 100644 --- a/modules/audio_processing/aec3/suppression_filter.cc +++ b/modules/audio_processing/aec3/suppression_filter.cc @@ -171,7 +171,7 @@ void SuppressionFilter::ApplyGain( for (int b = 0; b < e->NumBands(); ++b) { auto e_band = e->View(b, ch); for (size_t i = 0; i < kFftLengthBy2; ++i) { - e_band[i] = rtc::SafeClamp(e_band[i], -32768.f, 32767.f); + e_band[i] = SafeClamp(e_band[i], -32768.f, 32767.f); } } } diff --git a/modules/audio_processing/agc/agc_manager_direct.cc b/modules/audio_processing/agc/agc_manager_direct.cc index 0f2469df5c..b98d07d79a 100644 --- a/modules/audio_processing/agc/agc_manager_direct.cc +++ b/modules/audio_processing/agc/agc_manager_direct.cc @@ -152,7 +152,7 @@ int GetSpeechLevelErrorDb(float speech_level_dbfs, float speech_probability) { return 0; } - const float speech_level = rtc::SafeClamp( + const float speech_level = SafeClamp( speech_level_dbfs, kMinSpeechLevelDbfs, kMaxSpeechLevelDbfs); return std::round(kOverrideTargetSpeechLevelDbfs - speech_level); @@ -376,7 +376,7 @@ void MonoAgc::UpdateGain(int rms_error_db) { // Handle as much error as possible with the compressor first. int raw_compression = - rtc::SafeClamp(rms_error, kMinCompressionGain, max_compression_gain_); + SafeClamp(rms_error, kMinCompressionGain, max_compression_gain_); // Deemphasize the compression gain error. Move halfway between the current // target and the newly received target. This serves to soften perceptible @@ -397,8 +397,8 @@ void MonoAgc::UpdateGain(int rms_error_db) { // raw rather than deemphasized compression here as we would otherwise // shrink the amount of slack the compressor provides. const int residual_gain = - rtc::SafeClamp(rms_error - raw_compression, -kMaxResidualGainChange, - kMaxResidualGainChange); + SafeClamp(rms_error - raw_compression, -kMaxResidualGainChange, + kMaxResidualGainChange); RTC_DLOG(LS_INFO) << "[agc] rms_error=" << rms_error << ", target_compression=" << target_compression_ << ", residual_gain=" << residual_gain; diff --git a/modules/audio_processing/agc/agc_manager_direct_unittest.cc b/modules/audio_processing/agc/agc_manager_direct_unittest.cc index f9bb53a087..51708df740 100644 --- a/modules/audio_processing/agc/agc_manager_direct_unittest.cc +++ b/modules/audio_processing/agc/agc_manager_direct_unittest.cc @@ -258,8 +258,8 @@ class SpeechSamplesReader { // Apply gain and copy samples into `audio_buffer_`. std::transform(buffer_.begin(), buffer_.end(), audio_buffer_.channels()[0], [gain](int16_t v) -> float { - return rtc::SafeClamp(static_cast(v) * gain, - kMinSample, kMaxSample); + return SafeClamp(static_cast(v) * gain, + kMinSample, kMaxSample); }); agc.AnalyzePreProcess(audio_buffer_); @@ -292,8 +292,8 @@ class SpeechSamplesReader { // Apply gain and copy samples into `audio_buffer_`. std::transform(buffer_.begin(), buffer_.end(), audio_buffer_.channels()[0], [gain](int16_t v) -> float { - return rtc::SafeClamp(static_cast(v) * gain, - kMinSample, kMaxSample); + return SafeClamp(static_cast(v) * gain, + kMinSample, kMaxSample); }); agc.AnalyzePreProcess(audio_buffer_); diff --git a/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc b/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc index 5f924cbbcf..8bbbedced5 100644 --- a/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc +++ b/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc @@ -96,8 +96,8 @@ float ComputeGainChangeThisFrameDb(float target_gain_db, if (!gain_increase_allowed) { target_gain_difference_db = std::min(target_gain_difference_db, 0.0f); } - return rtc::SafeClamp(target_gain_difference_db, -max_gain_decrease_db, - max_gain_increase_db); + return SafeClamp(target_gain_difference_db, -max_gain_decrease_db, + max_gain_increase_db); } } // namespace diff --git a/modules/audio_processing/agc2/clipping_predictor.cc b/modules/audio_processing/agc2/clipping_predictor.cc index 06115a3065..77f928d2bd 100644 --- a/modules/audio_processing/agc2/clipping_predictor.cc +++ b/modules/audio_processing/agc2/clipping_predictor.cc @@ -151,7 +151,7 @@ class ClippingEventPredictor : public ClippingPredictor { } if (PredictClippingEvent(channel)) { const int new_level = - rtc::SafeClamp(level - default_step, min_mic_level, max_mic_level); + SafeClamp(level - default_step, min_mic_level, max_mic_level); const int step = level - new_level; if (step > 0) { return step; @@ -296,15 +296,15 @@ class ClippingPeakPredictor : public ClippingPredictor { step = default_step; } else { const int estimated_gain_change = - rtc::SafeClamp(-static_cast(std::ceil(estimate_db.value())), - -kClippingPredictorMaxGainChange, 0); + SafeClamp(-static_cast(std::ceil(estimate_db.value())), + -kClippingPredictorMaxGainChange, 0); step = std::max(level - ComputeVolumeUpdate(estimated_gain_change, level, min_mic_level, max_mic_level), default_step); } const int new_level = - rtc::SafeClamp(level - step, min_mic_level, max_mic_level); + SafeClamp(level - step, min_mic_level, max_mic_level); if (level > new_level) { return level - new_level; } diff --git a/modules/audio_processing/agc2/gain_applier.cc b/modules/audio_processing/agc2/gain_applier.cc index f833ad1fbe..927bb554c4 100644 --- a/modules/audio_processing/agc2/gain_applier.cc +++ b/modules/audio_processing/agc2/gain_applier.cc @@ -28,7 +28,7 @@ void ClipSignal(DeinterleavedView signal) { for (size_t k = 0; k < signal.num_channels(); ++k) { MonoView channel_view = signal[k]; for (auto& sample : channel_view) { - sample = rtc::SafeClamp(sample, kMinFloatS16Value, kMaxFloatS16Value); + sample = SafeClamp(sample, kMinFloatS16Value, kMaxFloatS16Value); } } } diff --git a/modules/audio_processing/agc2/input_volume_controller.cc b/modules/audio_processing/agc2/input_volume_controller.cc index fcb8f1db31..557c1e67d1 100644 --- a/modules/audio_processing/agc2/input_volume_controller.cc +++ b/modules/audio_processing/agc2/input_volume_controller.cc @@ -116,8 +116,8 @@ int GetSpeechLevelRmsErrorDb(float speech_level_dbfs, constexpr float kMaxSpeechLevelDbfs = 30.0f; RTC_DCHECK_GE(speech_level_dbfs, kMinSpeechLevelDbfs); RTC_DCHECK_LE(speech_level_dbfs, kMaxSpeechLevelDbfs); - speech_level_dbfs = rtc::SafeClamp( - speech_level_dbfs, kMinSpeechLevelDbfs, kMaxSpeechLevelDbfs); + speech_level_dbfs = SafeClamp(speech_level_dbfs, kMinSpeechLevelDbfs, + kMaxSpeechLevelDbfs); int rms_error_db = 0; if (speech_level_dbfs > target_range_max_dbfs) { @@ -343,7 +343,7 @@ void MonoInputVolumeController::UpdateInputVolume(int rms_error_db) { // Prevent too large microphone input volume changes by clamping the RMS // error. rms_error_db = - rtc::SafeClamp(rms_error_db, -KMaxAbsRmsErrorDbfs, KMaxAbsRmsErrorDbfs); + SafeClamp(rms_error_db, -KMaxAbsRmsErrorDbfs, KMaxAbsRmsErrorDbfs); if (rms_error_db == 0) { return; } diff --git a/modules/audio_processing/agc2/input_volume_controller_unittest.cc b/modules/audio_processing/agc2/input_volume_controller_unittest.cc index eaa847143c..d0f9b6ed09 100644 --- a/modules/audio_processing/agc2/input_volume_controller_unittest.cc +++ b/modules/audio_processing/agc2/input_volume_controller_unittest.cc @@ -173,8 +173,8 @@ class SpeechSamplesReader { // Apply gain and copy samples into `audio_buffer_`. std::transform(buffer_.begin(), buffer_.end(), audio_buffer_.channels()[0], [gain](int16_t v) -> float { - return rtc::SafeClamp(static_cast(v) * gain, - kMinSample, kMaxSample); + return SafeClamp(static_cast(v) * gain, + kMinSample, kMaxSample); }); controller.AnalyzeInputAudio(applied_input_volume, audio_buffer_); const auto recommended_input_volume = controller.RecommendInputVolume( diff --git a/modules/audio_processing/agc2/limiter.cc b/modules/audio_processing/agc2/limiter.cc index 7a99b94dce..7b585bf9b6 100644 --- a/modules/audio_processing/agc2/limiter.cc +++ b/modules/audio_processing/agc2/limiter.cc @@ -79,8 +79,8 @@ void ScaleSamples(MonoView per_sample_scaling_factors, for (size_t i = 0; i < signal.num_channels(); ++i) { MonoView channel = signal[i]; for (int j = 0; j < samples_per_channel; ++j) { - channel[j] = rtc::SafeClamp(channel[j] * per_sample_scaling_factors[j], - kMinFloatS16Value, kMaxFloatS16Value); + channel[j] = SafeClamp(channel[j] * per_sample_scaling_factors[j], + kMinFloatS16Value, kMaxFloatS16Value); } } } diff --git a/modules/audio_processing/agc2/saturation_protector.cc b/modules/audio_processing/agc2/saturation_protector.cc index 961baf4cd3..8255ec5b3f 100644 --- a/modules/audio_processing/agc2/saturation_protector.cc +++ b/modules/audio_processing/agc2/saturation_protector.cc @@ -88,7 +88,7 @@ void UpdateSaturationProtectorState(float peak_dbfs, } state.headroom_db = - rtc::SafeClamp(state.headroom_db, kMinMarginDb, kMaxMarginDb); + SafeClamp(state.headroom_db, kMinMarginDb, kMaxMarginDb); } // Saturation protector which recommends a headroom based on the recent peaks. diff --git a/modules/audio_processing/agc2/speech_level_estimator.cc b/modules/audio_processing/agc2/speech_level_estimator.cc index 7bf3252116..f9354d1607 100644 --- a/modules/audio_processing/agc2/speech_level_estimator.cc +++ b/modules/audio_processing/agc2/speech_level_estimator.cc @@ -20,7 +20,7 @@ namespace webrtc { namespace { float ClampLevelEstimateDbfs(float level_estimate_dbfs) { - return rtc::SafeClamp(level_estimate_dbfs, -90.0f, 30.0f); + return SafeClamp(level_estimate_dbfs, -90.0f, 30.0f); } // Returns the initial speech level estimate needed to apply the initial gain. diff --git a/modules/audio_processing/audio_processing_unittest.cc b/modules/audio_processing/audio_processing_unittest.cc index c83a7dba17..dfe0f0a732 100644 --- a/modules/audio_processing/audio_processing_unittest.cc +++ b/modules/audio_processing/audio_processing_unittest.cc @@ -670,13 +670,13 @@ void ApmTest::ProcessDelayVerificationTest(int delay_ms, // Calculate expected delay estimate and acceptable regions. Further, // limit them w.r.t. AEC delay estimation support. const size_t samples_per_ms = - rtc::SafeMin(16u, frame_.samples_per_channel() / 10); + SafeMin(16u, frame_.samples_per_channel() / 10); const int expected_median = - rtc::SafeClamp(delay_ms - system_delay_ms, delay_min, delay_max); - const int expected_median_high = rtc::SafeClamp( + SafeClamp(delay_ms - system_delay_ms, delay_min, delay_max); + const int expected_median_high = SafeClamp( expected_median + rtc::dchecked_cast(96 / samples_per_ms), delay_min, delay_max); - const int expected_median_low = rtc::SafeClamp( + const int expected_median_low = SafeClamp( expected_median - rtc::dchecked_cast(96 / samples_per_ms), delay_min, delay_max); // Verify delay metrics. diff --git a/modules/audio_processing/capture_levels_adjuster/audio_samples_scaler.cc b/modules/audio_processing/capture_levels_adjuster/audio_samples_scaler.cc index cb2336b87d..e770b14b48 100644 --- a/modules/audio_processing/capture_levels_adjuster/audio_samples_scaler.cc +++ b/modules/audio_processing/capture_levels_adjuster/audio_samples_scaler.cc @@ -84,7 +84,7 @@ void AudioSamplesScaler::Process(AudioBuffer& audio_buffer) { for (float& sample : channel_view) { constexpr float kMinFloatS16Value = -32768.f; constexpr float kMaxFloatS16Value = 32767.f; - sample = rtc::SafeClamp(sample, kMinFloatS16Value, kMaxFloatS16Value); + sample = SafeClamp(sample, kMinFloatS16Value, kMaxFloatS16Value); } } } diff --git a/modules/audio_processing/capture_levels_adjuster/capture_levels_adjuster.cc b/modules/audio_processing/capture_levels_adjuster/capture_levels_adjuster.cc index dfda582915..f65aae8923 100644 --- a/modules/audio_processing/capture_levels_adjuster/capture_levels_adjuster.cc +++ b/modules/audio_processing/capture_levels_adjuster/capture_levels_adjuster.cc @@ -80,7 +80,7 @@ void CaptureLevelsAdjuster::SetAnalogMicGainLevel(int level) { RTC_DCHECK_GE(level, kMinAnalogMicGainLevel); RTC_DCHECK_LE(level, kMaxAnalogMicGainLevel); int clamped_level = - rtc::SafeClamp(level, kMinAnalogMicGainLevel, kMaxAnalogMicGainLevel); + SafeClamp(level, kMinAnalogMicGainLevel, kMaxAnalogMicGainLevel); emulated_analog_mic_gain_level_ = clamped_level; UpdatePreAdjustmentGain(); diff --git a/modules/audio_processing/test/fake_recording_device.cc b/modules/audio_processing/test/fake_recording_device.cc index 58853b4066..f5aa7a4fa5 100644 --- a/modules/audio_processing/test/fake_recording_device.cc +++ b/modules/audio_processing/test/fake_recording_device.cc @@ -87,8 +87,8 @@ class FakeRecordingDeviceLinear final : public FakeRecordingDeviceWorker { for (size_t c = 0; c < buffer->num_channels(); ++c) { for (size_t i = 0; i < buffer->num_frames(); ++i) { buffer->channels()[c][i] = - rtc::SafeClamp(buffer->channels()[c][i] * mic_level_ / divisor, - kFloatSampleMin, kFloatSampleMax); + SafeClamp(buffer->channels()[c][i] * mic_level_ / divisor, + kFloatSampleMin, kFloatSampleMax); } } } @@ -125,8 +125,8 @@ class FakeRecordingDeviceAgc final : public FakeRecordingDeviceWorker { for (size_t c = 0; c < buffer->num_channels(); ++c) { for (size_t i = 0; i < buffer->num_frames(); ++i) { buffer->channels()[c][i] = - rtc::SafeClamp(buffer->channels()[c][i] * scaling_factor, - kFloatSampleMin, kFloatSampleMax); + SafeClamp(buffer->channels()[c][i] * scaling_factor, + kFloatSampleMin, kFloatSampleMax); } } } diff --git a/modules/congestion_controller/goog_cc/trendline_estimator.cc b/modules/congestion_controller/goog_cc/trendline_estimator.cc index 66730a2f96..2f8835a3cd 100644 --- a/modules/congestion_controller/goog_cc/trendline_estimator.cc +++ b/modules/congestion_controller/goog_cc/trendline_estimator.cc @@ -325,7 +325,7 @@ void TrendlineEstimator::UpdateThreshold(double modified_trend, const int64_t kMaxTimeDeltaMs = 100; int64_t time_delta_ms = std::min(now_ms - last_update_ms_, kMaxTimeDeltaMs); threshold_ += k * (fabs(modified_trend) - threshold_) * time_delta_ms; - threshold_ = rtc::SafeClamp(threshold_, 6.f, 600.f); + threshold_ = SafeClamp(threshold_, 6.f, 600.f); last_update_ms_ = now_ms; } diff --git a/modules/remote_bitrate_estimator/overuse_detector.cc b/modules/remote_bitrate_estimator/overuse_detector.cc index 9ee56b8108..75f7ed6059 100644 --- a/modules/remote_bitrate_estimator/overuse_detector.cc +++ b/modules/remote_bitrate_estimator/overuse_detector.cc @@ -93,7 +93,7 @@ void OveruseDetector::UpdateThreshold(double modified_offset, int64_t now_ms) { const int64_t kMaxTimeDeltaMs = 100; int64_t time_delta_ms = std::min(now_ms - last_update_ms_, kMaxTimeDeltaMs); threshold_ += k * (fabs(modified_offset) - threshold_) * time_delta_ms; - threshold_ = rtc::SafeClamp(threshold_, 6.f, 600.f); + threshold_ = SafeClamp(threshold_, 6.f, 600.f); last_update_ms_ = now_ms; } diff --git a/modules/rtp_rtcp/source/rtp_sender.cc b/modules/rtp_rtcp/source/rtp_sender.cc index 7739631edd..61dd81530b 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -420,15 +420,15 @@ std::vector> RTPSender::GeneratePadding( max_packet_size_ - max_padding_fec_packet_header_; if (audio_configured_) { // Allow smaller padding packets for audio. - padding_bytes_in_packet = rtc::SafeClamp( - bytes_left, kMinAudioPaddingLength, - rtc::SafeMin(max_payload_size, kMaxPaddingLength)); + padding_bytes_in_packet = + SafeClamp(bytes_left, kMinAudioPaddingLength, + SafeMin(max_payload_size, kMaxPaddingLength)); } else { // Always send full padding packets. This is accounted for by the // RtpPacketSender, which will make sure we don't send too much padding even // if a single packet is larger than requested. // We do this to avoid frequently sending small packets on higher bitrates. - padding_bytes_in_packet = rtc::SafeMin(max_payload_size, kMaxPaddingLength); + padding_bytes_in_packet = SafeMin(max_payload_size, kMaxPaddingLength); } while (bytes_left > 0) { diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index 7a10154730..2a7006e79e 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc @@ -983,7 +983,7 @@ void Connection::UpdateState(int64_t now) { return; // Computes our estimate of the RTT given the current estimate. - int rtt = rtc::SafeClamp(2 * rtt_, MINIMUM_RTT, MAXIMUM_RTT); + int rtt = webrtc::SafeClamp(2 * rtt_, MINIMUM_RTT, MAXIMUM_RTT); if (RTC_LOG_CHECK_LEVEL(LS_VERBOSE)) { std::string pings; diff --git a/p2p/base/pseudo_tcp.cc b/p2p/base/pseudo_tcp.cc index 3aaa2ad065..cc2122229f 100644 --- a/p2p/base/pseudo_tcp.cc +++ b/p2p/base/pseudo_tcp.cc @@ -713,8 +713,8 @@ bool PseudoTcp::process(Segment& seg) { m_rx_rttvar = (3 * m_rx_rttvar + abs_err) / 4; m_rx_srtt = (7 * m_rx_srtt + rtt) / 8; } - m_rx_rto = rtc::SafeClamp(m_rx_srtt + rtc::SafeMax(1, 4 * m_rx_rttvar), - MIN_RTO, MAX_RTO); + m_rx_rto = webrtc::SafeClamp( + m_rx_srtt + webrtc::SafeMax(1, 4 * m_rx_rttvar), MIN_RTO, MAX_RTO); #if _DEBUGMSG >= _DBG_VERBOSE RTC_LOG(LS_INFO) << "rtt: " << rtt << " srtt: " << m_rx_srtt << " rto: " << m_rx_rto; diff --git a/pc/jitter_buffer_delay.cc b/pc/jitter_buffer_delay.cc index a747588c68..5b9ab79520 100644 --- a/pc/jitter_buffer_delay.cc +++ b/pc/jitter_buffer_delay.cc @@ -29,10 +29,9 @@ void JitterBufferDelay::Set(std::optional delay_seconds) { int JitterBufferDelay::GetMs() const { RTC_DCHECK_RUN_ON(&worker_thread_checker_); - return rtc::SafeClamp( - rtc::saturated_cast(cached_delay_seconds_.value_or(kDefaultDelay) * - 1000), - 0, kMaximumDelayMs); + return SafeClamp(rtc::saturated_cast( + cached_delay_seconds_.value_or(kDefaultDelay) * 1000), + 0, kMaximumDelayMs); } } // namespace webrtc diff --git a/rtc_base/numerics/safe_minmax.h b/rtc_base/numerics/safe_minmax.h index cdb6da2909..045d48cc8a 100644 --- a/rtc_base/numerics/safe_minmax.h +++ b/rtc_base/numerics/safe_minmax.h @@ -84,7 +84,7 @@ #include "rtc_base/numerics/safe_compare.h" #include "rtc_base/type_traits.h" -namespace rtc { +namespace webrtc { namespace safe_minmax_impl { @@ -331,6 +331,14 @@ R2 SafeClamp(T x, L min, H max) { : static_cast(x); } +} // namespace webrtc + +// Re-export symbols from the webrtc namespace for backwards compatibility. +// TODO(bugs.webrtc.org/4222596): Remove once all references are updated. +namespace rtc { +using ::webrtc::SafeClamp; +using ::webrtc::SafeMax; +using ::webrtc::SafeMin; } // namespace rtc #endif // RTC_BASE_NUMERICS_SAFE_MINMAX_H_ diff --git a/rtc_base/numerics/safe_minmax_unittest.cc b/rtc_base/numerics/safe_minmax_unittest.cc index 2aa0221149..e267077310 100644 --- a/rtc_base/numerics/safe_minmax_unittest.cc +++ b/rtc_base/numerics/safe_minmax_unittest.cc @@ -17,7 +17,7 @@ #include "test/gtest.h" -namespace rtc { +namespace webrtc { namespace { @@ -344,4 +344,4 @@ uint32_t TestClampSafe(uint32_t x, uint32_t a, uint32_t b) { return SafeClamp(x, a, b); } -} // namespace rtc +} // namespace webrtc diff --git a/rtc_base/strings/string_builder.cc b/rtc_base/strings/string_builder.cc index 86e71efab3..f9c1302213 100644 --- a/rtc_base/strings/string_builder.cc +++ b/rtc_base/strings/string_builder.cc @@ -34,8 +34,7 @@ SimpleStringBuilder& SimpleStringBuilder::operator<<(char ch) { SimpleStringBuilder& SimpleStringBuilder::operator<<(absl::string_view str) { RTC_DCHECK_LT(size_ + str.length(), buffer_.size()) << "Buffer size was insufficient"; - const size_t chars_added = - rtc::SafeMin(str.length(), buffer_.size() - size_ - 1); + const size_t chars_added = SafeMin(str.length(), buffer_.size() - size_ - 1); memcpy(&buffer_[size_], str.data(), chars_added); size_ += chars_added; buffer_[size_] = '\0'; @@ -97,7 +96,7 @@ SimpleStringBuilder& SimpleStringBuilder::AppendFormat(const char* fmt, ...) { const int len = std::vsnprintf(&buffer_[size_], buffer_.size() - size_, fmt, args); if (len >= 0) { - const size_t chars_added = rtc::SafeMin(len, buffer_.size() - 1 - size_); + const size_t chars_added = SafeMin(len, buffer_.size() - 1 - size_); size_ += chars_added; RTC_DCHECK_EQ(len, chars_added) << "Buffer size was insufficient"; } else { diff --git a/test/network/cross_traffic.cc b/test/network/cross_traffic.cc index 4f16cfdf28..6f1b6f4ff1 100644 --- a/test/network/cross_traffic.cc +++ b/test/network/cross_traffic.cc @@ -56,7 +56,7 @@ void RandomWalkCrossTraffic::Process(Timestamp at_time) { if (at_time - last_update_time_ >= config_.update_interval) { intensity_ += random_.Gaussian(config_.bias, config_.variance) * sqrt((at_time - last_update_time_).seconds()); - intensity_ = rtc::SafeClamp(intensity_, 0.0, 1.0); + intensity_ = SafeClamp(intensity_, 0.0, 1.0); last_update_time_ = at_time; } pending_size_ += TrafficRate() * delta; diff --git a/video/corruption_detection/halton_frame_sampler.cc b/video/corruption_detection/halton_frame_sampler.cc index 643bde0132..d49d10a5df 100644 --- a/video/corruption_detection/halton_frame_sampler.cc +++ b/video/corruption_detection/halton_frame_sampler.cc @@ -137,7 +137,7 @@ double GetFilteredElement(int width, } // Take the rounding errors into consideration. - return rtc::SafeClamp(element_sum / total_weight, 0.0, 255.0); + return SafeClamp(element_sum / total_weight, 0.0, 255.0); } std::vector GetSampleValuesForFrame(