From 1709341fd94215363f4e74900796a29d94af9ebe Mon Sep 17 00:00:00 2001 From: philipel Date: Mon, 13 Jun 2022 13:14:43 +0200 Subject: [PATCH] Send keyframe request if the DependencyDescriptor fail to parse due to missing video structure. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: b/233610247 Change-Id: If471d9b81906c04f50a5f63e26408968adc8c275 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265392 Reviewed-by: Erik Språng Commit-Queue: Philip Eliasson Reviewed-by: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#37196} --- video/rtp_video_stream_receiver2.cc | 12 +++++++++++- video/rtp_video_stream_receiver2.h | 3 +++ video/rtp_video_stream_receiver2_unittest.cc | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc index 14632445e0..207da6296e 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -526,8 +526,18 @@ void RtpVideoStreamReceiver2::OnReceivedPayloadData( rtp_packet, video_header.frame_type == VideoFrameType::kVideoFrameKey); } - if (generic_descriptor_state == kDropPacket) + if (generic_descriptor_state == kDropPacket) { + Timestamp now = clock_->CurrentTime(); + if (video_structure_ == nullptr && + next_keyframe_request_for_missing_video_structure_ < now) { + // No video structure received yet, most likely part of the initial + // keyframe was lost. + RequestKeyFrame(); + next_keyframe_request_for_missing_video_structure_ = + now + TimeDelta::Seconds(1); + } return; + } // Color space should only be transmitted in the last packet of a frame, // therefore, neglect it otherwise so that last_color_space_ is not reset by diff --git a/video/rtp_video_stream_receiver2.h b/video/rtp_video_stream_receiver2.h index cb43b2c11f..8ed6ea0100 100644 --- a/video/rtp_video_stream_receiver2.h +++ b/video/rtp_video_stream_receiver2.h @@ -404,6 +404,9 @@ class RtpVideoStreamReceiver2 : public LossNotificationSender, RTC_GUARDED_BY(packet_sequence_checker_); std::map packet_infos_ RTC_GUARDED_BY(packet_sequence_checker_); + + Timestamp next_keyframe_request_for_missing_video_structure_ = + Timestamp::MinusInfinity(); }; } // namespace webrtc diff --git a/video/rtp_video_stream_receiver2_unittest.cc b/video/rtp_video_stream_receiver2_unittest.cc index 71cc1a7935..0507da9627 100644 --- a/video/rtp_video_stream_receiver2_unittest.cc +++ b/video/rtp_video_stream_receiver2_unittest.cc @@ -1109,6 +1109,26 @@ TEST_F(RtpVideoStreamReceiver2DependencyDescriptorTest, InjectPacketWith(stream_structure2, deltaframe_descriptor); } +TEST_F(RtpVideoStreamReceiver2DependencyDescriptorTest, + RequestKeyframeIfInitialKeyframePacketIsLost) { + FrameDependencyStructure stream_structure = CreateStreamStructure(); + + DependencyDescriptor keyframe_descriptor_without_structure; + keyframe_descriptor_without_structure.frame_dependencies = + stream_structure.templates[0]; + keyframe_descriptor_without_structure.frame_number = 0; + + EXPECT_CALL(mock_key_frame_request_sender_, RequestKeyFrame).Times(2); + InjectPacketWith(stream_structure, keyframe_descriptor_without_structure); + + // Not enough time since last keyframe request + time_controller_.AdvanceTime(TimeDelta::Millis(500)); + InjectPacketWith(stream_structure, keyframe_descriptor_without_structure); + + time_controller_.AdvanceTime(TimeDelta::Millis(501)); + InjectPacketWith(stream_structure, keyframe_descriptor_without_structure); +} + TEST_F(RtpVideoStreamReceiver2Test, TransformFrame) { rtc::scoped_refptr mock_frame_transformer = rtc::make_ref_counted>();