mpegts: Properly handle UTC time in sections
authorEdward Hervey <edward@collabora.com>
Sat, 6 Jul 2013 10:39:49 +0000 (12:39 +0200)
committerEdward Hervey <edward@collabora.com>
Sat, 6 Jul 2013 10:39:49 +0000 (12:39 +0200)
* 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
tests/examples/mpegts/ts-parser.c

index 9979076..b9904ea 100644 (file)
@@ -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);
 }
index ba38b3a..069be35 100644 (file)
@@ -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 *) "<NO TIME>";
     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