From ce61a754d8ac4eaf62a25b549a6617c689cbe35a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 25 Oct 2015 18:09:24 +0200 Subject: [PATCH] mpegtsdescriptor: Add API for creating extended descriptors and fix writing them https://bugzilla.gnome.org/show_bug.cgi?id=757049 --- gst-libs/gst/mpegts/gstmpegtsdescriptor.c | 41 ++++++++++++++++++++++--------- gst-libs/gst/mpegts/gstmpegtsdescriptor.h | 2 ++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c index da8419c..d4817d2 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c @@ -635,7 +635,6 @@ void _packetize_descriptor_array (GPtrArray * array, guint8 ** out_data) { guint i; - guint8 header_size; GstMpegtsDescriptor *descriptor; g_return_if_fail (out_data != NULL); @@ -647,13 +646,8 @@ _packetize_descriptor_array (GPtrArray * array, guint8 ** out_data) for (i = 0; i < array->len; i++) { descriptor = g_ptr_array_index (array, i); - if (descriptor->tag == GST_MTS_DESC_DVB_EXTENSION) - header_size = 3; - else - header_size = 2; - - memcpy (*out_data, descriptor->data, descriptor->length + header_size); - *out_data += descriptor->length + header_size; + memcpy (*out_data, descriptor->data, descriptor->length + 2); + *out_data += descriptor->length + 2; } } @@ -689,15 +683,15 @@ _new_descriptor_with_extension (guint8 tag, guint8 tag_extension, guint8 length) descriptor->tag = tag; descriptor->tag_extension = tag_extension; - descriptor->length = length; + descriptor->length = length + 1; descriptor->data = g_malloc (length + 3); data = descriptor->data; *data++ = descriptor->tag; - *data++ = descriptor->tag_extension; - *data = descriptor->length; + *data++ = descriptor->length; + *data = descriptor->tag_extension; return descriptor; } @@ -1105,3 +1099,28 @@ gst_mpegts_descriptor_from_custom (guint8 tag, const guint8 * data, return descriptor; } + +/** + * gst_mpegts_descriptor_from_custom_with_extension: + * @tag: descriptor tag + * @tag_extension: descriptor tag extension + * @data: (transfer none): descriptor data (after tag and length field) + * @length: length of @data + * + * Creates a #GstMpegtsDescriptor with custom @tag, @tag_extension and @data + * + * Returns: #GstMpegtsDescriptor + */ +GstMpegtsDescriptor * +gst_mpegts_descriptor_from_custom_with_extension (guint8 tag, + guint8 tag_extension, const guint8 * data, gsize length) +{ + GstMpegtsDescriptor *descriptor; + + descriptor = _new_descriptor_with_extension (tag, tag_extension, length); + + if (data && (length > 0)) + memcpy (descriptor->data + 3, data, length); + + return descriptor; +} diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h index bbef97d..af56be0 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h @@ -341,6 +341,8 @@ gst_mpegts_descriptor_parse_logical_channel (const GstMpegtsDescriptor *descript GstMpegtsDescriptor * gst_mpegts_descriptor_from_custom (guint8 tag, const guint8 *data, gsize length); +GstMpegtsDescriptor * +gst_mpegts_descriptor_from_custom_with_extension (guint8 tag, guint8 tag_extension, const guint8 *data, gsize length); G_END_DECLS -- 2.7.4