Commit 991b3137 authored by Albert Wang's avatar Albert Wang Committed by Mauro Carvalho Chehab

[media] media: soc_camera: don't clear pix->sizeimage in JPEG mode

In JPEG mode, the size of image is variable due to different JPEG compression
rate. We only can get the pix->sizeimage from the user.

If we clear pix->sizeimage in soc_camera_try_fmt() then we will get it from:
	ret = soc_mbus_image_size(xlate->host_fmt, pix->bytesperline,
				pix->height);
	if (ret < 0)
		return ret;

	pix->sizeimage = max_t(u32, pix->sizeimage, ret);

In general, this sizeimage will be larger than the actul JPEG image size.

But vb2 will check the buffer and size of image in __qbuf_userptr():
	/* Check if the provided plane buffer is large enough */
	if (planes[plane].length < q->plane_sizes[plane])

So we shouldn't clear the pix->sizeimage and also shouldn't re-calculate
the pix->sizeimage in soc_mbus_image_size() in JPEG mode

We also shouldn't re-calculate pix->bytesperline:
	ret = soc_mbus_bytes_per_line(pix->width, xlate->host_fmt);
	if (ret < 0)
		return ret;

	pix->bytesperline = max_t(u32, pix->bytesperline, ret);

pix->bytesperline also should be set by the user or by the driver's
try_fmt() implementation.

Change-Id: I700690a2287346127a624b5260922eaa5427a596
Signed-off-by: default avatarAlbert Wang <twang13@marvell.com>
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent ad5b9870
...@@ -171,7 +171,8 @@ static int soc_camera_try_fmt(struct soc_camera_device *icd, ...@@ -171,7 +171,8 @@ static int soc_camera_try_fmt(struct soc_camera_device *icd,
dev_dbg(icd->pdev, "TRY_FMT(%c%c%c%c, %ux%u)\n", dev_dbg(icd->pdev, "TRY_FMT(%c%c%c%c, %ux%u)\n",
pixfmtstr(pix->pixelformat), pix->width, pix->height); pixfmtstr(pix->pixelformat), pix->width, pix->height);
if (!(ici->capabilities & SOCAM_HOST_CAP_STRIDE)) { if (pix->pixelformat != V4L2_PIX_FMT_JPEG &&
!(ici->capabilities & SOCAM_HOST_CAP_STRIDE)) {
pix->bytesperline = 0; pix->bytesperline = 0;
pix->sizeimage = 0; pix->sizeimage = 0;
} }
......
...@@ -378,6 +378,9 @@ EXPORT_SYMBOL(soc_mbus_samples_per_pixel); ...@@ -378,6 +378,9 @@ EXPORT_SYMBOL(soc_mbus_samples_per_pixel);
s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf) s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf)
{ {
if (mf->fourcc == V4L2_PIX_FMT_JPEG)
return 0;
if (mf->layout != SOC_MBUS_LAYOUT_PACKED) if (mf->layout != SOC_MBUS_LAYOUT_PACKED)
return width * mf->bits_per_sample / 8; return width * mf->bits_per_sample / 8;
...@@ -400,6 +403,9 @@ EXPORT_SYMBOL(soc_mbus_bytes_per_line); ...@@ -400,6 +403,9 @@ EXPORT_SYMBOL(soc_mbus_bytes_per_line);
s32 soc_mbus_image_size(const struct soc_mbus_pixelfmt *mf, s32 soc_mbus_image_size(const struct soc_mbus_pixelfmt *mf,
u32 bytes_per_line, u32 height) u32 bytes_per_line, u32 height)
{ {
if (mf->fourcc == V4L2_PIX_FMT_JPEG)
return 0;
if (mf->layout == SOC_MBUS_LAYOUT_PACKED) if (mf->layout == SOC_MBUS_LAYOUT_PACKED)
return bytes_per_line * height; return bytes_per_line * height;
......
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