From 8f6a3c0a9910620bfdef7c826b881f4ba6fa194d Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Fri, 23 May 2014 01:41:18 -0300 Subject: [PATCH] mpegts: atsc: rename TVCT to VCT as it is the same as CVCT Make the ATSC section parse handle both TVCT and CVCT as they are nearly the same struct (CVCT uses 2 reserved bits that are ignored in TVCT). This is changing the glib type and the struct name but TVCT wasn't released in a stable package yet so there should be no problem. Also includes some parsing fixes and changes short_name to be directly stored as utf8 rather than utf16 https://bugzilla.gnome.org/show_bug.cgi?id=730642 --- gst-libs/gst/mpegts/gst-atsc-section.c | 138 ++++++++++++++++--------- gst-libs/gst/mpegts/gst-atsc-section.h | 35 ++++--- gst-libs/gst/mpegts/gstmpegtssection.c | 8 ++ gst-libs/gst/mpegts/gstmpegtssection.h | 4 +- 4 files changed, 118 insertions(+), 67 deletions(-) diff --git a/gst-libs/gst/mpegts/gst-atsc-section.c b/gst-libs/gst/mpegts/gst-atsc-section.c index a56be15d8e..553c65fe32 100644 --- a/gst-libs/gst/mpegts/gst-atsc-section.c +++ b/gst-libs/gst/mpegts/gst-atsc-section.c @@ -34,101 +34,108 @@ * */ -/* Terrestrial Virtual Channel Table TVCT */ -static GstMpegTsAtscTVCTSource * -_gst_mpegts_atsc_tvct_source_copy (GstMpegTsAtscTVCTSource * source) +/* Terrestrial/Cable Virtual Channel Table TVCT/CVCT */ +static GstMpegTsAtscVCTSource * +_gst_mpegts_atsc_vct_source_copy (GstMpegTsAtscVCTSource * source) { - GstMpegTsAtscTVCTSource *copy; + GstMpegTsAtscVCTSource *copy; - copy = g_slice_dup (GstMpegTsAtscTVCTSource, source); + copy = g_slice_dup (GstMpegTsAtscVCTSource, source); copy->descriptors = g_ptr_array_ref (source->descriptors); return copy; } static void -_gst_mpegts_atsc_tvct_source_free (GstMpegTsAtscTVCTSource * source) +_gst_mpegts_atsc_vct_source_free (GstMpegTsAtscVCTSource * source) { if (source->descriptors) g_ptr_array_unref (source->descriptors); - g_slice_free (GstMpegTsAtscTVCTSource, source); + g_slice_free (GstMpegTsAtscVCTSource, source); } -G_DEFINE_BOXED_TYPE (GstMpegTsAtscTVCTSource, gst_mpegts_atsc_tvct_source, - (GBoxedCopyFunc) _gst_mpegts_atsc_tvct_source_copy, - (GFreeFunc) _gst_mpegts_atsc_tvct_source_free); +G_DEFINE_BOXED_TYPE (GstMpegTsAtscVCTSource, gst_mpegts_atsc_vct_source, + (GBoxedCopyFunc) _gst_mpegts_atsc_vct_source_copy, + (GFreeFunc) _gst_mpegts_atsc_vct_source_free); -static GstMpegTsAtscTVCT * -_gst_mpegts_atsc_tvct_copy (GstMpegTsAtscTVCT * tvct) +static GstMpegTsAtscVCT * +_gst_mpegts_atsc_vct_copy (GstMpegTsAtscVCT * vct) { - GstMpegTsAtscTVCT *copy; + GstMpegTsAtscVCT *copy; - copy = g_slice_dup (GstMpegTsAtscTVCT, tvct); - copy->sources = g_ptr_array_ref (tvct->sources); - copy->descriptors = g_ptr_array_ref (tvct->descriptors); + copy = g_slice_dup (GstMpegTsAtscVCT, vct); + copy->sources = g_ptr_array_ref (vct->sources); + copy->descriptors = g_ptr_array_ref (vct->descriptors); return copy; } static void -_gst_mpegts_atsc_tvct_free (GstMpegTsAtscTVCT * tvct) +_gst_mpegts_atsc_vct_free (GstMpegTsAtscVCT * vct) { - g_ptr_array_unref (tvct->sources); - if (tvct->descriptors) - g_ptr_array_unref (tvct->descriptors); - g_slice_free (GstMpegTsAtscTVCT, tvct); + if (vct->sources) + g_ptr_array_unref (vct->sources); + if (vct->descriptors) + g_ptr_array_unref (vct->descriptors); + g_slice_free (GstMpegTsAtscVCT, vct); } -G_DEFINE_BOXED_TYPE (GstMpegTsAtscTVCT, gst_mpegts_atsc_tvct, - (GBoxedCopyFunc) _gst_mpegts_atsc_tvct_copy, - (GFreeFunc) _gst_mpegts_atsc_tvct_free); +G_DEFINE_BOXED_TYPE (GstMpegTsAtscVCT, gst_mpegts_atsc_vct, + (GBoxedCopyFunc) _gst_mpegts_atsc_vct_copy, + (GFreeFunc) _gst_mpegts_atsc_vct_free); static gpointer -_parse_atsc_tvct (GstMpegTsSection * section) +_parse_atsc_vct (GstMpegTsSection * section) { - GstMpegTsAtscTVCT *tvct = NULL; + GstMpegTsAtscVCT *vct = NULL; guint8 *data, *end, source_nb; guint32 tmp32; guint16 descriptors_loop_length, tmp16; guint i; + GError *err = NULL; - tvct = g_slice_new0 (GstMpegTsAtscTVCT); + vct = g_slice_new0 (GstMpegTsAtscVCT); data = section->data; end = data + section->section_length; - tvct->transport_stream_id = section->subtable_extension; + vct->transport_stream_id = section->subtable_extension; /* Skip already parsed data */ data += 8; /* minimum size */ - if (data - end < 2 + 2 + 4) + if (end - data < 2 + 2 + 4) goto error; - tvct->protocol_version = *data; + vct->protocol_version = *data; data += 1; source_nb = *data; data += 1; - tvct->sources = g_ptr_array_new_full (source_nb, - (GDestroyNotify) _gst_mpegts_atsc_tvct_source_free); + vct->sources = g_ptr_array_new_full (source_nb, + (GDestroyNotify) _gst_mpegts_atsc_vct_source_free); for (i = 0; i < source_nb; i++) { - GstMpegTsAtscTVCTSource *source; + GstMpegTsAtscVCTSource *source; /* minimum 32 bytes for a entry, 2 bytes second descriptor loop-length, 4 bytes crc */ if (end - data < 32 + 2 + 4) goto error; - source = g_slice_new0 (GstMpegTsAtscTVCTSource); - g_ptr_array_add (tvct->sources, source); - - /* FIXME: 7 utf16 charater - GST_READ_UINT16_BE x 7 or extern method ? */ - source->short_name = g_memdup (data, 14); + source = g_slice_new0 (GstMpegTsAtscVCTSource); + g_ptr_array_add (vct->sources, source); + + source->short_name = + g_convert ((gchar *) data, 14, "utf-8", "utf-16be", NULL, NULL, &err); + if (err) { + GST_WARNING ("Failed to convert VCT Source short_name to utf-8: %d %s", + err->code, err->message); + GST_MEMDUMP ("UTF-16 string", data, 14); + g_error_free (err); + } data += 14; tmp32 = GST_READ_UINT32_BE (data); @@ -150,7 +157,12 @@ _parse_atsc_tvct (GstMpegTsSection * section) source->ETM_location = (tmp16 >> 14) & 0x3; source->access_controlled = (tmp16 >> 13) & 0x1; source->hidden = (tmp16 >> 12) & 0x1; - source->hide_guide = (tmp16 >> 10) & 0x1; + + /* only used in CVCT */ + source->path_select = (tmp16 >> 11) & 0x1; + source->out_of_band = (tmp16 >> 10) & 0x1; + + source->hide_guide = (tmp16 >> 9) & 0x1; source->service_type = tmp16 & 0x3f; data += 2; @@ -176,17 +188,17 @@ _parse_atsc_tvct (GstMpegTsSection * section) if (end - data < descriptors_loop_length + 4) goto error; - tvct->descriptors = + vct->descriptors = gst_mpegts_parse_descriptors (data, descriptors_loop_length); - if (tvct->descriptors == NULL) + if (vct->descriptors == NULL) goto error; data += descriptors_loop_length; - return (gpointer) tvct; + return (gpointer) vct; error: - if (tvct) - _gst_mpegts_atsc_tvct_free (tvct); + if (vct) + _gst_mpegts_atsc_vct_free (vct); return NULL; } @@ -195,12 +207,12 @@ error: * gst_mpegts_section_get_atsc_tvct: * @section: a #GstMpegTsSection of type %GST_MPEGTS_SECTION_ATSC_TVCT * - * Returns the #GstMpegTsAtscTVCT contained in the @section + * Returns the #GstMpegTsAtscVCT contained in the @section * - * Returns: The #GstMpegTsAtscTVCT contained in the section, or %NULL if an error + * Returns: The #GstMpegTsAtscVCT contained in the section, or %NULL if an error * happened. */ -const GstMpegTsAtscTVCT * +const GstMpegTsAtscVCT * gst_mpegts_section_get_atsc_tvct (GstMpegTsSection * section) { g_return_val_if_fail (section->section_type == GST_MPEGTS_SECTION_ATSC_TVCT, @@ -209,8 +221,32 @@ gst_mpegts_section_get_atsc_tvct (GstMpegTsSection * section) if (!section->cached_parsed) section->cached_parsed = - __common_section_checks (section, 16, _parse_atsc_tvct, - (GDestroyNotify) _gst_mpegts_atsc_tvct_free); + __common_section_checks (section, 16, _parse_atsc_vct, + (GDestroyNotify) _gst_mpegts_atsc_vct_free); + + return (const GstMpegTsAtscVCT *) section->cached_parsed; +} + +/** + * gst_mpegts_section_get_atsc_cvct: + * @section: a #GstMpegTsSection of type %GST_MPEGTS_SECTION_ATSC_CVCT + * + * Returns the #GstMpegTsAtscVCT contained in the @section + * + * Returns: The #GstMpegTsAtscVCT contained in the section, or %NULL if an error + * happened. + */ +const GstMpegTsAtscVCT * +gst_mpegts_section_get_atsc_cvct (GstMpegTsSection * section) +{ + g_return_val_if_fail (section->section_type == GST_MPEGTS_SECTION_ATSC_CVCT, + NULL); + g_return_val_if_fail (section->cached_parsed || section->data, NULL); + + if (!section->cached_parsed) + section->cached_parsed = + __common_section_checks (section, 16, _parse_atsc_vct, + (GDestroyNotify) _gst_mpegts_atsc_vct_free); - return (const GstMpegTsAtscTVCT *) section->cached_parsed; + return (const GstMpegTsAtscVCT *) section->cached_parsed; } diff --git a/gst-libs/gst/mpegts/gst-atsc-section.h b/gst-libs/gst/mpegts/gst-atsc-section.h index dbf5fb120a..b7a5796d7f 100644 --- a/gst-libs/gst/mpegts/gst-atsc-section.h +++ b/gst-libs/gst/mpegts/gst-atsc-section.h @@ -66,21 +66,21 @@ typedef enum { GST_MTS_TABLE_ID_ATSC_SATELLITE_VIRTUAL_CHANNEL = 0xDA, } GstMpegTsSectionATSCTableID; -/* TVCT */ -#define GST_TYPE_MPEGTS_ATSC_TVCT (gst_mpegts_atsc_tvct_get_type ()) -#define GST_TYPE_MPEGTS_ATSC_TVCT_SOURCE (gst_mpegts_atsc_tvct_source_get_type ()) +/* TVCT/CVCT */ +#define GST_TYPE_MPEGTS_ATSC_VCT (gst_mpegts_atsc_vct_get_type ()) +#define GST_TYPE_MPEGTS_ATSC_VCT_SOURCE (gst_mpegts_atsc_vct_source_get_type ()) -typedef struct _GstMpegTsAtscTVCTSource GstMpegTsAtscTVCTSource; -typedef struct _GstMpegTsAtscTVCT GstMpegTsAtscTVCT; +typedef struct _GstMpegTsAtscVCTSource GstMpegTsAtscVCTSource; +typedef struct _GstMpegTsAtscVCT GstMpegTsAtscVCT; /** - * GstMpegTsAtscTVCTSource: + * GstMpegTsAtscVCTSource: * - * Source from a @GstMpegTsAtscTVCT + * Source from a @GstMpegTsAtscVCT, can be used both for TVCT and CVCT tables */ -struct _GstMpegTsAtscTVCTSource +struct _GstMpegTsAtscVCTSource { - gunichar2 *short_name; + gchar *short_name; guint16 major_channel_number; guint16 minor_channel_number; guint8 modulation_mode; @@ -91,6 +91,8 @@ struct _GstMpegTsAtscTVCTSource guint8 ETM_location; gboolean access_controlled; gboolean hidden; + gboolean path_select; /* CVCT only - reserved bit in TVCT */ + gboolean out_of_band; /* CVCT only - reserved bit in TVCT */ gboolean hide_guide; /* FIXME: */ guint8 service_type; @@ -99,12 +101,14 @@ struct _GstMpegTsAtscTVCTSource }; /** - * GstMpegTsAtscTVCT: + * GstMpegTsAtscVCT: * - * Terrestrial Virtual Channel Table (A65) + * Represents both: + * Terrestrial Virtual Channel Table (A65) + * Cable Virtual Channel Table (A65) * */ -struct _GstMpegTsAtscTVCT +struct _GstMpegTsAtscVCT { guint16 transport_stream_id; guint8 protocol_version; @@ -112,10 +116,11 @@ struct _GstMpegTsAtscTVCT GPtrArray *descriptors; }; -GType gst_mpegts_atsc_tvct_get_type (void); -GType gst_mpegts_atsc_tvct_source_get_type (void); +GType gst_mpegts_atsc_vct_get_type (void); +GType gst_mpegts_atsc_vct_source_get_type (void); -const GstMpegTsAtscTVCT * gst_mpegts_section_get_atsc_tvct (GstMpegTsSection * section); +const GstMpegTsAtscVCT * gst_mpegts_section_get_atsc_tvct (GstMpegTsSection * section); +const GstMpegTsAtscVCT * gst_mpegts_section_get_atsc_cvct (GstMpegTsSection * section); G_END_DECLS diff --git a/gst-libs/gst/mpegts/gstmpegtssection.c b/gst-libs/gst/mpegts/gstmpegtssection.c index 97a7e4afb4..70035c7622 100644 --- a/gst-libs/gst/mpegts/gstmpegtssection.c +++ b/gst-libs/gst/mpegts/gstmpegtssection.c @@ -1048,6 +1048,14 @@ _identify_section (guint16 pid, guint8 table_id) if (pid == 0x0014) return GST_MPEGTS_SECTION_TOT; break; + case GST_MTS_TABLE_ID_ATSC_TERRESTRIAL_VIRTUAL_CHANNEL: + if (pid == 0x1ffb) + return GST_MPEGTS_SECTION_ATSC_TVCT; + break; + case GST_MTS_TABLE_ID_ATSC_CABLE_VIRTUAL_CHANNEL: + if (pid == 0x1ffb) + return GST_MPEGTS_SECTION_ATSC_CVCT; + break; /* FIXME : FILL */ default: /* Handle ranges */ diff --git a/gst-libs/gst/mpegts/gstmpegtssection.h b/gst-libs/gst/mpegts/gstmpegtssection.h index eef9de1a00..2fd9df6a27 100644 --- a/gst-libs/gst/mpegts/gstmpegtssection.h +++ b/gst-libs/gst/mpegts/gstmpegtssection.h @@ -52,6 +52,7 @@ GType gst_mpegts_section_get_type (void); * @GST_MPEGTS_SECTION_TDT: Time and Date Table (EN 300 468) * @GST_MPEGTS_SECTION_TOT: Time Offset Table (EN 300 468) * @GST_MPEGTS_SECTION_ATSC_TVCT: ATSC Terrestrial Virtual Channel Table (A65) + * @GST_MPEGTS_SECTION_ATSC_CVCT: ATSC Cable Virtual Channel Table (A65) * * Types of #GstMpegTsSection that the library handles. */ @@ -67,7 +68,8 @@ typedef enum { GST_MPEGTS_SECTION_SDT, GST_MPEGTS_SECTION_TDT, GST_MPEGTS_SECTION_TOT, - GST_MPEGTS_SECTION_ATSC_TVCT + GST_MPEGTS_SECTION_ATSC_TVCT, + GST_MPEGTS_SECTION_ATSC_CVCT } GstMpegTsSectionType; /** -- 2.34.1