media: Add V4L2_TYPE_IS_CAPTURE helper
authorEzequiel Garcia <ezequiel@collabora.com>
Wed, 24 Jun 2020 19:28:00 +0000 (21:28 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Sun, 19 Jul 2020 06:13:24 +0000 (08:13 +0200)
It's all too easy to get confused by the V4L2_TYPE_IS_OUTPUT
macro, when it's used as !V4L2_TYPE_IS_OUTPUT.

Reduce the risk of confusion with macro to explicitly
check for the CAPTURE queue type case.

This change does not affect functionality, and it's
only intended to make the code more readable.

Suggested-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil-cisco@xs4all.nl: checkpatch: align with parenthesis]
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
13 files changed:
drivers/media/common/videobuf2/videobuf2-v4l2.c
drivers/media/platform/exynos-gsc/gsc-core.c
drivers/media/platform/exynos-gsc/gsc-m2m.c
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
drivers/media/platform/rcar_jpu.c
drivers/media/platform/sti/hva/hva-v4l2.c
drivers/media/platform/ti-vpe/vpe.c
drivers/media/test-drivers/vicodec/vicodec-core.c
drivers/media/v4l2-core/v4l2-mem2mem.c
drivers/staging/media/hantro/hantro_v4l2.c
drivers/staging/media/rkvdec/rkvdec.c
include/uapi/linux/videodev2.h

index 57aa183bd19835f8269a88c9fc64e624a2421724..30caad27281e1ab220cbb1e75080b28b0fbf3c07 100644 (file)
@@ -97,7 +97,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
        unsigned int bytesused;
        unsigned int plane;
 
-       if (!V4L2_TYPE_IS_OUTPUT(b->type))
+       if (V4L2_TYPE_IS_CAPTURE(b->type))
                return 0;
 
        if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
@@ -311,7 +311,7 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b
 
        /* Zero flags that we handle */
        vbuf->flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
