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 <mbonadei@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32567}
diff --git a/api/adaptation/resource.cc b/api/adaptation/resource.cc
index c6a7e32..dac03fe 100644
--- a/api/adaptation/resource.cc
+++ b/api/adaptation/resource.cc
@@ -21,7 +21,7 @@
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 bd653b7..035b0dc 100644
--- a/api/audio_codecs/ilbc/audio_encoder_ilbc.cc
+++ b/api/audio_codecs/ilbc/audio_encoder_ilbc.cc
@@ -32,7 +32,7 @@
// 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 4ab80ed..3453ce3 100644
--- a/api/media_types.cc
+++ b/api/media_types.cc
@@ -31,7 +31,7 @@
RTC_NOTREACHED();
return "";
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
} // namespace cricket
diff --git a/api/rtp_parameters.cc b/api/rtp_parameters.cc
index f22ed67..92f99e9 100644
--- a/api/rtp_parameters.cc
+++ b/api/rtp_parameters.cc
@@ -30,7 +30,7 @@
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 0ca7d3f..4d17aed 100644
--- a/api/test/dummy_peer_connection.h
+++ b/api/test/dummy_peer_connection.h
@@ -36,7 +36,7 @@
bool AddStream(MediaStreamInterface* stream) override { return false; }
void RemoveStream(MediaStreamInterface* stream) override {
- FATAL() << "Not implemented";
+ RTC_CHECK_NOTREACHED();
}
RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
@@ -100,17 +100,17 @@
}
void GetStats(RTCStatsCollectorCallback* callback) override {
- FATAL() << "Not implemented";
+ RTC_CHECK_NOTREACHED();
}
void GetStats(
rtc::scoped_refptr<RtpSenderInterface> selector,
rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {
- FATAL() << "Not implemented";
+ RTC_CHECK_NOTREACHED();
}
void GetStats(
rtc::scoped_refptr<RtpReceiverInterface> selector,
rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {
- FATAL() << "Not implemented";
+ RTC_CHECK_NOTREACHED();
}
void ClearStatsCache() override {}
@@ -145,33 +145,33 @@
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<SessionDescriptionInterface> desc,
rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer)
override {
- FATAL() << "Not implemented";
+ RTC_CHECK_NOTREACHED();
}
PeerConnectionInterface::RTCConfiguration GetConfiguration() override {
@@ -194,10 +194,8 @@
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<DtlsTransportInterface> LookupDtlsTransportByMid(
const std::string& mid) override {
@@ -235,7 +233,7 @@
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 ecc5699..d05eb45 100644
--- a/api/video_codecs/video_codec.cc
+++ b/api/video_codecs/video_codec.cc
@@ -120,7 +120,7 @@
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 bb97d30..95a41d0 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 @@
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 @@
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 b79d217..4fc4743 100644
--- a/call/adaptation/video_stream_adapter.cc
+++ b/call/adaptation/video_stream_adapter.cc
@@ -162,7 +162,7 @@
case Status::kRejectedByConstraint:
return "kRejectedByConstraint";
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
Adaptation::Adaptation(int validation_id,
@@ -382,7 +382,7 @@
case DegradationPreference::DISABLED:
return Adaptation::Status::kAdaptationDisabled;
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
Adaptation VideoStreamAdapter::GetAdaptationDown() {
@@ -462,7 +462,7 @@
case DegradationPreference::DISABLED:
return Adaptation::Status::kAdaptationDisabled;
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
VideoStreamAdapter::RestrictionsOrState VideoStreamAdapter::DecreaseResolution(
@@ -601,7 +601,7 @@
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 86e2712..f8a5bd8 100644
--- a/call/simulated_network.cc
+++ b/call/simulated_network.cc
@@ -77,7 +77,7 @@
}
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 d3e3694..244d780 100644
--- a/call/video_send_stream.cc
+++ b/call/video_send_stream.cc
@@ -28,7 +28,7 @@
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 d3dca90..ce119f1 100644
--- a/common_audio/wav_header.cc
+++ b/common_audio/wav_header.cc
@@ -132,7 +132,7 @@
case WavFormat::kWavFormatMuLaw:
return 7;
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
WavFormat MapHeaderFieldToWavFormat(uint16_t format_header_value) {
@@ -278,10 +278,8 @@
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 0d18c1e..4714175 100644
--- a/media/base/rtp_utils.cc
+++ b/media/base/rtp_utils.cc
@@ -323,7 +323,7 @@
case RtpPacketType::kUnknown:
return "Unknown";
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
RtpPacketType InferRtpPacketType(rtc::ArrayView<const char> packet) {
diff --git a/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc b/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc
index 032de20..9fbf42c 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 @@
// 50 bytes per frame of 30 ms => (approx) 13333 bits/s.
return 13333;
default:
- FATAL();
+ RTC_CHECK_NOTREACHED();
}
}
@@ -144,7 +144,7 @@
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 a218504..fb5bf6f 100644
--- a/modules/audio_device/android/audio_device_template.h
+++ b/modules/audio_device/android/audio_device_template.h
@@ -103,15 +103,13 @@
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 @@
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 @@
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 @@
}
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 12ac458..a3aa855 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::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 2d9c3e1..739997f 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 @@
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 9cf1e1d..56d7073 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -114,7 +114,7 @@
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 @@
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 1053642..04336b6 100644
--- a/modules/audio_processing/include/audio_processing.cc
+++ b/modules/audio_processing/include/audio_processing.cc
@@ -31,7 +31,7 @@
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 @@
case Agc1Config::Mode::kFixedDigital:
return "FixedDigital";
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
std::string GainController2LevelEstimatorToString(
@@ -54,7 +54,7 @@
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 0e91432..c3014d8 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 @@
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 adbc298..403c6ee 100644
--- a/modules/audio_processing/test/audio_processing_simulator.cc
+++ b/modules/audio_processing/test/audio_processing_simulator.cc
@@ -40,7 +40,7 @@
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 @@
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 b8cccd1..754b42d 100644
--- a/modules/audio_processing/test/debug_dump_replayer.cc
+++ b/modules/audio_processing/test/debug_dump_replayer.cc
@@ -80,8 +80,7 @@
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 37a20ce..839358d 100644
--- a/modules/audio_processing/test/test_utils.cc
+++ b/modules/audio_processing/test/test_utils.cc
@@ -146,8 +146,7 @@
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 75946fb..8536bf1 100644
--- a/modules/audio_processing/test/wav_based_simulator.cc
+++ b/modules/audio_processing/test/wav_based_simulator.cc
@@ -118,7 +118,7 @@
}
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 bef0d2f..5ffbc90 100644
--- a/modules/pacing/pacing_controller.cc
+++ b/modules/pacing/pacing_controller.cc
@@ -84,7 +84,7 @@
// 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 b44322b..f1e4edd 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 @@
case kVideoCodecMultiplex:
return std::make_unique<VideoRtpDepacketizerGeneric>();
}
- 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 3d1b381..584fced 100644
--- a/modules/rtp_rtcp/source/rtp_sender.cc
+++ b/modules/rtp_rtcp/source/rtp_sender.cc
@@ -128,7 +128,7 @@
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 16a1130..8cf60aa 100644
--- a/modules/rtp_rtcp/source/rtp_sender_audio.cc
+++ b/modules/rtp_rtcp/source/rtp_sender_audio.cc
@@ -46,7 +46,7 @@
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 540cfa3..5aebd2c 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 @@
// Conference mode temporal layering for screen content in base stream.
return std::make_unique<TemporalLayersChecker>(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 844063d..550ede7 100644
--- a/pc/dtls_transport.cc
+++ b/pc/dtls_transport.cc
@@ -31,7 +31,7 @@
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 6e9a7c1..cbff216 100644
--- a/pc/media_session.cc
+++ b/pc/media_session.cc
@@ -1818,7 +1818,7 @@
case RtpTransceiverDirection::kRecvOnly:
return audio_recv_codecs_;
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForAnswer(
@@ -1837,7 +1837,7 @@
case RtpTransceiverDirection::kRecvOnly:
return audio_recv_codecs_;
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForOffer(
@@ -1853,7 +1853,7 @@
case RtpTransceiverDirection::kRecvOnly:
return video_recv_codecs_;
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForAnswer(
@@ -1872,7 +1872,7 @@
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 165968c..3760a01 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -2408,7 +2408,7 @@
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 b8d9084..da42e5a 100644
--- a/pc/peer_connection_factory.cc
+++ b/pc/peer_connection_factory.cc
@@ -141,7 +141,7 @@
case cricket::MEDIA_TYPE_UNSUPPORTED:
return RtpCapabilities();
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
RtpCapabilities PeerConnectionFactory::GetRtpReceiverCapabilities(
@@ -167,7 +167,7 @@
case cricket::MEDIA_TYPE_UNSUPPORTED:
return RtpCapabilities();
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
rtc::scoped_refptr<AudioSourceInterface>
diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc
index 6f14e1e..5b21d33 100644
--- a/pc/rtc_stats_collector.cc
+++ b/pc/rtc_stats_collector.cc
@@ -216,7 +216,7 @@
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 80e56b8..68a948e 100644
--- a/pc/rtp_parameters_conversion.cc
+++ b/pc/rtp_parameters_conversion.cc
@@ -76,7 +76,7 @@
}
return cricket::FeedbackParam(cricket::kRtcpFbParamTransportCc);
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
template <typename C>
diff --git a/rtc_base/checks.cc b/rtc_base/checks.cc
index e5fc2ed..239ea9f 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 @@
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 @@
"# 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 61c074a..508de2a 100644
--- a/rtc_base/checks.h
+++ b/rtc_base/checks.h
@@ -338,6 +338,22 @@
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 @@
#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<false>(__FILE__, __LINE__, \
diff --git a/rtc_base/network_monitor.cc b/rtc_base/network_monitor.cc
index ba6b1b4..70c2ad5 100644
--- a/rtc_base/network_monitor.cc
+++ b/rtc_base/network_monitor.cc
@@ -21,7 +21,7 @@
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 5d58672..e00219c 100644
--- a/rtc_base/numerics/safe_conversions.h
+++ b/rtc_base/numerics/safe_conversions.h
@@ -63,12 +63,10 @@
// Should fail only on attempting to assign NaN to a saturated integer.
case internal::TYPE_INVALID:
- FATAL();
- return std::numeric_limits<Dst>::max();
+ RTC_CHECK_NOTREACHED();
}
- FATAL();
- return static_cast<Dst>(value);
+ RTC_CHECK_NOTREACHED();
}
} // namespace rtc
diff --git a/rtc_base/openssl_certificate.cc b/rtc_base/openssl_certificate.cc
index 9459f76..bd9bb04 100644
--- a/rtc_base/openssl_certificate.cc
+++ b/rtc_base/openssl_certificate.cc
@@ -244,13 +244,8 @@
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 @@
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 b997bf0..9606f42 100644
--- a/rtc_tools/sanitizers_unittest.cc
+++ b/rtc_tools/sanitizers_unittest.cc
@@ -110,7 +110,7 @@
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 d77488f..eb5d93f 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 @@
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 @@
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 @@
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 @@
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 @@
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 f7cf155..c7ca4bc 100644
--- a/video/adaptation/video_stream_encoder_resource_manager.cc
+++ b/video/adaptation/video_stream_encoder_resource_manager.cc
@@ -55,7 +55,7 @@
case VideoAdaptationReason::kCpu:
return "cpu";
}
- RTC_CHECK(false);
+ RTC_CHECK_NOTREACHED();
}
} // namespace