aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/hw_base_encode.c
diff options
context:
space:
mode:
authorTong Wu <tong1.wu@intel.com>2024-04-18 10:56:58 +0800
committerLynne <dev@lynne.ee>2024-07-02 14:15:12 +0200
commit3ca740f19ca0d0152075f9cf7c8d7e5cf6f4f870 (patch)
tree6d7ca576cb5ce78ca76729f77c8cabf99a4ae92e /libavcodec/hw_base_encode.c
parent1242abdcee257f0cfefc7aabf118d23253f37769 (diff)
downloadffmpeg-3ca740f19ca0d0152075f9cf7c8d7e5cf6f4f870.tar.gz
avcodec/vaapi_encode: extract gop configuration and two options to base layer
idr_interval and desired_b_depth are moved to HW_BASE_ENCODE_COMMON_OPTIONS. Signed-off-by: Tong Wu <tong1.wu@intel.com>
Diffstat (limited to 'libavcodec/hw_base_encode.c')
-rw-r--r--libavcodec/hw_base_encode.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index c4789380b6..56dc015e2e 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -593,6 +593,60 @@ end:
return 0;
}
+int ff_hw_base_init_gop_structure(AVCodecContext *avctx, uint32_t ref_l0, uint32_t ref_l1,
+ int flags, int prediction_pre_only)
+{
+ FFHWBaseEncodeContext *ctx = avctx->priv_data;
+
+ if (flags & FF_HW_FLAG_INTRA_ONLY || avctx->gop_size <= 1) {
+ av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n");
+ ctx->gop_size = 1;
+ } else if (ref_l0 < 1) {
+ av_log(avctx, AV_LOG_ERROR, "Driver does not support any "
+ "reference frames.\n");
+ return AVERROR(EINVAL);
+ } else if (!(flags & FF_HW_FLAG_B_PICTURES) || ref_l1 < 1 ||
+ avctx->max_b_frames < 1 || prediction_pre_only) {
+ if (ctx->p_to_gpb)
+ av_log(avctx, AV_LOG_VERBOSE, "Using intra and B-frames "
+ "(supported references: %d / %d).\n",
+ ref_l0, ref_l1);
+ else
+ av_log(avctx, AV_LOG_VERBOSE, "Using intra and P-frames "
+ "(supported references: %d / %d).\n", ref_l0, ref_l1);
+ ctx->gop_size = avctx->gop_size;
+ ctx->p_per_i = INT_MAX;
+ ctx->b_per_p = 0;
+ } else {
+ if (ctx->p_to_gpb)
+ av_log(avctx, AV_LOG_VERBOSE, "Using intra and B-frames "
+ "(supported references: %d / %d).\n",
+ ref_l0, ref_l1);
+ else
+ av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames "
+ "(supported references: %d / %d).\n", ref_l0, ref_l1);
+ ctx->gop_size = avctx->gop_size;
+ ctx->p_per_i = INT_MAX;
+ ctx->b_per_p = avctx->max_b_frames;
+ if (flags & FF_HW_FLAG_B_PICTURE_REFERENCES) {
+ ctx->max_b_depth = FFMIN(ctx->desired_b_depth,
+ av_log2(ctx->b_per_p) + 1);
+ } else {
+ ctx->max_b_depth = 1;
+ }
+ }
+
+ if (flags & FF_HW_FLAG_NON_IDR_KEY_PICTURES) {
+ ctx->closed_gop = !!(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP);
+ ctx->gop_per_idr = ctx->idr_interval + 1;
+ } else {
+ ctx->closed_gop = 1;
+ ctx->gop_per_idr = 1;
+ }
+
+ return 0;
+}
+
int ff_hw_base_encode_init(AVCodecContext *avctx)
{
FFHWBaseEncodeContext *ctx = avctx->priv_data;