Split the surface attribute retrieval
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Wed, 31 Jul 2019 11:08:43 +0000 (13:08 +0200)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Mon, 19 Aug 2019 17:26:55 +0000 (17:26 +0000)
gst-libs/gst/vaapi/gstvaapiutils_core.c

index 2074666..92d886d 100644 (file)
@@ -77,45 +77,72 @@ gst_vaapi_get_config_attribute (GstVaapiDisplay * display, VAProfile profile,
   return TRUE;
 }
 
-/**
- * gst_vaapi_get_surface_formats:
- * @display: a #GstVaapiDisplay
- * @config: a #VAConfigID
- *
- * Gets surface formats for the supplied config.
- *
- * This function will query for all the supported formats for the
- * supplied VA @config.
- *
- * Return value: (transfer full): a #GArray of #GstVideoFormats or %NULL
- */
-GArray *
-gst_vaapi_get_surface_formats (GstVaapiDisplay * display, VAConfigID config)
+static VASurfaceAttrib *
+get_surface_attributes (GstVaapiDisplay * display, VAConfigID config,
+    guint * num_attribs)
 {
   VASurfaceAttrib *surface_attribs = NULL;
-  guint i, num_surface_attribs = 0;
+  guint num_surface_attribs = 0;
   VAStatus va_status;
-  GArray *formats;
 
   if (config == VA_INVALID_ID)
-    return NULL;
+    goto error;
 
   GST_VAAPI_DISPLAY_LOCK (display);
   va_status = vaQuerySurfaceAttributes (GST_VAAPI_DISPLAY_VADISPLAY (display),
       config, NULL, &num_surface_attribs);
   GST_VAAPI_DISPLAY_UNLOCK (display);
   if (!vaapi_check_status (va_status, "vaQuerySurfaceAttributes()"))
-    return NULL;
+    goto error;
 
   surface_attribs = g_malloc (num_surface_attribs * sizeof (*surface_attribs));
   if (!surface_attribs)
-    return NULL;
+    goto error;
 
   GST_VAAPI_DISPLAY_LOCK (display);
   va_status = vaQuerySurfaceAttributes (GST_VAAPI_DISPLAY_VADISPLAY (display),
       config, surface_attribs, &num_surface_attribs);
   GST_VAAPI_DISPLAY_UNLOCK (display);
   if (!vaapi_check_status (va_status, "vaQuerySurfaceAttributes()"))
+    goto error;
+
+  if (num_attribs)
+    *num_attribs = num_surface_attribs;
+  return surface_attribs;
+
+  /* ERRORS */
+error:
+  {
+    if (num_attribs)
+      *num_attribs = -1;
+    if (surface_attribs)
+      g_free (surface_attribs);
+    return NULL;
+  }
+}
+
+/**
+ * gst_vaapi_get_surface_formats:
+ * @display: a #GstVaapiDisplay
+ * @config: a #VAConfigID
+ *
+ * Gets surface formats for the supplied config.
+ *
+ * This function will query for all the supported formats for the
+ * supplied VA @config.
+ *
+ * Return value: (transfer full): a #GArray of #GstVideoFormats or %NULL
+ */
+GArray *
+gst_vaapi_get_surface_formats (GstVaapiDisplay * display, VAConfigID config)
+{
+  VASurfaceAttrib *surface_attribs;
+  guint i, num_surface_attribs = 0;
+  GArray *formats;
+
+  surface_attribs =
+      get_surface_attributes (display, config, &num_surface_attribs);
+  if (!surface_attribs)
     return NULL;
 
   formats = g_array_sized_new (FALSE, FALSE, sizeof (GstVideoFormat),
@@ -150,6 +177,6 @@ gst_vaapi_get_surface_formats (GstVaapiDisplay * display, VAConfigID config)
 error:
   {
     g_free (surface_attribs);
+    return NULL;
   }
-  return NULL;
 }