3131#define HANTRO_DEFAULT_BIT_DEPTH 8
3232
3333static 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 );
3536static int hantro_set_fmt_cap (struct hantro_ctx * ctx ,
3637 struct v4l2_pix_format_mplane * pix_mp );
3738
3839static 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
123129const 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
399415int
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
431449void 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
437455static void
@@ -478,7 +496,8 @@ hantro_update_requires_hold_capture_buf(struct hantro_ctx *ctx, u32 fourcc)
478496}
479497
480498static 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,
614635static int
615636vidioc_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
620641static int
0 commit comments