glimagesink: add support for P010 variants
authorHaihao Xiang <haihao.xiang@intel.com>
Thu, 13 Jun 2019 05:07:06 +0000 (13:07 +0800)
committerHaihao Xiang <haihao.xiang@intel.com>
Tue, 18 Jun 2019 08:32:00 +0000 (16:32 +0800)
This makes a pipeline below works:

little endian:
gst-launch-1.0 videotestsrc ! video/x-raw,format=P010_10LE ! glimagesink

big endian:
gst-launch-1.0 videotestsrc ! video/x-raw,format=P010_10BE ! glimagesink

gst-libs/gst/gl/egl/gsteglimage.c
gst-libs/gst/gl/gstglcolorconvert.c
gst-libs/gst/gl/gstglcolorconvert.h
gst-libs/gst/gl/gstglformat.c
gst-libs/gst/gl/gstglformat.h
gst-libs/gst/gl/gstglmemory.h

index 21eb9da..12f0eaa 100644 (file)
 #define DRM_FORMAT_RGBA1010102  fourcc_code('R', 'A', '3', '0')
 #endif
 
+#ifndef DRM_FORMAT_R16
+#define DRM_FORMAT_R16          fourcc_code('R', '1', '6', ' ')
+#endif
+
+#ifndef DRM_FORMAT_GR1616
+#define DRM_FORMAT_GR1616       fourcc_code('G', 'R', '3', '2')
+#endif
+
+#ifndef DRM_FORMAT_RG1616
+#define DRM_FORMAT_RG1616       fourcc_code('R', 'G', '3', '2')
+#endif
+
 #ifndef EGL_LINUX_DMA_BUF_EXT
 #define EGL_LINUX_DMA_BUF_EXT 0x3270
 #endif
@@ -517,6 +529,14 @@ _drm_rgba_fourcc_from_info (GstVideoInfo * info, int plane,
       *out_format = GST_GL_RGB10_A2;
       return DRM_FORMAT_RGBA1010102;
 
+    case GST_VIDEO_FORMAT_P010_10LE:
+      *out_format = plane == 0 ? GST_GL_R16 : GST_GL_RG16;
+      return plane == 0 ? DRM_FORMAT_R16 : DRM_FORMAT_GR1616;
+
+    case GST_VIDEO_FORMAT_P010_10BE:
+      *out_format = plane == 0 ? GST_GL_R16 : GST_GL_RG16;
+      return plane == 0 ? DRM_FORMAT_R16 : DRM_FORMAT_RG1616;
+
     default:
       GST_ERROR ("Unsupported format for DMABuf.");
       return -1;
index ee27887..13c7fdc 100644 (file)
@@ -956,6 +956,14 @@ _init_supported_formats (GstGLContext * context, gboolean output,
     _append_value_string_list (supported_formats, "BGR10A2_LE", "RGB10A2_LE",
         NULL);
 #endif
+
+  if (!context || (gst_gl_format_is_supported (context, GST_GL_R16) &&
+          gst_gl_format_is_supported (context, GST_GL_RG16)))
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+    _append_value_string_list (supported_formats, "P010_10LE", NULL);
+#else
+    _append_value_string_list (supported_formats, "P010_10BE", NULL);
+#endif
 }
 
 /* copies the given caps */
@@ -1547,6 +1555,8 @@ _get_n_textures (GstVideoFormat v_format)
       return 1;
     case GST_VIDEO_FORMAT_NV12:
     case GST_VIDEO_FORMAT_NV21:
+    case GST_VIDEO_FORMAT_P010_10LE:
+    case GST_VIDEO_FORMAT_P010_10BE:
       return 2;
     case GST_VIDEO_FORMAT_I420:
     case GST_VIDEO_FORMAT_Y444:
@@ -1705,6 +1715,17 @@ _YUV_to_RGB (GstGLColorConvert * convert)
         info->shader_tex_names[1] = "UVtex";
         break;
       }
+      case GST_VIDEO_FORMAT_P010_10LE:
+      case GST_VIDEO_FORMAT_P010_10BE:
+      {
+        info->templ = &templ_SEMI_PLANAR_to_RGB;
+        info->frag_body =
+            g_strdup_printf (templ_SEMI_PLANAR_to_RGB_BODY, 'r', 'g',
+            pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
+        info->shader_tex_names[0] = "Ytex";
+        info->shader_tex_names[1] = "UVtex";
+        break;
+      }
       default:
         break;
     }
index e39ecbb..608bc9c 100644 (file)
@@ -88,9 +88,9 @@ struct _GstGLColorConvertClass
  * The currently supported formats that can be converted
  */
 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define COLOR_CONVERT_EXT_FORMATS ", BGR10A2_LE, RGB10A2_LE"
+#define COLOR_CONVERT_EXT_FORMATS ", BGR10A2_LE, RGB10A2_LE, P010_10LE"
 #else
-#define COLOR_CONVERT_EXT_FORMATS ""
+#define COLOR_CONVERT_EXT_FORMATS ", P010_10BE"
 #endif
 
 #define GST_GL_COLOR_CONVERT_FORMATS "{ RGBA, RGB, RGBx, BGR, BGRx, BGRA, xRGB, " \
