Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi
@ 2022-03-17  6:41 Fei Wang
  2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 2/4] vaapi_encode: Move block size calculation after entrypoint selection Fei Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Fei Wang @ 2022-03-17  6:41 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Fei Wang, Linjie Fu

From: Linjie Fu <linjie.fu@intel.com>

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>
---
update:
1. fall back logic that implemented in v3.
2. refine debug message.

 libavcodec/vaapi_encode.c      | 67 +++++++++++++++++++++++++++++++---
 libavcodec/vaapi_encode.h      |  1 +
 libavcodec/vaapi_encode_h265.c | 15 ++++++++
 3 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 3bf379b1a0..081eb475a3 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1827,6 +1827,7 @@ static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx)
     VAStatus vas;
     VAConfigAttrib attr = { VAConfigAttribEncMaxRefFrames };
     uint32_t ref_l0, ref_l1;
+    int prediction_pre_only;
 
     vas = vaGetConfigAttributes(ctx->hwctx->display,
                                 ctx->va_profile,
@@ -1845,6 +1846,51 @@ static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx)
         ref_l1 = attr.value >> 16 & 0xffff;
     }
 
+    ctx->p_to_gpb = 0;
+    prediction_pre_only = 0;
+
+#if VA_CHECK_VERSION(1, 9, 0)
+    if (!(ctx->codec->flags & FLAG_INTRA_ONLY ||
+        avctx->gop_size <= 1)) {
+        attr = (VAConfigAttrib) { VAConfigAttribPredictionDirection };
+        vas = vaGetConfigAttributes(ctx->hwctx->display,
+                                    ctx->va_profile,
+                                    ctx->va_entrypoint,
+                                    &attr, 1);
+        if (vas != VA_STATUS_SUCCESS) {
+            av_log(avctx, AV_LOG_WARNING, "Failed to query prediction direction "
+                   "attribute: %d (%s).\n", vas, vaErrorStr(vas));
+            return AVERROR_EXTERNAL;
+        } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+            av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any additional "
+                   "prediction constraints.\n");
+        } else {
+            if (((ref_l0 > 0 || ref_l1 > 0) && !(attr.value & VA_PREDICTION_DIRECTION_PREVIOUS)) ||
+                ((ref_l1 == 0) && (attr.value & (VA_PREDICTION_DIRECTION_FUTURE | VA_PREDICTION_DIRECTION_BI_NOT_EMPTY)))) {
+                av_log(avctx, AV_LOG_ERROR, "Driver report incorrect prediction "
+                       "direction attribute.\n");
+                return AVERROR_EXTERNAL;
+            }
+
+            if (!(attr.value & VA_PREDICTION_DIRECTION_FUTURE)) {
+                if (ref_l0 > 0 && ref_l1 > 0) {
+                    prediction_pre_only = 1;
+                    av_log(avctx, AV_LOG_VERBOSE, "Driver only support same reference "
+                           "lists for B-frames.\n");
+                }
+            }
+
+            if (attr.value & VA_PREDICTION_DIRECTION_BI_NOT_EMPTY) {
+                if (ref_l0 > 0 && ref_l1 > 0) {
+                    ctx->p_to_gpb = 1;
+                    av_log(avctx, AV_LOG_VERBOSE, "Driver does not support P-frames, "
+                           "replacing them with B-frames.\n");
+                }
+            }
+        }
+    }
+#endif
+
     if (ctx->codec->flags & FLAG_INTRA_ONLY ||
         avctx->gop_size <= 1) {
         av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n");
@@ -1854,15 +1900,26 @@ static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx)
                "reference frames.\n");
         return AVERROR(EINVAL);
     } else if (!(ctx->codec->flags & FLAG_B_PICTURES) ||
-               ref_l1 < 1 || avctx->max_b_frames < 1) {
-        av_log(avctx, AV_LOG_VERBOSE, "Using intra and P-frames "
-               "(supported references: %d / %d).\n", ref_l0, ref_l1);
+               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 {
-        av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames "
-               "(supported references: %d / %d).\n", ref_l0, ref_l1);
+       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;
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index b41604a883..61c5615eb8 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -328,6 +328,7 @@ typedef struct VAAPIEncodeContext {
     int idr_counter;
     int gop_counter;
     int end_of_stream;
+    int p_to_gpb;
 
     // Whether the driver supports ROI at all.
     int             roi_allowed;
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index e1dc53dfa9..ea45893508 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;
 }
 
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH v5 2/4] vaapi_encode: Move block size calculation after entrypoint selection
  2022-03-17  6:41 [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi Fei Wang
@ 2022-03-17  6:41 ` Fei Wang
  2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 3/4] vaapi_encode_h265: Explicitly set and correct some flags Fei Wang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Fei Wang @ 2022-03-17  6:41 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Mark Thompson, Fei Wang

From: Mark Thompson <sw@jkqxz.net>

The block size can be dependent on the profile and entrypoint selected.
It defaults to 16x16, with codecs able to override this choice with their
own function.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
 libavcodec/vaapi_encode.c       | 16 ++++++++++++++++
 libavcodec/vaapi_encode.h       |  7 +++++++
 libavcodec/vaapi_encode_h265.c  | 32 ++++++++++++++++++++++++++------
 libavcodec/vaapi_encode_mjpeg.c | 18 +++++++++++++++---
 libavcodec/vaapi_encode_mpeg2.c |  3 ---
 libavcodec/vaapi_encode_vp8.c   |  3 ---
 libavcodec/vaapi_encode_vp9.c   | 16 ++++++++++++----
 7 files changed, 76 insertions(+), 19 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 081eb475a3..3148c8915e 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -2069,6 +2069,8 @@ static av_cold int vaapi_encode_init_slice_structure(AVCodecContext *avctx)
         return 0;
     }
 
+    av_assert0(ctx->slice_block_height > 0 && ctx->slice_block_width > 0);
+
     ctx->slice_block_rows = (avctx->height + ctx->slice_block_height - 1) /
                              ctx->slice_block_height;
     ctx->slice_block_cols = (avctx->width  + ctx->slice_block_width  - 1) /
@@ -2458,6 +2460,20 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
     if (err < 0)
         goto fail;
 
+    if (ctx->codec->get_encoder_caps) {
+        err = ctx->codec->get_encoder_caps(avctx);
+        if (err < 0)
+            goto fail;
+    } else {
+        // Assume 16x16 blocks.
+        ctx->surface_width  = FFALIGN(avctx->width,  16);
+        ctx->surface_height = FFALIGN(avctx->height, 16);
+        if (ctx->codec->flags & FLAG_SLICE_CONTROL) {
+            ctx->slice_block_width  = 16;
+            ctx->slice_block_height = 16;
+        }
+    }
+
     err = vaapi_encode_init_rate_control(avctx);
     if (err < 0)
         goto fail;
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 61c5615eb8..f0021acccf 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -376,6 +376,13 @@ typedef struct VAAPIEncodeType {
     // factor depending on RC mode.
     int default_quality;
 
+    // Determine encode parameters like block sizes for surface alignment
+    // and slices. This may need to query the profile and entrypoint,
+    // which will be available when this function is called. If not set,
+    // assume that all blocks are 16x16 and that surfaces should be
+    // aligned to match this.
+    int (*get_encoder_caps)(AVCodecContext *avctx);
+
     // Perform any extra codec-specific configuration after the
     // codec context is initialised (set up the private data and
     // add any necessary global parameters).
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index ea45893508..706ec5d849 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -55,6 +55,10 @@ typedef struct VAAPIEncodeH265Picture {
 typedef struct VAAPIEncodeH265Context {
     VAAPIEncodeContext common;
 
+    // Encoder features.
+    uint32_t ctu_size;
+    uint32_t min_cb_size;
+
     // User options.
     int qp;
     int aud;
@@ -1091,6 +1095,27 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
     return 0;
 }
 
+static av_cold int vaapi_encode_h265_get_encoder_caps(AVCodecContext *avctx)
+{
+    VAAPIEncodeContext      *ctx = avctx->priv_data;
+    VAAPIEncodeH265Context *priv = avctx->priv_data;
+
+    if (!priv->ctu_size) {
+        priv->ctu_size     = 32;
+        priv->min_cb_size  = 16;
+    }
+    av_log(avctx, AV_LOG_VERBOSE, "Using CTU size %dx%d, "
+           "min CB size %dx%d.\n", priv->ctu_size, priv->ctu_size,
+           priv->min_cb_size, priv->min_cb_size);
+
+    ctx->surface_width  = FFALIGN(avctx->width,  priv->min_cb_size);
+    ctx->surface_height = FFALIGN(avctx->height, priv->min_cb_size);
+
+    ctx->slice_block_width = ctx->slice_block_height = priv->ctu_size;
+
+    return 0;
+}
+
 static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
 {
     VAAPIEncodeContext      *ctx = avctx->priv_data;
@@ -1160,6 +1185,7 @@ static const VAAPIEncodeType vaapi_encode_type_h265 = {
 
     .default_quality       = 25,
 
+    .get_encoder_caps      = &vaapi_encode_h265_get_encoder_caps,
     .configure             = &vaapi_encode_h265_configure,
 
     .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
@@ -1205,12 +1231,6 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
         VA_ENC_PACKED_HEADER_SLICE    | // Slice headers.
         VA_ENC_PACKED_HEADER_MISC;      // SEI
 
-    ctx->surface_width  = FFALIGN(avctx->width,  16);
-    ctx->surface_height = FFALIGN(avctx->height, 16);
-
-    // CTU size is currently hard-coded to 32.
-    ctx->slice_block_width = ctx->slice_block_height = 32;
-
     if (priv->qp > 0)
         ctx->explicit_qp = priv->qp;
 
diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index 6206b23e5f..87a03f181b 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -434,6 +434,20 @@ static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx,
     return 0;
 }
 
+static av_cold int vaapi_encode_mjpeg_get_encoder_caps(AVCodecContext *avctx)
+{
+    VAAPIEncodeContext *ctx = avctx->priv_data;
+    const AVPixFmtDescriptor *desc;
+
+    desc = av_pix_fmt_desc_get(ctx->input_frames->sw_format);
+    av_assert0(desc);
+
+    ctx->surface_width  = FFALIGN(avctx->width,  8 << desc->log2_chroma_w);
+    ctx->surface_height = FFALIGN(avctx->height, 8 << desc->log2_chroma_h);
+
+    return 0;
+}
+
 static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
 {
     VAAPIEncodeContext       *ctx = avctx->priv_data;
@@ -483,6 +497,7 @@ static const VAAPIEncodeType vaapi_encode_type_mjpeg = {
     .flags                 = FLAG_CONSTANT_QUALITY_ONLY |
                              FLAG_INTRA_ONLY,
 
+    .get_encoder_caps      = &vaapi_encode_mjpeg_get_encoder_caps,
     .configure             = &vaapi_encode_mjpeg_configure,
 
     .default_quality       = 80,
@@ -509,9 +524,6 @@ static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx)
     ctx->desired_packed_headers =
         VA_ENC_PACKED_HEADER_RAW_DATA;
 
-    ctx->surface_width  = FFALIGN(avctx->width,  8);
-    ctx->surface_height = FFALIGN(avctx->height, 8);
-
     return ff_vaapi_encode_init(avctx);
 }
 
diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index d084d8c4b9..f8809b08ab 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -623,9 +623,6 @@ static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx)
     ctx->desired_packed_headers = VA_ENC_PACKED_HEADER_SEQUENCE |
                                   VA_ENC_PACKED_HEADER_PICTURE;
 
-    ctx->surface_width  = FFALIGN(avctx->width,  16);
-    ctx->surface_height = FFALIGN(avctx->height, 16);
-
     return ff_vaapi_encode_init(avctx);
 }
 
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index 7d4578f674..ab3c84a618 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -210,9 +210,6 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext *avctx)
     // adding them anyway.
     ctx->desired_packed_headers = 0;
 
-    ctx->surface_width  = FFALIGN(avctx->width,  16);
-    ctx->surface_height = FFALIGN(avctx->height, 16);
-
     return ff_vaapi_encode_init(avctx);
 }
 
diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index be706e3bd6..837adaa825 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -184,6 +184,17 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
     return 0;
 }
 
+static av_cold int vaapi_encode_vp9_get_encoder_caps(AVCodecContext *avctx)
+{
+    VAAPIEncodeContext *ctx = avctx->priv_data;
+
+    // Surfaces must be aligned to 64x64 superblock boundaries.
+    ctx->surface_width  = FFALIGN(avctx->width,  64);
+    ctx->surface_height = FFALIGN(avctx->height, 64);
+
+    return 0;
+}
+
 static av_cold int vaapi_encode_vp9_configure(AVCodecContext *avctx)
 {
     VAAPIEncodeContext     *ctx = avctx->priv_data;
@@ -231,6 +242,7 @@ static const VAAPIEncodeType vaapi_encode_type_vp9 = {
 
     .picture_priv_data_size = sizeof(VAAPIEncodeVP9Picture),
 
+    .get_encoder_caps      = &vaapi_encode_vp9_get_encoder_caps,
     .configure             = &vaapi_encode_vp9_configure,
 
     .sequence_params_size  = sizeof(VAEncSequenceParameterBufferVP9),
@@ -251,10 +263,6 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx)
     // can write its own headers and there is no metadata to include.
     ctx->desired_packed_headers = 0;
 
-    // Surfaces must be aligned to superblock boundaries.
-    ctx->surface_width  = FFALIGN(avctx->width,  64);
-    ctx->surface_height = FFALIGN(avctx->height, 64);
-
     return ff_vaapi_encode_init(avctx);
 }
 
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH v5 3/4] vaapi_encode_h265: Explicitly set and correct some flags
  2022-03-17  6:41 [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi Fei Wang
  2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 2/4] vaapi_encode: Move block size calculation after entrypoint selection Fei Wang
@ 2022-03-17  6:41 ` Fei Wang
  2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 4/4] vaapi_encode_h265: Query encoding block sizes and features Fei Wang
  2022-03-29 12:44 ` [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi Xiang, Haihao
  3 siblings, 0 replies; 7+ messages in thread
From: Fei Wang @ 2022-03-17  6:41 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Mark Thompson, Fei Wang

From: Mark Thompson <sw@jkqxz.net>

max_14bit_constraint_flag should be set if the bit depth is not greater than
14 (currently always true).

one_picture_only_flag should not be set because we don't support the still
picture profiles.

general_profile_compatibility_flag should be set according to general_profile_idc
instead of bit depth.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
 libavcodec/vaapi_encode_h265.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 706ec5d849..cafc860772 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -303,17 +303,21 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
     ptl->general_profile_idc   = avctx->profile;
     ptl->general_tier_flag     = priv->tier;
 
-    if (chroma_format == 1) {
-        ptl->general_profile_compatibility_flag[1] = bit_depth ==  8;
-        ptl->general_profile_compatibility_flag[2] = bit_depth <= 10;
+    ptl->general_profile_compatibility_flag[ptl->general_profile_idc] = 1;
+
+    if (ptl->general_profile_compatibility_flag[1])
+        ptl->general_profile_compatibility_flag[2] = 1;
+    if (ptl->general_profile_compatibility_flag[3]) {
+        ptl->general_profile_compatibility_flag[1] = 1;
+        ptl->general_profile_compatibility_flag[2] = 1;
     }
-    ptl->general_profile_compatibility_flag[4] = 1;
 
     ptl->general_progressive_source_flag    = 1;
     ptl->general_interlaced_source_flag     = 0;
     ptl->general_non_packed_constraint_flag = 1;
     ptl->general_frame_only_constraint_flag = 1;
 
+    ptl->general_max_14bit_constraint_flag = bit_depth <= 14;
     ptl->general_max_12bit_constraint_flag = bit_depth <= 12;
     ptl->general_max_10bit_constraint_flag = bit_depth <= 10;
     ptl->general_max_8bit_constraint_flag  = bit_depth ==  8;
@@ -323,6 +327,7 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
     ptl->general_max_monochrome_constraint_flag = chroma_format == 0;
 
     ptl->general_intra_constraint_flag = ctx->gop_size == 1;
+    ptl->general_one_picture_only_constraint_flag = 0;
 
     ptl->general_lower_bit_rate_constraint_flag = 1;
 
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH v5 4/4] vaapi_encode_h265: Query encoding block sizes and features
  2022-03-17  6:41 [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi Fei Wang
  2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 2/4] vaapi_encode: Move block size calculation after entrypoint selection Fei Wang
  2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 3/4] vaapi_encode_h265: Explicitly set and correct some flags Fei Wang
@ 2022-03-17  6:41 ` Fei Wang
  2022-03-29 12:44 ` [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi Xiang, Haihao
  3 siblings, 0 replies; 7+ messages in thread
From: Fei Wang @ 2022-03-17  6:41 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Mark Thompson, Fei Wang

From: Mark Thompson <sw@jkqxz.net>

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
 libavcodec/vaapi_encode_h265.c | 114 +++++++++++++++++++++++++++++++--
 1 file changed, 108 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index cafc860772..ad138b6ddb 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -56,6 +56,9 @@ typedef struct VAAPIEncodeH265Context {
     VAAPIEncodeContext common;
 
     // Encoder features.
+    uint32_t va_features;
+    // Block size info.
+    uint32_t va_bs;
     uint32_t ctu_size;
     uint32_t min_cb_size;
 
@@ -427,9 +430,9 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
             vps->vps_max_latency_increase_plus1[i];
     }
 
-    // These have to come from the capabilities of the encoder.  We have no
-    // way to query them, so just hardcode parameters which work on the Intel
-    // driver.
+    // These values come from the capabilities of the first encoder
+    // implementation in the i965 driver on Intel Skylake.  They may
+    // fail badly with other platforms or drivers.
     // CTB size from 8x8 to 32x32.
     sps->log2_min_luma_coding_block_size_minus3   = 0;
     sps->log2_diff_max_min_luma_coding_block_size = 2;
@@ -447,6 +450,42 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 
     sps->pcm_enabled_flag = 0;
 
+// update sps setting according to queried result
+#if VA_CHECK_VERSION(1, 13, 0)
+    if (priv->va_features) {
+        VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features };
+
+        // Enable feature if get queried result is VA_FEATURE_SUPPORTED | VA_FEATURE_REQUIRED
+        sps->amp_enabled_flag =
+            !!features.bits.amp;
+        sps->sample_adaptive_offset_enabled_flag =
+            !!features.bits.sao;
+        sps->sps_temporal_mvp_enabled_flag =
+            !!features.bits.temporal_mvp;
+        sps->pcm_enabled_flag =
+            !!features.bits.pcm;
+    }
+
+    if (priv->va_bs) {
+        VAConfigAttribValEncHEVCBlockSizes bs = { .value = priv->va_bs };
+        sps->log2_min_luma_coding_block_size_minus3 =
+            ff_ctz(priv->min_cb_size) - 3;
+        sps->log2_diff_max_min_luma_coding_block_size =
+            ff_ctz(priv->ctu_size) - ff_ctz(priv->min_cb_size);
+
+        sps->log2_min_luma_transform_block_size_minus2 =
+            bs.bits.log2_min_luma_transform_block_size_minus2;
+        sps->log2_diff_max_min_luma_transform_block_size =
+            bs.bits.log2_max_luma_transform_block_size_minus2 -
+            bs.bits.log2_min_luma_transform_block_size_minus2;
+
+        sps->max_transform_hierarchy_depth_inter =
+            bs.bits.max_max_transform_hierarchy_depth_inter;
+        sps->max_transform_hierarchy_depth_intra =
+            bs.bits.max_max_transform_hierarchy_depth_intra;
+    }
+#endif
+
     // STRPSs should ideally be here rather than defined individually in
     // each slice, but the structure isn't completely fixed so for now
     // don't bother.
@@ -539,6 +578,23 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
     pps->cu_qp_delta_enabled_flag = (ctx->va_rc_mode != VA_RC_CQP);
     pps->diff_cu_qp_delta_depth   = 0;
 
+// update pps setting according to queried result
+#if VA_CHECK_VERSION(1, 13, 0)
+    if (priv->va_features) {
+        VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features };
+        if (ctx->va_rc_mode != VA_RC_CQP)
+            pps->cu_qp_delta_enabled_flag =
+                !!features.bits.cu_qp_delta;
+
+        pps->transform_skip_enabled_flag =
+            !!features.bits.transform_skip;
+        // set diff_cu_qp_delta_depth as its max value if cu_qp_delta enabled. Otherwise
+        // 0 will make cu_qp_delta invalid.
+        if (pps->cu_qp_delta_enabled_flag)
+            pps->diff_cu_qp_delta_depth = sps->log2_diff_max_min_luma_coding_block_size;
+    }
+#endif
+
     if (ctx->tile_rows && ctx->tile_cols) {
         int uniform_spacing;
 
@@ -640,8 +696,8 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 
         .coded_buf = VA_INVALID_ID,
 
-        .collocated_ref_pic_index = 0xff,
-
+        .collocated_ref_pic_index = sps->sps_temporal_mvp_enabled_flag ?
+                                    0 : 0xff,
         .last_picture = 0,
 
         .pic_init_qp            = pps->init_qp_minus26 + 26,
@@ -674,6 +730,8 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
             .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
             .loop_filter_across_tiles_enabled_flag =
                 pps->loop_filter_across_tiles_enabled_flag,
+            .pps_loop_filter_across_slices_enabled_flag =
+                pps->pps_loop_filter_across_slices_enabled_flag,
             .scaling_list_data_present_flag = (sps->sps_scaling_list_data_present_flag |
                                                pps->pps_scaling_list_data_present_flag),
             .screen_content_flag            = 0,
@@ -1001,10 +1059,13 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
         sh->num_long_term_sps  = 0;
         sh->num_long_term_pics = 0;
 
+        // when this flag is not present, it is inerred to 1.
+        sh->collocated_from_l0_flag = 1;
         sh->slice_temporal_mvp_enabled_flag =
             sps->sps_temporal_mvp_enabled_flag;
         if (sh->slice_temporal_mvp_enabled_flag) {
-            sh->collocated_from_l0_flag = sh->slice_type == HEVC_SLICE_B;
+            if (sh->slice_type == HEVC_SLICE_B)
+                sh->collocated_from_l0_flag = 1;
             sh->collocated_ref_idx      = 0;
         }
 
@@ -1105,6 +1166,47 @@ static av_cold int vaapi_encode_h265_get_encoder_caps(AVCodecContext *avctx)
     VAAPIEncodeContext      *ctx = avctx->priv_data;
     VAAPIEncodeH265Context *priv = avctx->priv_data;
 
+#if VA_CHECK_VERSION(1, 13, 0)
+    {
+        VAConfigAttribValEncHEVCBlockSizes block_size;
+        VAConfigAttrib attr;
+        VAStatus vas;
+
+        attr.type = VAConfigAttribEncHEVCFeatures;
+        vas = vaGetConfigAttributes(ctx->hwctx->display, ctx->va_profile,
+                                    ctx->va_entrypoint, &attr, 1);
+        if (vas != VA_STATUS_SUCCESS) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to query encoder "
+                   "features, using guessed defaults.\n");
+            return AVERROR_EXTERNAL;
+        } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+            av_log(avctx, AV_LOG_WARNING, "Driver does not advertise "
+                   "encoder features, using guessed defaults.\n");
+        } else {
+            priv->va_features = attr.value;
+        }
+
+        attr.type = VAConfigAttribEncHEVCBlockSizes;
+        vas = vaGetConfigAttributes(ctx->hwctx->display, ctx->va_profile,
+                                    ctx->va_entrypoint, &attr, 1);
+        if (vas != VA_STATUS_SUCCESS) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to query encoder "
+                   "block size, using guessed defaults.\n");
+            return AVERROR_EXTERNAL;
+        } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+            av_log(avctx, AV_LOG_WARNING, "Driver does not advertise "
+                   "encoder block size, using guessed defaults.\n");
+        } else {
+            priv->va_bs = block_size.value = attr.value;
+
+            priv->ctu_size =
+                1 << block_size.bits.log2_max_coding_tree_block_size_minus3 + 3;
+            priv->min_cb_size =
+                1 << block_size.bits.log2_min_luma_coding_block_size_minus3 + 3;
+        }
+    }
+#endif
+
     if (!priv->ctu_size) {
         priv->ctu_size     = 32;
         priv->min_cb_size  = 16;
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi
  2022-03-17  6:41 [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi Fei Wang
                   ` (2 preceding siblings ...)
  2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 4/4] vaapi_encode_h265: Query encoding block sizes and features Fei Wang
