diff --git a/video/rtp_video_stream_receiver.cc b/video/rtp_video_stream_receiver.cc index b3cf7fbbf2..6f1724f41a 100644 --- a/video/rtp_video_stream_receiver.cc +++ b/video/rtp_video_stream_receiver.cc @@ -378,6 +378,16 @@ int32_t RtpVideoStreamReceiver::ResendPackets(const uint16_t* sequence_numbers, void RtpVideoStreamReceiver::OnReceivedFrame( std::unique_ptr frame) { + // Request a key frame as soon as possible. + bool key_frame_requested = false; + if (!has_received_frame_) { + has_received_frame_ = true; + if (frame->FrameType() != kVideoFrameKey) { + key_frame_requested = true; + keyframe_request_sender_->RequestKeyFrame(); + } + } + // Optionally attempt to decrypt the raw video frame if it was provided. if (frame_decryptor_ != nullptr) { // When using encryption we expect the frame to have the generic descriptor. @@ -408,6 +418,14 @@ void RtpVideoStreamReceiver::OnReceivedFrame( inline_decrypted_bitstream, &bytes_written) != 0) { return; } + + if (!has_received_decrypted_frame_ && !key_frame_requested) { + has_received_decrypted_frame_ = true; + if (frame->FrameType() != kVideoFrameKey) { + keyframe_request_sender_->RequestKeyFrame(); + } + } + RTC_CHECK(bytes_written <= max_plaintext_byte_size); // Update the frame to contain just the written bytes. frame->SetLength(bytes_written); @@ -417,12 +435,6 @@ void RtpVideoStreamReceiver::OnReceivedFrame( return; } - if (!has_received_frame_) { - has_received_frame_ = true; - if (frame->FrameType() != kVideoFrameKey) - keyframe_request_sender_->RequestKeyFrame(); - } - reference_finder_->ManageFrame(std::move(frame)); } diff --git a/video/rtp_video_stream_receiver.h b/video/rtp_video_stream_receiver.h index 9c88173a13..ed5164769e 100644 --- a/video/rtp_video_stream_receiver.h +++ b/video/rtp_video_stream_receiver.h @@ -208,6 +208,8 @@ class RtpVideoStreamReceiver : public RecoveredPacketReceiver, // E2EE Video Frame Decryptor (Optional) rtc::scoped_refptr frame_decryptor_; + // Set to true on the first successsfully decrypted frame. + bool has_received_decrypted_frame_ = false; }; } // namespace webrtc