Commit bed8d803 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

[media] soc-camera: Honor user-requested bytesperline and sizeimage

Compute the bytesperline and sizeimage values when trying/setting
formats or when allocating buffers by taking the user-requested values
into account.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 8929c963
...@@ -206,17 +206,25 @@ static int mx3_videobuf_setup(struct vb2_queue *vq, ...@@ -206,17 +206,25 @@ static int mx3_videobuf_setup(struct vb2_queue *vq,
if (fmt) { if (fmt) {
const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd, const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd,
fmt->fmt.pix.pixelformat); fmt->fmt.pix.pixelformat);
int bytes_per_line; unsigned int bytes_per_line;
int ret;
if (!xlate) if (!xlate)
return -EINVAL; return -EINVAL;
bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width, ret = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
xlate->host_fmt); xlate->host_fmt);
if (bytes_per_line < 0) if (ret < 0)
return bytes_per_line; return ret;
bytes_per_line = max_t(u32, fmt->fmt.pix.bytesperline, ret);
ret = soc_mbus_image_size(xlate->host_fmt, bytes_per_line,
fmt->fmt.pix.height);
if (ret < 0)
return ret;
sizes[0] = bytes_per_line * fmt->fmt.pix.height; sizes[0] = max_t(u32, fmt->fmt.pix.sizeimage, ret);
} else { } else {
/* Called from VIDIOC_REQBUFS or in compatibility mode */ /* Called from VIDIOC_REQBUFS or in compatibility mode */
sizes[0] = icd->sizeimage; sizes[0] = icd->sizeimage;
......
...@@ -214,17 +214,25 @@ static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq, ...@@ -214,17 +214,25 @@ static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
if (fmt) { if (fmt) {
const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd, const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd,
fmt->fmt.pix.pixelformat); fmt->fmt.pix.pixelformat);
int bytes_per_line; unsigned int bytes_per_line;
int ret;
if (!xlate) if (!xlate)
return -EINVAL; return -EINVAL;
bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width, ret = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
xlate->host_fmt); xlate->host_fmt);
if (bytes_per_line < 0) if (ret < 0)
return bytes_per_line; return ret;
bytes_per_line = max_t(u32, fmt->fmt.pix.bytesperline, ret);
ret = soc_mbus_image_size(xlate->host_fmt, bytes_per_line,
fmt->fmt.pix.height);
if (ret < 0)
return ret;
sizes[0] = bytes_per_line * fmt->fmt.pix.height; sizes[0] = max_t(u32, fmt->fmt.pix.sizeimage, ret);
} else { } else {
/* Called from VIDIOC_REQBUFS or in compatibility mode */ /* Called from VIDIOC_REQBUFS or in compatibility mode */
sizes[0] = icd->sizeimage; sizes[0] = icd->sizeimage;
......
...@@ -164,6 +164,7 @@ static int soc_camera_try_fmt(struct soc_camera_device *icd, ...@@ -164,6 +164,7 @@ static int soc_camera_try_fmt(struct soc_camera_device *icd,
struct v4l2_format *f) struct v4l2_format *f)
{ {
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
const struct soc_camera_format_xlate *xlate;
struct v4l2_pix_format *pix = &f->fmt.pix; struct v4l2_pix_format *pix = &f->fmt.pix;
int ret; int ret;
...@@ -177,22 +178,22 @@ static int soc_camera_try_fmt(struct soc_camera_device *icd, ...@@ -177,22 +178,22 @@ static int soc_camera_try_fmt(struct soc_camera_device *icd,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (!pix->sizeimage) { xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
if (!pix->bytesperline) { if (!xlate)
const struct soc_camera_format_xlate *xlate; return -EINVAL;
xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); ret = soc_mbus_bytes_per_line(pix->width, xlate->host_fmt);
if (!xlate) if (ret < 0)
return -EINVAL; return ret;
ret = soc_mbus_bytes_per_line(pix->width, pix->bytesperline = max_t(u32, pix->bytesperline, ret);
xlate->host_fmt);
if (ret > 0) ret = soc_mbus_image_size(xlate->host_fmt, pix->bytesperline,
pix->bytesperline = ret; pix->height);
} if (ret < 0)
if (pix->bytesperline) return ret;
pix->sizeimage = pix->bytesperline * pix->height;
} pix->sizeimage = max_t(u32, pix->sizeimage, ret);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment