Return a status in ParsedRtcEventLog instead of checked_cast.

Bug: webrtc:375120297
Change-Id: I64bd6b9e5ef646c787d23e3abc1bd6b3fd209d4a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/367121
Reviewed-by: Mirta Dvornicic <mirtad@webrtc.org>
Auto-Submit: Björn Terelius <terelius@webrtc.org>
Commit-Queue: Mirta Dvornicic <mirtad@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43345}
This commit is contained in:
Björn Terelius 2024-10-30 16:30:55 +01:00 committed by WebRTC LUCI CQ
parent db40c1cd5f
commit 661ed679a2

View File

@ -377,40 +377,66 @@ ParsedRtcEventLog::ParseStatus StoreRtpPackets(
// Base event // Base event
{ {
RTPHeader header; RTPHeader header;
header.markerBit = rtc::checked_cast<bool>(proto.marker()); RTC_PARSE_CHECK_OR_RETURN(
header.payloadType = rtc::checked_cast<uint8_t>(proto.payload_type()); rtc::IsValueInRangeForNumericType<bool>(proto.marker()));
header.sequenceNumber = header.markerBit = static_cast<bool>(proto.marker());
rtc::checked_cast<uint16_t>(proto.sequence_number()); RTC_PARSE_CHECK_OR_RETURN(
header.timestamp = rtc::checked_cast<uint32_t>(proto.rtp_timestamp()); rtc::IsValueInRangeForNumericType<uint8_t>(proto.payload_type()));
header.ssrc = rtc::checked_cast<uint32_t>(proto.ssrc()); header.payloadType = static_cast<uint8_t>(proto.payload_type());
RTC_PARSE_CHECK_OR_RETURN(
rtc::IsValueInRangeForNumericType<uint16_t>(proto.sequence_number()));
header.sequenceNumber = static_cast<uint16_t>(proto.sequence_number());
RTC_PARSE_CHECK_OR_RETURN(
rtc::IsValueInRangeForNumericType<uint32_t>(proto.rtp_timestamp()));
header.timestamp = static_cast<uint32_t>(proto.rtp_timestamp());
RTC_PARSE_CHECK_OR_RETURN(
rtc::IsValueInRangeForNumericType<uint32_t>(proto.ssrc()));
header.ssrc = static_cast<uint32_t>(proto.ssrc());
header.numCSRCs = 0; // TODO(terelius): Implement CSRC. header.numCSRCs = 0; // TODO(terelius): Implement CSRC.
header.paddingLength = rtc::checked_cast<size_t>(proto.padding_size()); RTC_PARSE_CHECK_OR_RETURN(
header.headerLength = rtc::checked_cast<size_t>(proto.header_size()); rtc::IsValueInRangeForNumericType<size_t>(proto.padding_size()));
header.paddingLength = static_cast<size_t>(proto.padding_size());
RTC_PARSE_CHECK_OR_RETURN(
rtc::IsValueInRangeForNumericType<size_t>(proto.header_size()));
header.headerLength = static_cast<size_t>(proto.header_size());
// TODO(terelius): Should we implement payload_type_frequency? // TODO(terelius): Should we implement payload_type_frequency?
if (proto.has_transport_sequence_number()) { if (proto.has_transport_sequence_number()) {
header.extension.hasTransportSequenceNumber = true; header.extension.hasTransportSequenceNumber = true;
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<uint16_t>(
proto.transport_sequence_number()));
header.extension.transportSequenceNumber = header.extension.transportSequenceNumber =
rtc::checked_cast<uint16_t>(proto.transport_sequence_number()); static_cast<uint16_t>(proto.transport_sequence_number());
} }
if (proto.has_transmission_time_offset()) { if (proto.has_transmission_time_offset()) {
header.extension.hasTransmissionTimeOffset = true; header.extension.hasTransmissionTimeOffset = true;
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<int32_t>(
proto.transmission_time_offset()));
header.extension.transmissionTimeOffset = header.extension.transmissionTimeOffset =
rtc::checked_cast<int32_t>(proto.transmission_time_offset()); static_cast<int32_t>(proto.transmission_time_offset());
} }
if (proto.has_absolute_send_time()) { if (proto.has_absolute_send_time()) {
header.extension.hasAbsoluteSendTime = true; header.extension.hasAbsoluteSendTime = true;
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<uint32_t>(
proto.absolute_send_time()));
header.extension.absoluteSendTime = header.extension.absoluteSendTime =
rtc::checked_cast<uint32_t>(proto.absolute_send_time()); static_cast<uint32_t>(proto.absolute_send_time());
} }
if (proto.has_video_rotation()) { if (proto.has_video_rotation()) {
header.extension.hasVideoRotation = true; header.extension.hasVideoRotation = true;
RTC_PARSE_CHECK_OR_RETURN(
rtc::IsValueInRangeForNumericType<uint8_t>(proto.video_rotation()));
header.extension.videoRotation = ConvertCVOByteToVideoRotation( header.extension.videoRotation = ConvertCVOByteToVideoRotation(
rtc::checked_cast<uint8_t>(proto.video_rotation())); static_cast<uint8_t>(proto.video_rotation()));
} }
if (proto.has_audio_level()) { if (proto.has_audio_level()) {
RTC_PARSE_CHECK_OR_RETURN(proto.has_voice_activity()); RTC_PARSE_CHECK_OR_RETURN(proto.has_voice_activity());
bool voice_activity = rtc::checked_cast<bool>(proto.voice_activity()); RTC_PARSE_CHECK_OR_RETURN(
int audio_level = rtc::checked_cast<int>(proto.audio_level()); rtc::IsValueInRangeForNumericType<bool>(proto.voice_activity()));
bool voice_activity = static_cast<bool>(proto.voice_activity());
RTC_PARSE_CHECK_OR_RETURN(
rtc::IsValueInRangeForNumericType<int>(proto.audio_level()));
int audio_level = static_cast<int>(proto.audio_level());
RTC_PARSE_CHECK_OR_RETURN_LE(audio_level, 0x7F); RTC_PARSE_CHECK_OR_RETURN_LE(audio_level, 0x7F);
header.extension.set_audio_level(AudioLevel(voice_activity, audio_level)); header.extension.set_audio_level(AudioLevel(voice_activity, audio_level));
} else { } else {
@ -570,21 +596,36 @@ ParsedRtcEventLog::ParseStatus StoreRtpPackets(
ToSigned(timestamp_ms_values[i].value(), &timestamp_ms)); ToSigned(timestamp_ms_values[i].value(), &timestamp_ms));
RTPHeader header; RTPHeader header;
header.markerBit = rtc::checked_cast<bool>(*marker_values[i]); RTC_PARSE_CHECK_OR_RETURN(
header.payloadType = rtc::checked_cast<uint8_t>(*payload_type_values[i]); rtc::IsValueInRangeForNumericType<bool>(*marker_values[i]));
header.sequenceNumber = header.markerBit = static_cast<bool>(*marker_values[i]);
rtc::checked_cast<uint16_t>(*sequence_number_values[i]); RTC_PARSE_CHECK_OR_RETURN(
header.timestamp = rtc::checked_cast<uint32_t>(*rtp_timestamp_values[i]); rtc::IsValueInRangeForNumericType<uint8_t>(*payload_type_values[i]));
header.ssrc = rtc::checked_cast<uint32_t>(*ssrc_values[i]); header.payloadType = static_cast<uint8_t>(*payload_type_values[i]);
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<uint16_t>(
*sequence_number_values[i]));
header.sequenceNumber = static_cast<uint16_t>(*sequence_number_values[i]);
RTC_PARSE_CHECK_OR_RETURN(
rtc::IsValueInRangeForNumericType<uint32_t>(*rtp_timestamp_values[i]));
header.timestamp = static_cast<uint32_t>(*rtp_timestamp_values[i]);
RTC_PARSE_CHECK_OR_RETURN(
rtc::IsValueInRangeForNumericType<uint32_t>(*ssrc_values[i]));
header.ssrc = static_cast<uint32_t>(*ssrc_values[i]);
header.numCSRCs = 0; // TODO(terelius): Implement CSRC. header.numCSRCs = 0; // TODO(terelius): Implement CSRC.
header.paddingLength = rtc::checked_cast<size_t>(*padding_size_values[i]); RTC_PARSE_CHECK_OR_RETURN(
header.headerLength = rtc::checked_cast<size_t>(*header_size_values[i]); rtc::IsValueInRangeForNumericType<size_t>(*padding_size_values[i]));
header.paddingLength = static_cast<size_t>(*padding_size_values[i]);
RTC_PARSE_CHECK_OR_RETURN(
rtc::IsValueInRangeForNumericType<size_t>(*header_size_values[i]));
header.headerLength = static_cast<size_t>(*header_size_values[i]);
// TODO(terelius): Should we implement payload_type_frequency? // TODO(terelius): Should we implement payload_type_frequency?
if (transport_sequence_number_values.size() > i && if (transport_sequence_number_values.size() > i &&
transport_sequence_number_values[i].has_value()) { transport_sequence_number_values[i].has_value()) {
header.extension.hasTransportSequenceNumber = true; header.extension.hasTransportSequenceNumber = true;
header.extension.transportSequenceNumber = rtc::checked_cast<uint16_t>( RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<uint16_t>(
transport_sequence_number_values[i].value()); transport_sequence_number_values[i].value()));
header.extension.transportSequenceNumber =
static_cast<uint16_t>(transport_sequence_number_values[i].value());
} }
if (transmission_time_offset_values.size() > i && if (transmission_time_offset_values.size() > i &&
transmission_time_offset_values[i].has_value()) { transmission_time_offset_values[i].has_value()) {
@ -598,21 +639,28 @@ ParsedRtcEventLog::ParseStatus StoreRtpPackets(
if (absolute_send_time_values.size() > i && if (absolute_send_time_values.size() > i &&
absolute_send_time_values[i].has_value()) { absolute_send_time_values[i].has_value()) {
header.extension.hasAbsoluteSendTime = true; header.extension.hasAbsoluteSendTime = true;
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<uint32_t>(
absolute_send_time_values[i].value()));
header.extension.absoluteSendTime = header.extension.absoluteSendTime =
rtc::checked_cast<uint32_t>(absolute_send_time_values[i].value()); static_cast<uint32_t>(absolute_send_time_values[i].value());
} }
if (video_rotation_values.size() > i && if (video_rotation_values.size() > i &&
video_rotation_values[i].has_value()) { video_rotation_values[i].has_value()) {
header.extension.hasVideoRotation = true; header.extension.hasVideoRotation = true;
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<uint8_t>(
video_rotation_values[i].value()));
header.extension.videoRotation = ConvertCVOByteToVideoRotation( header.extension.videoRotation = ConvertCVOByteToVideoRotation(
rtc::checked_cast<uint8_t>(video_rotation_values[i].value())); static_cast<uint8_t>(video_rotation_values[i].value()));
} }
if (audio_level_values.size() > i && audio_level_values[i].has_value()) { if (audio_level_values.size() > i && audio_level_values[i].has_value()) {
RTC_PARSE_CHECK_OR_RETURN(voice_activity_values.size() > i && RTC_PARSE_CHECK_OR_RETURN(voice_activity_values.size() > i &&
voice_activity_values[i].has_value()); voice_activity_values[i].has_value());
bool voice_activity = RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<bool>(
rtc::checked_cast<bool>(voice_activity_values[i].value()); voice_activity_values[i].value()));
int audio_level = rtc::checked_cast<int>(audio_level_values[i].value()); bool voice_activity = static_cast<bool>(voice_activity_values[i].value());
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<int>(
audio_level_values[i].value()));
int audio_level = static_cast<int>(audio_level_values[i].value());
RTC_PARSE_CHECK_OR_RETURN_LE(audio_level, 0x7F); RTC_PARSE_CHECK_OR_RETURN_LE(audio_level, 0x7F);
header.extension.set_audio_level(AudioLevel(voice_activity, audio_level)); header.extension.set_audio_level(AudioLevel(voice_activity, audio_level));
} else { } else {
@ -3510,23 +3558,30 @@ ParsedRtcEventLog::StoreAudioNetworkAdaptationEvent(
} }
if (uplink_packet_loss_fraction_values[i].has_value()) { if (uplink_packet_loss_fraction_values[i].has_value()) {
float uplink_packet_loss_fraction2; float uplink_packet_loss_fraction2;
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<uint32_t>(
uplink_packet_loss_fraction_values[i].value()));
RTC_PARSE_CHECK_OR_RETURN(ParsePacketLossFractionFromProtoFormat( RTC_PARSE_CHECK_OR_RETURN(ParsePacketLossFractionFromProtoFormat(
rtc::checked_cast<uint32_t>( static_cast<uint32_t>(uplink_packet_loss_fraction_values[i].value()),
uplink_packet_loss_fraction_values[i].value()),
&uplink_packet_loss_fraction2)); &uplink_packet_loss_fraction2));
runtime_config.uplink_packet_loss_fraction = uplink_packet_loss_fraction2; runtime_config.uplink_packet_loss_fraction = uplink_packet_loss_fraction2;
} }
if (enable_fec_values[i].has_value()) { if (enable_fec_values[i].has_value()) {
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<bool>(
enable_fec_values[i].value()));
runtime_config.enable_fec = runtime_config.enable_fec =
rtc::checked_cast<bool>(enable_fec_values[i].value()); static_cast<bool>(enable_fec_values[i].value());
} }
if (enable_dtx_values[i].has_value()) { if (enable_dtx_values[i].has_value()) {
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<bool>(
enable_dtx_values[i].value()));
runtime_config.enable_dtx = runtime_config.enable_dtx =
rtc::checked_cast<bool>(enable_dtx_values[i].value()); static_cast<bool>(enable_dtx_values[i].value());
} }
if (num_channels_values[i].has_value()) { if (num_channels_values[i].has_value()) {
RTC_PARSE_CHECK_OR_RETURN(rtc::IsValueInRangeForNumericType<size_t>(
num_channels_values[i].value()));
runtime_config.num_channels = runtime_config.num_channels =
rtc::checked_cast<size_t>(num_channels_values[i].value()); static_cast<size_t>(num_channels_values[i].value());
} }
audio_network_adaptation_events_.emplace_back( audio_network_adaptation_events_.emplace_back(
Timestamp::Millis(timestamp_ms), runtime_config); Timestamp::Millis(timestamp_ms), runtime_config);