linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2,0/5] media: change the calculation method of sizeimage
@ 2024-04-09  6:44 Yunfei Dong
  2024-04-09  6:44 ` [PATCH v2,1/5] media: mediatek: vcodec: fix incorrect MT2T format information Yunfei Dong
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Yunfei Dong @ 2024-04-09  6:44 UTC (permalink / raw)
  To: Nícolas F . R . A . Prado, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	Yunfei Dong, linux-media, devicetree, linux-kernel,
	linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

The bytesperline and sizeimage of each plan are different for 8bit
and 10bit bitstreams. Using v4l2 common interface to calculate them
independently.

---
compare with v1:
- add patch 1/2/3/4
- change the calculation method for sizeimage for patch 5
---
Yunfei Dong (5):
  media: mediatek: vcodec: fix incorrect MT2T format information
  media: mediatek: vcodec: fix incorrect MT2R format information
  media: mediatek: vcodec: add MM21 format definition
  media: mediatek: vcodec: add MT21 format definition
  media: mediatek: vcodec: fix incorrect sizeimage for 10bit bitstream

 .../mediatek/vcodec/decoder/mtk_vcodec_dec.c  | 28 ++++++-------------
 drivers/media/v4l2-core/v4l2-common.c         | 12 +++++---
 2 files changed, 16 insertions(+), 24 deletions(-)

-- 
2.18.0



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2,1/5] media: mediatek: vcodec: fix incorrect MT2T format information
  2024-04-09  6:44 [PATCH v2,0/5] media: change the calculation method of sizeimage Yunfei Dong
@ 2024-04-09  6:44 ` Yunfei Dong
  2024-04-18 20:17   ` Nicolas Dufresne
  2024-04-09  6:44 ` [PATCH v2,2/5] media: mediatek: vcodec: fix incorrect MT2R " Yunfei Dong
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Yunfei Dong @ 2024-04-09  6:44 UTC (permalink / raw)
  To: Nícolas F . R . A . Prado, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	Yunfei Dong, linux-media, devicetree, linux-kernel,
	linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Changing the bpp and hdiv values to make sure the bytesperline
of plane[0] and plane[1] are the same. The width and height are
64 align.

Fixes: 6afcc2b0aebf ("media: mediatek: vcodec: Add capture format to support 10bit tile mode")
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 drivers/media/v4l2-core/v4l2-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index d34d210908d9..8587cd14741c 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -265,8 +265,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
 		{ .format = V4L2_PIX_FMT_VYUY,    .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 },
 		{ .format = V4L2_PIX_FMT_Y212,    .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 },
 		{ .format = V4L2_PIX_FMT_YUV48_12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
-		{ .format = V4L2_PIX_FMT_MT2110T, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,
-		  .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }},
+		{ .format = V4L2_PIX_FMT_MT2110T, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 5, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 1, .vdiv = 2,
+		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
 		{ .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,
 		  .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }},
 
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2,2/5] media: mediatek: vcodec: fix incorrect MT2R format information
  2024-04-09  6:44 [PATCH v2,0/5] media: change the calculation method of sizeimage Yunfei Dong
  2024-04-09  6:44 ` [PATCH v2,1/5] media: mediatek: vcodec: fix incorrect MT2T format information Yunfei Dong
@ 2024-04-09  6:44 ` Yunfei Dong
  2024-04-09  6:44 ` [PATCH v2,3/5] media: mediatek: vcodec: add MM21 format definition Yunfei Dong
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Yunfei Dong @ 2024-04-09  6:44 UTC (permalink / raw)
  To: Nícolas F . R . A . Prado, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	Yunfei Dong, linux-media, devicetree, linux-kernel,
	linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Changing the bpp and hdiv values to make sure the bytesperline
of plane[0] and plane[1] are the same. The width and height are
64 align.

Fixes: 1dff2beb60d3 ("media: mediatek: vcodec: Add capture format to support 10bit raster mode")
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 drivers/media/v4l2-core/v4l2-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 8587cd14741c..cef1492dba22 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -267,8 +267,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
 		{ .format = V4L2_PIX_FMT_YUV48_12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
 		{ .format = V4L2_PIX_FMT_MT2110T, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 5, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 1, .vdiv = 2,
 		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
-		{ .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,
-		  .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }},
+		{ .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 5, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 1, .vdiv = 2,
+		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
 
 		/* YUV planar formats */
 		{ .format = V4L2_PIX_FMT_NV12,    .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 },
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2,3/5] media: mediatek: vcodec: add MM21 format definition
  2024-04-09  6:44 [PATCH v2,0/5] media: change the calculation method of sizeimage Yunfei Dong
  2024-04-09  6:44 ` [PATCH v2,1/5] media: mediatek: vcodec: fix incorrect MT2T format information Yunfei Dong
  2024-04-09  6:44 ` [PATCH v2,2/5] media: mediatek: vcodec: fix incorrect MT2R " Yunfei Dong
@ 2024-04-09  6:44 ` Yunfei Dong
  2024-04-18 20:20   ` Nicolas Dufresne
  2024-04-09  6:44 ` [PATCH v2,4/5] media: mediatek: vcodec: add MT21 " Yunfei Dong
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Yunfei Dong @ 2024-04-09  6:44 UTC (permalink / raw)
  To: Nícolas F . R . A . Prado, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	Yunfei Dong, linux-media, devicetree, linux-kernel,
	linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Adding the definition of MM21 format to calculate bytesperline
