2014-04-09 08:04:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Stefan Ringel
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Stefan Ringel <linuxtv@stefanringel.de>
|
|
|
|
*
|
|
|
|
* 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 <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-05-23 04:41:18 +00:00
|
|
|
/* Terrestrial/Cable Virtual Channel Table TVCT/CVCT */
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscVCTSource *
|
|
|
|
_gst_mpegts_atsc_vct_source_copy (GstMpegtsAtscVCTSource * source)
|
2014-04-09 08:04:46 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscVCTSource *copy;
|
2014-04-09 08:04:46 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscVCTSource, source);
|
2014-04-09 08:04:46 +00:00
|
|
|
copy->descriptors = g_ptr_array_ref (source->descriptors);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_vct_source_free (GstMpegtsAtscVCTSource * source)
|
2014-04-09 08:04:46 +00:00
|
|
|
{
|
2014-05-15 22:16:30 +00:00
|
|
|
if (source->descriptors)
|
|
|
|
g_ptr_array_unref (source->descriptors);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscVCTSource, source);
|
2014-04-09 08:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscVCTSource, gst_mpegts_atsc_vct_source,
|
2014-05-23 04:41:18 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_vct_source_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_vct_source_free);
|
2014-04-09 08:04:46 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscVCT *
|
|
|
|
_gst_mpegts_atsc_vct_copy (GstMpegtsAtscVCT * vct)
|
2014-04-09 08:04:46 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscVCT *copy;
|
2014-04-09 08:04:46 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscVCT, vct);
|
2014-05-23 04:41:18 +00:00
|
|
|
copy->sources = g_ptr_array_ref (vct->sources);
|
|
|
|
copy->descriptors = g_ptr_array_ref (vct->descriptors);
|
2014-04-09 08:04:46 +00:00
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_vct_free (GstMpegtsAtscVCT * vct)
|
2014-04-09 08:04:46 +00:00
|
|
|
{
|
2014-05-23 04:41:18 +00:00
|
|
|
if (vct->sources)
|
|
|
|
g_ptr_array_unref (vct->sources);
|
|
|
|
if (vct->descriptors)
|
|
|
|
g_ptr_array_unref (vct->descriptors);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscVCT, vct);
|
2014-04-09 08:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscVCT, gst_mpegts_atsc_vct,
|
2014-05-23 04:41:18 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_vct_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_vct_free);
|
2014-04-09 08:04:46 +00:00
|
|
|
|
|
|
|
static gpointer
|
2014-06-25 12:50:05 +00:00
|
|
|
_parse_atsc_vct (GstMpegtsSection * section)
|
2014-04-09 08:04:46 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscVCT *vct = NULL;
|
2014-04-09 08:04:46 +00:00
|
|
|
guint8 *data, *end, source_nb;
|
|
|
|
guint32 tmp32;
|
|
|
|
guint16 descriptors_loop_length, tmp16;
|
2014-04-15 23:25:51 +00:00
|
|
|
guint i;
|
2014-05-23 04:41:18 +00:00
|
|
|
GError *err = NULL;
|
2014-04-09 08:04:46 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
vct = g_slice_new0 (GstMpegtsAtscVCT);
|
2014-04-09 08:04:46 +00:00
|
|
|
|
|
|
|
data = section->data;
|
|
|
|
end = data + section->section_length;
|
|
|
|
|
2014-05-23 04:41:18 +00:00
|
|
|
vct->transport_stream_id = section->subtable_extension;
|
2014-04-09 08:04:46 +00:00
|
|
|
|
|
|
|
/* Skip already parsed data */
|
|
|
|
data += 8;
|
|
|
|
|
|
|
|
/* minimum size */
|
2014-05-23 04:41:18 +00:00
|
|
|
if (end - data < 2 + 2 + 4)
|
2014-04-09 08:04:46 +00:00
|
|
|
goto error;
|
|
|
|
|
2014-05-23 04:41:18 +00:00
|
|
|
vct->protocol_version = *data;
|
2014-04-09 08:04:46 +00:00
|
|
|
data += 1;
|
|
|
|
|
|
|
|
source_nb = *data;
|
|
|
|
data += 1;
|
|
|
|
|
2014-05-23 04:41:18 +00:00
|
|
|
vct->sources = g_ptr_array_new_full (source_nb,
|
|
|
|
(GDestroyNotify) _gst_mpegts_atsc_vct_source_free);
|
2014-04-09 08:04:46 +00:00
|
|
|
|
2014-04-15 23:25:51 +00:00
|
|
|
for (i = 0; i < source_nb; i++) {
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscVCTSource *source;
|
2014-04-09 08:04:46 +00:00
|
|
|
|
|
|
|
/* minimum 32 bytes for a entry, 2 bytes second descriptor
|
|
|
|
loop-length, 4 bytes crc */
|
|
|
|
if (end - data < 32 + 2 + 4)
|
|
|
|
goto error;
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
source = g_slice_new0 (GstMpegtsAtscVCTSource);
|
2014-05-23 04:41:18 +00:00
|
|
|
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);
|
|
|
|
}
|
2014-04-09 08:04:46 +00:00
|
|
|
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;
|
2014-05-23 04:41:18 +00:00
|
|
|
|
|
|
|
/* only used in CVCT */
|
|
|
|
source->path_select = (tmp16 >> 11) & 0x1;
|
|
|
|
source->out_of_band = (tmp16 >> 10) & 0x1;
|
|
|
|
|
|
|
|
source->hide_guide = (tmp16 >> 9) & 0x1;
|
2014-04-09 08:04:46 +00:00
|
|
|
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;
|
|
|
|
|
2014-05-23 04:41:18 +00:00
|
|
|
vct->descriptors =
|
2014-04-09 08:04:46 +00:00
|
|
|
gst_mpegts_parse_descriptors (data, descriptors_loop_length);
|
2014-05-23 04:41:18 +00:00
|
|
|
if (vct->descriptors == NULL)
|
2014-04-09 08:04:46 +00:00
|
|
|
goto error;
|
|
|
|
data += descriptors_loop_length;
|
|
|
|
|
2014-05-23 04:41:18 +00:00
|
|
|
return (gpointer) vct;
|
2014-04-09 08:04:46 +00:00
|
|
|
|
|
|
|
error:
|
2014-06-02 06:22:15 +00:00
|
|
|
_gst_mpegts_atsc_vct_free (vct);
|
2014-04-09 08:04:46 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_mpegts_section_get_atsc_tvct:
|
2014-06-25 12:50:05 +00:00
|
|
|
* @section: a #GstMpegtsSection of type %GST_MPEGTS_SECTION_ATSC_TVCT
|
2014-04-09 08:04:46 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns the #GstMpegtsAtscVCT contained in the @section
|
2014-04-09 08:04:46 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns: The #GstMpegtsAtscVCT contained in the section, or %NULL if an error
|
2014-04-09 08:04:46 +00:00
|
|
|
* happened.
|
|
|
|
*/
|
2014-06-25 12:50:05 +00:00
|
|
|
const GstMpegtsAtscVCT *
|
|
|
|
gst_mpegts_section_get_atsc_tvct (GstMpegtsSection * section)
|
2014-04-09 08:04:46 +00:00
|
|
|
{
|
|
|
|
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 =
|
2014-05-23 04:41:18 +00:00
|
|
|
__common_section_checks (section, 16, _parse_atsc_vct,
|
|
|
|
(GDestroyNotify) _gst_mpegts_atsc_vct_free);
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
return (const GstMpegtsAtscVCT *) section->cached_parsed;
|
2014-05-23 04:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_mpegts_section_get_atsc_cvct:
|
2014-06-25 12:50:05 +00:00
|
|
|
* @section: a #GstMpegtsSection of type %GST_MPEGTS_SECTION_ATSC_CVCT
|
2014-05-23 04:41:18 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns the #GstMpegtsAtscVCT contained in the @section
|
2014-05-23 04:41:18 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns: The #GstMpegtsAtscVCT contained in the section, or %NULL if an error
|
2014-05-23 04:41:18 +00:00
|
|
|
* happened.
|
|
|
|
*/
|
2014-06-25 12:50:05 +00:00
|
|
|
const GstMpegtsAtscVCT *
|
|
|
|
gst_mpegts_section_get_atsc_cvct (GstMpegtsSection * section)
|
2014-05-23 04:41:18 +00:00
|
|
|
{
|
|
|
|
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);
|
2014-04-09 08:04:46 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
return (const GstMpegtsAtscVCT *) section->cached_parsed;
|
2014-04-09 08:04:46 +00:00
|
|
|
}
|
2014-05-15 15:31:05 +00:00
|
|
|
|
|
|
|
/* MGT */
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscMGTTable *
|
|
|
|
_gst_mpegts_atsc_mgt_table_copy (GstMpegtsAtscMGTTable * mgt_table)
|
2014-05-15 15:31:05 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscMGTTable *copy;
|
2014-05-15 15:31:05 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscMGTTable, mgt_table);
|
2014-05-15 15:31:05 +00:00
|
|
|
copy->descriptors = g_ptr_array_ref (mgt_table->descriptors);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_mgt_table_free (GstMpegtsAtscMGTTable * mgt_table)
|
2014-05-15 15:31:05 +00:00
|
|
|
{
|
|
|
|
g_ptr_array_unref (mgt_table->descriptors);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscMGTTable, mgt_table);
|
2014-05-15 15:31:05 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscMGTTable, gst_mpegts_atsc_mgt_table,
|
2014-05-15 15:31:05 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_mgt_table_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_mgt_table_free);
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscMGT *
|
|
|
|
_gst_mpegts_atsc_mgt_copy (GstMpegtsAtscMGT * mgt)
|
2014-05-15 15:31:05 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscMGT *copy;
|
2014-05-15 15:31:05 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscMGT, mgt);
|
2014-05-15 15:31:05 +00:00
|
|
|
copy->tables = g_ptr_array_ref (mgt->tables);
|
|
|
|
copy->descriptors = g_ptr_array_ref (mgt->descriptors);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_mgt_free (GstMpegtsAtscMGT * mgt)
|
2014-05-15 15:31:05 +00:00
|
|
|
{
|
|
|
|
g_ptr_array_unref (mgt->tables);
|
|
|
|
g_ptr_array_unref (mgt->descriptors);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscMGT, mgt);
|
2014-05-15 15:31:05 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscMGT, gst_mpegts_atsc_mgt,
|
2014-05-15 15:31:05 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_mgt_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_mgt_free);
|
|
|
|
|
|
|
|
static gpointer
|
2014-06-25 12:50:05 +00:00
|
|
|
_parse_atsc_mgt (GstMpegtsSection * section)
|
2014-05-15 15:31:05 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscMGT *mgt = NULL;
|
2014-05-15 15:31:05 +00:00
|
|
|
guint i = 0;
|
|
|
|
guint8 *data, *end;
|
|
|
|
guint16 descriptors_loop_length;
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
mgt = g_slice_new0 (GstMpegtsAtscMGT);
|
2014-05-15 15:31:05 +00:00
|
|
|
|
|
|
|
data = section->data;
|
|
|
|
end = data + section->section_length;
|
|
|
|
|
|
|
|
/* Skip already parsed data */
|
|
|
|
data += 8;
|
|
|
|
|
|
|
|
mgt->protocol_version = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
mgt->tables_defined = GST_READ_UINT16_BE (data);
|
|
|
|
data += 2;
|
|
|
|
mgt->tables = g_ptr_array_new_full (mgt->tables_defined,
|
|
|
|
(GDestroyNotify) _gst_mpegts_atsc_mgt_table_free);
|
|
|
|
for (i = 0; i < mgt->tables_defined && data + 11 < end; i++) {
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscMGTTable *mgt_table;
|
2014-05-15 15:31:05 +00:00
|
|
|
|
|
|
|
if (data + 11 >= end) {
|
|
|
|
GST_WARNING ("MGT data too short to parse inner table num %d", i);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
mgt_table = g_slice_new0 (GstMpegtsAtscMGTTable);
|
2014-05-15 15:31:05 +00:00
|
|
|
g_ptr_array_add (mgt->tables, mgt_table);
|
|
|
|
|
|
|
|
mgt_table->table_type = GST_READ_UINT16_BE (data);
|
|
|
|
data += 2;
|
|
|
|
mgt_table->pid = GST_READ_UINT16_BE (data) & 0x1FFF;
|
|
|
|
data += 2;
|
|
|
|
mgt_table->version_number = GST_READ_UINT8 (data) & 0x1F;
|
|
|
|
data += 1;
|
|
|
|
mgt_table->number_bytes = GST_READ_UINT32_BE (data);
|
|
|
|
data += 4;
|
|
|
|
descriptors_loop_length = GST_READ_UINT16_BE (data) & 0x0FFF;
|
|
|
|
data += 2;
|
|
|
|
|
|
|
|
if (data + descriptors_loop_length >= end) {
|
|
|
|
GST_WARNING ("MGT data too short to parse inner table descriptors (table "
|
|
|
|
"num %d", i);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
mgt_table->descriptors =
|
|
|
|
gst_mpegts_parse_descriptors (data, descriptors_loop_length);
|
|
|
|
data += descriptors_loop_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
descriptors_loop_length = GST_READ_UINT16_BE (data) & 0xFFF;
|
|
|
|
data += 2;
|
|
|
|
if (data + descriptors_loop_length >= end) {
|
|
|
|
GST_WARNING ("MGT data too short to parse descriptors");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
mgt->descriptors =
|
|
|
|
gst_mpegts_parse_descriptors (data, descriptors_loop_length);
|
|
|
|
data += descriptors_loop_length;
|
|
|
|
|
|
|
|
return (gpointer) mgt;
|
|
|
|
|
|
|
|
error:
|
2014-06-02 06:22:15 +00:00
|
|
|
_gst_mpegts_atsc_mgt_free (mgt);
|
2014-05-15 15:31:05 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_mpegts_section_get_atsc_mgt:
|
2014-06-25 12:50:05 +00:00
|
|
|
* @section: a #GstMpegtsSection of type %GST_MPEGTS_SECTION_ATSC_MGT
|
2014-05-15 15:31:05 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns the #GstMpegtsAtscMGT contained in the @section.
|
2014-05-15 15:31:05 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns: The #GstMpegtsAtscMGT contained in the section, or %NULL if an error
|
2014-05-15 15:31:05 +00:00
|
|
|
* happened.
|
|
|
|
*/
|
2014-06-25 12:50:05 +00:00
|
|
|
const GstMpegtsAtscMGT *
|
|
|
|
gst_mpegts_section_get_atsc_mgt (GstMpegtsSection * section)
|
2014-05-15 15:31:05 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (section->section_type == GST_MPEGTS_SECTION_ATSC_MGT,
|
|
|
|
NULL);
|
|
|
|
g_return_val_if_fail (section->cached_parsed || section->data, NULL);
|
|
|
|
|
|
|
|
if (!section->cached_parsed)
|
|
|
|
section->cached_parsed =
|
|
|
|
__common_section_checks (section, 17, _parse_atsc_mgt,
|
|
|
|
(GDestroyNotify) _gst_mpegts_atsc_mgt_free);
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
return (const GstMpegtsAtscMGT *) section->cached_parsed;
|
2014-05-15 15:31:05 +00:00
|
|
|
}
|
2014-05-19 16:46:03 +00:00
|
|
|
|
2014-05-28 18:59:23 +00:00
|
|
|
/* Multi string structure */
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscStringSegment *
|
|
|
|
_gst_mpegts_atsc_string_segment_copy (GstMpegtsAtscStringSegment * seg)
|
2014-05-19 16:46:03 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscStringSegment *copy;
|
2014-05-19 16:46:03 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscStringSegment, seg);
|
2014-05-19 16:46:03 +00:00
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_string_segment_free (GstMpegtsAtscStringSegment * seg)
|
2014-05-19 16:46:03 +00:00
|
|
|
{
|
|
|
|
if (seg->cached_string)
|
|
|
|
g_free (seg->cached_string);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscStringSegment, seg);
|
2014-05-19 16:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_string_segment_decode_string (GstMpegtsAtscStringSegment * seg)
|
2014-05-19 16:46:03 +00:00
|
|
|
{
|
2014-05-19 19:20:44 +00:00
|
|
|
const gchar *from_encoding;
|
|
|
|
|
2014-05-19 16:46:03 +00:00
|
|
|
g_return_if_fail (seg->cached_string == NULL);
|
|
|
|
|
|
|
|
if (seg->compression_type != 0) {
|
|
|
|
GST_FIXME ("Compressed strings not yet supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-19 19:20:44 +00:00
|
|
|
/* FIXME add more encodings */
|
|
|
|
switch (seg->mode) {
|
|
|
|
case 0x3F:
|
|
|
|
from_encoding = "UTF-16BE";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
from_encoding = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-27 15:50:02 +00:00
|
|
|
if (from_encoding != NULL && seg->compressed_data_size > 0) {
|
2014-05-19 19:20:44 +00:00
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
seg->cached_string =
|
|
|
|
g_convert ((gchar *) seg->compressed_data,
|
|
|
|
(gssize) seg->compressed_data_size, "UTF-8", from_encoding, NULL, NULL,
|
|
|
|
&err);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
GST_WARNING ("Failed to convert input string from codeset %s",
|
|
|
|
from_encoding);
|
|
|
|
g_error_free (err);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
seg->cached_string =
|
|
|
|
g_strndup ((gchar *) seg->compressed_data, seg->compressed_data_size);
|
|
|
|
}
|
2014-05-19 16:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2014-06-25 12:50:05 +00:00
|
|
|
gst_mpegts_atsc_string_segment_get_string (GstMpegtsAtscStringSegment * seg)
|
2014-05-19 16:46:03 +00:00
|
|
|
{
|
|
|
|
if (!seg->cached_string)
|
|
|
|
_gst_mpegts_atsc_string_segment_decode_string (seg);
|
|
|
|
|
|
|
|
return seg->cached_string;
|
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscStringSegment, gst_mpegts_atsc_string_segment,
|
2014-05-19 16:46:03 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_string_segment_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_string_segment_free);
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscMultString *
|
|
|
|
_gst_mpegts_atsc_mult_string_copy (GstMpegtsAtscMultString * mstring)
|
2014-05-19 16:46:03 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscMultString *copy;
|
2014-05-19 16:46:03 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscMultString, mstring);
|
2014-05-19 16:46:03 +00:00
|
|
|
copy->segments = g_ptr_array_ref (mstring->segments);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_mult_string_free (GstMpegtsAtscMultString * mstring)
|
2014-05-19 16:46:03 +00:00
|
|
|
{
|
|
|
|
g_ptr_array_unref (mstring->segments);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscMultString, mstring);
|
2014-05-19 16:46:03 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscMultString, gst_mpegts_atsc_mult_string,
|
2014-05-19 16:46:03 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_mult_string_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_mult_string_free);
|
|
|
|
|
2014-05-28 18:59:23 +00:00
|
|
|
static GPtrArray *
|
|
|
|
_parse_atsc_mult_string (guint8 * data, guint datasize)
|
2014-05-19 16:46:03 +00:00
|
|
|
{
|
|
|
|
guint8 num_strings;
|
2014-05-28 18:59:23 +00:00
|
|
|
GPtrArray *res = NULL;
|
|
|
|
guint8 *end = data + datasize;
|
|
|
|
gint i;
|
2014-05-19 16:46:03 +00:00
|
|
|
|
2014-05-28 18:59:23 +00:00
|
|
|
if (datasize > 0) {
|
2014-05-19 16:46:03 +00:00
|
|
|
/* 1 is the minimum entry size, so no need to check here */
|
|
|
|
num_strings = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
|
2014-05-28 18:59:23 +00:00
|
|
|
res =
|
|
|
|
g_ptr_array_new_full (num_strings,
|
|
|
|
(GDestroyNotify) _gst_mpegts_atsc_mult_string_free);
|
|
|
|
|
2014-05-19 16:46:03 +00:00
|
|
|
for (i = 0; i < num_strings; i++) {
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscMultString *mstring;
|
2014-05-19 16:46:03 +00:00
|
|
|
guint8 num_segments;
|
|
|
|
gint j;
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
mstring = g_slice_new0 (GstMpegtsAtscMultString);
|
2014-05-28 18:59:23 +00:00
|
|
|
g_ptr_array_add (res, mstring);
|
2014-05-19 16:46:03 +00:00
|
|
|
mstring->segments =
|
|
|
|
g_ptr_array_new_full (num_strings,
|
|
|
|
(GDestroyNotify) _gst_mpegts_atsc_string_segment_free);
|
|
|
|
|
2014-05-28 18:59:23 +00:00
|
|
|
/* each entry needs at least 4 bytes (lang code and segments number) */
|
|
|
|
if (end - data < 4) {
|
|
|
|
GST_WARNING ("Data too short for multstring parsing %d",
|
|
|
|
(gint) (end - data));
|
2014-05-19 16:46:03 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
mstring->iso_639_langcode[0] = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
mstring->iso_639_langcode[1] = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
mstring->iso_639_langcode[2] = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
num_segments = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
|
|
|
|
for (j = 0; j < num_segments; j++) {
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscStringSegment *seg;
|
2014-05-19 16:46:03 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
seg = g_slice_new0 (GstMpegtsAtscStringSegment);
|
2014-05-19 16:46:03 +00:00
|
|
|
g_ptr_array_add (mstring->segments, seg);
|
|
|
|
|
2014-05-28 18:59:23 +00:00
|
|
|
/* each entry needs at least 3 bytes */
|
|
|
|
if (end - data < 3) {
|
|
|
|
GST_WARNING ("Data too short for multstring parsing %d", datasize);
|
2014-05-19 16:46:03 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
seg->compression_type = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
seg->mode = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
seg->compressed_data_size = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
|
2014-05-28 18:59:23 +00:00
|
|
|
if (end - data < seg->compressed_data_size) {
|
|
|
|
GST_WARNING ("Data too short for multstring parsing %d", datasize);
|
2014-05-19 16:46:03 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seg->compressed_data_size)
|
|
|
|
seg->compressed_data = data;
|
|
|
|
data += seg->compressed_data_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2014-05-28 18:59:23 +00:00
|
|
|
return res;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (res)
|
|
|
|
g_ptr_array_unref (res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EIT */
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscEITEvent *
|
|
|
|
_gst_mpegts_atsc_eit_event_copy (GstMpegtsAtscEITEvent * event)
|
2014-05-28 18:59:23 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscEITEvent *copy;
|
2014-05-28 18:59:23 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscEITEvent, event);
|
2014-05-28 18:59:23 +00:00
|
|
|
copy->titles = g_ptr_array_ref (event->titles);
|
|
|
|
copy->descriptors = g_ptr_array_ref (event->descriptors);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_eit_event_free (GstMpegtsAtscEITEvent * event)
|
2014-05-28 18:59:23 +00:00
|
|
|
{
|
|
|
|
if (event->titles)
|
|
|
|
g_ptr_array_unref (event->titles);
|
|
|
|
if (event->descriptors)
|
|
|
|
g_ptr_array_unref (event->descriptors);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscEITEvent, event);
|
2014-05-28 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscEITEvent, gst_mpegts_atsc_eit_event,
|
2014-05-28 18:59:23 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_eit_event_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_eit_event_free);
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscEIT *
|
|
|
|
_gst_mpegts_atsc_eit_copy (GstMpegtsAtscEIT * eit)
|
2014-05-28 18:59:23 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscEIT *copy;
|
2014-05-28 18:59:23 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscEIT, eit);
|
2014-05-28 18:59:23 +00:00
|
|
|
copy->events = g_ptr_array_ref (eit->events);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_eit_free (GstMpegtsAtscEIT * eit)
|
2014-05-28 18:59:23 +00:00
|
|
|
{
|
|
|
|
if (eit->events)
|
|
|
|
g_ptr_array_unref (eit->events);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscEIT, eit);
|
2014-05-28 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscEIT, gst_mpegts_atsc_eit,
|
2014-05-28 18:59:23 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_eit_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_eit_free);
|
|
|
|
|
|
|
|
static gpointer
|
2014-06-25 12:50:05 +00:00
|
|
|
_parse_atsc_eit (GstMpegtsSection * section)
|
2014-05-28 18:59:23 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscEIT *eit = NULL;
|
2014-05-28 18:59:23 +00:00
|
|
|
guint i = 0;
|
|
|
|
guint8 *data, *end;
|
|
|
|
guint8 num_events;
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
eit = g_slice_new0 (GstMpegtsAtscEIT);
|
2014-05-28 18:59:23 +00:00
|
|
|
|
|
|
|
data = section->data;
|
|
|
|
end = data + section->section_length;
|
|
|
|
|
|
|
|
eit->source_id = section->subtable_extension;
|
|
|
|
|
|
|
|
/* Skip already parsed data */
|
|
|
|
data += 8;
|
|
|
|
|
|
|
|
eit->protocol_version = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
num_events = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
|
|
|
|
eit->events = g_ptr_array_new_with_free_func ((GDestroyNotify)
|
|
|
|
_gst_mpegts_atsc_eit_event_free);
|
|
|
|
|
|
|
|
for (i = 0; i < num_events; i++) {
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscEITEvent *event;
|
2014-05-28 18:59:23 +00:00
|
|
|
guint32 tmp;
|
|
|
|
guint8 text_length;
|
|
|
|
guint16 descriptors_loop_length;
|
|
|
|
|
|
|
|
if (end - data < 12) {
|
|
|
|
GST_WARNING ("PID %d invalid EIT entry length %d with %u events",
|
|
|
|
section->pid, (gint) (end - 4 - data), num_events);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
event = g_slice_new0 (GstMpegtsAtscEITEvent);
|
2014-05-28 18:59:23 +00:00
|
|
|
g_ptr_array_add (eit->events, event);
|
|
|
|
|
|
|
|
event->event_id = GST_READ_UINT16_BE (data) & 0x3FFF;
|
|
|
|
data += 2;
|
|
|
|
event->start_time = GST_READ_UINT32_BE (data);
|
|
|
|
data += 4;
|
|
|
|
|
|
|
|
tmp = GST_READ_UINT32_BE (data);
|
|
|
|
data += 4;
|
|
|
|
event->etm_location = (tmp >> 28) & 0x3;
|
|
|
|
event->length_in_seconds = (tmp >> 8) & 0x0FFFFF;
|
|
|
|
text_length = tmp & 0xFF;
|
|
|
|
|
|
|
|
if (text_length > end - data - 4 - 2) {
|
|
|
|
GST_WARNING ("PID %d invalid EIT entry length %d with %u events",
|
|
|
|
section->pid, (gint) (end - 4 - data), num_events);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
event->titles = _parse_atsc_mult_string (data, text_length);
|
|
|
|
data += text_length;
|
|
|
|
|
|
|
|
descriptors_loop_length = GST_READ_UINT16_BE (data) & 0x0FFF;
|
|
|
|
data += 2;
|
|
|
|
|
|
|
|
if (end - data - 4 < descriptors_loop_length) {
|
|
|
|
GST_WARNING ("PID %d invalid EIT entry length %d with %u events",
|
|
|
|
section->pid, (gint) (end - 4 - data), num_events);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
event->descriptors =
|
|
|
|
gst_mpegts_parse_descriptors (data, descriptors_loop_length);
|
|
|
|
data += descriptors_loop_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data != end - 4) {
|
|
|
|
GST_WARNING ("PID %d invalid EIT parsed %d length %d",
|
|
|
|
section->pid, (gint) (data - section->data), section->section_length);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (gpointer) eit;
|
|
|
|
|
|
|
|
error:
|
2014-06-02 06:22:15 +00:00
|
|
|
_gst_mpegts_atsc_eit_free (eit);
|
2014-05-28 18:59:23 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_mpegts_section_get_atsc_eit:
|
2014-06-25 12:50:05 +00:00
|
|
|
* @section: a #GstMpegtsSection of type %GST_MPEGTS_SECTION_ATSC_EIT
|
2014-05-28 18:59:23 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns the #GstMpegtsAtscEIT contained in the @section.
|
2014-05-28 18:59:23 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns: The #GstMpegtsAtscEIT contained in the section, or %NULL if an error
|
2014-05-28 18:59:23 +00:00
|
|
|
* happened.
|
|
|
|
*/
|
2014-06-25 12:50:05 +00:00
|
|
|
const GstMpegtsAtscEIT *
|
|
|
|
gst_mpegts_section_get_atsc_eit (GstMpegtsSection * section)
|
2014-05-28 18:59:23 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (section->section_type == GST_MPEGTS_SECTION_ATSC_EIT,
|
|
|
|
NULL);
|
|
|
|
g_return_val_if_fail (section->cached_parsed || section->data, NULL);
|
|
|
|
|
|
|
|
if (!section->cached_parsed)
|
|
|
|
section->cached_parsed =
|
|
|
|
__common_section_checks (section, 14, _parse_atsc_eit,
|
|
|
|
(GDestroyNotify) _gst_mpegts_atsc_eit_free);
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
return (const GstMpegtsAtscEIT *) section->cached_parsed;
|
2014-05-28 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscETT *
|
|
|
|
_gst_mpegts_atsc_ett_copy (GstMpegtsAtscETT * ett)
|
2014-05-28 18:59:23 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscETT *copy;
|
2014-05-28 18:59:23 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscETT, ett);
|
2014-05-28 18:59:23 +00:00
|
|
|
copy->messages = g_ptr_array_ref (ett->messages);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_ett_free (GstMpegtsAtscETT * ett)
|
2014-05-28 18:59:23 +00:00
|
|
|
{
|
|
|
|
if (ett->messages)
|
|
|
|
g_ptr_array_unref (ett->messages);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscETT, ett);
|
2014-05-28 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscETT, gst_mpegts_atsc_ett,
|
2014-05-28 18:59:23 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_ett_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_ett_free);
|
|
|
|
|
|
|
|
static gpointer
|
2014-06-25 12:50:05 +00:00
|
|
|
_parse_ett (GstMpegtsSection * section)
|
2014-05-28 18:59:23 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscETT *ett = NULL;
|
2014-05-28 18:59:23 +00:00
|
|
|
guint8 *data, *end;
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
ett = g_slice_new0 (GstMpegtsAtscETT);
|
2014-05-28 18:59:23 +00:00
|
|
|
|
|
|
|
data = section->data;
|
|
|
|
end = data + section->section_length;
|
|
|
|
|
2014-05-28 19:34:08 +00:00
|
|
|
ett->ett_table_id_extension = section->subtable_extension;
|
|
|
|
|
2014-05-28 18:59:23 +00:00
|
|
|
/* Skip already parsed data */
|
|
|
|
data += 8;
|
|
|
|
|
|
|
|
ett->protocol_version = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
ett->etm_id = GST_READ_UINT32_BE (data);
|
|
|
|
data += 4;
|
|
|
|
|
|
|
|
ett->messages = _parse_atsc_mult_string (data, end - data - 4);
|
|
|
|
data += end - data - 4;
|
2014-05-19 16:46:03 +00:00
|
|
|
|
|
|
|
if (data != end - 4) {
|
|
|
|
GST_WARNING ("PID %d invalid ETT parsed %d length %d",
|
|
|
|
section->pid, (gint) (data - section->data), section->section_length);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (gpointer) ett;
|
|
|
|
|
|
|
|
error:
|
2014-06-02 06:22:15 +00:00
|
|
|
_gst_mpegts_atsc_ett_free (ett);
|
2014-05-19 16:46:03 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_mpegts_section_get_atsc_ett:
|
2014-06-25 12:50:05 +00:00
|
|
|
* @section: a #GstMpegtsSection of type %GST_MPEGTS_SECTION_ATSC_ETT
|
2014-05-19 16:46:03 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns the #GstMpegtsAtscETT contained in the @section.
|
2014-05-19 16:46:03 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns: The #GstMpegtsAtscETT contained in the section, or %NULL if an error
|
2014-05-19 16:46:03 +00:00
|
|
|
* happened.
|
|
|
|
*/
|
2014-06-25 12:50:05 +00:00
|
|
|
const GstMpegtsAtscETT *
|
|
|
|
gst_mpegts_section_get_atsc_ett (GstMpegtsSection * section)
|
2014-05-19 16:46:03 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (section->section_type == GST_MPEGTS_SECTION_ATSC_ETT,
|
|
|
|
NULL);
|
|
|
|
g_return_val_if_fail (section->cached_parsed || section->data, NULL);
|
|
|
|
|
|
|
|
if (!section->cached_parsed)
|
|
|
|
section->cached_parsed = __common_section_checks (section, 17, _parse_ett,
|
|
|
|
(GDestroyNotify) _gst_mpegts_atsc_ett_free);
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
return (const GstMpegtsAtscETT *) section->cached_parsed;
|
2014-05-19 16:46:03 +00:00
|
|
|
}
|
2014-05-22 04:47:48 +00:00
|
|
|
|
|
|
|
/* STT */
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
static GstMpegtsAtscSTT *
|
|
|
|
_gst_mpegts_atsc_stt_copy (GstMpegtsAtscSTT * stt)
|
2014-05-22 04:47:48 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscSTT *copy;
|
2014-05-22 04:47:48 +00:00
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
copy = g_slice_dup (GstMpegtsAtscSTT, stt);
|
2014-05-22 04:47:48 +00:00
|
|
|
copy->descriptors = g_ptr_array_ref (stt->descriptors);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-25 12:50:05 +00:00
|
|
|
_gst_mpegts_atsc_stt_free (GstMpegtsAtscSTT * stt)
|
2014-05-22 04:47:48 +00:00
|
|
|
{
|
|
|
|
if (stt->descriptors)
|
|
|
|
g_ptr_array_unref (stt->descriptors);
|
2014-06-25 12:50:05 +00:00
|
|
|
g_slice_free (GstMpegtsAtscSTT, stt);
|
2014-05-22 04:47:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstMpegtsAtscSTT, gst_mpegts_atsc_stt,
|
2014-05-22 04:47:48 +00:00
|
|
|
(GBoxedCopyFunc) _gst_mpegts_atsc_stt_copy,
|
|
|
|
(GFreeFunc) _gst_mpegts_atsc_stt_free);
|
|
|
|
|
|
|
|
static gpointer
|
2014-06-25 12:50:05 +00:00
|
|
|
_parse_atsc_stt (GstMpegtsSection * section)
|
2014-05-22 04:47:48 +00:00
|
|
|
{
|
2014-06-25 12:50:05 +00:00
|
|
|
GstMpegtsAtscSTT *stt = NULL;
|
2014-05-22 04:47:48 +00:00
|
|
|
guint8 *data, *end;
|
|
|
|
guint16 daylight_saving;
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
stt = g_slice_new0 (GstMpegtsAtscSTT);
|
2014-05-22 04:47:48 +00:00
|
|
|
|
|
|
|
data = section->data;
|
|
|
|
end = data + section->section_length;
|
|
|
|
|
|
|
|
/* Skip already parsed data */
|
|
|
|
data += 8;
|
|
|
|
|
|
|
|
stt->protocol_version = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
stt->system_time = GST_READ_UINT32_BE (data);
|
|
|
|
data += 4;
|
|
|
|
stt->gps_utc_offset = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
|
|
|
|
|
|
|
daylight_saving = GST_READ_UINT16_BE (data);
|
|
|
|
data += 2;
|
|
|
|
stt->ds_status = daylight_saving >> 15;
|
|
|
|
stt->ds_dayofmonth = (daylight_saving >> 8) & 0x1F;
|
|
|
|
stt->ds_hour = daylight_saving & 0xFF;
|
|
|
|
|
|
|
|
stt->descriptors = gst_mpegts_parse_descriptors (data, end - data - 4);
|
|
|
|
if (stt->descriptors == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return (gpointer) stt;
|
|
|
|
|
|
|
|
error:
|
2014-06-02 06:22:15 +00:00
|
|
|
_gst_mpegts_atsc_stt_free (stt);
|
2014-05-22 04:47:48 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_mpegts_section_get_atsc_stt:
|
2014-06-25 12:50:05 +00:00
|
|
|
* @section: a #GstMpegtsSection of type %GST_MPEGTS_SECTION_ATSC_STT
|
2014-05-22 04:47:48 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns the #GstMpegtsAtscSTT contained in the @section.
|
2014-05-22 04:47:48 +00:00
|
|
|
*
|
2014-06-25 12:50:05 +00:00
|
|
|
* Returns: The #GstMpegtsAtscSTT contained in the section, or %NULL if an error
|
2014-05-22 04:47:48 +00:00
|
|
|
* happened.
|
|
|
|
*/
|
2014-06-25 12:50:05 +00:00
|
|
|
const GstMpegtsAtscSTT *
|
|
|
|
gst_mpegts_section_get_atsc_stt (GstMpegtsSection * section)
|
2014-05-22 04:47:48 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (section->section_type == GST_MPEGTS_SECTION_ATSC_STT,
|
|
|
|
NULL);
|
|
|
|
g_return_val_if_fail (section->cached_parsed || section->data, NULL);
|
|
|
|
|
|
|
|
if (!section->cached_parsed)
|
|
|
|
section->cached_parsed =
|
|
|
|
__common_section_checks (section, 20, _parse_atsc_stt,
|
|
|
|
(GDestroyNotify) _gst_mpegts_atsc_stt_free);
|
|
|
|
|
2014-06-25 12:50:05 +00:00
|
|
|
return (const GstMpegtsAtscSTT *) section->cached_parsed;
|
2014-05-22 04:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GPS_TO_UTC_TICKS G_GINT64_CONSTANT(315964800)
|
|
|
|
static GstDateTime *
|
|
|
|
_gst_mpegts_atsc_gps_time_to_datetime (guint32 systemtime, guint8 gps_offset)
|
|
|
|
{
|
|
|
|
return gst_date_time_new_from_unix_epoch_utc (systemtime - gps_offset +
|
|
|
|
GPS_TO_UTC_TICKS);
|
|
|
|
}
|
|
|
|
|
|
|
|
GstDateTime *
|
2014-06-25 12:50:05 +00:00
|
|
|
gst_mpegts_atsc_stt_get_datetime_utc (GstMpegtsAtscSTT * stt)
|
2014-05-22 04:47:48 +00:00
|
|
|
{
|
|
|
|
if (stt->utc_datetime == NULL)
|
|
|
|
stt->utc_datetime = _gst_mpegts_atsc_gps_time_to_datetime (stt->system_time,
|
|
|
|
stt->gps_utc_offset);
|
|
|
|
|
|
|
|
if (stt->utc_datetime)
|
|
|
|
return gst_date_time_ref (stt->utc_datetime);
|
|
|
|
return NULL;
|
|
|
|
}
|