Skip to content

Commit 80c7373

Browse files
Benjamin Gaignardmchehab
authored andcommitted
media: verisilicon: Conditionally ignore native formats
AV1 film grain feature requires to use the postprocessor to produce valid frames. In such case the driver shouldn't propose native pixels format but only post-processed pixels format. Additionally if when setting a control a value could change capture queue pixels formats it is needed to call hantro_reset_raw_fmt(). 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 003afda commit 80c7373

5 files changed

Lines changed: 63 additions & 25 deletions

File tree

drivers/media/platform/verisilicon/hantro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ struct hantro_dev {
231231
* @ctrl_handler: Control handler used to register controls.
232232
* @jpeg_quality: User-specified JPEG compression quality.
233233
* @bit_depth: Bit depth of current frame
234+
* @need_postproc: Set to true if the bitstream features require to
235+
* use the post-processor.
234236
*
235237
* @codec_ops: Set of operations related to codec mode.
236238
* @postproc: Post-processing context.
@@ -261,6 +263,7 @@ struct hantro_ctx {
261263

262264
const struct hantro_codec_ops *codec_ops;
263265
struct hantro_postproc_ctx postproc;
266+
bool need_postproc;
264267

265268
/* Specific for particular codec modes. */
266269
union {

drivers/media/platform/verisilicon/hantro_drv.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static int hantro_vp9_s_ctrl(struct v4l2_ctrl *ctrl)
319319
if (ctx->bit_depth == bit_depth)
320320
return 0;
321321

322-
return hantro_reset_raw_fmt(ctx, bit_depth);
322+
return hantro_reset_raw_fmt(ctx, bit_depth, HANTRO_AUTO_POSTPROC);
323323
}
324324
default:
325325
return -EINVAL;
@@ -343,7 +343,7 @@ static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
343343
if (ctx->bit_depth == bit_depth)
344344
return 0;
345345

346-
return hantro_reset_raw_fmt(ctx, bit_depth);
346+
return hantro_reset_raw_fmt(ctx, bit_depth, HANTRO_AUTO_POSTPROC);
347347
}
348348
default:
349349
return -EINVAL;
@@ -363,11 +363,17 @@ static int hantro_av1_s_ctrl(struct v4l2_ctrl *ctrl)
363363
case V4L2_CID_STATELESS_AV1_SEQUENCE:
364364
{
365365
int bit_depth = ctrl->p_new.p_av1_sequence->bit_depth;
366+
bool need_postproc = HANTRO_AUTO_POSTPROC;
366367

367-
if (ctx->bit_depth == bit_depth)
368+
if (ctrl->p_new.p_av1_sequence->flags
369+
& V4L2_AV1_SEQUENCE_FLAG_FILM_GRAIN_PARAMS_PRESENT)
370+
need_postproc = HANTRO_FORCE_POSTPROC;
371+
372+
if (ctx->bit_depth == bit_depth &&
373+
ctx->need_postproc == need_postproc)
368374
return 0;
369375

370-
return hantro_reset_raw_fmt(ctx, bit_depth);
376+
return hantro_reset_raw_fmt(ctx, bit_depth, need_postproc);
371377
}
372378
default:
373379
return -EINVAL;

drivers/media/platform/verisilicon/hantro_postproc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ bool hantro_needs_postproc(const struct hantro_ctx *ctx,
5757
{
5858
if (ctx->is_encoder)
5959
return false;
60+
61+
if (ctx->need_postproc)
62+
return true;
63+
6064
return fmt->postprocessed;
6165
}
6266

@@ -197,7 +201,7 @@ int hantro_postproc_alloc(struct hantro_ctx *ctx)
197201
unsigned int i, buf_size;
198202

199203
/* this should always pick native format */
200-
fmt = hantro_get_default_fmt(ctx, false, ctx->bit_depth);
204+
fmt = hantro_get_default_fmt(ctx, false, ctx->bit_depth, HANTRO_AUTO_POSTPROC);
201205
if (!fmt)
202206
return -EINVAL;
203207
v4l2_fill_pixfmt_mp(&pix_mp, fmt->fourcc, ctx->src_fmt.width,

drivers/media/platform/verisilicon/hantro_v4l2.c

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,21 @@
3131
#define HANTRO_DEFAULT_BIT_DEPTH 8
3232

3333
static int hantro_set_fmt_out(struct hantro_ctx *ctx,
34-
struct v4l2_pix_format_mplane *pix_mp);
34+
struct v4l2_pix_format_mplane *pix_mp,
35+
bool need_postproc);
3536
static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
3637
struct v4l2_pix_format_mplane *pix_mp);
3738

3839
static const struct hantro_fmt *
39-
hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts)
40+
hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts, bool need_postproc)
4041
{
4142
const struct hantro_fmt *formats;
4243

44+
if (need_postproc) {
45+
*num_fmts = 0;
46+
return NULL;
47+
}
48+
4349
if (ctx->is_encoder) {
4450
formats = ctx->dev->variant->enc_fmts;
4551
*num_fmts = ctx->dev->variant->num_enc_fmts;
@@ -108,7 +114,7 @@ hantro_find_format(const struct hantro_ctx *ctx, u32 fourcc)
108114
const struct hantro_fmt *formats;
109115
unsigned int i, num_fmts;
110116

111-
formats = hantro_get_formats(ctx, &num_fmts);
117+
formats = hantro_get_formats(ctx, &num_fmts, HANTRO_AUTO_POSTPROC);
112118
for (i = 0; i < num_fmts; i++)
113119
if (formats[i].fourcc == fourcc)
114120
return &formats[i];
@@ -121,18 +127,28 @@ hantro_find_format(const struct hantro_ctx *ctx, u32 fourcc)
121127
}
122128

123129
const struct hantro_fmt *
124-
hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream, int bit_depth)
130+
hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream,
131+
int bit_depth, bool need_postproc)
125132
{
126133
const struct hantro_fmt *formats;
127134
unsigned int i, num_fmts;
128135

129-
formats = hantro_get_formats(ctx, &num_fmts);
136+
formats = hantro_get_formats(ctx, &num_fmts, need_postproc);
137+
for (i = 0; i < num_fmts; i++) {
138+
if (bitstream == (formats[i].codec_mode !=
139+
HANTRO_MODE_NONE) &&
140+
hantro_check_depth_match(&formats[i], bit_depth))
141+
return &formats[i];
142+
}
143+
144+
formats = hantro_get_postproc_formats(ctx, &num_fmts);
130145
for (i = 0; i < num_fmts; i++) {
131146
if (bitstream == (formats[i].codec_mode !=
132147
HANTRO_MODE_NONE) &&
133148
hantro_check_depth_match(&formats[i], bit_depth))
134149
return &formats[i];
135150
}
151+
136152
return NULL;
137153
}
138154

