162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ciThe Virtual Stateless Decoder Driver (visl)
462306a36Sopenharmony_ci===========================================
562306a36Sopenharmony_ci
662306a36Sopenharmony_ciA virtual stateless decoder device for stateless uAPI development
762306a36Sopenharmony_cipurposes.
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciThis tool's objective is to help the development and testing of
1062306a36Sopenharmony_ciuserspace applications that use the V4L2 stateless API to decode media.
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciA userspace implementation can use visl to run a decoding loop even when
1362306a36Sopenharmony_cino hardware is available or when the kernel uAPI for the codec has not
1462306a36Sopenharmony_cibeen upstreamed yet. This can reveal bugs at an early stage.
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ciThis driver can also trace the contents of the V4L2 controls submitted
1762306a36Sopenharmony_cito it.  It can also dump the contents of the vb2 buffers through a
1862306a36Sopenharmony_cidebugfs interface. This is in many ways similar to the tracing
1962306a36Sopenharmony_ciinfrastructure available for other popular encode/decode APIs out there
2062306a36Sopenharmony_ciand can help develop a userspace application by using another (working)
2162306a36Sopenharmony_cione as a reference.
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci.. note::
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci        No actual decoding of video frames is performed by visl. The
2662306a36Sopenharmony_ci        V4L2 test pattern generator is used to write various debug information
2762306a36Sopenharmony_ci        to the capture buffers instead.
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciModule parameters
3062306a36Sopenharmony_ci-----------------
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci- visl_debug: Activates debug info, printing various debug messages through
3362306a36Sopenharmony_ci  dprintk. Also controls whether per-frame debug info is shown. Defaults to off.
3462306a36Sopenharmony_ci  Note that enabling this feature can result in slow performance through serial.
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci- visl_transtime_ms: Simulated process time in milliseconds. Slowing down the
3762306a36Sopenharmony_ci  decoding speed can be useful for debugging.
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci- visl_dprintk_frame_start, visl_dprintk_frame_nframes: Dictates a range of
4062306a36Sopenharmony_ci  frames where dprintk is activated. This only controls the dprintk tracing on a
4162306a36Sopenharmony_ci  per-frame basis. Note that printing a lot of data can be slow through serial.
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci- keep_bitstream_buffers: Controls whether bitstream (i.e. OUTPUT) buffers are
4462306a36Sopenharmony_ci  kept after a decoding session. Defaults to false so as to reduce the amount of
4562306a36Sopenharmony_ci  clutter. keep_bitstream_buffers == false works well when live debugging the
4662306a36Sopenharmony_ci  client program with GDB.
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci- bitstream_trace_frame_start, bitstream_trace_nframes: Similar to
4962306a36Sopenharmony_ci  visl_dprintk_frame_start, visl_dprintk_nframes, but controls the dumping of
5062306a36Sopenharmony_ci  buffer data through debugfs instead.
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciWhat is the default use case for this driver?
5362306a36Sopenharmony_ci---------------------------------------------
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciThis driver can be used as a way to compare different userspace implementations.
5662306a36Sopenharmony_ciThis assumes that a working client is run against visl and that the ftrace and
5762306a36Sopenharmony_ciOUTPUT buffer data is subsequently used to debug a work-in-progress
5862306a36Sopenharmony_ciimplementation.
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciInformation on reference frames, their timestamps, the status of the OUTPUT and
6162306a36Sopenharmony_ciCAPTURE queues and more can be read directly from the CAPTURE buffers.
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ciSupported codecs
6462306a36Sopenharmony_ci----------------
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ciThe following codecs are supported:
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci- FWHT
6962306a36Sopenharmony_ci- MPEG2
7062306a36Sopenharmony_ci- VP8
7162306a36Sopenharmony_ci- VP9
7262306a36Sopenharmony_ci- H.264
7362306a36Sopenharmony_ci- HEVC
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_civisl trace events
7662306a36Sopenharmony_ci-----------------
7762306a36Sopenharmony_ciThe trace events are defined on a per-codec basis, e.g.:
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci.. code-block:: bash
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci        $ ls /sys/kernel/debug/tracing/events/ | grep visl
8262306a36Sopenharmony_ci        visl_fwht_controls
8362306a36Sopenharmony_ci        visl_h264_controls
8462306a36Sopenharmony_ci        visl_hevc_controls
8562306a36Sopenharmony_ci        visl_mpeg2_controls
8662306a36Sopenharmony_ci        visl_vp8_controls
8762306a36Sopenharmony_ci        visl_vp9_controls
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciFor example, in order to dump HEVC SPS data:
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci.. code-block:: bash
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci        $ echo 1 >  /sys/kernel/debug/tracing/events/visl_hevc_controls/v4l2_ctrl_hevc_sps/enable
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciThe SPS data will be dumped to the trace buffer, i.e.:
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci.. code-block:: bash
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci        $ cat /sys/kernel/debug/tracing/trace
10062306a36Sopenharmony_ci        video_parameter_set_id 0
10162306a36Sopenharmony_ci        seq_parameter_set_id 0
10262306a36Sopenharmony_ci        pic_width_in_luma_samples 1920
10362306a36Sopenharmony_ci        pic_height_in_luma_samples 1080
10462306a36Sopenharmony_ci        bit_depth_luma_minus8 0
10562306a36Sopenharmony_ci        bit_depth_chroma_minus8 0
10662306a36Sopenharmony_ci        log2_max_pic_order_cnt_lsb_minus4 4
10762306a36Sopenharmony_ci        sps_max_dec_pic_buffering_minus1 6
10862306a36Sopenharmony_ci        sps_max_num_reorder_pics 2
10962306a36Sopenharmony_ci        sps_max_latency_increase_plus1 0
11062306a36Sopenharmony_ci        log2_min_luma_coding_block_size_minus3 0
11162306a36Sopenharmony_ci        log2_diff_max_min_luma_coding_block_size 3
11262306a36Sopenharmony_ci        log2_min_luma_transform_block_size_minus2 0
11362306a36Sopenharmony_ci        log2_diff_max_min_luma_transform_block_size 3
11462306a36Sopenharmony_ci        max_transform_hierarchy_depth_inter 2
11562306a36Sopenharmony_ci        max_transform_hierarchy_depth_intra 2
11662306a36Sopenharmony_ci        pcm_sample_bit_depth_luma_minus1 0
11762306a36Sopenharmony_ci        pcm_sample_bit_depth_chroma_minus1 0
11862306a36Sopenharmony_ci        log2_min_pcm_luma_coding_block_size_minus3 0
11962306a36Sopenharmony_ci        log2_diff_max_min_pcm_luma_coding_block_size 0
12062306a36Sopenharmony_ci        num_short_term_ref_pic_sets 0
12162306a36Sopenharmony_ci        num_long_term_ref_pics_sps 0
12262306a36Sopenharmony_ci        chroma_format_idc 1
12362306a36Sopenharmony_ci        sps_max_sub_layers_minus1 0
12462306a36Sopenharmony_ci        flags AMP_ENABLED|SAMPLE_ADAPTIVE_OFFSET|TEMPORAL_MVP_ENABLED|STRONG_INTRA_SMOOTHING_ENABLED
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ciDumping OUTPUT buffer data through debugfs
12862306a36Sopenharmony_ci------------------------------------------
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ciIf the **VISL_DEBUGFS** Kconfig is enabled, visl will populate
13162306a36Sopenharmony_ci**/sys/kernel/debug/visl/bitstream** with OUTPUT buffer data according to the
13262306a36Sopenharmony_civalues of bitstream_trace_frame_start and bitstream_trace_nframes. This can
13362306a36Sopenharmony_cihighlight errors as broken clients may fail to fill the buffers properly.
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ciA single file is created for each processed OUTPUT buffer. Its name contains an
13662306a36Sopenharmony_ciinteger that denotes the buffer sequence, i.e.:
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci.. code-block:: c
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci	snprintf(name, 32, "bitstream%d", run->src->sequence);
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ciDumping the values is simply a matter of reading from the file, i.e.:
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ciFor the buffer with sequence == 0:
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci.. code-block:: bash
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci        $ xxd /sys/kernel/debug/visl/bitstream/bitstream0
14962306a36Sopenharmony_ci        00000000: 2601 af04 d088 bc25 a173 0e41 a4f2 3274  &......%.s.A..2t
15062306a36Sopenharmony_ci        00000010: c668 cb28 e775 b4ac f53a ba60 f8fd 3aa1  .h.(.u...:.`..:.
15162306a36Sopenharmony_ci        00000020: 46b4 bcfc 506c e227 2372 e5f5 d7ea 579f  F...Pl.'#r....W.
15262306a36Sopenharmony_ci        00000030: 6371 5eb5 0eb8 23b5 ca6a 5de5 983a 19e4  cq^...#..j]..:..
15362306a36Sopenharmony_ci        00000040: e8c3 4320 b4ba a226 cbc1 4138 3a12 32d6  ..C ...&..A8:.2.
15462306a36Sopenharmony_ci        00000050: fef3 247b 3523 4e90 9682 ac8e eb0c a389  ..${5#N.........
15562306a36Sopenharmony_ci        00000060: ddd0 6cfc 0187 0e20 7aae b15b 1812 3d33  ..l.... z..[..=3
15662306a36Sopenharmony_ci        00000070: e1c5 f425 a83a 00b7 4f18 8127 3c4c aefb  ...%.:..O..'<L..
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ciFor the buffer with sequence == 1:
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci.. code-block:: bash
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci        $ xxd /sys/kernel/debug/visl/bitstream/bitstream1
16362306a36Sopenharmony_ci        00000000: 0201 d021 49e1 0c40 aa11 1449 14a6 01dc  ...!I..@...I....
16462306a36Sopenharmony_ci        00000010: 7023 889a c8cd 2cd0 13b4 dab0 e8ca 21fe  p#....,.......!.
16562306a36Sopenharmony_ci        00000020: c4c8 ab4c 486e 4e2f b0df 96cc c74e 8dde  ...LHnN/.....N..
16662306a36Sopenharmony_ci        00000030: 8ce7 ee36 d880 4095 4d64 30a0 ff4f 0c5e  ...6..@.Md0..O.^
16762306a36Sopenharmony_ci        00000040: f16b a6a1 d806 ca2a 0ece a673 7bea 1f37  .k.....*...s{..7
16862306a36Sopenharmony_ci        00000050: 370f 5bb9 1dc4 ba21 6434 bc53 0173 cba0  7.[....!d4.S.s..
16962306a36Sopenharmony_ci        00000060: dfe6 bc99 01ea b6e0 346b 92b5 c8de 9f5d  ........4k.....]
17062306a36Sopenharmony_ci        00000070: e7cc 3484 1769 fef2 a693 a945 2c8b 31da  ..4..i.....E,.1.
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ciAnd so on.
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ciBy default, the files are removed during STREAMOFF. This is to reduce the amount
17562306a36Sopenharmony_ciof clutter.
176