Skip to content

Commit 7040ed4

Browse files
Benjamin Gaignardmchehab
authored andcommitted
media: verisilicon: Check AV1 bitstreams bit depth
The driver supports 8 and 10 bits bitstreams, make sure to discard other cases. It could happens that userland test if V4L2_CID_STATELESS_AV1_SEQUENCE exists without setting bit_depth field in this case use HANTRO_DEFAULT_BIT_DEPTH value. Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
1 parent 53421e7 commit 7040ed4

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

drivers/media/platform/verisilicon/hantro_drv.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,13 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
275275
/* We only support profile 0 */
276276
if (dec_params->profile != 0)
277277
return -EINVAL;
278+
} else if (ctrl->id == V4L2_CID_STATELESS_AV1_SEQUENCE) {
279+
const struct v4l2_ctrl_av1_sequence *sequence = ctrl->p_new.p_av1_sequence;
280+
281+
if (sequence->bit_depth != 8 && sequence->bit_depth != 10)
282+
return -EINVAL;
278283
}
284+
279285
return 0;
280286
}
281287

@@ -346,6 +352,30 @@ static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
346352
return 0;
347353
}
348354

355+
static int hantro_av1_s_ctrl(struct v4l2_ctrl *ctrl)
356+
{
357+
struct hantro_ctx *ctx;
358+
359+
ctx = container_of(ctrl->handler,
360+
struct hantro_ctx, ctrl_handler);
361+
362+
switch (ctrl->id) {
363+
case V4L2_CID_STATELESS_AV1_SEQUENCE:
364+
{
365+
int bit_depth = ctrl->p_new.p_av1_sequence->bit_depth;
366+
367+
if (ctx->bit_depth == bit_depth)
368+
return 0;
369+
370+
return hantro_reset_raw_fmt(ctx, bit_depth);
371+
}
372+
default:
373+
return -EINVAL;
374+
}
375+
376+
return 0;
377+
}
378+
349379
static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
350380
.try_ctrl = hantro_try_ctrl,
351381
};
@@ -363,6 +393,11 @@ static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
363393
.s_ctrl = hantro_hevc_s_ctrl,
364394
};
365395

396+
static const struct v4l2_ctrl_ops hantro_av1_ctrl_ops = {
397+
.try_ctrl = hantro_try_ctrl,
398+
.s_ctrl = hantro_av1_s_ctrl,
399+
};
400+
366401
#define HANTRO_JPEG_ACTIVE_MARKERS (V4L2_JPEG_ACTIVE_MARKER_APP0 | \
367402
V4L2_JPEG_ACTIVE_MARKER_COM | \
368403
V4L2_JPEG_ACTIVE_MARKER_DQT | \
@@ -540,6 +575,7 @@ static const struct hantro_ctrl controls[] = {
540575
.codec = HANTRO_AV1_DECODER,
541576
.cfg = {
542577
.id = V4L2_CID_STATELESS_AV1_SEQUENCE,
578+
.ops = &hantro_av1_ctrl_ops,
543579
},
544580
}, {
545581
.codec = HANTRO_AV1_DECODER,

drivers/media/platform/verisilicon/hantro_v4l2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ hantro_check_depth_match(const struct hantro_fmt *fmt, int bit_depth)
8686
if (!fmt->match_depth && !fmt->postprocessed)
8787
return true;
8888

89+
/* 0 means default depth, which is 8 */
90+
if (!bit_depth)
91+
bit_depth = HANTRO_DEFAULT_BIT_DEPTH;
92+
8993
fmt_depth = hantro_get_format_depth(fmt->fourcc);
9094

9195
/*

0 commit comments

Comments
 (0)