and sizeimage of plane[0] and plane[1].

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 drivers/media/v4l2-core/v4l2-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index cef1492dba22..0d5de132e07f 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -269,6 +269,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
 		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
 		{ .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 5, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 1, .vdiv = 2,
 		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
+		{ .format = V4L2_PIX_FMT_MM21, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 1, 1, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 2,
+		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
 
 		/* YUV planar formats */
 		{ .format = V4L2_PIX_FMT_NV12,    .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 },
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2,4/5] media: mediatek: vcodec: add MT21 format definition
  2024-04-09  6:44 [PATCH v2,0/5] media: change the calculation method of sizeimage Yunfei Dong
                   ` (2 preceding siblings ...)
  2024-04-09  6:44 ` [PATCH v2,3/5] media: mediatek: vcodec: add MM21 format definition Yunfei Dong
@ 2024-04-09  6:44 ` Yunfei Dong
  2024-04-18 20:24   ` Nicolas Dufresne
  2024-04-09  6:44 ` [PATCH v2,5/5] media: mediatek: vcodec: fix incorrect sizeimage for 10bit bitstream Yunfei Dong
  2024-04-18 20:17 ` [PATCH v2,0/5] media: change the calculation method of sizeimage Nicolas Dufresne
  5 siblings, 1 reply; 11+ messages in thread
From: Yunfei Dong @ 2024-04-09  6:44 UTC (permalink / raw)
  To: Nícolas F . R . A . Prado, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	Yunfei Dong, linux-media, devicetree, linux-kernel,
	linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Adding the definition of MT21 format to calculate bytesperline
and sizeimage of plane[0] and plane[1].

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 drivers/media/v4l2-core/v4l2-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 0d5de132e07f..6dba989c2291 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -271,6 +271,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
 		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
 		{ .format = V4L2_PIX_FMT_MM21, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 1, 1, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 2,
 		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
+		{ .format = V4L2_PIX_FMT_MT21C, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 1, 1, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 2,
+		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
 
 		/* YUV planar formats */
 		{ .format = V4L2_PIX_FMT_NV12,    .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 },
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2,5/5] media: mediatek: vcodec: fix incorrect sizeimage for 10bit bitstream
  2024-04-09  6:44 [PATCH v2,0/5] media: change the calculation method of sizeimage Yunfei Dong
                   ` (3 preceding siblings ...)
  2024-04-09  6:44 ` [PATCH v2,4/5] media: mediatek: vcodec: add MT21 " Yunfei Dong
@ 2024-04-09  6:44 ` Yunfei Dong
  2024-04-18 20:33   ` Nicolas Dufresne
  2024-04-18 20:17 ` [PATCH v2,0/5] media: change the calculation method of sizeimage Nicolas Dufresne
  5 siblings, 1 reply; 11+ messages in thread
From: Yunfei Dong @ 2024-04-09  6:44 UTC (permalink / raw)
  To: Nícolas F . R . A . Prado, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	Yunfei Dong, linux-media, devicetree, linux-kernel,
	linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

The sizeimage of each plane is calculated the same way for 8bit and
10bit bitstream. Using v4l2 common interface v4l2_fill_pixfmt_mp to
separate.

Fixes: 9d86be9bda6c ("media: mediatek: vcodec: Add driver to support 10bit")
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../mediatek/vcodec/decoder/mtk_vcodec_dec.c  | 28 ++++++-------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
index 9107707de6c4..fbfba69682ea 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
@@ -262,40 +262,28 @@ static int vidioc_try_fmt(struct mtk_vcodec_dec_ctx *ctx, struct v4l2_format *f,
 		int tmp_w, tmp_h;
 
 		/*
-		 * Find next closer width align 64, height align 64, size align
-		 * 64 rectangle
+		 * Find next closer width align 64, heign align 64, size align 64 rectangle
 		 * Note: This only get default value, the real HW needed value
 		 *       only available when ctx in MTK_STATE_HEADER state
 		 */
 		tmp_w = pix_fmt_mp->width;
 		tmp_h = pix_fmt_mp->height;
+
 		v4l_bound_align_image(&pix_fmt_mp->width, MTK_VDEC_MIN_W, frmsize->max_width, 6,
 				      &pix_fmt_mp->height, MTK_VDEC_MIN_H, frmsize->max_height, 6,
 				      9);
 
-		if (pix_fmt_mp->width < tmp_w &&
-		    (pix_fmt_mp->width + 64) <= frmsize->max_width)
+		if (pix_fmt_mp->width < tmp_w && (pix_fmt_mp->width + 64) <= frmsize->max_width)
 			pix_fmt_mp->width += 64;
-		if (pix_fmt_mp->height < tmp_h &&
-		    (pix_fmt_mp->height + 64) <= frmsize->max_height)
+		if (pix_fmt_mp->height < tmp_h && (pix_fmt_mp->height + 64) <= frmsize->max_height)
 			pix_fmt_mp->height += 64;
 
+		v4l2_fill_pixfmt_mp(pix_fmt_mp, fmt->fourcc, pix_fmt_mp->width, pix_fmt_mp->height);
 		mtk_v4l2_vdec_dbg(0, ctx,
-				  "before resize wxh=%dx%d, after resize wxh=%dx%d, sizeimage=%d",
+				  "before resize:%dx%d, after resize:%dx%d, sizeimage=0x%x_0x%x",
 				  tmp_w, tmp_h, pix_fmt_mp->width, pix_fmt_mp->height,
-				  pix_fmt_mp->width * pix_fmt_mp->height);
-
-		pix_fmt_mp->num_planes = fmt->num_planes;
-		pix_fmt_mp->plane_fmt[0].sizeimage =
-				pix_fmt_mp->width * pix_fmt_mp->height;
-		pix_fmt_mp->plane_fmt[0].bytesperline = pix_fmt_mp->width;
-
-		if (pix_fmt_mp->num_planes == 2) {
-			pix_fmt_mp->plane_fmt[1].sizeimage =
-				(pix_fmt_mp->width * pix_fmt_mp->height) / 2;
-			pix_fmt_mp->plane_fmt[1].bytesperline =
-				pix_fmt_mp->width;
-		}
+				  pix_fmt_mp->plane_fmt[0].sizeimage,
+				  pix_fmt_mp->plane_fmt[1].sizeimage);
 	}
 
 	pix_fmt_mp->flags = 0;
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2,1/5] media: mediatek: vcodec: fix incorrect MT2T format information
  2024-04-09  6:44 ` [PATCH v2,1/5] media: mediatek: vcodec: fix incorrect MT2T format information Yunfei Dong
@ 2024-04-18 20:17   ` Nicolas Dufresne
  0 siblings, 0 replies; 11+ messages in thread
From: Nicolas Dufresne @ 2024-04-18 20:17 UTC (permalink / raw)
  To: Yunfei Dong, Nícolas F . R . A . Prado, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	linux-media, devicetree, linux-kernel, linux-arm-kernel,
	linux-mediatek, Project_Global_Chrome_Upstream_Group

Le mardi 09 avril 2024 à 14:44 +0800, Yunfei Dong a écrit :
> Changing the bpp and hdiv values to make sure the bytesperline
> of plane[0] and plane[1] are the same. The width and height are
> 64 align.
> 
> Fixes: 6afcc2b0aebf ("media: mediatek: vcodec: Add capture format to support 10bit tile mode")
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
>  drivers/media/v4l2-core/v4l2-common.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
> index d34d210908d9..8587cd14741c 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -265,8 +265,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
>  		{ .format = V4L2_PIX_FMT_VYUY,    .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 },
>  		{ .format = V4L2_PIX_FMT_Y212,    .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 },
>  		{ .format = V4L2_PIX_FMT_YUV48_12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
> -		{ .format = V4L2_PIX_FMT_MT2110T, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,
> -		  .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }},
> +		{ .format = V4L2_PIX_FMT_MT2110T, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 5, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 1, .vdiv = 2,
> +		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},

The code that calculate the info you are fixing:

plane->bytesperline =
	info->bpp[i] * DIV_ROUND_UP(aligned_width, hdiv) / info->bpp_div[i];
plane->sizeimage = plane->bytesperline * DIV_ROUND_UP(aligned_height, vdiv);

hdiv is 1 for the first plane, and 2 for second plane. Let say we have 1920x1080
video, bytesperline for that first planes would be 5 * (1920 / 1) / 4 = 2400.
But for the second plane with your change we have 5 * (1920 / 2) / 4 = 1200. For
me, you failed to achieve your goal, or there is a bug elsewhere.

The second change should have its own commit, but I think it should be dropped.
The driver is hacked to be compatible with the Mali GPUs (64x64 textures), but
does not need this alignment. And in any case, the block should represent the
pixel format required alignment, so I'd suggest to leave it like this, and
simply align width/height before calling the function to calculate
stride/sizeimage. The 64x64 alignment can be applied using
v4l2_apply_frmsize_constraints() during try fmt (or v4l_bound_align_image(), but
first is preferred).

Same comments apply to the following patch, which should be squashed.

>  		{ .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,
>  		  .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }},
>  



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2,0/5] media: change the calculation method of sizeimage
  2024-04-09  6:44 [PATCH v2,0/5] media: change the calculation method of sizeimage Yunfei Dong
                   ` (4 preceding siblings ...)
  2024-04-09  6:44 ` [PATCH v2,5/5] media: mediatek: vcodec: fix incorrect sizeimage for 10bit bitstream Yunfei Dong
@ 2024-04-18 20:17 ` Nicolas Dufresne
  5 siblings, 0 replies; 11+ messages in thread
From: Nicolas Dufresne @ 2024-04-18 20:17 UTC (permalink / raw)
  To: Yunfei Dong, Nícolas F . R . A . Prado, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	linux-media, devicetree, linux-kernel, linux-arm-kernel,
	linux-mediatek, Project_Global_Chrome_Upstream_Group

Hi,

sorry for the long delay.

Le mardi 09 avril 2024 à 14:44 +0800, Yunfei Dong a écrit :
> The bytesperline and sizeimage of each plan are different for 8bit
> and 10bit bitstreams. Using v4l2 common interface to calculate them
> independently.
> 
> ---
> compare with v1:
> - add patch 1/2/3/4
> - change the calculation method for sizeimage for patch 5
> ---
> Yunfei Dong (5):
>   media: mediatek: vcodec: fix incorrect MT2T format information
>   media: mediatek: vcodec: fix incorrect MT2R format information

As per recommandation of the "Submitting Patches":
> On the other hand, if you make a single change to numerous files, group those
> changes into a single patch. Thus a single logical change is contained within
> a single patch.

In general, when two patches have an identical description its a sign they
should be one patch. Would be nice to squash these two.

>   media: mediatek: vcodec: add MM21 format definition
>   media: mediatek: vcodec: add MT21 format definition

Same.

>   media: mediatek: vcodec: fix incorrect sizeimage for 10bit bitstream
> 
>  .../mediatek/vcodec/decoder/mtk_vcodec_dec.c  | 28 ++++++-------------
>  drivers/media/v4l2-core/v4l2-common.c         | 12 +++++---
>  2 files changed, 16 insertions(+), 24 deletions(-)
> 



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2,3/5] media: mediatek: vcodec: add MM21 format definition
  2024-04-09  6:44 ` [PATCH v2,3/5] media: mediatek: vcodec: add MM21 format definition Yunfei Dong
@ 2024-04-18 20:20   ` Nicolas Dufresne
  0 siblings, 0 replies; 11+ messages in thread
From: Nicolas Dufresne @ 2024-04-18 20:20 UTC (permalink / raw)
  To: Yunfei Dong, Nícolas F . R . A . Prado, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	linux-media, devicetree, linux-kernel, linux-arm-kernel,
	linux-mediatek, Project_Global_Chrome_Upstream_Group

Le mardi 09 avril 2024 à 14:44 +0800, Yunfei Dong a écrit :
> Adding the definition of MM21 format to calculate bytesperline
> and sizeimage of plane[0] and plane[1].
> 
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
>  drivers/media/v4l2-core/v4l2-common.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
> index cef1492dba22..0d5de132e07f 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -269,6 +269,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
>  		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
>  		{ .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 5, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 1, .vdiv = 2,
>  		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
> +		{ .format = V4L2_PIX_FMT_MM21, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 1, 1, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 2,
> +		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},

MM21 has the same subsampling as NV12M, so hdiv should be 2 for correctness. The
64x64 block is incorrect. The only difference between this and NV12M should be
with block.

>  
>  		/* YUV planar formats */
>  		{ .format = V4L2_PIX_FMT_NV12,    .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 },



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2,4/5] media: mediatek: vcodec: add MT21 format definition
  2024-04-09  6:44 ` [PATCH v2,4/5] media: mediatek: vcodec: add MT21 " Yunfei Dong
@ 2024-04-18 20:24   ` Nicolas Dufresne
  0 siblings, 0 replies; 11+ messages in thread
From: Nicolas Dufresne @ 2024-04-18 20:24 UTC (permalink / raw)
  To: Yunfei Dong, Nícolas F . R . A . Prado, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	linux-media, devicetree, linux-kernel, linux-arm-kernel,
	linux-mediatek, Project_Global_Chrome_Upstream_Group

Le mardi 09 avril 2024 à 14:44 +0800, Yunfei Dong a écrit :
> Adding the definition of MT21 format to calculate bytesperline

MT21C in the subject and description.

> and sizeimage of plane[0] and plane[1].
> 
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
>  drivers/media/v4l2-core/v4l2-common.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
> index 0d5de132e07f..6dba989c2291 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -271,6 +271,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
>  		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
>  		{ .format = V4L2_PIX_FMT_MM21, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 1, 1, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 2,
>  		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},
> +		{ .format = V4L2_PIX_FMT_MT21C, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 1, 1, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 2,
> +		  .block_w = { 64, 64, 0, 0 }, .block_h = { 64, 64, 0, 0 }},

As you may notice, we have no support for compressed formats yet in this helper.
I believe for these formats we need some extra code to add the header size
calculation. One way could be to add a ops in that table for when a header is
needed. That ops would implement the format specific extra space calculation
which would be added to sizeimage of each planes (in in one of the planes
depending on the specifics of the format).

>  
>  		/* YUV planar formats */
>  		{ .format = V4L2_PIX_FMT_NV12,    .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 },



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2,5/5] media: mediatek: vcodec: fix incorrect sizeimage for 10bit bitstream
  2024-04-09  6:44 ` [PATCH v2,5/5] media: mediatek: vcodec: fix incorrect sizeimage for 10bit bitstream Yunfei Dong
@ 2024-04-18 20:33   ` Nicolas Dufresne
  0 siblings, 0 replies; 11+ messages in thread
