<div dir="ltr">Please review.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 27 Sep 2020 at 23:58, Vikram Fugro <<a href="mailto:vikram.fugro@gmail.com">vikram.fugro@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Add raw video fourcc conversion support to convert<br>
from gstreamer representation (for strings that are<br>
not equal to length 4) to vlc representation.<br>
---<br>
 modules/codec/Makefile.am                     |  4 +-<br>
 modules/codec/gstreamer/fourcc.c              | 92 +++++++++++++++++++<br>
 modules/codec/gstreamer/gstvlc.h              | 34 +++++++<br>
 .../gstreamer/gstvlcpictureplaneallocator.c   | 26 +++++-<br>
 4 files changed, 151 insertions(+), 5 deletions(-)<br>
 create mode 100644 modules/codec/gstreamer/fourcc.c<br>
 create mode 100644 modules/codec/gstreamer/gstvlc.h<br>
<br>
diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am<br>
index f8ff8b35bc..cd61920831 100644<br>
--- a/modules/codec/Makefile.am<br>
+++ b/modules/codec/Makefile.am<br>
@@ -604,7 +604,9 @@ libgstdecode_plugin_la_SOURCES = codec/gstreamer/gstdecode.c \<br>
                                                                 codec/gstreamer/gstvlcvideopool.c \<br>
                                                                 codec/gstreamer/gstvlcvideopool.h \<br>
                                                                 codec/gstreamer/gstvlcvideosink.c \<br>
-                                                                codec/gstreamer/gstvlcvideosink.h<br>
+                                                                codec/gstreamer/gstvlcvideosink.h \<br>
+                                                                codec/gstreamer/fourcc.c \<br>
+                                                                codec/gstreamer/gstvlc.h<br>
 libgstdecode_plugin_la_CFLAGS = $(AM_CFLAGS) $(GST_VIDEO_CFLAGS) $(GST_APP_CFLAGS)<br>
 libgstdecode_plugin_la_LIBADD = $(GST_VIDEO_LIBS) $(GST_APP_LIBS)<br>
 if HAVE_GST_DECODE<br>
diff --git a/modules/codec/gstreamer/fourcc.c b/modules/codec/gstreamer/fourcc.c<br>
new file mode 100644<br>
index 0000000000..28d92890bf<br>
--- /dev/null<br>
+++ b/modules/codec/gstreamer/fourcc.c<br>
@@ -0,0 +1,92 @@<br>
+<br>
+/*****************************************************************************<br>
+ * fourcc.c: convert between gst <->  vlc formats<br>
+ *****************************************************************************<br>
+ * Copyright (C) 2020 VLC authors and VideoLAN<br>
+ * $Id:<br>
+ *<br>
+ * Author: Vikram Fugro <<a href="mailto:vikram.fugro@gmail.com" target="_blank">vikram.fugro@gmail.com</a>><br>
+ *<br>
+ * This library is free software; you can redistribute it and/or<br>
+ * modify it under the terms of the GNU Library General Public<br>
+ * License as published by the Free Software Foundation; either<br>
+ * version 2.1 of the License, or (at your option) any later version.<br>
+ *<br>
+ * This library is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
+ * Lesser General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU Library General Public<br>
+ * License along with this library; if not, write to the Free Software<br>
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA<br>
+ *****************************************************************************/<br>
+<br>
+/*****************************************************************************<br>
+ * Preamble<br>
+ *****************************************************************************/<br>
+<br>
+#include "gstvlc.h"<br>
+<br>
+typedef struct<br>
+{<br>
+    char gst [10];<br>
+    vlc_fourcc_t i_fourcc;<br>
+} gst_vlc_rawvideo_fourcc;<br>
+<br>
+/*<br>
+ * Raw Video Formats<br>
+ */<br>
+static const gst_vlc_rawvideo_fourcc raw_video_fmts[] =<br>
+{<br>
+    // NOTE: These should be sorted entries, keyed by `gst` field<br>
+    // cat entries | tr -dc "[:alnum:][:space:]_" | sort -n -k1 | xargs printf "{ \"%s\", %s },\n"<br>
+    { "I420_10BE", VLC_CODEC_I420_10B },<br>
+    { "I420_10LE", VLC_CODEC_I420_10L },<br>
+    { "I420_12BE", VLC_CODEC_I420_12B },<br>
+    { "I420_12LE", VLC_CODEC_I420_12L },<br>
+    { "I420_16BE", VLC_CODEC_I420_16B },<br>
+    { "I420_16LE", VLC_CODEC_I420_16L },<br>
+    { "I420_9BE", VLC_CODEC_I420_9B },<br>
+    { "I420_9LE", VLC_CODEC_I420_9L },<br>
+    { "I422_10BE", VLC_CODEC_I422_10B },<br>
+    { "I422_10LE", VLC_CODEC_I422_10L },<br>
+    { "I422_12BE", VLC_CODEC_I422_12B },<br>
+    { "I422_12LE", VLC_CODEC_I422_12L },<br>
+    { "I422_16BE", VLC_CODEC_I422_16B },<br>
+    { "I422_16LE", VLC_CODEC_I422_16L },<br>
+    { "I422_9BE", VLC_CODEC_I422_9B },<br>
+    { "I422_9LE", VLC_CODEC_I422_9L },<br>
+    { "I444_10BE", VLC_CODEC_I444_10B },<br>
+    { "I444_10LE", VLC_CODEC_I444_10L },<br>
+    { "I444_12BE", VLC_CODEC_I444_12B },<br>
+    { "I444_12LE", VLC_CODEC_I444_12L },<br>
+    { "I444_16BE", VLC_CODEC_I444_16B },<br>
+    { "I444_16LE", VLC_CODEC_I444_16L },<br>
+    { "I444_9BE", VLC_CODEC_I444_9B },<br>
+    { "I444_9LE", VLC_CODEC_I444_9L },<br>
+};<br>
+<br>
+static int compare_func( const void* key, const void* ent )<br>
+{<br>
+    return strcmp( (char*)key, ((gst_vlc_rawvideo_fourcc*)ent)->gst );<br>
+}<br>
+<br>
+vlc_fourcc_t GetGstVLCFourcc( const char* gst )<br>
+{<br>
+    gst_vlc_rawvideo_fourcc* found = NULL;<br>
+<br>
+    if( !gst )<br>
+    {<br>
+        return VLC_CODEC_UNKNOWN;<br>
+    }<br>
+<br>
+    found = bsearch( gst, raw_video_fmts,<br>
+                ARRAY_SIZE(raw_video_fmts), sizeof(gst_vlc_rawvideo_fourcc),<br>
+                compare_func );<br>
+<br>
+    if( !found )<br>
+        return VLC_CODEC_UNKNOWN;<br>
+    else<br>
+        return found->i_fourcc;<br>
+}<br>
diff --git a/modules/codec/gstreamer/gstvlc.h b/modules/codec/gstreamer/gstvlc.h<br>
new file mode 100644<br>
index 0000000000..f99b827d8f<br>
--- /dev/null<br>
+++ b/modules/codec/gstreamer/gstvlc.h<br>
@@ -0,0 +1,34 @@<br>
+/*****************************************************************************<br>
+ * gst.h:<br>
+ *****************************************************************************<br>
+ * Copyright (C) 2020 VLC authors and VideoLAN<br>
+ *<br>
+ * Author: Vikram Fugro <<a href="mailto:vikram.fugro@gmail.com" target="_blank">vikram.fugro@gmail.com</a>><br>
+ *<br>
+ * This library is free software; you can redistribute it and/or<br>
+ * modify it under the terms of the GNU Library General Public<br>
+ * License as published by the Free Software Foundation; either<br>
+ * version 2.1 of the License, or (at your option) any later version.<br>
+ *<br>
+ * This library is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
+ * Lesser General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU Library General Public<br>
+ * License along with this library; if not, write to the Free Software<br>
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA<br>
+ *****************************************************************************/<br>
+<br>
+/*****************************************************************************<br>
+ * Preamble<br>
+ *****************************************************************************/<br>
+#ifndef VLC_GST_H_<br>
+#define VLC_GST_H_<br>
+<br>
+#include <vlc_common.h><br>
+#include <vlc_codec.h><br>
+<br>
+vlc_fourcc_t GetGstVLCFourcc( const char* );<br>
+<br>
+#endif /* VLC_GST_H_ */<br>
diff --git a/modules/codec/gstreamer/gstvlcpictureplaneallocator.c b/modules/codec/gstreamer/gstvlcpictureplaneallocator.c<br>
index 2245ee551a..e240435107 100644<br>
--- a/modules/codec/gstreamer/gstvlcpictureplaneallocator.c<br>
+++ b/modules/codec/gstreamer/gstvlcpictureplaneallocator.c<br>
@@ -27,6 +27,7 @@<br>
 #include <gst/gst.h><br>
