2021-03-30 22:20:03

by Fritz Koenig

[permalink] [raw]
Subject: [PATCH] media: mtk-vcodec: vdec: Reduce padding in VIDIOC_TRY_FMT

If the header has been parsed or the codec is stateless
reduce the padding of the decoded frame.
In stateless codecs width and height are specified by
the application.

Signed-off-by: Fritz Koenig <[email protected]>
---
.../platform/mtk-vcodec/mtk_vcodec_dec.c | 59 ++++++++++++-------
1 file changed, 39 insertions(+), 20 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
index 56d86e59421e..9c88454dc10c 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
@@ -653,7 +653,7 @@ static int vidioc_vdec_subscribe_evt(struct v4l2_fh *fh,
}
}

-static int vidioc_try_fmt(struct v4l2_format *f,
+static int vidioc_try_fmt(struct v4l2_format *f, void *priv,
const struct mtk_video_fmt *fmt)
{
struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
@@ -665,6 +665,7 @@ static int vidioc_try_fmt(struct v4l2_format *f,
pix_fmt_mp->plane_fmt[0].bytesperline = 0;
} else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
int tmp_w, tmp_h;
+ struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);

pix_fmt_mp->height = clamp(pix_fmt_mp->height,
MTK_VDEC_MIN_H,
@@ -673,27 +674,45 @@ static int vidioc_try_fmt(struct v4l2_format *f,
MTK_VDEC_MIN_W,
MTK_VDEC_MAX_W);

+ tmp_w = pix_fmt_mp->width;
+ tmp_h = pix_fmt_mp->height;
+
+ if (ctx->dev->vdec_pdata->uses_stateless_api ||
+ ctx->state >= MTK_STATE_HEADER) {
+ v4l_bound_align_image(&pix_fmt_mp->width,
+ MTK_VDEC_MIN_W,
+ MTK_VDEC_MAX_W, 4,
+ &pix_fmt_mp->height,
+ MTK_VDEC_MIN_H,
+ MTK_VDEC_MAX_H, 5, 6);
+
+ if (pix_fmt_mp->width < tmp_w &&
+ (pix_fmt_mp->width + 16) <= MTK_VDEC_MAX_W)
+ pix_fmt_mp->width += 16;
+ if (pix_fmt_mp->height < tmp_h &&
+ (pix_fmt_mp->height + 32) <= MTK_VDEC_MAX_H)
+ pix_fmt_mp->height += 32;
+ } else {
/*
- * Find next closer width align 64, heign align 64, size align
+ * Find next closer width align 64, height 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,
- MTK_VDEC_MAX_W, 6,
- &pix_fmt_mp->height,
- MTK_VDEC_MIN_H,
- MTK_VDEC_MAX_H, 6, 9);
-
- if (pix_fmt_mp->width < tmp_w &&
- (pix_fmt_mp->width + 64) <= MTK_VDEC_MAX_W)
- pix_fmt_mp->width += 64;
- if (pix_fmt_mp->height < tmp_h &&
- (pix_fmt_mp->height + 64) <= MTK_VDEC_MAX_H)
- pix_fmt_mp->height += 64;
+ v4l_bound_align_image(&pix_fmt_mp->width,
+ MTK_VDEC_MIN_W,
+ MTK_VDEC_MAX_W, 6,
+ &pix_fmt_mp->height,
+ MTK_VDEC_MIN_H,
+ MTK_VDEC_MAX_H, 6, 9);
+
+ if (pix_fmt_mp->width < tmp_w &&
+ (pix_fmt_mp->width + 64) <= MTK_VDEC_MAX_W)
+ pix_fmt_mp->width += 64;
+ if (pix_fmt_mp->height < tmp_h &&
+ (pix_fmt_mp->height + 64) <= MTK_VDEC_MAX_H)
+ pix_fmt_mp->height += 64;
+ }

mtk_v4l2_debug(0,
"before resize width=%d, height=%d, after resize width=%d, height=%d, sizeimage=%d",
@@ -729,7 +748,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
fmt = mtk_vdec_find_format(f);
}

- return vidioc_try_fmt(f, fmt);
+ return vidioc_try_fmt(f, priv, fmt);
}

static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
@@ -749,7 +768,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
return -EINVAL;
}

- return vidioc_try_fmt(f, fmt);
+ return vidioc_try_fmt(f, priv, fmt);
}

static int vidioc_vdec_g_selection(struct file *file, void *priv,
@@ -875,7 +894,7 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv,
return -EINVAL;

q_data->fmt = fmt;
- vidioc_try_fmt(f, q_data->fmt);
+ vidioc_try_fmt(f, priv, q_data->fmt);
if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
q_data->sizeimage[0] = pix_mp->plane_fmt[0].sizeimage;
q_data->coded_width = pix_mp->width;
--
2.31.0.291.g576ba9dcdaf-goog


2021-03-31 07:20:11

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] media: mtk-vcodec: vdec: Reduce padding in VIDIOC_TRY_FMT

Hi Fritz,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on linux/master linus/master v5.12-rc5 next-20210330]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Fritz-Koenig/media-mtk-vcodec-vdec-Reduce-padding-in-VIDIOC_TRY_FMT/20210331-061702
base: git://linuxtv.org/media_tree.git master
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/70ddfb8b962ccf027d02fdb4502452f8996bb25f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Fritz-Koenig/media-mtk-vcodec-vdec-Reduce-padding-in-VIDIOC_TRY_FMT/20210331-061702
git checkout 70ddfb8b962ccf027d02fdb4502452f8996bb25f
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c: In function 'vidioc_try_fmt':
>> drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c:680:17: error: 'struct mtk_vcodec_dev' has no member named 'vdec_pdata'; did you mean 'venc_pdata'?
680 | if (ctx->dev->vdec_pdata->uses_stateless_api ||
| ^~~~~~~~~~
| venc_pdata


vim +680 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c

655
656 static int vidioc_try_fmt(struct v4l2_format *f, void *priv,
657 const struct mtk_video_fmt *fmt)
658 {
659 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
660
661 pix_fmt_mp->field = V4L2_FIELD_NONE;
662
663 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
664 pix_fmt_mp->num_planes = 1;
665 pix_fmt_mp->plane_fmt[0].bytesperline = 0;
666 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
667 int tmp_w, tmp_h;
668 struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
669
670 pix_fmt_mp->height = clamp(pix_fmt_mp->height,
671 MTK_VDEC_MIN_H,
672 MTK_VDEC_MAX_H);
673 pix_fmt_mp->width = clamp(pix_fmt_mp->width,
674 MTK_VDEC_MIN_W,
675 MTK_VDEC_MAX_W);
676
677 tmp_w = pix_fmt_mp->width;
678 tmp_h = pix_fmt_mp->height;
679
> 680 if (ctx->dev->vdec_pdata->uses_stateless_api ||
681 ctx->state >= MTK_STATE_HEADER) {
682 v4l_bound_align_image(&pix_fmt_mp->width,
683 MTK_VDEC_MIN_W,
684 MTK_VDEC_MAX_W, 4,
685 &pix_fmt_mp->height,
686 MTK_VDEC_MIN_H,
687 MTK_VDEC_MAX_H, 5, 6);
688
689 if (pix_fmt_mp->width < tmp_w &&
690 (pix_fmt_mp->width + 16) <= MTK_VDEC_MAX_W)
691 pix_fmt_mp->width += 16;
692 if (pix_fmt_mp->height < tmp_h &&
693 (pix_fmt_mp->height + 32) <= MTK_VDEC_MAX_H)
694 pix_fmt_mp->height += 32;
695 } else {
696 /*
697 * Find next closer width align 64, height align 64, size align
698 * 64 rectangle
699 * Note: This only get default value, the real HW needed value
700 * only available when ctx in MTK_STATE_HEADER state
701 */
702 v4l_bound_align_image(&pix_fmt_mp->width,
703 MTK_VDEC_MIN_W,
704 MTK_VDEC_MAX_W, 6,
705 &pix_fmt_mp->height,
706 MTK_VDEC_MIN_H,
707 MTK_VDEC_MAX_H, 6, 9);
708
709 if (pix_fmt_mp->width < tmp_w &&
710 (pix_fmt_mp->width + 64) <= MTK_VDEC_MAX_W)
711 pix_fmt_mp->width += 64;
712 if (pix_fmt_mp->height < tmp_h &&
713 (pix_fmt_mp->height + 64) <= MTK_VDEC_MAX_H)
714 pix_fmt_mp->height += 64;
715 }
716
717 mtk_v4l2_debug(0,
718 "before resize width=%d, height=%d, after resize width=%d, height=%d, sizeimage=%d",
719 tmp_w, tmp_h, pix_fmt_mp->width,
720 pix_fmt_mp->height,
721 pix_fmt_mp->width * pix_fmt_mp->height);
722
723 pix_fmt_mp->num_planes = fmt->num_planes;
724 pix_fmt_mp->plane_fmt[0].sizeimage =
725 pix_fmt_mp->width * pix_fmt_mp->height;
726 pix_fmt_mp->plane_fmt[0].bytesperline = pix_fmt_mp->width;
727
728 if (pix_fmt_mp->num_planes == 2) {
729 pix_fmt_mp->plane_fmt[1].sizeimage =
730 (pix_fmt_mp->width * pix_fmt_mp->height) / 2;
731 pix_fmt_mp->plane_fmt[1].bytesperline =
732 pix_fmt_mp->width;
733 }
734 }
735
736 pix_fmt_mp->flags = 0;
737 return 0;
738 }
739

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (5.08 kB)
.config.gz (76.67 kB)
Download all attachments