diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-02-15 05:26:49 +0100 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2021-03-11 11:59:48 +0100 |
commit | a9512b261afd1aec188d3b3a760b69115e0d1209 (patch) | |
tree | e1272383e7fd317495426ed4154c7d3de38827c5 /drivers/staging/media/imx | |
parent | 7edcce6cc082f5b164382e0ca3291ade5c164fdb (diff) |
media: imx: capture: Simplify capture_validate_fmt() implementation
capture_validate_fmt() delegates the media bus format to pixel format
conversion to __capture_legacy_try_fmt(). It turns out that this can be
simplified quite a lot:
- The format lookup from media bus code can be performed by the recently
added capture_find_format() function instead of receiving the
information from a side effect of __capture_legacy_try_fmt().
- The validation of the pixel format size isn't needed, as they
duplicate the validation of the compose rectangle. The pixel format
size is directly derived from the size of the incoming stream, which
is stored in the compose rectangle. If the compose rectangle is valid,
the pixel format size will be valid too.
By removing the validation of the pixel format size and using
capture_find_format() to lookup the format, we can stop using
__capture_legacy_try_fmt() and simplify capture_validate_fmt().
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Diffstat (limited to 'drivers/staging/media/imx')
-rw-r--r-- | drivers/staging/media/imx/imx-media-capture.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c index 6350acd0dba9..ed4e51b93dc5 100644 --- a/drivers/staging/media/imx/imx-media-capture.c +++ b/drivers/staging/media/imx/imx-media-capture.c @@ -537,27 +537,35 @@ static int capture_validate_fmt(struct capture_priv *priv) { struct v4l2_subdev_format fmt_src; const struct imx_media_pixfmt *cc; - struct v4l2_rect compose; - struct v4l2_pix_format pixfmt; int ret; + /* Retrieve the media bus format on the source subdev. */ fmt_src.pad = priv->src_sd_pad; fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE; ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src); if (ret) return ret; - v4l2_fill_pix_format(&pixfmt, &fmt_src.format); + /* + * Verify that the media bus size matches the size set on the video + * node. It is sufficient to check the compose rectangle size without + * checking the rounded size from vdev.fmt, as the rounded size is + * derived directly from the compose rectangle size, and will thus + * always match if the compose rectangle matches. + */ + if (priv->vdev.compose.width != fmt_src.format.width || + priv->vdev.compose.height != fmt_src.format.height) + return -EPIPE; + + /* + * Verify that the media bus code is compatible with the pixel format + * set on the video node. + */ + cc = capture_find_format(fmt_src.format.code, 0); + if (!cc || priv->vdev.cc->cs != cc->cs) + return -EPIPE; - ret = __capture_legacy_try_fmt(priv, &fmt_src, &pixfmt, &cc, &compose); - if (ret) - return ret; - - return (priv->vdev.fmt.width != pixfmt.width || - priv->vdev.fmt.height != pixfmt.height || - priv->vdev.cc->cs != cc->cs || - priv->vdev.compose.width != compose.width || - priv->vdev.compose.height != compose.height) ? -EPIPE : 0; + return 0; } static int capture_start_streaming(struct vb2_queue *vq, unsigned int count) |