diff --git a/gst-libs/gst/mpegts/gstmpegts-private.h b/gst-libs/gst/mpegts/gstmpegts-private.h index 4d067fa580..7607b813ee 100644 --- a/gst-libs/gst/mpegts/gstmpegts-private.h +++ b/gst-libs/gst/mpegts/gstmpegts-private.h @@ -33,6 +33,11 @@ G_GNUC_INTERNAL void __initialize_descriptors (void); G_GNUC_INTERNAL guint32 _calc_crc32 (const guint8 *data, guint datalen); G_GNUC_INTERNAL gchar *get_encoding_and_convert (const gchar *text, guint length); G_GNUC_INTERNAL guint8 *dvb_text_from_utf8 (const gchar * text, gsize *out_size); +G_GNUC_INTERNAL void _free_descriptor (GstMpegTsDescriptor *descriptor); +G_GNUC_INTERNAL GstMpegTsDescriptor *_new_descriptor (guint8 tag, guint8 length); +G_GNUC_INTERNAL GstMpegTsDescriptor *_new_descriptor_with_extension (guint8 tag, + guint8 tag_extension, guint8 length); +G_GNUC_INTERNAL GstMpegTsSection *_gst_mpegts_section_init (guint16 pid, guint8 table_id); typedef gpointer (*GstMpegTsParseFunc) (GstMpegTsSection *section); G_GNUC_INTERNAL gpointer __common_desc_checks (GstMpegTsSection *section, diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c index d82f35f7de..a49adfdc87 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c @@ -627,6 +627,51 @@ failed: } } +GstMpegTsDescriptor * +_new_descriptor (guint8 tag, guint8 length) +{ + GstMpegTsDescriptor *descriptor; + guint8 *data; + + descriptor = g_slice_new (GstMpegTsDescriptor); + + descriptor->tag = tag; + descriptor->tag_extension = 0; + descriptor->length = length; + + descriptor->data = g_malloc (length + 2); + + data = descriptor->data; + + *data++ = descriptor->tag; + *data = descriptor->length; + + return descriptor; +} + +GstMpegTsDescriptor * +_new_descriptor_with_extension (guint8 tag, guint8 tag_extension, guint8 length) +{ + GstMpegTsDescriptor *descriptor; + guint8 *data; + + descriptor = g_slice_new (GstMpegTsDescriptor); + + descriptor->tag = tag; + descriptor->tag_extension = tag_extension; + descriptor->length = length; + + descriptor->data = g_malloc (length + 3); + + data = descriptor->data; + + *data++ = descriptor->tag; + *data++ = descriptor->tag_extension; + *data = descriptor->length; + + return descriptor; +} + static GstMpegTsDescriptor * _copy_descriptor (GstMpegTsDescriptor * desc) { @@ -638,7 +683,7 @@ _copy_descriptor (GstMpegTsDescriptor * desc) return copy; } -static void +void _free_descriptor (GstMpegTsDescriptor * desc) { g_free ((gpointer) desc->data); diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h index f8efbd1fed..0afff7c1de 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h @@ -254,7 +254,7 @@ struct _GstMpegTsDescriptor guint8 tag; guint8 tag_extension; guint8 length; - const guint8 *data; + guint8 *data; }; GPtrArray *gst_mpegts_parse_descriptors (guint8 * buffer, gsize buf_len); diff --git a/gst-libs/gst/mpegts/gstmpegtssection.c b/gst-libs/gst/mpegts/gstmpegtssection.c index 6b6b3ece63..6a2bed5062 100644 --- a/gst-libs/gst/mpegts/gstmpegtssection.c +++ b/gst-libs/gst/mpegts/gstmpegtssection.c @@ -715,6 +715,24 @@ _identify_section (guint16 pid, guint8 table_id) } +GstMpegTsSection * +_gst_mpegts_section_init (guint16 pid, guint8 table_id) +{ + GstMpegTsSection *section; + + section = g_slice_new0 (GstMpegTsSection); + gst_mini_object_init (GST_MINI_OBJECT_CAST (section), 0, MPEG_TYPE_TS_SECTION, + (GstMiniObjectCopyFunction) _gst_mpegts_section_copy, NULL, + (GstMiniObjectFreeFunction) _gst_mpegts_section_free); + + section->pid = pid; + section->table_id = table_id; + section->current_next_indicator = TRUE; + section->section_type = _identify_section (pid, table_id); + + return section; +} + /** * gst_mpegts_section_new: * @pid: the PID to which this section belongs @@ -739,6 +757,7 @@ gst_mpegts_section_new (guint16 pid, guint8 * data, gsize data_size) { GstMpegTsSection *res = NULL; guint8 tmp; + guint8 table_id; guint16 section_length; /* Check for length */ @@ -746,15 +765,14 @@ gst_mpegts_section_new (guint16 pid, guint8 * data, gsize data_size) if (G_UNLIKELY (data_size < section_length + 3)) goto short_packet; - res = g_slice_new0 (GstMpegTsSection); - gst_mini_object_init (GST_MINI_OBJECT_CAST (res), 0, MPEG_TYPE_TS_SECTION, - (GstMiniObjectCopyFunction) _gst_mpegts_section_copy, NULL, - (GstMiniObjectFreeFunction) _gst_mpegts_section_free); + /* Table id is in first byte */ + table_id = *data; + + res = _gst_mpegts_section_init (pid, table_id); - res->pid = pid; res->data = data; - /* table_id : 8 bit */ - res->table_id = *data++; + /* table_id (already parsed) : 8 bit */ + data++; /* section_syntax_indicator : 1 bit * other_fields (reserved) : 3 bit*/ res->short_section = (*data & 0x80) == 0x00; @@ -780,8 +798,6 @@ gst_mpegts_section_new (guint16 pid, guint8 * data, gsize data_size) res->last_section_number = *data; } - res->section_type = _identify_section (res->pid, res->table_id); - return res; short_packet: