media: mtk-vcodec: venc: support ENUM_FRAMESIZES on OUTPUT formats
authorAlexandre Courbot <acourbot@chromium.org>
Fri, 21 Aug 2020 10:36:06 +0000 (12:36 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Sat, 26 Sep 2020 08:10:40 +0000 (10:10 +0200)
v4l2-compliance requires ENUM_FRAMESIZES to support OUTPUT formats.
Reuse mtk_venc_find_format() to make sure both queues are considered
when serving an ENUM_FRAMESIZES.

[hverkuil: fixed some checkpatch alignment warnings]

Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
Acked-by: Tiffany Lin <tiffany.lin@mediatek.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c

index 3329ccd..7c6585a 100644 (file)
@@ -123,28 +123,44 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f,
        return 0;
 }
 
+static const struct mtk_video_fmt *
+mtk_venc_find_format(u32 fourcc, const struct mtk_vcodec_enc_pdata *pdata)
+{
+       const struct mtk_video_fmt *fmt;
+       unsigned int k;
+
+       for (k = 0; k < pdata->num_capture_formats; k++) {
+               fmt = &pdata->capture_formats[k];
+               if (fmt->fourcc == fourcc)
+                       return fmt;
+       }
+
+       for (k = 0; k < pdata->num_output_formats; k++) {
+               fmt = &pdata->output_formats[k];
+               if (fmt->fourcc == fourcc)
+                       return fmt;
+       }
+
+       return NULL;
+}
+
 static int vidioc_enum_framesizes(struct file *file, void *fh,
                                  struct v4l2_frmsizeenum *fsize)
 {
-       const struct mtk_vcodec_enc_pdata *pdata =
-               fh_to_ctx(fh)->dev->venc_pdata;
-       int i = 0;
+       const struct mtk_video_fmt *fmt;
 
        if (fsize->index != 0)
                return -EINVAL;
 
-       for (i = 0; i < pdata->num_capture_formats; ++i) {
-               const struct mtk_video_fmt *fmt = &pdata->capture_formats[i];
+       fmt = mtk_venc_find_format(fsize->pixel_format,
+                                  fh_to_ctx(fh)->dev->venc_pdata);
+       if (!fmt)
+               return -EINVAL;
 
-               if (fsize->pixel_format != fmt->fourcc)
-                       continue;
+       fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
+       fsize->stepwise = mtk_venc_framesizes;
 
-               fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
-               fsize->stepwise = mtk_venc_framesizes;
-               return 0;
-       }
-
-       return -EINVAL;
+       return 0;
 }
 
 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
@@ -222,27 +238,6 @@ static struct mtk_q_data *mtk_venc_get_q_data(struct mtk_vcodec_ctx *ctx,
        return &ctx->q_data[MTK_Q_DATA_DST];
 }
 
-static const struct mtk_video_fmt *
-mtk_venc_find_format(struct v4l2_format *f, const struct mtk_vcodec_enc_pdata *pdata)
-{
-       const struct mtk_video_fmt *fmt;
-       unsigned int k;
-
-       for (k = 0; k < pdata->num_capture_formats; k++) {
-               fmt = &pdata->capture_formats[k];
-               if (fmt->fourcc == f->fmt.pix.pixelformat)
-                       return fmt;
-       }
-
-       for (k = 0; k < pdata->num_output_formats; k++) {
-               fmt = &pdata->output_formats[k];
-               if (fmt->fourcc == f->fmt.pix.pixelformat)
-                       return fmt;
-       }
-
-       return NULL;
-}
-
 /* V4L2 specification suggests the driver corrects the format struct if any of
  * the dimensions is unsupported
  */
@@ -403,7 +398,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, void *priv,
                return -EINVAL;
        }
 
-       fmt = mtk_venc_find_format(f, pdata);
+       fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
        if (!fmt) {
                fmt = &ctx->dev->venc_pdata->capture_formats[0];
                f->fmt.pix.pixelformat = fmt->fourcc;
@@ -467,7 +462,7 @@ static int vidioc_venc_s_fmt_out(struct file *file, void *priv,
                return -EINVAL;
        }
 
-       fmt = mtk_venc_find_format(f, pdata);
+       fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
        if (!fmt) {
                fmt = &ctx->dev->venc_pdata->output_formats[0];
                f->fmt.pix.pixelformat = fmt->fourcc;
@@ -550,7 +545,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
        struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
        const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
 
-       fmt = mtk_venc_find_format(f, pdata);
+       fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
        if (!fmt) {
                fmt = &ctx->dev->venc_pdata->capture_formats[0];
                f->fmt.pix.pixelformat = fmt->fourcc;
@@ -570,7 +565,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
        struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
        const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
 
-       fmt = mtk_venc_find_format(f, pdata);
+       fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
        if (!fmt) {
                fmt = &ctx->dev->venc_pdata->output_formats[0];
                f->fmt.pix.pixelformat = fmt->fourcc;