1 /* SPDX-License-Identifier: GPL-2.0 */
3 * A virtual stateless device for stateless uAPI development purposes.
5 * This tool's objective is to help the development and testing of userspace
6 * applications that use the V4L2 stateless API to decode media.
8 * A userspace implementation can use visl to run a decoding loop even when no
9 * hardware is available or when the kernel uAPI for the codec has not been
10 * upstreamed yet. This can reveal bugs at an early stage.
12 * This driver can also trace the contents of the V4L2 controls submitted to it.
13 * It can also dump the contents of the vb2 buffers through a debugfs
14 * interface. This is in many ways similar to the tracing infrastructure
15 * available for other popular encode/decode APIs out there and can help develop
16 * a userspace application by using another (working) one as a reference.
18 * Note that no actual decoding of video frames is performed by visl. The V4L2
19 * test pattern generator is used to write various debug information to the
20 * capture buffers instead.
22 * Copyright (C) 2022 Collabora, Ltd.
24 * Based on the vim2m driver, that is:
26 * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
27 * Pawel Osciak, <pawel@osciak.com>
28 * Marek Szyprowski, <m.szyprowski@samsung.com>
30 * Based on the vicodec driver, that is:
32 * Copyright 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
34 * Based on the Cedrus VPU driver, that is:
36 * Copyright (C) 2016 Florent Revest <florent.revest@free-electrons.com>
37 * Copyright (C) 2018 Paul Kocialkowski <paul.kocialkowski@bootlin.com>
38 * Copyright (C) 2018 Bootlin
44 #include <linux/debugfs.h>
45 #include <linux/list.h>
47 #include <media/v4l2-ctrls.h>
48 #include <media/v4l2-device.h>
49 #include <media/tpg/v4l2-tpg.h>
51 #define VISL_NAME "visl"
52 #define VISL_M2M_NQUEUES 2
54 #define TPG_STR_BUF_SZ 2048
56 extern unsigned int visl_transtime_ms
;
59 const struct visl_ctrl_desc
*ctrls
;
60 unsigned int num_ctrls
;
63 struct visl_coded_format_desc
{
65 struct v4l2_frmsize_stepwise frmsize
;
66 const struct visl_ctrls
*ctrls
;
67 unsigned int num_decoded_fmts
;
68 const u32
*decoded_fmts
;
71 extern const struct visl_coded_format_desc visl_coded_fmts
[];
72 extern const size_t num_coded_fmts
;
79 extern unsigned int visl_debug
;
80 #define dprintk(dev, fmt, arg...) \
81 v4l2_dbg(1, visl_debug, &(dev)->v4l2_dev, "%s: " fmt, __func__, ## arg)
83 extern int visl_dprintk_frame_start
;
84 extern unsigned int visl_dprintk_nframes
;
85 extern bool keep_bitstream_buffers
;
86 extern int bitstream_trace_frame_start
;
87 extern unsigned int bitstream_trace_nframes
;
88 extern bool tpg_verbose
;
90 #define frame_dprintk(dev, current, fmt, arg...) \
92 if (visl_dprintk_frame_start > -1 && \
93 (current) >= visl_dprintk_frame_start && \
94 (current) < visl_dprintk_frame_start + visl_dprintk_nframes) \
95 dprintk(dev, fmt, ## arg); \
99 unsigned int sequence
;
103 struct v4l2_device v4l2_dev
;
104 struct video_device vfd
;
105 #ifdef CONFIG_MEDIA_CONTROLLER
106 struct media_device mdev
;
109 struct mutex dev_mutex
;
111 struct v4l2_m2m_dev
*m2m_dev
;
113 #ifdef CONFIG_VISL_DEBUGFS
114 struct dentry
*debugfs_root
;
115 struct dentry
*bitstream_debugfs
;
116 struct list_head bitstream_blobs
;
118 /* Protects the "blob" list */
119 struct mutex bitstream_lock
;
135 struct list_head list
;
136 struct dentry
*dentry
;
137 struct debugfs_blob_wrapper blob
;
142 struct visl_dev
*dev
;
143 struct v4l2_ctrl_handler hdl
;
145 struct mutex vb_mutex
;
147 struct visl_q_data q_data
[VISL_M2M_NQUEUES
];
148 enum visl_codec current_codec
;
150 const struct visl_coded_format_desc
*coded_format_desc
;
152 struct v4l2_format coded_fmt
;
153 struct v4l2_format decoded_fmt
;
156 u64 capture_streamon_jiffies
;
160 struct visl_ctrl_desc
{
161 struct v4l2_ctrl_config cfg
;
164 static inline struct visl_ctx
*visl_file_to_ctx(struct file
*file
)
166 return container_of(file
->private_data
, struct visl_ctx
, fh
);
169 static inline struct visl_ctx
*visl_v4l2fh_to_ctx(struct v4l2_fh
*v4l2_fh
)
171 return container_of(v4l2_fh
, struct visl_ctx
, fh
);
174 void *visl_find_control_data(struct visl_ctx
*ctx
, u32 id
);
175 struct v4l2_ctrl
*visl_find_control(struct visl_ctx
*ctx
, u32 id
);
176 u32
visl_control_num_elems(struct visl_ctx
*ctx
, u32 id
);
178 #endif /* _VISL_H_ */