-       if (!vb->vb2_queue->copy_timestamp || !V4L2_TYPE_IS_OUTPUT(b->type)) {
+       if (!vb->vb2_queue->copy_timestamp || V4L2_TYPE_IS_CAPTURE(b->type)) {
                /*
                 * Non-COPY timestamps and non-OUTPUT queues will get
                 * their timestamp and timestamp source flags from the
index f6650b45bc3d2184898f4d1e8169827c8001f779..9f41c2e7097a649a206db31fad99b22d59372fe7 100644 (file)
@@ -577,7 +577,7 @@ int gsc_try_selection(struct gsc_ctx *ctx, struct v4l2_selection *s)
        v4l_bound_align_image(&tmp_w, min_w, max_w, mod_x,
                              &tmp_h, min_h, max_h, mod_y, 0);
 
-       if (!V4L2_TYPE_IS_OUTPUT(s->type) &&
+       if (V4L2_TYPE_IS_CAPTURE(s->type) &&
            (ctx->gsc_ctrls.rotate->val == 90 ||
             ctx->gsc_ctrls.rotate->val == 270))
                gsc_check_crop_change(tmp_h, tmp_w,
index e2c162635f7278826052dd684d41e3236471d688..27a3c92c73bce4c031546ecb8bac185b603178e1 100644 (file)
@@ -255,7 +255,7 @@ static int gsc_m2m_buf_prepare(struct vb2_buffer *vb)
        if (IS_ERR(frame))
                return PTR_ERR(frame);
 
-       if (!V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
+       if (V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type)) {
                for (i = 0; i < frame->fmt->num_planes; i++)
                        vb2_set_plane_payload(vb, i, frame->payload[i]);
        }
index f82a81a3bdee2f1ae6d312278ecb8f901d272bc1..61fed1e35a005dcf4d0f841553c90a6a1a567538 100644 (file)
@@ -731,7 +731,7 @@ static void mtk_jpeg_stop_streaming(struct vb2_queue *q)
         * subsampling. Update capture queue when the stream is off.
         */
        if (ctx->state == MTK_JPEG_SOURCE_CHANGE &&
-           !V4L2_TYPE_IS_OUTPUT(q->type)) {
+           V4L2_TYPE_IS_CAPTURE(q->type)) {
                struct mtk_jpeg_src_buf *src_buf;
 
                vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
index bb9caaf513bcb0787cfeef372ace0d343d932683..724c7333b6e5a75f6838d7c76553e8680df9d078 100644 (file)
@@ -193,7 +193,7 @@ static const struct mtk_mdp_fmt *mtk_mdp_try_fmt_mplane(struct mtk_mdp_ctx *ctx,
 
        pix_mp->field = V4L2_FIELD_NONE;
        pix_mp->pixelformat = fmt->pixelformat;
-       if (!V4L2_TYPE_IS_OUTPUT(f->type)) {
+       if (V4L2_TYPE_IS_CAPTURE(f->type)) {
                pix_mp->colorspace = ctx->colorspace;
                pix_mp->xfer_func = ctx->xfer_func;
                pix_mp->ycbcr_enc = ctx->ycbcr_enc;
@@ -327,9 +327,8 @@ static int mtk_mdp_try_crop(struct mtk_mdp_ctx *ctx, u32 type,
        mtk_mdp_bound_align_image(&new_w, min_w, max_w, align_w,
                                  &new_h, min_h, max_h, align_h);
 
-       if (!V4L2_TYPE_IS_OUTPUT(type) &&
-               (ctx->ctrls.rotate->val == 90 ||
-               ctx->ctrls.rotate->val == 270))
+       if (V4L2_TYPE_IS_CAPTURE(type) &&
+           (ctx->ctrls.rotate->val == 90 || ctx->ctrls.rotate->val == 270))
                mtk_mdp_check_crop_change(new_h, new_w,
                                          &r->width, &r->height);
        else
index 5250a14324e917ce645a1122f0c0779aa8d98cc1..9b99ff368698098abce61f4d301bdd1094a3a9cc 100644 (file)
@@ -1066,7 +1066,7 @@ static int jpu_buf_prepare(struct vb2_buffer *vb)
                }
 
                /* decoder capture queue */
-               if (!ctx->encoder && !V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type))
+               if (!ctx->encoder && V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type))
                        vb2_set_plane_payload(vb, i, size);
        }
 
index 197b99d8fd9cf61623d539c81f48fbf1f5a72dcb..bb34d6997d99158d86d077bdc7331a593d63749a 100644 (file)
@@ -1087,7 +1087,7 @@ static void hva_stop_streaming(struct vb2_queue *vq)
 
        if ((V4L2_TYPE_IS_OUTPUT(vq->type) &&
             vb2_is_streaming(&ctx->fh.m2m_ctx->cap_q_ctx.q)) ||
-           (!V4L2_TYPE_IS_OUTPUT(vq->type) &&
+           (V4L2_TYPE_IS_CAPTURE(vq->type) &&
             vb2_is_streaming(&ctx->fh.m2m_ctx->out_q_ctx.q))) {
                dev_dbg(dev, "%s %s out=%d cap=%d\n",
                        ctx->name, to_type_str(vq->type),
index cff2fcd6d812a49ca125cf5a749100bec3fabae8..346f8212791cf843280f8daaeefd031ee9acb04a 100644 (file)
@@ -1576,7 +1576,7 @@ static int vpe_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 
        *f = q_data->format;
 
-       if (!V4L2_TYPE_IS_OUTPUT(f->type)) {
+       if (V4L2_TYPE_IS_CAPTURE(f->type)) {
                struct vpe_q_data *s_q_data;
                struct v4l2_pix_format_mplane *spix;
 
index e879290727ef449ca03e10940cd16b3feec42914..8941d73f6611db4a54cda773e0cadcedf0d5fcbd 100644 (file)
@@ -1442,7 +1442,7 @@ static void vicodec_buf_queue(struct vb2_buffer *vb)
                .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
        };
 
-       if (!V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type) &&
+       if (V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type) &&
            vb2_is_streaming(vb->vb2_queue) &&
            v4l2_m2m_dst_buf_is_last(ctx->fh.m2m_ctx)) {
                unsigned int i;
@@ -1479,7 +1479,7 @@ static void vicodec_buf_queue(struct vb2_buffer *vb)
         * in the compressed stream
         */
        if (ctx->is_stateless || ctx->is_enc ||
-           !V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
+           V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type)) {
                v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
                return;
        }
@@ -1574,7 +1574,7 @@ static int vicodec_start_streaming(struct vb2_queue *q,
        state->gop_cnt = 0;
 
        if ((V4L2_TYPE_IS_OUTPUT(q->type) && !ctx->is_enc) ||
-           (!V4L2_TYPE_IS_OUTPUT(q->type) && ctx->is_enc))
+           (V4L2_TYPE_IS_CAPTURE(q->type) && ctx->is_enc))
                return 0;
 
        if (info->id == V4L2_PIX_FMT_FWHT ||
index 62ac9424c92a754b8602d20440dacc4a4900bd5f..95a8f2dc5341d490996c278d40343f01b3913de8 100644 (file)
@@ -556,7 +556,7 @@ int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
        ret = vb2_querybuf(vq, buf);
 
        /* Adjust MMAP memory offsets for the CAPTURE queue */
-       if (buf->memory == V4L2_MEMORY_MMAP && !V4L2_TYPE_IS_OUTPUT(vq->type)) {
+       if (buf->memory == V4L2_MEMORY_MMAP && V4L2_TYPE_IS_CAPTURE(vq->type)) {
                if (V4L2_TYPE_IS_MULTIPLANAR(vq->type)) {
                        for (i = 0; i < buf->length; ++i)
                                buf->m.planes[i].m.mem_offset
@@ -712,7 +712,7 @@ int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
        int ret;
 
        vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
-       if (!V4L2_TYPE_IS_OUTPUT(vq->type) &&
+       if (V4L2_TYPE_IS_CAPTURE(vq->type) &&
            (buf->flags & V4L2_BUF_FLAG_REQUEST_FD)) {
                dprintk("%s: requests cannot be used with capture buffers\n",
                        __func__);
@@ -729,7 +729,7 @@ int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
         * buffer as DONE with LAST flag since it won't be queued on the
         * device.
         */
-       if (!V4L2_TYPE_IS_OUTPUT(vq->type) &&
+       if (V4L2_TYPE_IS_CAPTURE(vq->type) &&
            vb2_is_streaming(vq) && !vb2_start_streaming_called(vq) &&
           (v4l2_m2m_has_stopped(m2m_ctx) || v4l2_m2m_dst_buf_is_last(m2m_ctx)))
                v4l2_m2m_force_last_buf_done(m2m_ctx, vq);
index f28a94e2fa934d6454d59cfe6ffd5fabe6f68444..63859e8a0923ec0eabdc263ddc3f8d3f0d89f9c0 100644 (file)
@@ -237,7 +237,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
                          enum v4l2_buf_type type)
 {
        const struct hantro_fmt *fmt, *vpu_fmt;
-       bool capture = !V4L2_TYPE_IS_OUTPUT(type);
+       bool capture = V4L2_TYPE_IS_CAPTURE(type);
        bool coded;
 
        coded = capture == hantro_is_encoder_ctx(ctx);
index 225eeca73356e50686d7c943de21c6f686ed6d25..fd68671f02861aef4749eb562cb628f544816fb5 100644 (file)
@@ -489,7 +489,7 @@ static int rkvdec_start_streaming(struct vb2_queue *q, unsigned int count)
        const struct rkvdec_coded_fmt_desc *desc;
        int ret;
 
-       if (!V4L2_TYPE_IS_OUTPUT(q->type))
+       if (V4L2_TYPE_IS_CAPTURE(q->type))
                return 0;
 
        desc = ctx->coded_fmt_desc;
index 303805438814f9cbdf7800a784a226bc6723ffb3..c7b70ff53bc1dd0f3acdd1428138a7a0ca10c0a3 100644 (file)
@@ -171,6 +171,8 @@ enum v4l2_buf_type {
         || (type) == V4L2_BUF_TYPE_SDR_OUTPUT                  \
         || (type) == V4L2_BUF_TYPE_META_OUTPUT)
 
+#define V4L2_TYPE_IS_CAPTURE(type) (!V4L2_TYPE_IS_OUTPUT(type))
+
 enum v4l2_tuner_type {
        V4L2_TUNER_RADIO             = 1,
        V4L2_TUNER_ANALOG_TV         = 2,