From d07ffae3433e955156f7572781c92b0067b8417b Mon Sep 17 00:00:00 2001 From: Fabian Orccon Date: Wed, 19 Jul 2023 09:51:00 +0200 Subject: [PATCH] h264parser: Write Unregistered User Data Part-of: --- .../gst-libs/gst/codecparsers/gsth264parser.c | 28 ++++++++++++++++ .../tests/check/libs/h264parser.c | 32 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/gsth264parser.c b/subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/gsth264parser.c index 287124dc81..f32f0c5602 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/gsth264parser.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/gsth264parser.c @@ -2845,6 +2845,19 @@ error: return FALSE; } +static gboolean +gst_h264_write_sei_user_data_unregistered (NalWriter * nw, + GstH264UserDataUnregistered * udu) +{ + WRITE_BYTES (nw, udu->uuid, 16); + WRITE_BYTES (nw, udu->data, udu->size); + + return TRUE; + +error: + return FALSE; +} + static gboolean gst_h264_write_sei_frame_packing (NalWriter * nw, GstH264FramePacking * frame_packing) @@ -3029,6 +3042,12 @@ gst_h264_create_sei_memory_internal (guint8 nal_prefix_size, payload_size_data += rud->size; break; } + case GST_H264_SEI_USER_DATA_UNREGISTERED:{ + GstH264UserDataUnregistered *udu = &msg->payload.user_data_unregistered; + + payload_size_data = 16 + udu->size; + break; + } case GST_H264_SEI_FRAME_PACKING:{ GstH264FramePacking *frame_packing = &msg->payload.frame_packing; guint leading_zeros, rest; @@ -3216,6 +3235,15 @@ gst_h264_create_sei_memory_internal (guint8 nal_prefix_size, } have_written_data = TRUE; break; + case GST_H264_SEI_USER_DATA_UNREGISTERED: + GST_DEBUG ("Writing \"Unregistered user data\""); + if (!gst_h264_write_sei_user_data_unregistered (&nw, + &msg->payload.user_data_unregistered)) { + GST_WARNING ("Failed to write \"Unregistered user data\""); + goto error; + } + have_written_data = TRUE; + break; case GST_H264_SEI_FRAME_PACKING: GST_DEBUG ("Writing \"Frame packing\""); if (!gst_h264_write_sei_frame_packing (&nw, diff --git a/subprojects/gst-plugins-bad/tests/check/libs/h264parser.c b/subprojects/gst-plugins-bad/tests/check/libs/h264parser.c index 0d92e81eea..33676ebfe9 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/h264parser.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/h264parser.c @@ -332,6 +332,16 @@ static guint8 h264_sei_user_data_registered[] = { 0x00, 0xff, 0x80 }; +static guint8 h264_sei_user_data_unregistered[] = { + 0x00, 0x00, 0x00, 0x01, 0x06, + 0x05, // Payload type. + 0x18, // Payload size. + 0x4D, 0x49, 0x53, 0x50, 0x6D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x65, 0x63, + 0x74, 0x69, 0x6D, 0x65, // UUID. + 0x70, 0x69, 0x67, 0x73, 0x20, 0x66, 0x6c, 0x79, // Payload data + 0x80 +}; + /* frame packing, side-by-side */ static guint8 h264_sei_frame_packing[] = { 0x00, 0x00, 0x00, 0x01, 0x06, 0x2d, 0x07, 0x81, 0x81, 0x00, 0x00, 0x03, @@ -425,6 +435,15 @@ check_sei_user_data_registered (const GstH264RegisteredUserData * a, return !memcmp (a->data, b->data, a->size); } +static gboolean +check_sei_user_data_unregistered (const GstH264UserDataUnregistered * a, + const GstH264UserDataUnregistered * b) +{ + return a->size == b->size && + !memcmp (a->uuid, b->uuid, sizeof (a->uuid)) && + !memcmp (a->data, b->data, a->size); +} + static gboolean check_sei_frame_packing (const GstH264FramePacking * a, const GstH264FramePacking * b) @@ -594,6 +613,9 @@ GST_START_TEST (test_h264_create_sei) {h264_sei_user_data_registered, G_N_ELEMENTS (h264_sei_user_data_registered), GST_H264_SEI_REGISTERED_USER_DATA, {0,}, (SEICheckFunc) check_sei_user_data_registered}, + {h264_sei_user_data_unregistered, G_N_ELEMENTS (h264_sei_user_data_unregistered), + GST_H264_SEI_USER_DATA_UNREGISTERED, {0,}, + (SEICheckFunc) check_sei_user_data_unregistered}, {h264_sei_frame_packing, G_N_ELEMENTS (h264_sei_frame_packing), GST_H264_SEI_FRAME_PACKING, {0,}, (SEICheckFunc) check_sei_frame_packing}, @@ -671,6 +693,16 @@ GST_START_TEST (test_h264_create_sei) dst_rud->data = g_malloc (src_rud->size); memcpy ((guint8 *) dst_rud->data, src_rud->data, src_rud->size); + } else if (test_list[i].type == GST_H264_SEI_USER_DATA_UNREGISTERED) { + GstH264UserDataUnregistered *dst_udu = + &test_list[i].parsed_message.payload.user_data_unregistered; + const GstH264SEIMessage *src_msg = + &g_array_index (msg_array, GstH264SEIMessage, 0); + const GstH264UserDataUnregistered *src_udu = + &src_msg->payload.user_data_unregistered; + + dst_udu->data = g_malloc (src_udu->size); + memcpy ((guint8 *) dst_udu->data, src_udu->data, src_udu->size); } g_array_unref (msg_array); }