Skip to contentSkip to conversation

media: imx-jpeg: Support for negotiating bytesperline with client

PATCH In review Ming Qian 2 participants 2 messages Feb 5, 2024 – Feb 19, 2024

Subsystems (3)
lore
Share & tools
lore

Ming Qian

author
#0 lore raw

PATCH 1/1 media: imx-jpeg: Support for negotiating bytesperline with client

This mxc-jpeg driver doesn't allow the client to set the bytesperline, but for some android cts case, it need to negotiate the bytesperline between decoder and display, and fail the case if driver doesn't support negotiating bytesperline

The jpegdec and jpegenc does support to set bytesperline which is multiple of 2, and greater than the value calulated by driver.

---
 drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 16 ++++++++++++++++
 drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h |  1 +
 2 files changed, 17 insertions(+)
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +16 -0
index 64112b63298c..cc97790ed30f 100644
@@ -1373,6 +1373,8 @@ static bool mxc_jpeg_source_change(struct mxc_jpeg_ctx *ctx,
 		q_data_cap->crop.top = 0;
 		q_data_cap->crop.width = jpeg_src_buf->w;
 		q_data_cap->crop.height = jpeg_src_buf->h;
+		q_data_cap->bytesperline[0] = 0;
+		q_data_cap->bytesperline[1] = 0;
 
 		/*
 		 * align up the resolution for CAST IP,
@@ -1752,6 +1754,14 @@ static u32 mxc_jpeg_get_image_format(struct device *dev,
 
 static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, u32 precision)
 {
+	u32 bytesperline[2];
+
+	bytesperline[0] = q->bytesperline[0];
+	bytesperline[1] = q->bytesperline[0];	/*imx-jpeg only support the same line pitch*/
+	v4l_bound_align_image(&bytesperline[0], 0, MXC_JPEG_MAX_LINE, 2,
+			      &bytesperline[1], 0, MXC_JPEG_MAX_LINE, 2,
+			      0);
+
 	/* Bytes distance between the leftmost pixels in two adjacent lines */
 	if (q->fmt->fourcc == V4L2_PIX_FMT_JPEG) {
 		/* bytesperline unused for compressed formats */
@@ -1775,6 +1785,12 @@ static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, u32 precision)
 		q->bytesperline[0] = q->w_adjusted * DIV_ROUND_UP(precision, 8);
 		q->bytesperline[1] = 0;
 	}
+
+	if (q->fmt->fourcc != V4L2_PIX_FMT_JPEG) {
+		q->bytesperline[0] = max(q->bytesperline[0], bytesperline[0]);
+		if (q->fmt->mem_planes > 1)
+			q->bytesperline[1] = max(q->bytesperline[1], bytesperline[1]);
+	}
 }
 
 static void mxc_jpeg_sizeimage(struct mxc_jpeg_q_data *q)
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h +1 -0
index dc4afeeff5b6..86e324b21aed 100644
@@ -22,6 +22,7 @@
 #define MXC_JPEG_MIN_HEIGHT		64
 #define MXC_JPEG_MAX_WIDTH		0x2000
 #define MXC_JPEG_MAX_HEIGHT		0x2000
+#define MXC_JPEG_MAX_LINE		0x8000
 #define MXC_JPEG_MAX_CFG_STREAM		0x1000
 #define MXC_JPEG_H_ALIGN		3
 #define MXC_JPEG_W_ALIGN		3
Signature · 1 line
2.43.0-rc1
Reviewed-by Mirela Rabulea on v1 1/1
#1 lore raw

Hi Ming,

Quoted 9 lines · Ming Qian

This mxc-jpeg driver doesn't allow the client to set the bytesperline, but for some android cts case, it need to negotiate the bytesperline between decoder and display, and fail the case if driver doesn't support negotiating bytesperline

The jpegdec and jpegenc does support to set bytesperline which is multiple of 2, and greater than the value calulated by driver.

There is a typo in the commit message: calulated.
Other than that,

Regards,
Mirela

Quoted 58 lines
---
  drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 16 ++++++++++++++++
  drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h |  1 +
  2 files changed, 17 insertions(+)
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +16 -0
index 64112b63298c..cc97790ed30f 100644
@@ -1373,6 +1373,8 @@ static bool mxc_jpeg_source_change(struct mxc_jpeg_ctx *ctx,
  		q_data_cap->crop.top = 0;
  		q_data_cap->crop.width = jpeg_src_buf->w;
  		q_data_cap->crop.height = jpeg_src_buf->h;
+		q_data_cap->bytesperline[0] = 0;
+		q_data_cap->bytesperline[1] = 0;
 
  		/*
  		 * align up the resolution for CAST IP,
@@ -1752,6 +1754,14 @@ static u32 mxc_jpeg_get_image_format(struct device *dev,
 
  static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, u32 precision)
  {
+	u32 bytesperline[2];
+
+	bytesperline[0] = q->bytesperline[0];
+	bytesperline[1] = q->bytesperline[0];	/*imx-jpeg only support the same line pitch*/
+	v4l_bound_align_image(&bytesperline[0], 0, MXC_JPEG_MAX_LINE, 2,
+			      &bytesperline[1], 0, MXC_JPEG_MAX_LINE, 2,
+			      0);
+
  	/* Bytes distance between the leftmost pixels in two adjacent lines */
  	if (q->fmt->fourcc == V4L2_PIX_FMT_JPEG) {
  		/* bytesperline unused for compressed formats */
@@ -1775,6 +1785,12 @@ static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, u32 precision)
  		q->bytesperline[0] = q->w_adjusted * DIV_ROUND_UP(precision, 8);
  		q->bytesperline[1] = 0;
  	}
+
+	if (q->fmt->fourcc != V4L2_PIX_FMT_JPEG) {
+		q->bytesperline[0] = max(q->bytesperline[0], bytesperline[0]);
+		if (q->fmt->mem_planes > 1)
+			q->bytesperline[1] = max(q->bytesperline[1], bytesperline[1]);
+	}
  }
 
  static void mxc_jpeg_sizeimage(struct mxc_jpeg_q_data *q)
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h +1 -0
index dc4afeeff5b6..86e324b21aed 100644
@@ -22,6 +22,7 @@
  #define MXC_JPEG_MIN_HEIGHT		64
  #define MXC_JPEG_MAX_WIDTH		0x2000
  #define MXC_JPEG_MAX_HEIGHT		0x2000
+#define MXC_JPEG_MAX_LINE		0x8000
  #define MXC_JPEG_MAX_CFG_STREAM		0x1000
  #define MXC_JPEG_H_ALIGN		3
  #define MXC_JPEG_W_ALIGN		3