• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _V4L2_CTL_H
2 #define _V4L2_CTL_H
3 
4 #include <cstdint>
5 #include <linux/videodev2.h>
6 #include <linux/v4l2-subdev.h>
7 #include <v4l-getsubopt.h>
8 
9 #include <v4l2-info.h>
10 
11 #ifndef NO_LIBV4L2
12 #include <libv4l2.h>
13 #else
14 #define v4l2_open(file, oflag, ...) (-1)
15 #define v4l2_close(fd) (-1)
16 #define v4l2_ioctl(fd, request, ...) (-1)
17 #define v4l2_mmap(start, length, prot, flags, fd, offset) (MAP_FAILED)
18 #define v4l2_munmap(_start, length) (-1)
19 #endif
20 
21 #include "cv4l-helpers.h"
22 
23 class cv4l_disable_trace {
24 public:
cv4l_disable_trace(cv4l_fd & fd)25 	cv4l_disable_trace(cv4l_fd &fd) : _fd(fd)
26 	{
27 		old_trace = _fd.g_trace();
28 		_fd.s_trace(0);
29 	}
~cv4l_disable_trace()30 	~cv4l_disable_trace()
31 	{
32 		_fd.s_trace(old_trace);
33 	}
34 private:
35 	cv4l_fd &_fd;
36 	unsigned int old_trace;
37 };
38 
39 /* Available options.
40 
41    Please keep the first part (options < 128) in alphabetical order.
42    That makes it easier to see which short options are still free.
43 
44    In general the lower case is used to set something and the upper
45    case is used to retrieve a setting. */
46 enum Option {
47 	OptGetSlicedVbiFormat = 'B',
48 	OptSetSlicedVbiFormat = 'b',
49 	OptGetCtrl = 'C',
50 	OptSetCtrl = 'c',
51 	OptSetDevice = 'd',
52 	OptGetDriverInfo = 'D',
53 	OptSetOutDevice = 'e',
54 	OptSetExportDevice = 'E',
55 	OptGetFreq = 'F',
56 	OptSetFreq = 'f',
57 	OptHelp = 'h',
58 	OptGetInput = 'I',
59 	OptSetInput = 'i',
60 	OptConcise = 'k',
61 	OptListCtrls = 'l',
62 	OptListCtrlsMenus = 'L',
63 	OptListOutputs = 'N',
64 	OptListInputs = 'n',
65 	OptGetOutput = 'O',
66 	OptSetOutput = 'o',
67 	OptGetParm = 'P',
68 	OptSetParm = 'p',
69 	OptSubset = 'r',
70 	OptGetStandard = 'S',
71 	OptSetStandard = 's',
72 	OptGetTuner = 'T',
73 	OptSetTuner = 't',
74 	OptGetVideoFormat = 'V',
75 	OptSetVideoFormat = 'v',
76 	OptUseWrapper = 'w',
77 	OptGetVideoOutFormat = 'X',
78 	OptSetVideoOutFormat = 'x',
79 	OptMediaBusInfo = 'z',
80 
81 	OptGetSlicedVbiOutFormat = 128,
82 	OptGetOverlayFormat,
83 	OptGetVbiFormat,
84 	OptGetVbiOutFormat,
85 	OptGetSdrFormat,
86 	OptGetSdrOutFormat,
87 	OptGetMetaFormat,
88 	OptGetMetaOutFormat,
89 	OptGetSubDevFormat,
90 	OptSetSlicedVbiOutFormat,
91 	OptSetOverlayFormat,
92 	OptSetVbiFormat,
93 	OptSetVbiOutFormat,
94 	OptSetSdrFormat,
95 	OptSetSdrOutFormat,
96 	OptSetMetaFormat,
97 	OptSetMetaOutFormat,
98 	OptSetSubDevFormat,
99 	OptTryVideoOutFormat,
100 	OptTrySlicedVbiOutFormat,
101 	OptTrySlicedVbiFormat,
102 	OptTryVideoFormat,
103 	OptTryOverlayFormat,
104 	OptTryVbiFormat,
105 	OptTryVbiOutFormat,
106 	OptTrySdrFormat,
107 	OptTrySdrOutFormat,
108 	OptTryMetaFormat,
109 	OptTryMetaOutFormat,
110 	OptTrySubDevFormat,
111 	OptAll,
112 	OptListStandards,
113 	OptListFormats,
114 	OptListFormatsExt,
115 	OptListFields,
116 	OptListFrameSizes,
117 	OptListFrameIntervals,
118 	OptListOverlayFormats,
119 	OptListSdrFormats,
120 	OptListSdrOutFormats,
121 	OptListOutFormats,
122 	OptListOutFormatsExt,
123 	OptListMetaFormats,
124 	OptListMetaOutFormats,
125 	OptListSubDevMBusCodes,
126 	OptListSubDevFrameSizes,
127 	OptListSubDevFrameIntervals,
128 	OptListOutFields,
129 	OptClearClips,
130 	OptClearBitmap,
131 	OptAddClip,
132 	OptAddBitmap,
133 	OptFindFb,
134 	OptLogStatus,
135 	OptVerbose,
136 	OptSilent,
137 	OptGetSlicedVbiCap,
138 	OptGetSlicedVbiOutCap,
139 	OptGetFBuf,
140 	OptSetFBuf,
141 	OptGetCrop,
142 	OptSetCrop,
143 	OptGetOutputCrop,
144 	OptSetOutputCrop,
145 	OptGetOverlayCrop,
146 	OptSetOverlayCrop,
147 	OptGetOutputOverlayCrop,
148 	OptSetOutputOverlayCrop,
149 	OptGetSelection,
150 	OptSetSelection,
151 	OptGetOutputSelection,
152 	OptSetOutputSelection,
153 	OptGetSubDevSelection,
154 	OptSetSubDevSelection,
155 	OptTrySubDevSelection,
156 	OptGetSubDevFPS,
157 	OptSetSubDevFPS,
158 	OptGetAudioInput,
159 	OptSetAudioInput,
160 	OptGetAudioOutput,
161 	OptSetAudioOutput,
162 	OptListAudioOutputs,
163 	OptListAudioInputs,
164 	OptGetCropCap,
165 	OptGetOutputCropCap,
166 	OptGetOverlayCropCap,
167 	OptGetOutputOverlayCropCap,
168 	OptOverlay,
169 	OptSleep,
170 	OptGetJpegComp,
171 	OptSetJpegComp,
172 	OptGetModulator,
173 	OptSetModulator,
174 	OptListFreqBands,
175 	OptListDevices,
176 	OptGetOutputParm,
177 	OptSetOutputParm,
178 	OptQueryStandard,
179 	OptPollForEvent,
180 	OptEPollForEvent,
181 	OptWaitForEvent,
182 	OptGetPriority,
183 	OptSetPriority,
184 	OptListDvTimings,
185 	OptQueryDvTimings,
186 	OptGetDvTimings,
187 	OptSetDvBtTimings,
188 	OptGetDvTimingsCap,
189 	OptSetEdid,
190 	OptClearEdid,
191 	OptGetEdid,
192 	OptInfoEdid,
193 	OptShowEdid,
194 	OptKeepEdidChecksums,
195 	OptGetRouting,
196 	OptSetRouting,
197 	OptTryRouting,
198 	OptFreqSeek,
199 	OptEncoderCmd,
200 	OptTryEncoderCmd,
201 	OptDecoderCmd,
202 	OptTryDecoderCmd,
203 	OptTunerIndex,
204 	OptListBuffers,
205 	OptListBuffersOut,
206 	OptListBuffersVbi,
207 	OptListBuffersSlicedVbi,
208 	OptListBuffersVbiOut,
209 	OptListBuffersSlicedVbiOut,
210 	OptListBuffersSdr,
211 	OptListBuffersSdrOut,
212 	OptListBuffersMeta,
213 	OptListBuffersMetaOut,
214 	OptStreamCount,
215 	OptStreamSkip,
216 	OptStreamLoop,
217 	OptStreamSleep,
218 	OptStreamPoll,
219 	OptStreamNoQuery,
220 	OptStreamTo,
221 	OptStreamToHdr,
222 	OptStreamToHost,
223 	OptStreamLossless,
224 	OptStreamShowDeltaNow,
225 	OptStreamBufCaps,
226 	OptStreamMmap,
227 	OptStreamUser,
228 	OptStreamDmaBuf,
229 	OptStreamFrom,
230 	OptStreamFromHdr,
231 	OptStreamFromHost,
232 	OptStreamOutPattern,
233 	OptStreamOutSquare,
234 	OptStreamOutBorder,
235 	OptStreamOutInsertSAV,
236 	OptStreamOutInsertEAV,
237 	OptStreamOutHorSpeed,
238 	OptStreamOutVertSpeed,
239 	OptStreamOutPercFill,
240 	OptStreamOutAlphaComponent,
241 	OptStreamOutAlphaRedOnly,
242 	OptStreamOutRGBLimitedRange,
243 	OptStreamOutPixelAspect,
244 	OptStreamOutVideoAspect,
245 	OptStreamOutBufCaps,
246 	OptStreamOutMmap,
247 	OptStreamOutUser,
248 	OptStreamOutDmaBuf,
249 	OptListPatterns,
250 	OptHelpTuner,
251 	OptHelpIO,
252 	OptHelpStds,
253 	OptHelpVidCap,
254 	OptHelpVidOut,
255 	OptHelpOverlay,
256 	OptHelpVbi,
257 	OptHelpSdr,
258 	OptHelpMeta,
259 	OptHelpSubDev,
260 	OptHelpSelection,
261 	OptHelpMisc,
262 	OptHelpStreaming,
263 	OptHelpEdid,
264 	OptHelpAll,
265 	OptVersion,
266 	OptLast = 512
267 };
268 
269 extern char options[OptLast];
270 extern unsigned capabilities;
271 extern unsigned out_capabilities;
272 extern unsigned priv_magic;
273 extern unsigned out_priv_magic;
274 extern bool is_multiplanar;
275 extern __u32 vidcap_buftype;
276 extern __u32 vidout_buftype;
277 extern int verbose;
278 
279 /* fmts specified */
280 #define FmtWidth		(1L<<0)
281 #define FmtHeight		(1L<<1)
282 #define FmtChromaKey		(1L<<2)
283 #define FmtGlobalAlpha		(1L<<3)
284 #define FmtPixelFormat		(1L<<4)
285 #define FmtLeft			(1L<<5)
286 #define FmtTop			(1L<<6)
287 #define FmtField		(1L<<7)
288 #define FmtColorspace		(1L<<8)
289 #define FmtYCbCr		(1L<<9)
290 #define FmtQuantization		(1L<<10)
291 #define FmtFlags		(1L<<11)
292 #define FmtBytesPerLine		(1L<<12)
293 #define FmtXferFunc		(1L<<13)
294 #define FmtSizeImage		(1L<<14)
295 
296 // v4l2-ctl.cpp
297 int doioctl_name(int fd, unsigned long int request, void *parm, const char *name);
298 int test_ioctl(int fd, unsigned long cmd, void *arg);
299 int parse_subopt(char **subs, const char * const *subopts, char **value);
300 __u32 parse_field(const char *s);
301 __u32 parse_colorspace(const char *s);
302 __u32 parse_xfer_func(const char *s);
303 __u32 parse_ycbcr(const char *s);
304 __u32 parse_hsv(const char *s);
305 __u32 parse_quantization(const char *s);
306 int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat,
307 	      __u32 &field, __u32 &colorspace, __u32 &xfer, __u32 &ycbcr,
308 	      __u32 &quantization, __u32 &flags, __u32 *bytesperline,
309 	      __u32 *sizeimage);
310 int parse_selection_target(const char *s, unsigned int &target);
311 int parse_selection_flags(const char *s);
312 void print_selection(const struct v4l2_selection &sel);
313 __u32 find_pixel_format(int fd, unsigned index, bool output, bool mplane);
314 bool valid_pixel_format(int fd, __u32 pixelformat, bool output, bool mplane);
315 void print_frmsize(const struct v4l2_frmsizeenum &frmsize, const char *prefix);
316 void print_frmival(const struct v4l2_frmivalenum &frmival, const char *prefix);
317 void printfmt(int fd, const struct v4l2_format &vfmt);
318 void print_video_formats(cv4l_fd &fd, __u32 type, unsigned int mbus_code);
319 void print_video_formats_ext(cv4l_fd &fd, __u32 type, unsigned int mbus_code);
320 
subscribe_event(cv4l_fd & fd,__u32 type)321 static inline bool subscribe_event(cv4l_fd &fd, __u32 type)
322 {
323 	struct v4l2_event_subscription sub;
324 
325 	memset(&sub, 0, sizeof(sub));
326 	sub.type = type;
327 
328 	cv4l_disable_trace dt(fd);
329 	return !fd.subscribe_event(sub);
330 }
331 
332 #define doioctl(n, r, p) doioctl_name(n, r, p, #r)
333 
334 #define info(fmt, args...) 			\
335 	do {					\
336 		if (!options[OptSilent])	\
337 			printf(fmt, ##args);	\
338 	} while (0)
339 
340 #define stderr_info(fmt, args...) 			\
341 	do {						\
342 		if (!options[OptSilent])		\
343 			fprintf(stderr, fmt, ##args);	\
344 	} while (0)
345 
346 // v4l2-ctl-common.cpp
347 void common_usage(void);
348 void common_cmd(int ch, char *optarg);
349 void common_set(cv4l_fd &fd);
350 void common_get(cv4l_fd &fd);
351 void common_list(const std::string &media_bus_info, cv4l_fd &fd);
352 void common_process_controls(cv4l_fd &fd);
353 void common_control_event(int fd, const struct v4l2_event *ev);
354 int common_find_ctrl_id(const char *name);
355 
356 // v4l2-ctl-tuner.cpp
357 void tuner_usage(void);
358 void tuner_cmd(int ch, char *optarg);
359 void tuner_set(cv4l_fd &fd);
360 void tuner_get(cv4l_fd &fd);
361 
362 // v4l2-ctl-io.cpp
363 void io_usage(void);
364 void io_cmd(int ch, char *optarg);
365 void io_set(cv4l_fd &fd);
366 void io_get(cv4l_fd &fd);
367 void io_list(cv4l_fd &fd);
368 
369 // v4l2-ctl-stds.cpp
370 void stds_usage(void);
371 void stds_cmd(int ch, char *optarg);
372 void stds_set(cv4l_fd &fd);
373 void stds_get(cv4l_fd &fd);
374 void stds_list(cv4l_fd &fd);
375 
376 // v4l2-ctl-vidcap.cpp
377 void vidcap_usage(void);
378 void vidcap_cmd(int ch, char *optarg);
379 int vidcap_get_and_update_fmt(cv4l_fd &_fd, struct v4l2_format &vfmt);
380 void vidcap_set(cv4l_fd &fd);
381 void vidcap_get(cv4l_fd &fd);
382 void vidcap_list(cv4l_fd &fd);
383 void print_touch_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q);
384 
385 // v4l2-ctl-vidout.cpp
386 void vidout_usage(void);
387 void vidout_cmd(int ch, char *optarg);
388 void vidout_set(cv4l_fd &fd);
389 void vidout_get(cv4l_fd &fd);
390 void vidout_list(cv4l_fd &fd);
391 
392 // v4l2-ctl-overlay.cpp
393 void overlay_usage(void);
394 void overlay_cmd(int ch, char *optarg);
395 void overlay_set(cv4l_fd &fd);
396 void overlay_get(cv4l_fd &fd);
397 void overlay_list(cv4l_fd &fd);
398 
399 // v4l2-ctl-vbi.cpp
400 void vbi_usage(void);
401 void vbi_cmd(int ch, char *optarg);
402 void vbi_set(cv4l_fd &fd);
403 void vbi_get(cv4l_fd &fd);
404 void vbi_list(cv4l_fd &fd);
405 
406 // v4l2-ctl-sdr.cpp
407 void sdr_usage(void);
408 void sdr_cmd(int ch, char *optarg);
409 void sdr_set(cv4l_fd &fd);
410 void sdr_get(cv4l_fd &fd);
411 void sdr_list(cv4l_fd &fd);
412 
413 // v4l2-ctl-meta.cpp
414 void meta_usage(void);
415 void meta_cmd(int ch, char *optarg);
416 void meta_set(cv4l_fd &fd);
417 void meta_get(cv4l_fd &fd);
418 void meta_list(cv4l_fd &fd);
419 void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q);
420 void meta_fillbuffer(cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q);
421 
422 // v4l2-ctl-subdev.cpp
423 void subdev_usage(void);
424 void subdev_cmd(int ch, char *optarg);
425 void subdev_set(cv4l_fd &fd);
426 void subdev_get(cv4l_fd &fd);
427 void subdev_list(cv4l_fd &fd);
428 
429 // v4l2-ctl-selection.cpp
430 void selection_usage(void);
431 void selection_cmd(int ch, char *optarg);
432 void selection_set(cv4l_fd &fd);
433 void selection_get(cv4l_fd &fd);
434 
435 // v4l2-ctl-misc.cpp
436 // This one is also used by the streaming code.
437 extern struct v4l2_decoder_cmd dec_cmd;
438 void misc_usage(void);
439 void misc_cmd(int ch, char *optarg);
440 void misc_set(cv4l_fd &fd);
441 void misc_get(cv4l_fd &fd);
442 
443 // v4l2-ctl-streaming.cpp
444 void streaming_usage(void);
445 void streaming_cmd(int ch, char *optarg);
446 void streaming_set(cv4l_fd &fd, cv4l_fd &out_fd, cv4l_fd &exp_fd);
447 void streaming_list(cv4l_fd &fd, cv4l_fd &out_fd);
448 
449 // v4l2-ctl-edid.cpp
450 void edid_usage(void);
451 void edid_cmd(int ch, char *optarg);
452 void edid_set(cv4l_fd &fd);
453 void edid_get(cv4l_fd &fd);
454 
455 /* v4l2-ctl-modes.cpp */
456 bool calc_cvt_modeline(int image_width, int image_height,
457 		       int refresh_rate, int reduced_blanking,
458 		       bool interlaced, bool reduced_fps,
459 		       struct v4l2_bt_timings *cvt);
460 
461 bool calc_gtf_modeline(int image_width, int image_height,
462 		       int refresh_rate, bool reduced_blanking,
463 		       bool interlaced, struct v4l2_bt_timings *gtf);
464 #endif
465