From 057d24811daae96c2353add41453d118cd9eb586 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Sat, 6 Jul 2013 12:39:49 +0200 Subject: [PATCH] mpegts: Properly handle UTC time in sections * don't unref inexistant GstDateTime * Fine-tune hour/min/sec BCD reading code * Update example code accordingly --- gst-libs/gst/mpegts/gst-dvb-section.c | 15 ++++++++++----- tests/examples/mpegts/ts-parser.c | 20 +++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/gst-libs/gst/mpegts/gst-dvb-section.c b/gst-libs/gst/mpegts/gst-dvb-section.c index 9979076..b9904ea 100644 --- a/gst-libs/gst/mpegts/gst-dvb-section.c +++ b/gst-libs/gst/mpegts/gst-dvb-section.c @@ -82,9 +82,12 @@ _parse_utc_time (guint8 * data) utc_ptr = data + 2; - hour = ((utc_ptr[0] & 0xF0) >> 4) * 10 + (utc_ptr[0] & 0x0F); - minute = ((utc_ptr[1] & 0xF0) >> 4) * 10 + (utc_ptr[1] & 0x0F); - second = ((utc_ptr[2] & 0xF0) >> 4) * 10 + (utc_ptr[2] & 0x0F); + /* First digit of hours cannot exceeed 2 (max: 23 hours) */ + hour = ((utc_ptr[0] & 0x30) >> 4) * 10 + (utc_ptr[0] & 0x0F); + /* First digit of minutes cannot exced 5 (max: 59 mins) */ + minute = ((utc_ptr[1] & 0x70) >> 4) * 10 + (utc_ptr[1] & 0x0F); + /* first digit of seconds cannot exceed 5 (max: 59 seconds) */ + second = ((utc_ptr[2] & 0x70) >> 4) * 10 + (utc_ptr[2] & 0x0F); /* Time is UTC */ return gst_date_time_new (0.0, year, month, day, hour, minute, @@ -102,7 +105,8 @@ _gst_mpegts_eit_event_copy (GstMpegTsEITEvent * eit) static void _gst_mpegts_eit_event_free (GstMpegTsEITEvent * eit) { - gst_date_time_unref (eit->start_time); + if (eit->start_time) + gst_date_time_unref (eit->start_time); g_array_unref (eit->descriptors); g_slice_free (GstMpegTsEITEvent, eit); } @@ -703,7 +707,8 @@ _gst_mpegts_tot_copy (GstMpegTsTOT * tot) static void _gst_mpegts_tot_free (GstMpegTsTOT * tot) { - gst_date_time_unref (tot->utc_time); + if (tot->utc_time) + gst_date_time_unref (tot->utc_time); g_array_unref (tot->descriptors); g_slice_free (GstMpegTsTOT, tot); } diff --git a/tests/examples/mpegts/ts-parser.c b/tests/examples/mpegts/ts-parser.c index ba38b3a..069be35 100644 --- a/tests/examples/mpegts/ts-parser.c +++ b/tests/examples/mpegts/ts-parser.c @@ -259,10 +259,11 @@ dump_eit (GstMpegTsSection * section) len = eit->events->len; g_printf (" %d Event(s):\n", len); for (i = 0; i < len; i++) { - gchar *tmp; + gchar *tmp = (gchar *) ""; GstMpegTsEITEvent *event = g_ptr_array_index (eit->events, i); - tmp = gst_date_time_to_iso8601_string (event->start_time); + if (event->start_time) + tmp = gst_date_time_to_iso8601_string (event->start_time); g_printf (" event_id:0x%04x, start_time:%s, duration:%" GST_TIME_FORMAT "\n", event->event_id, tmp, GST_TIME_ARGS (event->duration * GST_SECOND)); @@ -270,7 +271,8 @@ dump_eit (GstMpegTsSection * section) event->running_status, enum_name (GST_TYPE_MPEG_TS_RUNNING_STATUS, event->running_status), event->free_CA_mode, event->free_CA_mode ? "MAYBE SCRAMBLED" : "NOT SCRAMBLED"); - g_free (tmp); + if (event->start_time) + g_free (tmp); dump_descriptors (event->descriptors, 9); } } @@ -331,11 +333,15 @@ static void dump_tdt (GstMpegTsSection * section) { GstDateTime *date = gst_mpegts_section_get_tdt (section); - gchar *str = gst_date_time_to_iso8601_string (date); - g_printf (" utc_time : %s\n", str); - g_free (str); - gst_date_time_unref (date); + if (date) { + gchar *str = gst_date_time_to_iso8601_string (date); + g_printf (" utc_time : %s\n", str); + g_free (str); + gst_date_time_unref (date); + } else { + g_printf (" No utc_time present\n"); + } } static void -- 2.7.4