From 352444fcace861c0b0e2b1654187f5244e1be1f4 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Mon, 28 Nov 2016 15:58:53 -0800 Subject: [PATCH] RTC_[D]CHECK_op: Remove superfluous casts There's no longer any need to make the two arguments have the same signedness, so we can remove a bunch of superfluous (and sometimes dangerous) casts. It turned out I also had to fix the safe_cmp functions to properly handle enums that are implicitly convertible to integers. NOPRESUBMIT=true BUG=webrtc:6645 Review-Url: https://codereview.webrtc.org/2534683002 Cr-Commit-Position: refs/heads/master@{#15281} --- webrtc/audio/audio_transport_proxy.cc | 7 +- webrtc/base/checks.h | 3 +- webrtc/base/file_posix.cc | 2 +- webrtc/base/random_unittest.cc | 2 +- webrtc/base/safe_compare.h | 91 +++++++++++++++---- webrtc/base/safe_compare_unittest.cc | 15 +++ webrtc/base/stringutils.cc | 4 +- webrtc/base/task_queue_win.cc | 2 +- webrtc/common_types.cc | 10 +- .../codecs/cng/audio_encoder_cng.cc | 2 +- .../audio_coding/codecs/cng/webrtc_cng.cc | 2 +- .../audio_coding/neteq/dtmf_tone_generator.cc | 10 +- webrtc/modules/audio_coding/neteq/normal.cc | 2 +- .../audio_device/android/audio_track_jni.cc | 2 +- .../modules/audio_device/fine_audio_buffer.cc | 2 +- .../modules/audio_processing/aec/aec_core.cc | 7 +- .../level_controller/down_sampler.cc | 9 +- .../level_controller/signal_classifier.cc | 2 +- .../vad/voice_activity_detector.cc | 2 +- .../source/forward_error_correction.cc | 2 +- webrtc/modules/rtp_rtcp/source/rtcp_sender.cc | 12 +-- .../codecs/h264/h264_encoder_impl.cc | 4 +- .../video_coding/codecs/vp8/vp8_impl.cc | 4 +- .../video_coding/codecs/vp9/vp9_impl.cc | 4 +- .../video_coding/video_codec_initializer.cc | 2 +- webrtc/pc/mediasession.cc | 2 +- webrtc/test/fake_network_pipe_unittest.cc | 2 +- webrtc/test/layer_filtering_transport.cc | 2 +- webrtc/test/rtcp_packet_parser.h | 2 +- webrtc/video/video_quality_test.cc | 2 +- 30 files changed, 140 insertions(+), 74 deletions(-) diff --git a/webrtc/audio/audio_transport_proxy.cc b/webrtc/audio/audio_transport_proxy.cc index 7036c1059c..c201d8a490 100644 --- a/webrtc/audio/audio_transport_proxy.cc +++ b/webrtc/audio/audio_transport_proxy.cc @@ -110,14 +110,13 @@ void AudioTransportProxy::PullRenderData(int bits_per_sample, void* audio_data, int64_t* elapsed_time_ms, int64_t* ntp_time_ms) { - RTC_DCHECK_EQ(static_cast(bits_per_sample), 16); + RTC_DCHECK_EQ(bits_per_sample, 16); RTC_DCHECK_GE(number_of_channels, 1); RTC_DCHECK_LE(number_of_channels, 2); - RTC_DCHECK_GE(static_cast(sample_rate), - AudioProcessing::NativeRate::kSampleRate8kHz); + RTC_DCHECK_GE(sample_rate, AudioProcessing::NativeRate::kSampleRate8kHz); // 100 = 1 second / data duration (10 ms). - RTC_DCHECK_EQ(static_cast(number_of_frames * 100), sample_rate); + RTC_DCHECK_EQ(number_of_frames * 100, sample_rate); // 8 = bits per byte. RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, diff --git a/webrtc/base/checks.h b/webrtc/base/checks.h index 653ed322e7..e165741b85 100644 --- a/webrtc/base/checks.h +++ b/webrtc/base/checks.h @@ -246,8 +246,7 @@ class FatalMessage { // remainder is zero. template inline T CheckedDivExact(T a, T b) { - RTC_CHECK_EQ(a % b, static_cast(0)) << a << " is not evenly divisible by " - << b; + RTC_CHECK_EQ(a % b, 0) << a << " is not evenly divisible by " << b; return a / b; } diff --git a/webrtc/base/file_posix.cc b/webrtc/base/file_posix.cc index 9c166ec1a2..c386a34f77 100644 --- a/webrtc/base/file_posix.cc +++ b/webrtc/base/file_posix.cc @@ -81,7 +81,7 @@ size_t File::ReadAt(uint8_t* buffer, size_t length, size_t offset) { } bool File::Seek(size_t offset) { - RTC_DCHECK_LE(offset, static_cast(std::numeric_limits::max())); + RTC_DCHECK_LE(offset, std::numeric_limits::max()); return lseek(file_, static_cast(offset), SEEK_SET) != -1; } diff --git a/webrtc/base/random_unittest.cc b/webrtc/base/random_unittest.cc index 0d9041fa80..704e81fb2f 100644 --- a/webrtc/base/random_unittest.cc +++ b/webrtc/base/random_unittest.cc @@ -23,7 +23,7 @@ namespace { // Computes the positive remainder of x/n. template T fdiv_remainder(T x, T n) { - RTC_CHECK_GE(n, static_cast(0)); + RTC_CHECK_GE(n, 0); T remainder = x % n; if (remainder < 0) remainder += n; diff --git a/webrtc/base/safe_compare.h b/webrtc/base/safe_compare.h index 37ddf780c7..39fb917a70 100644 --- a/webrtc/base/safe_compare.h +++ b/webrtc/base/safe_compare.h @@ -145,26 +145,81 @@ RTC_SAFECMP_MAKE_OP(GtOp, >) RTC_SAFECMP_MAKE_OP(GeOp, >=) #undef RTC_SAFECMP_MAKE_OP +// Determines if the given type is an enum that converts implicitly to +// an integral type. +template +struct IsIntEnum { + private: + // This overload is used if the type is an enum, and unary plus + // compiles and turns it into an integral type. + template ::value && + std::is_integral())>::value>::type* = + nullptr> + static int Test(int); + + // Otherwise, this overload is used. + template + static char Test(...); + + public: + static constexpr bool value = + std::is_same::type>(0)), + int>::value; +}; + +// Determines if the given type is integral, or an enum that +// converts implicitly to an integral type. +template +struct IsIntlike { + private: + using X = typename std::remove_reference::type; + + public: + static constexpr bool value = + std::is_integral::value || IsIntEnum::value; +}; + +namespace test_enum_intlike { + +enum E1 { e1 }; +enum { e2 }; +enum class E3 { e3 }; +struct S {}; + +static_assert(IsIntEnum::value, ""); +static_assert(IsIntEnum::value, ""); +static_assert(!IsIntEnum::value, ""); +static_assert(!IsIntEnum::value, ""); +static_assert(!IsIntEnum::value, ""); +static_assert(!IsIntEnum::value, ""); + +static_assert(IsIntlike::value, ""); +static_assert(IsIntlike::value, ""); +static_assert(!IsIntlike::value, ""); +static_assert(IsIntlike::value, ""); +static_assert(!IsIntlike::value, ""); +static_assert(!IsIntlike::value, ""); + +} // test_enum_intlike } // namespace safe_cmp_impl -#define RTC_SAFECMP_MAKE_FUN(name) \ - template < \ - typename T1, typename T2, \ - typename std::enable_if< \ - std::is_integral::type>::value && \ - std::is_integral::type>::value>:: \ - type* = nullptr> \ - inline bool name(T1 a, T2 b) { \ - return safe_cmp_impl::Cmp(a, b); \ - } \ - template ::type>::value || \ - !std::is_integral::type>:: \ - value>::type* = nullptr> \ - inline bool name(T1&& a, T2&& b) { \ - return safe_cmp_impl::name##Op::Op(a, b); \ +#define RTC_SAFECMP_MAKE_FUN(name) \ + template ::value && \ + safe_cmp_impl::IsIntlike::value>::type* = nullptr> \ + inline bool name(T1 a, T2 b) { \ + /* Unary plus here turns enums into real integral types. */ \ + return safe_cmp_impl::Cmp(+a, +b); \ + } \ + template ::value || \ + !safe_cmp_impl::IsIntlike::value>::type* = nullptr> \ + inline bool name(T1&& a, T2&& b) { \ + return safe_cmp_impl::name##Op::Op(a, b); \ } RTC_SAFECMP_MAKE_FUN(Eq) RTC_SAFECMP_MAKE_FUN(Ne) diff --git a/webrtc/base/safe_compare_unittest.cc b/webrtc/base/safe_compare_unittest.cc index 12ab4696ef..f52c7eedcc 100644 --- a/webrtc/base/safe_compare_unittest.cc +++ b/webrtc/base/safe_compare_unittest.cc @@ -376,4 +376,19 @@ TEST(SafeCmpTest, Ge) { EXPECT_TRUE(safe_cmp::Ge(p2, p2)); } +TEST(SafeCmpTest, Enum) { + enum E1 { e1 = 13 }; + enum { e2 = 13 }; + enum E3 : unsigned { e3 = 13 }; + enum : unsigned { e4 = 13 }; + EXPECT_TRUE(safe_cmp::Eq(13, e1)); + EXPECT_TRUE(safe_cmp::Eq(13u, e1)); + EXPECT_TRUE(safe_cmp::Eq(13, e2)); + EXPECT_TRUE(safe_cmp::Eq(13u, e2)); + EXPECT_TRUE(safe_cmp::Eq(13, e3)); + EXPECT_TRUE(safe_cmp::Eq(13u, e3)); + EXPECT_TRUE(safe_cmp::Eq(13, e4)); + EXPECT_TRUE(safe_cmp::Eq(13u, e4)); +} + } // namespace rtc diff --git a/webrtc/base/stringutils.cc b/webrtc/base/stringutils.cc index 48830e4233..eca1362163 100644 --- a/webrtc/base/stringutils.cc +++ b/webrtc/base/stringutils.cc @@ -57,7 +57,7 @@ int ascii_string_compare(const wchar_t* s1, const char* s2, size_t n, if (n-- == 0) return 0; c1 = transformation(*s1); // Double check that characters are not UTF-8 - RTC_DCHECK_LT(static_cast(*s2), 128); + RTC_DCHECK_LT(*s2, 128); // Note: *s2 gets implicitly promoted to wchar_t c2 = transformation(*s2); if (c1 != c2) return (c1 < c2) ? -1 : 1; @@ -80,7 +80,7 @@ size_t asccpyn(wchar_t* buffer, size_t buflen, #if RTC_DCHECK_IS_ON // Double check that characters are not UTF-8 for (size_t pos = 0; pos < srclen; ++pos) - RTC_DCHECK_LT(static_cast(source[pos]), 128); + RTC_DCHECK_LT(source[pos], 128); #endif std::copy(source, source + srclen, buffer); buffer[srclen] = 0; diff --git a/webrtc/base/task_queue_win.cc b/webrtc/base/task_queue_win.cc index 6d7ca4e6df..81b1cd1b9f 100644 --- a/webrtc/base/task_queue_win.cc +++ b/webrtc/base/task_queue_win.cc @@ -61,7 +61,7 @@ TaskQueue::TaskQueue(const char* queue_name) TaskQueue::~TaskQueue() { RTC_DCHECK(!IsCurrent()); while (!PostThreadMessage(thread_.GetThreadRef(), WM_QUIT, 0, 0)) { - RTC_CHECK_EQ(static_cast(ERROR_NOT_ENOUGH_QUOTA), ::GetLastError()); + RTC_CHECK_EQ(ERROR_NOT_ENOUGH_QUOTA, ::GetLastError()); Sleep(1); } thread_.Stop(); diff --git a/webrtc/common_types.cc b/webrtc/common_types.cc index 2cbad4711d..aa76768465 100644 --- a/webrtc/common_types.cc +++ b/webrtc/common_types.cc @@ -154,8 +154,8 @@ BitrateAllocation::BitrateAllocation() : sum_(0), bitrates_{} {} bool BitrateAllocation::SetBitrate(size_t spatial_index, size_t temporal_index, uint32_t bitrate_bps) { - RTC_DCHECK_LT(spatial_index, static_cast(kMaxSpatialLayers)); - RTC_DCHECK_LT(temporal_index, static_cast(kMaxTemporalStreams)); + RTC_DCHECK_LT(spatial_index, kMaxSpatialLayers); + RTC_DCHECK_LT(temporal_index, kMaxTemporalStreams); RTC_DCHECK_LE(bitrates_[spatial_index][temporal_index], sum_); uint64_t new_bitrate_sum_bps = sum_; new_bitrate_sum_bps -= bitrates_[spatial_index][temporal_index]; @@ -170,14 +170,14 @@ bool BitrateAllocation::SetBitrate(size_t spatial_index, uint32_t BitrateAllocation::GetBitrate(size_t spatial_index, size_t temporal_index) const { - RTC_DCHECK_LT(spatial_index, static_cast(kMaxSpatialLayers)); - RTC_DCHECK_LT(temporal_index, static_cast(kMaxTemporalStreams)); + RTC_DCHECK_LT(spatial_index, kMaxSpatialLayers); + RTC_DCHECK_LT(temporal_index, kMaxTemporalStreams); return bitrates_[spatial_index][temporal_index]; } // Get the sum of all the temporal layer for a specific spatial layer. uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const { - RTC_DCHECK_LT(spatial_index, static_cast(kMaxSpatialLayers)); + RTC_DCHECK_LT(spatial_index, kMaxSpatialLayers); uint32_t sum = 0; for (int i = 0; i < kMaxTemporalStreams; ++i) sum += bitrates_[spatial_index][i]; diff --git a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc index b1629410fc..fe1b9de683 100644 --- a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc +++ b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc @@ -98,7 +98,7 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeImpl( if (rtp_timestamps_.size() < frames_to_encode) { return EncodedInfo(); } - RTC_CHECK_LE(static_cast(frames_to_encode * 10), kMaxFrameSizeMs) + RTC_CHECK_LE(frames_to_encode * 10, kMaxFrameSizeMs) << "Frame size cannot be larger than " << kMaxFrameSizeMs << " ms when using VAD/CNG."; diff --git a/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.cc b/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.cc index 4c28f89c9e..886b5fc325 100644 --- a/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.cc +++ b/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.cc @@ -260,7 +260,7 @@ size_t ComfortNoiseEncoder::Encode(rtc::ArrayView speech, int16_t speechBuf[kCngMaxOutsizeOrder]; const size_t num_samples = speech.size(); - RTC_CHECK_LE(num_samples, static_cast(kCngMaxOutsizeOrder)); + RTC_CHECK_LE(num_samples, kCngMaxOutsizeOrder); for (i = 0; i < num_samples; i++) { speechBuf[i] = speech[i]; diff --git a/webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc b/webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc index 947bf6dbaa..2079d2ebeb 100644 --- a/webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc +++ b/webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc @@ -138,14 +138,14 @@ int DtmfToneGenerator::Init(int fs, int event, int attenuation) { RTC_DCHECK_GT(arraysize(kCoeff1), fs_index); RTC_DCHECK_GT(arraysize(kCoeff2), fs_index); RTC_DCHECK_LE(0, event); - RTC_DCHECK_GT(arraysize(kCoeff1[fs_index]), static_cast(event)); - RTC_DCHECK_GT(arraysize(kCoeff2[fs_index]), static_cast(event)); + RTC_DCHECK_GT(arraysize(kCoeff1[fs_index]), event); + RTC_DCHECK_GT(arraysize(kCoeff2[fs_index]), event); coeff1_ = kCoeff1[fs_index][event]; coeff2_ = kCoeff2[fs_index][event]; // Look up amplitude multiplier. RTC_DCHECK_LE(0, attenuation); - RTC_DCHECK_GT(arraysize(kAmplitude), static_cast(attenuation)); + RTC_DCHECK_GT(arraysize(kAmplitude), attenuation); amplitude_ = kAmplitude[attenuation]; // Initialize sample history. @@ -153,8 +153,8 @@ int DtmfToneGenerator::Init(int fs, int event, int attenuation) { RTC_DCHECK_GT(arraysize(kInitValue1), fs_index); RTC_DCHECK_GT(arraysize(kInitValue2), fs_index); RTC_DCHECK_LE(0, event); - RTC_DCHECK_GT(arraysize(kInitValue1[fs_index]), static_cast(event)); - RTC_DCHECK_GT(arraysize(kInitValue2[fs_index]), static_cast(event)); + RTC_DCHECK_GT(arraysize(kInitValue1[fs_index]), event); + RTC_DCHECK_GT(arraysize(kInitValue2[fs_index]), event); sample_history1_[0] = kInitValue1[fs_index][event]; sample_history1_[1] = 0; sample_history2_[0] = kInitValue2[fs_index][event]; diff --git a/webrtc/modules/audio_coding/neteq/normal.cc b/webrtc/modules/audio_coding/neteq/normal.cc index 95272c77c6..48e1e930d2 100644 --- a/webrtc/modules/audio_coding/neteq/normal.cc +++ b/webrtc/modules/audio_coding/neteq/normal.cc @@ -152,7 +152,7 @@ int Normal::Process(const int16_t* input, } else if (last_mode == kModeRfc3389Cng) { RTC_DCHECK_EQ(output->Channels(), 1); // Not adapted for multi-channel yet. static const size_t kCngLength = 48; - RTC_DCHECK_LE(static_cast(8 * fs_mult), kCngLength); + RTC_DCHECK_LE(8 * fs_mult, kCngLength); int16_t cng_output[kCngLength]; // Reset mute factor and start up fresh. external_mute_factor_array[0] = 16384; diff --git a/webrtc/modules/audio_device/android/audio_track_jni.cc b/webrtc/modules/audio_device/android/audio_track_jni.cc index 7072c25aa8..72e056f368 100644 --- a/webrtc/modules/audio_device/android/audio_track_jni.cc +++ b/webrtc/modules/audio_device/android/audio_track_jni.cc @@ -255,7 +255,7 @@ void AudioTrackJni::OnGetPlayoutData(size_t length) { ALOGE("AudioDeviceBuffer::RequestPlayoutData failed!"); return; } - RTC_DCHECK_EQ(static_cast(samples), frames_per_buffer_); + RTC_DCHECK_EQ(samples, frames_per_buffer_); // Copy decoded data into common byte buffer to ensure that it can be // written to the Java based audio track. samples = audio_device_buffer_->GetPlayoutData(direct_buffer_address_); diff --git a/webrtc/modules/audio_device/fine_audio_buffer.cc b/webrtc/modules/audio_device/fine_audio_buffer.cc index 7fffdd14fb..c0ee15e663 100644 --- a/webrtc/modules/audio_device/fine_audio_buffer.cc +++ b/webrtc/modules/audio_device/fine_audio_buffer.cc @@ -106,7 +106,7 @@ void FineAudioBuffer::GetPlayoutData(int8_t* buffer) { // If playout_cached_bytes_ is larger than the cache buffer, uninitialized // memory will be read. RTC_CHECK_LE(playout_cached_bytes_, bytes_per_10_ms_); - RTC_CHECK_EQ(static_cast(-bytes_left), playout_cached_bytes_); + RTC_CHECK_EQ(-bytes_left, playout_cached_bytes_); playout_cached_buffer_start_ = 0; memcpy(playout_cache_buffer_.get(), cache_ptr, playout_cached_bytes_); } diff --git a/webrtc/modules/audio_processing/aec/aec_core.cc b/webrtc/modules/audio_processing/aec/aec_core.cc index b410c55507..814c38b4ba 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.cc +++ b/webrtc/modules/audio_processing/aec/aec_core.cc @@ -1744,7 +1744,7 @@ void FormNearendBlock( const float nearend_buffer[NUM_HIGH_BANDS_MAX + 1] [PART_LEN - (FRAME_LEN - PART_LEN)], float nearend_block[NUM_HIGH_BANDS_MAX + 1][PART_LEN]) { - RTC_DCHECK_LE(num_samples_from_nearend_frame, static_cast(PART_LEN)); + RTC_DCHECK_LE(num_samples_from_nearend_frame, PART_LEN); const int num_samples_from_buffer = PART_LEN - num_samples_from_nearend_frame; if (num_samples_from_buffer > 0) { @@ -1795,15 +1795,14 @@ void FormOutputFrame(size_t output_start_index, size_t* output_buffer_size, float output_buffer[NUM_HIGH_BANDS_MAX + 1][2 * PART_LEN], float* const* output_frame) { - RTC_DCHECK_LE(static_cast(FRAME_LEN), *output_buffer_size); + RTC_DCHECK_LE(FRAME_LEN, *output_buffer_size); for (size_t i = 0; i < num_bands; ++i) { memcpy(&output_frame[i][output_start_index], &output_buffer[i][0], FRAME_LEN * sizeof(float)); } (*output_buffer_size) -= FRAME_LEN; if (*output_buffer_size > 0) { - RTC_DCHECK_GE(static_cast(2 * PART_LEN - FRAME_LEN), - (*output_buffer_size)); + RTC_DCHECK_GE(2 * PART_LEN - FRAME_LEN, (*output_buffer_size)); for (size_t i = 0; i < num_bands; ++i) { memcpy(&output_buffer[i][0], &output_buffer[i][FRAME_LEN], (*output_buffer_size) * sizeof(float)); diff --git a/webrtc/modules/audio_processing/level_controller/down_sampler.cc b/webrtc/modules/audio_processing/level_controller/down_sampler.cc index e1be7edabc..f4a08ee346 100644 --- a/webrtc/modules/audio_processing/level_controller/down_sampler.cc +++ b/webrtc/modules/audio_processing/level_controller/down_sampler.cc @@ -69,12 +69,11 @@ void DownSampler::Initialize(int sample_rate_hz) { void DownSampler::DownSample(rtc::ArrayView in, rtc::ArrayView out) { data_dumper_->DumpWav("lc_down_sampler_input", in, sample_rate_hz_, 1); - RTC_DCHECK_EQ(static_cast(sample_rate_hz_ * - AudioProcessing::kChunkSizeMs / 1000), + RTC_DCHECK_EQ(sample_rate_hz_ * AudioProcessing::kChunkSizeMs / 1000, in.size()); - RTC_DCHECK_EQ(static_cast(AudioProcessing::kSampleRate8kHz * - AudioProcessing::kChunkSizeMs / 1000), - out.size()); + RTC_DCHECK_EQ( + AudioProcessing::kSampleRate8kHz * AudioProcessing::kChunkSizeMs / 1000, + out.size()); const size_t kMaxNumFrames = AudioProcessing::kSampleRate48kHz * AudioProcessing::kChunkSizeMs / 1000; float x[kMaxNumFrames]; diff --git a/webrtc/modules/audio_processing/level_controller/signal_classifier.cc b/webrtc/modules/audio_processing/level_controller/signal_classifier.cc index f38dfb2e13..59cdc34c18 100644 --- a/webrtc/modules/audio_processing/level_controller/signal_classifier.cc +++ b/webrtc/modules/audio_processing/level_controller/signal_classifier.cc @@ -129,7 +129,7 @@ void SignalClassifier::Initialize(int sample_rate_hz) { void SignalClassifier::Analyze(const AudioBuffer& audio, SignalType* signal_type) { - RTC_DCHECK_EQ(audio.num_frames(), static_cast(sample_rate_hz_ / 100)); + RTC_DCHECK_EQ(audio.num_frames(), sample_rate_hz_ / 100); // Compute the signal power spectrum. float downsampled_frame[80]; diff --git a/webrtc/modules/audio_processing/vad/voice_activity_detector.cc b/webrtc/modules/audio_processing/vad/voice_activity_detector.cc index 7b495f4231..6aa58adaa6 100644 --- a/webrtc/modules/audio_processing/vad/voice_activity_detector.cc +++ b/webrtc/modules/audio_processing/vad/voice_activity_detector.cc @@ -39,7 +39,7 @@ VoiceActivityDetector::~VoiceActivityDetector() = default; void VoiceActivityDetector::ProcessChunk(const int16_t* audio, size_t length, int sample_rate_hz) { - RTC_DCHECK_EQ(static_cast(length), sample_rate_hz / 100); + RTC_DCHECK_EQ(length, sample_rate_hz / 100); RTC_DCHECK_LE(length, kMaxLength); // Resample to the required rate. const int16_t* resampled_ptr = audio; diff --git a/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc b/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc index 7a3b1583d8..8c35f4000f 100644 --- a/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc +++ b/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc @@ -105,7 +105,7 @@ int ForwardErrorCorrection::EncodeFec(const PacketList& media_packets, // Sanity check arguments. RTC_DCHECK_GT(num_media_packets, 0); RTC_DCHECK_GE(num_important_packets, 0); - RTC_DCHECK_LE(static_cast(num_important_packets), num_media_packets); + RTC_DCHECK_LE(num_important_packets, num_media_packets); RTC_DCHECK(fec_packets->empty()); const size_t max_media_packets = fec_header_writer_->MaxMediaPackets(); if (num_media_packets > max_media_packets) { diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc index e6cf669522..2f4d393b83 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc @@ -103,7 +103,7 @@ class PacketContainer : public rtcp::CompoundPacket, } size_t SendPackets(size_t max_payload_length) { - RTC_DCHECK_LE(max_payload_length, static_cast(IP_PACKET_SIZE)); + RTC_DCHECK_LE(max_payload_length, IP_PACKET_SIZE); uint8_t buffer[IP_PACKET_SIZE]; BuildExternalBuffer(buffer, max_payload_length, this); return bytes_sent_; @@ -325,7 +325,7 @@ int32_t RTCPSender::SetCNAME(const char* c_name) { if (!c_name) return -1; - RTC_DCHECK_LT(strlen(c_name), static_cast(RTCP_CNAME_SIZE)); + RTC_DCHECK_LT(strlen(c_name), RTCP_CNAME_SIZE); rtc::CritScope lock(&critical_section_rtcp_sender_); cname_ = c_name; return 0; @@ -333,7 +333,7 @@ int32_t RTCPSender::SetCNAME(const char* c_name) { int32_t RTCPSender::AddMixedCNAME(uint32_t SSRC, const char* c_name) { RTC_DCHECK(c_name); - RTC_DCHECK_LT(strlen(c_name), static_cast(RTCP_CNAME_SIZE)); + RTC_DCHECK_LT(strlen(c_name), RTCP_CNAME_SIZE); rtc::CritScope lock(&critical_section_rtcp_sender_); if (csrc_cnames_.size() >= kRtpCsrcSize) return -1; @@ -466,7 +466,7 @@ std::unique_ptr RTCPSender::BuildSR(const RtcpContext& ctx) { std::unique_ptr RTCPSender::BuildSDES( const RtcpContext& ctx) { size_t length_cname = cname_.length(); - RTC_CHECK_LT(length_cname, static_cast(RTCP_CNAME_SIZE)); + RTC_CHECK_LT(length_cname, RTCP_CNAME_SIZE); rtcp::Sdes* sdes = new rtcp::Sdes(); sdes->AddCName(ssrc_, cname_); @@ -933,7 +933,7 @@ bool RTCPSender::AddReportBlock(const FeedbackState& feedback_state, } void RTCPSender::SetCsrcs(const std::vector& csrcs) { - RTC_DCHECK_LE(csrcs.size(), static_cast(kRtpCsrcSize)); + RTC_DCHECK_LE(csrcs.size(), kRtpCsrcSize); rtc::CritScope lock(&critical_section_rtcp_sender_); csrcs_ = csrcs; } @@ -1037,7 +1037,7 @@ bool RTCPSender::SendFeedbackPacket(const rtcp::TransportFeedback& packet) { // but we can't because of an incorrect warning (C4822) in MVS 2013. } sender(transport_, event_log_); - RTC_DCHECK_LE(max_payload_length_, static_cast(IP_PACKET_SIZE)); + RTC_DCHECK_LE(max_payload_length_, IP_PACKET_SIZE); uint8_t buffer[IP_PACKET_SIZE]; return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && !sender.send_failure_; diff --git a/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc b/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc index 6012f073ca..5332a3c2e0 100644 --- a/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc +++ b/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc @@ -95,7 +95,7 @@ static void RtpFragmentize(EncodedImage* encoded_image, for (int nal = 0; nal < layerInfo.iNalCount; ++nal, ++fragments_count) { RTC_CHECK_GE(layerInfo.pNalLengthInByte[nal], 0); // Ensure |required_size| will not overflow. - RTC_CHECK_LE(static_cast(layerInfo.pNalLengthInByte[nal]), + RTC_CHECK_LE(layerInfo.pNalLengthInByte[nal], std::numeric_limits::max() - required_size); required_size += layerInfo.pNalLengthInByte[nal]; } @@ -326,7 +326,7 @@ int32_t H264EncoderImpl::Encode(const VideoFrame& input_frame, bool force_key_frame = false; if (frame_types != nullptr) { // We only support a single stream. - RTC_DCHECK_EQ(frame_types->size(), static_cast(1)); + RTC_DCHECK_EQ(frame_types->size(), 1); // Skip frame? if ((*frame_types)[0] == kEmptyFrame) { return WEBRTC_VIDEO_CODEC_OK; diff --git a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc index c045100abc..148140eccf 100644 --- a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc +++ b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc @@ -697,8 +697,8 @@ int VP8EncoderImpl::Encode(const VideoFrame& frame, // |raw_images_[0]|, the resolution of these frames must match. Note that // |input_image| might be scaled from |frame|. In that case, the resolution of // |raw_images_[0]| should have been updated in UpdateCodecFrameSize. - RTC_DCHECK_EQ(input_image->width(), static_cast(raw_images_[0].d_w)); - RTC_DCHECK_EQ(input_image->height(), static_cast(raw_images_[0].d_h)); + RTC_DCHECK_EQ(input_image->width(), raw_images_[0].d_w); + RTC_DCHECK_EQ(input_image->height(), raw_images_[0].d_h); // Image in vpx_image_t format. // Input image is const. VP8's raw image is not defined as const. diff --git a/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc b/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc index 97f745b50b..bfb5606e2c 100644 --- a/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -497,8 +497,8 @@ int VP9EncoderImpl::Encode(const VideoFrame& input_image, if (frame_types && frame_types->size() > 0) { frame_type = (*frame_types)[0]; } - RTC_DCHECK_EQ(input_image.width(), static_cast(raw_->d_w)); - RTC_DCHECK_EQ(input_image.height(), static_cast(raw_->d_h)); + RTC_DCHECK_EQ(input_image.width(), raw_->d_w); + RTC_DCHECK_EQ(input_image.height(), raw_->d_h); // Set input image for use in the callback. // This was necessary since you need some information from input_image. diff --git a/webrtc/modules/video_coding/video_codec_initializer.cc b/webrtc/modules/video_coding/video_codec_initializer.cc index c6db91619b..dbdede07ad 100644 --- a/webrtc/modules/video_coding/video_codec_initializer.cc +++ b/webrtc/modules/video_coding/video_codec_initializer.cc @@ -164,7 +164,7 @@ VideoCodec VideoCodecInitializer::VideoEncoderConfigToVideoCodec( video_codec.minBitrate = streams[0].min_bitrate_bps / 1000; if (video_codec.minBitrate < kEncoderMinBitrateKbps) video_codec.minBitrate = kEncoderMinBitrateKbps; - RTC_DCHECK_LE(streams.size(), static_cast(kMaxSimulcastStreams)); + RTC_DCHECK_LE(streams.size(), kMaxSimulcastStreams); if (video_codec.codecType == kVideoCodecVP9) { // If the vector is empty, bitrates will be configured automatically. RTC_DCHECK(config.spatial_layers.empty() || diff --git a/webrtc/pc/mediasession.cc b/webrtc/pc/mediasession.cc index abeeeab09c..fda38dfdff 100644 --- a/webrtc/pc/mediasession.cc +++ b/webrtc/pc/mediasession.cc @@ -118,7 +118,7 @@ static bool CreateCryptoParams(int tag, const std::string& cipher, return false; } - RTC_CHECK_EQ(static_cast(master_key_len), master_key.size()); + RTC_CHECK_EQ(master_key_len, master_key.size()); std::string key = rtc::Base64::Encode(master_key); out->tag = tag; diff --git a/webrtc/test/fake_network_pipe_unittest.cc b/webrtc/test/fake_network_pipe_unittest.cc index 7374bb1405..6e635e1559 100644 --- a/webrtc/test/fake_network_pipe_unittest.cc +++ b/webrtc/test/fake_network_pipe_unittest.cc @@ -70,7 +70,7 @@ class FakeNetworkPipeTest : public ::testing::Test { } void SendPackets(FakeNetworkPipe* pipe, int number_packets, int packet_size) { - RTC_DCHECK_GE(packet_size, static_cast(sizeof(int))); + RTC_DCHECK_GE(packet_size, sizeof(int)); std::unique_ptr packet(new uint8_t[packet_size]); for (int i = 0; i < number_packets; ++i) { // Set a sequence number for the packets by diff --git a/webrtc/test/layer_filtering_transport.cc b/webrtc/test/layer_filtering_transport.cc index cba1a57eb4..26805539b9 100644 --- a/webrtc/test/layer_filtering_transport.cc +++ b/webrtc/test/layer_filtering_transport.cc @@ -51,7 +51,7 @@ bool LayerFilteringTransport::SendRtp(const uint8_t* packet, RTPHeader header; parser.Parse(&header); - RTC_DCHECK_LE(length, static_cast(IP_PACKET_SIZE)); + RTC_DCHECK_LE(length, IP_PACKET_SIZE); uint8_t temp_buffer[IP_PACKET_SIZE]; memcpy(temp_buffer, packet, length); diff --git a/webrtc/test/rtcp_packet_parser.h b/webrtc/test/rtcp_packet_parser.h index 163ea41317..ef1fab823d 100644 --- a/webrtc/test/rtcp_packet_parser.h +++ b/webrtc/test/rtcp_packet_parser.h @@ -41,7 +41,7 @@ template bool ParseSinglePacket(const uint8_t* buffer, size_t size, Packet* packet) { rtcp::CommonHeader header; RTC_CHECK(header.Parse(buffer, size)); - RTC_CHECK_EQ(static_cast(size), header.NextPacket() - buffer); + RTC_CHECK_EQ(size, header.NextPacket() - buffer); return packet->Parse(header); } // Same function, but takes raw buffer as single argument instead of pair. diff --git a/webrtc/video/video_quality_test.cc b/webrtc/video/video_quality_test.cc index 8f5cb367e2..d72b60c790 100644 --- a/webrtc/video/video_quality_test.cc +++ b/webrtc/video/video_quality_test.cc @@ -877,7 +877,7 @@ void VideoQualityTest::CheckParams() { RTC_CHECK_GE(stream.min_bitrate_bps, 0); RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps); RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps); - RTC_CHECK_EQ(static_cast(stream.temporal_layer_thresholds_bps.size()), + RTC_CHECK_EQ(stream.temporal_layer_thresholds_bps.size(), params_.video.num_temporal_layers - 1); } // TODO(ivica): Should we check if the sum of all streams/layers is equal to