From b4651890be4db10a6a6ebf0e6cf2fad7d00623b9 Mon Sep 17 00:00:00 2001 From: SureshGuttula Date: Fri, 8 Jan 2021 07:39:31 +0530 Subject: [PATCH] frontends/va: Update conditional checks for code stability. Added parameter checks and updated returns based on that. https://github.com/intel/libva-utils/tree/master/test run test_va_api Signed-off-by: SureshGuttula Reviewed-by: Thong Thai Part-of: --- src/gallium/frontends/va/config.c | 41 +++++++++++++++++++++++++----- src/gallium/frontends/va/context.c | 15 +++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/gallium/frontends/va/config.c b/src/gallium/frontends/va/config.c index 4c59eed051c..e7172a3c7a5 100644 --- a/src/gallium/frontends/va/config.c +++ b/src/gallium/frontends/va/config.c @@ -87,7 +87,9 @@ vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile, } p = ProfileToPipe(profile); - if (p == PIPE_VIDEO_PROFILE_UNKNOWN) + if (p == PIPE_VIDEO_PROFILE_UNKNOWN || + (u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 && + !debug_get_option_mpeg4())) return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; pscreen = VL_VA_PSCREEN(ctx); @@ -211,7 +213,10 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin if (!config) return VA_STATUS_ERROR_ALLOCATION_FAILED; - if (profile == VAProfileNone && entrypoint == VAEntrypointVideoProc) { + if (profile == VAProfileNone) { + if (entrypoint != VAEntrypointVideoProc) + return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + config->entrypoint = PIPE_VIDEO_ENTRYPOINT_UNKNOWN; config->profile = PIPE_VIDEO_PROFILE_UNKNOWN; supported_rt_formats = VA_RT_FORMAT_YUV420 | @@ -225,6 +230,10 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin FREE(config); return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT; } + } else { + /*other attrib_types are not supported.*/ + FREE(config); + return VA_STATUS_ERROR_INVALID_VALUE; } } @@ -239,7 +248,9 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin } p = ProfileToPipe(profile); - if (p == PIPE_VIDEO_PROFILE_UNKNOWN) { + if (p == PIPE_VIDEO_PROFILE_UNKNOWN || + (u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 && + !debug_get_option_mpeg4())) { FREE(config); return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; } @@ -248,20 +259,22 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin switch (entrypoint) { case VAEntrypointVLD: + supported_rt_formats = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422; if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED)) { FREE(config); - return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; + return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; } config->entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM; break; case VAEntrypointEncSlice: + supported_rt_formats = VA_RT_FORMAT_YUV420; if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE, PIPE_VIDEO_CAP_SUPPORTED)) { FREE(config); - return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; + return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; } config->entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE; @@ -273,7 +286,6 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin } config->profile = p; - supported_rt_formats = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422; if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010, p, config->entrypoint) || pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016, p, @@ -281,13 +293,22 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin supported_rt_formats |= VA_RT_FORMAT_YUV420_10BPP; for (int i = 0; i rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT; else if (attrib_list[i].value == VA_RC_VBR) config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE; - else + else if (attrib_list[i].value == VA_RC_CQP) config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE; + else { + FREE(config); + return VA_STATUS_ERROR_INVALID_VALUE; + } } if (attrib_list[i].type == VAConfigAttribRTFormat) { if (attrib_list[i].value & supported_rt_formats) { @@ -297,6 +318,12 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT; } } + if (attrib_list[i].type == VAConfigAttribEncPackedHeaders) { + if (attrib_list[i].value != 0) { + FREE(config); + return VA_STATUS_ERROR_INVALID_VALUE; + } + } } /* Default value if not specified in the input attributes. */ diff --git a/src/gallium/frontends/va/context.c b/src/gallium/frontends/va/context.c index ca2fcde38bd..556e0cb74e7 100644 --- a/src/gallium/frontends/va/context.c +++ b/src/gallium/frontends/va/context.c @@ -217,6 +217,7 @@ vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width, vlVaContext *context; vlVaConfig *config; int is_vpp; + int max_supported_width,max_supported_height; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; @@ -226,6 +227,9 @@ vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width, config = handle_table_get(drv->htab, config_id); mtx_unlock(&drv->mutex); + if (!config) + return VA_STATUS_ERROR_INVALID_CONFIG; + is_vpp = config->profile == PIPE_VIDEO_PROFILE_UNKNOWN && !picture_width && !picture_height && !flag && !render_targets && !num_render_targets; @@ -239,6 +243,17 @@ vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width, if (is_vpp) { context->decoder = NULL; } else { + if (config->entrypoint != PIPE_VIDEO_ENTRYPOINT_UNKNOWN) { + max_supported_width = drv->vscreen->pscreen->get_video_param(drv->vscreen->pscreen, + config->profile, config->entrypoint, + PIPE_VIDEO_CAP_MAX_WIDTH); + max_supported_height = drv->vscreen->pscreen->get_video_param(drv->vscreen->pscreen, + config->profile, config->entrypoint, + PIPE_VIDEO_CAP_MAX_HEIGHT); + + if (picture_width > max_supported_width || picture_height > max_supported_height) + return VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED; + } context->templat.profile = config->profile; context->templat.entrypoint = config->entrypoint; context->templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420; -- 2.34.1