| 1217 | }; |
| 1218 | |
| 1219 | static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx) |
| 1220 | { |
| 1221 | VAAPIEncodeContext *ctx = avctx->priv_data; |
| 1222 | uint32_t supported_va_rc_modes; |
| 1223 | const VAAPIEncodeRCMode *rc_mode; |
| 1224 | int64_t rc_bits_per_second; |
| 1225 | int rc_target_percentage; |
| 1226 | int rc_window_size; |
| 1227 | int rc_quality; |
| 1228 | int64_t hrd_buffer_size; |
| 1229 | int64_t hrd_initial_buffer_fullness; |
| 1230 | int fr_num, fr_den; |
| 1231 | VAConfigAttrib rc_attr = { VAConfigAttribRateControl }; |
| 1232 | VAStatus vas; |
| 1233 | char supported_rc_modes_string[64]; |
| 1234 | |
| 1235 | vas = vaGetConfigAttributes(ctx->hwctx->display, |
| 1236 | ctx->va_profile, ctx->va_entrypoint, |
| 1237 | &rc_attr, 1); |
| 1238 | if (vas != VA_STATUS_SUCCESS) { |
| 1239 | av_log(avctx, AV_LOG_ERROR, "Failed to query rate control " |
| 1240 | "config attribute: %d (%s).\n", vas, vaErrorStr(vas)); |
| 1241 | return AVERROR_EXTERNAL; |
| 1242 | } |
| 1243 | if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) { |
| 1244 | av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any " |
| 1245 | "supported rate control modes: assuming CQP only.\n"); |
| 1246 | supported_va_rc_modes = VA_RC_CQP; |
| 1247 | strcpy(supported_rc_modes_string, "unknown"); |
| 1248 | } else { |
| 1249 | char *str = supported_rc_modes_string; |
| 1250 | size_t len = sizeof(supported_rc_modes_string); |
| 1251 | int i, first = 1, res; |
| 1252 | |
| 1253 | supported_va_rc_modes = rc_attr.value; |
| 1254 | if (ctx->blbrc) { |
| 1255 | #if VA_CHECK_VERSION(0, 39, 2) |
| 1256 | if (!(supported_va_rc_modes & VA_RC_MB)) { |
| 1257 | ctx->blbrc = 0; |
| 1258 | av_log(avctx, AV_LOG_WARNING, "Driver does not support BLBRC.\n"); |
| 1259 | } |
| 1260 | #else |
| 1261 | ctx->blbrc = 0; |
| 1262 | av_log(avctx, AV_LOG_WARNING, "Please consider to update to VAAPI 0.39.2 " |
| 1263 | "or above, which can support BLBRC.\n"); |
| 1264 | #endif |
| 1265 | } |
| 1266 | |
| 1267 | for (i = 0; i < FF_ARRAY_ELEMS(vaapi_encode_rc_modes); i++) { |
| 1268 | rc_mode = &vaapi_encode_rc_modes[i]; |
| 1269 | if (supported_va_rc_modes & rc_mode->va_mode) { |
| 1270 | res = snprintf(str, len, "%s%s", |
| 1271 | first ? "" : ", ", rc_mode->name); |
| 1272 | first = 0; |
| 1273 | if (res < 0) { |
| 1274 | *str = 0; |
| 1275 | break; |
| 1276 | } |
no test coverage detected