Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: mediatek: vcodec: decoder: Embed framesize inside mtk_video_fmt

Right now the decoder maintains two separate lists for supported pixel
formats and frame sizes. Getting the supported frame sizes for the
current set format is a bit convoluted, requiring a search through
the separate frame size list. The frame sizes are used to clamp and
align requested resolutions.

Instead, the frame size structure could be embedded inside the pixel
format structure. Getting one also gets the other. And since the
the driver already keeps pointers to the current set format, getting
the frame sizes becomes straightforward.

Do just that. Move v4l2_frmsize_stepwise inside mtk_video_fmt, and get
rid of mtk_codec_framesizes.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

authored by

Chen-Yu Tsai and committed by
Mauro Carvalho Chehab
cfce5b18 e8d266d5

+22 -82
+9 -27
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
··· 261 261 } 262 262 } 263 263 264 - static const struct v4l2_frmsize_stepwise *mtk_vdec_get_frmsize(struct mtk_vcodec_ctx *ctx, 265 - u32 pixfmt) 266 - { 267 - const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata; 268 - int i; 269 - 270 - for (i = 0; i < *dec_pdata->num_framesizes; ++i) 271 - if (pixfmt == dec_pdata->vdec_framesizes[i].fourcc) 272 - return &dec_pdata->vdec_framesizes[i].stepwise; 273 - 274 - /* 275 - * This should never happen since vidioc_try_fmt_vid_out_mplane() 276 - * always passes through a valid format for the output side, and 277 - * for the capture side, a valid output format should already have 278 - * been set. 279 - */ 280 - WARN_ONCE(1, "Unsupported format requested.\n"); 281 - return &dec_pdata->vdec_framesizes[0].stepwise; 282 - } 283 - 284 264 static int vidioc_try_fmt(struct mtk_vcodec_ctx *ctx, struct v4l2_format *f, 285 265 const struct mtk_video_fmt *fmt) 286 266 { 287 267 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp; 288 268 const struct v4l2_frmsize_stepwise *frmsize; 289 - u32 fourcc; 290 269 291 270 pix_fmt_mp->field = V4L2_FIELD_NONE; 292 271 293 272 /* Always apply frame size constraints from the coded side */ 294 273 if (V4L2_TYPE_IS_OUTPUT(f->type)) 295 - fourcc = f->fmt.pix_mp.pixelformat; 274 + frmsize = &fmt->frmsize; 296 275 else 297 - fourcc = ctx->q_data[MTK_Q_DATA_SRC].fmt->fourcc; 276 + frmsize = &ctx->q_data[MTK_Q_DATA_SRC].fmt->frmsize; 298 277 299 - frmsize = mtk_vdec_get_frmsize(ctx, fourcc); 300 278 pix_fmt_mp->width = clamp(pix_fmt_mp->width, MTK_VDEC_MIN_W, frmsize->max_width); 301 279 pix_fmt_mp->height = clamp(pix_fmt_mp->height, MTK_VDEC_MIN_H, frmsize->max_height); 302 280 ··· 574 596 if (fsize->index != 0) 575 597 return -EINVAL; 576 598 577 - for (i = 0; i < *dec_pdata->num_framesizes; ++i) { 578 - if (fsize->pixel_format != dec_pdata->vdec_framesizes[i].fourcc) 599 + for (i = 0; i < *dec_pdata->num_formats; i++) { 600 + if (fsize->pixel_format != dec_pdata->vdec_formats[i].fourcc) 579 601 continue; 580 602 603 + /* Only coded formats have frame sizes set */ 604 + if (!dec_pdata->vdec_formats[i].frmsize.max_width) 605 + return -ENOTTY; 606 + 581 607 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; 582 - fsize->stepwise = dec_pdata->vdec_framesizes[i].stepwise; 608 + fsize->stepwise = dec_pdata->vdec_formats[i].frmsize; 583 609 584 610 mtk_v4l2_debug(1, "%x, %d %d %d %d %d %d", 585 611 ctx->dev->dec_capability,
+6 -23
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
··· 17 17 .type = MTK_FMT_DEC, 18 18 .num_planes = 1, 19 19 .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, 20 + .frmsize = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16, 21 + MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 }, 20 22 }, 21 23 { 22 24 .fourcc = V4L2_PIX_FMT_VP8, 23 25 .type = MTK_FMT_DEC, 24 26 .num_planes = 1, 25 27 .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, 28 + .frmsize = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16, 29 + MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 }, 26 30 }, 27 31 { 28 32 .fourcc = V4L2_PIX_FMT_VP9, 29 33 .type = MTK_FMT_DEC, 30 34 .num_planes = 1, 31 35 .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, 36 + .frmsize = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16, 37 + MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 }, 32 38 }, 33 39 { 34 40 .fourcc = V4L2_PIX_FMT_MT21C, ··· 48 42 49 43 #define DEFAULT_OUT_FMT_IDX 0 50 44 #define DEFAULT_CAP_FMT_IDX 3 51 - 52 - static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = { 53 - { 54 - .fourcc = V4L2_PIX_FMT_H264, 55 - .stepwise = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16, 56 - MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 }, 57 - }, 58 - { 59 - .fourcc = V4L2_PIX_FMT_VP8, 60 - .stepwise = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16, 61 - MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 }, 62 - }, 63 - { 64 - .fourcc = V4L2_PIX_FMT_VP9, 65 - .stepwise = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16, 66 - MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 }, 67 - }, 68 - }; 69 - 70 - static const unsigned int num_supported_framesize = 71 - ARRAY_SIZE(mtk_vdec_framesizes); 72 45 73 46 /* 74 47 * This function tries to clean all display buffers, the buffers will return ··· 603 618 .num_formats = &num_supported_formats, 604 619 .default_out_fmt = &mtk_video_formats[DEFAULT_OUT_FMT_IDX], 605 620 .default_cap_fmt = &mtk_video_formats[DEFAULT_CAP_FMT_IDX], 606 - .vdec_framesizes = mtk_vdec_framesizes, 607 - .num_framesizes = &num_supported_framesize, 608 621 .worker = mtk_vdec_worker, 609 622 .flush_decoder = mtk_vdec_flush_decoder, 610 623 .is_subdev_supported = false,
+6 -17
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
··· 112 112 #define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) 113 113 114 114 static struct mtk_video_fmt mtk_video_formats[5]; 115 - static struct mtk_codec_framesizes mtk_vdec_framesizes[3]; 116 115 117 116 static struct mtk_video_fmt default_out_format; 118 117 static struct mtk_video_fmt default_cap_format; 119 118 static unsigned int num_formats; 120 - static unsigned int num_framesizes; 121 119 122 120 static const struct v4l2_frmsize_stepwise stepwise_fhd = { 123 121 .min_width = MTK_VDEC_MIN_W, ··· 346 348 struct mtk_vcodec_dev *dev = ctx->dev; 347 349 const struct mtk_vcodec_dec_pdata *pdata = dev->vdec_pdata; 348 350 int count_formats = *pdata->num_formats; 349 - int count_framesizes = *pdata->num_framesizes; 350 351 351 352 switch (fourcc) { 352 353 case V4L2_PIX_FMT_H264_SLICE: ··· 354 357 mtk_video_formats[count_formats].fourcc = fourcc; 355 358 mtk_video_formats[count_formats].type = MTK_FMT_DEC; 356 359 mtk_video_formats[count_formats].num_planes = 1; 360 + mtk_video_formats[count_formats].frmsize = stepwise_fhd; 357 361 358 - mtk_vdec_framesizes[count_framesizes].fourcc = fourcc; 359 - mtk_vdec_framesizes[count_framesizes].stepwise = stepwise_fhd; 360 362 if (!(ctx->dev->dec_capability & VCODEC_CAPABILITY_4K_DISABLED) && 361 363 fourcc != V4L2_PIX_FMT_VP8_FRAME) { 362 - mtk_vdec_framesizes[count_framesizes].stepwise.max_width = 364 + mtk_video_formats[count_formats].frmsize.max_width = 363 365 VCODEC_DEC_4K_CODED_WIDTH; 364 - mtk_vdec_framesizes[count_framesizes].stepwise.max_height = 366 + mtk_video_formats[count_formats].frmsize.max_height = 365 367 VCODEC_DEC_4K_CODED_HEIGHT; 366 368 } 367 - num_framesizes++; 368 369 break; 369 370 case V4L2_PIX_FMT_MM21: 370 371 case V4L2_PIX_FMT_MT21C: ··· 376 381 } 377 382 378 383 num_formats++; 379 - mtk_v4l2_debug(3, "num_formats: %d num_frames:%d dec_capability: 0x%x", 380 - count_formats, count_framesizes, ctx->dev->dec_capability); 384 + mtk_v4l2_debug(3, "num_formats: %d dec_capability: 0x%x", 385 + count_formats, ctx->dev->dec_capability); 381 386 } 382 387 383 388 static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx) 384 389 { 385 390 int cap_format_count = 0, out_format_count = 0; 386 391 387 - if (num_formats && num_framesizes) 392 + if (num_formats) 388 393 return; 389 394 390 395 if (ctx->dev->dec_capability & MTK_VDEC_FORMAT_MM21) { ··· 463 468 .num_formats = &num_formats, 464 469 .default_out_fmt = &default_out_format, 465 470 .default_cap_fmt = &default_cap_format, 466 - .vdec_framesizes = mtk_vdec_framesizes, 467 - .num_framesizes = &num_framesizes, 468 471 .uses_stateless_api = true, 469 472 .worker = mtk_vdec_worker, 470 473 .flush_decoder = mtk_vdec_flush_decoder, ··· 481 488 .num_formats = &num_formats, 482 489 .default_out_fmt = &default_out_format, 483 490 .default_cap_fmt = &default_cap_format, 484 - .vdec_framesizes = mtk_vdec_framesizes, 485 - .num_framesizes = &num_framesizes, 486 491 .uses_stateless_api = true, 487 492 .worker = mtk_vdec_worker, 488 493 .flush_decoder = mtk_vdec_flush_decoder, ··· 498 507 .num_formats = &num_formats, 499 508 .default_out_fmt = &default_out_format, 500 509 .default_cap_fmt = &default_cap_format, 501 - .vdec_framesizes = mtk_vdec_framesizes, 502 - .num_framesizes = &num_framesizes, 503 510 .uses_stateless_api = true, 504 511 .worker = mtk_vdec_worker, 505 512 .flush_decoder = mtk_vdec_flush_decoder,
+1 -15
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
··· 126 126 enum mtk_fmt_type type; 127 127 u32 num_planes; 128 128 u32 flags; 129 - }; 130 - 131 - /* 132 - * struct mtk_codec_framesizes - Structure used to store information about 133 - * framesizes 134 - */ 135 - struct mtk_codec_framesizes { 136 - u32 fourcc; 137 - struct v4l2_frmsize_stepwise stepwise; 129 + struct v4l2_frmsize_stepwise frmsize; 138 130 }; 139 131 140 132 /* ··· 363 371 * @default_out_fmt: default output buffer format 364 372 * @default_cap_fmt: default capture buffer format 365 373 * 366 - * @vdec_framesizes: supported video decoder frame sizes 367 - * @num_framesizes: count of video decoder frame sizes 368 - * 369 374 * @hw_arch: hardware arch is used to separate pure_sin_core and lat_sin_core 370 375 * 371 376 * @is_subdev_supported: whether support parent-node architecture(subdev) ··· 384 395 const int *num_formats; 385 396 const struct mtk_video_fmt *default_out_fmt; 386 397 const struct mtk_video_fmt *default_cap_fmt; 387 - 388 - const struct mtk_codec_framesizes *vdec_framesizes; 389 - const int *num_framesizes; 390 398 391 399 enum mtk_vdec_hw_arch hw_arch; 392 400