Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion src/amf/amf_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,37 @@ namespace amf {
if (config.pa_activity_type && !set_verified_int64(AMF_PA_ACTIVITY_TYPE, *config.pa_activity_type, "PA activity type")) return false;
}

// BEGIN INSERT1 (HEVC Gradual Decoder Refresh configuration)
if (client_config.enableIntraRefresh == 1) {
constexpr int64_t GOP_SIZE = 120;
constexpr int64_t CTU_SIZE = 64;

encoder->SetProperty(AMF_VIDEO_ENCODER_HEVC_NUM_GOPS_PER_IDR, 0);

if (encoder->SetProperty(AMF_VIDEO_ENCODER_HEVC_GOP_SIZE, GOP_SIZE) == AMF_OK) {
const int64_t width = (encode_width > 0) ? encode_width : 3840;
const int64_t height = (encode_height > 0) ? encode_height : 2160;

const int64_t ctu_width = (width + CTU_SIZE - 1) / CTU_SIZE;
const int64_t ctu_height = (height + CTU_SIZE - 1) / CTU_SIZE;

constexpr int64_t TARGET_DURATION = GOP_SIZE;
const int64_t ctbs_per_slot =
std::max<int64_t>(1, (ctu_width * ctu_height) / TARGET_DURATION);

if (!set_verified_int64(
AMF_VIDEO_ENCODER_HEVC_INTRA_REFRESH_NUM_CTBS_PER_SLOT,
ctbs_per_slot,
"HEVC GDR CTBs Per Slot")) {
return false;
}
BOOST_LOG(info) << "AMF: Fixed HEVC GDR active. " << ctbs_per_slot << " CTBs/slot configured.";
}
} else {
BOOST_LOG(info) << "AMF: Intra-Refresh disabled (not requested by client)";
}
// END INSERT1

// NOTE: LOWLATENCY_MODE is intentionally NOT forced here.
//
// Previously this block hard-coded AMF_VIDEO_ENCODER_(HEVC_)LOWLATENCY_MODE = true
Expand Down Expand Up @@ -1838,7 +1869,7 @@ namespace amf {
}
}
}

auto disable_rfi_after_property_failure = [&](const char *property_label, AMF_RESULT property_result) {
BOOST_LOG(warning) << "AMF: failed to apply " << property_label << " (error=" << property_result
<< "); disabling RFI and falling back to IDR recovery";
Expand All @@ -1860,6 +1891,21 @@ namespace amf {
return false;
};

// BEGIN INSERT2 (HEVC GDR IDR interception)
if (encoder && current_config.enableIntraRefresh == 1 && force_idr) {
if (surface -> SetProperty(
AMF_VIDEO_ENCODER_HEVC_FORCE_PICTURE_TYPE,
AMF_VIDEO_ENCODER_HEVC_PICTURE_TYPE_I) != AMF_OK) {
BOOST_LOG(warning) << "AMF GDR: Failed to suppress IDR request";
}
if (surface -> SetProperty(
AMF_VIDEO_ENCODER_HEVC_INSERT_HEADER,
true) != AMF_OK) {
BOOST_LOG(warning) << "AMF GDR: Failed to insert VPS/SPS/PPS";
}
}
// END INSERT2

auto set_forced_idr_properties = [&]() {
auto check = [&](AMF_RESULT property_result, const char *label) {
if (property_result == AMF_OK) return true;
Expand Down