Skip to content

Commit

Permalink
nvenc: generate less IDR frames if rfi is delayed
Browse files Browse the repository at this point in the history
If IDR frame was generated due too rfi request being too large, we
didn't save it in last rfi range.

Also move rfi_needs_confirmation variable modification to a more
logical place, even if doesn't affect how current code works.
Any unfulfilled rfi request needs confirmation, whether it's direct rfi
flag in transported frame or indirect IDR frame.
  • Loading branch information
ns6089 authored and cgutman committed Sep 13, 2023
1 parent 84a5dbf commit 68f9a89
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/nvenc/nvenc_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ namespace nvenc {
return true;
}

encoder_state.rfi_needs_confirmation = true;

if (last_frame < first_frame) {
BOOST_LOG(error) << "NvEnc: invaid rfi request " << first_frame << "-" << last_frame << ", generating IDR";
return false;
Expand All @@ -508,14 +510,13 @@ namespace nvenc {
BOOST_LOG(debug) << "NvEnc: rfi request " << first_frame << "-" << last_frame << " expanding to last encoded frame " << encoder_state.last_encoded_frame_index;
last_frame = encoder_state.last_encoded_frame_index;

encoder_state.last_rfi_range = { first_frame, last_frame };

if (last_frame - first_frame + 1 >= encoder_params.ref_frames_in_dpb) {
BOOST_LOG(debug) << "NvEnc: rfi request too large, generating IDR";
return false;
}

encoder_state.rfi_needs_confirmation = true;
encoder_state.last_rfi_range = { first_frame, last_frame };

for (auto i = first_frame; i <= last_frame; i++) {
if (nvenc_failed(nvenc->nvEncInvalidateRefFrames(encoder, i))) {
BOOST_LOG(error) << "NvEncInvalidateRefFrames " << i << " failed: " << last_error_string;
Expand Down

0 comments on commit 68f9a89

Please sign in to comment.