mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-08 18:39:54 +00:00
Add GST_TYPE_DATE, a boxed type that wraps GDate, and the usual bunch of utility functions along with a hack that che...
Original commit message from CVS: * docs/gst/gstreamer-sections.txt: * gst/gststructure.c: (gst_structure_set_valist), (gst_structure_get_date): * gst/gststructure.h: * gst/gstvalue.c: (gst_value_set_date), (gst_value_get_date), (gst_date_copy), (gst_value_compare_date), (gst_value_serialize_date), (gst_value_deserialize_date), (gst_value_transform_date_string), (gst_value_transform_string_date), (_gst_value_initialize): * gst/gstvalue.h: Add GST_TYPE_DATE, a boxed type that wraps GDate, and the usual bunch of utility functions along with a hack that checks that developers don't accidentally use G_TYPE_DATE where GST_TYPE_DATE is required. Part of the grand scheme in #170777.
This commit is contained in:
parent
59479d47a3
commit
7390d68eee
6 changed files with 235 additions and 0 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2005-09-22 Tim-Philipp Müller <tim at centricular dot net>
|
||||
|
||||
* docs/gst/gstreamer-sections.txt:
|
||||
* gst/gststructure.c: (gst_structure_set_valist),
|
||||
(gst_structure_get_date):
|
||||
* gst/gststructure.h:
|
||||
* gst/gstvalue.c: (gst_value_set_date), (gst_value_get_date),
|
||||
(gst_date_copy), (gst_value_compare_date),
|
||||
(gst_value_serialize_date), (gst_value_deserialize_date),
|
||||
(gst_value_transform_date_string),
|
||||
(gst_value_transform_string_date), (_gst_value_initialize):
|
||||
* gst/gstvalue.h:
|
||||
Add GST_TYPE_DATE, a boxed type that wraps GDate, and the usual
|
||||
bunch of utility functions along with a hack that checks that
|
||||
developers don't accidentally use G_TYPE_DATE where GST_TYPE_DATE
|
||||
is required. Part of the grand scheme in #170777.
|
||||
|
||||
2005-09-22 Andy Wingo <wingo@pobox.com>
|
||||
|
||||
* gst/gstconfig.h.in: Psych out gtk-doc.
|
||||
|
|
|
@ -1623,6 +1623,7 @@ gst_structure_get_int
|
|||
gst_structure_get_fourcc
|
||||
gst_structure_get_double
|
||||
gst_structure_get_string
|
||||
gst_structure_get_date
|
||||
gst_structure_map_in_place
|
||||
gst_structure_nth_field_name
|
||||
gst_structure_set_parent_refcount
|
||||
|
@ -2036,6 +2037,12 @@ gst_value_get_fraction_numerator
|
|||
gst_value_get_fraction_denominator
|
||||
gst_value_fraction_multiply
|
||||
|
||||
<SUBSECTION date>
|
||||
GST_VALUE_HOLDS_DATE
|
||||
GST_TYPE_DATE
|
||||
gst_value_set_date
|
||||
gst_value_get_date
|
||||
|
||||
<SUBSECTION caps>
|
||||
GST_VALUE_HOLDS_CAPS
|
||||
gst_value_set_caps
|
||||
|
|
|
@ -438,6 +438,14 @@ gst_structure_set_valist (GstStructure * structure,
|
|||
field.name = g_quark_from_string (fieldname);
|
||||
|
||||
type = va_arg (varargs, GType);
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,8,0)
|
||||
if (type == G_TYPE_DATE) {
|
||||
g_warning ("Don't use G_TYPE_DATE, use GST_TYPE_DATE instead\n");
|
||||
type = GST_TYPE_DATE;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_value_init (&field.value, type);
|
||||
G_VALUE_COLLECT (&field.value, varargs, 0, &err);
|
||||
if (err) {
|
||||
|
@ -944,6 +952,40 @@ gst_structure_get_fourcc (const GstStructure * structure,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_structure_get_date:
|
||||
* @structure: a #GstStructure
|
||||
* @fieldname: the name of a field
|
||||
* @value: a pointer to a #GDate to set
|
||||
*
|
||||
* Sets the date pointed to by @date_out corresponding to the date of the
|
||||
* given field. Caller is responsible for making sure the field exists
|
||||
* and has the correct type.
|
||||
*
|
||||
* Returns: TRUE if the value could be set correctly
|
||||
*/
|
||||
gboolean
|
||||
gst_structure_get_date (const GstStructure * structure, const gchar * fieldname,
|
||||
GDate ** date_out)
|
||||
{
|
||||
GstStructureField *field;
|
||||
|
||||
g_return_val_if_fail (structure != NULL, FALSE);
|
||||
g_return_val_if_fail (fieldname != NULL, FALSE);
|
||||
g_return_val_if_fail (date_out != NULL, FALSE);
|
||||
|
||||
field = gst_structure_get_field (structure, fieldname);
|
||||
|
||||
if (field == NULL)
|
||||
return FALSE;
|
||||
if (!GST_VALUE_HOLDS_DATE (&field->value))
|
||||
return FALSE;
|
||||
|
||||
*date_out = g_value_dup_boxed (&field->value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_structure_get_double:
|
||||
* @structure: a #GstStructure
|
||||
|
|
|
@ -130,6 +130,9 @@ gboolean gst_structure_get_fourcc (const GstStructure
|
|||
gboolean gst_structure_get_double (const GstStructure *structure,
|
||||
const gchar *fieldname,
|
||||
gdouble *value);
|
||||
gboolean gst_structure_get_date (const GstStructure *structure,
|
||||
const gchar *fieldname,
|
||||
GDate **date_out);
|
||||
G_CONST_RETURN gchar * gst_structure_get_string (const GstStructure *structure,
|
||||
const gchar *fieldname);
|
||||
|
||||
|
|
142
gst/gstvalue.c
142
gst/gstvalue.c
|
@ -64,6 +64,7 @@ GType gst_type_double_range;
|
|||
GType gst_type_list;
|
||||
GType gst_type_array;
|
||||
GType gst_type_fraction;
|
||||
GType gst_type_date;
|
||||
|
||||
static GArray *gst_value_table;
|
||||
static GArray *gst_value_union_funcs;
|
||||
|
@ -2970,6 +2971,125 @@ gst_value_compare_fraction (const GValue * value1, const GValue * value2)
|
|||
return GST_VALUE_UNORDERED;
|
||||
}
|
||||
|
||||
/*********
|
||||
* GDate *
|
||||
*********/
|
||||
|
||||
/**
|
||||
* gst_value_set_date:
|
||||
* @value: a GValue initialized to GST_TYPE_DATE
|
||||
* @caps: the date to set the value to
|
||||
*
|
||||
* Sets the contents of @value to coorespond to @date. The actual
|
||||
* #GDate structure is copied before it is used.
|
||||
*/
|
||||
void
|
||||
gst_value_set_date (GValue * value, const GDate * date)
|
||||
{
|
||||
g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_DATE);
|
||||
|
||||
g_value_set_boxed (value, date);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_value_get_date:
|
||||
* @value: a GValue initialized to GST_TYPE_DATE
|
||||
*
|
||||
* Gets the contents of @value.
|
||||
*
|
||||
* Returns: the contents of @value
|
||||
*/
|
||||
const GDate *
|
||||
gst_value_get_date (const GValue * value)
|
||||
{
|
||||
g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_DATE, NULL);
|
||||
|
||||
return (const GDate *) g_value_get_boxed (value);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
gst_date_copy (gpointer boxed)
|
||||
{
|
||||
const GDate *date = (const GDate *) boxed;
|
||||
|
||||
return g_date_new_julian (g_date_get_julian (date));
|
||||
}
|
||||
|
||||
static int
|
||||
gst_value_compare_date (const GValue * value1, const GValue * value2)
|
||||
{
|
||||
const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
|
||||
const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
|
||||
guint32 j1, j2;
|
||||
|
||||
if (date1 == date2)
|
||||
return GST_VALUE_EQUAL;
|
||||
|
||||
if ((date1 == NULL || !g_date_valid (date1))
|
||||
&& (date2 != NULL && g_date_valid (date2))) {
|
||||
return GST_VALUE_LESS_THAN;
|
||||
}
|
||||
|
||||
if ((date2 == NULL || !g_date_valid (date2))
|
||||
&& (date1 != NULL && g_date_valid (date1))) {
|
||||
return GST_VALUE_GREATER_THAN;
|
||||
}
|
||||
|
||||
if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
|
||||
|| !g_date_valid (date2)) {
|
||||
return GST_VALUE_UNORDERED;
|
||||
}
|
||||
|
||||
j1 = g_date_get_julian (date1);
|
||||
j2 = g_date_get_julian (date2);
|
||||
|
||||
if (j1 == j2)
|
||||
return GST_VALUE_EQUAL;
|
||||
else if (j1 < j2)
|
||||
return GST_VALUE_LESS_THAN;
|
||||
else
|
||||
return GST_VALUE_GREATER_THAN;
|
||||
}
|
||||
|
||||
static char *
|
||||
gst_value_serialize_date (const GValue * val)
|
||||
{
|
||||
const GDate *date = (const GDate *) g_value_get_boxed (val);
|
||||
|
||||
if (date == NULL || !g_date_valid (date))
|
||||
return g_strdup ("9999-99-99");
|
||||
|
||||
return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
|
||||
g_date_get_month (date), g_date_get_day (date));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_value_deserialize_date (GValue * dest, const char *s)
|
||||
{
|
||||
guint year, month, day;
|
||||
|
||||
if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
|
||||
return FALSE;
|
||||
|
||||
if (!g_date_valid_dmy (day, month, year))
|
||||
return FALSE;
|
||||
|
||||
g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
|
||||
{
|
||||
dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
|
||||
{
|
||||
gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
|
||||
}
|
||||
|
||||
void
|
||||
_gst_value_initialize (void)
|
||||
{
|
||||
|
@ -3186,7 +3306,25 @@ _gst_value_initialize (void)
|
|||
gst_value.type = GST_TYPE_CAPS;
|
||||
gst_value_register (&gst_value);
|
||||
}
|
||||
{
|
||||
static GstValueTable gst_value = {
|
||||
0,
|
||||
gst_value_compare_date,
|
||||
gst_value_serialize_date,
|
||||
gst_value_deserialize_date,
|
||||
};
|
||||
|
||||
/* Not using G_TYPE_DATE here on purpose, even if we could
|
||||
* if GLIB_CHECK_VERSION(2,8,0) was true: we don't want the
|
||||
* serialised strings to have different type strings depending
|
||||
* on what version is used, so FIXME in 0.11 when we
|
||||
* require GLib-2.8 */
|
||||
gst_type_date = g_boxed_type_register_static ("GstDate",
|
||||
(GBoxedCopyFunc) gst_date_copy, (GBoxedFreeFunc) g_date_free);
|
||||
|
||||
gst_value.type = gst_type_date;
|
||||
gst_value_register (&gst_value);
|
||||
}
|
||||
|
||||
REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
|
||||
REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
|
||||
|
@ -3224,6 +3362,10 @@ _gst_value_initialize (void)
|
|||
gst_value_transform_fraction_double);
|
||||
g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
|
||||
gst_value_transform_double_fraction);
|
||||
g_value_register_transform_func (GST_TYPE_DATE, G_TYPE_STRING,
|
||||
gst_value_transform_date_string);
|
||||
g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_DATE,
|
||||
gst_value_transform_string_date);
|
||||
|
||||
gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
|
||||
gst_value_intersect_int_int_range);
|
||||
|
|
|
@ -148,6 +148,14 @@ G_BEGIN_DECLS
|
|||
*/
|
||||
#define GST_VALUE_HOLDS_FRACTION(x) (G_VALUE_HOLDS(x, gst_type_fraction))
|
||||
|
||||
/**
|
||||
* GST_VALUE_HOLDS_DATE:
|
||||
* @x: the #GValue to check
|
||||
*
|
||||
* Checks if the given #GValue contains a #GST_TYPE_DATE value.
|
||||
*/
|
||||
#define GST_VALUE_HOLDS_DATE(x) (G_VALUE_HOLDS(x, gst_type_date))
|
||||
|
||||
/**
|
||||
* GST_TYPE_FOURCC:
|
||||
*
|
||||
|
@ -204,6 +212,15 @@ G_BEGIN_DECLS
|
|||
|
||||
#define GST_TYPE_FRACTION gst_type_fraction
|
||||
|
||||
/**
|
||||
* GST_TYPE_DATE:
|
||||
*
|
||||
* a boxed #GValue type for #GDate that represents a date.
|
||||
*
|
||||
* Returns: the #GType of GstDate
|
||||
*/
|
||||
|
||||
#define GST_TYPE_DATE gst_type_date
|
||||
|
||||
/**
|
||||
* GST_VALUE_LESS_THAN:
|
||||
|
@ -284,6 +301,7 @@ GST_EXPORT GType gst_type_double_range;
|
|||
GST_EXPORT GType gst_type_list;
|
||||
GST_EXPORT GType gst_type_array;
|
||||
GST_EXPORT GType gst_type_fraction;
|
||||
GST_EXPORT GType gst_type_date;
|
||||
|
||||
void gst_value_register (const GstValueTable *table);
|
||||
void gst_value_init_and_copy (GValue *dest,
|
||||
|
@ -341,6 +359,12 @@ gboolean gst_value_fraction_multiply (GValue *product,
|
|||
const GValue *factor1,
|
||||
const GValue *factor2);
|
||||
|
||||
/* date */
|
||||
G_CONST_RETURN GDate *
|
||||
gst_value_get_date (const GValue *value);
|
||||
void gst_value_set_date (GValue *value,
|
||||
const GDate *date);
|
||||
|
||||
/* compare */
|
||||
int gst_value_compare (const GValue *value1,
|
||||
const GValue *value2);
|
||||
|
|
Loading…
Reference in a new issue