Skip to content

Commit

Permalink
media: Add V4L2_TYPE_IS_CAPTURE helper
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Ezequiel Garcia <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
[[email protected]: checkpatch: align with parenthesis]
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
ezequielgarcia authored and sigmaris committed Aug 8, 2020
1 parent 96d89dd commit 457a3d9
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions drivers/media/common/videobuf2/videobuf2-v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/platform/exynos-gsc/gsc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/platform/exynos-gsc/gsc-m2m.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/platform/rcar_jpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/media/platform/sti/hva/hva-v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/platform/ti-vpe/vpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions drivers/media/test-drivers/vicodec/vicodec-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ||
Expand Down
6 changes: 3 additions & 3 deletions drivers/media/v4l2-core/v4l2-mem2mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/media/hantro/hantro_v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/media/rkvdec/rkvdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/uapi/linux/videodev2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 457a3d9

Please sign in to comment.