From 94f2b91f1158908e8de6a8c44fd9f7be600ea238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Tue, 3 Dec 2024 13:45:55 +0100 Subject: [PATCH] Fix maybe incorrect spatial id when reading corruption detection message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In addition, avoid empty conversion when no message is present. Bug: chromium:379326016 Change-Id: I855069fa89a157ba862b5162c56858825ebc1a40 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/370160 Reviewed-by: Sergey Silkin Commit-Queue: Erik Språng Auto-Submit: Erik Språng Cr-Commit-Position: refs/heads/main@{#43487} --- video/rtp_video_stream_receiver2.cc | 67 +++++++++++++++++------------ 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc index 143e151af8..3982cf11e3 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -616,36 +616,49 @@ bool RtpVideoStreamReceiver2::OnReceivedPayloadData( } else if (last_color_space_) { video_header.color_space = last_color_space_; } - CorruptionDetectionMessage message; - rtp_packet.GetExtension(&message); - int spatial_idx = 0; + + std::optional spatial_id; if (video_header.generic.has_value()) { - spatial_idx = video_header.generic->spatial_index; - } - if (message.sample_values().empty()) { - video_header.frame_instrumentation_data = - ConvertCorruptionDetectionMessageToFrameInstrumentationSyncData( - message, last_corruption_detection_state_by_layer_[spatial_idx] - .sequence_index); - } else { - // `OnReceivedPayloadData` might be called several times, however, we - // don't want to increase the sequence index each time. - if (!last_corruption_detection_state_by_layer_[spatial_idx] - .timestamp.has_value() || - rtp_packet.Timestamp() != - last_corruption_detection_state_by_layer_[spatial_idx] - .timestamp) { - video_header.frame_instrumentation_data = - ConvertCorruptionDetectionMessageToFrameInstrumentationData( - message, last_corruption_detection_state_by_layer_[spatial_idx] - .sequence_index); - last_corruption_detection_state_by_layer_[spatial_idx].timestamp = - rtp_packet.Timestamp(); + spatial_id = video_header.generic->spatial_index; + if (spatial_id >= kMaxSpatialLayers) { + RTC_LOG(LS_WARNING) << "Invalid spatial id: " << *spatial_id + << ". Ignoring corruption detection mesaage."; + spatial_id.reset(); } + } else { + spatial_id = 0; } - if (video_header.frame_instrumentation_data.has_value()) { - SetLastCorruptionDetectionIndex(*video_header.frame_instrumentation_data, - spatial_idx); + + std::optional message = + rtp_packet.GetExtension(); + if (message.has_value() && spatial_id.has_value()) { + if (message->sample_values().empty()) { + video_header.frame_instrumentation_data = + ConvertCorruptionDetectionMessageToFrameInstrumentationSyncData( + *message, last_corruption_detection_state_by_layer_[*spatial_id] + .sequence_index); + } else { + // `OnReceivedPayloadData` might be called several times, however, we + // don't want to increase the sequence index each time. + if (!last_corruption_detection_state_by_layer_[*spatial_id] + .timestamp.has_value() || + rtp_packet.Timestamp() != + last_corruption_detection_state_by_layer_[*spatial_id] + .timestamp) { + video_header.frame_instrumentation_data = + ConvertCorruptionDetectionMessageToFrameInstrumentationData( + *message, + last_corruption_detection_state_by_layer_[*spatial_id] + .sequence_index); + last_corruption_detection_state_by_layer_[*spatial_id].timestamp = + rtp_packet.Timestamp(); + } + } + + if (video_header.frame_instrumentation_data.has_value()) { + SetLastCorruptionDetectionIndex( + *video_header.frame_instrumentation_data, *spatial_id); + } } } video_header.video_frame_tracking_id =