summaryrefslogtreecommitdiff
path: root/libavcodec/vaapi_encode_h265.c
diff options
context:
space:
mode:
authorMark Thompson <sw@jkqxz.net>2016-04-12 23:13:31 +0100
committerAnton Khirnov <anton@khirnov.net>2016-04-15 10:07:04 +0200
commitf6b85523692b0e7d4c4efb8449fa201d313424fe (patch)
treeee84ef7e68d38e4dd1db1c3cff9f1e13d4b64b22 /libavcodec/vaapi_encode_h265.c
parent18019f8cb9663dd1032c65aa453eaec18d641905 (diff)
vaapi_encode: Refactor slightly to allow easier setting of global options
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavcodec/vaapi_encode_h265.c')
-rw-r--r--libavcodec/vaapi_encode_h265.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 0aa40e31b6..323efd46a7 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1125,20 +1125,21 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
return 0;
}
-static VAConfigAttrib vaapi_encode_h265_config_attributes[] = {
- { .type = VAConfigAttribRTFormat,
- .value = VA_RT_FORMAT_YUV420 },
- { .type = VAConfigAttribRateControl,
- .value = VA_RC_CQP },
- { .type = VAConfigAttribEncPackedHeaders,
- .value = (VA_ENC_PACKED_HEADER_SEQUENCE |
- VA_ENC_PACKED_HEADER_SLICE) },
-};
-
static av_cold int vaapi_encode_h265_init_internal(AVCodecContext *avctx)
{
+ static const VAConfigAttrib default_config_attributes[] = {
+ { .type = VAConfigAttribRTFormat,
+ .value = VA_RT_FORMAT_YUV420 },
+ { .type = VAConfigAttribEncPackedHeaders,
+ .value = (VA_ENC_PACKED_HEADER_SEQUENCE |
+ VA_ENC_PACKED_HEADER_SLICE) },
+ { .type = VAConfigAttribRateControl,
+ .value = VA_RC_CQP },
+ };
+
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeH265Context *priv = ctx->priv_data;
+ int i;
switch (avctx->profile) {
case FF_PROFILE_HEVC_MAIN:
@@ -1156,8 +1157,6 @@ static av_cold int vaapi_encode_h265_init_internal(AVCodecContext *avctx)
}
ctx->va_entrypoint = VAEntrypointEncSlice;
- ctx->va_rc_mode = VA_RC_CQP;
-
ctx->input_width = avctx->width;
ctx->input_height = avctx->height;
ctx->aligned_width = FFALIGN(ctx->input_width, 16);
@@ -1169,6 +1168,19 @@ static av_cold int vaapi_encode_h265_init_internal(AVCodecContext *avctx)
ctx->input_width, ctx->input_height, ctx->aligned_width,
ctx->aligned_height, priv->ctu_width, priv->ctu_height);
+ for (i = 0; i < FF_ARRAY_ELEMS(default_config_attributes); i++) {
+ ctx->config_attributes[ctx->nb_config_attributes++] =
+ default_config_attributes[i];
+ }
+
+ if (avctx->bit_rate > 0) {
+ av_log(avctx, AV_LOG_ERROR, "H.265 constant-bitrate encoding "
+ "is not supported.\n");
+ return AVERROR_PATCHWELCOME;
+ }
+
+ ctx->va_rc_mode = VA_RC_CQP;
+
priv->fixed_qp_p = avctx->global_quality;
if (avctx->i_quant_factor > 0.0)
priv->fixed_qp_idr = (int)((priv->fixed_qp_p * avctx->i_quant_factor +
@@ -1183,10 +1195,6 @@ static av_cold int vaapi_encode_h265_init_internal(AVCodecContext *avctx)
av_log(avctx, AV_LOG_DEBUG, "QP = %d / %d / %d for IDR / P / B frames.\n",
priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
- ctx->config_attributes = vaapi_encode_h265_config_attributes;
- ctx->nb_config_attributes =
- FF_ARRAY_ELEMS(vaapi_encode_h265_config_attributes);
-
ctx->nb_recon_frames = 20;
return 0;