#include <gobject/gvaluecollector.h>
#include "gstutils.h"
+/* GstValueUnionFunc:
+ * @dest: a #GValue for the result
+ * @value1: a #GValue operand
+ * @value2: a #GValue operand
+ *
+ * Used by gst_value_union() to perform unification for a specific #GValue
+ * type. Register a new implementation with gst_value_register_union_func().
+ *
+ * Returns: %TRUE if a union was successful
+ */
+typedef gboolean (*GstValueUnionFunc) (GValue * dest,
+ const GValue * value1, const GValue * value2);
+
+/* GstValueIntersectFunc:
+ * @dest: (out caller-allocates): a #GValue for the result
+ * @value1: a #GValue operand
+ * @value2: a #GValue operand
+ *
+ * Used by gst_value_intersect() to perform intersection for a specific #GValue
+ * type. If the intersection is non-empty, the result is
+ * placed in @dest and TRUE is returned. If the intersection is
+ * empty, @dest is unmodified and FALSE is returned.
+ * Register a new implementation with gst_value_register_intersect_func().
+ *
+ * Returns: %TRUE if the values can intersect
+ */
+typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
+ const GValue * value1, const GValue * value2);
+
+/* GstValueSubtractFunc:
+ * @dest: (out caller-allocates): a #GValue for the result
+ * @minuend: a #GValue operand
+ * @subtrahend: a #GValue operand
+ *
+ * Used by gst_value_subtract() to perform subtraction for a specific #GValue
+ * type. Register a new implementation with gst_value_register_subtract_func().
+ *
+ * Returns: %TRUE if the subtraction is not empty
+ */
+typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
+ const GValue * minuend, const GValue * subtrahend);
+
+static void gst_value_register_union_func (GType type1,
+ GType type2, GstValueUnionFunc func);
+static void gst_value_register_intersect_func (GType type1,
+ GType type2, GstValueIntersectFunc func);
+static void gst_value_register_subtract_func (GType minuend_type,
+ GType subtrahend_type, GstValueSubtractFunc func);
+
typedef struct _GstValueUnionInfo GstValueUnionInfo;
struct _GstValueUnionInfo
{
static gboolean
gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
{
+ if (G_UNLIKELY (value == NULL))
+ return FALSE;
+
if (GST_VALUE_HOLDS_LIST (value)) {
if (VALUE_LIST_SIZE (value) == 0)
return FALSE;
return gst_value_list_or_array_get_basic_type (&g_array_index (array,
GValue, 0), type);
}
+
*type = G_VALUE_TYPE (value);
+
return TRUE;
}
/*************
* int range *
+ *
+ * Values in the range are defined as any value greater or equal
+ * to min*step, AND lesser or equal to max*step.
+ * For step == 1, this falls back to the traditional range semantics.
*************/
+#define INT_RANGE_MIN(v) (((gint *)((v)->data[0].v_pointer))[0])
+#define INT_RANGE_MAX(v) (((gint *)((v)->data[0].v_pointer))[1])
+#define INT_RANGE_STEP(v) (((gint *)((v)->data[0].v_pointer))[2])
+
static void
gst_value_init_int_range (GValue * value)
{
- value->data[0].v_int = 0;
- value->data[1].v_int = 0;
+ gint *vals = g_slice_alloc0 (3 * sizeof (gint));
+ value->data[0].v_pointer = vals;
+ INT_RANGE_MIN (value) = 0;
+ INT_RANGE_MAX (value) = 0;
+ INT_RANGE_STEP (value) = 1;
+}
+
+static void
+gst_value_free_int_range (GValue * value)
+{
+ g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
+ g_slice_free1 (3 * sizeof (gint), value->data[0].v_pointer);
+ value->data[0].v_pointer = NULL;
}
static void
gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
{
- dest_value->data[0].v_int = src_value->data[0].v_int;
- dest_value->data[1].v_int = src_value->data[1].v_int;
+ gint *vals = (gint *) dest_value->data[0].v_pointer;
+ gint *src_vals = (gint *) src_value->data[0].v_pointer;
+
+ if (vals == NULL) {
+ gst_value_init_int_range (dest_value);
+ }
+ if (src_vals != NULL) {
+ INT_RANGE_MIN (dest_value) = INT_RANGE_MIN (src_value);
+ INT_RANGE_MAX (dest_value) = INT_RANGE_MAX (src_value);
+ INT_RANGE_STEP (dest_value) = INT_RANGE_STEP (src_value);
+ }
}
static gchar *
gst_value_collect_int_range (GValue * value, guint n_collect_values,
GTypeCValue * collect_values, guint collect_flags)
{
+ gint *vals = value->data[0].v_pointer;
+
if (n_collect_values != 2)
return g_strdup_printf ("not enough value locations for `%s' passed",
G_VALUE_TYPE_NAME (value));
return g_strdup_printf ("range start is not smaller than end for `%s'",
G_VALUE_TYPE_NAME (value));
- value->data[0].v_int = collect_values[0].v_int;
- value->data[1].v_int = collect_values[1].v_int;
+ if (vals == NULL) {
+ gst_value_init_int_range (value);
+ }
+
+ gst_value_set_int_range_step (value, collect_values[0].v_int,
+ collect_values[1].v_int, 1);
return NULL;
}
{
guint32 *int_range_start = collect_values[0].v_pointer;
guint32 *int_range_end = collect_values[1].v_pointer;
+ guint32 *int_range_step = collect_values[2].v_pointer;
+ gint *vals = (gint *) value->data[0].v_pointer;
if (!int_range_start)
return g_strdup_printf ("start value location for `%s' passed as NULL",
if (!int_range_end)
return g_strdup_printf ("end value location for `%s' passed as NULL",
G_VALUE_TYPE_NAME (value));
+ if (!int_range_step)
+ return g_strdup_printf ("step value location for `%s' passed as NULL",
+ G_VALUE_TYPE_NAME (value));
- *int_range_start = value->data[0].v_int;
- *int_range_end = value->data[1].v_int;
+ if (G_UNLIKELY (vals == NULL)) {
+ return g_strdup_printf ("Uninitialised `%s' passed",
+ G_VALUE_TYPE_NAME (value));
+ }
+
+ *int_range_start = INT_RANGE_MIN (value);
+ *int_range_end = INT_RANGE_MAX (value);
+ *int_range_step = INT_RANGE_STEP (value);
return NULL;
}
/**
- * gst_value_set_int_range:
+ * gst_value_set_int_range_step:
* @value: a GValue initialized to GST_TYPE_INT_RANGE
* @start: the start of the range
* @end: the end of the range
+ * @step: the step of the range
*
- * Sets @value to the range specified by @start and @end.
+ * Sets @value to the range specified by @start, @end and @step.
*/
void
-gst_value_set_int_range (GValue * value, gint start, gint end)
+gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
{
g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
g_return_if_fail (start < end);
+ g_return_if_fail (step > 0);
+ g_return_if_fail (start % step == 0);
+ g_return_if_fail (end % step == 0);
- value->data[0].v_int = start;
- value->data[1].v_int = end;
+ INT_RANGE_MIN (value) = start / step;
+ INT_RANGE_MAX (value) = end / step;
+ INT_RANGE_STEP (value) = step;
+}
+
+/**
+ * gst_value_set_int_range:
+ * @value: a GValue initialized to GST_TYPE_INT_RANGE
+ * @start: the start of the range
+ * @end: the end of the range
+ *
+ * Sets @value to the range specified by @start and @end.
+ */
+void
+gst_value_set_int_range (GValue * value, gint start, gint end)
+{
+ gst_value_set_int_range_step (value, start, end, 1);
}
/**
{
g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
- return value->data[0].v_int;
+ return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
}
/**
{
g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
- return value->data[1].v_int;
+ return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
+}
+
+/**
+ * gst_value_get_int_range_step:
+ * @value: a GValue initialized to GST_TYPE_INT_RANGE
+ *
+ * Gets the step of the range specified by @value.
+ *
+ * Returns: the step of the range
+ */
+gint
+gst_value_get_int_range_step (const GValue * value)
+{
+ g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
+
+ return INT_RANGE_STEP (value);
}
static void
gst_value_transform_int_range_string (const GValue * src_value,
GValue * dest_value)
{
- dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
- (int) src_value->data[0].v_int, (int) src_value->data[1].v_int);
+ if (INT_RANGE_STEP (src_value) == 1)
+ dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
+ INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
+ else
+ dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
+ INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
+ INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
+ INT_RANGE_STEP (src_value));
}
static gint
gst_value_compare_int_range (const GValue * value1, const GValue * value2)
{
- if (value2->data[0].v_int == value1->data[0].v_int &&
- value2->data[1].v_int == value1->data[1].v_int)
+ /* calculate the number of values in each range */
+ gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
+ gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
+
+ /* they must be equal */
+ if (n1 != n2)
+ return GST_VALUE_UNORDERED;
+
+ /* if empty, equal */
+ if (n1 == 0)
return GST_VALUE_EQUAL;
- return GST_VALUE_UNORDERED;
+
+ /* if more than one value, then it is only equal if the step is equal
+ and bounds lie on the same value */
+ if (n1 > 1) {
+ if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
+ INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
+ INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2)) {
+ return GST_VALUE_EQUAL;
+ }
+ return GST_VALUE_UNORDERED;
+ } else {
+ /* if just one, only if the value is equal */
+ if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
+ return GST_VALUE_EQUAL;
+ return GST_VALUE_UNORDERED;
+ }
}
static gchar *
gst_value_serialize_int_range (const GValue * value)
{
- return g_strdup_printf ("[ %d, %d ]", value->data[0].v_int,
- value->data[1].v_int);
+ if (INT_RANGE_STEP (value) == 1)
+ return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
+ INT_RANGE_MAX (value));
+ else
+ return g_strdup_printf ("[ %d, %d, %d ]",
+ INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
+ INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
}
static gboolean
/***************
* int64 range *
+ *
+ * Values in the range are defined as any value greater or equal
+ * to min*step, AND lesser or equal to max*step.
+ * For step == 1, this falls back to the traditional range semantics.
***************/
+#define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
+#define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
+#define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
+
static void
gst_value_init_int64_range (GValue * value)
{
- value->data[0].v_int64 = 0;
- value->data[1].v_int64 = 0;
+ gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
+ value->data[0].v_pointer = vals;
+ INT64_RANGE_MIN (value) = 0;
+ INT64_RANGE_MAX (value) = 0;
+ INT64_RANGE_STEP (value) = 1;
+}
+
+static void
+gst_value_free_int64_range (GValue * value)
+{
+ g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
+ g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
+ value->data[0].v_pointer = NULL;
}
static void
gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
{
- dest_value->data[0].v_int64 = src_value->data[0].v_int64;
- dest_value->data[1].v_int64 = src_value->data[1].v_int64;
+ gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
+ gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
+
+ if (vals == NULL) {
+ gst_value_init_int64_range (dest_value);
+ }
+
+ if (src_vals != NULL) {
+ INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
+ INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
+ INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
+ }
}
static gchar *
gst_value_collect_int64_range (GValue * value, guint n_collect_values,
GTypeCValue * collect_values, guint collect_flags)
{
+ gint64 *vals = value->data[0].v_pointer;
+
if (n_collect_values != 2)
return g_strdup_printf ("not enough value locations for `%s' passed",
G_VALUE_TYPE_NAME (value));
return g_strdup_printf ("range start is not smaller than end for `%s'",
G_VALUE_TYPE_NAME (value));
- value->data[0].v_int64 = collect_values[0].v_int64;
- value->data[1].v_int64 = collect_values[1].v_int64;
+ if (vals == NULL) {
+ gst_value_init_int64_range (value);
+ }
+
+ gst_value_set_int64_range_step (value, collect_values[0].v_int64,
+ collect_values[1].v_int64, 1);
return NULL;
}
{
guint64 *int_range_start = collect_values[0].v_pointer;
guint64 *int_range_end = collect_values[1].v_pointer;
+ guint64 *int_range_step = collect_values[2].v_pointer;
+ gint64 *vals = (gint64 *) value->data[0].v_pointer;
if (!int_range_start)
return g_strdup_printf ("start value location for `%s' passed as NULL",
if (!int_range_end)
return g_strdup_printf ("end value location for `%s' passed as NULL",
G_VALUE_TYPE_NAME (value));
+ if (!int_range_step)
+ return g_strdup_printf ("step value location for `%s' passed as NULL",
+ G_VALUE_TYPE_NAME (value));
- *int_range_start = value->data[0].v_int64;
- *int_range_end = value->data[1].v_int64;
+ if (G_UNLIKELY (vals == NULL)) {
+ return g_strdup_printf ("Uninitialised `%s' passed",
+ G_VALUE_TYPE_NAME (value));
+ }
+
+ *int_range_start = INT64_RANGE_MIN (value);
+ *int_range_end = INT64_RANGE_MAX (value);
+ *int_range_step = INT64_RANGE_STEP (value);
return NULL;
}
/**
+ * gst_value_set_int64_range_step:
+ * @value: a GValue initialized to GST_TYPE_INT64_RANGE
+ * @start: the start of the range
+ * @end: the end of the range
+ * @step: the step of the range
+ *
+ * Sets @value to the range specified by @start, @end and @step.
+ *
+ * Since: 0.11.0
+ */
+void
+gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
+ gint64 step)
+{
+ g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
+ g_return_if_fail (start < end);
+ g_return_if_fail (step > 0);
+ g_return_if_fail (start % step == 0);
+ g_return_if_fail (end % step == 0);
+
+ INT64_RANGE_MIN (value) = start / step;
+ INT64_RANGE_MAX (value) = end / step;
+ INT64_RANGE_STEP (value) = step;
+}
+
+/**
* gst_value_set_int64_range:
* @value: a GValue initialized to GST_TYPE_INT64_RANGE
* @start: the start of the range
void
gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
{
- g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
- g_return_if_fail (start < end);
-
- value->data[0].v_int64 = start;
- value->data[1].v_int64 = end;
+ gst_value_set_int64_range_step (value, start, end, 1);
}
/**
{
g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
- return value->data[0].v_int64;
+ return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
}
/**
{
g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
- return value->data[1].v_int64;
+ return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
+}
+
+/**
+ * gst_value_get_int64_range_step:
+ * @value: a GValue initialized to GST_TYPE_INT64_RANGE
+ *
+ * Gets the step of the range specified by @value.
+ *
+ * Returns: the step of the range
+ *
+ * Since: 0.11.0
+ */
+gint64
+gst_value_get_int64_range_step (const GValue * value)
+{
+ g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
+
+ return INT64_RANGE_STEP (value);
}
static void
gst_value_transform_int64_range_string (const GValue * src_value,
GValue * dest_value)
{
- dest_value->data[0].v_pointer =
- g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
- src_value->data[0].v_int64, src_value->data[1].v_int64);
+ if (INT64_RANGE_STEP (src_value) == 1)
+ dest_value->data[0].v_pointer =
+ g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
+ INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
+ else
+ dest_value->data[0].v_pointer =
+ g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
+ ",%" G_GINT64_FORMAT "]",
+ INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
+ INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
+ INT64_RANGE_STEP (src_value));
}
static gint
gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
{
- if (value2->data[0].v_int64 == value1->data[0].v_int64 &&
- value2->data[1].v_int64 == value1->data[1].v_int64)
+ /* calculate the number of values in each range */
+ gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
+ gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
+
+ /* they must be equal */
+ if (n1 != n2)
+ return GST_VALUE_UNORDERED;
+
+ /* if empty, equal */
+ if (n1 == 0)
return GST_VALUE_EQUAL;
- return GST_VALUE_UNORDERED;
+
+ /* if more than one value, then it is only equal if the step is equal
+ and bounds lie on the same value */
+ if (n1 > 1) {
+ if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
+ INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
+ INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2)) {
+ return GST_VALUE_EQUAL;
+ }
+ return GST_VALUE_UNORDERED;
+ } else {
+ /* if just one, only if the value is equal */
+ if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
+ return GST_VALUE_EQUAL;
+ return GST_VALUE_UNORDERED;
+ }
}
static gchar *
gst_value_serialize_int64_range (const GValue * value)
{
- return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
- value->data[0].v_int64, value->data[1].v_int64);
+ if (INT64_RANGE_STEP (value) == 1)
+ return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
+ INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
+ else
+ return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
+ G_GINT64_FORMAT " ]",
+ INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
+ INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
+ INT64_RANGE_STEP (value));
}
static gboolean
return FALSE;
}
+/**************
+ * GstSegment *
+ **************/
+static gchar *
+gst_value_serialize_segment (const GValue * value)
+{
+ GstSegment *seg = g_value_get_boxed (value);
+ gchar *t, *res;
+ GstStructure *s;
+
+ s = gst_structure_new ("GstSegment",
+ "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
+ "rate", G_TYPE_DOUBLE, seg->rate,
+ "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
+ "format", GST_TYPE_FORMAT, seg->format,
+ "base", G_TYPE_UINT64, seg->base,
+ "start", G_TYPE_UINT64, seg->start,
+ "stop", G_TYPE_UINT64, seg->stop,
+ "time", G_TYPE_UINT64, seg->time,
+ "position", G_TYPE_UINT64, seg->position,
+ "duration", G_TYPE_UINT64, seg->duration, NULL);
+ t = gst_structure_to_string (s);
+ res = g_strdup_printf ("\"%s\"", t);
+ g_free (t);
+ gst_structure_free (s);
+
+ return res;
+}
+
+static gboolean
+gst_value_deserialize_segment (GValue * dest, const gchar * s)
+{
+ GstStructure *str;
+ GstSegment seg;
+ gboolean res;
+
+ str = gst_structure_from_string (s, NULL);
+ if (str == NULL)
+ return FALSE;
+
+ res = gst_structure_get (str,
+ "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
+ "rate", G_TYPE_DOUBLE, &seg.rate,
+ "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
+ "format", GST_TYPE_FORMAT, &seg.format,
+ "base", G_TYPE_UINT64, &seg.base,
+ "start", G_TYPE_UINT64, &seg.start,
+ "stop", G_TYPE_UINT64, &seg.stop,
+ "time", G_TYPE_UINT64, &seg.time,
+ "position", G_TYPE_UINT64, &seg.position,
+ "duration", G_TYPE_UINT64, &seg.duration, NULL);
+ gst_structure_free (str);
+
+ if (res)
+ g_value_set_boxed (dest, &seg);
+
+ return res;
+}
+
/****************
* GstStructure *
****************/
GstBuffer *buf1 = gst_value_get_buffer (value1);
GstBuffer *buf2 = gst_value_get_buffer (value2);
gsize size1, size2;
- gpointer data1, data2;
+ GstMapInfo info1, info2;
gint result = GST_VALUE_UNORDERED;
size1 = gst_buffer_get_size (buf1);
if (size1 == 0)
return GST_VALUE_EQUAL;
- data1 = gst_buffer_map (buf1, &size1, NULL, GST_MAP_READ);
- data2 = gst_buffer_map (buf2, &size2, NULL, GST_MAP_READ);
- g_assert (data1);
- g_assert (data2);
+ if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
+ return GST_VALUE_UNORDERED;
- if (memcmp (data1, data2, size1) == 0)
+ if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
+ gst_buffer_unmap (buf1, &info2);
+ return GST_VALUE_UNORDERED;
+ }
+
+ if (memcmp (info1.data, info2.data, info1.size) == 0)
result = GST_VALUE_EQUAL;
- gst_buffer_unmap (buf2, data2, size2);
- gst_buffer_unmap (buf1, data1, size1);
+ gst_buffer_unmap (buf2, &info1);
+ gst_buffer_unmap (buf1, &info2);
return result;
}
static gchar *
gst_value_serialize_buffer (const GValue * value)
{
+ GstMapInfo info;
guint8 *data;
gint i;
- gsize size;
gchar *string;
GstBuffer *buffer;
if (buffer == NULL)
return NULL;
- data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
+ if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
+ return NULL;
+
+ data = info.data;
- string = g_malloc (size * 2 + 1);
- for (i = 0; i < size; i++) {
+ string = g_malloc (info.size * 2 + 1);
+ for (i = 0; i < info.size; i++) {
sprintf (string + i * 2, "%02x", data[i]);
}
- string[size * 2] = 0;
+ string[info.size * 2] = 0;
- gst_buffer_unmap (buffer, data, size);
+ gst_buffer_unmap (buffer, &info);
return string;
}
GstBuffer *buffer;
gint len;
gchar ts[3];
+ GstMapInfo info;
guint8 *data;
gint i;
- gsize size;
len = strlen (s);
if (len & 1)
goto wrong_length;
- buffer = gst_buffer_new_allocate (NULL, len / 2, 0);
- data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE);
+ buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
+ if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
+ goto map_failed;
+ data = info.data;
for (i = 0; i < len / 2; i++) {
if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
data[i] = (guint8) strtoul (ts, NULL, 16);
}
- gst_buffer_unmap (buffer, data, size);
+ gst_buffer_unmap (buffer, &info);
gst_value_take_buffer (dest, buffer);
{
return FALSE;
}
+map_failed:
+ {
+ return FALSE;
+ }
wrong_char:
{
gst_buffer_unref (buffer);
- gst_buffer_unmap (buffer, data, size);
+ gst_buffer_unmap (buffer, &info);
return FALSE;
}
}
return TRUE;
}
+/****************
+ * subset *
+ ****************/
+
+static gboolean
+gst_value_is_subset_int_range_int_range (const GValue * value1,
+ const GValue * value2)
+{
+ gint gcd;
+
+ g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
+ g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
+
+ if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
+ INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
+ return FALSE;
+ if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
+ INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
+ return FALSE;
+
+ if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
+ if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
+ INT_RANGE_STEP (value1))
+ return FALSE;
+ return TRUE;
+ }
+
+ gcd =
+ gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
+ INT_RANGE_STEP (value2));
+ if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean
+gst_value_is_subset_int64_range_int64_range (const GValue * value1,
+ const GValue * value2)
+{
+ gint64 gcd;
+
+ g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
+ g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
+
+ if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
+ return FALSE;
+ if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
+ return FALSE;
+
+ if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
+ if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
+ INT64_RANGE_STEP (value1))
+ return FALSE;
+ return TRUE;
+ }
+
+ gcd =
+ gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
+ INT64_RANGE_STEP (value2));
+ if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
+ return FALSE;
+
+ return TRUE;
+}
+
+/**
+ * gst_value_is_subset:
+ * @value1: a #GValue
+ * @value2: a #GValue
+ *
+ * Check that @value1 is a subset of @value2.
+ *
+ * Return: %TRUE is @value1 is a subset of @value2
+ */
+gboolean
+gst_value_is_subset (const GValue * value1, const GValue * value2)
+{
+ /* special case for int/int64 ranges, since we cannot compute
+ the difference for those when they have different steps,
+ and it's actually a lot simpler to compute whether a range
+ is a subset of another. */
+ if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
+ return gst_value_is_subset_int_range_int_range (value1, value2);
+ } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
+ && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
+ return gst_value_is_subset_int64_range_int64_range (value1, value2);
+ }
+
+ /*
+ * 1 - [1,2] = empty
+ * -> !subset
+ *
+ * [1,2] - 1 = 2
+ * -> 1 - [1,2] = empty
+ * -> subset
+ *
+ * [1,3] - [1,2] = 3
+ * -> [1,2] - [1,3] = empty
+ * -> subset
+ *
+ * {1,2} - {1,3} = 2
+ * -> {1,3} - {1,2} = 3
+ * -> !subset
+ *
+ * First caps subtraction needs to return a non-empty set, second
+ * subtractions needs to give en empty set.
+ * Both substractions are switched below, as it's faster that way.
+ */
+ if (!gst_value_subtract (NULL, value1, value2)) {
+ if (gst_value_subtract (NULL, value2, value1)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
/*********
* union *
*********/
gst_value_union_int_int_range (GValue * dest, const GValue * src1,
const GValue * src2)
{
- if (src2->data[0].v_int <= src1->data[0].v_int &&
- src2->data[1].v_int >= src1->data[0].v_int) {
- gst_value_init_and_copy (dest, src2);
+ gint v = src1->data[0].v_int;
+
+ /* check if it's already in the range */
+ if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
+ INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
+ v % INT_RANGE_STEP (src2) == 0) {
+ if (dest)
+ gst_value_init_and_copy (dest, src2);
return TRUE;
}
+
+ /* check if it extends the range */
+ if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
+ if (dest) {
+ gst_value_init_and_copy (dest, src2);
+ --INT_RANGE_MIN (src2);
+ }
+ return TRUE;
+ }
+ if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
+ if (dest) {
+ gst_value_init_and_copy (dest, src2);
+ ++INT_RANGE_MAX (src2);
+ }
+ return TRUE;
+ }
+
return FALSE;
}
gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
const GValue * src2)
{
- gint min;
- gint max;
-
- min = MAX (src1->data[0].v_int, src2->data[0].v_int);
- max = MIN (src1->data[1].v_int, src2->data[1].v_int);
+ /* We can union in several special cases:
+ 1 - one is a subset of another
+ 2 - same step and not disjoint
+ 3 - different step, at least one with one value which matches a 'next' or 'previous'
+ - anything else ?
+ */
- if (min <= max) {
- g_value_init (dest, GST_TYPE_INT_RANGE);
- gst_value_set_int_range (dest,
- MIN (src1->data[0].v_int, src2->data[0].v_int),
- MAX (src1->data[1].v_int, src2->data[1].v_int));
+ /* 1 - subset */
+ if (gst_value_is_subset_int_range_int_range (src1, src2)) {
+ if (dest)
+ gst_value_init_and_copy (dest, src2);
return TRUE;
}
+ if (gst_value_is_subset_int_range_int_range (src2, src1)) {
+ if (dest)
+ gst_value_init_and_copy (dest, src1);
+ return TRUE;
+ }
+
+ /* 2 - same step and not disjoint */
+ if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
+ if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
+ INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
+ (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
+ INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
+ if (dest) {
+ gint step = INT_RANGE_STEP (src1);
+ gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
+ gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
+ g_value_init (dest, GST_TYPE_INT_RANGE);
+ gst_value_set_int_range_step (dest, min, max, step);
+ }
+ return TRUE;
+ }
+ }
+ /* 3 - single value matches next or previous */
+ if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
+ gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
+ gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
+ if (n1 == 1 || n2 == 1) {
+ const GValue *range_value = NULL;
+ gint scalar = 0;
+ if (n1 == 1) {
+ range_value = src2;
+ scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
+ } else if (n2 == 1) {
+ range_value = src1;
+ scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
+ }
+
+ if (scalar ==
+ (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
+ if (dest) {
+ gst_value_init_and_copy (dest, range_value);
+ --INT_RANGE_MIN (range_value);
+ }
+ return TRUE;
+ } else if (scalar ==
+ (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
+ if (dest) {
+ gst_value_init_and_copy (dest, range_value);
+ ++INT_RANGE_MIN (range_value);
+ }
+ return TRUE;
+ }
+ }
+ }
+
+ /* If we get there, we did not find a way to make a union that can be
+ represented with our simplistic model. */
return FALSE;
}
gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
const GValue * src2)
{
- if (src2->data[0].v_int <= src1->data[0].v_int &&
- src2->data[1].v_int >= src1->data[0].v_int) {
+ if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
+ INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
+ src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
{
gint min;
gint max;
+ gint step;
+
+ step =
+ INT_RANGE_STEP (src1) /
+ gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
+ INT_RANGE_STEP (src2));
+ if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
+ return FALSE;
+ step *= INT_RANGE_STEP (src2);
- min = MAX (src1->data[0].v_int, src2->data[0].v_int);
- max = MIN (src1->data[1].v_int, src2->data[1].v_int);
+ min =
+ MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
+ INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
+ min = (min + step - 1) / step * step;
+ max =
+ MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
+ INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
+ max = max / step * step;
if (min < max) {
if (dest) {
g_value_init (dest, GST_TYPE_INT_RANGE);
- gst_value_set_int_range (dest, min, max);
+ gst_value_set_int_range_step (dest, min, max, step);
}
return TRUE;
}
gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
const GValue * src2)
{
- if (src2->data[0].v_int64 <= src1->data[0].v_int64 &&
- src2->data[1].v_int64 >= src1->data[0].v_int64) {
+ if (INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2) <= src1->data[0].v_int &&
+ INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2) >= src1->data[0].v_int &&
+ src1->data[0].v_int % INT64_RANGE_STEP (src2) == 0) {
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
{
gint64 min;
gint64 max;
+ gint64 step;
- min = MAX (src1->data[0].v_int64, src2->data[0].v_int64);
- max = MIN (src1->data[1].v_int64, src2->data[1].v_int64);
+ step =
+ INT64_RANGE_STEP (src1) /
+ gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
+ INT64_RANGE_STEP (src2));
+ if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
+ return FALSE;
+ step *= INT64_RANGE_STEP (src2);
+
+ min =
+ MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
+ INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
+ min = (min + step - 1) / step * step;
+ max =
+ MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
+ INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
+ max = max / step * step;
if (min < max) {
if (dest) {
g_value_init (dest, GST_TYPE_INT64_RANGE);
- gst_value_set_int64_range (dest, min, max);
+ gst_value_set_int64_range_step (dest, min, max, step);
}
return TRUE;
}
{
gint min = gst_value_get_int_range_min (subtrahend);
gint max = gst_value_get_int_range_max (subtrahend);
+ gint step = gst_value_get_int_range_step (subtrahend);
gint val = g_value_get_int (minuend);
/* subtracting a range from an int only works if the int is not in the
* range */
- if (val < min || val > max) {
+ if (val < min || val > max || val % step) {
/* and the result is the int */
if (dest)
gst_value_init_and_copy (dest, minuend);
*/
static gboolean
gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
- gint max2)
+ gint max2, gint step)
{
GValue v1 = { 0, };
GValue v2 = { 0, };
GValue *pv1, *pv2; /* yeah, hungarian! */
+ g_return_val_if_fail (step > 0, FALSE);
+ g_return_val_if_fail (min1 % step == 0, FALSE);
+ g_return_val_if_fail (max1 % step == 0, FALSE);
+ g_return_val_if_fail (min2 % step == 0, FALSE);
+ g_return_val_if_fail (max2 % step == 0, FALSE);
+
if (min1 <= max1 && min2 <= max2) {
pv1 = &v1;
pv2 = &v2;
if (min1 < max1) {
g_value_init (pv1, GST_TYPE_INT_RANGE);
- gst_value_set_int_range (pv1, min1, max1);
+ gst_value_set_int_range_step (pv1, min1, max1, step);
} else if (min1 == max1) {
g_value_init (pv1, G_TYPE_INT);
g_value_set_int (pv1, min1);
}
if (min2 < max2) {
g_value_init (pv2, GST_TYPE_INT_RANGE);
- gst_value_set_int_range (pv2, min2, max2);
+ gst_value_set_int_range_step (pv2, min2, max2, step);
} else if (min2 == max2) {
g_value_init (pv2, G_TYPE_INT);
g_value_set_int (pv2, min2);
{
gint min = gst_value_get_int_range_min (minuend);
gint max = gst_value_get_int_range_max (minuend);
+ gint step = gst_value_get_int_range_step (minuend);
gint val = g_value_get_int (subtrahend);
g_return_val_if_fail (min < max, FALSE);
/* value is outside of the range, return range unchanged */
- if (val < min || val > max) {
+ if (val < min || val > max || val % step) {
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
} else {
/* max must be MAXINT too as val <= max */
- if (val == G_MAXINT) {
- max--;
- val--;
+ if (val >= G_MAXINT - step + 1) {
+ max -= step;
+ val -= step;
}
/* min must be MININT too as val >= max */
- if (val == G_MININT) {
- min++;
- val++;
+ if (val <= G_MININT + step - 1) {
+ min += step;
+ val += step;
}
if (dest)
- gst_value_create_new_range (dest, min, val - 1, val + 1, max);
+ gst_value_create_new_range (dest, min, val - step, val + step, max, step);
}
return TRUE;
}
{
gint min1 = gst_value_get_int_range_min (minuend);
gint max1 = gst_value_get_int_range_max (minuend);
+ gint step1 = gst_value_get_int_range_step (minuend);
gint min2 = gst_value_get_int_range_min (subtrahend);
gint max2 = gst_value_get_int_range_max (subtrahend);
+ gint step2 = gst_value_get_int_range_step (subtrahend);
+ gint step;
- if (max2 == G_MAXINT && min2 == G_MININT) {
+ if (step1 != step2) {
+ /* ENOIMPL */
+ g_assert (FALSE);
return FALSE;
- } else if (max2 == G_MAXINT) {
- return gst_value_create_new_range (dest, min1, MIN (min2 - 1, max1), 1, 0);
- } else if (min2 == G_MININT) {
- return gst_value_create_new_range (dest, MAX (max2 + 1, min1), max1, 1, 0);
+ }
+ step = step1;
+
+ if (max2 >= max1 && min2 <= min1) {
+ return FALSE;
+ } else if (max2 >= max1) {
+ return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
+ step, 0, step);
+ } else if (min2 <= min1) {
+ return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
+ step, 0, step);
} else {
- return gst_value_create_new_range (dest, min1, MIN (min2 - 1, max1),
- MAX (max2 + 1, min1), max1);
+ return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
+ MAX (max2 + step, min1), max1, step);
}
}
{
gint64 min = gst_value_get_int64_range_min (subtrahend);
gint64 max = gst_value_get_int64_range_max (subtrahend);
+ gint64 step = gst_value_get_int64_range_step (subtrahend);
gint64 val = g_value_get_int64 (minuend);
/* subtracting a range from an int64 only works if the int64 is not in the
* range */
- if (val < min || val > max) {
+ if (val < min || val > max || val % step) {
/* and the result is the int64 */
if (dest)
gst_value_init_and_copy (dest, minuend);
*/
static gboolean
gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
- gint64 min2, gint64 max2)
+ gint64 min2, gint64 max2, gint64 step)
{
GValue v1 = { 0, };
GValue v2 = { 0, };
GValue *pv1, *pv2; /* yeah, hungarian! */
+ g_return_val_if_fail (step > 0, FALSE);
+ g_return_val_if_fail (min1 % step == 0, FALSE);
+ g_return_val_if_fail (max1 % step == 0, FALSE);
+ g_return_val_if_fail (min2 % step == 0, FALSE);
+ g_return_val_if_fail (max2 % step == 0, FALSE);
+
if (min1 <= max1 && min2 <= max2) {
pv1 = &v1;
pv2 = &v2;
if (min1 < max1) {
g_value_init (pv1, GST_TYPE_INT64_RANGE);
- gst_value_set_int64_range (pv1, min1, max1);
+ gst_value_set_int64_range_step (pv1, min1, max1, step);
} else if (min1 == max1) {
g_value_init (pv1, G_TYPE_INT64);
g_value_set_int64 (pv1, min1);
}
if (min2 < max2) {
g_value_init (pv2, GST_TYPE_INT64_RANGE);
- gst_value_set_int64_range (pv2, min2, max2);
+ gst_value_set_int64_range_step (pv2, min2, max2, step);
} else if (min2 == max2) {
g_value_init (pv2, G_TYPE_INT64);
g_value_set_int64 (pv2, min2);
{
gint64 min = gst_value_get_int64_range_min (minuend);
gint64 max = gst_value_get_int64_range_max (minuend);
+ gint64 step = gst_value_get_int64_range_step (minuend);
gint64 val = g_value_get_int64 (subtrahend);
g_return_val_if_fail (min < max, FALSE);
/* value is outside of the range, return range unchanged */
- if (val < min || val > max) {
+ if (val < min || val > max || val % step) {
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
} else {
/* max must be MAXINT64 too as val <= max */
- if (val == G_MAXINT64) {
- max--;
- val--;
+ if (val >= G_MAXINT64 - step + 1) {
+ max -= step;
+ val -= step;
}
/* min must be MININT64 too as val >= max */
- if (val == G_MININT64) {
- min++;
- val++;
+ if (val <= G_MININT64 + step - 1) {
+ min += step;
+ val += step;
}
if (dest)
- gst_value_create_new_int64_range (dest, min, val - 1, val + 1, max);
+ gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
+ step);
}
return TRUE;
}
{
gint64 min1 = gst_value_get_int64_range_min (minuend);
gint64 max1 = gst_value_get_int64_range_max (minuend);
+ gint64 step1 = gst_value_get_int64_range_step (minuend);
gint64 min2 = gst_value_get_int64_range_min (subtrahend);
gint64 max2 = gst_value_get_int64_range_max (subtrahend);
+ gint64 step2 = gst_value_get_int64_range_step (subtrahend);
+ gint64 step;
+
+ if (step1 != step2) {
+ /* ENOIMPL */
+ g_assert (FALSE);
+ return FALSE;
+ }
+ step = step1;
- if (max2 == G_MAXINT64 && min2 == G_MININT64) {
+ if (max2 >= max1 && min2 <= min1) {
return FALSE;
- } else if (max2 == G_MAXINT64) {
- return gst_value_create_new_int64_range (dest, min1, MIN (min2 - 1, max1),
- 1, 0);
- } else if (min2 == G_MININT64) {
- return gst_value_create_new_int64_range (dest, MAX (max2 + 1, min1), max1,
- 1, 0);
+ } else if (max2 >= max1) {
+ return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
+ max1), step, 0, step);
+ } else if (min2 <= min1) {
+ return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
+ max1, step, 0, step);
} else {
- return gst_value_create_new_int64_range (dest, min1, MIN (min2 - 1, max1),
- MAX (max2 + 1, min1), max1);
+ return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
+ max1), MAX (max2 + step, min1), max1, step);
}
}
if (CHECK_TYPES (INT, G)) {
const gint rmin = gst_value_get_int_range_min (value);
const gint rmax = gst_value_get_int_range_max (value);
+ const gint rstep = gst_value_get_int_range_step (value);
/* note: this will overflow for min 0 and max INT_MAX, but this
would only be equal to a list of INT_MAX elements, which seems
very unlikely */
- if (list_size != rmax - rmin + 1)
+ if (list_size != rmax / rstep - rmin / rstep + 1)
return FALSE;
for (n = 0; n < list_size; ++n) {
gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
- if (v < rmin || v > rmax) {
+ if (v < rmin || v > rmax || v % rstep) {
return FALSE;
}
}
} else if (CHECK_TYPES (INT64, G)) {
const gint64 rmin = gst_value_get_int64_range_min (value);
const gint64 rmax = gst_value_get_int64_range_max (value);
+ const gint64 rstep = gst_value_get_int64_range_step (value);
GST_DEBUG ("List/range of int64s");
- if (list_size != rmax - rmin + 1)
+ if (list_size != rmax / rstep - rmin / rstep + 1)
return FALSE;
for (n = 0; n < list_size; ++n) {
gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
- if (v < rmin || v > rmax)
+ if (v < rmin || v > rmax || v % rstep)
return FALSE;
}
return TRUE;
return TRUE;
}
-/**
- * gst_value_register_union_func: (skip)
+/* gst_value_register_union_func: (skip)
* @type1: a type to union
* @type2: another type to union
* @func: a function that implements creating a union between the two types
* started, as gst_value_register_union_func() is not thread-safe and cannot
* be used at the same time as gst_value_union() or gst_value_can_union().
*/
-void
+static void
gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
{
GstValueUnionInfo union_info;
-/**
- * gst_value_register_intersect_func: (skip)
+/* gst_value_register_intersect_func: (skip)
* @type1: the first type to intersect
* @type2: the second type to intersect
* @func: the intersection function
* cannot be used at the same time as gst_value_intersect() or
* gst_value_can_intersect().
*/
-void
+static void
gst_value_register_intersect_func (GType type1, GType type2,
GstValueIntersectFunc func)
{
return gst_value_can_compare (minuend, subtrahend);
}
-/**
- * gst_value_register_subtract_func: (skip)
+/* gst_value_register_subtract_func: (skip)
* @minuend_type: type of the minuend
* @subtrahend_type: type of the subtrahend
* @func: function to use
* started, as gst_value_register_subtract_func() is not thread-safe and
* cannot be used at the same time as gst_value_subtract().
*/
-void
+static void
gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
GstValueSubtractFunc func)
{
s1 = gst_value_get_bitmask (src1);
s2 = gst_value_get_bitmask (src2);
- g_value_init (dest, GST_TYPE_BITMASK);
- gst_value_set_bitmask (dest, s1 & s2);
+ if (dest) {
+ g_value_init (dest, GST_TYPE_BITMASK);
+ gst_value_set_bitmask (dest, s1 & s2);
+ }
return TRUE;
}
static const GTypeValueTable _gst_int_range_value_table = {
gst_value_init_int_range,
- NULL,
+ gst_value_free_int_range,
gst_value_copy_int_range,
NULL,
(char *) "ii",
static const GTypeValueTable _gst_int64_range_value_table = {
gst_value_init_int64_range,
- NULL,
+ gst_value_free_int64_range,
gst_value_copy_int64_range,
NULL,
(char *) "qq",
FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
-GType
-gst_date_time_get_type (void)
-{
- static GType gst_date_time_type = 0;
-
- if (G_UNLIKELY (gst_date_time_type == 0)) {
- gst_date_time_type = g_boxed_type_register_static ("GstDateTime",
- (GBoxedCopyFunc) gst_date_time_ref,
- (GBoxedFreeFunc) gst_date_time_unref);
- }
-
- return gst_date_time_type;
-}
+G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time,
+ (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref);
static const GTypeValueTable _gst_bitmask_value_table = {
gst_value_init_bitmask,
static GstValueTable gst_value = {
0,
NULL,
+ gst_value_serialize_segment,
+ gst_value_deserialize_segment,
+ };
+
+ gst_value.type = GST_TYPE_SEGMENT;
+ gst_value_register (&gst_value);
+ }
+ {
+ static GstValueTable gst_value = {
+ 0,
+ NULL,
gst_value_serialize_structure,
gst_value_deserialize_structure,
};