From cfb4da7215f96085ce167551382541ecdb99d4f7 Mon Sep 17 00:00:00 2001 From: Jesper Larsen Date: Tue, 19 Nov 2013 10:50:30 +0100 Subject: [PATCH] mpegts: Support parsing of DVB Teletext descriptor Descriptor tag is 0x56 --- gst-libs/gst/mpegts/gst-dvb-descriptor.c | 65 ++++++++++++++++++++++++ gst-libs/gst/mpegts/gst-dvb-descriptor.h | 24 +++++++++ 2 files changed, 89 insertions(+) diff --git a/gst-libs/gst/mpegts/gst-dvb-descriptor.c b/gst-libs/gst/mpegts/gst-dvb-descriptor.c index 8a22c891a8..0db9e62154 100644 --- a/gst-libs/gst/mpegts/gst-dvb-descriptor.c +++ b/gst-libs/gst/mpegts/gst-dvb-descriptor.c @@ -319,6 +319,71 @@ gst_mpegts_descriptor_parse_dvb_short_event (const GstMpegTsDescriptor * return TRUE; } +/* GST_MTS_DESC_DVB_TELETEXT (0x56) */ +/** + * gst_mpegts_descriptor_parse_dvb_teletext_idx: + * @descriptor: a %GST_MTS_DESC_DVB_TELETEXT #GstMpegTsDescriptor + * @idx: The id of the teletext to get + * @language_code: (out) (allow-none): a 4-byte gchar array to hold language + * @teletext_type: (out) (allow-none): #GstMpegTsDVBTeletextType + * @magazine_number: (out) (allow-none): + * @page_number: (out) (allow-none): + * + * Parses teletext number @idx in the @descriptor. The language is in ISO639 format. + * + * Returns: FALSE on out-of-bounds and errors + */ +gboolean +gst_mpegts_descriptor_parse_dvb_teletext_idx (const GstMpegTsDescriptor * + descriptor, guint idx, gchar (*language_code)[4], + GstMpegTsDVBTeletextType * teletext_type, guint8 * magazine_number, + guint8 * page_number) +{ + guint8 *data; + + g_return_val_if_fail (descriptor != NULL && descriptor->data != NULL, FALSE); + g_return_val_if_fail (descriptor->tag == GST_MTS_DESC_DVB_TELETEXT, FALSE); + + if (descriptor->length / 5 <= idx) + return FALSE; + + data = (guint8 *) descriptor->data + 2 + idx * 5; + + if (language_code) { + memcpy (language_code, data, 3); + (*language_code)[3] = 0; + } + + if (teletext_type) + *teletext_type = data[3] >> 3; + + if (magazine_number) + *magazine_number = data[3] & 0x07; + + if (page_number) + *page_number = data[4]; + + return TRUE; +} + +/** + * gst_mpegts_descriptor_parse_dvb_teletext_nb: + * @descriptor: a %GST_MTS_DESC_DVB_TELETEXT #GstMpegTsDescriptor + * + * Find the number of teletext entries in @descriptor + * + * Returns: Number of teletext entries + */ +guint +gst_mpegts_descriptor_parse_dvb_teletext_nb (const GstMpegTsDescriptor * + descriptor) +{ + if (descriptor == NULL && descriptor->data == NULL) + return 0; + + return descriptor->length / 5; +} + /* GST_MTS_DESC_DVB_SUBTITLING (0x59) */ /** diff --git a/gst-libs/gst/mpegts/gst-dvb-descriptor.h b/gst-libs/gst/mpegts/gst-dvb-descriptor.h index 957dd10aea..0e429e09b4 100644 --- a/gst-libs/gst/mpegts/gst-dvb-descriptor.h +++ b/gst-libs/gst/mpegts/gst-dvb-descriptor.h @@ -339,6 +339,30 @@ gboolean gst_mpegts_descriptor_parse_dvb_component (const GstMpegTsDescriptor *d gboolean gst_mpegts_descriptor_parse_dvb_stream_identifier (const GstMpegTsDescriptor *descriptor, guint8 *component_tag); +/* GST_MTS_DESC_DVB_TELETEXT (0x56) */ +/** + * GstMpegTsDVBTeletextType: + * + * The type of teletext page. + * + * As specified in Table 100 of ETSI EN 300 468 v1.13.1 + */ +typedef enum { + INITIAL_PAGE = 0x01, + SUBTITLE_PAGE, + ADDITIONAL_INFO_PAGE, + PROGRAMME_SCHEDULE_PAGE, + HEARING_IMPAIRED_PAGE +} GstMpegTsDVBTeletextType; + +gboolean gst_mpegts_descriptor_parse_dvb_teletext_idx (const GstMpegTsDescriptor * + descriptor, guint idx, gchar (*language_code)[4], + GstMpegTsDVBTeletextType * teletext_type, guint8 * magazine_number, + guint8 * page_number); + +guint gst_mpegts_descriptor_parse_dvb_teletext_nb (const GstMpegTsDescriptor * + descriptor); + /* GST_MTS_DESC_DVB_SUBTITLING (0x59) */ gboolean gst_mpegts_descriptor_parse_dvb_subtitling_idx (const GstMpegTsDescriptor *descriptor, guint idx, gchar (*lang)[4],