summaryrefslogtreecommitdiff
path: root/libavcodec/vaapi_encode_mjpeg.c
diff options
context:
space:
mode:
authorMark Thompson <sw@jkqxz.net>2016-09-18 14:55:26 +0100
committerMark Thompson <sw@jkqxz.net>2016-11-21 22:13:41 +0000
commitc8241e730f116f1c9cfc0b34110aa7f052e05332 (patch)
treef7a034248989e485bd6e979e55588eec89c3ae8a /libavcodec/vaapi_encode_mjpeg.c
parent06d73d002e7f911f26ae1548b46e442a6ece9a4a (diff)
vaapi_encode: Refactor initialisation
This allows better checking of capabilities and will make it easier to add more functionality later. It also commonises some duplicated code around rate control setup and adds more comments explaining the internals. (cherry picked from commit 80a5d05108cb218e8cd2e25c6621a3bfef0a832e)
Diffstat (limited to 'libavcodec/vaapi_encode_mjpeg.c')
-rw-r--r--libavcodec/vaapi_encode_mjpeg.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index 316b3595c8..3ca902a6af 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -277,8 +277,8 @@ static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx,
vpic->reconstructed_picture = pic->recon_surface;
vpic->coded_buf = pic->output_buffer;
- vpic->picture_width = ctx->input_width;
- vpic->picture_height = ctx->input_height;
+ vpic->picture_width = avctx->width;
+ vpic->picture_height = avctx->height;
vpic->pic_flags.bits.profile = 0;
vpic->pic_flags.bits.progressive = 0;
@@ -333,31 +333,10 @@ static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx,
return 0;
}
-static av_cold int vaapi_encode_mjpeg_init_internal(AVCodecContext *avctx)
+static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
{
- static const VAConfigAttrib default_config_attributes[] = {
- { .type = VAConfigAttribRTFormat,
- .value = VA_RT_FORMAT_YUV420 },
- { .type = VAConfigAttribEncPackedHeaders,
- .value = VA_ENC_PACKED_HEADER_SEQUENCE },
- };
-
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMJPEGContext *priv = ctx->priv_data;
- int i;
-
- ctx->va_profile = VAProfileJPEGBaseline;
- ctx->va_entrypoint = VAEntrypointEncPicture;
-
- ctx->input_width = avctx->width;
- ctx->input_height = avctx->height;
- ctx->aligned_width = FFALIGN(ctx->input_width, 8);
- ctx->aligned_height = FFALIGN(ctx->input_height, 8);
-
- for (i = 0; i < FF_ARRAY_ELEMS(default_config_attributes); i++) {
- ctx->config_attributes[ctx->nb_config_attributes++] =
- default_config_attributes[i];
- }
priv->quality = avctx->global_quality;
if (priv->quality < 1 || priv->quality > 100) {
@@ -374,7 +353,7 @@ static av_cold int vaapi_encode_mjpeg_init_internal(AVCodecContext *avctx)
static VAAPIEncodeType vaapi_encode_type_mjpeg = {
.priv_data_size = sizeof(VAAPIEncodeMJPEGContext),
- .init = &vaapi_encode_mjpeg_init_internal,
+ .configure = &vaapi_encode_mjpeg_configure,
.picture_params_size = sizeof(VAEncPictureParameterBufferJPEG),
.init_picture_params = &vaapi_encode_mjpeg_init_picture_params,
@@ -390,7 +369,21 @@ static VAAPIEncodeType vaapi_encode_type_mjpeg = {
static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx)
{
- return ff_vaapi_encode_init(avctx, &vaapi_encode_type_mjpeg);
+ VAAPIEncodeContext *ctx = avctx->priv_data;
+
+ ctx->codec = &vaapi_encode_type_mjpeg;
+
+ ctx->va_profile = VAProfileJPEGBaseline;
+ ctx->va_entrypoint = VAEntrypointEncPicture;
+
+ ctx->va_rt_format = VA_RT_FORMAT_YUV420;
+
+ ctx->va_rc_mode = VA_RC_CQP;
+
+ ctx->surface_width = FFALIGN(avctx->width, 8);
+ ctx->surface_height = FFALIGN(avctx->height, 8);
+
+ return ff_vaapi_encode_init(avctx);
}
static const AVCodecDefault vaapi_encode_mjpeg_defaults[] = {