libs: context: query surface format before context to create surface.
authorWangfei <fei.w.wang@intel.com>
Mon, 1 Oct 2018 01:26:05 +0000 (09:26 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Wed, 10 Oct 2018 18:13:01 +0000 (20:13 +0200)
Before using context to create surface, the supported surface format
should be checked first.

https://bugzilla.gnome.org/show_bug.cgi?id=797222

gst-libs/gst/vaapi/gstvaapicontext.c
gst-libs/gst/vaapi/gstvaapisurface.c
gst-libs/gst/vaapi/gstvaapisurface.h

index afbf8b4..dcce889 100644 (file)
@@ -133,9 +133,13 @@ context_ensure_surfaces (GstVaapiContext * context)
   GstVaapiSurface *surface;
   guint i;
 
+  if (!ensure_formats (context))
+    return FALSE;
+
   for (i = context->surfaces->len; i < num_surfaces; i++) {
-    surface = gst_vaapi_surface_new (GST_VAAPI_OBJECT_DISPLAY (context),
-        cip->chroma_type, cip->width, cip->height);
+    surface =
+        gst_vaapi_surface_new_from_formats (GST_VAAPI_OBJECT_DISPLAY (context),
+        cip->chroma_type, cip->width, cip->height, context->formats);
     if (!surface)
       return FALSE;
     gst_vaapi_surface_set_parent_context (surface, context);
index f7f948f..40d9874 100644 (file)
@@ -317,6 +317,51 @@ error_unsupported_format:
 GST_VAAPI_OBJECT_DEFINE_CLASS (GstVaapiSurface, gst_vaapi_surface);
 
 /**
+ * gst_vaapi_surface_new_from_formats:
+ * @display: a #GstVaapiDisplay
+ * @chroma_type: the surface chroma format
+ * @width: the requested surface width
+ * @height: the requested surface height
+ * @formats: the limited format list
+ *
+ * Creates a new #GstVaapiSurface with a @chroma_type valid for any
+ * format in @formats; If there aren't any, the returned surface is
+ * created forcing the passed @chroma_type.
+ *
+ * Return value: the newly allocated #GstVaapiSurface object
+ */
+GstVaapiSurface *
+gst_vaapi_surface_new_from_formats (GstVaapiDisplay * display,
+    GstVaapiChromaType chroma_type, guint width, guint height, GArray * formats)
+{
+  GstVaapiSurface *surface;
+  guint i;
+
+  for (i = 0; i < formats->len; i++) {
+    GstVideoFormat format = g_array_index (formats, GstVideoFormat, i);
+    if (format == gst_vaapi_video_format_from_chroma (chroma_type))
+      return gst_vaapi_surface_new (display, chroma_type, width, height);
+  }
+
+  /* Fallback: if there's no format valid for the chroma type let's
+   * just use the passed chroma */
+  surface = gst_vaapi_object_new (gst_vaapi_surface_class (), display);
+  if (!surface)
+    return NULL;
+  if (!gst_vaapi_surface_create (surface, chroma_type, width, height))
+    goto error;
+
+  return surface;
+
+  /* ERRORS */
+error:
+  {
+    gst_vaapi_object_unref (surface);
+    return NULL;
+  }
+}
+
+/**
  * gst_vaapi_surface_new:
  * @display: a #GstVaapiDisplay
  * @chroma_type: the surface chroma format
index eaed6f8..e9ffeb8 100644 (file)
@@ -170,6 +170,10 @@ typedef struct _GstVaapiSurface                 GstVaapiSurface;
 typedef struct _GstVaapiSurfaceProxy            GstVaapiSurfaceProxy;
 
 GstVaapiSurface *
+gst_vaapi_surface_new_from_formats (GstVaapiDisplay * display,
+    GstVaapiChromaType chroma_type, guint width, guint height, GArray * formts);
+
+GstVaapiSurface *
 gst_vaapi_surface_new (GstVaapiDisplay * display,
     GstVaapiChromaType chroma_type, guint width, guint height);