v4l2: fix division by 0 for complex video formats
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 17 Jan 2018 10:10:37 +0000 (11:10 +0100)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 17 Jan 2018 18:32:58 +0000 (13:32 -0500)
So complex video formats have 0 as pstride. Don't try to divide the
stride in such cases.

https://bugzilla.gnome.org/show_bug.cgi?id=792596

sys/v4l2/gstv4l2object.c

index 995c719..a5e6707 100644 (file)
@@ -3022,7 +3022,7 @@ gst_v4l2_object_save_format (GstV4l2Object * v4l2object,
 {
   const GstVideoFormatInfo *finfo = info->finfo;
   gboolean standard_stride = TRUE;
-  gint stride, padded_width, padded_height, i;
+  gint stride, pstride, padded_width, padded_height, i;
 
   if (GST_VIDEO_INFO_FORMAT (info) == GST_VIDEO_FORMAT_ENCODED) {
     v4l2object->n_v4l2_planes = 1;
@@ -3036,7 +3036,16 @@ gst_v4l2_object_save_format (GstV4l2Object * v4l2object,
   else
     stride = format->fmt.pix.bytesperline;
 
-  padded_width = stride / GST_VIDEO_FORMAT_INFO_PSTRIDE (finfo, 0);
+  pstride = GST_VIDEO_FORMAT_INFO_PSTRIDE (finfo, 0);
+  if (pstride) {
+    padded_width = stride / pstride;
+  } else {
+    /* pstride can be 0 for complex formats */
+    GST_WARNING_OBJECT (v4l2object->element,
+        "format %s has a pstride of 0, cannot compute padded with",
+        gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (info)));
+    padded_width = stride;
+  }
 
   if (padded_width < format->fmt.pix.width)
     GST_WARNING_OBJECT (v4l2object->dbg_obj,