surface pool config based on video info
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Thu, 23 Jul 2015 18:07:59 +0000 (20:07 +0200)
committerVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Thu, 13 Aug 2015 15:20:19 +0000 (17:20 +0200)
First added the function gst_vaapi_video_format_get_best_native(), which
returns the best native format that matches a particular chroma type:

YUV 4:2:0 -> NV12, YUV 4:2:2 -> YUY2, YUV 4:0:0 -> Y800

RGB32 chroma and encoded format map to NV12 too.

That format is used to configure, initially, the surface's pool for the
allocator.

Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
https://bugzilla.gnome.org/show_bug.cgi?id=744042

gst-libs/gst/vaapi/video-format.c
gst-libs/gst/vaapi/video-format.h
gst/vaapi/gstvaapivideomemory.c

index 34c70aa..9a6edd4 100644 (file)
@@ -270,3 +270,35 @@ gst_vaapi_video_format_get_score (GstVideoFormat format)
 
   return m ? (m - &gst_vaapi_video_formats[0]) : G_MAXUINT;
 }
+
+/**
+ * gst_vaapi_video_format_get_best_native:
+ * @format: a #GstVideoFormat
+ *
+ * Returns the best "native" pixel format that matches a particular
+ * color-space.
+ *
+ * Returns: the #GstVideoFormat with the corresponding best native
+ * format for #GstVaapiSurface
+ **/
+GstVideoFormat
+gst_vaapi_video_format_get_best_native (GstVideoFormat format)
+{
+  GstVaapiChromaType chroma_type;
+
+  if (format == GST_VIDEO_FORMAT_ENCODED)
+    return GST_VIDEO_FORMAT_NV12;
+
+  chroma_type = gst_vaapi_video_format_get_chroma_type (format);
+  switch (chroma_type) {
+    case GST_VAAPI_CHROMA_TYPE_YUV422:
+      return GST_VIDEO_FORMAT_YUY2;
+    case GST_VAAPI_CHROMA_TYPE_YUV400:
+      return GST_VIDEO_FORMAT_GRAY8;
+    case GST_VAAPI_CHROMA_TYPE_YUV420:
+    case GST_VAAPI_CHROMA_TYPE_RGB32:  /* GstVideoGLTextureUploadMeta */
+      return GST_VIDEO_FORMAT_NV12;
+    default:
+      return GST_VIDEO_FORMAT_UNKNOWN;
+  };
+}
index 4830522..25e1161 100644 (file)
@@ -53,6 +53,9 @@ gst_vaapi_video_format_get_chroma_type (GstVideoFormat format);
 guint
 gst_vaapi_video_format_get_score (GstVideoFormat format);
 
+GstVideoFormat
+gst_vaapi_video_format_get_best_native (GstVideoFormat format);
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_VIDEO_FORMAT_H */
index 4985672..21c0299 100644 (file)
@@ -659,10 +659,12 @@ allocator_configure_surface_info (GstVaapiDisplay * display,
   GstVaapiSurface *surface = NULL;
   GstVaapiImage *image = NULL;
   gboolean updated;
+  GstVideoFormat fmt;
 
   vinfo = &allocator->video_info;
 
-  gst_video_info_set_format (&allocator->surface_info, GST_VIDEO_FORMAT_NV12,
+  fmt = gst_vaapi_video_format_get_best_native (GST_VIDEO_INFO_FORMAT (vinfo));
+  gst_video_info_set_format (&allocator->surface_info, fmt,
       GST_VIDEO_INFO_WIDTH (vinfo), GST_VIDEO_INFO_HEIGHT (vinfo));
 
   /* nothing to configure */