]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vaapi_encode_vp9.c
vaapi_encode: Add common options between all encoders
[ffmpeg] / libavcodec / vaapi_encode_vp9.c
index 9108699ac383a441a34075debc42d423e71196a4..4d7cec0520ca8830447e61c022b9c65f29f67c92 100644 (file)
 
 
 typedef struct VAAPIEncodeVP9Context {
+    VAAPIEncodeContext common;
+
+    // User options.
+    int loop_filter_level;
+    int loop_filter_sharpness;
+
+    // Derived settings.
     int q_idx_idr;
     int q_idx_p;
     int q_idx_b;
 
+    // Stream state.
+
     // Reference direction for B-like frames:
     // 0 - most recent P/IDR frame is last.
     // 1 - most recent P frame is golden.
     int last_ref_dir;
 } VAAPIEncodeVP9Context;
 
-typedef struct VAAPIEncodeVP9Options {
-    int loop_filter_level;
-    int loop_filter_sharpness;
-} VAAPIEncodeVP9Options;
-
 
 #define vseq_var(name)     vseq->name, name
 #define vseq_field(name)   vseq->seq_fields.bits.name, name
@@ -82,10 +86,8 @@ static int vaapi_encode_vp9_init_sequence_params(AVCodecContext *avctx)
 static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
                                                 VAAPIEncodePicture *pic)
 {
-    VAAPIEncodeContext              *ctx = avctx->priv_data;
+    VAAPIEncodeVP9Context          *priv = avctx->priv_data;
     VAEncPictureParameterBufferVP9 *vpic = pic->codec_picture_params;
-    VAAPIEncodeVP9Context          *priv = ctx->priv_data;
-    VAAPIEncodeVP9Options           *opt = ctx->codec_options;
     int i;
 
     vpic->reconstructed_frame = pic->recon_surface;
@@ -169,8 +171,8 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
     vpic->chroma_ac_qindex_delta = 0;
     vpic->chroma_dc_qindex_delta = 0;
 
-    vpic->filter_level    = opt->loop_filter_level;
-    vpic->sharpness_level = opt->loop_filter_sharpness;
+    vpic->filter_level    = priv->loop_filter_level;
+    vpic->sharpness_level = priv->loop_filter_sharpness;
 
     if (avctx->max_b_frames > 0 && pic->type == PICTURE_TYPE_P)
         priv->last_ref_dir = !priv->last_ref_dir;
@@ -180,8 +182,7 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
 
 static av_cold int vaapi_encode_vp9_configure(AVCodecContext *avctx)
 {
-    VAAPIEncodeContext     *ctx = avctx->priv_data;
-    VAAPIEncodeVP9Context *priv = ctx->priv_data;
+    VAAPIEncodeVP9Context *priv = avctx->priv_data;
 
     priv->q_idx_p = av_clip(avctx->global_quality, 0, VP9_MAX_QUANT);
     if (avctx->i_quant_factor > 0.0)
@@ -202,10 +203,16 @@ static av_cold int vaapi_encode_vp9_configure(AVCodecContext *avctx)
     return 0;
 }
 
+static const VAAPIEncodeProfile vaapi_encode_vp9_profiles[] = {
+    { FF_PROFILE_VP9_0,  8, 3, 1, 1, VAProfileVP9Profile0 },
+    { FF_PROFILE_VP9_2, 10, 3, 1, 1, VAProfileVP9Profile2 },
+    { FF_PROFILE_UNKNOWN }
+};
+
 static const VAAPIEncodeType vaapi_encode_type_vp9 = {
-    .configure             = &vaapi_encode_vp9_configure,
+    .profiles              = vaapi_encode_vp9_profiles,
 
-    .priv_data_size        = sizeof(VAAPIEncodeVP9Context),
+    .configure             = &vaapi_encode_vp9_configure,
 
     .sequence_params_size  = sizeof(VAEncSequenceParameterBufferVP9),
     .init_sequence_params  = &vaapi_encode_vp9_init_sequence_params,
@@ -220,31 +227,6 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx)
 
     ctx->codec = &vaapi_encode_type_vp9;
 
-    switch (avctx->profile) {
-    case FF_PROFILE_VP9_0:
-    case FF_PROFILE_UNKNOWN:
-        ctx->va_profile = VAProfileVP9Profile0;
-        ctx->va_rt_format = VA_RT_FORMAT_YUV420;
-        break;
-    case FF_PROFILE_VP9_1:
-        av_log(avctx, AV_LOG_ERROR, "VP9 profile 1 is not "
-               "supported.\n");
-        return AVERROR_PATCHWELCOME;
-    case FF_PROFILE_VP9_2:
-        ctx->va_profile = VAProfileVP9Profile2;
-        ctx->va_rt_format = VA_RT_FORMAT_YUV420_10BPP;
-        break;
-    case FF_PROFILE_VP9_3:
-        av_log(avctx, AV_LOG_ERROR, "VP9 profile 3 is not "
-               "supported.\n");
-        return AVERROR_PATCHWELCOME;
-    default:
-        av_log(avctx, AV_LOG_ERROR, "Unknown VP9 profile %d.\n",
-               avctx->profile);
-        return AVERROR(EINVAL);
-    }
-    ctx->va_entrypoint = VAEntrypointEncSlice;
-
     if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
         ctx->va_rc_mode = VA_RC_CQP;
     } else if (avctx->bit_rate > 0) {
@@ -266,10 +248,10 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx)
     return ff_vaapi_encode_init(avctx);
 }
 
-#define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options_data) + \
-                   offsetof(VAAPIEncodeVP9Options, x))
+#define OFFSET(x) offsetof(VAAPIEncodeVP9Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_vp9_options[] = {
+    VAAPI_ENCODE_COMMON_OPTIONS,
     { "loop_filter_level", "Loop filter level",
       OFFSET(loop_filter_level), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 63, FLAGS },
     { "loop_filter_sharpness", "Loop filter sharpness",
@@ -278,7 +260,6 @@ static const AVOption vaapi_encode_vp9_options[] = {
 };
 
 static const AVCodecDefault vaapi_encode_vp9_defaults[] = {
-    { "profile",        "0"   },
     { "b",              "0"   },
     { "bf",             "0"   },
     { "g",              "250" },
@@ -298,8 +279,7 @@ AVCodec ff_vp9_vaapi_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("VP9 (VAAPI)"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_VP9,
-    .priv_data_size = (sizeof(VAAPIEncodeContext) +
-                       sizeof(VAAPIEncodeVP9Options)),
+    .priv_data_size = sizeof(VAAPIEncodeVP9Context),
     .init           = &vaapi_encode_vp9_init,
     .encode2        = &ff_vaapi_encode2,
     .close          = &ff_vaapi_encode_close,