diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc b/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc index ba1e597ad8..f1b12f0beb 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc +++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc @@ -139,10 +139,6 @@ rtclog::IceCandidatePairConfig::IceCandidateType ConvertIceCandidateType( return rtclog::IceCandidatePairConfig::PRFLX; case IceCandidateType::kRelay: return rtclog::IceCandidatePairConfig::RELAY; - default: - // TODO(tommi): Remove the default handler when kNumValues is gone. - RTC_DCHECK_NOTREACHED(); - return rtclog::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE; } } @@ -200,6 +196,7 @@ rtclog::IceCandidatePairConfig::NetworkType ConvertIceCandidateNetworkType( return rtclog::IceCandidatePairConfig::CELLULAR; case IceCandidateNetworkType::kNumValues: RTC_DCHECK_NOTREACHED(); + break; } RTC_DCHECK_NOTREACHED(); return rtclog::IceCandidatePairConfig::UNKNOWN_NETWORK_TYPE; diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc b/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc index a07afbe48a..4c662fd266 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc +++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc @@ -206,8 +206,6 @@ rtclog2::IceCandidatePairConfig::IceCandidateType ConvertToProtoFormat( return rtclog2::IceCandidatePairConfig::PRFLX; case IceCandidateType::kRelay: return rtclog2::IceCandidatePairConfig::RELAY; - case IceCandidateType::kNumValues: - RTC_DCHECK_NOTREACHED(); } RTC_DCHECK_NOTREACHED(); return rtclog2::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE; diff --git a/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h b/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h index a44f530e77..e77253d9fb 100644 --- a/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h +++ b/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h @@ -32,14 +32,13 @@ enum class IceCandidatePairConfigType { kNumValues, }; -// TODO(qingsi): Change the names of candidate types to "host", "srflx", "prflx" -// and "relay" after the naming is spec-compliant in the signaling part +// TODO(tommi): Change the names of candidate types to "host", "srflx" for +// spec-compliance. enum class IceCandidateType { kLocal, kStun, kPrflx, kRelay, - kNumValues, }; enum class IceCandidatePairProtocol { diff --git a/logging/rtc_event_log/rtc_event_log_unittest_helper.cc b/logging/rtc_event_log/rtc_event_log_unittest_helper.cc index 1aff19fc34..df3586a3b6 100644 --- a/logging/rtc_event_log/rtc_event_log_unittest_helper.cc +++ b/logging/rtc_event_log/rtc_event_log_unittest_helper.cc @@ -217,10 +217,27 @@ EventGenerator::NewProbeResultSuccess() { return std::make_unique(id, bitrate_bps); } +constexpr uint32_t CandidateTypeCount() { + // This switch statement only exists to catch changes to the IceCandidateType + // enumeration. If you get an error here, please update the switch statement + // and the return value. + IceCandidateType type = IceCandidateType::kLocal; + switch (type) { + case IceCandidateType::kLocal: + case IceCandidateType::kStun: + case IceCandidateType::kPrflx: + case IceCandidateType::kRelay: + break; + } + return 4u; +} + std::unique_ptr EventGenerator::NewIceCandidatePairConfig() { - IceCandidateType local_candidate_type = static_cast( - prng_.Rand(static_cast(IceCandidateType::kNumValues) - 1)); + static_assert(static_cast(IceCandidateType::kLocal) == 0, + "Expect kLocal to be the first enum value, equal to 0"); + IceCandidateType local_candidate_type = + static_cast(prng_.Rand(CandidateTypeCount() - 1)); IceCandidateNetworkType local_network_type = static_cast(prng_.Rand( static_cast(IceCandidateNetworkType::kNumValues) - 1)); @@ -228,8 +245,8 @@ EventGenerator::NewIceCandidatePairConfig() { static_cast(prng_.Rand( static_cast(IceCandidatePairAddressFamily::kNumValues) - 1)); - IceCandidateType remote_candidate_type = static_cast( - prng_.Rand(static_cast(IceCandidateType::kNumValues) - 1)); + IceCandidateType remote_candidate_type = + static_cast(prng_.Rand(CandidateTypeCount() - 1)); IceCandidatePairAddressFamily remote_address_family = static_cast(prng_.Rand( static_cast(IceCandidatePairAddressFamily::kNumValues) - diff --git a/rtc_tools/rtc_event_log_to_text/converter.cc b/rtc_tools/rtc_event_log_to_text/converter.cc index 35a780f043..79cf03ead4 100644 --- a/rtc_tools/rtc_event_log_to_text/converter.cc +++ b/rtc_tools/rtc_event_log_to_text/converter.cc @@ -234,8 +234,7 @@ bool Convert(std::string inputfile, candidate_type_name{{IceCandidateType::kLocal, "LOCAL"}, {IceCandidateType::kStun, "STUN"}, {IceCandidateType::kPrflx, "PRFLX"}, - {IceCandidateType::kRelay, "RELAY"}, - {IceCandidateType::kNumValues, "NUM_VALUES"}}; + {IceCandidateType::kRelay, "RELAY"}}; static const std::map protocol_name{{IceCandidatePairProtocol::kUnknown, "UNKNOWN"},