mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
value: add function to fixate a value
Add a function to fixate a GValue. This is the same function as is in GstPad.
This commit is contained in:
parent
9553ea1c07
commit
e2b6e88d5f
2 changed files with 69 additions and 0 deletions
|
@ -4036,6 +4036,73 @@ gst_value_is_fixed (const GValue * value)
|
|||
return gst_type_is_fixed (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_value_fixate:
|
||||
* @dest: the #GValue destination
|
||||
* @src: the #GValue to fixate
|
||||
*
|
||||
* Fixate @src into a new value @dest.
|
||||
* For ranges, the first element is taken. For lists and arrays, the
|
||||
* first item is fixated and returned.
|
||||
* If @src is already fixed, this function returns FALSE.
|
||||
*
|
||||
* Returns: true if @dest contains a fixated version of @src.
|
||||
*/
|
||||
gboolean
|
||||
gst_value_fixate (GValue * dest, const GValue * src)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_VALUE (src), FALSE);
|
||||
g_return_val_if_fail (dest != NULL, FALSE);
|
||||
|
||||
if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
|
||||
g_value_init (dest, G_TYPE_INT);
|
||||
g_value_set_int (dest, gst_value_get_int_range_min (src));
|
||||
} else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
|
||||
g_value_init (dest, G_TYPE_DOUBLE);
|
||||
g_value_set_double (dest, gst_value_get_double_range_min (src));
|
||||
} else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
|
||||
gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
|
||||
} else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
|
||||
GValue temp = { 0 };
|
||||
|
||||
/* list could be empty */
|
||||
if (gst_value_list_get_size (src) <= 0)
|
||||
return FALSE;
|
||||
|
||||
gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
|
||||
|
||||
if (!gst_value_fixate (dest, &temp))
|
||||
gst_value_init_and_copy (dest, &temp);
|
||||
g_value_unset (&temp);
|
||||
} else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
|
||||
gboolean res = FALSE;
|
||||
guint n, len;
|
||||
|
||||
len = gst_value_array_get_size (src);
|
||||
g_value_init (dest, GST_TYPE_ARRAY);
|
||||
for (n = 0; n < len; n++) {
|
||||
GValue kid = { 0 };
|
||||
const GValue *orig_kid = gst_value_array_get_value (src, n);
|
||||
|
||||
if (!gst_value_fixate (&kid, orig_kid))
|
||||
gst_value_init_and_copy (&kid, orig_kid);
|
||||
else
|
||||
res = TRUE;
|
||||
gst_value_array_append_value (dest, &kid);
|
||||
g_value_unset (&kid);
|
||||
}
|
||||
|
||||
if (!res)
|
||||
g_value_unset (dest);
|
||||
|
||||
return res;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/************
|
||||
* fraction *
|
||||
************/
|
||||
|
|
|
@ -590,6 +590,8 @@ void gst_value_register_subtract_func (GType minuend_type,
|
|||
|
||||
/* fixation */
|
||||
gboolean gst_value_is_fixed (const GValue *value);
|
||||
gboolean gst_value_fixate (GValue *dest,
|
||||
const GValue *src);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
Loading…
Reference in a new issue