From b50f06309afc11da783b977589ab4a708ac87822 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Mon, 16 Dec 2019 23:19:46 +0800 Subject: [PATCH] libs: encoder: set context info profile by encoder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of init_context_info() setting the passed profile, it is assumed that it has to be set by each encoder. Signed-off-by: Víctor Manuel Jáquez Leal --- gst-libs/gst/vaapi/gstvaapiencoder.c | 26 +++++++++------------- gst-libs/gst/vaapi/gstvaapiencoder_h264.c | 2 +- gst-libs/gst/vaapi/gstvaapiencoder_h265.c | 1 + gst-libs/gst/vaapi/gstvaapiencoder_jpeg.c | 3 +++ gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c | 3 +++ gst-libs/gst/vaapi/gstvaapiencoder_vp8.c | 3 +++ gst-libs/gst/vaapi/gstvaapiencoder_vp9.c | 1 + 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c index 3f0e9a7cd0..ccd804d2de 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder.c @@ -713,21 +713,9 @@ get_default_chroma_type (GstVaapiEncoder * encoder, } static void -init_context_info (GstVaapiEncoder * encoder, GstVaapiContextInfo * cip, - GstVaapiProfile profile) +init_context_info (GstVaapiEncoder * encoder, GstVaapiContextInfo * cip) { - const GstVaapiEncoderClassData *const cdata = - GST_VAAPI_ENCODER_GET_CLASS (encoder)->class_data; - cip->usage = GST_VAAPI_CONTEXT_USAGE_ENCODE; - cip->profile = profile; - if (cdata->codec == GST_VAAPI_CODEC_JPEG) { - cip->entrypoint = GST_VAAPI_ENTRYPOINT_PICTURE_ENCODE; - } else { - if (cip->entrypoint != GST_VAAPI_ENTRYPOINT_SLICE_ENCODE_LP && - cip->entrypoint != GST_VAAPI_ENTRYPOINT_SLICE_ENCODE_FEI) - cip->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE; - } cip->chroma_type = get_default_chroma_type (encoder, cip); cip->width = 0; cip->height = 0; @@ -744,8 +732,10 @@ set_context_info (GstVaapiEncoder * encoder) GST_VIDEO_INFO_FORMAT (GST_VAAPI_ENCODER_VIDEO_INFO (encoder)); guint fei_function = config->fei_function; - init_context_info (encoder, cip, get_profile (encoder)); + g_assert (cip->profile != GST_VAAPI_PROFILE_UNKNOWN); + g_assert (cip->entrypoint != GST_VAAPI_ENTRYPOINT_INVALID); + init_context_info (encoder, cip); cip->chroma_type = gst_vaapi_video_format_get_chroma_type (format); cip->width = GST_VAAPI_ENCODER_WIDTH (encoder); cip->height = GST_VAAPI_ENCODER_HEIGHT (encoder); @@ -1483,6 +1473,8 @@ gst_vaapi_encoder_class_init (GstVaapiEncoderClass * klass) static GstVaapiContext * create_test_context_config (GstVaapiEncoder * encoder, GstVaapiProfile profile) { + const GstVaapiEncoderClassData *const cdata = + GST_VAAPI_ENCODER_GET_CLASS (encoder)->class_data; GstVaapiContextInfo cip = { 0, }; GstVaapiContext *ctxt; @@ -1493,7 +1485,11 @@ create_test_context_config (GstVaapiEncoder * encoder, GstVaapiProfile profile) if (profile == GST_VAAPI_PROFILE_UNKNOWN) profile = get_profile (encoder); - init_context_info (encoder, &cip, profile); + cip.profile = profile; + cip.entrypoint = (cdata->codec == GST_VAAPI_CODEC_JPEG) ? + GST_VAAPI_ENTRYPOINT_PICTURE_ENCODE : GST_VAAPI_ENTRYPOINT_SLICE_ENCODE; + + init_context_info (encoder, &cip); ctxt = gst_vaapi_context_new (encoder->display, &cip); return ctxt; } diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c index f3dcc3df33..abff56a856 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c @@ -3346,7 +3346,7 @@ set_context_info (GstVaapiEncoder * base_encoder) GST_VAAPI_ENCODER_H264_COMPLIANCE_MODE_RESTRICT_CODED_BUFFER_ALLOC) base_encoder->codedbuf_size /= encoder->min_cr; - + base_encoder->context_info.profile = base_encoder->profile; base_encoder->context_info.entrypoint = encoder->entrypoint; return GST_VAAPI_ENCODER_STATUS_SUCCESS; diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c index 795075e308..0c14422ae8 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c @@ -2540,6 +2540,7 @@ set_context_info (GstVaapiEncoder * base_encoder) base_encoder->codedbuf_size += GST_ROUND_UP_16 (vip->width) * GST_ROUND_UP_16 (vip->height) * 3 / 2; + base_encoder->context_info.profile = base_encoder->profile; base_encoder->context_info.entrypoint = encoder->entrypoint; return GST_VAAPI_ENCODER_STATUS_SUCCESS; diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_jpeg.c b/gst-libs/gst/vaapi/gstvaapiencoder_jpeg.c index 5691087751..4c87a8aa38 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_jpeg.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_jpeg.c @@ -197,6 +197,9 @@ set_context_info (GstVaapiEncoder * base_encoder) base_encoder->codedbuf_size += MAX_APP_HDR_SIZE + MAX_FRAME_HDR_SIZE + MAX_QUANT_TABLE_SIZE + MAX_HUFFMAN_TABLE_SIZE + MAX_SCAN_HDR_SIZE; + base_encoder->context_info.profile = base_encoder->profile; + base_encoder->context_info.entrypoint = GST_VAAPI_ENTRYPOINT_PICTURE_ENCODE; + return GST_VAAPI_ENCODER_STATUS_SUCCESS; } diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c index 0aca23ba68..58477d7eec 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c @@ -689,6 +689,9 @@ set_context_info (GstVaapiEncoder * base_encoder) base_encoder->codedbuf_size += (GST_ROUND_UP_16 (vip->height) / 16) * MAX_SLICE_HDR_SIZE; + base_encoder->context_info.profile = base_encoder->profile; + base_encoder->context_info.entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE; + return GST_VAAPI_ENCODER_STATUS_SUCCESS; } diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c index b91fa43517..ce88cfb6f0 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c @@ -173,6 +173,9 @@ set_context_info (GstVaapiEncoder * base_encoder) MAX_TOKEN_PROB_UPDATE_SIZE + MAX_MV_PROBE_UPDATE_SIZE + MAX_REST_OF_FRAME_HDR_SIZE; + base_encoder->context_info.profile = base_encoder->profile; + base_encoder->context_info.entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE; + return GST_VAAPI_ENCODER_STATUS_SUCCESS; } diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c b/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c index 07c8154b87..9315e3db2f 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c @@ -219,6 +219,7 @@ set_context_info (GstVaapiEncoder * base_encoder) base_encoder->codedbuf_size = GST_ROUND_UP_16 (vip->width) * GST_ROUND_UP_16 (vip->height) * 3 / 2; + base_encoder->context_info.profile = base_encoder->profile; base_encoder->context_info.entrypoint = encoder->entrypoint; return GST_VAAPI_ENCODER_STATUS_SUCCESS;