1 // SPDX-License-Identifier: GPL-2.0
3 * Contains the virtual decoder logic. The functions here control the
4 * tracing/TPG on a per-frame basis
8 #include "visl-debugfs.h"
10 #include "visl-trace-fwht.h"
11 #include "visl-trace-mpeg2.h"
12 #include "visl-trace-vp8.h"
13 #include "visl-trace-vp9.h"
14 #include "visl-trace-h264.h"
15 #include "visl-trace-hevc.h"
16 #include "visl-trace-av1.h"
18 #include <linux/delay.h>
19 #include <linux/workqueue.h>
20 #include <media/v4l2-mem2mem.h>
21 #include <media/tpg/v4l2-tpg.h>
23 #define LAST_BUF_IDX (V4L2_AV1_REF_LAST_FRAME - V4L2_AV1_REF_LAST_FRAME)
24 #define LAST2_BUF_IDX (V4L2_AV1_REF_LAST2_FRAME - V4L2_AV1_REF_LAST_FRAME)
25 #define LAST3_BUF_IDX (V4L2_AV1_REF_LAST3_FRAME - V4L2_AV1_REF_LAST_FRAME)
26 #define GOLDEN_BUF_IDX (V4L2_AV1_REF_GOLDEN_FRAME - V4L2_AV1_REF_LAST_FRAME)
27 #define BWD_BUF_IDX (V4L2_AV1_REF_BWDREF_FRAME - V4L2_AV1_REF_LAST_FRAME)
28 #define ALT2_BUF_IDX (V4L2_AV1_REF_ALTREF2_FRAME - V4L2_AV1_REF_LAST_FRAME)
29 #define ALT_BUF_IDX (V4L2_AV1_REF_ALTREF_FRAME - V4L2_AV1_REF_LAST_FRAME)
31 static void *plane_vaddr(struct tpg_data
*tpg
, struct vb2_buffer
*buf
,
32 u32 p
, u32 bpl
[TPG_MAX_PLANES
], u32 h
)
37 if (p
== 0 || tpg_g_buffers(tpg
) > 1)
38 return vb2_plane_vaddr(buf
, p
);
39 vbuf
= vb2_plane_vaddr(buf
, 0);
40 for (i
= 0; i
< p
; i
++)
41 vbuf
+= bpl
[i
] * h
/ tpg
->vdownsampling
[i
];
45 static void visl_print_ts_idx(u8
**buf
, __kernel_size_t
*buflen
, const char *name
,
46 u64 ts
, struct vb2_buffer
*vb2_buf
)
50 if (tpg_verbose
&& vb2_buf
) {
51 len
= scnprintf(*buf
, *buflen
, "%s: %lld, vb2_idx: %d\n", name
,
54 len
= scnprintf(*buf
, *buflen
, "%s: %lld\n", name
, ts
);
61 static void visl_get_ref_frames(struct visl_ctx
*ctx
, u8
*buf
,
62 __kernel_size_t buflen
, struct visl_run
*run
)
64 struct vb2_queue
*cap_q
= &ctx
->fh
.m2m_ctx
->cap_q_ctx
.q
;
65 char header
[] = "Reference frames:\n";
69 len
= scnprintf(buf
, buflen
, header
);
73 switch (ctx
->current_codec
) {
77 case VISL_CODEC_FWHT
: {
78 struct vb2_buffer
*vb2_buf
;
80 vb2_buf
= vb2_find_buffer(cap_q
, run
->fwht
.params
->backward_ref_ts
);
82 visl_print_ts_idx(&buf
, &buflen
, "backwards_ref_ts",
83 run
->fwht
.params
->backward_ref_ts
, vb2_buf
);
88 case VISL_CODEC_MPEG2
: {
89 struct vb2_buffer
*b_ref
;
90 struct vb2_buffer
*f_ref
;
92 b_ref
= vb2_find_buffer(cap_q
, run
->mpeg2
.pic
->backward_ref_ts
);
93 f_ref
= vb2_find_buffer(cap_q
, run
->mpeg2
.pic
->forward_ref_ts
);
95 visl_print_ts_idx(&buf
, &buflen
, "backward_ref_ts",
96 run
->mpeg2
.pic
->backward_ref_ts
, b_ref
);
97 visl_print_ts_idx(&buf
, &buflen
, "forward_ref_ts",
98 run
->mpeg2
.pic
->forward_ref_ts
, f_ref
);
103 case VISL_CODEC_VP8
: {
104 struct vb2_buffer
*last
;
105 struct vb2_buffer
*golden
;
106 struct vb2_buffer
*alt
;
108 last
= vb2_find_buffer(cap_q
, run
->vp8
.frame
->last_frame_ts
);
109 golden
= vb2_find_buffer(cap_q
, run
->vp8
.frame
->golden_frame_ts
);
110 alt
= vb2_find_buffer(cap_q
, run
->vp8
.frame
->alt_frame_ts
);
112 visl_print_ts_idx(&buf
, &buflen
, "last_ref_ts",
113 run
->vp8
.frame
->last_frame_ts
, last
);
114 visl_print_ts_idx(&buf
, &buflen
, "golden_ref_ts",
115 run
->vp8
.frame
->golden_frame_ts
, golden
);
116 visl_print_ts_idx(&buf
, &buflen
, "alt_ref_ts",
117 run
->vp8
.frame
->alt_frame_ts
, alt
);
122 case VISL_CODEC_VP9
: {
123 struct vb2_buffer
*last
;
124 struct vb2_buffer
*golden
;
125 struct vb2_buffer
*alt
;
127 last
= vb2_find_buffer(cap_q
, run
->vp9
.frame
->last_frame_ts
);
128 golden
= vb2_find_buffer(cap_q
, run
->vp9
.frame
->golden_frame_ts
);
129 alt
= vb2_find_buffer(cap_q
, run
->vp9
.frame
->alt_frame_ts
);
131 visl_print_ts_idx(&buf
, &buflen
, "last_ref_ts",
132 run
->vp9
.frame
->last_frame_ts
, last
);
133 visl_print_ts_idx(&buf
, &buflen
, "golden_ref_ts",
134 run
->vp9
.frame
->golden_frame_ts
, golden
);
135 visl_print_ts_idx(&buf
, &buflen
, "alt_ref_ts",
136 run
->vp9
.frame
->alt_frame_ts
, alt
);
141 case VISL_CODEC_H264
: {
142 char entry
[] = "dpb[%d]:%u, vb2_index: %d\n";
143 char entry_stable
[] = "dpb[%d]:%u\n";
144 struct vb2_buffer
*vb2_buf
;
146 for (i
= 0; i
< ARRAY_SIZE(run
->h264
.dpram
->dpb
); i
++) {
147 vb2_buf
= vb2_find_buffer(cap_q
,
148 run
->h264
.dpram
->dpb
[i
].reference_ts
);
149 if (tpg_verbose
&& vb2_buf
) {
150 len
= scnprintf(buf
, buflen
, entry
, i
,
151 run
->h264
.dpram
->dpb
[i
].reference_ts
,
154 len
= scnprintf(buf
, buflen
, entry_stable
, i
,
155 run
->h264
.dpram
->dpb
[i
].reference_ts
);
164 case VISL_CODEC_HEVC
: {
165 char entry
[] = "dpb[%d]:%u, vb2_index: %d\n";
166 char entry_stable
[] = "dpb[%d]:%u\n";
167 struct vb2_buffer
*vb2_buf
;
169 for (i
= 0; i
< ARRAY_SIZE(run
->hevc
.dpram
->dpb
); i
++) {
170 vb2_buf
= vb2_find_buffer(cap_q
, run
->hevc
.dpram
->dpb
[i
].timestamp
);
171 if (tpg_verbose
&& vb2_buf
) {
172 len
= scnprintf(buf
, buflen
, entry
, i
,
173 run
->hevc
.dpram
->dpb
[i
].timestamp
,
176 len
= scnprintf(buf
, buflen
, entry_stable
, i
,
177 run
->hevc
.dpram
->dpb
[i
].timestamp
);
187 case VISL_CODEC_AV1
: {
188 int idx_last
= run
->av1
.frame
->ref_frame_idx
[LAST_BUF_IDX
];
189 int idx_last2
= run
->av1
.frame
->ref_frame_idx
[LAST2_BUF_IDX
];
190 int idx_last3
= run
->av1
.frame
->ref_frame_idx
[LAST3_BUF_IDX
];
191 int idx_golden
= run
->av1
.frame
->ref_frame_idx
[GOLDEN_BUF_IDX
];
192 int idx_bwd
= run
->av1
.frame
->ref_frame_idx
[BWD_BUF_IDX
];
193 int idx_alt2
= run
->av1
.frame
->ref_frame_idx
[ALT2_BUF_IDX
];
194 int idx_alt
= run
->av1
.frame
->ref_frame_idx
[ALT_BUF_IDX
];
196 const u64
*reference_frame_ts
= run
->av1
.frame
->reference_frame_ts
;
198 struct vb2_buffer
*ref_last
=
199 vb2_find_buffer(cap_q
, reference_frame_ts
[idx_last
]);
200 struct vb2_buffer
*ref_last2
=
201 vb2_find_buffer(cap_q
, reference_frame_ts
[idx_last2
]);
202 struct vb2_buffer
*ref_last3
=
203 vb2_find_buffer(cap_q
, reference_frame_ts
[idx_last3
]);
204 struct vb2_buffer
*ref_golden
=
205 vb2_find_buffer(cap_q
, reference_frame_ts
[idx_golden
]);
206 struct vb2_buffer
*ref_bwd
=
207 vb2_find_buffer(cap_q
, reference_frame_ts
[idx_bwd
]);
208 struct vb2_buffer
*ref_alt2
=
209 vb2_find_buffer(cap_q
, reference_frame_ts
[idx_alt2
]);
210 struct vb2_buffer
*ref_alt
=
211 vb2_find_buffer(cap_q
, reference_frame_ts
[idx_alt
]);
213 visl_print_ts_idx(&buf
, &buflen
, "ref_last_ts",
214 reference_frame_ts
[idx_last
], ref_last
);
215 visl_print_ts_idx(&buf
, &buflen
, "ref_last2_ts",
216 reference_frame_ts
[idx_last2
], ref_last2
);
217 visl_print_ts_idx(&buf
, &buflen
, "ref_last3_ts",
218 reference_frame_ts
[idx_last3
], ref_last3
);
219 visl_print_ts_idx(&buf
, &buflen
, "ref_golden_ts",
220 reference_frame_ts
[idx_golden
], ref_golden
);
221 visl_print_ts_idx(&buf
, &buflen
, "ref_bwd_ts",
222 reference_frame_ts
[idx_bwd
], ref_bwd
);
223 visl_print_ts_idx(&buf
, &buflen
, "ref_alt2_ts",
224 reference_frame_ts
[idx_alt2
], ref_alt2
);
225 visl_print_ts_idx(&buf
, &buflen
, "ref_alt_ts",
226 reference_frame_ts
[idx_alt
], ref_alt
);
233 static char *visl_get_vb2_state(enum vb2_buffer_state state
)
236 case VB2_BUF_STATE_DEQUEUED
:
238 case VB2_BUF_STATE_IN_REQUEST
:
240 case VB2_BUF_STATE_PREPARING
:
242 case VB2_BUF_STATE_QUEUED
:
244 case VB2_BUF_STATE_ACTIVE
:
246 case VB2_BUF_STATE_DONE
:
248 case VB2_BUF_STATE_ERROR
:
255 static int visl_fill_bytesused(struct vb2_v4l2_buffer
*v4l2_vb2_buf
, char *buf
, size_t bufsz
)
260 for (i
= 0; i
< v4l2_vb2_buf
->vb2_buf
.num_planes
; i
++)
261 len
+= scnprintf(buf
, bufsz
,
262 "bytesused[%u]: %u length[%u]: %u data_offset[%u]: %u",
263 i
, v4l2_vb2_buf
->planes
[i
].bytesused
,
264 i
, v4l2_vb2_buf
->planes
[i
].length
,
265 i
, v4l2_vb2_buf
->planes
[i
].data_offset
);
270 static void visl_tpg_fill_sequence(struct visl_ctx
*ctx
,
271 struct visl_run
*run
, char buf
[], size_t bufsz
)
277 stream_ms
= jiffies_to_msecs(get_jiffies_64() - ctx
->capture_streamon_jiffies
);
279 len
= scnprintf(buf
, bufsz
,
280 "stream time: %02d:%02d:%02d:%03d ",
281 (stream_ms
/ (60 * 60 * 1000)) % 24,
282 (stream_ms
/ (60 * 1000)) % 60,
283 (stream_ms
/ 1000) % 60,
289 scnprintf(buf
, bufsz
,
290 "sequence:%u timestamp:%lld field:%s",
292 run
->dst
->vb2_buf
.timestamp
,
293 (run
->dst
->field
== V4L2_FIELD_ALTERNATE
) ?
294 (run
->dst
->field
== V4L2_FIELD_TOP
?
295 " top" : " bottom") : "none");
298 static bool visl_tpg_fill_codec_specific(struct visl_ctx
*ctx
,
299 struct visl_run
*run
,
300 char buf
[], size_t bufsz
)
303 * To add variability, we need a value that is stable for a given
304 * input but is different than already shown fields.
305 * The pic order count value defines the display order of the frames
306 * (which can be different than the decoding order that is shown with
307 * the sequence number).
308 * Therefore it is stable for a given input and will add a different
309 * value that is more specific to the way the input is encoded.
311 switch (ctx
->current_codec
) {
312 case VISL_CODEC_H264
:
313 scnprintf(buf
, bufsz
,
314 "H264: %u", run
->h264
.dpram
->pic_order_cnt_lsb
);
316 case VISL_CODEC_HEVC
:
317 scnprintf(buf
, bufsz
,
318 "HEVC: %d", run
->hevc
.dpram
->pic_order_cnt_val
);
327 static void visl_tpg_fill(struct visl_ctx
*ctx
, struct visl_run
*run
)
329 u8
*basep
[TPG_MAX_PLANES
][2];
330 char *buf
= ctx
->tpg_str_buf
;
334 const u32 line_height
= 16;
336 struct vb2_queue
*out_q
= &ctx
->fh
.m2m_ctx
->out_q_ctx
.q
;
337 struct vb2_queue
*cap_q
= &ctx
->fh
.m2m_ctx
->cap_q_ctx
.q
;
338 struct v4l2_pix_format_mplane
*coded_fmt
= &ctx
->coded_fmt
.fmt
.pix_mp
;
339 struct v4l2_pix_format_mplane
*decoded_fmt
= &ctx
->decoded_fmt
.fmt
.pix_mp
;
343 for (p
= 0; p
< tpg_g_planes(&ctx
->tpg
); p
++) {
344 void *vbuf
= plane_vaddr(&ctx
->tpg
,
345 &run
->dst
->vb2_buf
, p
,
346 ctx
->tpg
.bytesperline
,
347 ctx
->tpg
.buf_height
);
349 tpg_calc_text_basep(&ctx
->tpg
, basep
, p
, vbuf
);
350 tpg_fill_plane_buffer(&ctx
->tpg
, 0, p
, vbuf
);
353 visl_tpg_fill_sequence(ctx
, run
, buf
, TPG_STR_BUF_SZ
);
354 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, buf
);
355 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s\n", buf
);
356 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "");
359 if (visl_tpg_fill_codec_specific(ctx
, run
, buf
, TPG_STR_BUF_SZ
)) {
360 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, buf
);
361 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s\n", buf
);
362 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "");
366 visl_get_ref_frames(ctx
, buf
, TPG_STR_BUF_SZ
, run
);
368 while ((line_str
= strsep(&tmp
, "\n")) && strlen(line_str
)) {
369 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, line_str
);
370 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s\n", line_str
);
373 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "");
378 "OUTPUT pixelformat: %c%c%c%c, resolution: %dx%d, num_planes: %d",
379 coded_fmt
->pixelformat
,
380 (coded_fmt
->pixelformat
>> 8) & 0xff,
381 (coded_fmt
->pixelformat
>> 16) & 0xff,
382 (coded_fmt
->pixelformat
>> 24) & 0xff,
385 coded_fmt
->num_planes
);
387 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, buf
);
388 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s\n", buf
);
390 for (i
= 0; i
< coded_fmt
->num_planes
; i
++) {
393 "plane[%d]: bytesperline: %d, sizeimage: %d",
395 coded_fmt
->plane_fmt
[i
].bytesperline
,
396 coded_fmt
->plane_fmt
[i
].sizeimage
);
398 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, buf
);
399 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s\n", buf
);
404 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "");
405 scnprintf(buf
, TPG_STR_BUF_SZ
, "Output queue status:");
406 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, buf
);
407 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s\n", buf
);
410 for (i
= 0; i
< vb2_get_num_buffers(out_q
); i
++) {
411 char entry
[] = "index: %u, state: %s, request_fd: %d, ";
413 struct vb2_buffer
*vb2
;
416 vb2
= vb2_get_buffer(out_q
, i
);
420 q_status
= visl_get_vb2_state(vb2
->state
);
422 len
+= scnprintf(&buf
[len
], TPG_STR_BUF_SZ
- len
,
424 to_vb2_v4l2_buffer(vb2
)->request_fd
);
426 len
+= visl_fill_bytesused(to_vb2_v4l2_buffer(vb2
),
428 TPG_STR_BUF_SZ
- len
);
430 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, &buf
[old_len
]);
431 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s", &buf
[old_len
]);
436 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "");
440 "CAPTURE pixelformat: %c%c%c%c, resolution: %dx%d, num_planes: %d",
441 decoded_fmt
->pixelformat
,
442 (decoded_fmt
->pixelformat
>> 8) & 0xff,
443 (decoded_fmt
->pixelformat
>> 16) & 0xff,
444 (decoded_fmt
->pixelformat
>> 24) & 0xff,
447 decoded_fmt
->num_planes
);
449 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, buf
);
450 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s\n", buf
);
452 for (i
= 0; i
< decoded_fmt
->num_planes
; i
++) {
455 "plane[%d]: bytesperline: %d, sizeimage: %d",
457 decoded_fmt
->plane_fmt
[i
].bytesperline
,
458 decoded_fmt
->plane_fmt
[i
].sizeimage
);
460 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, buf
);
461 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s\n", buf
);
466 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "");
467 scnprintf(buf
, TPG_STR_BUF_SZ
, "Capture queue status:");
468 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, buf
);
469 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s\n", buf
);
472 for (i
= 0; i
< vb2_get_num_buffers(cap_q
); i
++) {
474 struct vb2_buffer
*vb2
;
477 vb2
= vb2_get_buffer(cap_q
, i
);
481 q_status
= visl_get_vb2_state(vb2
->state
);
483 len
+= scnprintf(&buf
[len
], TPG_STR_BUF_SZ
- len
,
484 "index: %u, status: %s, timestamp: %llu, is_held: %d",
485 vb2
->index
, q_status
,
487 to_vb2_v4l2_buffer(vb2
)->is_held
);
489 tpg_gen_text(&ctx
->tpg
, basep
, line
++ * line_height
, 16, &buf
[old_len
]);
490 frame_dprintk(ctx
->dev
, run
->dst
->sequence
, "%s", &buf
[old_len
]);
495 static void visl_trace_ctrls(struct visl_ctx
*ctx
, struct visl_run
*run
)
499 switch (ctx
->current_codec
) {
501 case VISL_CODEC_NONE
:
503 case VISL_CODEC_FWHT
:
504 trace_v4l2_ctrl_fwht_params(run
->fwht
.params
);
506 case VISL_CODEC_MPEG2
:
507 trace_v4l2_ctrl_mpeg2_sequence(run
->mpeg2
.seq
);
508 trace_v4l2_ctrl_mpeg2_picture(run
->mpeg2
.pic
);
509 trace_v4l2_ctrl_mpeg2_quantisation(run
->mpeg2
.quant
);
512 trace_v4l2_ctrl_vp8_frame(run
->vp8
.frame
);
513 trace_v4l2_ctrl_vp8_entropy(run
->vp8
.frame
);
516 trace_v4l2_ctrl_vp9_frame(run
->vp9
.frame
);
517 trace_v4l2_ctrl_vp9_compressed_hdr(run
->vp9
.probs
);
518 trace_v4l2_ctrl_vp9_compressed_coeff(run
->vp9
.probs
);
519 trace_v4l2_vp9_mv_probs(&run
->vp9
.probs
->mv
);
521 case VISL_CODEC_H264
:
522 trace_v4l2_ctrl_h264_sps(run
->h264
.sps
);
523 trace_v4l2_ctrl_h264_pps(run
->h264
.pps
);
524 trace_v4l2_ctrl_h264_scaling_matrix(run
->h264
.sm
);
525 trace_v4l2_ctrl_h264_slice_params(run
->h264
.spram
);
527 for (i
= 0; i
< ARRAY_SIZE(run
->h264
.spram
->ref_pic_list0
); i
++)
528 trace_v4l2_h264_ref_pic_list0(&run
->h264
.spram
->ref_pic_list0
[i
], i
);
529 for (i
= 0; i
< ARRAY_SIZE(run
->h264
.spram
->ref_pic_list0
); i
++)
530 trace_v4l2_h264_ref_pic_list1(&run
->h264
.spram
->ref_pic_list1
[i
], i
);
532 trace_v4l2_ctrl_h264_decode_params(run
->h264
.dpram
);
534 for (i
= 0; i
< ARRAY_SIZE(run
->h264
.dpram
->dpb
); i
++)
535 trace_v4l2_h264_dpb_entry(&run
->h264
.dpram
->dpb
[i
], i
);
537 trace_v4l2_ctrl_h264_pred_weights(run
->h264
.pwht
);
539 case VISL_CODEC_HEVC
:
540 trace_v4l2_ctrl_hevc_sps(run
->hevc
.sps
);
541 trace_v4l2_ctrl_hevc_pps(run
->hevc
.pps
);
542 trace_v4l2_ctrl_hevc_slice_params(run
->hevc
.spram
);
543 trace_v4l2_ctrl_hevc_scaling_matrix(run
->hevc
.sm
);
544 trace_v4l2_ctrl_hevc_decode_params(run
->hevc
.dpram
);
546 for (i
= 0; i
< ARRAY_SIZE(run
->hevc
.dpram
->dpb
); i
++)
547 trace_v4l2_hevc_dpb_entry(&run
->hevc
.dpram
->dpb
[i
]);
549 trace_v4l2_hevc_pred_weight_table(&run
->hevc
.spram
->pred_weight_table
);
552 trace_v4l2_ctrl_av1_sequence(run
->av1
.seq
);
553 trace_v4l2_ctrl_av1_frame(run
->av1
.frame
);
554 trace_v4l2_ctrl_av1_film_grain(run
->av1
.grain
);
555 trace_v4l2_ctrl_av1_tile_group_entry(run
->av1
.tge
);
560 void visl_device_run(void *priv
)
562 struct visl_ctx
*ctx
= priv
;
563 struct visl_run run
= {};
564 struct media_request
*src_req
;
566 run
.src
= v4l2_m2m_next_src_buf(ctx
->fh
.m2m_ctx
);
567 run
.dst
= v4l2_m2m_next_dst_buf(ctx
->fh
.m2m_ctx
);
569 /* Apply request(s) controls if needed. */
570 src_req
= run
.src
->vb2_buf
.req_obj
.req
;
573 v4l2_ctrl_request_setup(src_req
, &ctx
->hdl
);
575 v4l2_m2m_buf_copy_metadata(run
.src
, run
.dst
, true);
576 run
.dst
->sequence
= ctx
->q_data
[V4L2_M2M_DST
].sequence
++;
577 run
.src
->sequence
= ctx
->q_data
[V4L2_M2M_SRC
].sequence
++;
578 run
.dst
->field
= ctx
->decoded_fmt
.fmt
.pix
.field
;
580 switch (ctx
->current_codec
) {
582 case VISL_CODEC_NONE
:
584 case VISL_CODEC_FWHT
:
585 run
.fwht
.params
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_FWHT_PARAMS
);
587 case VISL_CODEC_MPEG2
:
588 run
.mpeg2
.seq
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_MPEG2_SEQUENCE
);
589 run
.mpeg2
.pic
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_MPEG2_PICTURE
);
590 run
.mpeg2
.quant
= visl_find_control_data(ctx
,
591 V4L2_CID_STATELESS_MPEG2_QUANTISATION
);
594 run
.vp8
.frame
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_VP8_FRAME
);
597 run
.vp9
.frame
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_VP9_FRAME
);
598 run
.vp9
.probs
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_VP9_COMPRESSED_HDR
);
600 case VISL_CODEC_H264
:
601 run
.h264
.sps
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_H264_SPS
);
602 run
.h264
.pps
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_H264_PPS
);
603 run
.h264
.sm
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_H264_SCALING_MATRIX
);
604 run
.h264
.spram
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_H264_SLICE_PARAMS
);
605 run
.h264
.dpram
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_H264_DECODE_PARAMS
);
606 run
.h264
.pwht
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_H264_PRED_WEIGHTS
);
608 case VISL_CODEC_HEVC
:
609 run
.hevc
.sps
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_HEVC_SPS
);
610 run
.hevc
.pps
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_HEVC_PPS
);
611 run
.hevc
.spram
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_HEVC_SLICE_PARAMS
);
612 run
.hevc
.sm
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_HEVC_SCALING_MATRIX
);
613 run
.hevc
.dpram
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_HEVC_DECODE_PARAMS
);
616 run
.av1
.seq
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_AV1_SEQUENCE
);
617 run
.av1
.frame
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_AV1_FRAME
);
618 run
.av1
.tge
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY
);
619 run
.av1
.grain
= visl_find_control_data(ctx
, V4L2_CID_STATELESS_AV1_FILM_GRAIN
);
623 frame_dprintk(ctx
->dev
, run
.dst
->sequence
,
624 "Got OUTPUT buffer sequence %d, timestamp %llu\n",
625 run
.src
->sequence
, run
.src
->vb2_buf
.timestamp
);
627 frame_dprintk(ctx
->dev
, run
.dst
->sequence
,
628 "Got CAPTURE buffer sequence %d, timestamp %llu\n",
629 run
.dst
->sequence
, run
.dst
->vb2_buf
.timestamp
);
631 visl_tpg_fill(ctx
, &run
);
632 visl_trace_ctrls(ctx
, &run
);
634 if (bitstream_trace_frame_start
> -1 &&
635 run
.dst
->sequence
>= bitstream_trace_frame_start
&&
636 run
.dst
->sequence
< bitstream_trace_frame_start
+ bitstream_trace_nframes
)
637 visl_trace_bitstream(ctx
, &run
);
639 /* Complete request(s) controls if needed. */
641 v4l2_ctrl_request_complete(src_req
, &ctx
->hdl
);
643 if (visl_transtime_ms
)
644 usleep_range(visl_transtime_ms
* 1000, 2 * visl_transtime_ms
* 1000);
646 v4l2_m2m_buf_done_and_job_finish(ctx
->dev
->m2m_dev
,
647 ctx
->fh
.m2m_ctx
, VB2_BUF_STATE_DONE
);