@@ -199,7 +215,7 @@ static int vidioc_enum_fmt(struct file *file, void *priv,
199215
*/
200216
skip_mode_none = capture == ctx->is_encoder;
201217

202-
formats = hantro_get_formats(ctx, &num_fmts);
218+
formats = hantro_get_formats(ctx, &num_fmts, HANTRO_AUTO_POSTPROC);
203219
for (i = 0; i < num_fmts; i++) {
204220
bool mode_none = formats[i].codec_mode == HANTRO_MODE_NONE;
205221
fmt = &formats[i];
@@ -294,7 +310,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
294310

295311
fmt = hantro_find_format(ctx, pix_mp->pixelformat);
296312
if (!fmt) {
297-
fmt = hantro_get_default_fmt(ctx, coded, HANTRO_DEFAULT_BIT_DEPTH);
313+
fmt = hantro_get_default_fmt(ctx, coded, HANTRO_DEFAULT_BIT_DEPTH, HANTRO_AUTO_POSTPROC);
298314
pix_mp->pixelformat = fmt->fourcc;
299315
}
300316

@@ -383,7 +399,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx)
383399
const struct hantro_fmt *vpu_fmt;
384400
struct v4l2_pix_format_mplane fmt;
385401

386-
vpu_fmt = hantro_get_default_fmt(ctx, true, HANTRO_DEFAULT_BIT_DEPTH);
402+
vpu_fmt = hantro_get_default_fmt(ctx, true, HANTRO_DEFAULT_BIT_DEPTH, HANTRO_AUTO_POSTPROC);
387403
if (!vpu_fmt)
388404
return;
389405

@@ -393,17 +409,17 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx)
393409
if (ctx->is_encoder)
394410
hantro_set_fmt_cap(ctx, &fmt);
395411
else
396-
hantro_set_fmt_out(ctx, &fmt);
412+
hantro_set_fmt_out(ctx, &fmt, HANTRO_AUTO_POSTPROC);
397413
}
398414