@ 2022-03-29 12:44 ` Xiang, Haihao
  2022-04-06  8:31   ` Xiang, Haihao
  3 siblings, 1 reply; 7+ messages in thread
From: Xiang, Haihao @ 2022-03-29 12:44 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wang, Fei W, linjie.fu

On Thu, 2022-03-17 at 14:41 +0800, Fei Wang wrote:
> From: Linjie Fu <linjie.fu@intel.com>
> 
> 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>
> ---
> update:
> 1. fall back logic that implemented in v3.
> 2. refine debug message.
> 
>  libavcodec/vaapi_encode.c      | 67 +++++++++++++++++++++++++++++++---
>  libavcodec/vaapi_encode.h      |  1 +
>  libavcodec/vaapi_encode_h265.c | 15 ++++++++
>  3 files changed, 78 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 3bf379b1a0..081eb475a3 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -1827,6 +1827,7 @@ static av_cold int
> vaapi_encode_init_gop_structure(AVCodecContext *avctx)
>      VAStatus vas;
>      VAConfigAttrib attr = { VAConfigAttribEncMaxRefFrames };
>      uint32_t ref_l0, ref_l1;
> +    int prediction_pre_only;
>  
>      vas = vaGetConfigAttributes(ctx->hwctx->display,
>                                  ctx->va_profile,
> @@ -1845,6 +1846,51 @@ static av_cold int
> vaapi_encode_init_gop_structure(AVCodecContext *avctx)
>          ref_l1 = attr.value >> 16 & 0xffff;
>      }
>  
> +    ctx->p_to_gpb = 0;
> +    prediction_pre_only = 0;
> +
> +#if VA_CHECK_VERSION(1, 9, 0)
> +    if (!(ctx->codec->flags & FLAG_INTRA_ONLY ||
> +        avctx->gop_size <= 1)) {
> +        attr = (VAConfigAttrib) { VAConfigAttribPredictionDirection };
> +        vas = vaGetConfigAttributes(ctx->hwctx->display,
> +                                    ctx->va_profile,
> +                                    ctx->va_entrypoint,
> +                                    &attr, 1);
> +        if (vas != VA_STATUS_SUCCESS) {
> +            av_log(avctx, AV_LOG_WARNING, "Failed to query prediction
> direction "
> +                   "attribute: %d (%s).\n", vas, vaErrorStr(vas));
> +            return AVERROR_EXTERNAL;
> +        } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
> +            av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any
> additional "
> +                   "prediction constraints.\n");
> +        } else {
> +            if (((ref_l0 > 0 || ref_l1 > 0) && !(attr.value &
> VA_PREDICTION_DIRECTION_PREVIOUS)) ||
> +                ((ref_l1 == 0) && (attr.value &
> (VA_PREDICTION_DIRECTION_FUTURE | VA_PREDICTION_DIRECTION_BI_NOT_EMPTY)))) {
> +                av_log(avctx, AV_LOG_ERROR, "Driver report incorrect
> prediction "
> +                       "direction attribute.\n");
> +                return AVERROR_EXTERNAL;
> +            }
> +
> +            if (!(attr.value & VA_PREDICTION_DIRECTION_FUTURE)) {
> +                if (ref_l0 > 0 && ref_l1 > 0) {
> +                    prediction_pre_only = 1;
> +                    av_log(avctx, AV_LOG_VERBOSE, "Driver only support same
> reference "
> +                           "lists for B-frames.\n");
> +                }
> +            }
> +
> +            if (attr.value & VA_PREDICTION_DIRECTION_BI_NOT_EMPTY) {
> +                if (ref_l0 > 0 && ref_l1 > 0) {
> +                    ctx->p_to_gpb = 1;
> +                    av_log(avctx, AV_LOG_VERBOSE, "Driver does not support P-
> frames, "
> +                           "replacing them with B-frames.\n");
> +                }
> +            }
> +        }
> +    }
> +#endif
> +
>      if (ctx->codec->flags & FLAG_INTRA_ONLY ||
>          avctx->gop_size <= 1) {
>          av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n");
> @@ -1854,15 +1900,26 @@ static av_cold int
> vaapi_encode_init_gop_structure(AVCodecContext *avctx)
>                 "reference frames.\n");
>          return AVERROR(EINVAL);
>      } else if (!(ctx->codec->flags & FLAG_B_PICTURES) ||
> -               ref_l1 < 1 || avctx->max_b_frames < 1) {
> -        av_log(avctx, AV_LOG_VERBOSE, "Using intra and P-frames "
> -               "(supported references: %d / %d).\n", ref_l0, ref_l1);
> +               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 {
> -        av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames "
> -               "(supported references: %d / %d).\n", ref_l0, ref_l1);
> +       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;
> diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
> index b41604a883..61c5615eb8 100644
> --- a/libavcodec/vaapi_encode.h
> +++ b/libavcodec/vaapi_encode.h
> @@ -328,6 +328,7 @@ typedef struct VAAPIEncodeContext {
>      int idr_counter;
>      int gop_counter;
>      int end_of_stream;
> +    int p_to_gpb;
>  
>      // Whether the driver supports ROI at all.
>      int             roi_allowed;
> diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
> index e1dc53dfa9..ea45893508 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;
>  }

Hi Mark,

The new patchset version LGTM and works well, do you have any comment?

Thanks
Haihao
 

>  
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi
  2022-03-29 12:44 ` [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi Xiang, Haihao
@ 2022-04-06  8:31   ` Xiang, Haihao
  2022-04-11  3:50     ` Xiang, Haihao
  0 siblings, 1 reply; 7+ messages in thread
From: Xiang, Haihao @ 2022-04-06  8:31 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wang, Fei W, linjie.fu

On Tue, 2022-03-29 at 12:44 +0000, Xiang, Haihao wrote:
> On Thu, 2022-03-17 at 14:41 +0800, Fei Wang wrote:
> > From: Linjie Fu <linjie.fu@intel.com>
> > 
> > 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>
> > ---
> > update:
> > 1. fall back logic that implemented in v3.
> > 2. refine debug message.
> > 
> >  libavcodec/vaapi_encode.c      | 67 +++++++++++++++++++++++++++++++---
> >  libavcodec/vaapi_encode.h      |  1 +
> >  libavcodec/vaapi_encode_h265.c | 15 ++++++++
> >  3 files changed, 78 insertions(+), 5 deletions(-)
> > 
> > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> > index 3bf379b1a0..081eb475a3 100644
> > --- a/libavcodec/vaapi_encode.c
> > +++ b/libavcodec/vaapi_encode.c
> > @@ -1827,6 +1827,7 @@ static av_cold int
> > vaapi_encode_init_gop_structure(AVCodecContext *avctx)
> >      VAStatus vas;
> >      VAConfigAttrib attr = { VAConfigAttribEncMaxRefFrames };
> >      uint32_t ref_l0, ref_l1;
> > +    int prediction_pre_only;
> >  
> >      vas = vaGetConfigAttributes(ctx->hwctx->display,
> >                                  ctx->va_profile,
> > @@ -1845,6 +1846,51 @@ static av_cold int
> > vaapi_encode_init_gop_structure(AVCodecContext *avctx)
> >          ref_l1 = attr.value >> 16 & 0xffff;
> >      }
> >  
> > +    ctx->p_to_gpb = 0;
> > +    prediction_pre_only = 0;
> > +
> > +#if VA_CHECK_VERSION(1, 9, 0)
> > +    if (!(ctx->codec->flags & FLAG_INTRA_ONLY ||
> > +        avctx->gop_size <= 1)) {
> > +        attr = (VAConfigAttrib) { VAConfigAttribPredictionDirection };
> > +        vas = vaGetConfigAttributes(ctx->hwctx->display,
> > +                                    ctx->va_profile,
> > +                                    ctx->va_entrypoint,
> > +                                    &attr, 1);
> > +        if (vas != VA_STATUS_SUCCESS) {
> > +            av_log(avctx, AV_LOG_WARNING, "Failed to query prediction
> > direction "
> > +                   "attribute: %d (%s).\n", vas, vaErrorStr(vas));
> > +            return AVERROR_EXTERNAL;
> > +        } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
> > +            av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any
> > additional "
> > +                   "prediction constraints.\n");
> > +        } else {
> > +            if (((ref_l0 > 0 || ref_l1 > 0) && !(attr.value &
> > VA_PREDICTION_DIRECTION_PREVIOUS)) ||
> > +                ((ref_l1 == 0) && (attr.value &
> > (VA_PREDICTION_DIRECTION_FUTURE | VA_PREDICTION_DIRECTION_BI_NOT_EMPTY)))) {
> > +                av_log(avctx, AV_LOG_ERROR, "Driver report incorrect
> > prediction "
> > +                       "direction attribute.\n");
> > +                return AVERROR_EXTERNAL;
> > +            }
> > +
> > +            if (!(attr.value & VA_PREDICTION_DIRECTION_FUTURE)) {
> > +                if (ref_l0 > 0 && ref_l1 > 0) {
> > +                    prediction_pre_only = 1;
> > +                    av_log(avctx, AV_LOG_VERBOSE, "Driver only support same
> > reference "
> > +                           "lists for B-frames.\n");
> > +                }
> > +            }
> > +
> > +            if (attr.value & VA_PREDICTION_DIRECTION_BI_NOT_EMPTY) {
> > +                if (ref_l0 > 0 && ref_l1 > 0) {
> > +                    ctx->p_to_gpb = 1;
> > +                    av_log(avctx, AV_LOG_VERBOSE, "Driver does not support
> > P-
> > frames, "
> > +                           "replacing them with B-frames.\n");
> > +                }
> > +            }
> > +        }
> > +    }
> > +#endif
> > +
> >      if (ctx->codec->flags & FLAG_INTRA_ONLY ||
> >          avctx->gop_size <= 1) {
> >          av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n");
> > @@ -1854,15 +1900,26 @@ static av_cold int
> > vaapi_encode_init_gop_structure(AVCodecContext *avctx)
> >                 "reference frames.\n");
> >          return AVERROR(EINVAL);
> >      } else if (!(ctx->codec->flags & FLAG_B_PICTURES) ||
> > -               ref_l1 < 1 || avctx->max_b_frames < 1) {
> > -        av_log(avctx, AV_LOG_VERBOSE, "Using intra and P-frames "
> > -               "(supported references: %d / %d).\n", ref_l0, ref_l1);
> > +               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 {
> > -        av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames "
> > -               "(supported references: %d / %d).\n", ref_l0, ref_l1);
> > +       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;
> > diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
> > index b41604a883..61c5615eb8 100644
> > --- a/libavcodec/vaapi_encode.h
> > +++ b/libavcodec/vaapi_encode.h
> > @@ -328,6 +328,7 @@ typedef struct VAAPIEncodeContext {
> >      int idr_counter;
> >      int gop_counter;
> >      int end_of_stream;
> > +    int p_to_gpb;
> >  
> >      // Whether the driver supports ROI at all.
> >      int             roi_allowed;
> > diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
> > index e1dc53dfa9..ea45893508 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;
> >  }
> 
> Hi Mark,
> 
> The new patchset version LGTM and works well, do you have any comment?
> 

Ping, I'll merge this patchset in a few days if no more comments.

Thanks
Haihao

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi
  2022-04-06  8:31   ` Xiang, Haihao
@ 2022-04-11  3:50     ` Xiang, Haihao
  0 siblings, 0 replies; 7+ messages in thread
From: Xiang, Haihao @ 2022-04-11  3:50 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Wang, Fei W, linjie.fu

On Wed, 2022-04-06 at 08:31 +0000, Xiang, Haihao wrote:
> On Tue, 2022-03-29 at 12:44 +0000, Xiang, Haihao wrote:
> > On Thu, 2022-03-17 at 14:41 +0800, Fei Wang wrote:
> > > From: Linjie Fu <linjie.fu@intel.com>
> > > 
> > > 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>
> > > ---
> > > update:
> > > 1. fall back logic that implemented in v3.
> > > 2. refine debug message.
> > > 
> > >  libavcodec/vaapi_encode.c      | 67 +++++++++++++++++++++++++++++++---
> > >  libavcodec/vaapi_encode.h      |  1 +
> > >  libavcodec/vaapi_encode_h265.c | 15 ++++++++
> > >  3 files changed, 78 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> > > index 3bf379b1a0..081eb475a3 100644
> > > --- a/libavcodec/vaapi_encode.c
> > > +++ b/libavcodec/vaapi_encode.c
> > > @@ -1827,6 +1827,7 @@ static av_cold int
> > > vaapi_encode_init_gop_structure(AVCodecContext *avctx)
> > >      VAStatus vas;
> > >      VAConfigAttrib attr = { VAConfigAttribEncMaxRefFrames };
> > >      uint32_t ref_l0, ref_l1;
> > > +    int prediction_pre_only;
> > >  
> > >      vas = vaGetConfigAttributes(ctx->hwctx->display,
> > >                                  ctx->va_profile,
> > > @@ -1845,6 +1846,51 @@ static av_cold int
> > > vaapi_encode_init_gop_structure(AVCodecContext *avctx)
> > >          ref_l1 = attr.value >> 16 & 0xffff;
> > >      }
> > >  
> > > +    ctx->p_to_gpb = 0;
> > > +    prediction_pre_only = 0;
> > > +
> > > +#if VA_CHECK_VERSION(1, 9, 0)
> > > +    if (!(ctx->codec->flags & FLAG_INTRA_ONLY ||
> > > +        avctx->gop_size <= 1)) {
> > > +        attr = (VAConfigAttrib) { VAConfigAttribPredictionDirection };
> > > +        vas = vaGetConfigAttributes(ctx->hwctx->display,
> > > +                                    ctx->va_profile,
> > > +                                    ctx->va_entrypoint,
> > > +                                    &attr, 1);
> > > +        if (vas != VA_STATUS_SUCCESS) {
> > > +            av_log(avctx, AV_LOG_WARNING, "Failed to query prediction
> > > direction "
> > > +                   "attribute: %d (%s).\n", vas, vaErrorStr(vas));
> > > +            return AVERROR_EXTERNAL;
> > > +        } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
> > > +            av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any
> > > additional "
> > > +                   "prediction constraints.\n");
> > > +        } else {
> > > +            if (((ref_l0 > 0 || ref_l1 > 0) && !(attr.value &
> > > VA_PREDICTION_DIRECTION_PREVIOUS)) ||
> > > +                ((ref_l1 == 0) && (attr.value &
> > > (VA_PREDICTION_DIRECTION_FUTURE | VA_PREDICTION_DIRECTION_BI_NOT_EMPTY))))
> > > {
> > > +                av_log(avctx, AV_LOG_ERROR, "Driver report incorrect
> > > prediction "
> > > +                       "direction attribute.\n");
> > > +                return AVERROR_EXTERNAL;
> > > +            }
> > > +
> > > +            if (!(attr.value & VA_PREDICTION_DIRECTION_FUTURE)) {
> > > +                if (ref_l0 > 0 && ref_l1 > 0) {
> > > +                    prediction_pre_only = 1;
> > > +                    av_log(avctx, AV_LOG_VERBOSE, "Driver only support
> > > same
> > > reference "
> > > +                           "lists for B-frames.\n");
> > > +                }
> > > +            }
> > > +
> > > +            if (attr.value & VA_PREDICTION_DIRECTION_BI_NOT_EMPTY) {
> > > +                if (ref_l0 > 0 && ref_l1 > 0) {
> > > +                    ctx->p_to_gpb = 1;
> > > +                    av_log(avctx, AV_LOG_VERBOSE, "Driver does not
> > > support
> > > P-
> > > frames, "
> > > +                           "replacing them with B-frames.\n");
> > > +                }
> > > +            }
> > > +        }
> > > +    }
> > > +#endif
> > > +
> > >      if (ctx->codec->flags & FLAG_INTRA_ONLY ||
> > >          avctx->gop_size <= 1) {
> > >          av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n");
> > > @@ -1854,15 +1900,26 @@ static av_cold int
> > > vaapi_encode_init_gop_structure(AVCodecContext *avctx)
> > >                 "reference frames.\n");
> > >          return AVERROR(EINVAL);
> > >      } else if (!(ctx->codec->flags & FLAG_B_PICTURES) ||
> > > -               ref_l1 < 1 || avctx->max_b_frames < 1) {
> > > -        av_log(avctx, AV_LOG_VERBOSE, "Using intra and P-frames "
> > > -               "(supported references: %d / %d).\n", ref_l0, ref_l1);
> > > +               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 {
> > > -        av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames "
> > > -               "(supported references: %d / %d).\n", ref_l0, ref_l1);
> > > +       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;
> > > diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
> > > index b41604a883..61c5615eb8 100644
> > > --- a/libavcodec/vaapi_encode.h
> > > +++ b/libavcodec/vaapi_encode.h
> > > @@ -328,6 +328,7 @@ typedef struct VAAPIEncodeContext {
> > >      int idr_counter;
> > >      int gop_counter;
> > >      int end_of_stream;
> > > +    int p_to_gpb;
> > >  
> > >      // Whether the driver supports ROI at all.
> > >      int             roi_allowed;
> > > diff --git a/libavcodec/vaapi_encode_h265.c
> > > b/libavcodec/vaapi_encode_h265.c
> > > index e1dc53dfa9..ea45893508 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;
> > >  }
> > 
> > Hi Mark,
> > 
> > The new patchset version LGTM and works well, do you have any comment?
> > 
> 
> Ping, I'll merge this patchset in a few days if no more comments.
> 

Applied, thx

-Haihao


_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-11  3:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-17  6:41 [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi Fei Wang
2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 2/4] vaapi_encode: Move block size calculation after entrypoint selection Fei Wang
2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 3/4] vaapi_encode_h265: Explicitly set and correct some flags Fei Wang
2022-03-17  6:41 ` [FFmpeg-devel] [PATCH v5 4/4] vaapi_encode_h265: Query encoding block sizes and features Fei Wang
2022-03-29 12:44 ` [FFmpeg-devel] [PATCH v5 1/4] lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi Xiang, Haihao
2022-04-06  8:31   ` Xiang, Haihao
2022-04-11  3:50     ` Xiang, Haihao

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git