From b7d256b4c292d0a83f8c7eb2a02de9700082700b Mon Sep 17 00:00:00 2001 From: Jesper Larsen Date: Tue, 19 Nov 2013 11:30:33 +0100 Subject: [PATCH] mpegts: Support registration and custom descriptor Support for registration descriptor (0x05) Add function to create a descriptor with custom tag and data --- gst-libs/gst/mpegts/gstmpegtsdescriptor.c | 52 +++++++++++++++++++++++ gst-libs/gst/mpegts/gstmpegtsdescriptor.h | 9 ++++ 2 files changed, 61 insertions(+) diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c index 35a8f89fdb..be2773548d 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c @@ -830,6 +830,34 @@ gst_mpegts_find_descriptor (GPtrArray * descriptors, guint8 tag) return NULL; } +/* GST_MTS_DESC_REGISTRATION (0x05) */ +/** + * gst_mpegts_descriptor_from_registration: + * @format_identifier: (transfer none): a 4 character format identifier string + * @additional_info: (transfer none) (allow-none): pointer to optional additional info + * @additional_info_length: length of the optional @additional_info + * + * Creates a %GST_MTS_DESC_REGISTRATION #GstMpegTsDescriptor + * + * Return: #GstMpegTsDescriptor, %NULL on failure + */ +GstMpegTsDescriptor * +gst_mpegts_descriptor_from_registration (const gchar * format_identifier, + guint8 * additional_info, gsize additional_info_length) +{ + GstMpegTsDescriptor *descriptor; + + g_return_val_if_fail (format_identifier != NULL, NULL); + + descriptor = _new_descriptor (GST_MTS_DESC_REGISTRATION, + 4 + additional_info_length); + + memcpy (descriptor->data + 2, format_identifier, 4); + if (additional_info && (additional_info_length > 0)) + memcpy (descriptor->data + 6, additional_info, additional_info_length); + + return descriptor; +} /* GST_MTS_DESC_ISO_639_LANGUAGE (0x0A) */ /** @@ -957,3 +985,27 @@ gst_mpegts_descriptor_parse_logical_channel (const GstMpegTsDescriptor * return TRUE; } + +/** + * gst_mpegts_descriptor_from_custom: + * @tag: descriptor tag + * @data: (transfer none): descriptor data (after tag and length field) + * @length: length of @data + * + * Creates a #GstMpegTsDescriptor with custom @tag and @data + * + * Returns: #GstMpegTsDescriptor + */ +GstMpegTsDescriptor * +gst_mpegts_descriptor_from_custom (guint8 tag, const guint8 * data, + gsize length) +{ + GstMpegTsDescriptor *descriptor; + + descriptor = _new_descriptor (tag, length); + + if (data && (length > 0)) + memcpy (descriptor->data + 2, data, length); + + return descriptor; +} diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h index 0afff7c1de..7c367885ba 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h @@ -262,6 +262,12 @@ GPtrArray *gst_mpegts_parse_descriptors (guint8 * buffer, gsize buf_len); const GstMpegTsDescriptor * gst_mpegts_find_descriptor (GPtrArray *descriptors, guint8 tag); +/* GST_MTS_DESC_REGISTRATION (0x05) */ + +GstMpegTsDescriptor *gst_mpegts_descriptor_from_registration ( + const gchar *format_identifier, + guint8 *additional_info, gsize additional_info_length); + /* GST_MTS_DESC_ISO_639_LANGUAGE (0x0A) */ /** * GstMpegTsISO639AudioType: @@ -317,6 +323,9 @@ gboolean gst_mpegts_descriptor_parse_logical_channel (const GstMpegTsDescriptor *descriptor, GstMpegTsLogicalChannelDescriptor *res); +GstMpegTsDescriptor * +gst_mpegts_descriptor_from_custom (guint8 tag, const guint8 *data, gsize length); + G_END_DECLS #endif /* GST_MPEGTS_DESCRIPTOR_H */