Message ID | 20240409064431.16909-6-yunfei.dong@mediatek.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | media: change the calculation method of sizeimage | expand |
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;
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;
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(-)