media: vivid: fix wrong sizeimage value for mplane
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Wed, 26 Jun 2024 10:59:13 +0000 (12:59 +0200)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Wed, 26 Jun 2024 15:28:31 +0000 (17:28 +0200)
In several places a division by fmt->vdownsampling[p] was
missing in the sizeimage[p] calculation, causing incorrect
behavior for multiplanar formats were some planes are smaller
than the first plane.

Found by new v4l2-compliance tests.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/test-drivers/vivid/vivid-vid-cap.c
drivers/media/test-drivers/vivid/vivid-vid-out.c

index 2804975fe2787454808ff774e8859cdae3bbd175..3a3041a0378f1f9b276cebb1ca5cc86c7e3de811 100644 (file)
@@ -106,8 +106,9 @@ static int vid_cap_queue_setup(struct vb2_queue *vq,
                if (*nplanes != buffers)
                        return -EINVAL;
                for (p = 0; p < buffers; p++) {
-                       if (sizes[p] < tpg_g_line_width(&dev->tpg, p) * h +
-                                               dev->fmt_cap->data_offset[p])
+                       if (sizes[p] < tpg_g_line_width(&dev->tpg, p) * h /
+                                       dev->fmt_cap->vdownsampling[p] +
+                                       dev->fmt_cap->data_offset[p])
                                return -EINVAL;
                }
        } else {
index 1653b2988f7e351313e439bee6303c4a27c97d4e..7a0f4c61ac807781190930544c3335ceaebbf675 100644 (file)
@@ -63,14 +63,16 @@ static int vid_out_queue_setup(struct vb2_queue *vq,
                if (sizes[0] < size)
                        return -EINVAL;
                for (p = 1; p < planes; p++) {
-                       if (sizes[p] < dev->bytesperline_out[p] * h +
-                                      vfmt->data_offset[p])
+                       if (sizes[p] < dev->bytesperline_out[p] * h /
+                                       vfmt->vdownsampling[p] +
+                                       vfmt->data_offset[p])
                                return -EINVAL;
                }
        } else {
                for (p = 0; p < planes; p++)
-                       sizes[p] = p ? dev->bytesperline_out[p] * h +
-                                      vfmt->data_offset[p] : size;
+                       sizes[p] = p ? dev->bytesperline_out[p] * h /
+                                       vfmt->vdownsampling[p] +
+                                       vfmt->data_offset[p] : size;
        }
 
        *nplanes = planes;
@@ -124,7 +126,7 @@ static int vid_out_buf_prepare(struct vb2_buffer *vb)
 
        for (p = 0; p < planes; p++) {
                if (p)
-                       size = dev->bytesperline_out[p] * h;
+                       size = dev->bytesperline_out[p] * h / vfmt->vdownsampling[p];
                size += vb->planes[p].data_offset;
 
                if (vb2_get_plane_payload(vb, p) < size) {
@@ -331,8 +333,8 @@ int vivid_g_fmt_vid_out(struct file *file, void *priv,
        for (p = 0; p < mp->num_planes; p++) {
                mp->plane_fmt[p].bytesperline = dev->bytesperline_out[p];
                mp->plane_fmt[p].sizeimage =
-                       mp->plane_fmt[p].bytesperline * mp->height +
-                       fmt->data_offset[p];
+                       mp->plane_fmt[p].bytesperline * mp->height /
+                       fmt->vdownsampling[p] + fmt->data_offset[p];
        }
        for (p = fmt->buffers; p < fmt->planes; p++) {
                unsigned stride = dev->bytesperline_out[p];