From c95b93966734b44962f2479006b85375d0556c98 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Sun, 8 Nov 2020 00:49:37 +0100 Subject: [PATCH] Introduce RTC_CHECK_NOTREACHED(), an always-checking RTC_NOTREACHED() And use it in a few places that were using RTC_CHECK(false) or FATAL() to do the exact same job. There should be no change in behavior. Bug: none Change-Id: I36d5e6bcf35fd41534e08a8c879fa0811b4f1967 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191963 Reviewed-by: Mirko Bonadei Commit-Queue: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#32567} --- api/adaptation/resource.cc | 2 +- api/audio_codecs/ilbc/audio_encoder_ilbc.cc | 2 +- api/media_types.cc | 2 +- api/rtp_parameters.cc | 2 +- api/test/dummy_peer_connection.h | 28 ++++--- api/video_codecs/video_codec.cc | 2 +- ...video_encoder_software_fallback_wrapper.cc | 4 +- call/adaptation/video_stream_adapter.cc | 8 +- call/simulated_network.cc | 2 +- call/video_send_stream.cc | 2 +- common_audio/wav_header.cc | 6 +- media/base/rtp_utils.cc | 2 +- .../codecs/ilbc/audio_encoder_ilbc.cc | 4 +- .../android/audio_device_template.h | 47 ++++-------- .../audio_device/android/audio_record_jni.cc | 3 +- .../agc2/adaptive_mode_level_estimator.cc | 2 +- .../audio_processing/audio_processing_impl.cc | 4 +- .../include/audio_processing.cc | 6 +- .../test/aec_dump_based_simulator.cc | 3 +- .../test/audio_processing_simulator.cc | 4 +- .../test/debug_dump_replayer.cc | 3 +- modules/audio_processing/test/test_utils.cc | 3 +- .../test/wav_based_simulator.cc | 2 +- modules/pacing/pacing_controller.cc | 2 +- .../source/create_video_rtp_depacketizer.cc | 2 +- modules/rtp_rtcp/source/rtp_sender.cc | 2 +- modules/rtp_rtcp/source/rtp_sender_audio.cc | 2 +- .../codecs/vp8/temporal_layers_checker.cc | 2 +- pc/dtls_transport.cc | 2 +- pc/media_session.cc | 8 +- pc/peer_connection.cc | 2 +- pc/peer_connection_factory.cc | 4 +- pc/rtc_stats_collector.cc | 2 +- pc/rtp_parameters_conversion.cc | 2 +- rtc_base/checks.cc | 73 ++++++++++++------- rtc_base/checks.h | 24 ++++++ rtc_base/network_monitor.cc | 2 +- rtc_base/numerics/safe_conversions.h | 6 +- rtc_base/openssl_certificate.cc | 18 +---- rtc_tools/sanitizers_unittest.cc | 2 +- .../jni/audio_device/audio_device_module.cc | 45 ++++-------- .../video_stream_encoder_resource_manager.cc | 2 +- 42 files changed, 168 insertions(+), 177 deletions(-) diff --git a/api/adaptation/resource.cc b/api/adaptation/resource.cc index c6a7e327b3..dac03fe019 100644 --- a/api/adaptation/resource.cc +++ b/api/adaptation/resource.cc @@ -21,7 +21,7 @@ const char* ResourceUsageStateToString(ResourceUsageState usage_state) { case ResourceUsageState::kUnderuse: return "kUnderuse"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } ResourceListener::~ResourceListener() {} diff --git a/api/audio_codecs/ilbc/audio_encoder_ilbc.cc b/api/audio_codecs/ilbc/audio_encoder_ilbc.cc index bd653b7979..035b0dc34f 100644 --- a/api/audio_codecs/ilbc/audio_encoder_ilbc.cc +++ b/api/audio_codecs/ilbc/audio_encoder_ilbc.cc @@ -32,7 +32,7 @@ int GetIlbcBitrate(int ptime) { // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. return 13333; default: - FATAL(); + RTC_CHECK_NOTREACHED(); } } } // namespace diff --git a/api/media_types.cc b/api/media_types.cc index 4ab80edbf9..3453ce3905 100644 --- a/api/media_types.cc +++ b/api/media_types.cc @@ -31,7 +31,7 @@ std::string MediaTypeToString(MediaType type) { RTC_NOTREACHED(); return ""; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } } // namespace cricket diff --git a/api/rtp_parameters.cc b/api/rtp_parameters.cc index f22ed67402..92f99e9bb8 100644 --- a/api/rtp_parameters.cc +++ b/api/rtp_parameters.cc @@ -30,7 +30,7 @@ const char* DegradationPreferenceToString( case DegradationPreference::BALANCED: return "balanced"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } const double kDefaultBitratePriority = 1.0; diff --git a/api/test/dummy_peer_connection.h b/api/test/dummy_peer_connection.h index 0ca7d3f1b4..4d17aeddd0 100644 --- a/api/test/dummy_peer_connection.h +++ b/api/test/dummy_peer_connection.h @@ -36,7 +36,7 @@ class DummyPeerConnection : public PeerConnectionInterface { bool AddStream(MediaStreamInterface* stream) override { return false; } void RemoveStream(MediaStreamInterface* stream) override { - FATAL() << "Not implemented"; + RTC_CHECK_NOTREACHED(); } RTCErrorOr> AddTrack( @@ -100,17 +100,17 @@ class DummyPeerConnection : public PeerConnectionInterface { } void GetStats(RTCStatsCollectorCallback* callback) override { - FATAL() << "Not implemented"; + RTC_CHECK_NOTREACHED(); } void GetStats( rtc::scoped_refptr selector, rtc::scoped_refptr callback) override { - FATAL() << "Not implemented"; + RTC_CHECK_NOTREACHED(); } void GetStats( rtc::scoped_refptr selector, rtc::scoped_refptr callback) override { - FATAL() << "Not implemented"; + RTC_CHECK_NOTREACHED(); } void ClearStatsCache() override {} @@ -145,33 +145,33 @@ class DummyPeerConnection : public PeerConnectionInterface { return nullptr; } - void RestartIce() override { FATAL() << "Not implemented"; } + void RestartIce() override { RTC_CHECK_NOTREACHED(); } // Create a new offer. // The CreateSessionDescriptionObserver callback will be called when done. void CreateOffer(CreateSessionDescriptionObserver* observer, const RTCOfferAnswerOptions& options) override { - FATAL() << "Not implemented"; + RTC_CHECK_NOTREACHED(); } void CreateAnswer(CreateSessionDescriptionObserver* observer, const RTCOfferAnswerOptions& options) override { - FATAL() << "Not implemented"; + RTC_CHECK_NOTREACHED(); } void SetLocalDescription(SetSessionDescriptionObserver* observer, SessionDescriptionInterface* desc) override { - FATAL() << "Not implemented"; + RTC_CHECK_NOTREACHED(); } void SetRemoteDescription(SetSessionDescriptionObserver* observer, SessionDescriptionInterface* desc) override { - FATAL() << "Not implemented"; + RTC_CHECK_NOTREACHED(); } void SetRemoteDescription( std::unique_ptr desc, rtc::scoped_refptr observer) override { - FATAL() << "Not implemented"; + RTC_CHECK_NOTREACHED(); } PeerConnectionInterface::RTCConfiguration GetConfiguration() override { @@ -194,10 +194,8 @@ class DummyPeerConnection : public PeerConnectionInterface { return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); } - void SetAudioPlayout(bool playout) override { FATAL() << "Not implemented"; } - void SetAudioRecording(bool recording) override { - FATAL() << "Not implemented"; - } + void SetAudioPlayout(bool playout) override { RTC_CHECK_NOTREACHED(); } + void SetAudioRecording(bool recording) override { RTC_CHECK_NOTREACHED(); } rtc::scoped_refptr LookupDtlsTransportByMid( const std::string& mid) override { @@ -235,7 +233,7 @@ class DummyPeerConnection : public PeerConnectionInterface { return false; } - void StopRtcEventLog() { FATAL() << "Not implemented"; } + void StopRtcEventLog() { RTC_CHECK_NOTREACHED(); } void Close() override {} diff --git a/api/video_codecs/video_codec.cc b/api/video_codecs/video_codec.cc index ecc569978b..d05eb456fc 100644 --- a/api/video_codecs/video_codec.cc +++ b/api/video_codecs/video_codec.cc @@ -120,7 +120,7 @@ const char* CodecTypeToPayloadString(VideoCodecType type) { case kVideoCodecGeneric: return kPayloadNameGeneric; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } VideoCodecType PayloadStringToCodecType(const std::string& name) { diff --git a/api/video_codecs/video_encoder_software_fallback_wrapper.cc b/api/video_codecs/video_encoder_software_fallback_wrapper.cc index bb97d3087b..95a41d0e30 100644 --- a/api/video_codecs/video_encoder_software_fallback_wrapper.cc +++ b/api/video_codecs/video_encoder_software_fallback_wrapper.cc @@ -162,7 +162,7 @@ class VideoEncoderSoftwareFallbackWrapper final : public VideoEncoder { case EncoderState::kForcedFallback: return fallback_encoder_.get(); } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } // Updates encoder with last observed parameters, such as callbacks, rates, @@ -346,7 +346,7 @@ int32_t VideoEncoderSoftwareFallbackWrapper::Encode( case EncoderState::kForcedFallback: return fallback_encoder_->Encode(frame, frame_types); } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } int32_t VideoEncoderSoftwareFallbackWrapper::EncodeWithMainEncoder( diff --git a/call/adaptation/video_stream_adapter.cc b/call/adaptation/video_stream_adapter.cc index b79d217e3f..4fc4743a32 100644 --- a/call/adaptation/video_stream_adapter.cc +++ b/call/adaptation/video_stream_adapter.cc @@ -162,7 +162,7 @@ const char* Adaptation::StatusToString(Adaptation::Status status) { case Status::kRejectedByConstraint: return "kRejectedByConstraint"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } Adaptation::Adaptation(int validation_id, @@ -382,7 +382,7 @@ VideoStreamAdapter::RestrictionsOrState VideoStreamAdapter::GetAdaptationUpStep( case DegradationPreference::DISABLED: return Adaptation::Status::kAdaptationDisabled; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } Adaptation VideoStreamAdapter::GetAdaptationDown() { @@ -462,7 +462,7 @@ VideoStreamAdapter::GetAdaptationDownStep( case DegradationPreference::DISABLED: return Adaptation::Status::kAdaptationDisabled; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } VideoStreamAdapter::RestrictionsOrState VideoStreamAdapter::DecreaseResolution( @@ -601,7 +601,7 @@ Adaptation VideoStreamAdapter::GetAdaptDownResolution() { GetAdaptDownResolutionStepForBalanced(input_state), input_state); } } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } VideoStreamAdapter::RestrictionsOrState diff --git a/call/simulated_network.cc b/call/simulated_network.cc index 86e27122fe..f8a5bd893d 100644 --- a/call/simulated_network.cc +++ b/call/simulated_network.cc @@ -77,7 +77,7 @@ bool CoDelSimulation::DropDequeuedPacket(Timestamp now, } return false; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } SimulatedNetwork::SimulatedNetwork(Config config, uint64_t random_seed) diff --git a/call/video_send_stream.cc b/call/video_send_stream.cc index d3e36949a9..244d78089c 100644 --- a/call/video_send_stream.cc +++ b/call/video_send_stream.cc @@ -28,7 +28,7 @@ const char* StreamTypeToString(VideoSendStream::StreamStats::StreamType type) { case VideoSendStream::StreamStats::StreamType::kFlexfec: return "flexfec"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } } // namespace diff --git a/common_audio/wav_header.cc b/common_audio/wav_header.cc index d3dca9055d..ce119f1095 100644 --- a/common_audio/wav_header.cc +++ b/common_audio/wav_header.cc @@ -132,7 +132,7 @@ uint16_t MapWavFormatToHeaderField(WavFormat format) { case WavFormat::kWavFormatMuLaw: return 7; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } WavFormat MapHeaderFieldToWavFormat(uint16_t format_header_value) { @@ -278,10 +278,8 @@ size_t GetFormatBytesPerSample(WavFormat format) { return 1; case WavFormat::kWavFormatIeeeFloat: return 4; - default: - RTC_CHECK(false); - return 2; } + RTC_CHECK_NOTREACHED(); } bool CheckWavParameters(size_t num_channels, diff --git a/media/base/rtp_utils.cc b/media/base/rtp_utils.cc index 0d18c1e9e8..4714175226 100644 --- a/media/base/rtp_utils.cc +++ b/media/base/rtp_utils.cc @@ -323,7 +323,7 @@ absl::string_view RtpPacketTypeToString(RtpPacketType packet_type) { case RtpPacketType::kUnknown: return "Unknown"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } RtpPacketType InferRtpPacketType(rtc::ArrayView packet) { diff --git a/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc b/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc index 032de20246..9fbf42ceeb 100644 --- a/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc +++ b/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc @@ -34,7 +34,7 @@ int GetIlbcBitrate(int ptime) { // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. return 13333; default: - FATAL(); + RTC_CHECK_NOTREACHED(); } } @@ -144,7 +144,7 @@ size_t AudioEncoderIlbcImpl::RequiredOutputSizeBytes() const { case 6: return 2 * 50; default: - FATAL(); + RTC_CHECK_NOTREACHED(); } } diff --git a/modules/audio_device/android/audio_device_template.h b/modules/audio_device/android/audio_device_template.h index a2185047e5..fb5bf6fa59 100644 --- a/modules/audio_device/android/audio_device_template.h +++ b/modules/audio_device/android/audio_device_template.h @@ -103,15 +103,13 @@ class AudioDeviceTemplate : public AudioDeviceGeneric { int32_t PlayoutDeviceName(uint16_t index, char name[kAdmMaxDeviceNameSize], char guid[kAdmMaxGuidSize]) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t RecordingDeviceName(uint16_t index, char name[kAdmMaxDeviceNameSize], char guid[kAdmMaxGuidSize]) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t SetPlayoutDevice(uint16_t index) override { @@ -123,8 +121,7 @@ class AudioDeviceTemplate : public AudioDeviceGeneric { int32_t SetPlayoutDevice( AudioDeviceModule::WindowsDeviceType device) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t SetRecordingDevice(uint16_t index) override { @@ -136,8 +133,7 @@ class AudioDeviceTemplate : public AudioDeviceGeneric { int32_t SetRecordingDevice( AudioDeviceModule::WindowsDeviceType device) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t PlayoutIsAvailable(bool& available) override { @@ -266,53 +262,38 @@ class AudioDeviceTemplate : public AudioDeviceGeneric { } int32_t SetMicrophoneVolume(uint32_t volume) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t MicrophoneVolume(uint32_t& volume) const override { - FATAL() << "Should never be called"; + RTC_CHECK_NOTREACHED(); return -1; } int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t MinMicrophoneVolume(uint32_t& minVolume) const override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t SpeakerMuteIsAvailable(bool& available) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } - int32_t SetSpeakerMute(bool enable) override { - FATAL() << "Should never be called"; - return -1; - } + int32_t SetSpeakerMute(bool enable) override { RTC_CHECK_NOTREACHED(); } - int32_t SpeakerMute(bool& enabled) const override { - FATAL() << "Should never be called"; - return -1; - } + int32_t SpeakerMute(bool& enabled) const override { RTC_CHECK_NOTREACHED(); } int32_t MicrophoneMuteIsAvailable(bool& available) override { - FATAL() << "Not implemented"; - return -1; + RTC_CHECK_NOTREACHED(); } - int32_t SetMicrophoneMute(bool enable) override { - FATAL() << "Not implemented"; - return -1; - } + int32_t SetMicrophoneMute(bool enable) override { RTC_CHECK_NOTREACHED(); } int32_t MicrophoneMute(bool& enabled) const override { - FATAL() << "Not implemented"; - return -1; + RTC_CHECK_NOTREACHED(); } // Returns true if the audio manager has been configured to support stereo diff --git a/modules/audio_device/android/audio_record_jni.cc b/modules/audio_device/android/audio_record_jni.cc index 12ac45876c..a3aa85565a 100644 --- a/modules/audio_device/android/audio_record_jni.cc +++ b/modules/audio_device/android/audio_record_jni.cc @@ -219,8 +219,7 @@ int32_t AudioRecordJni::EnableBuiltInAEC(bool enable) { int32_t AudioRecordJni::EnableBuiltInAGC(bool enable) { // TODO(henrika): possibly remove when no longer used by any client. - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t AudioRecordJni::EnableBuiltInNS(bool enable) { diff --git a/modules/audio_processing/agc2/adaptive_mode_level_estimator.cc b/modules/audio_processing/agc2/adaptive_mode_level_estimator.cc index 2d9c3e1f8f..739997f5e3 100644 --- a/modules/audio_processing/agc2/adaptive_mode_level_estimator.cc +++ b/modules/audio_processing/agc2/adaptive_mode_level_estimator.cc @@ -42,7 +42,7 @@ float GetLevel(const VadLevelAnalyzer::Result& vad_level, return vad_level.peak_dbfs; break; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } } // namespace diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc index 9cf1e1d7b5..56d7073ae6 100644 --- a/modules/audio_processing/audio_processing_impl.cc +++ b/modules/audio_processing/audio_processing_impl.cc @@ -114,7 +114,7 @@ GainControl::Mode Agc1ConfigModeToInterfaceMode( case Agc1Config::kFixedDigital: return GainControl::kFixedDigital; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } // Maximum lengths that frame of samples being passed from the render side to @@ -1830,7 +1830,7 @@ void AudioProcessingImpl::InitializeNoiseSuppressor() { case NoiseSuppresionConfig::kVeryHigh: return NsConfig::SuppressionLevel::k21dB; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); }; NsConfig cfg; diff --git a/modules/audio_processing/include/audio_processing.cc b/modules/audio_processing/include/audio_processing.cc index 105364270e..04336b6113 100644 --- a/modules/audio_processing/include/audio_processing.cc +++ b/modules/audio_processing/include/audio_processing.cc @@ -31,7 +31,7 @@ std::string NoiseSuppressionLevelToString( case AudioProcessing::Config::NoiseSuppression::Level::kVeryHigh: return "VeryHigh"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } std::string GainController1ModeToString(const Agc1Config::Mode& mode) { @@ -43,7 +43,7 @@ std::string GainController1ModeToString(const Agc1Config::Mode& mode) { case Agc1Config::Mode::kFixedDigital: return "FixedDigital"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } std::string GainController2LevelEstimatorToString( @@ -54,7 +54,7 @@ std::string GainController2LevelEstimatorToString( case Agc2Config::LevelEstimator::kPeak: return "Peak"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } int GetDefaultMaxInternalRate() { diff --git a/modules/audio_processing/test/aec_dump_based_simulator.cc b/modules/audio_processing/test/aec_dump_based_simulator.cc index 0e914320e3..c3014d8e0b 100644 --- a/modules/audio_processing/test/aec_dump_based_simulator.cc +++ b/modules/audio_processing/test/aec_dump_based_simulator.cc @@ -269,8 +269,7 @@ void AecDumpBasedSimulator::HandleEvent( HandleMessage(event_msg.runtime_setting()); break; case webrtc::audioproc::Event::UNKNOWN_EVENT: - RTC_CHECK(false); - break; + RTC_CHECK_NOTREACHED(); } } diff --git a/modules/audio_processing/test/audio_processing_simulator.cc b/modules/audio_processing/test/audio_processing_simulator.cc index adbc298e9e..403c6ee649 100644 --- a/modules/audio_processing/test/audio_processing_simulator.cc +++ b/modules/audio_processing/test/audio_processing_simulator.cc @@ -40,7 +40,7 @@ EchoCanceller3Config ReadAec3ConfigFromJsonFile(const std::string& filename) { std::ifstream f(filename.c_str()); if (f.fail()) { std::cout << "Failed to open the file " << filename << std::endl; - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } while (std::getline(f, s)) { json_string += s; @@ -52,7 +52,7 @@ EchoCanceller3Config ReadAec3ConfigFromJsonFile(const std::string& filename) { if (!parsing_successful) { std::cout << "Parsing of json string failed: " << std::endl << json_string << std::endl; - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } RTC_CHECK(EchoCanceller3Config::Validate(&cfg)); diff --git a/modules/audio_processing/test/debug_dump_replayer.cc b/modules/audio_processing/test/debug_dump_replayer.cc index b8cccd126c..754b42d281 100644 --- a/modules/audio_processing/test/debug_dump_replayer.cc +++ b/modules/audio_processing/test/debug_dump_replayer.cc @@ -80,8 +80,7 @@ bool DebugDumpReplayer::RunNextEvent() { break; case audioproc::Event::UNKNOWN_EVENT: // We do not expect to receive UNKNOWN event. - RTC_CHECK(false); - return false; + RTC_CHECK_NOTREACHED(); } LoadNextMessage(); return true; diff --git a/modules/audio_processing/test/test_utils.cc b/modules/audio_processing/test/test_utils.cc index 37a20cee1e..839358d497 100644 --- a/modules/audio_processing/test/test_utils.cc +++ b/modules/audio_processing/test/test_utils.cc @@ -146,8 +146,7 @@ AudioProcessing::ChannelLayout LayoutFromChannels(size_t num_channels) { case 2: return AudioProcessing::kStereo; default: - RTC_CHECK(false); - return AudioProcessing::kMono; + RTC_CHECK_NOTREACHED(); } } diff --git a/modules/audio_processing/test/wav_based_simulator.cc b/modules/audio_processing/test/wav_based_simulator.cc index 75946fb3fa..8536bf13be 100644 --- a/modules/audio_processing/test/wav_based_simulator.cc +++ b/modules/audio_processing/test/wav_based_simulator.cc @@ -118,7 +118,7 @@ void WavBasedSimulator::Process() { } break; default: - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } call_chain_index = (call_chain_index + 1) % call_chain_.size(); diff --git a/modules/pacing/pacing_controller.cc b/modules/pacing/pacing_controller.cc index bef0d2f93d..5ffbc903b3 100644 --- a/modules/pacing/pacing_controller.cc +++ b/modules/pacing/pacing_controller.cc @@ -84,7 +84,7 @@ int GetPriorityForType(RtpPacketMediaType type) { // BWE high. return kFirstPriority + 4; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } } // namespace diff --git a/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc b/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc index b44322baa5..f1e4eddb4b 100644 --- a/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc +++ b/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc @@ -37,7 +37,7 @@ std::unique_ptr CreateVideoRtpDepacketizer( case kVideoCodecMultiplex: return std::make_unique(); } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } } // namespace webrtc diff --git a/modules/rtp_rtcp/source/rtp_sender.cc b/modules/rtp_rtcp/source/rtp_sender.cc index 3d1b381675..584fced397 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -128,7 +128,7 @@ bool IsNonVolatile(RTPExtensionType type) { RTC_NOTREACHED(); return false; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } bool HasBweExtension(const RtpHeaderExtensionMap& extensions_map) { diff --git a/modules/rtp_rtcp/source/rtp_sender_audio.cc b/modules/rtp_rtcp/source/rtp_sender_audio.cc index 16a1130334..8cf60aaecd 100644 --- a/modules/rtp_rtcp/source/rtp_sender_audio.cc +++ b/modules/rtp_rtcp/source/rtp_sender_audio.cc @@ -46,7 +46,7 @@ const char* FrameTypeToString(AudioFrameType frame_type) { case AudioFrameType::kAudioFrameCN: return "audio_cn"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } #endif diff --git a/modules/video_coding/codecs/vp8/temporal_layers_checker.cc b/modules/video_coding/codecs/vp8/temporal_layers_checker.cc index 540cfa354a..5aebd2c526 100644 --- a/modules/video_coding/codecs/vp8/temporal_layers_checker.cc +++ b/modules/video_coding/codecs/vp8/temporal_layers_checker.cc @@ -29,7 +29,7 @@ TemporalLayersChecker::CreateTemporalLayersChecker(Vp8TemporalLayersType type, // Conference mode temporal layering for screen content in base stream. return std::make_unique(num_temporal_layers); } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } TemporalLayersChecker::TemporalLayersChecker(int num_temporal_layers) diff --git a/pc/dtls_transport.cc b/pc/dtls_transport.cc index 844063d00d..550ede790d 100644 --- a/pc/dtls_transport.cc +++ b/pc/dtls_transport.cc @@ -31,7 +31,7 @@ DtlsTransportState TranslateState(cricket::DtlsTransportState internal_state) { case cricket::DTLS_TRANSPORT_FAILED: return DtlsTransportState::kFailed; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } } // namespace diff --git a/pc/media_session.cc b/pc/media_session.cc index 6e9a7c147c..cbff21635e 100644 --- a/pc/media_session.cc +++ b/pc/media_session.cc @@ -1818,7 +1818,7 @@ const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForOffer( case RtpTransceiverDirection::kRecvOnly: return audio_recv_codecs_; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForAnswer( @@ -1837,7 +1837,7 @@ const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForAnswer( case RtpTransceiverDirection::kRecvOnly: return audio_recv_codecs_; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForOffer( @@ -1853,7 +1853,7 @@ const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForOffer( case RtpTransceiverDirection::kRecvOnly: return video_recv_codecs_; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForAnswer( @@ -1872,7 +1872,7 @@ const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForAnswer( case RtpTransceiverDirection::kRecvOnly: return video_recv_codecs_; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } void MergeCodecsFromDescription( diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 165968c11b..3760a01c9f 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -2408,7 +2408,7 @@ void PeerConnection::ReportBestConnectionState( GetIceCandidatePairCounter(local, remote), kIceCandidatePairMax); } else { - RTC_CHECK(0); + RTC_CHECK_NOTREACHED(); } // Increment the counter for IP type. diff --git a/pc/peer_connection_factory.cc b/pc/peer_connection_factory.cc index b8d9084679..da42e5a096 100644 --- a/pc/peer_connection_factory.cc +++ b/pc/peer_connection_factory.cc @@ -141,7 +141,7 @@ RtpCapabilities PeerConnectionFactory::GetRtpSenderCapabilities( case cricket::MEDIA_TYPE_UNSUPPORTED: return RtpCapabilities(); } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } RtpCapabilities PeerConnectionFactory::GetRtpReceiverCapabilities( @@ -167,7 +167,7 @@ RtpCapabilities PeerConnectionFactory::GetRtpReceiverCapabilities( case cricket::MEDIA_TYPE_UNSUPPORTED: return RtpCapabilities(); } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } rtc::scoped_refptr diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index 6f14e1eb40..5b21d33f89 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -216,7 +216,7 @@ const char* QualityLimitationReasonToRTCQualityLimitationReason( case QualityLimitationReason::kOther: return RTCQualityLimitationReason::kOther; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } double DoubleAudioLevelFromIntAudioLevel(int audio_level) { diff --git a/pc/rtp_parameters_conversion.cc b/pc/rtp_parameters_conversion.cc index 80e56b896f..68a948ea8e 100644 --- a/pc/rtp_parameters_conversion.cc +++ b/pc/rtp_parameters_conversion.cc @@ -76,7 +76,7 @@ RTCErrorOr ToCricketFeedbackParam( } return cricket::FeedbackParam(cricket::kRtcpFbParamTransportCc); } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } template diff --git a/rtc_base/checks.cc b/rtc_base/checks.cc index e5fc2ed416..239ea9f0da 100644 --- a/rtc_base/checks.cc +++ b/rtc_base/checks.cc @@ -36,6 +36,21 @@ #include "rtc_base/checks.h" namespace { + +RTC_NORETURN void WriteFatalLogAndAbort(const std::string& output) { + const char* output_c = output.c_str(); +#if defined(WEBRTC_ANDROID) + __android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n", output_c); +#endif + fflush(stdout); + fprintf(stderr, "%s", output_c); + fflush(stderr); +#if defined(WEBRTC_WIN) + DebugBreak(); +#endif + abort(); +} + #if defined(__GNUC__) __attribute__((__format__(__printf__, 2, 3))) #endif @@ -149,19 +164,7 @@ RTC_NORETURN void FatalLog(const char* file, va_end(args); - const char* output = s.c_str(); - -#if defined(WEBRTC_ANDROID) - __android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n", output); -#endif - - fflush(stdout); - fprintf(stderr, "%s", output); - fflush(stderr); -#if defined(WEBRTC_WIN) - DebugBreak(); -#endif - abort(); + WriteFatalLogAndAbort(s); } #else // RTC_CHECK_MSG_ENABLED RTC_NORETURN void FatalLog(const char* file, int line) { @@ -174,22 +177,40 @@ RTC_NORETURN void FatalLog(const char* file, int line) { "# Check failed.\n" "# ", file, line, LAST_SYSTEM_ERROR); - const char* output = s.c_str(); - -#if defined(WEBRTC_ANDROID) - __android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n", output); -#endif - - fflush(stdout); - fprintf(stderr, "%s", output); - fflush(stderr); -#if defined(WEBRTC_WIN) - DebugBreak(); -#endif - abort(); + WriteFatalLogAndAbort(s); } #endif // RTC_CHECK_MSG_ENABLED +#if RTC_DCHECK_IS_ON + +RTC_NORETURN void UnreachableCodeReached(const char* file, int line) { + std::string s; + AppendFormat(&s, + "\n\n" + "#\n" + "# Unreachable code reached: %s, line %d\n" + "# last system error: %u\n" + "# ", + file, line, LAST_SYSTEM_ERROR); + WriteFatalLogAndAbort(s); +} + +#else // !RTC_DCHECK_IS_ON + +RTC_NORETURN void UnreachableCodeReached() { + std::string s; + AppendFormat(&s, + "\n\n" + "#\n" + "# Unreachable code reached (file and line unknown)\n" + "# last system error: %u\n" + "# ", + LAST_SYSTEM_ERROR); + WriteFatalLogAndAbort(s); +} + +#endif // !RTC_DCHECK_IS_ON + } // namespace webrtc_checks_impl } // namespace rtc diff --git a/rtc_base/checks.h b/rtc_base/checks.h index 61c074ac82..508de2a577 100644 --- a/rtc_base/checks.h +++ b/rtc_base/checks.h @@ -338,6 +338,22 @@ class FatalLogCall final { const char* message_; }; +#if RTC_DCHECK_IS_ON + +// Be helpful, and include file and line in the RTC_CHECK_NOTREACHED error +// message. +#define RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS __FILE__, __LINE__ +RTC_NORETURN RTC_EXPORT void UnreachableCodeReached(const char* file, int line); + +#else + +// Be mindful of binary size, and don't include file and line in the +// RTC_CHECK_NOTREACHED error message. +#define RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS +RTC_NORETURN RTC_EXPORT void UnreachableCodeReached(); + +#endif + } // namespace webrtc_checks_impl // The actual stream used isn't important. We reference |ignored| in the code @@ -430,6 +446,14 @@ class FatalLogCall final { #define RTC_UNREACHABLE_CODE_HIT false #define RTC_NOTREACHED() RTC_DCHECK(RTC_UNREACHABLE_CODE_HIT) +// Kills the process with an error message. Never returns. Use when you wish to +// assert that a point in the code is never reached. +#define RTC_CHECK_NOTREACHED() \ + do { \ + ::rtc::webrtc_checks_impl::UnreachableCodeReached( \ + RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS); \ + } while (0) + // TODO(bugs.webrtc.org/8454): Add an RTC_ prefix or rename differently. #define FATAL() \ ::rtc::webrtc_checks_impl::FatalLogCall(__FILE__, __LINE__, \ diff --git a/rtc_base/network_monitor.cc b/rtc_base/network_monitor.cc index ba6b1b495a..70c2ad5020 100644 --- a/rtc_base/network_monitor.cc +++ b/rtc_base/network_monitor.cc @@ -21,7 +21,7 @@ const char* NetworkPreferenceToString(NetworkPreference preference) { case NetworkPreference::NOT_PREFERRED: return "NOT_PREFERRED"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } NetworkMonitorInterface::NetworkMonitorInterface() {} diff --git a/rtc_base/numerics/safe_conversions.h b/rtc_base/numerics/safe_conversions.h index 5d58672510..e00219cbd7 100644 --- a/rtc_base/numerics/safe_conversions.h +++ b/rtc_base/numerics/safe_conversions.h @@ -63,12 +63,10 @@ inline constexpr Dst saturated_cast(Src value) { // Should fail only on attempting to assign NaN to a saturated integer. case internal::TYPE_INVALID: - FATAL(); - return std::numeric_limits::max(); + RTC_CHECK_NOTREACHED(); } - FATAL(); - return static_cast(value); + RTC_CHECK_NOTREACHED(); } } // namespace rtc diff --git a/rtc_base/openssl_certificate.cc b/rtc_base/openssl_certificate.cc index 9459f76df6..bd9bb04fd4 100644 --- a/rtc_base/openssl_certificate.cc +++ b/rtc_base/openssl_certificate.cc @@ -244,13 +244,8 @@ std::unique_ptr OpenSSLCertificate::Clone() const { std::string OpenSSLCertificate::ToPEMString() const { BIO* bio = BIO_new(BIO_s_mem()); - if (!bio) { - FATAL() << "Unreachable code."; - } - if (!PEM_write_bio_X509(bio, x509_)) { - BIO_free(bio); - FATAL() << "Unreachable code."; - } + RTC_CHECK(bio); + RTC_CHECK(PEM_write_bio_X509(bio, x509_)); BIO_write(bio, "\0", 1); char* buffer; BIO_get_mem_data(bio, &buffer); @@ -264,13 +259,8 @@ void OpenSSLCertificate::ToDER(Buffer* der_buffer) const { der_buffer->SetSize(0); // Calculates the DER representation of the certificate, from scratch. BIO* bio = BIO_new(BIO_s_mem()); - if (!bio) { - FATAL() << "Unreachable code."; - } - if (!i2d_X509_bio(bio, x509_)) { - BIO_free(bio); - FATAL() << "Unreachable code."; - } + RTC_CHECK(bio); + RTC_CHECK(i2d_X509_bio(bio, x509_)); char* data = nullptr; size_t length = BIO_get_mem_data(bio, &data); der_buffer->SetData(data, length); diff --git a/rtc_tools/sanitizers_unittest.cc b/rtc_tools/sanitizers_unittest.cc index b997bf0c23..9606f42216 100644 --- a/rtc_tools/sanitizers_unittest.cc +++ b/rtc_tools/sanitizers_unittest.cc @@ -110,7 +110,7 @@ void DataRace() { thread2.Join(); // TSan seems to mess with gtest's death detection. // Fail intentionally, and rely on detecting the error message. - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } TEST(SanitizersDeathTest, ThreadSanitizer) { diff --git a/sdk/android/src/jni/audio_device/audio_device_module.cc b/sdk/android/src/jni/audio_device/audio_device_module.cc index d77488ff4a..eb5d93fa29 100644 --- a/sdk/android/src/jni/audio_device/audio_device_module.cc +++ b/sdk/android/src/jni/audio_device/audio_device_module.cc @@ -151,15 +151,13 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t PlayoutDeviceName(uint16_t index, char name[kAdmMaxDeviceNameSize], char guid[kAdmMaxGuidSize]) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t RecordingDeviceName(uint16_t index, char name[kAdmMaxDeviceNameSize], char guid[kAdmMaxGuidSize]) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t SetPlayoutDevice(uint16_t index) override { @@ -171,8 +169,7 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t SetPlayoutDevice( AudioDeviceModule::WindowsDeviceType device) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t SetRecordingDevice(uint16_t index) override { @@ -184,8 +181,7 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t SetRecordingDevice( AudioDeviceModule::WindowsDeviceType device) override { - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t PlayoutIsAvailable(bool* available) override { @@ -396,62 +392,52 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t SetMicrophoneVolume(uint32_t volume) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t MicrophoneVolume(uint32_t* volume) const override { RTC_LOG(INFO) << __FUNCTION__; - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override { RTC_LOG(INFO) << __FUNCTION__; - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t MinMicrophoneVolume(uint32_t* minVolume) const override { RTC_LOG(INFO) << __FUNCTION__; - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t SpeakerMuteIsAvailable(bool* available) override { RTC_LOG(INFO) << __FUNCTION__; - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t SetSpeakerMute(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t SpeakerMute(bool* enabled) const override { RTC_LOG(INFO) << __FUNCTION__; - FATAL() << "Should never be called"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t MicrophoneMuteIsAvailable(bool* available) override { RTC_LOG(INFO) << __FUNCTION__; - FATAL() << "Not implemented"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t SetMicrophoneMute(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - FATAL() << "Not implemented"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t MicrophoneMute(bool* enabled) const override { RTC_LOG(INFO) << __FUNCTION__; - FATAL() << "Not implemented"; - return -1; + RTC_CHECK_NOTREACHED(); } int32_t StereoPlayoutIsAvailable(bool* available) const override { @@ -569,8 +555,7 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t EnableBuiltInAGC(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - FATAL() << "HW AGC is not available"; - return -1; + RTC_CHECK_NOTREACHED(); } // TODO(henrika): add implementation for OpenSL ES based audio as well. diff --git a/video/adaptation/video_stream_encoder_resource_manager.cc b/video/adaptation/video_stream_encoder_resource_manager.cc index f7cf155cd8..c7ca4bccf1 100644 --- a/video/adaptation/video_stream_encoder_resource_manager.cc +++ b/video/adaptation/video_stream_encoder_resource_manager.cc @@ -55,7 +55,7 @@ std::string ToString(VideoAdaptationReason reason) { case VideoAdaptationReason::kCpu: return "cpu"; } - RTC_CHECK(false); + RTC_CHECK_NOTREACHED(); } } // namespace