From a6eb0e54894af7d1896bfc65853d1b194479ad0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Wed, 21 Oct 2015 11:44:50 +0100 Subject: [PATCH] flvdemux: extract both creation date and time Before we only extracted the date part. --- gst/flv/gstflvdemux.c | 112 +++++++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 46 deletions(-) diff --git a/gst/flv/gstflvdemux.c b/gst/flv/gstflvdemux.c index 8d523f3..25d7695 100644 --- a/gst/flv/gstflvdemux.c +++ b/gst/flv/gstflvdemux.c @@ -38,6 +38,7 @@ #include "gstflvmux.h" #include +#include #include #include #include @@ -243,55 +244,74 @@ gst_flv_demux_check_seekability (GstFlvDemux * demux) GST_DEBUG_OBJECT (demux, "upstream seekable: %d", demux->upstream_seekable); } -static void -parse_flv_demux_parse_date_string (GDate * date, const gchar * s) +static GstDateTime * +parse_flv_demux_parse_date_string (const gchar * s) { - g_date_set_parse (date, s); - if (g_date_valid (date)) - return; + static const gchar months[12][4] = { + "Jan", "Feb", "Mar", "Apr", + "May", "Jun", "Jul", "Aug", + "Sep", "Oct", "Nov", "Dec" + }; + GstDateTime *dt = NULL; + gchar **tokens; + guint64 d; + gchar *endptr; + gint i, hh, mm, ss; + gint year = -1, month = -1, day = -1; + gint hour = -1, minute = -1, seconds = -1; /* "Fri Oct 15 15:13:16 2004" needs to be parsed */ - { - static const gchar *months[] = { - "Jan", "Feb", "Mar", "Apr", - "May", "Jun", "Jul", "Aug", - "Sep", "Oct", "Nov", "Dec" - }; - gchar **tokens = g_strsplit (s, " ", -1); - guint64 d; - gchar *endptr; - gint i; - - if (g_strv_length (tokens) != 5) - goto out; - - if (strlen (tokens[1]) != 3) - goto out; - for (i = 0; i < 12; i++) { - if (!strcmp (tokens[1], months[i])) { - break; - } - } - if (i == 12) - goto out; - g_date_set_month (date, i + 1); + tokens = g_strsplit (s, " ", -1); + + if (g_strv_length (tokens) != 5) + goto out; + + /* year */ + d = g_ascii_strtoull (tokens[4], &endptr, 10); + if (d == 0 && *endptr != '\0') + goto out; - d = g_ascii_strtoull (tokens[2], &endptr, 10); - if (d == 0 && *endptr != '\0') - goto out; + year = d; - g_date_set_day (date, d); + /* month */ + if (strlen (tokens[1]) != 3) + goto out; + for (i = 0; i < 12; i++) { + if (!strcmp (tokens[1], months[i])) { + break; + } + } + if (i == 12) + goto out; + + month = i + 1; - d = g_ascii_strtoull (tokens[4], &endptr, 10); - if (d == 0 && *endptr != '\0') - goto out; + /* day */ + d = g_ascii_strtoull (tokens[2], &endptr, 10); + if (d == 0 && *endptr != '\0') + goto out; - g_date_set_year (date, d); + day = d; - out: - if (tokens) - g_strfreev (tokens); + /* time */ + hh = mm = ss = 0; + if (sscanf (tokens[3], "%02d:%02d:%02d", &hh, &mm, &ss) < 2) + goto out; + if (hh >= 0 && hh < 24 && mm >= 0 && mm < 60 && ss >= 0 && ss < 60) { + hour = hh; + minute = mm; + seconds = ss; } + +out: + + if (tokens) + g_strfreev (tokens); + + if (year > 0) + dt = gst_date_time_new (0.0, year, month, day, hour, minute, seconds); + + return dt; } static gboolean @@ -374,16 +394,16 @@ gst_flv_demux_parse_metadata_item (GstFlvDemux * demux, GstByteReader * reader, GST_DEBUG_OBJECT (demux, "%s => (string) %s", tag_name, s); if (!strcmp (tag_name, "creationdate")) { - GDate *date = g_date_new (); + GstDateTime *dt; - parse_flv_demux_parse_date_string (date, s); - if (!g_date_valid (date)) { - GST_DEBUG_OBJECT (demux, "Failed to parse string as date"); + dt = parse_flv_demux_parse_date_string (s); + if (dt == NULL) { + GST_DEBUG_OBJECT (demux, "Failed to parse '%s' into datetime", s); } else { gst_tag_list_add (demux->taglist, GST_TAG_MERGE_REPLACE, - GST_TAG_DATE, date, NULL); + GST_TAG_DATE_TIME, dt, NULL); } - g_date_free (date); + gst_date_time_unref (dt); } else if (!strcmp (tag_name, "creator")) { gst_tag_list_add (demux->taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ARTIST, s, NULL); -- 2.7.4