From: Nicolas Dufresne @ 2024-04-18 20:33 UTC (permalink / raw)
  To: Yunfei Dong, Nícolas F . R . A . Prado, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Nathan Hebert,
	Sebastian Fricke
  Cc: Hsin-Yi Wang, Fritz Koenig, Daniel Vetter, Steve Cho,
	linux-media, devicetree, linux-kernel, linux-arm-kernel,
	linux-mediatek, Project_Global_Chrome_Upstream_Group

Le mardi 09 avril 2024 à 14:44 +0800, Yunfei Dong a écrit :
> The sizeimage of each plane is calculated the same way for 8bit and
> 10bit bitstream. Using v4l2 common interface v4l2_fill_pixfmt_mp to
> separate.
> 
> Fixes: 9d86be9bda6c ("media: mediatek: vcodec: Add driver to support 10bit")
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
>  .../mediatek/vcodec/decoder/mtk_vcodec_dec.c  | 28 ++++++-------------
>  1 file changed, 8 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
> index 9107707de6c4..fbfba69682ea 100644
> --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
> +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
> @@ -262,40 +262,28 @@ static int vidioc_try_fmt(struct mtk_vcodec_dec_ctx *ctx, struct v4l2_format *f,
>  		int tmp_w, tmp_h;
>  
>  		/*
> -		 * Find next closer width align 64, height align 64, size align
> -		 * 64 rectangle
> +		 * Find next closer width align 64, heign align 64, size align 64 rectangle
>  		 * Note: This only get default value, the real HW needed value
>  		 *       only available when ctx in MTK_STATE_HEADER state
>  		 */
>  		tmp_w = pix_fmt_mp->width;
>  		tmp_h = pix_fmt_mp->height;
> +
>  		v4l_bound_align_image(&pix_fmt_mp->width, MTK_VDEC_MIN_W, frmsize->max_width, 6,
>  				      &pix_fmt_mp->height, MTK_VDEC_MIN_H, frmsize->max_height, 6,
>  				      9);
>  
> -		if (pix_fmt_mp->width < tmp_w &&
> -		    (pix_fmt_mp->width + 64) <= frmsize->max_width)
> +		if (pix_fmt_mp->width < tmp_w && (pix_fmt_mp->width + 64) <= frmsize->max_width)
>  			pix_fmt_mp->width += 64;
> -		if (pix_fmt_mp->height < tmp_h &&
> -		    (pix_fmt_mp->height + 64) <= frmsize->max_height)
> +		if (pix_fmt_mp->height < tmp_h && (pix_fmt_mp->height + 64) <= frmsize->max_height)
>  			pix_fmt_mp->height += 64;

This seems overlay complicated, make sure your frmsize is valid (with
step_width/height set to 64 from your Mali requirement) and then simply call:

	v4l2_apply_frmsize_constraints(...)

All this hand written clamping code with hardcoded values should go away.

>  
> +		v4l2_fill_pixfmt_mp(pix_fmt_mp, fmt->fourcc, pix_fmt_mp->width, pix_fmt_mp->height);
>  		mtk_v4l2_vdec_dbg(0, ctx,
> -				  "before resize wxh=%dx%d, after resize wxh=%dx%d, sizeimage=%d",
> +				  "before resize:%dx%d, after resize:%dx%d, sizeimage=0x%x_0x%x",
>  				  tmp_w, tmp_h, pix_fmt_mp->width, pix_fmt_mp->height,
> -				  pix_fmt_mp->width * pix_fmt_mp->height);
> -
> -		pix_fmt_mp->num_planes = fmt->num_planes;
> -		pix_fmt_mp->plane_fmt[0].sizeimage =
> -				pix_fmt_mp->width * pix_fmt_mp->height;
> -		pix_fmt_mp->plane_fmt[0].bytesperline = pix_fmt_mp->width;
> -
> -		if (pix_fmt_mp->num_planes == 2) {
> -			pix_fmt_mp->plane_fmt[1].sizeimage =
> -				(pix_fmt_mp->width * pix_fmt_mp->height) / 2;
> -			pix_fmt_mp->plane_fmt[1].bytesperline =
> -				pix_fmt_mp->width;
> -		}
> +				  pix_fmt_mp->plane_fmt[0].sizeimage,
> +				  pix_fmt_mp->plane_fmt[1].sizeimage);
>  	}
>  
>  	pix_fmt_mp->flags = 0;



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-04-22 19:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09  6:44 [PATCH v2,0/5] media: change the calculation method of sizeimage Yunfei Dong
2024-04-09  6:44 ` [PATCH v2,1/5] media: mediatek: vcodec: fix incorrect MT2T format information Yunfei Dong
2024-04-18 20:17   ` Nicolas Dufresne
2024-04-09  6:44 ` [PATCH v2,2/5] media: mediatek: vcodec: fix incorrect MT2R " Yunfei Dong
2024-04-09  6:44 ` [PATCH v2,3/5] media: mediatek: vcodec: add MM21 format definition Yunfei Dong
2024-04-18 20:20   ` Nicolas Dufresne
2024-04-09  6:44 ` [PATCH v2,4/5] media: mediatek: vcodec: add MT21 " Yunfei Dong
2024-04-18 20:24   ` Nicolas Dufresne
2024-04-09  6:44 ` [PATCH v2,5/5] media: mediatek: vcodec: fix incorrect sizeimage for 10bit bitstream Yunfei Dong
2024-04-18 20:33   ` Nicolas Dufresne
2024-04-18 20:17 ` [PATCH v2,0/5] media: change the calculation method of sizeimage Nicolas Dufresne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).