vpx: Define formats for compatibility
authorSeungha Yang <seungha@centricular.com>
Sun, 30 Oct 2022 11:03:10 +0000 (20:03 +0900)
committerSeungha Yang <seungha@centricular.com>
Thu, 3 Nov 2022 20:14:23 +0000 (05:14 +0900)
ifdef for enum values never work. Instead, define new enum type
and use it

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3298>

subprojects/gst-plugins-good/ext/vpx/gstvp9dec.c
subprojects/gst-plugins-good/ext/vpx/gstvp9enc.c
subprojects/gst-plugins-good/ext/vpx/gstvpxcompat.h [new file with mode: 0644]
subprojects/gst-plugins-good/ext/vpx/gstvpxdec.h
subprojects/gst-plugins-good/ext/vpx/gstvpxenc.h

index dea6655..ae9833f 100644 (file)
@@ -148,34 +148,31 @@ gst_vp9_dec_get_valid_format (GstVPXDec * dec, vpx_image_t * img,
     GstVideoFormat * fmt)
 {
   switch (img->fmt) {
-    case VPX_IMG_FMT_I420:
+    case GST_VPX_IMG_FMT_I420:
       *fmt = GST_VIDEO_FORMAT_I420;
       return TRUE;
 
-    case VPX_IMG_FMT_YV12:
+    case GST_VPX_IMG_FMT_YV12:
       *fmt = GST_VIDEO_FORMAT_YV12;
       return TRUE;
 
-    case VPX_IMG_FMT_I422:
+    case GST_VPX_IMG_FMT_I422:
       *fmt = GST_VIDEO_FORMAT_Y42B;
       return TRUE;
 
-    case VPX_IMG_FMT_I444:
+    case GST_VPX_IMG_FMT_I444:
       if (img->cs == VPX_CS_SRGB)
         *fmt = GST_VIDEO_FORMAT_GBR;
       else
         *fmt = GST_VIDEO_FORMAT_Y444;
       return TRUE;
-#ifdef VPX_IMG_FMT_I440
-    case VPX_IMG_FMT_I440:
+    case GST_VPX_IMG_FMT_I440:
       /* Planar, half height, full width U/V */
       GST_FIXME_OBJECT (dec, "Please add a 4:4:0 planar frame format");
       GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
           (NULL), ("Unsupported frame format - 4:4:0 planar"));
       return FALSE;
-#endif
-    case VPX_IMG_FMT_I42016:
-      /* VPX_IMG_FMT_I420 | VPX_IMG_FMT_HIGHBITDEPTH */
+    case GST_VPX_IMG_FMT_I42016:
       if (img->bit_depth == 10) {
         *fmt = GST_VIDEO_FORMAT_I420_10LE;
         return TRUE;
@@ -184,8 +181,7 @@ gst_vp9_dec_get_valid_format (GstVPXDec * dec, vpx_image_t * img,
       GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
           (NULL), ("Unsupported frame format - 16-bit 4:2:0 planar"));
       return FALSE;
-    case VPX_IMG_FMT_I42216:
-      /* VPX_IMG_FMT_I422 | VPX_IMG_FMT_HIGHBITDEPTH */
+    case GST_VPX_IMG_FMT_I42216:
       if (img->bit_depth == 10) {
         *fmt = GST_VIDEO_FORMAT_I422_10LE;
         return TRUE;
@@ -194,22 +190,16 @@ gst_vp9_dec_get_valid_format (GstVPXDec * dec, vpx_image_t * img,
       GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
           (NULL), ("Unsupported frame format - 16-bit 4:2:2 planar"));
       return FALSE;
-#ifdef VPX_IMG_FMT_I44416
-    case VPX_IMG_FMT_I44416:
-      /* VPX_IMG_FMT_I444 | VPX_IMG_FMT_HIGHBITDEPTH */
+    case GST_VPX_IMG_FMT_I44416:
       GST_FIXME_OBJECT (dec, "Please add 16-bit Y444 format");
       GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
           (NULL), ("Unsupported frame format - 16-bit 4:4:4 planar"));
       return FALSE;
-#endif
-#ifdef VPX_IMG_FMT_I44016
-    case VPX_IMG_FMT_I44016:
-      /* VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH */
+    case GST_VPX_IMG_FMT_I44016:
       GST_FIXME_OBJECT (dec, "Please add 16-bit 4:4:0 planar frame format");
       GST_ELEMENT_WARNING (dec, STREAM, NOT_IMPLEMENTED,
           (NULL), ("Unsupported frame format - 16-bit 4:4:0 planar"));
       return FALSE;
-#endif
     default:
       return FALSE;
   }
index 2145996..e79ae2b 100644 (file)
@@ -395,6 +395,7 @@ gst_vp9_get_vpx_colorspace (GstVPXEnc * encoder, GstVideoColorimetry * in_cinfo,
   gchar *colorimetry_str;
   guint i;
 
+  /* *INDENT-OFF* */
   static const struct
   {
     const gchar *str;
@@ -406,6 +407,7 @@ gst_vp9_get_vpx_colorspace (GstVPXEnc * encoder, GstVideoColorimetry * in_cinfo,
     GST_VIDEO_COLORIMETRY_SMPTE240M, VPX_CS_SMPTE_240}, {
     GST_VIDEO_COLORIMETRY_BT2020, VPX_CS_BT_2020}
   };
+  /* *INDENT-ON* */
 
   /* We support any range, all mapped CSC are by default reduced range. */
   cinfo.range = GST_VIDEO_COLOR_RANGE_16_235;
@@ -533,33 +535,33 @@ gst_vp9_enc_set_image_format (GstVPXEnc * enc, vpx_image_t * image)
 {
   switch (enc->input_state->info.finfo->format) {
     case GST_VIDEO_FORMAT_I420:
-      image->fmt = VPX_IMG_FMT_I420;
+      image->fmt = GST_VPX_IMG_FMT_I420;
       image->bps = 12;
       image->x_chroma_shift = image->y_chroma_shift = 1;
       break;
     case GST_VIDEO_FORMAT_YV12:
-      image->fmt = VPX_IMG_FMT_YV12;
+      image->fmt = GST_VPX_IMG_FMT_YV12;
       image->bps = 12;
       image->x_chroma_shift = image->y_chroma_shift = 1;
       break;
     case GST_VIDEO_FORMAT_Y42B:
-      image->fmt = VPX_IMG_FMT_I422;
+      image->fmt = GST_VPX_IMG_FMT_I422;
       image->bps = 16;
       image->x_chroma_shift = 1;
       image->y_chroma_shift = 0;
       break;
     case GST_VIDEO_FORMAT_Y444:
-      image->fmt = VPX_IMG_FMT_I444;
+      image->fmt = GST_VPX_IMG_FMT_I444;
       image->bps = 24;
       image->x_chroma_shift = image->y_chroma_shift = 0;
       break;
     case GST_VIDEO_FORMAT_I420_10LE:
-      image->fmt = VPX_IMG_FMT_I42016;
+      image->fmt = GST_VPX_IMG_FMT_I42016;
       image->bps = 15;
       image->x_chroma_shift = image->y_chroma_shift = 1;
       break;
     case GST_VIDEO_FORMAT_I422_10LE:
-      image->fmt = VPX_IMG_FMT_I42216;
+      image->fmt = GST_VPX_IMG_FMT_I42216;
       image->bps = 20;
       image->x_chroma_shift = 1;
       image->y_chroma_shift = 0;
diff --git a/subprojects/gst-plugins-good/ext/vpx/gstvpxcompat.h b/subprojects/gst-plugins-good/ext/vpx/gstvpxcompat.h
new file mode 100644 (file)
index 0000000..1919791
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * GStreamer
+ * Copyright (C) 2022 Seungha Yang <seungha@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+#define GST_VPX_IMG_FMT_PLANAR 0x100
+#define GST_VPX_IMG_FMT_UV_FLIP 0x200
+#define GST_VPX_IMG_FMT_HIGHBITDEPTH 0x800
+
+/* vpx_img_fmt with GST_ prefix */
+typedef enum gst_vpx_img_fmt
+{
+  GST_VPX_IMG_FMT_NONE,
+  GST_VPX_IMG_FMT_YV12 = GST_VPX_IMG_FMT_PLANAR | GST_VPX_IMG_FMT_UV_FLIP | 1,
+  GST_VPX_IMG_FMT_I420 = GST_VPX_IMG_FMT_PLANAR | 2,
+  GST_VPX_IMG_FMT_I422 = GST_VPX_IMG_FMT_PLANAR | 5,
+  GST_VPX_IMG_FMT_I444 = GST_VPX_IMG_FMT_PLANAR | 6,
+  GST_VPX_IMG_FMT_I440 = GST_VPX_IMG_FMT_PLANAR | 7,
+  GST_VPX_IMG_FMT_NV12 = GST_VPX_IMG_FMT_PLANAR | 9,
+  GST_VPX_IMG_FMT_I42016 = GST_VPX_IMG_FMT_I420 | GST_VPX_IMG_FMT_HIGHBITDEPTH,
+  GST_VPX_IMG_FMT_I42216 = GST_VPX_IMG_FMT_I422 | GST_VPX_IMG_FMT_HIGHBITDEPTH,
+  GST_VPX_IMG_FMT_I44416 = GST_VPX_IMG_FMT_I444 | GST_VPX_IMG_FMT_HIGHBITDEPTH,
+  GST_VPX_IMG_FMT_I44016 = GST_VPX_IMG_FMT_I440 | GST_VPX_IMG_FMT_HIGHBITDEPTH
+} gst_vpx_img_fmt_t;
+
+G_END_DECLS
index 00035f5..e48f4e7 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <gst/gst.h>
 #include <gst/video/gstvideodecoder.h>
+#include "gstvpxcompat.h"
 
 /* FIXME: Undef HAVE_CONFIG_H because vpx_codec.h uses it,
  * which causes compilation failures */
index ad458f2..d9c40e5 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <gst/gst.h>
 #include <gst/video/gstvideoencoder.h>
+#include "gstvpxcompat.h"
 
 /* FIXME: Undef HAVE_CONFIG_H because vpx_codec.h uses it,
  * which causes compilation failures */