Merge branch 'master' into 0.11

Conflicts:
	gst/gstvalue.c
This commit is contained in:
Wim Taymans 2011-11-07 17:17:39 +01:00
commit c9a4037805
3 changed files with 131 additions and 58 deletions

View file

@ -1292,7 +1292,7 @@ gst_caps_intersect_zig_zag (const GstCaps * caps1, const GstCaps * caps2)
static GstCaps *
gst_caps_intersect_first (const GstCaps * caps1, const GstCaps * caps2)
{
guint64 i; /* index can be up to 2 * G_MAX_UINT */
guint i;
guint j, len1, len2;
GstStructure *struct1;

View file

@ -3078,10 +3078,7 @@ gst_caps_structure_can_intersect_field (GQuark id, const GValue * val1,
if (eq == GST_VALUE_UNORDERED) {
/* we need to try interseting */
GValue dest_value = { 0 };
if (gst_value_intersect (&dest_value, val1, val2)) {
g_value_unset (&dest_value);
} else {
if (!gst_value_intersect (NULL, val1, val2)) {
return FALSE;
}
} else if (eq != GST_VALUE_EQUAL) {
@ -3115,11 +3112,8 @@ gst_structure_can_intersect (const GstStructure * struct1,
return FALSE;
/* tries to intersect if we have the field in both */
if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct1,
gst_caps_structure_can_intersect_field, (gpointer) struct2)))
return FALSE;
return TRUE;
return gst_structure_foreach ((GstStructure *) struct1,
gst_caps_structure_can_intersect_field, (gpointer) struct2);
}
static gboolean
@ -3127,17 +3121,23 @@ gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value,
gpointer user_data)
{
GstStructure *superset = user_data;
GValue subtraction = { 0, };
const GValue *other;
int comparison;
if (!(other = gst_structure_id_get_value (superset, field_id)))
/* field is missing in the superset => is subset */
return TRUE;
comparison = gst_value_compare (other, value);
/* equal values are subset */
if (gst_value_compare (other, value) == GST_VALUE_EQUAL)
if (comparison == GST_VALUE_EQUAL)
return TRUE;
/* ordered, but unequal, values are not */
if (comparison != GST_VALUE_UNORDERED)
return FALSE;
/*
* 1 - [1,2] = empty
* -> !subset
@ -3156,14 +3156,12 @@ gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value,
*
* 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 (&subtraction, other, value)) {
g_value_unset (&subtraction);
/* !empty result, swapping must be empty */
if (!gst_value_subtract (&subtraction, value, other))
if (!gst_value_subtract (NULL, value, other)) {
if (gst_value_subtract (NULL, other, value)) {
return TRUE;
g_value_unset (&subtraction);
}
}
return FALSE;
}

View file