399415
int
400-
hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth)
416+
hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth, bool need_postproc)
401417
{
402418
const struct hantro_fmt *raw_vpu_fmt;
403419
struct v4l2_pix_format_mplane raw_fmt, *encoded_fmt;
404420
int ret;
405421

406-
raw_vpu_fmt = hantro_get_default_fmt(ctx, false, bit_depth);
422+
raw_vpu_fmt = hantro_get_default_fmt(ctx, false, bit_depth, need_postproc);
407423
if (!raw_vpu_fmt)
408424
return -EINVAL;
409425

@@ -418,20 +434,22 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth)
418434
raw_fmt.width = encoded_fmt->width;
419435
raw_fmt.height = encoded_fmt->height;
420436
if (ctx->is_encoder)
421-
ret = hantro_set_fmt_out(ctx, &raw_fmt);
437+
ret = hantro_set_fmt_out(ctx, &raw_fmt, need_postproc);
422438
else
423439
ret = hantro_set_fmt_cap(ctx, &raw_fmt);
424440

425-
if (!ret)
441+
if (!ret) {
426442
ctx->bit_depth = bit_depth;
443+
ctx->need_postproc = need_postproc;
444+
}
427445

428446
return ret;
429447
}
430448

431449
void hantro_reset_fmts(struct hantro_ctx *ctx)
432450
{
433451
hantro_reset_encoded_fmt(ctx);
434-
hantro_reset_raw_fmt(ctx, HANTRO_DEFAULT_BIT_DEPTH);
452+
hantro_reset_raw_fmt(ctx, HANTRO_DEFAULT_BIT_DEPTH, HANTRO_AUTO_POSTPROC);
435453
}
436454

437455
static void
@@ -478,7 +496,8 @@ hantro_update_requires_hold_capture_buf(struct hantro_ctx *ctx, u32 fourcc)
478496
}
479497

480498
static int hantro_set_fmt_out(struct hantro_ctx *ctx,
481-
struct v4l2_pix_format_mplane *pix_mp)
499+
struct v4l2_pix_format_mplane *pix_mp,
500+
bool need_postproc)
482501
{
483502
struct vb2_queue *vq;
484503
int ret;
@@ -531,7 +550,9 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx,
531550
* changes to the raw format.
532551
*/
533552
if (!ctx->is_encoder)
534-
hantro_reset_raw_fmt(ctx, hantro_get_format_depth(pix_mp->pixelformat));
553+
hantro_reset_raw_fmt(ctx,
554+
hantro_get_format_depth(pix_mp->pixelformat),
555+
need_postproc);
535556

536557
/* Colorimetry information are always propagated. */
537558
ctx->dst_fmt.colorspace = pix_mp->colorspace;
@@ -594,7 +615,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
594615
* changes to the raw format.
595616
*/
596617
if (ctx->is_encoder)
597-
hantro_reset_raw_fmt(ctx, HANTRO_DEFAULT_BIT_DEPTH);
618+
hantro_reset_raw_fmt(ctx, HANTRO_DEFAULT_BIT_DEPTH, HANTRO_AUTO_POSTPROC);
598619

599620
/* Colorimetry information are always propagated. */
600621
ctx->src_fmt.colorspace = pix_mp->colorspace;
@@ -614,7 +635,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
614635
static int
615636
vidioc_s_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)
616637
{
617-
return hantro_set_fmt_out(fh_to_ctx(priv), &f->fmt.pix_mp);
638+
return hantro_set_fmt_out(fh_to_ctx(priv), &f->fmt.pix_mp, HANTRO_AUTO_POSTPROC);
618639
}
619640

620641
static int

drivers/media/platform/verisilicon/hantro_v4l2.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818

1919
#include "hantro.h"
2020

21+
#define HANTRO_FORCE_POSTPROC true
22+
#define HANTRO_AUTO_POSTPROC false
23+
2124
extern const struct v4l2_ioctl_ops hantro_ioctl_ops;
2225
extern const struct vb2_ops hantro_queue_ops;
2326

24-
int hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth);
27+
int hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth, bool need_postproc);
2528
void hantro_reset_fmts(struct hantro_ctx *ctx);
2629
int hantro_get_format_depth(u32 fourcc);
2730
const struct hantro_fmt *
28-
hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream, int bit_depth);
31+
hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream,
32+
int bit_depth, bool need_postproc);
2933

3034
#endif /* HANTRO_V4L2_H_ */

0 commit comments

Comments
 (0)