index 73b13e9..91286fb 100644 (file)
@@ -75,6 +75,7 @@ _gl_format_n_components (guint format)
     case GST_GL_LUMINANCE_ALPHA:
     case GST_GL_RG:
     case GST_GL_RG8:
+    case GST_GL_RG16:
       return 2;
     case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE:
     case GST_VIDEO_GL_TEXTURE_TYPE_R:
@@ -82,6 +83,7 @@ _gl_format_n_components (guint format)
     case GST_GL_ALPHA:
     case GST_GL_RED:
     case GST_GL_R8:
+    case GST_GL_R16:
       return 1;
     default:
       return 0;
@@ -201,6 +203,9 @@ gst_gl_format_from_video_info (GstGLContext * context, GstVideoInfo * vinfo,
     case GST_VIDEO_FORMAT_BGR10A2_LE:
     case GST_VIDEO_FORMAT_RGB10A2_LE:
       return GST_GL_RGB10_A2;
+    case GST_VIDEO_FORMAT_P010_10LE:
+    case GST_VIDEO_FORMAT_P010_10BE:
+      return plane == 0 ? GST_GL_R16 : GST_GL_RG16;
     default:
       n_plane_components = 4;
       g_assert_not_reached ();
@@ -269,6 +274,8 @@ gst_gl_sized_gl_format_from_gl_format_type (GstGLContext * context,
           if (!USING_GLES3 (context) && USING_GLES2 (context) && ext_texture_rg)
             return GST_GL_RG;
           return GST_GL_RG8;
+        case GL_UNSIGNED_SHORT:
+          return GST_GL_RG16;
       }
       break;
     case GST_GL_RED:
@@ -277,6 +284,8 @@ gst_gl_sized_gl_format_from_gl_format_type (GstGLContext * context,
           if (!USING_GLES3 (context) && USING_GLES2 (context) && ext_texture_rg)
             return GST_GL_RED;
           return GST_GL_R8;
+        case GL_UNSIGNED_SHORT:
+          return GST_GL_R16;
       }
       break;
     case GST_GL_RGBA8:
@@ -292,6 +301,8 @@ gst_gl_sized_gl_format_from_gl_format_type (GstGLContext * context,
     case GST_GL_DEPTH_COMPONENT16:
     case GST_GL_DEPTH24_STENCIL8:
     case GST_GL_RGB10_A2:
+    case GST_GL_R16:
+    case GST_GL_RG16:
       return format;
     default:
       g_critical ("Unknown GL format 0x%x type 0x%x provided", format, type);
@@ -363,6 +374,14 @@ gst_gl_format_type_from_sized_gl_format (GstGLFormat format,
       *unsized_format = GST_GL_RGBA;
       *gl_type = GL_UNSIGNED_INT_2_10_10_10_REV;
       break;
+    case GST_GL_R16:
+      *unsized_format = GST_GL_RED;
+      *gl_type = GL_UNSIGNED_SHORT;
+      break;
+    case GST_GL_RG16:
+      *unsized_format = GST_GL_RG;
+      *gl_type = GL_UNSIGNED_SHORT;
+      break;
     default:
       g_critical ("Unknown GL format 0x%x provided", format);
       *unsized_format = format;
@@ -435,6 +454,12 @@ gst_gl_format_is_supported (GstGLContext * context, GstGLFormat format)
           || USING_GLES3 (context)
           || gst_gl_context_check_feature (context,
           "GL_OES_required_internalformat");
+    case GST_GL_R16:
+    case GST_GL_RG16:
+      return gst_gl_context_check_gl_version (context,
+          GST_GL_API_OPENGL | GST_GL_API_OPENGL3, 3, 0)
+          || (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 1)
+          && gst_gl_context_check_feature (context, "GL_EXT_texture_norm16"));
     default:
       g_assert_not_reached ();
       return FALSE;
index 8705d45..1e95ceb 100644 (file)
@@ -98,6 +98,8 @@ G_BEGIN_DECLS
  *                           a 8-bit component for stencil informat.
  * @GST_GL_RGBA10_A2: Four components of bit depth 10, 10, 10 and 2 stored in the
  *                    R, G, B and A texture components respectively.
+ * @GST_GL_R16: Single 16-bit component stored in the R texture component
+ * @GST_GL_RG16: Two 16-bit components stored in the R and G texture components
  */
 typedef enum
 {
@@ -128,6 +130,9 @@ typedef enum
   GST_GL_DEPTH24_STENCIL8               = 0x88F0,
 
   GST_GL_RGB10_A2                       = 0x8059,
+
+  GST_GL_R16                            = 0x822A,
+  GST_GL_RG16                           = 0x822C,
 } GstGLFormat;
 
 GST_GL_API
index b18bbf3..3c5610b 100644 (file)
@@ -51,9 +51,9 @@ GType gst_gl_memory_allocator_get_type(void);
  * List of video formats that are supported by #GstGLMemory
  */
 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define MEMORY_VIDEO_EXT_FORMATS ", BGR10A2_LE, RGB10A2_LE"
+#define MEMORY_VIDEO_EXT_FORMATS ", BGR10A2_LE, RGB10A2_LE, P010_10LE"
 #else
-#define MEMORY_VIDEO_EXT_FORMATS ""
+#define MEMORY_VIDEO_EXT_FORMATS ", P010_10BE"
 #endif
 
 #define GST_GL_MEMORY_VIDEO_FORMATS_STR \