visl.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * A virtual stateless device for stateless uAPI development purposes.
  4. *
  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.
  7. *
  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.
  11. *
  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.
  17. *
  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.
  21. *
  22. * Copyright (C) 2022 Collabora, Ltd.
  23. *
  24. * Based on the vim2m driver, that is:
  25. *
  26. * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
  27. * Pawel Osciak, <pawel@osciak.com>
  28. * Marek Szyprowski, <m.szyprowski@samsung.com>
  29. *
  30. * Based on the vicodec driver, that is:
  31. *
  32. * Copyright 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  33. *
  34. * Based on the Cedrus VPU driver, that is:
  35. *
  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
  39. */
  40. #ifndef _VISL_H_
  41. #define _VISL_H_
  42. #include <linux/debugfs.h>
  43. #include <linux/list.h>
  44. #include <media/v4l2-ctrls.h>
  45. #include <media/v4l2-device.h>
  46. #include <media/tpg/v4l2-tpg.h>
  47. #define VISL_NAME "visl"
  48. #define VISL_M2M_NQUEUES 2
  49. #define TPG_STR_BUF_SZ 2048
  50. extern unsigned int visl_transtime_ms;
  51. struct visl_ctrls {
  52. const struct visl_ctrl_desc *ctrls;
  53. unsigned int num_ctrls;
  54. };
  55. struct visl_coded_format_desc {
  56. u32 pixelformat;
  57. struct v4l2_frmsize_stepwise frmsize;
  58. const struct visl_ctrls *ctrls;
  59. unsigned int num_decoded_fmts;
  60. const u32 *decoded_fmts;
  61. };
  62. extern const struct visl_coded_format_desc visl_coded_fmts[];
  63. extern const size_t num_coded_fmts;
  64. enum {
  65. V4L2_M2M_SRC = 0,
  66. V4L2_M2M_DST = 1,
  67. };
  68. extern unsigned int visl_debug;
  69. #define dprintk(dev, fmt, arg...) \
  70. v4l2_dbg(1, visl_debug, &(dev)->v4l2_dev, "%s: " fmt, __func__, ## arg)
  71. extern int visl_dprintk_frame_start;
  72. extern unsigned int visl_dprintk_nframes;
  73. extern bool keep_bitstream_buffers;
  74. extern int bitstream_trace_frame_start;
  75. extern unsigned int bitstream_trace_nframes;
  76. extern bool tpg_verbose;
  77. #define frame_dprintk(dev, current, fmt, arg...) \
  78. do { \
  79. if (visl_dprintk_frame_start > -1 && \
  80. (current) >= visl_dprintk_frame_start && \
  81. (current) < visl_dprintk_frame_start + visl_dprintk_nframes) \
  82. dprintk(dev, fmt, ## arg); \
  83. } while (0) \
  84. struct visl_q_data {
  85. unsigned int sequence;
  86. };
  87. struct visl_dev {
  88. struct v4l2_device v4l2_dev;
  89. struct video_device vfd;
  90. #ifdef CONFIG_MEDIA_CONTROLLER
  91. struct media_device mdev;
  92. #endif
  93. struct mutex dev_mutex;
  94. struct v4l2_m2m_dev *m2m_dev;
  95. #ifdef CONFIG_VISL_DEBUGFS
  96. struct dentry *debugfs_root;
  97. struct dentry *bitstream_debugfs;
  98. struct list_head bitstream_blobs;
  99. /* Protects the "blob" list */
  100. struct mutex bitstream_lock;
  101. #endif
  102. };
  103. enum visl_codec {
  104. VISL_CODEC_NONE,
  105. VISL_CODEC_FWHT,
  106. VISL_CODEC_MPEG2,
  107. VISL_CODEC_VP8,
  108. VISL_CODEC_VP9,
  109. VISL_CODEC_H264,
  110. VISL_CODEC_HEVC,
  111. VISL_CODEC_AV1,
  112. };
  113. struct visl_blob {
  114. struct list_head list;
  115. struct dentry *dentry;
  116. struct debugfs_blob_wrapper blob;
  117. };
  118. struct visl_ctx {
  119. struct v4l2_fh fh;
  120. struct visl_dev *dev;
  121. struct v4l2_ctrl_handler hdl;
  122. struct mutex vb_mutex;
  123. struct visl_q_data q_data[VISL_M2M_NQUEUES];
  124. enum visl_codec current_codec;
  125. const struct visl_coded_format_desc *coded_format_desc;
  126. struct v4l2_format coded_fmt;
  127. struct v4l2_format decoded_fmt;
  128. struct tpg_data tpg;
  129. u64 capture_streamon_jiffies;
  130. char *tpg_str_buf;
  131. };
  132. struct visl_ctrl_desc {
  133. struct v4l2_ctrl_config cfg;
  134. };
  135. static inline struct visl_ctx *visl_file_to_ctx(struct file *file)
  136. {
  137. return container_of(file->private_data, struct visl_ctx, fh);
  138. }
  139. static inline struct visl_ctx *visl_v4l2fh_to_ctx(struct v4l2_fh *v4l2_fh)
  140. {
  141. return container_of(v4l2_fh, struct visl_ctx, fh);
  142. }
  143. void *visl_find_control_data(struct visl_ctx *ctx, u32 id);
  144. struct v4l2_ctrl *visl_find_control(struct visl_ctx *ctx, u32 id);
  145. u32 visl_control_num_elems(struct visl_ctx *ctx, u32 id);
  146. #endif /* _VISL_H_ */