v4l2-request-test.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (C) 2018 Paul Kocialkowski <paul.kocialkowski@bootlin.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _V4L2_REQUEST_TEST_H_
  18. #define _V4L2_REQUEST_TEST_H_
  19. #include <stdbool.h>
  20. #include <linux/types.h>
  21. #include <linux/v4l2-controls.h>
  22. #include <linux/videodev2.h>
  23. #include <mpeg2-ctrls.h>
  24. #include <h264-ctrls.h>
  25. #include <hevc-ctrls.h>
  26. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  27. #define TS_REF_INDEX(index) ((index) * 1000)
  28. #define INDEX_REF_TS(ts) ((ts) / 1000)
  29. /*
  30. * Structures
  31. */
  32. struct config {
  33. char *video_path;
  34. char *media_path;
  35. char *drm_path;
  36. char *drm_driver;
  37. char *preset_name;
  38. char *slices_path;
  39. char *slices_filename_format;
  40. unsigned int buffers_count;
  41. unsigned int fps;
  42. bool quiet;
  43. bool interactive;
  44. bool loop;
  45. };
  46. struct format_description {
  47. char *description;
  48. unsigned int v4l2_format;
  49. unsigned int v4l2_buffers_count;
  50. bool v4l2_mplane;
  51. unsigned int drm_format;
  52. uint64_t drm_modifier;
  53. unsigned int planes_count;
  54. unsigned int bpp;
  55. };
  56. /* Presets */
  57. enum codec_type {
  58. CODEC_TYPE_MPEG2,
  59. CODEC_TYPE_H264,
  60. CODEC_TYPE_H265,
  61. };
  62. enum pct {
  63. PCT_I,
  64. PCT_P,
  65. PCT_B,
  66. PCT_SI,
  67. PCT_SP
  68. };
  69. union controls {
  70. struct {
  71. struct v4l2_ctrl_mpeg2_slice_params slice_params;
  72. struct v4l2_ctrl_mpeg2_quantization quantization;
  73. } mpeg2;
  74. #ifdef V4L2_PIX_FMT_H264_SLICE
  75. struct {
  76. struct v4l2_ctrl_h264_decode_params decode_params;
  77. struct v4l2_ctrl_h264_pps pps;
  78. struct v4l2_h264_pred_weight_table pred_weight;
  79. struct v4l2_ctrl_h264_scaling_matrix scaling_matrix;
  80. struct v4l2_ctrl_h264_slice_params slice_params;
  81. struct v4l2_ctrl_h264_sps sps;
  82. } h264;
  83. #endif
  84. #ifdef V4L2_PIX_FMT_HEVC_SLICE
  85. struct {
  86. struct v4l2_ctrl_hevc_sps sps;
  87. struct v4l2_ctrl_hevc_pps pps;
  88. struct v4l2_ctrl_hevc_slice_params slice_params;
  89. } h265;
  90. #endif
  91. };
  92. struct frame {
  93. unsigned int index;
  94. union controls frame;
  95. };
  96. struct preset {
  97. char *name;
  98. char *description;
  99. char *license;
  100. char *attribution;
  101. unsigned int width;
  102. unsigned int height;
  103. unsigned int buffers_count;
  104. enum codec_type type;
  105. struct frame *frames;
  106. unsigned int frames_count;
  107. unsigned int display_count;
  108. };
  109. /* V4L2 */
  110. struct video_setup {
  111. unsigned int output_type;
  112. unsigned int capture_type;
  113. };
  114. struct video_buffer {
  115. void *source_map;
  116. void *source_data;
  117. unsigned int source_size;
  118. void *destination_map[VIDEO_MAX_PLANES];
  119. unsigned int destination_map_lengths[VIDEO_MAX_PLANES];
  120. void *destination_data[VIDEO_MAX_PLANES];
  121. unsigned int destination_sizes[VIDEO_MAX_PLANES];
  122. unsigned int destination_offsets[VIDEO_MAX_PLANES];
  123. unsigned int destination_bytesperlines[VIDEO_MAX_PLANES];
  124. unsigned int destination_planes_count;
  125. unsigned int destination_buffers_count;
  126. int export_fds[VIDEO_MAX_PLANES];
  127. int request_fd;
  128. };
  129. /* DRM */
  130. struct gem_buffer {
  131. void *data;
  132. unsigned int size;
  133. unsigned int handles[4];
  134. unsigned int pitches[4];
  135. unsigned int offsets[4];
  136. unsigned int planes_count;
  137. unsigned int framebuffer_id;
  138. };
  139. struct display_properties_ids {
  140. uint32_t connector_crtc_id;
  141. uint32_t crtc_mode_id;
  142. uint32_t crtc_active;
  143. uint32_t plane_fb_id;
  144. uint32_t plane_crtc_id;
  145. uint32_t plane_src_x;
  146. uint32_t plane_src_y;
  147. uint32_t plane_src_w;
  148. uint32_t plane_src_h;
  149. uint32_t plane_crtc_x;
  150. uint32_t plane_crtc_y;
  151. uint32_t plane_crtc_w;
  152. uint32_t plane_crtc_h;
  153. uint32_t plane_zpos;
  154. };
  155. struct display_setup {
  156. unsigned int connector_id;
  157. unsigned int encoder_id;
  158. unsigned int crtc_id;
  159. unsigned int plane_id;
  160. unsigned int width;
  161. unsigned int height;
  162. unsigned int x;
  163. unsigned int y;
  164. unsigned int scaled_width;
  165. unsigned int scaled_height;
  166. unsigned int buffers_count;
  167. bool use_dmabuf;
  168. struct display_properties_ids properties_ids;
  169. };
  170. /*
  171. * Functions
  172. */
  173. /* Presets */
  174. void presets_usage(void);
  175. struct preset *preset_find(char *name);
  176. int frame_controls_fill(struct frame *frame, struct preset *preset,
  177. unsigned int buffers_count, unsigned int index,
  178. unsigned int slice_size);
  179. unsigned int frame_pct(struct preset *preset, unsigned int index);
  180. unsigned int frame_backward_ref_index(struct preset *preset,
  181. unsigned int index);
  182. int frame_gop_next(unsigned int *index);
  183. int frame_gop_dequeue(void);
  184. int frame_gop_queue(unsigned int index);
  185. int frame_gop_schedule(struct preset *preset, unsigned int index);
  186. /* V4L2 */
  187. bool video_engine_capabilities_test(int video_fd,
  188. unsigned int capabilities_required);
  189. bool video_engine_format_test(int video_fd, bool mplane, unsigned int width,
  190. unsigned int height, unsigned int format);
  191. int video_engine_start(int video_fd, int media_fd, unsigned int width,
  192. unsigned int height, struct format_description *format,
  193. enum codec_type type, struct video_buffer **buffers,
  194. unsigned int buffers_count, struct video_setup *setup);
  195. int video_engine_stop(int video_fd, struct video_buffer *buffers,
  196. unsigned int buffers_count, struct video_setup *setup);
  197. int video_engine_decode(int video_fd, unsigned int index, union controls *frame,
  198. enum codec_type type, uint64_t ts, void *source_data,
  199. unsigned int source_size, struct video_buffer *buffers,
  200. struct video_setup *setup);
  201. /* DRM */
  202. int display_engine_start(int drm_fd, unsigned int width, unsigned int height,
  203. struct format_description *format,
  204. struct video_buffer *video_buffers, unsigned int count,
  205. struct gem_buffer **buffers,
  206. struct display_setup *setup);
  207. int display_engine_stop(int drm_fd, struct gem_buffer *buffers,
  208. struct display_setup *setup);
  209. int display_engine_show(int drm_fd, unsigned int index,
  210. struct video_buffer *video_buffers,
  211. struct gem_buffer *buffers,
  212. struct display_setup *setup);
  213. #endif