frontends/va: Update conditional checks for code stability.
authorSureshGuttula <sguttula@amd.com>
Fri, 8 Jan 2021 02:09:31 +0000 (07:39 +0530)
committerMarge Bot <eric+marge@anholt.net>
Thu, 4 Feb 2021 12:05:28 +0000 (12:05 +0000)
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 <sguttula@amd.com>
Reviewed-by: Thong Thai <thong.thai@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8374>

src/gallium/frontends/va/config.c
src/gallium/frontends/va/context.c

index 4c59eed051c55ee318f6ee58cac263a11a83a791..e7172a3c7a538bf59984080b59130731ed5db893 100644 (file)
@@ -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 <num_attribs ; i++) {
+      if (attrib_list[i].type != VAConfigAttribRTFormat &&
+         entrypoint == VAEntrypointVLD ) {
+         FREE(config);
+         return VA_STATUS_ERROR_INVALID_VALUE;
+      }
       if (attrib_list[i].type == VAConfigAttribRateControl) {
          if (attrib_list[i].value == VA_RC_CBR)
             config->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. */
index ca2fcde38bd1147c0dde28b8a5c0ab2d9c23bcb3..556e0cb74e719e7dfef00fd2449dda282a5a7669 100644 (file)
@@ -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;