From 79ea87f256ec2f1a02920fb535d7ee520915d65d Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 14 Apr 2022 15:02:11 -0400 Subject: [PATCH] opengl: Add NV12_4L4 conversion support This format is produced notably by Hantro G1/G2 HW. Using a shader instead of the Hantro embedded converter helps reduce drastrictly the memory usage at a relatively small GPU overhead. Part-of: --- .../gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c | 1 + .../gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.c | 15 ++++++++++++++- .../gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.h | 2 +- .../gst-plugins-base/gst-libs/gst/gl/gstglformat.c | 1 + .../gst-plugins-base/gst-libs/gst/gl/gstglmemory.h | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c index 25fd068..e5b030b 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/egl/gsteglimage.c @@ -513,6 +513,7 @@ _drm_rgba_fourcc_from_info (const GstVideoInfo * info, int plane, case GST_VIDEO_FORMAT_NV16: case GST_VIDEO_FORMAT_NV61: case GST_VIDEO_FORMAT_NV12_16L32S: + case GST_VIDEO_FORMAT_NV12_4L4: *out_format = plane == 0 ? GST_GL_RED : GST_GL_RG; return plane == 0 ? DRM_FORMAT_R8 : rg_fourcc; diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.c index a59e6aa..78d0b37 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.c @@ -1129,7 +1129,8 @@ _init_supported_formats (GstGLContext * context, gboolean output, } if (!context || USING_GLES3 (context) || USING_OPENGL30 (context)) { - _append_value_string_list (supported_formats, "NV12_16L32S", NULL); + _append_value_string_list (supported_formats, "NV12_16L32S", "NV12_4L4", + NULL); } } @@ -1763,6 +1764,7 @@ _get_n_textures (GstVideoFormat v_format) case GST_VIDEO_FORMAT_P016_LE: case GST_VIDEO_FORMAT_P016_BE: case GST_VIDEO_FORMAT_NV12_16L32S: + case GST_VIDEO_FORMAT_NV12_4L4: return 2; case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_Y444: @@ -2127,6 +2129,17 @@ _YUV_to_RGB (GstGLColorConvert * convert) info->shader_tex_names[1] = "UVtex"; break; } + case GST_VIDEO_FORMAT_NV12_4L4: + { + char val2 = convert->priv->in_tex_formats[1] == GST_GL_RG ? 'g' : 'a'; + info->templ = &templ_TILED_SEMI_PLANAR_to_RGB; + info->frag_body = g_strdup_printf (templ_TILED_SEMI_PLANAR_to_RGB_BODY, + 4, 4, 2, 4, 'r', val2, + 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; } diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.h index 3bf1f42..83b8dc0 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.h @@ -103,7 +103,7 @@ struct _GstGLColorConvertClass "xBGR, ARGB, ABGR, GBRA, GBR, RGBP, BGRP, Y444, I420, YV12, Y42B, " \ "Y41B, NV12, NV21, NV16, NV61, YUY2, UYVY, Y210, AYUV, " \ "VUYA, Y410, GRAY8, GRAY16_LE, GRAY16_BE, " \ - "RGB16, BGR16, ARGB64, A420, AV12, NV12_16L32S" \ + "RGB16, BGR16, ARGB64, A420, AV12, NV12_16L32S, NV12_4L4" \ GST_GL_COLOR_CONVERT_EXT_FORMATS "}" /** diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.c index b624ac3..2649056 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.c @@ -193,6 +193,7 @@ gst_gl_format_from_video_info (GstGLContext * context, case GST_VIDEO_FORMAT_NV16: case GST_VIDEO_FORMAT_NV61: case GST_VIDEO_FORMAT_NV12_16L32S: + case GST_VIDEO_FORMAT_NV12_4L4: n_plane_components = plane == 0 ? 1 : 2; break; case GST_VIDEO_FORMAT_AV12: diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmemory.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmemory.h index 0916c4f..5000759 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmemory.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmemory.h @@ -64,7 +64,7 @@ GType gst_gl_memory_allocator_get_type(void); #define GST_GL_MEMORY_VIDEO_FORMATS_STR \ "{ RGBA, BGRA, RGBx, BGRx, ARGB, ABGR, xRGB, xBGR, GBRA, GBR, RGBP, BGRP, RGB, BGR, RGB16, BGR16, " \ "AYUV, VUYA, Y410, I420, YV12, NV12, NV21, NV16, NV61, YUY2, UYVY, Y210, Y41B, " \ - "Y42B, Y444, GRAY8, GRAY16_LE, GRAY16_BE, ARGB64, A420, AV12, NV12_16L32S" \ + "Y42B, Y444, GRAY8, GRAY16_LE, GRAY16_BE, ARGB64, A420, AV12, NV12_16L32S, NV12_4L4" \ GST_GL_MEMORY_VIDEO_EXT_FORMATS "}" /** -- 2.7.4