mxfdemux: Add support for Canon XF-HEVC
authorEdward Hervey <edward@centricular.com>
Wed, 12 Oct 2022 09:12:50 +0000 (11:12 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 12 Oct 2022 09:15:57 +0000 (09:15 +0000)
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1495

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

subprojects/gst-plugins-bad/gst/mxf/gstmxfelement.c
subprojects/gst-plugins-bad/gst/mxf/meson.build
subprojects/gst-plugins-bad/gst/mxf/mxfcustom.c [new file with mode: 0644]
subprojects/gst-plugins-bad/gst/mxf/mxfcustom.h [new file with mode: 0644]

index f2c1166..c9ca201 100644 (file)
@@ -38,6 +38,7 @@
 #include "mxfvc3.h"
 #include "mxfprores.h"
 #include "mxfvanc.h"
+#include "mxfcustom.h"
 
 GST_DEBUG_CATEGORY (mxf_debug);
 #define GST_CAT_DEFAULT mxf_debug
@@ -77,6 +78,7 @@ mxf_element_init (GstPlugin * plugin)
     mxf_vc3_init ();
     mxf_prores_init ();
     mxf_vanc_init ();
+    mxf_custom_init ();
     g_once_init_leave (&res, TRUE);
   }
 }
index 73d08b3..24ec93a 100644 (file)
@@ -18,6 +18,7 @@ mxf_sources = [
   'mxfvc3.c',
   'mxfprores.c',
   'mxfvanc.c',
+  'mxfcustom.c',
 #  'mxfdms1.c',
 ]
 
diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfcustom.c b/subprojects/gst-plugins-bad/gst/mxf/mxfcustom.c
new file mode 100644 (file)
index 0000000..d266045
--- /dev/null
@@ -0,0 +1,115 @@
+/* GStreamer
+ * Copyright (C) 2022 Edward Hervey <edward@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.
+ */
+
+/* Custom mappings
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <gst/base/base.h>
+#include <gst/video/video.h>
+#include <string.h>
+
+#include "mxfcustom.h"
+#include "mxfessence.h"
+
+GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
+#define GST_CAT_DEFAULT mxf_debug
+
+/* Custom Canon XF-HEVC essence */
+static const MXFUL mxf_canon_xf_hevc = { {0x06, 0x0E, 0x2B, 0x34,
+        0x04, 0x01, 0x01, 0x0c,
+        0x0e, 0x15, 0x00, 0x04,
+    0x02, 0x10, 0x00, 0x01}
+};
+
+static gboolean
+mxf_is_canon_xfhevc_essence_track (const MXFMetadataTimelineTrack * track)
+{
+  guint i;
+
+  g_return_val_if_fail (track != NULL, FALSE);
+
+  if (track->parent.descriptor == NULL)
+    return FALSE;
+
+  for (i = 0; i < track->parent.n_descriptor; i++) {
+    MXFMetadataFileDescriptor *d = track->parent.descriptor[i];
+    MXFUL *key;
+
+    if (!d)
+      continue;
+
+    key = &d->essence_container;
+    if (mxf_ul_is_equal (key, &mxf_canon_xf_hevc))
+      return TRUE;
+  }
+
+  return FALSE;
+}
+
+static GstFlowReturn
+mxf_canon_xfhevc_handle_essence_element (const MXFUL * key, GstBuffer * buffer,
+    GstCaps * caps,
+    MXFMetadataTimelineTrack * track,
+    gpointer mapping_data, GstBuffer ** outbuf)
+{
+  *outbuf = buffer;
+  /* Blindly accept it */
+  return GST_FLOW_OK;
+}
+
+static MXFEssenceWrapping
+mxf_canon_xfhevc_get_track_wrapping (const MXFMetadataTimelineTrack * track)
+{
+  /* Assume it's always frame wrapping */
+  return MXF_ESSENCE_WRAPPING_FRAME_WRAPPING;
+}
+
+static GstCaps *
+mxf_canon_xfhevc_create_caps (MXFMetadataTimelineTrack * track,
+    GstTagList ** tags, gboolean * intra_only,
+    MXFEssenceElementHandleFunc * handler, gpointer * mapping_data)
+{
+  GstCaps *caps = NULL;
+
+  g_return_val_if_fail (track != NULL, NULL);
+
+  *handler = mxf_canon_xfhevc_handle_essence_element;
+  *intra_only = TRUE;
+  caps = gst_caps_from_string ("video/x-h265");
+
+  return caps;
+}
+
+static const MXFEssenceElementHandler mxf_canon_xfhevc_essence_element_handler = {
+  mxf_is_canon_xfhevc_essence_track,
+  mxf_canon_xfhevc_get_track_wrapping,
+  mxf_canon_xfhevc_create_caps
+};
+
+void
+mxf_custom_init (void)
+{
+  mxf_essence_element_handler_register
+      (&mxf_canon_xfhevc_essence_element_handler);
+}
diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfcustom.h b/subprojects/gst-plugins-bad/gst/mxf/mxfcustom.h
new file mode 100644 (file)
index 0000000..cd085a6
--- /dev/null
@@ -0,0 +1,30 @@
+/* GStreamer
+ * Copyright (C) 2022 Edward Hervey <edward@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.
+ */
+
+/* Custom mappings
+ */
+
+#ifndef __MXF_CUSTOM_H__
+#define __MXF_CUSTOM_H__
+
+#include <gst/gst.h>
+
+void mxf_custom_init (void);
+
+#endif /* __MXF_CUSTOM_H__ */