}
}
+static GstH264ParserResult
+gst_h264_parser_parse_user_data_unregistered (GstH264NalParser * nalparser,
+ GstH264UserDataUnregistered * urud, NalReader * nr, guint payload_size)
+{
+ guint8 *data = NULL;
+ gint i;
+
+ if (payload_size < 16) {
+ GST_WARNING ("Too small payload size %d", payload_size);
+ return GST_H264_PARSER_BROKEN_DATA;
+ }
+
+ for (int i = 0; i < 16; i++) {
+ READ_UINT8 (nr, urud->uuid[i], 8);
+ --payload_size;
+ }
+
+ urud->size = payload_size;
+
+ data = g_malloc0 (payload_size);
+ for (i = 0; i < payload_size; ++i) {
+ READ_UINT8 (nr, data[i], 8);
+ }
+
+ if (payload_size < 1) {
+ GST_WARNING ("No more remaining payload data to store");
+ return GST_H264_PARSER_BROKEN_DATA;
+ }
+
+ urud->data = data;
+ GST_MEMDUMP ("SEI user data unregistered", data, payload_size);
+ return GST_H264_PARSER_OK;
+
+error:
+ {
+ GST_WARNING ("error parsing \"User Data Unregistered\"");
+ return GST_H264_PARSER_ERROR;
+ }
+}
+
static GstH264ParserResult
gst_h264_parser_parse_recovery_point (GstH264NalParser * nalparser,
GstH264RecoveryPoint * rp, NalReader * nr)
res = gst_h264_parser_parse_registered_user_data (nalparser,
&sei->payload.registered_user_data, nr, payload_size >> 3);
break;
+ case GST_H264_SEI_USER_DATA_UNREGISTERED:
+ res = gst_h264_parser_parse_user_data_unregistered (nalparser,
+ &sei->payload.user_data_unregistered, nr, payload_size >> 3);
+ break;
case GST_H264_SEI_RECOVERY_POINT:
res = gst_h264_parser_parse_recovery_point (nalparser,
&sei->payload.recovery_point, nr);
* @GST_H264_SEI_BUF_PERIOD: Buffering Period SEI Message
* @GST_H264_SEI_PIC_TIMING: Picture Timing SEI Message
* @GST_H264_SEI_REGISTERED_USER_DATA: Registered user data (D.2.5)
+ * @GST_H264_SEI_USER_DATA_UNREGISTERED: Registered user data (D.2.6) (Since: 1.22)
* @GST_H264_SEI_RECOVERY_POINT: Recovery Point SEI Message (D.2.7)
* @GST_H264_SEI_STEREO_VIDEO_INFO: stereo video info SEI message (Since: 1.6)
* @GST_H264_SEI_FRAME_PACKING: Frame Packing Arrangement (FPA) message that
GST_H264_SEI_BUF_PERIOD = 0,
GST_H264_SEI_PIC_TIMING = 1,
GST_H264_SEI_REGISTERED_USER_DATA = 4,
+ GST_H264_SEI_USER_DATA_UNREGISTERED = 5,
GST_H264_SEI_RECOVERY_POINT = 6,
GST_H264_SEI_STEREO_VIDEO_INFO = 21,
GST_H264_SEI_FRAME_PACKING = 45,
typedef struct _GstH264ClockTimestamp GstH264ClockTimestamp;
typedef struct _GstH264PicTiming GstH264PicTiming;
typedef struct _GstH264RegisteredUserData GstH264RegisteredUserData;
+typedef struct _GstH264UserDataUnregistered GstH264UserDataUnregistered;
typedef struct _GstH264BufferingPeriod GstH264BufferingPeriod;
typedef struct _GstH264RecoveryPoint GstH264RecoveryPoint;
typedef struct _GstH264StereoVideoInfo GstH264StereoVideoInfo;
guint size;
};
+/**
+ * GstH264UserDataUnregistered:
+ * The User data unregistered SEI message syntax.
+ * @uuid: an uuid_iso_iec_11578.
+ * @data: the data of user_data_payload_byte
+ * @size: the size of @data in bytes
+ *
+ * Since: 1.22
+ */
+struct _GstH264UserDataUnregistered
+{
+ guint8 uuid[16];
+ const guint8 *data;
+ guint size;
+};
+
struct _GstH264BufferingPeriod
{
GstH264SPS *sps;
GstH264MasteringDisplayColourVolume mastering_display_colour_volume;
GstH264ContentLightLevel content_light_level;
GstH264SEIUnhandledPayload unhandled_payload;
+ GstH264UserDataUnregistered user_data_unregistered;
/* ... could implement more */
} payload;
};
{
GstH264Parse *h264parse = GST_H264_PARSE (object);
+ gst_video_user_data_unregistered_free (&h264parse->user_data_unregistered);
+
g_object_unref (h264parse->frame_out);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
+static void
+gst_h264_parse_process_sei_user_data_unregistered (GstH264Parse * h264parse,
+ GstH264UserDataUnregistered * urud)
+{
+ GstByteReader br;
+
+ if (urud->data == NULL || urud->size < 1)
+ return;
+
+ gst_byte_reader_init (&br, urud->data, urud->size);
+
+ gst_video_parse_user_data_unregistered ((GstElement *) h264parse,
+ &h264parse->user_data_unregistered, &br, urud->uuid);
+}
+
static void
gst_h264_parse_process_sei (GstH264Parse * h264parse, GstH264NalUnit * nalu)
{
gst_h264_parse_process_sei_user_data (h264parse,
&sei.payload.registered_user_data);
break;
+ case GST_H264_SEI_USER_DATA_UNREGISTERED:
+ gst_h264_parse_process_sei_user_data_unregistered (h264parse,
+ &sei.payload.user_data_unregistered);
+ break;
case GST_H264_SEI_BUF_PERIOD:
if (h264parse->ts_trn_nb == GST_CLOCK_TIME_NONE ||
h264parse->dts == GST_CLOCK_TIME_NONE)
gst_video_push_user_data ((GstElement *) h264parse, &h264parse->user_data,
parse_buffer);
+ gst_video_push_user_data_unregistered ((GstElement *) h264parse,
+ &h264parse->user_data_unregistered, parse_buffer);
+
gst_h264_parse_reset_frame (h264parse);
return GST_FLOW_OK;
gboolean first_in_bundle;
GstVideoParseUserData user_data;
+ GstVideoParseUserDataUnregistered user_data_unregistered;
GstVideoMasteringDisplayInfo mastering_display_info;
guint mastering_display_info_state;
#include <gst/base/base.h>
#include <gst/pbutils/pbutils.h>
#include <gst/video/video.h>
+#include <gst/video/video-sei.h>
#include <gst/base/gstbitreader.h>
#include <gstvideoparseutils.h>
afd->afd = (GstVideoAFDValue) afd_data;
return TRUE;
}
+
+/*
+ * gst_video_parse_user_data_unregistered:
+ * @elt: #GstElement that is parsing user data
+ * @user_data: #GstVideoParseUserDataUnregistered struct to hold parsed data
+ * @br: #GstByteReader attached to buffer of user data
+ * @uuid: User Data Unregistered UUID
+ *
+ * Parse user data and store in @user_data
+ */
+void
+gst_video_parse_user_data_unregistered (GstElement * elt,
+ GstVideoParseUserDataUnregistered * user_data,
+ GstByteReader * br, guint8 uuid[16])
+{
+ gst_video_user_data_unregistered_free (user_data);
+
+ memcpy (&user_data->uuid, uuid, 16);
+ user_data->size = gst_byte_reader_get_size (br);
+ gst_byte_reader_dup_data (br, user_data->size, &user_data->data);
+}
+
+/*
+ * gst_video_user_data_unregistered_free:
+ * @user_data: #GstVideoParseUserDataUnregistered holding SEI User Data Unregistered
+ *
+ * Frees the user data unregistered
+ */
+void
+gst_video_user_data_unregistered_free (GstVideoParseUserDataUnregistered *
+ user_data)
+{
+ g_free (user_data->data);
+ user_data->data = NULL;
+ user_data->size = 0;
+}
+
+/*
+ * gst_video_push_user_data_unregistered:
+ * @elt: #GstElement that is pushing user data
+ * @user_data: #GstVideoParseUserDataUnregistered holding SEI User Data Unregistered
+ * @buf: #GstBuffer that receives the parsed data
+ *
+ * After user data has been parsed, add the data to @buf
+ */
+void
+gst_video_push_user_data_unregistered (GstElement * elt,
+ GstVideoParseUserDataUnregistered * user_data, GstBuffer * buf)
+{
+ if (user_data->data != NULL) {
+ gst_buffer_add_video_sei_user_data_unregistered_meta (buf, user_data->uuid,
+ user_data->data, user_data->size);
+ gst_video_user_data_unregistered_free (user_data);
+ }
+}
} GstVideoParseUserData;
+/*
+ * GstVideoParseUserDataUnregistered
+ *
+ * Holds unparsed User Data Unregistered.
+ */
+typedef struct
+{
+ guint8 uuid[16];
+ guint8 *data;
+ gsize size;
+} GstVideoParseUserDataUnregistered;
+
G_BEGIN_DECLS
void gst_video_parse_user_data(GstElement * elt, GstVideoParseUserData * user_data,
GstByteReader * br, guint8 field, guint16 provider_code);
+void gst_video_parse_user_data_unregistered(GstElement * elt, GstVideoParseUserDataUnregistered * user_data,
+ GstByteReader * br, guint8 uuid[16]);
+
+void gst_video_user_data_unregistered_free(GstVideoParseUserDataUnregistered * user_data);
+
void gst_video_push_user_data(GstElement * elt, GstVideoParseUserData * user_data,
GstBuffer * buf);
+void gst_video_push_user_data_unregistered(GstElement * elt, GstVideoParseUserDataUnregistered * user_data,
+ GstBuffer * buf);
+
G_END_DECLS
#endif /* __VIDEO_PARSE_UTILS_H__ */
'video-multiview.c',
'video-resampler.c',
'video-scaler.c',
+ 'video-sei.c',
'video-tile.c',
'video-overlay-composition.c',
'videodirection.c',
--- /dev/null
+/* GStreamer
+ * Copyright (C) 2021 Fluendo S.A. <support@fluendo.com>
+ * Authors: Andoni Morales Alastruey <amorales@fluendo.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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <gst/base/gstbytereader.h>
+#include "video-sei.h"
+
+/**
+ * SECTION:gstvideosei
+ * @title: GstVideo SEI Unregistered User Data
+ * @short_description: Utilities for SEI User Data Unregistered
+ *
+ * A collection of objects and methods to assist with SEI User Data Unregistered
+ * metadata in H.264 and H.265 streams.
+ */
+
+/* ST 0604 Section 11.1 12.1, 12.2 */
+static const guint8 H264_MISP_MICROSECTIME[] = {
+ 0x4D, 0x49, 0x53, 0x50, 0x6D, 0x69, 0x63, 0x72,
+ 0x6F, 0x73, 0x65, 0x63, 0x74, 0x69, 0x6D, 0x65
+};
+
+static const guint8 H265_MISP_MICROSECONDS[] = {
+ 0xA8, 0x68, 0x7D, 0xD4, 0xD7, 0x59, 0x37, 0x58,
+ 0xA5, 0xCE, 0xF0, 0x33, 0x8B, 0x65, 0x45, 0xF1
+};
+
+static const guint8 H265_MISP_NANOSECONDS[] = {
+ 0xCF, 0x84, 0x82, 0x78, 0xEE, 0x23, 0x30, 0x6C,
+ 0x92, 0x65, 0xE8, 0xFE, 0xF2, 0x2F, 0xB8, 0xB8
+};
+
+#ifndef GST_DISABLE_GST_DEBUG
+#define GST_CAT_DEFAULT ensure_debug_category()
+static GstDebugCategory *
+ensure_debug_category (void)
+{
+ static gsize cat_gonce = 0;
+
+ if (g_once_init_enter (&cat_gonce)) {
+ gsize cat_done;
+
+ cat_done = (gsize) _gst_debug_category_new ("video-sei", 0,
+ "H.264 / H.265 SEI messages utilities");
+
+ g_once_init_leave (&cat_gonce, cat_done);
+ }
+
+ return (GstDebugCategory *) cat_gonce;
+}
+#else
+#define ensure_debug_category() /* NOOP */
+#endif /* GST_DISABLE_GST_DEBUG */
+
+/* SEI User Data Unregistered implementation */
+
+GType
+gst_video_sei_user_data_unregistered_meta_api_get_type (void)
+{
+ static GType type = 0;
+
+ if (g_once_init_enter (&type)) {
+ static const gchar *tags[] = {
+ GST_META_TAG_VIDEO_STR,
+ NULL
+ };
+ GType _type =
+ gst_meta_api_type_register ("GstVideoSEIUserDataUnregisteredMetaAPI",
+ tags);
+ g_once_init_leave (&type, _type);
+ }
+ return type;
+}
+
+static gboolean
+gst_video_sei_user_data_unregistered_meta_init (GstMeta * meta, gpointer params,
+ GstBuffer * buffer)
+{
+ GstVideoSEIUserDataUnregisteredMeta *emeta =
+ (GstVideoSEIUserDataUnregisteredMeta *) meta;
+
+ emeta->data = NULL;
+ emeta->size = 0;
+
+ return TRUE;
+}
+
+static gboolean
+gst_video_sei_user_data_unregistered_meta_transform (GstBuffer * dest,
+ GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data)
+{
+ GstVideoSEIUserDataUnregisteredMeta *smeta =
+ (GstVideoSEIUserDataUnregisteredMeta *) meta;
+
+ if (GST_META_TRANSFORM_IS_COPY (type)) {
+ GST_DEBUG ("copy SEI User Data Unregistered metadata");
+ gst_buffer_add_video_sei_user_data_unregistered_meta (dest,
+ smeta->uuid, smeta->data, smeta->size);
+ return TRUE;
+ } else {
+ /* return FALSE, if transform type is not supported */
+ return FALSE;
+ }
+}
+
+static void
+gst_video_sei_user_data_unregistered_meta_free (GstMeta * meta, GstBuffer * buf)
+{
+ GstVideoSEIUserDataUnregisteredMeta *smeta =
+ (GstVideoSEIUserDataUnregisteredMeta *) meta;
+
+ g_free (smeta->data);
+ smeta->data = NULL;
+}
+
+const GstMetaInfo *
+gst_video_sei_user_data_unregistered_meta_get_info (void)
+{
+ static const GstMetaInfo *meta_info = NULL;
+
+ if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
+ const GstMetaInfo *mi =
+ gst_meta_register (GST_VIDEO_SEI_USER_DATA_UNREGISTERED_META_API_TYPE,
+ "GstVideoSEIUserDataUnregisteredMeta",
+ sizeof (GstVideoSEIUserDataUnregisteredMeta),
+ gst_video_sei_user_data_unregistered_meta_init,
+ gst_video_sei_user_data_unregistered_meta_free,
+ gst_video_sei_user_data_unregistered_meta_transform);
+ g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) mi);
+ }
+ return meta_info;
+}
+
+/**
+ * gst_buffer_add_video_sei_user_data_unregistered_meta:
+ * @buffer: a #GstBuffer
+ * @uuid: User Data Unregistered UUID
+ * @data: (transfer none): SEI User Data Unregistered buffer
+ * @size: size of the data buffer
+ *
+ * Attaches #GstVideoSEIUserDataUnregisteredMeta metadata to @buffer with the given
+ * parameters.
+ *
+ * Returns: (transfer none): the #GstVideoSEIUserDataUnregisteredMeta on @buffer.
+ *
+ * Since: 1.22
+ */
+GstVideoSEIUserDataUnregisteredMeta *
+gst_buffer_add_video_sei_user_data_unregistered_meta (GstBuffer * buffer,
+ guint8 uuid[16], guint8 * data, gsize size)
+{
+ GstVideoSEIUserDataUnregisteredMeta *meta;
+ g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
+ g_return_val_if_fail (data != NULL, NULL);
+
+ meta = (GstVideoSEIUserDataUnregisteredMeta *) gst_buffer_add_meta (buffer,
+ GST_VIDEO_SEI_USER_DATA_UNREGISTERED_META_INFO, NULL);
+ g_assert (meta != NULL);
+
+ memcpy (meta->data, data, size);
+ meta->size = size;
+
+ return meta;
+}
+
+gboolean
+ gst_video_sei_user_data_unregistered_parse_precision_time_stamp
+ (GstVideoSEIUserDataUnregisteredMeta * user_data, guint8 * status,
+ guint64 * precision_time_stamp) {
+ guint8 *data = user_data->data;
+
+ if (memcmp (user_data->uuid, &H264_MISP_MICROSECTIME, 16) != 0 &&
+ memcmp (user_data->uuid, &H265_MISP_MICROSECONDS, 16) != 0 &&
+ memcmp (user_data->uuid, &H265_MISP_NANOSECONDS, 16) != 0) {
+ GST_WARNING
+ ("User Data Unregistered UUID is not a known MISP Timestamp UUID");
+ return FALSE;
+ }
+
+ if (user_data->size < 12) {
+ GST_WARNING ("MISP Precision Time Stamp data size is too short, ignoring");
+ return FALSE;
+ }
+
+ /* Status */
+ *status = data[0];
+
+ *precision_time_stamp =
+ /* Two MS bytes of Time Stamp (microseconds) */
+ _GST_GET (data, 1, 64, 56) | _GST_GET (data, 2, 64, 48) |
+ /* Start Code Emulation Prevention Byte (0xFF) */
+ /* Two next MS bytes of Time Stamp (microseconds) */
+ _GST_GET (data, 4, 64, 40) | _GST_GET (data, 5, 64, 32) |
+ /* Start Code Emulation Prevention Byte (0xFF) */
+ /* Two LS bytes of Time Stamp (microseconds) */
+ _GST_GET (data, 7, 64, 24) | _GST_GET (data, 8, 64, 16) |
+ /* Start Code Emulation Prevention Byte (0xFF) */
+ /* Two next LS bytes of Time Stamp (microseconds) */
+ _GST_GET (data, 10, 64, 8) | _GST_GET (data, 11, 64, 0);
+
+ return TRUE;
+}
--- /dev/null
+/* GStreamer
+ * Copyright (C) <2021> Fluendo S.A. <contact@fluendo.com>
+ * Authors: Andoni Morales Alastruey <amorales@fluendo.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.
+ */
+
+#ifndef __GST_VIDEO_SEI_USER_DATA_UNREGISTERED_H__
+#define __GST_VIDEO_SEI_USER_DATA_UNREGISTERED_H__
+
+#include <gst/gst.h>
+#include <gst/video/video.h>
+
+G_BEGIN_DECLS
+
+/**
+ * GstVideoSEIUserDataUnregisteredMeta:
+ * @meta: parent #GstMeta
+ * @description: H.264 H.265 metadata from SEI User Data Unregistered messages
+ * @uuid: User Data Unregistered UUID
+ * @data: Unparsed data buffer
+ * @size: Size of the data buffer
+ *
+ * Since: 1.22
+ */
+typedef struct {
+ GstMeta meta;
+
+ guint8 uuid[16];
+ guint8 *data;
+ gsize size;
+} GstVideoSEIUserDataUnregisteredMeta;
+
+GST_VIDEO_API
+GType gst_video_sei_user_data_unregistered_meta_api_get_type (void);
+/**
+ * GST_VIDEO_SEI_USER_DATA_UNREGISTERED_META_API_TYPE:
+ *
+ * Since: 1.22
+ */
+#define GST_VIDEO_SEI_USER_DATA_UNREGISTERED_META_API_TYPE (\
+ gst_video_sei_user_data_unregistered_meta_api_get_type())
+
+GST_VIDEO_API
+const GstMetaInfo *gst_video_sei_user_data_unregistered_meta_get_info (void);
+/**
+ * GST_VIDEO_SEI_USER_DATA_UNREGISTERED_META_INFO:
+ *
+ * Since: 1.22
+ */
+#define GST_VIDEO_SEI_USER_DATA_UNREGISTERED_META_INFO (\
+ gst_video_sei_user_data_unregistered_meta_get_info())
+
+/**
+ * gst_buffer_get_video_sei_user_data_unregistered_meta:
+ * @b: A #GstBuffer
+ *
+ * Gets the #GstVideoSEIUserDataUnregisteredMeta that might be present on @b.
+ *
+ * Since: 1.22
+ *
+ * Returns: The first #GstVideoSEIUserDataUnregisteredMeta present on @b, or %NULL if
+ * no #GstVideoSEIUserDataUnregisteredMeta are present
+ */
+#define gst_buffer_get_video_sei_user_data_unregistered_meta(b) \
+ ((GstVideoSEIUserDataUnregisteredMeta*)gst_buffer_get_meta((b),GST_VIDEO_SEI_USER_DATA_UNREGISTERED_META_API_TYPE))
+
+GST_VIDEO_API
+GstVideoSEIUserDataUnregisteredMeta *gst_buffer_add_video_sei_user_data_unregistered_meta (GstBuffer * buffer,
+ guint8 uuid[16],
+ guint8 * data,
+ gsize size);
+
+GST_VIDEO_API
+gboolean gst_video_sei_user_data_unregistered_parse_precision_time_stamp (GstVideoSEIUserDataUnregisteredMeta * user_data,
+ guint8 * status,
+ guint64 * precision_time_stamp);
+
+G_END_DECLS
+
+#endif /* __GST_VIDEO_SEI_USER_DATA_UNREGISTERED_H__ */