v4l2src: Use fraction compare util function.

Use the fraction compare utility to compare function, not the
handcrafted one. The handcrafted one is buggy as it doesn't take into
account rounding error. For example comparing a framerate of 20/1 on a
camera configured as 30/1 fps would yield true: 1 == (1 * 20)/30 and not
re-configure the camera. Fixes #656104
This commit is contained in:
Sjoerd Simons 2011-08-07 12:23:26 +02:00
parent 1438bf26ac
commit 8edb15d12f

View file

@ -202,11 +202,6 @@ too_many_trials:
} }
} }
/* Note about fraction simplification
* n1/d1 == n2/d2 is also written as n1 == ( n2 * d1 ) / d2
*/
#define fractions_are_equal(n1,d1,n2,d2) ((n1) == gst_util_uint64_scale_int((n2), (d1), (d2)))
/****************************************************** /******************************************************
* gst_v4l2src_set_capture(): * gst_v4l2src_set_capture():
* set capture parameters * set capture parameters
@ -242,8 +237,9 @@ gst_v4l2src_set_capture (GstV4l2Src * v4l2src, guint32 pixelformat,
} }
/* Note: V4L2 provides the frame interval, we have the frame rate */ /* Note: V4L2 provides the frame interval, we have the frame rate */
if (fractions_are_equal (stream.parm.capture.timeperframe.numerator, if (gst_util_fraction_compare (stream.parm.capture.timeperframe.numerator,
stream.parm.capture.timeperframe.denominator, fps_d, fps_n)) { stream.parm.capture.timeperframe.denominator, fps_d, fps_n) == 0) {
GST_DEBUG_OBJECT (v4l2src, "Desired framerate already set"); GST_DEBUG_OBJECT (v4l2src, "Desired framerate already set");
goto already_set; goto already_set;
} }