Skip to content

Commit d35c64e

Browse files
Kwiboohverkuil
authored andcommitted
media: rkvdec: Add get_image_fmt ops
Add support for a get_image_fmt() ops that returns the required image format. The CAPTURE format is reset when the required image format changes and the buffer queue is not busy. Signed-off-by: Jonas Karlman <[email protected]> Tested-by: Nicolas Dufresne <[email protected]> Reviewed-by: Jonas Karlman <[email protected]> Co-developed-by: Nicolas Dufresne <[email protected]> Signed-off-by: Nicolas Dufresne <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent d43d7db commit d35c64e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

drivers/staging/media/rkvdec/rkvdec.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ static bool rkvdec_image_fmt_match(enum rkvdec_image_fmt fmt1,
3434
fmt1 == RKVDEC_IMG_FMT_ANY;
3535
}
3636

37+
static bool rkvdec_image_fmt_changed(struct rkvdec_ctx *ctx,
38+
enum rkvdec_image_fmt image_fmt)
39+
{
40+
if (image_fmt == RKVDEC_IMG_FMT_ANY)
41+
return false;
42+
43+
return ctx->image_fmt != image_fmt;
44+
}
45+
3746
static u32 rkvdec_enum_decoded_fmt(struct rkvdec_ctx *ctx, int index,
3847
enum rkvdec_image_fmt image_fmt)
3948
{
@@ -118,8 +127,34 @@ static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
118127
return 0;
119128
}
120129

130+
static int rkvdec_s_ctrl(struct v4l2_ctrl *ctrl)
131+
{
132+
struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl);
133+
const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc;
134+
enum rkvdec_image_fmt image_fmt;
135+
struct vb2_queue *vq;
136+
137+
/* Check if this change requires a capture format reset */
138+
if (!desc->ops->get_image_fmt)
139+
return 0;
140+
141+
image_fmt = desc->ops->get_image_fmt(ctx, ctrl);
142+
if (rkvdec_image_fmt_changed(ctx, image_fmt)) {
143+
vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
144+
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
145+
if (vb2_is_busy(vq))
146+
return -EBUSY;
147+
148+
ctx->image_fmt = image_fmt;
149+
rkvdec_reset_decoded_fmt(ctx);
150+
}
151+
152+
return 0;
153+
}
154+
121155
static const struct v4l2_ctrl_ops rkvdec_ctrl_ops = {
122156
.try_ctrl = rkvdec_try_ctrl,
157+
.s_ctrl = rkvdec_s_ctrl,
123158
};
124159

125160
static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] = {

drivers/staging/media/rkvdec/rkvdec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct rkvdec_coded_fmt_ops {
7373
struct vb2_v4l2_buffer *dst_buf,
7474
enum vb2_buffer_state result);
7575
int (*try_ctrl)(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl);
76+
enum rkvdec_image_fmt (*get_image_fmt)(struct rkvdec_ctx *ctx,
77+
struct v4l2_ctrl *ctrl);
7678
};
7779

7880
enum rkvdec_image_fmt {

0 commit comments

Comments
 (0)