v4l2: Add protection when set decoder capture fps accroding to output fps
authorHou Qi <qi.hou@nxp.com>
Mon, 9 Aug 2021 02:46:30 +0000 (10:46 +0800)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 17 Aug 2021 13:27:28 +0000 (13:27 +0000)
Some v4l2 drivers don't have the capacity to change framerate. There is
chance to make decoder capture fps to be 0/0 if numerator and denominator
returned by G_PARM ioctl are both 0. It causes critical warning
"passed '0' as denominator for `GstFraction'".

In order to fix this, add protection when set decoder capture fps according
to output fps.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/1048>

sys/v4l2/gstv4l2object.c

index db60cbc..9851ffc 100644 (file)
@@ -2229,8 +2229,9 @@ gst_v4l2_object_get_streamparm (GstV4l2Object * v4l2object, GstVideoInfo * info)
     GST_WARNING_OBJECT (v4l2object->dbg_obj, "VIDIOC_G_PARM failed");
     return FALSE;
   }
-  if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
-      || v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+  if ((streamparm.parm.capture.timeperframe.numerator != 0)
+      && (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
+          || v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
     GST_VIDEO_INFO_FPS_N (info) =
         streamparm.parm.capture.timeperframe.denominator;
     GST_VIDEO_INFO_FPS_D (info) =
@@ -4239,7 +4240,8 @@ gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object, GstVideoInfo * info)
 
   gst_v4l2_object_get_colorspace (v4l2object, &fmt, &info->colorimetry);
   gst_v4l2_object_get_streamparm (v4l2object, info);
-  if ((info->fps_n == 0) && (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
+  if ((info->fps_n == 0 && v4l2object->info.fps_d != 0)
+      && (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
           || v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
     info->fps_d = v4l2object->info.fps_d;
     info->fps_n = v4l2object->info.fps_n;