summaryrefslogtreecommitdiff
path: root/libavcodec/vaapi_encode_h265.c
diff options
context:
space:
mode:
authorLinjie Fu <linjie.fu@intel.com>2022-03-17 14:41:49 +0800
committerHaihao Xiang <haihao.xiang@intel.com>2022-04-11 11:38:43 +0800
commita285968a0b122484635846babd9a1e8183e70fb0 (patch)
tree7e3833f6192a743095fd7f51a2dbbaccfa82c0a2 /libavcodec/vaapi_encode_h265.c
parent6e45acd23b6b5062f548c2551b1a64cc268eb787 (diff)
downloadffmpeg-a285968a0b122484635846babd9a1e8183e70fb0.tar.gz
lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi
Use GPB frames to replace regular P/B frames if backend driver does not support it. - GPB: Generalized P and B picture. Regular P/B frames replaced by B frames with previous-predict only, L0 == L1. Normal B frames still have 2 different ref_lists and allow bi-prediction Signed-off-by: Linjie Fu <linjie.fu@intel.com> Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Diffstat (limited to 'libavcodec/vaapi_encode_h265.c')
-rw-r--r--libavcodec/vaapi_encode_h265.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 0be32588c0..76d67237d2 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -886,6 +886,7 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
VAAPIEncodeSlice *slice)
{
+ VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeH265Context *priv = avctx->priv_data;
VAAPIEncodeH265Picture *hpic = pic->priv_data;
const H265RawSPS *sps = &priv->raw_sps;
@@ -908,6 +909,9 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
sh->slice_type = hpic->slice_type;
+ if (sh->slice_type == HEVC_SLICE_P && ctx->p_to_gpb)
+ sh->slice_type = HEVC_SLICE_B;
+
sh->slice_pic_order_cnt_lsb = hpic->pic_order_cnt &
(1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1;
@@ -1066,6 +1070,9 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
av_assert0(pic->type == PICTURE_TYPE_P ||
pic->type == PICTURE_TYPE_B);
vslice->ref_pic_list0[0] = vpic->reference_frames[0];
+ if (ctx->p_to_gpb && pic->type == PICTURE_TYPE_P)
+ // Reference for GPB B-frame, L0 == L1
+ vslice->ref_pic_list1[0] = vpic->reference_frames[0];
}
if (pic->nb_refs >= 2) {
// Forward reference for B-frame.
@@ -1073,6 +1080,14 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
vslice->ref_pic_list1[0] = vpic->reference_frames[1];
}
+ if (pic->type == PICTURE_TYPE_P && ctx->p_to_gpb) {
+ vslice->slice_type = HEVC_SLICE_B;
+ for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
+ vslice->ref_pic_list1[i].picture_id = vslice->ref_pic_list0[i].picture_id;
+ vslice->ref_pic_list1[i].flags = vslice->ref_pic_list0[i].flags;
+ }
+ }
+
return 0;
}