mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
value: use datetime serialise/deserialise functions for datetimes
This re-uses existing code and makes sure we properly serialise and deserialise datetimes where not all fields are set (thus fixing some warnings when serialising such datetimes).
This commit is contained in:
parent
8e7bc47ccd
commit
93a2b6e9b3
3 changed files with 23 additions and 43 deletions
|
@ -148,6 +148,8 @@ void __gst_element_factory_add_interface (GstElementFactory *
|
|||
/* This is only meant for internal uses */
|
||||
gint __gst_date_time_compare (const GstDateTime * dt1, const GstDateTime * dt2);
|
||||
|
||||
gchar * __gst_date_time_serialize (GstDateTime * datetime, gboolean with_usecs);
|
||||
|
||||
#ifndef GST_DISABLE_REGISTRY
|
||||
/* Secret variable to initialise gst without registry cache */
|
||||
GST_EXPORT gboolean _gst_disable_registry_cache;
|
||||
|
|
|
@ -5259,50 +5259,29 @@ static gchar *
|
|||
gst_value_serialize_date_time (const GValue * val)
|
||||
{
|
||||
GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
|
||||
gfloat offset;
|
||||
gint tzhour, tzminute;
|
||||
|
||||
if (date == NULL)
|
||||
return g_strdup ("null");
|
||||
|
||||
offset = gst_date_time_get_time_zone_offset (date);
|
||||
|
||||
tzhour = (gint) ABS (offset);
|
||||
tzminute = (gint) ((ABS (offset) - tzhour) * 60);
|
||||
|
||||
return g_strdup_printf ("\"%04d-%02d-%02dT%02d:%02d:%02d.%06d"
|
||||
"%c%02d%02d\"", gst_date_time_get_year (date),
|
||||
gst_date_time_get_month (date), gst_date_time_get_day (date),
|
||||
gst_date_time_get_hour (date), gst_date_time_get_minute (date),
|
||||
gst_date_time_get_second (date), gst_date_time_get_microsecond (date),
|
||||
offset >= 0 ? '+' : '-', tzhour, tzminute);
|
||||
return __gst_date_time_serialize (date, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_value_deserialize_date_time (GValue * dest, const gchar * s)
|
||||
{
|
||||
gint year, month, day, hour, minute, second, usecond;
|
||||
gchar signal;
|
||||
gint offset = 0;
|
||||
gfloat tzoffset = 0;
|
||||
gint ret;
|
||||
GstDateTime *datetime;
|
||||
|
||||
if (!s || strcmp (s, "null") == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ret = sscanf (s, "%04d-%02d-%02dT%02d:%02d:%02d.%06d%c%04d",
|
||||
&year, &month, &day, &hour, &minute, &second, &usecond, &signal, &offset);
|
||||
if (ret >= 9) {
|
||||
tzoffset = (offset / 100) + ((offset % 100) / 60.0);
|
||||
if (signal == '-')
|
||||
tzoffset = -tzoffset;
|
||||
} else
|
||||
return FALSE;
|
||||
|
||||
g_value_take_boxed (dest, gst_date_time_new (tzoffset, year, month, day, hour,
|
||||
minute, second + (usecond / 1000000.0)));
|
||||
return TRUE;
|
||||
datetime = gst_date_time_new_from_iso8601_string (s);
|
||||
if (datetime != NULL) {
|
||||
g_value_take_boxed (dest, datetime);
|
||||
return TRUE;
|
||||
}
|
||||
GST_WARNING ("Failed to deserialize date time string '%s'", s);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -2046,8 +2046,8 @@ GST_START_TEST (test_date_time)
|
|||
gst_structure_free (s);
|
||||
s = NULL;
|
||||
|
||||
fail_unless (g_str_equal (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)\"2010-06-23T07:40:10.000000+0000\";"));
|
||||
fail_unless_equals_string (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)2010-06-23T07:40:10Z;");
|
||||
|
||||
s = gst_structure_from_string (str, NULL);
|
||||
g_free (str);
|
||||
|
@ -2075,8 +2075,8 @@ GST_START_TEST (test_date_time)
|
|||
gst_structure_free (s);
|
||||
s = NULL;
|
||||
|
||||
fail_unless (g_str_equal (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)\"2010-06-23T07:40:10.000000+0000\";"));
|
||||
fail_unless_equals_string (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)2010-06-23T07:40:10Z;");
|
||||
g_free (str);
|
||||
str = NULL;
|
||||
|
||||
|
@ -2102,8 +2102,8 @@ GST_START_TEST (test_date_time)
|
|||
gst_structure_free (s);
|
||||
s = NULL;
|
||||
|
||||
fail_unless (g_str_equal (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)\"2010-06-23T07:40:10.000001-0300\";"));
|
||||
fail_unless_equals_string (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)2010-06-23T07:40:10.000001-0300;");
|
||||
|
||||
s = gst_structure_from_string (str, NULL);
|
||||
g_free (str);
|
||||
|
@ -2130,8 +2130,8 @@ GST_START_TEST (test_date_time)
|
|||
str = gst_structure_to_string (s);
|
||||
gst_structure_free (s);
|
||||
s = NULL;
|
||||
fail_unless (g_str_equal (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)\"2010-06-23T07:40:10.000001-0300\";"));
|
||||
fail_unless_equals_string (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)2010-06-23T07:40:10.000001-0300;");
|
||||
|
||||
g_free (str);
|
||||
str = NULL;
|
||||
|
@ -2158,8 +2158,8 @@ GST_START_TEST (test_date_time)
|
|||
gst_structure_free (s);
|
||||
s = NULL;
|
||||
|
||||
fail_unless (g_str_equal (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)\"2010-06-23T07:40:10.000001+0200\";"));
|
||||
fail_unless_equals_string (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)2010-06-23T07:40:10.000001+0200;");
|
||||
|
||||
s = gst_structure_from_string (str, NULL);
|
||||
g_free (str);
|
||||
|
@ -2186,12 +2186,11 @@ GST_START_TEST (test_date_time)
|
|||
str = gst_structure_to_string (s);
|
||||
gst_structure_free (s);
|
||||
s = NULL;
|
||||
fail_unless (g_str_equal (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)\"2010-06-23T07:40:10.000001+0200\";"));
|
||||
fail_unless_equals_string (str,
|
||||
"media/x-type, SOME_DATE_TIME_TAG=(datetime)2010-06-23T07:40:10.000001+0200;");
|
||||
|
||||
g_free (str);
|
||||
str = NULL;
|
||||
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
|
Loading…
Reference in a new issue