From f566d172025f785bcc8b4ad4110399140f2512bd Mon Sep 17 00:00:00 2001 From: Stefan Ringel Date: Wed, 9 Apr 2014 10:04:46 +0200 Subject: [PATCH] mpegts: add atsc terrestrial virtual channel table https://bugzilla.gnome.org/show_bug.cgi?id=727460 --- docs/libs/gst-plugins-bad-libs-sections.txt | 4 + gst-libs/gst/mpegts/Makefile.am | 3 +- gst-libs/gst/mpegts/gst-atsc-section.c | 213 ++++++++++++++++++++ gst-libs/gst/mpegts/gst-atsc-section.h | 51 +++++ gst-libs/gst/mpegts/gstmpegtssection.c | 9 - gst-libs/gst/mpegts/gstmpegtssection.h | 4 +- 6 files changed, 273 insertions(+), 11 deletions(-) create mode 100644 gst-libs/gst/mpegts/gst-atsc-section.c diff --git a/docs/libs/gst-plugins-bad-libs-sections.txt b/docs/libs/gst-plugins-bad-libs-sections.txt index 239978f2a4..4ac35be803 100644 --- a/docs/libs/gst-plugins-bad-libs-sections.txt +++ b/docs/libs/gst-plugins-bad-libs-sections.txt @@ -363,6 +363,10 @@ gst_mpeg_ts_stream_type_get_type
gst-atsc-section GstMpegTsSectionATSCTableID + +GstMpegTsAtscTVCTSource +GstMpegTsAtscTVCT +gst_mpegts_section_get_atsc_tvct GST_TYPE_MPEG_TS_SECTION_ATSC_TABLE_ID gst_mpeg_ts_section_atsc_table_id_get_type diff --git a/gst-libs/gst/mpegts/Makefile.am b/gst-libs/gst/mpegts/Makefile.am index 071b356f13..cfedd15e7e 100644 --- a/gst-libs/gst/mpegts/Makefile.am +++ b/gst-libs/gst/mpegts/Makefile.am @@ -4,7 +4,8 @@ libgstmpegts_@GST_API_VERSION@_la_SOURCES = \ gstmpegtssection.c \ gstmpegtsdescriptor.c \ gst-dvb-descriptor.c \ - gst-dvb-section.c + gst-dvb-section.c \ + gst-atsc-section.c libgstmpegts_@GST_API_VERSION@includedir = \ $(includedir)/gstreamer-@GST_API_VERSION@/gst/mpegts diff --git a/gst-libs/gst/mpegts/gst-atsc-section.c b/gst-libs/gst/mpegts/gst-atsc-section.c new file mode 100644 index 0000000000..3fa8e989b5 --- /dev/null +++ b/gst-libs/gst/mpegts/gst-atsc-section.c @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2014 Stefan Ringel + * + * Authors: + * Stefan Ringel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include "mpegts.h" +#include "gstmpegts-private.h" + +/** + * SECTION:gst-atsc-section + * @title: ATSC variants of MPEG-TS sections + * @short_description: Sections for the various ATSC specifications + * @include: gst/mpegts/mpegts.h + * + */ + +/* Terrestrial Virtual Channel Table TVCT */ +static GstMpegTsAtscTVCTSource * +_gst_mpegts_atsc_tvct_source_copy (GstMpegTsAtscTVCTSource * source) +{ + GstMpegTsAtscTVCTSource *copy; + + copy = g_slice_dup (GstMpegTsAtscTVCTSource, source); + copy->descriptors = g_ptr_array_ref (source->descriptors); + + return copy; +} + +static void +_gst_mpegts_atsc_tvct_source_free (GstMpegTsAtscTVCTSource * source) +{ + g_ptr_array_unref (source->descriptors); + g_slice_free (GstMpegTsAtscTVCTSource, 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); + +static GstMpegTsAtscTVCT * +_gst_mpegts_atsc_tvct_copy (GstMpegTsAtscTVCT * tvct) +{ + GstMpegTsAtscTVCT *copy; + + copy = g_slice_dup (GstMpegTsAtscTVCT, tvct); + copy->sources = g_ptr_array_ref (tvct->sources); + copy->descriptors = g_ptr_array_ref (tvct->descriptors); + + return copy; +} + +static void +_gst_mpegts_atsc_tvct_free (GstMpegTsAtscTVCT * tvct) +{ + g_ptr_array_unref (tvct->sources); + g_ptr_array_unref (tvct->descriptors); + g_slice_free (GstMpegTsAtscTVCT, tvct); +} + +G_DEFINE_BOXED_TYPE (GstMpegTsAtscTVCT, gst_mpegts_atsc_tvct, + (GBoxedCopyFunc) _gst_mpegts_atsc_tvct_copy, + (GFreeFunc) _gst_mpegts_atsc_tvct_free); + +static gpointer +_parse_atsc_tvct (GstMpegTsSection * section) +{ + GstMpegTsAtscTVCT *tvct = NULL; + guint8 *data, *end, source_nb; + guint32 tmp32; + guint16 descriptors_loop_length, tmp16; + + tvct = g_slice_new0 (GstMpegTsAtscTVCT); + + data = section->data; + end = data + section->section_length; + + tvct->transport_stream_id = section->subtable_extension; + + /* Skip already parsed data */ + data += 8; + + /* minimum size */ + if (data - end < 2 + 2 + 4) + goto error; + + tvct->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); + + for (guint i = 0; i < source_nb; i++) { + GstMpegTsAtscTVCTSource *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); + data += 14; + + tmp32 = GST_READ_UINT32_BE (data); + source->major_channel_number = (tmp32 >> 18) & 0x03FF; + source->minor_channel_number = (tmp32 >> 8) & 0x03FF; + source->modulation_mode = tmp32 & 0xF; + data += 4; + + source->carrier_frequency = GST_READ_UINT32_BE (data); + data += 4; + + source->channel_TSID = GST_READ_UINT16_BE (data); + data += 2; + + source->program_number = GST_READ_UINT16_BE (data); + data += 2; + + tmp16 = GST_READ_UINT16_BE (data); + source->ETM_location = (tmp16 >> 14) & 0x3; + source->access_controlled = (tmp16 >> 13) & 0x1; + source->hidden = (tmp16 >> 12) & 0x1; + source->hide_guide = (tmp16 >> 10) & 0x1; + source->service_type = tmp16 & 0x3f; + data += 2; + + source->source_id = GST_READ_UINT16_BE (data); + data += 2; + + descriptors_loop_length = GST_READ_UINT16_BE (data) & 0x03FF; + data += 2; + + if (end - data < descriptors_loop_length + 6) + goto error; + + source->descriptors = + gst_mpegts_parse_descriptors (data, descriptors_loop_length); + if (source->descriptors == NULL) + goto error; + data += descriptors_loop_length; + } + + descriptors_loop_length = GST_READ_UINT16_BE (data) & 0x03FF; + data += 2; + + if (end - data < descriptors_loop_length + 4) + goto error; + + tvct->descriptors = + gst_mpegts_parse_descriptors (data, descriptors_loop_length); + if (tvct->descriptors == NULL) + goto error; + data += descriptors_loop_length; + + return (gpointer) tvct; + +error: + if (tvct) + _gst_mpegts_atsc_tvct_free (tvct); + + return NULL; +} + +/** + * 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 #GstMpegTsAtscTVCT contained in the section, or %NULL if an error + * happened. + */ +const GstMpegTsAtscTVCT * +gst_mpegts_section_get_atsc_tvct (GstMpegTsSection * section) +{ + g_return_val_if_fail (section->section_type == GST_MPEGTS_SECTION_ATSC_TVCT, + 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_tvct, + (GDestroyNotify) _gst_mpegts_atsc_tvct_free); + + return (const GstMpegTsAtscTVCT *) section->cached_parsed; +} diff --git a/gst-libs/gst/mpegts/gst-atsc-section.h b/gst-libs/gst/mpegts/gst-atsc-section.h index 6489aca484..dbf5fb120a 100644 --- a/gst-libs/gst/mpegts/gst-atsc-section.h +++ b/gst-libs/gst/mpegts/gst-atsc-section.h @@ -66,6 +66,57 @@ 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 ()) + +typedef struct _GstMpegTsAtscTVCTSource GstMpegTsAtscTVCTSource; +typedef struct _GstMpegTsAtscTVCT GstMpegTsAtscTVCT; + +/** + * GstMpegTsAtscTVCTSource: + * + * Source from a @GstMpegTsAtscTVCT + */ +struct _GstMpegTsAtscTVCTSource +{ + gunichar2 *short_name; + guint16 major_channel_number; + guint16 minor_channel_number; + guint8 modulation_mode; + guint32 carrier_frequency; + guint16 channel_TSID; + guint16 program_number; + /* FIXME: */ + guint8 ETM_location; + gboolean access_controlled; + gboolean hidden; + gboolean hide_guide; + /* FIXME: */ + guint8 service_type; + guint16 source_id; + GPtrArray *descriptors; +}; + +/** + * GstMpegTsAtscTVCT: + * + * Terrestrial Virtual Channel Table (A65) + * + */ +struct _GstMpegTsAtscTVCT +{ + guint16 transport_stream_id; + guint8 protocol_version; + GPtrArray *sources; + GPtrArray *descriptors; +}; + +GType gst_mpegts_atsc_tvct_get_type (void); +GType gst_mpegts_atsc_tvct_source_get_type (void); + +const GstMpegTsAtscTVCT * gst_mpegts_section_get_atsc_tvct (GstMpegTsSection * section); + G_END_DECLS #endif /* GST_MPEGTS_SECTION_H */ diff --git a/gst-libs/gst/mpegts/gstmpegtssection.c b/gst-libs/gst/mpegts/gstmpegtssection.c index 4913095eb5..3769118863 100644 --- a/gst-libs/gst/mpegts/gstmpegtssection.c +++ b/gst-libs/gst/mpegts/gstmpegtssection.c @@ -52,15 +52,6 @@ * and other specifications mentionned in the documentation. */ -/* FIXME : Move this to proper file once we have a C file for it */ -/** - * SECTION:gst-atsc-section - * @title: ATSC variants of MPEG-TS sections - * @short_description: Sections for the various ATSC specifications - * @include: gst/mpegts/mpegts.h - * - */ - /* * TODO * diff --git a/gst-libs/gst/mpegts/gstmpegtssection.h b/gst-libs/gst/mpegts/gstmpegtssection.h index 1e8e94cb44..eef9de1a00 100644 --- a/gst-libs/gst/mpegts/gstmpegtssection.h +++ b/gst-libs/gst/mpegts/gstmpegtssection.h @@ -51,6 +51,7 @@ GType gst_mpegts_section_get_type (void); * @GST_MPEGTS_SECTION_SDT: Service Description Table (EN 300 468) * @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) * * Types of #GstMpegTsSection that the library handles. */ @@ -65,7 +66,8 @@ typedef enum { GST_MPEGTS_SECTION_BAT, GST_MPEGTS_SECTION_SDT, GST_MPEGTS_SECTION_TDT, - GST_MPEGTS_SECTION_TOT + GST_MPEGTS_SECTION_TOT, + GST_MPEGTS_SECTION_ATSC_TVCT } GstMpegTsSectionType; /**