v4l2src: Use fraction compare util function.
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Sun, 7 Aug 2011 10:23:26 +0000 (12:23 +0200)
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>
Sun, 7 Aug 2011 14:41:53 +0000 (16:41 +0200)
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

sys/v4l2/v4l2src_calls.c

index fb6c374..9627dfa 100644 (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():
  *   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 */
-  if (fractions_are_equal (stream.parm.capture.timeperframe.numerator,
-          stream.parm.capture.timeperframe.denominator, fps_d, fps_n)) {
+  if (gst_util_fraction_compare (stream.parm.capture.timeperframe.numerator,
+          stream.parm.capture.timeperframe.denominator, fps_d, fps_n) == 0) {
+
     GST_DEBUG_OBJECT (v4l2src, "Desired framerate already set");
     goto already_set;
   }