surface: add helper function to get chroma type from GstVideoFormat.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 10 Jul 2013 07:48:40 +0000 (09:48 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 10 Jul 2013 15:03:47 +0000 (17:03 +0200)
Add gst_video_format_get_chroma_type() helper function to determine
the GstVaapiChromaType from a standard GStreamer video format. It is
possible to reconstruct that from GstVideoFormatInfo but it is much
simpler (and faster?) to use the local GstVideoFormatMap table.

docs/reference/libs/libs-sections.txt
gst-libs/gst/vaapi/video-format.c
gst-libs/gst/vaapi/video-format.h

index 36cd6f4..bd0229c 100644 (file)
@@ -4,6 +4,7 @@
 gst_video_format_from_caps
 gst_video_format_from_structure
 gst_video_format_from_va_format
+gst_video_format_get_chroma_type
 gst_video_format_get_score
 gst_video_format_is_rgb
 gst_video_format_is_yuv
index 7d9efca..b5a3c85 100644 (file)
 #include "sysdeps.h"
 #include <gst/video/video.h>
 #include "gstvaapicompat.h"
+#include "gstvaapisurface.h"
 #include "video-format.h"
 
 typedef struct _GstVideoFormatMap GstVideoFormatMap;
 struct _GstVideoFormatMap {
     GstVideoFormat      format;
+    GstVaapiChromaType  chroma_type;
     const char         *caps_str;
     VAImageFormat       va_format;
 };
@@ -49,23 +51,26 @@ struct _GstVideoFormatMap {
     GST_VIDEO_CAPS_##FORMAT
 #endif
 
-#define DEF_YUV(FORMAT, FOURCC, ENDIAN, BPP)                            \
+#define DEF_YUV(FORMAT, FOURCC, ENDIAN, BPP, SUB)                       \
     { G_PASTE(GST_VIDEO_FORMAT_,FORMAT),                                \
+      G_PASTE(GST_VAAPI_CHROMA_TYPE_YUV,SUB),                           \
       GST_VIDEO_CAPS_MAKE_YUV(FORMAT),                                  \
       { VA_FOURCC FOURCC, VA_##ENDIAN##_FIRST, BPP, }, }
+
 #define DEF_RGB(FORMAT, FOURCC, ENDIAN, BPP, DEPTH, R,G,B,A)            \
     { G_PASTE(GST_VIDEO_FORMAT_,FORMAT),                                \
+      G_PASTE(GST_VAAPI_CHROMA_TYPE_RGB,BPP),                           \
       GST_VIDEO_CAPS_MAKE_RGB(FORMAT),                                  \
       { VA_FOURCC FOURCC, VA_##ENDIAN##_FIRST, BPP, DEPTH, R,G,B,A }, }
 
 /* Image formats, listed in HW order preference */
 static const GstVideoFormatMap gst_video_formats[] = {
-    DEF_YUV(NV12, ('N','V','1','2'), LSB, 12),
-    DEF_YUV(YV12, ('Y','V','1','2'), LSB, 12),
-    DEF_YUV(I420, ('I','4','2','0'), LSB, 12),
-    DEF_YUV(YUY2, ('Y','U','Y','2'), LSB, 16),
-    DEF_YUV(UYVY, ('U','Y','V','Y'), LSB, 16),
-    DEF_YUV(AYUV, ('A','Y','U','V'), LSB, 32),
+    DEF_YUV(NV12, ('N','V','1','2'), LSB, 12, 420),
+    DEF_YUV(YV12, ('Y','V','1','2'), LSB, 12, 420),
+    DEF_YUV(I420, ('I','4','2','0'), LSB, 12, 420),
+    DEF_YUV(YUY2, ('Y','U','Y','2'), LSB, 16, 422),
+    DEF_YUV(UYVY, ('U','Y','V','Y'), LSB, 16, 422),
+    DEF_YUV(AYUV, ('A','Y','U','V'), LSB, 32, 444),
 #if G_BYTE_ORDER == G_BIG_ENDIAN
     DEF_RGB(ARGB, ('A','R','G','B'), MSB, 32,
             32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000),
@@ -85,7 +90,7 @@ static const GstVideoFormatMap gst_video_formats[] = {
     DEF_RGB(RGBx, ('R','G','B','X'), LSB, 32,
             24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000),
 #endif
-    DEF_YUV(GRAY8, ('Y','8','0','0'), LSB, 8),
+    DEF_YUV(GRAY8, ('Y','8','0','0'), LSB, 8, 400),
     { 0, }
 };
 
@@ -311,6 +316,24 @@ gst_video_format_to_va_format(GstVideoFormat format)
 }
 
 /**
+ * gst_video_format_get_chroma_type:
+ * @format: a #GstVideoFormat
+ *
+ * Converts a #GstVideoFormat into the corresponding #GstVaapiChromaType
+ * format.
+ *
+ * Return value: the #GstVaapiChromaType format, or zero if no match
+ *   was found.
+ */
+guint
+gst_video_format_get_chroma_type(GstVideoFormat format)
+{
+    const GstVideoFormatMap * const m = get_map(format);
+
+    return m ? m->chroma_type : 0;
+}
+
+/**
  * gst_video_format_get_score:
  * @format: a #GstVideoFormat
  *
index 5ba3950..a1dc9f6 100644 (file)
@@ -50,6 +50,9 @@ const VAImageFormat *
 gst_video_format_to_va_format(GstVideoFormat format);
 
 guint
+gst_video_format_get_chroma_type(GstVideoFormat format);
+
+guint
 gst_video_format_get_score(GstVideoFormat format);
 
 G_END_DECLS