From 63f8b970af2de5a44c34e60b2f0984b54f06a833 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Sun, 3 Jun 2012 10:56:28 +0200 Subject: [PATCH] mpegtsbase/packetizer: Add CAT section handling Allows reporting the global EMM --- gst/mpegtsdemux/mpegtsbase.c | 19 +++++++++++ gst/mpegtsdemux/mpegtspacketizer.c | 54 ++++++++++++++++++++++++++++++ gst/mpegtsdemux/mpegtspacketizer.h | 2 ++ 3 files changed, 75 insertions(+) diff --git a/gst/mpegtsdemux/mpegtsbase.c b/gst/mpegtsdemux/mpegtsbase.c index 188276feb6..f3144df876 100644 --- a/gst/mpegtsdemux/mpegtsbase.c +++ b/gst/mpegtsdemux/mpegtsbase.c @@ -1011,6 +1011,16 @@ same_program: } } +static void +mpegts_base_apply_cat (MpegTSBase * base, GstStructure * cat_info) +{ + GST_DEBUG_OBJECT (base, "CAT %" GST_PTR_FORMAT, cat_info); + + gst_element_post_message (GST_ELEMENT_CAST (base), + gst_message_new_element (GST_OBJECT (base), + gst_structure_copy (cat_info))); +} + static void mpegts_base_apply_nit (MpegTSBase * base, guint16 pmt_pid, GstStructure * nit_info) @@ -1099,7 +1109,16 @@ mpegts_base_handle_psi (MpegTSBase * base, MpegTSPacketizerSection * section) res = FALSE; break; + case 0x01: + /* CAT */ + structure = mpegts_packetizer_parse_cat (base->packetizer, section); + if (structure) + mpegts_base_apply_cat (base, structure); + else + res = FALSE; + break; case 0x02: + /* PMT */ structure = mpegts_packetizer_parse_pmt (base->packetizer, section); if (G_LIKELY (structure)) mpegts_base_apply_pmt (base, section->pid, structure); diff --git a/gst/mpegtsdemux/mpegtspacketizer.c b/gst/mpegtsdemux/mpegtspacketizer.c index c1b0144a03..6e49f670a3 100644 --- a/gst/mpegtsdemux/mpegtspacketizer.c +++ b/gst/mpegtsdemux/mpegtspacketizer.c @@ -48,6 +48,8 @@ static GQuark QUARK_PROGRAM_NUMBER; static GQuark QUARK_PID; static GQuark QUARK_PROGRAMS; +static GQuark QUARK_CAT; + static GQuark QUARK_PMT; static GQuark QUARK_PCR_PID; static GQuark QUARK_VERSION_NUMBER; @@ -522,6 +524,56 @@ error: return FALSE; } +GstStructure * +mpegts_packetizer_parse_cat (MpegTSPacketizer2 * packetizer, + MpegTSPacketizerSection * section) +{ + GstStructure *cat_info = NULL; + guint8 *data; + guint8 tmp; + GValueArray *descriptors; + GstMPEGDescriptor *desc; + guint desc_len; + + /* Skip parts already parsed */ + data = section->data + 3; + + /* reserved : 18bits */ + data += 2; + + /* version_number : 5 bits + * current_next_indicator : 1 bit */ + tmp = *data++; + section->version_number = (tmp >> 1) & 0x1F; + section->current_next_indicator = tmp & 0x01; + + /* skip already handled section_number and last_section_number */ + data += 2; + + cat_info = gst_structure_new_id_empty (QUARK_CAT); + + /* descriptors */ + desc_len = section->section_length - 4 - 8; + desc = gst_mpeg_descriptor_parse (data, desc_len); + if (desc) + gst_mpeg_descriptor_free (desc); + descriptors = g_value_array_new (0); + if (!mpegts_packetizer_parse_descriptors (packetizer, &data, data + desc_len, + descriptors)) { + g_value_array_free (descriptors); + goto error; + } + gst_structure_id_set (cat_info, QUARK_DESCRIPTORS, G_TYPE_VALUE_ARRAY, + descriptors, NULL); + g_value_array_free (descriptors); + + return cat_info; +error: + if (cat_info) + gst_structure_free (cat_info); + return NULL; +} + GstStructure * mpegts_packetizer_parse_pat (MpegTSPacketizer2 * packetizer, MpegTSPacketizerSection * section) @@ -2579,6 +2631,8 @@ _init_local (void) QUARK_PID = g_quark_from_string ("pid"); QUARK_PROGRAMS = g_quark_from_string ("programs"); + QUARK_CAT = g_quark_from_string ("pat"); + QUARK_PMT = g_quark_from_string ("pmt"); QUARK_PCR_PID = g_quark_from_string ("pcr-pid"); QUARK_VERSION_NUMBER = g_quark_from_string ("version-number"); diff --git a/gst/mpegtsdemux/mpegtspacketizer.h b/gst/mpegtsdemux/mpegtspacketizer.h index 2e6d2c419f..b3600591a9 100644 --- a/gst/mpegtsdemux/mpegtspacketizer.h +++ b/gst/mpegtsdemux/mpegtspacketizer.h @@ -192,6 +192,8 @@ void mpegts_packetizer_remove_stream(MpegTSPacketizer2 *packetizer, gboolean mpegts_packetizer_push_section (MpegTSPacketizer2 *packetzer, MpegTSPacketizerPacket *packet, MpegTSPacketizerSection *section); +GstStructure *mpegts_packetizer_parse_cat (MpegTSPacketizer2 *packetizer, + MpegTSPacketizerSection *section); GstStructure *mpegts_packetizer_parse_pat (MpegTSPacketizer2 *packetizer, MpegTSPacketizerSection *section); GstStructure *mpegts_packetizer_parse_pmt (MpegTSPacketizer2 *packetizer, -- 2.34.1