<br>
 #include "gstvlcpictureplaneallocator.h"<br>
+#include "gstvlc.h"<br>
<br>
 #include <vlc_common.h><br>
<br>
@@ -130,6 +131,22 @@ static GstMemory* gst_vlc_picture_plane_copy(<br>
     return NULL;<br>
 }<br>
<br>
+static vlc_fourcc_t gst_vlc_to_map_format( char* psz_fourcc )<br>
+{<br>
+    if( !psz_fourcc )<br>
+        return VLC_CODEC_UNKNOWN;<br>
+<br>
+    if( strlen( psz_fourcc ) != 4 )<br>
+    {<br>
+        return GetGstVLCFourcc( psz_fourcc );<br>
+    }<br>
+    else<br>
+    {<br>
+        return vlc_fourcc_GetCodecFromString(<br>
+                VIDEO_ES, psz_fourcc );<br>
+    }<br>
+}<br>
+<br>
 void gst_vlc_picture_plane_allocator_release(<br>
     GstVlcPicturePlaneAllocator *p_allocator, GstBuffer *p_buffer )<br>
 {<br>
@@ -212,6 +229,7 @@ bool gst_vlc_picture_plane_allocator_alloc(<br>
     return true;<br>
 }<br>
<br>
+<br>
 bool gst_vlc_set_vout_fmt( GstVideoInfo *p_info, GstVideoAlignment *p_align,<br>
         GstCaps *p_caps, decoder_t *p_dec )<br>
 {<br>
@@ -221,10 +239,10 @@ bool gst_vlc_set_vout_fmt( GstVideoInfo *p_info, GstVideoAlignment *p_align,<br>
     vlc_fourcc_t i_chroma;<br>
     int i_padded_width, i_padded_height;<br>
<br>
-    i_chroma = p_outfmt->i_codec = vlc_fourcc_GetCodecFromString(<br>
-            VIDEO_ES,<br>
-            gst_structure_get_string( p_str, "format" ) );<br>
-    if( !i_chroma )<br>
+    const char* psz_fourcc = gst_structure_get_string( p_str, "format" );<br>
+<br>
+    i_chroma = p_outfmt->i_codec = gst_vlc_to_map_format( psz_fourcc );<br>
+    if( !i_chroma || i_chroma == VLC_CODEC_UNKNOWN )<br>
     {<br>
         msg_Err( p_dec, "video chroma type not supported" );<br>
         return false;<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div>