- } else { /* seems no point in SET, if can't get GET */
- /* Note: V4L2 gives us the frame interval, we need the frame rate */
- stream.parm.capture.timeperframe.numerator = fps_d;
- stream.parm.capture.timeperframe.denominator = fps_n;
-
- if (ioctl (fd, VIDIOC_S_PARM, &stream) < 0) {
- GST_ELEMENT_WARNING (v4l2src, RESOURCE, SETTINGS,
- (_("Could not set parameters on device '%s'"),
- v4l2src->v4l2object->videodev), GST_ERROR_SYSTEM);
-
- /* FIXME: better test for fraction equality */
- if (stream.parm.capture.timeperframe.numerator != fps_d
- || stream.parm.capture.timeperframe.denominator != fps_n)
- goto invalid_framerate;
- }
+ goto done;
+ }
+
+ /* 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)) {
+ GST_LOG_OBJECT (v4l2src, "Desired framerate already set, nothing to do");
+ goto done;
+ }
+
+ /* We want to change the frame rate, so check whether we can. Some cheap USB
+ * cameras don't have the capability */
+ if ((stream.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
+ GST_DEBUG_OBJECT (v4l2src, "Not setting framerate (not supported)");
+ goto done;
+ }
+
+ GST_LOG_OBJECT (v4l2src, "Setting framerate to %u/%u", fps_n, fps_d);
+
+ /* Note: V4L2 wants the frame interval, we have the frame rate */
+ stream.parm.capture.timeperframe.numerator = fps_d;
+ stream.parm.capture.timeperframe.denominator = fps_n;