@ -2474,7 +2474,8 @@ gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
{
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, src1);
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
}
@ -2492,13 +2493,17 @@ gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
max = MIN (src1->data[1].v_int, src2->data[1].v_int);
if (min < max) {
g_value_init (dest, GST_TYPE_INT_RANGE);
gst_value_set_int_range (dest, min, max);
if (dest) {
g_value_init (dest, GST_TYPE_INT_RANGE);
gst_value_set_int_range (dest, min, max);
}
return TRUE;
}
if (min == max) {
g_value_init (dest, G_TYPE_INT);
g_value_set_int (dest, min);
if (dest) {
g_value_init (dest, G_TYPE_INT);
g_value_set_int (dest, min);
}
return TRUE;
}
@ -2511,7 +2516,8 @@ gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
{
if (src2->data[0].v_int64 <= src1->data[0].v_int64 &&
src2->data[1].v_int64 >= src1->data[0].v_int64) {
gst_value_init_and_copy (dest, src1);
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
}
@ -2529,13 +2535,17 @@ gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
max = MIN (src1->data[1].v_int64, src2->data[1].v_int64);
if (min < max) {
g_value_init (dest, GST_TYPE_INT64_RANGE);
gst_value_set_int64_range (dest, min, max);
if (dest) {
g_value_init (dest, GST_TYPE_INT64_RANGE);
gst_value_set_int64_range (dest, min, max);
}
return TRUE;
}
if (min == max) {
g_value_init (dest, G_TYPE_INT64);
g_value_set_int64 (dest, min);
if (dest) {
g_value_init (dest, G_TYPE_INT64);
g_value_set_int64 (dest, min);
}
return TRUE;
}
@ -2548,7 +2558,8 @@ gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
{
if (src2->data[0].v_double <= src1->data[0].v_double &&
src2->data[1].v_double >= src1->data[0].v_double) {
gst_value_init_and_copy (dest, src1);
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
}
@ -2566,13 +2577,17 @@ gst_value_intersect_double_range_double_range (GValue * dest,
max = MIN (src1->data[1].v_double, src2->data[1].v_double);
if (min < max) {
g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
gst_value_set_double_range (dest, min, max);
if (dest) {
g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
gst_value_set_double_range (dest, min, max);
}
return TRUE;
}
if (min == max) {
g_value_init (dest, G_TYPE_DOUBLE);
g_value_set_int (dest, (int) min);
if (dest) {
g_value_init (dest, G_TYPE_DOUBLE);
g_value_set_int (dest, (int) min);
}
return TRUE;
}
@ -2591,6 +2606,15 @@ gst_value_intersect_list (GValue * dest, const GValue * value1,
for (i = 0; i < size; i++) {
const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
/* quicker version when we don't need the resulting set */
if (!dest) {
if (gst_value_intersect (NULL, cur, value2)) {
ret = TRUE;
break;
}
continue;
}
if (gst_value_intersect (&intersection, cur, value2)) {
/* append value */
if (!ret) {
@ -2625,6 +2649,18 @@ gst_value_intersect_array (GValue * dest, const GValue * src1,
size = gst_value_array_get_size (src1);
if (size != gst_value_array_get_size (src2))
return FALSE;
/* quicker value when we don't need the resulting set */
if (!dest) {
for (n = 0; n < size; n++) {
if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
gst_value_array_get_value (src2, n))) {
return FALSE;
}
}
return TRUE;
}
g_value_init (dest, GST_TYPE_ARRAY);
for (n = 0; n < size; n++) {
@ -2659,7 +2695,8 @@ gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
(res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
gst_value_init_and_copy (dest, src1);
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
}
}
@ -2701,14 +2738,17 @@ gst_value_intersect_fraction_range_fraction_range (GValue * dest,
res = gst_value_compare_with_func (min, max, compare);
g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
if (res == GST_VALUE_LESS_THAN) {
g_value_init (dest, GST_TYPE_FRACTION_RANGE);
vals1 = dest->data[0].v_pointer;
g_value_copy (min, &vals1[0]);
g_value_copy (max, &vals1[1]);
if (dest) {
g_value_init (dest, GST_TYPE_FRACTION_RANGE);
vals1 = dest->data[0].v_pointer;
g_value_copy (min, &vals1[0]);
g_value_copy (max, &vals1[1]);
}
return TRUE;
}
if (res == GST_VALUE_EQUAL) {
gst_value_init_and_copy (dest, min);
if (dest)
gst_value_init_and_copy (dest, min);
return TRUE;
}
}
@ -2732,7 +2772,8 @@ gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
* range */
if (val < min || val > max) {
/* and the result is the int */
gst_value_init_and_copy (dest, minuend);
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
}
return FALSE;
@ -2761,6 +2802,9 @@ gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
return FALSE;
}
if (!dest)
return TRUE;
if (min1 < max1) {
g_value_init (pv1, GST_TYPE_INT_RANGE);
gst_value_set_int_range (pv1, min1, max1);
@ -2796,7 +2840,8 @@ gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
/* value is outside of the range, return range unchanged */
if (val < min || val > max) {
gst_value_init_and_copy (dest, minuend);
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
} else {
/* max must be MAXINT too as val <= max */
@ -2809,7 +2854,8 @@ gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
min++;
val++;
}
gst_value_create_new_range (dest, min, val - 1, val + 1, max);
if (dest)
gst_value_create_new_range (dest, min, val - 1, val + 1, max);
}
return TRUE;
}
@ -2847,7 +2893,8 @@ gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
* range */
if (val < min || val > max) {
/* and the result is the int64 */
gst_value_init_and_copy (dest, minuend);
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
}
return FALSE;
@ -2876,6 +2923,9 @@ gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
return FALSE;
}
if (!dest)
return TRUE;
if (min1 < max1) {
g_value_init (pv1, GST_TYPE_INT64_RANGE);
gst_value_set_int64_range (pv1, min1, max1);
@ -2911,7 +2961,8 @@ gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
/* value is outside of the range, return range unchanged */
if (val < min || val > max) {
gst_value_init_and_copy (dest, minuend);
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
} else {
/* max must be MAXINT64 too as val <= max */
@ -2924,7 +2975,8 @@ gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
min++;
val++;
}
gst_value_create_new_int64_range (dest, min, val - 1, val + 1, max);
if (dest)
gst_value_create_new_int64_range (dest, min, val - 1, val + 1, max);
}
return TRUE;
}
@ -2961,7 +3013,8 @@ gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
gdouble val = g_value_get_double (minuend);
if (val < min || val > max) {
gst_value_init_and_copy (dest, minuend);
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
}
return FALSE;
@ -2973,7 +3026,8 @@ gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
{
/* since we don't have open ranges, we cannot create a hole in
* a double range. We return the original range */
gst_value_init_and_copy (dest, minuend);
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
}
@ -3004,6 +3058,9 @@ gst_value_subtract_double_range_double_range (GValue * dest,
return FALSE;
}
if (!dest)
return TRUE;
if (min1 < max1) {
g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
gst_value_set_double_range (pv1, min1, max1);
@ -3036,6 +3093,15 @@ gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
for (i = 0; i < size; i++) {
const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
/* quicker version when we can discard the result */
if (!dest) {
if (gst_value_subtract (NULL, cur, subtrahend)) {
ret = TRUE;
break;
}
continue;
}
if (gst_value_subtract (&subtraction, cur, subtrahend)) {
if (!ret) {
gst_value_init_and_copy (dest, &subtraction);
@ -3081,7 +3147,8 @@ gst_value_subtract_list (GValue * dest, const GValue * minuend,
return FALSE;
}
}
gst_value_init_and_copy (dest, result);
if (dest)
gst_value_init_and_copy (dest, result);
g_value_unset (result);
return TRUE;
}
@ -3102,7 +3169,8 @@ gst_value_subtract_fraction_fraction_range (GValue * dest,
gst_value_compare_with_func (minuend, max, compare) ==
GST_VALUE_GREATER_THAN) {
/* and the result is the value */
gst_value_init_and_copy (dest, minuend);
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
}
}
@ -3115,7 +3183,8 @@ gst_value_subtract_fraction_range_fraction (GValue * dest,
{
/* since we don't have open ranges, we cannot create a hole in
* a range. We return the original range */
gst_value_init_and_copy (dest, minuend);
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
}
@ -3166,6 +3235,9 @@ gst_value_subtract_fraction_range_fraction_range (GValue * dest,
return FALSE;
}
if (!dest)
return TRUE;
if (cmp1 == GST_VALUE_LESS_THAN) {
g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
gst_value_set_fraction_range (pv1, min1, max1);
@ -3489,14 +3561,14 @@ gst_value_can_intersect (const GValue * value1, const GValue * value2)
/**
* gst_value_intersect:
* @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
* intersection value
* intersection value. May be NULL if the resulting set if not needed.
* @value1: a value to intersect
* @value2: another value to intersect
*
* Calculates the intersection of two values. If the values have
* a non-empty intersection, the value representing the intersection
* is placed in @dest. If the intersection is non-empty, @dest is
* not modified.
* is placed in @dest, unless NULL. If the intersection is non-empty,
* @dest is not modified.
*
* Returns: TRUE if the intersection is non-empty
*/
@ -3508,7 +3580,6 @@ gst_value_intersect (GValue * dest, const GValue * value1,
guint i, len;
GType ltype, type1, type2;
g_return_val_if_fail (dest != NULL, FALSE);
g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
@ -3521,7 +3592,8 @@ gst_value_intersect (GValue * dest, const GValue * value1,
return gst_value_intersect_list (dest, value2, value1);
if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
gst_value_init_and_copy (dest, value1);
if (dest)
gst_value_init_and_copy (dest, value1);
return TRUE;
}
@ -3542,6 +3614,8 @@ gst_value_intersect (GValue * dest, const GValue * value1,
return FALSE;
}
/**
* gst_value_register_intersect_func: (skip)
* @type1: the first type to intersect
@ -3575,7 +3649,8 @@ gst_value_register_intersect_func (GType type1, GType type2,
/**
* gst_value_subtract:
* @dest: (out caller-allocates): the destination value for the result if the
* subtraction is not empty
* subtraction is not empty. May be NULL, in which case the resulting set
* will not be computed, which can give a fair speedup.
* @minuend: the value to subtract from
* @subtrahend: the value to subtract
*
@ -3592,7 +3667,6 @@ gst_value_subtract (GValue * dest, const GValue * minuend,
guint i, len;
GType ltype, mtype, stype;
g_return_val_if_fail (dest != NULL, FALSE);
g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
@ -3616,7 +3690,8 @@ gst_value_subtract (GValue * dest, const GValue * minuend,
}
if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
gst_value_init_and_copy (dest, minuend);
if (dest)
gst_value_init_and_copy (dest, minuend);
return TRUE;
}