mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 02:01:12 +00:00
gst/gststructure.c: Fix fraction list fixation code. Take the fraction with the smallest difference with the target i...
Original commit message from CVS: * gst/gststructure.c: (gst_structure_fixate_field_nearest_fraction): Fix fraction list fixation code. Take the fraction with the smallest difference with the target instead of the first one in the list. * tests/check/gst/gststructure.c: (GST_START_TEST), (gst_structure_suite): Added test to verify correct fraction list fixation behaviour.
This commit is contained in:
parent
b4136f995e
commit
a0274c10a7
3 changed files with 62 additions and 13 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2007-09-04 Wim Taymans <wim.taymans@gmail.com>
|
||||
|
||||
* gst/gststructure.c:
|
||||
(gst_structure_fixate_field_nearest_fraction):
|
||||
Fix fraction list fixation code. Take the fraction with the smallest
|
||||
difference with the target instead of the first one in the list.
|
||||
|
||||
* tests/check/gst/gststructure.c: (GST_START_TEST),
|
||||
(gst_structure_suite):
|
||||
Added test to verify correct fraction list fixation behaviour.
|
||||
|
||||
2007-09-02 Tim-Philipp Müller <tim at centricular dot net>
|
||||
|
||||
* win32/common/libgstreamer.def:
|
||||
|
|
|
@ -2167,23 +2167,23 @@ gst_structure_fixate_field_nearest_fraction (GstStructure * structure,
|
|||
|
||||
gst_value_set_fraction (&target, target_numerator, target_denominator);
|
||||
|
||||
best = NULL;
|
||||
|
||||
n = gst_value_list_get_size (value);
|
||||
for (i = 0; i < n; i++) {
|
||||
list_value = gst_value_list_get_value (value, i);
|
||||
if (G_VALUE_TYPE (list_value) == GST_TYPE_FRACTION) {
|
||||
if (best == NULL) {
|
||||
best = list_value;
|
||||
gst_value_set_fraction (&best_diff, 0, 1);
|
||||
} else {
|
||||
if (gst_value_compare (list_value, &target) == GST_VALUE_LESS_THAN)
|
||||
gst_value_fraction_subtract (&cur_diff, &target, list_value);
|
||||
else
|
||||
gst_value_fraction_subtract (&cur_diff, list_value, &target);
|
||||
|
||||
if (gst_value_compare (&cur_diff, &best_diff) == GST_VALUE_LESS_THAN) {
|
||||
best = list_value;
|
||||
g_value_copy (&cur_diff, &best_diff);
|
||||
}
|
||||
if (gst_value_compare (list_value, &target) == GST_VALUE_LESS_THAN)
|
||||
gst_value_fraction_subtract (&cur_diff, &target, list_value);
|
||||
else
|
||||
gst_value_fraction_subtract (&cur_diff, list_value, &target);
|
||||
|
||||
if (!best
|
||||
|| gst_value_compare (&cur_diff,
|
||||
&best_diff) == GST_VALUE_LESS_THAN) {
|
||||
best = list_value;
|
||||
g_value_copy (&cur_diff, &best_diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2196,6 +2196,5 @@ gst_structure_fixate_field_nearest_fraction (GstStructure * structure,
|
|||
g_value_unset (&target);
|
||||
return res;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -204,6 +204,44 @@ GST_START_TEST (test_fixate)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_fixate_frac_list)
|
||||
{
|
||||
GstStructure *s;
|
||||
GValue list = { 0 };
|
||||
GValue frac = { 0 };
|
||||
gchar *str;
|
||||
gint num, denom;
|
||||
|
||||
g_value_init (&list, GST_TYPE_LIST);
|
||||
g_value_init (&frac, GST_TYPE_FRACTION);
|
||||
|
||||
gst_value_set_fraction (&frac, 30, 1);
|
||||
gst_value_list_append_value (&list, &frac);
|
||||
gst_value_set_fraction (&frac, 15, 1);
|
||||
gst_value_list_append_value (&list, &frac);
|
||||
gst_value_set_fraction (&frac, 10, 1);
|
||||
gst_value_list_append_value (&list, &frac);
|
||||
|
||||
s = gst_structure_new ("name", NULL);
|
||||
gst_structure_set_value (s, "frac", &list);
|
||||
g_value_unset (&frac);
|
||||
g_value_unset (&list);
|
||||
|
||||
str = gst_structure_to_string (s);
|
||||
GST_DEBUG ("list %s", str);
|
||||
g_free (str);
|
||||
|
||||
/* fixate to the nearest fraction, this should give 15/1 */
|
||||
fail_unless (gst_structure_fixate_field_nearest_fraction (s, "frac", 14, 1));
|
||||
|
||||
fail_unless (gst_structure_get_fraction (s, "frac", &num, &denom));
|
||||
fail_unless (num == 15);
|
||||
fail_unless (denom == 1);
|
||||
|
||||
gst_structure_free (s);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_structure_suite (void)
|
||||
|
@ -217,6 +255,7 @@ gst_structure_suite (void)
|
|||
tcase_add_test (tc_chain, test_complete_structure);
|
||||
tcase_add_test (tc_chain, test_structure_new);
|
||||
tcase_add_test (tc_chain, test_fixate);
|
||||
tcase_add_test (tc_chain, test_fixate_frac_list);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue