aboutsummaryrefslogtreecommitdiffstats
path: root/utils/v4l2-ctl/v4l2-ctl.h
blob: 703c05c2943f3a2556eac7bb53dfaa37927bf599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
#ifndef _V4L2_CTL_H
#define _V4L2_CTL_H

#ifdef ANDROID
#include <android-config.h>
#else
#include <config.h>
#endif

#include <string>

#include <linux/videodev2.h>
#include <linux/v4l2-subdev.h>

#include <v4l2-info.h>

#ifndef NO_LIBV4L2
#include <libv4l2.h>
#else
#define v4l2_open(file, oflag, ...) (-1)
#define v4l2_close(fd) (-1)
#define v4l2_ioctl(fd, request, ...) (-1)
#define v4l2_mmap(start, length, prot, flags, fd, offset) (MAP_FAILED)
#define v4l2_munmap(_start, length) (-1)
#endif

#include "cv4l-helpers.h"

class cv4l_disable_trace {
public:
	cv4l_disable_trace(cv4l_fd &fd) : _fd(fd)
	{
		old_trace = _fd.g_trace();
		_fd.s_trace(0);
	}
	~cv4l_disable_trace()
	{
		_fd.s_trace(old_trace);
	}
private:
	cv4l_fd &_fd;
	unsigned int old_trace;
};

/* Available options.

   Please keep the first part (options < 128) in alphabetical order.
   That makes it easier to see which short options are still free.

   In general the lower case is used to set something and the upper
   case is used to retrieve a setting. */
enum Option {
	OptGetSlicedVbiFormat = 'B',
	OptSetSlicedVbiFormat = 'b',
	OptGetCtrl = 'C',
	OptSetCtrl = 'c',
	OptSetDevice = 'd',
	OptGetDriverInfo = 'D',
	OptSetOutDevice = 'e',
	OptSetExportDevice = 'E',
	OptGetFreq = 'F',
	OptSetFreq = 'f',
	OptHelp = 'h',
	OptGetInput = 'I',
	OptSetInput = 'i',
	OptConcise = 'k',
	OptListCtrls = 'l',
	OptListCtrlsMenus = 'L',
	OptListOutputs = 'N',
	OptListInputs = 'n',
	OptGetOutput = 'O',
	OptSetOutput = 'o',
	OptGetParm = 'P',
	OptSetParm = 'p',
	OptSubset = 'r',
	OptGetStandard = 'S',
	OptSetStandard = 's',
	OptGetTuner = 'T',
	OptSetTuner = 't',
	OptGetVideoFormat = 'V',
	OptSetVideoFormat = 'v',
	OptUseWrapper = 'w',
	OptGetVideoOutFormat = 'X',
	OptSetVideoOutFormat = 'x',
	OptMediaBusInfo = 'z',

	OptGetSlicedVbiOutFormat = 128,
	OptGetOverlayFormat,
	OptGetVbiFormat,
	OptGetVbiOutFormat,
	OptGetSdrFormat,
	OptGetSdrOutFormat,
	OptGetMetaFormat,
	OptGetMetaOutFormat,
	OptGetSubDevFormat,
	OptSetSlicedVbiOutFormat,
	OptSetOverlayFormat,
	OptSetVbiFormat,
	OptSetVbiOutFormat,
	OptSetSdrFormat,
	OptSetSdrOutFormat,
	OptSetMetaFormat,
	OptSetMetaOutFormat,
	OptSetSubDevFormat,
	OptTryVideoOutFormat,
	OptTrySlicedVbiOutFormat,
	OptTrySlicedVbiFormat,
	OptTryVideoFormat,
	OptTryOverlayFormat,
	OptTryVbiFormat,
	OptTryVbiOutFormat,
	OptTrySdrFormat,
	OptTrySdrOutFormat,
	OptTryMetaFormat,
	OptTryMetaOutFormat,
	OptTrySubDevFormat,
	OptAll,
	OptListStandards,
	OptListFormats,
	OptListFormatsExt,
	OptListFields,
	OptListFrameSizes,
	OptListFrameIntervals,
	OptListOverlayFormats,
	OptListSdrFormats,
	OptListSdrOutFormats,
	OptListOutFormats,
	OptListOutFormatsExt,
	OptListMetaFormats,
	OptListMetaOutFormats,
	OptListSubDevMBusCodes,
	OptListSubDevFrameSizes,
	OptListSubDevFrameIntervals,
	OptListOutFields,
	OptClearClips,
	OptClearBitmap,
	OptAddClip,
	OptAddBitmap,
	OptFindFb,
	OptLogStatus,
	OptVerbose,
	OptSilent,
	OptGetSlicedVbiCap,
	OptGetSlicedVbiOutCap,
	OptGetFBuf,
	OptSetFBuf,
	OptGetCrop,
	OptSetCrop,
	OptGetOutputCrop,
	OptSetOutputCrop,
	OptGetOverlayCrop,
	OptSetOverlayCrop,
	OptGetOutputOverlayCrop,
	OptSetOutputOverlayCrop,
	OptGetSelection,
	OptSetSelection,
	OptGetOutputSelection,
	OptSetOutputSelection,
	OptGetSubDevSelection,
	OptSetSubDevSelection,
	OptTrySubDevSelection,
	OptGetSubDevFPS,
	OptSetSubDevFPS,
	OptGetAudioInput,
	OptSetAudioInput,
	OptGetAudioOutput,
	OptSetAudioOutput,
	OptListAudioOutputs,
	OptListAudioInputs,
	OptGetCropCap,
	OptGetOutputCropCap,
	OptGetOverlayCropCap,
	OptGetOutputOverlayCropCap,
	OptOverlay,
	OptSleep,
	OptGetJpegComp,
	OptSetJpegComp,
	OptGetModulator,
	OptSetModulator,
	OptListFreqBands,
	OptListDevices,
	OptGetOutputParm,
	OptSetOutputParm,
	OptQueryStandard,
	OptPollForEvent,
	OptWaitForEvent,
	OptGetPriority,
	OptSetPriority,
	OptListDvTimings,
	OptQueryDvTimings,
	OptGetDvTimings,
	OptSetDvBtTimings,
	OptGetDvTimingsCap,
	OptSetEdid,
	OptClearEdid,
	OptGetEdid,
	OptInfoEdid,
	OptFixEdidChecksums,
	OptFreqSeek,
	OptEncoderCmd,
	OptTryEncoderCmd,
	OptDecoderCmd,
	OptTryDecoderCmd,
	OptTunerIndex,
	OptListBuffers,
	OptListBuffersOut,
	OptListBuffersVbi,
	OptListBuffersSlicedVbi,
	OptListBuffersVbiOut,
	OptListBuffersSlicedVbiOut,
	OptListBuffersSdr,
	OptListBuffersSdrOut,
	OptListBuffersMeta,
	OptListBuffersMetaOut,
	OptStreamCount,
	OptStreamSkip,
	OptStreamLoop,
	OptStreamSleep,
	OptStreamPoll,
	OptStreamNoQuery,
	OptStreamTo,
	OptStreamToHdr,
	OptStreamToHost,
	OptStreamLossless,
	OptStreamBufCaps,
	OptStreamMmap,
	OptStreamUser,
	OptStreamDmaBuf,
	OptStreamFrom,
	OptStreamFromHdr,
	OptStreamFromHost,
	OptStreamOutPattern,
	OptStreamOutSquare,
	OptStreamOutBorder,
	OptStreamOutInsertSAV,
	OptStreamOutInsertEAV,
	OptStreamOutHorSpeed,
	OptStreamOutVertSpeed,
	OptStreamOutPercFill,
	OptStreamOutAlphaComponent,
	OptStreamOutAlphaRedOnly,
	OptStreamOutRGBLimitedRange,
	OptStreamOutPixelAspect,
	OptStreamOutVideoAspect,
	OptStreamOutBufCaps,
	OptStreamOutMmap,
	OptStreamOutUser,
	OptStreamOutDmaBuf,
	OptListPatterns,
	OptHelpTuner,
	OptHelpIO,
	OptHelpStds,
	OptHelpVidCap,
	OptHelpVidOut,
	OptHelpOverlay,
	OptHelpVbi,
	OptHelpSdr,
	OptHelpMeta,
	OptHelpSubDev,
	OptHelpSelection,
	OptHelpMisc,
	OptHelpStreaming,
	OptHelpEdid,
	OptHelpAll,
	OptLast = 512
};

extern char options[OptLast];
extern unsigned capabilities;
extern unsigned out_capabilities;
extern unsigned priv_magic;
extern unsigned out_priv_magic;
extern bool is_multiplanar;
extern __u32 vidcap_buftype;
extern __u32 vidout_buftype;
extern int verbose;

typedef struct {
	unsigned flag;
	const char *str;
} flag_def;

/* fmts specified */
#define FmtWidth		(1L<<0)
#define FmtHeight		(1L<<1)
#define FmtChromaKey		(1L<<2)
#define FmtGlobalAlpha		(1L<<3)
#define FmtPixelFormat		(1L<<4)
#define FmtLeft			(1L<<5)
#define FmtTop			(1L<<6)
#define FmtField		(1L<<7)
#define FmtColorspace		(1L<<8)
#define FmtYCbCr		(1L<<9)
#define FmtQuantization		(1L<<10)
#define FmtFlags		(1L<<11)
#define FmtBytesPerLine		(1L<<12)
#define FmtXferFunc		(1L<<13)

// v4l2-ctl.cpp
int doioctl_name(int fd, unsigned long int request, void *parm, const char *name);
int test_ioctl(int fd, int cmd, void *arg);
int parse_subopt(char **subs, const char * const *subopts, char **value);
__u32 parse_field(const char *s);
__u32 parse_colorspace(const char *s);
__u32 parse_xfer_func(const char *s);
__u32 parse_ycbcr(const char *s);
__u32 parse_hsv(const char *s);
__u32 parse_quantization(const char *s);
int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat,
	      __u32 &field, __u32 &colorspace, __u32 &xfer, __u32 &ycbcr,
	      __u32 &quantization, __u32 &flags, __u32 *bytesperline);
int parse_selection_target(const char *s, unsigned int &target);
int parse_selection_flags(const char *s);
void print_selection(const struct v4l2_selection &sel);
__u32 find_pixel_format(int fd, unsigned index, bool output, bool mplane);
void print_frmsize(const struct v4l2_frmsizeenum &frmsize, const char *prefix);
void print_frmival(const struct v4l2_frmivalenum &frmival, const char *prefix);
void printfmt(int fd, const struct v4l2_format &vfmt);
void print_video_formats(cv4l_fd &fd, __u32 type);
void print_video_formats_ext(cv4l_fd &fd, __u32 type);

#define doioctl(n, r, p) doioctl_name(n, r, p, #r)

// v4l2-ctl-common.cpp
void common_usage(void);
void common_cmd(int ch, char *optarg);
void common_set(cv4l_fd &fd);
void common_get(cv4l_fd &fd);
void common_list(cv4l_fd &fd);
void common_process_controls(cv4l_fd &fd);
void common_control_event(const struct v4l2_event *ev);
int common_find_ctrl_id(const char *name);

// v4l2-ctl-tuner.cpp
void tuner_usage(void);
void tuner_cmd(int ch, char *optarg);
void tuner_set(cv4l_fd &fd);
void tuner_get(cv4l_fd &fd);

// v4l2-ctl-io.cpp
void io_usage(void);
void io_cmd(int ch, char *optarg);
void io_set(cv4l_fd &fd);
void io_get(cv4l_fd &fd);
void io_list(cv4l_fd &fd);

// v4l2-ctl-stds.cpp
void stds_usage(void);
void stds_cmd(int ch, char *optarg);
void stds_set(cv4l_fd &fd);
void stds_get(cv4l_fd &fd);
void stds_list(cv4l_fd &fd);

// v4l2-ctl-vidcap.cpp
void vidcap_usage(void);
void vidcap_cmd(int ch, char *optarg);
int vidcap_get_and_update_fmt(cv4l_fd &_fd, struct v4l2_format &vfmt);
void vidcap_set(cv4l_fd &fd);
void vidcap_get(cv4l_fd &fd);
void vidcap_list(cv4l_fd &fd);

// v4l2-ctl-vidout.cpp
void vidout_usage(void);
void vidout_cmd(int ch, char *optarg);
void vidout_set(cv4l_fd &fd);
void vidout_get(cv4l_fd &fd);
void vidout_list(cv4l_fd &fd);

// v4l2-ctl-overlay.cpp
void overlay_usage(void);
void overlay_cmd(int ch, char *optarg);
void overlay_set(cv4l_fd &fd);
void overlay_get(cv4l_fd &fd);
void overlay_list(cv4l_fd &fd);

// v4l2-ctl-vbi.cpp
void vbi_usage(void);
void vbi_cmd(int ch, char *optarg);
void vbi_set(cv4l_fd &fd);
void vbi_get(cv4l_fd &fd);
void vbi_list(cv4l_fd &fd);

// v4l2-ctl-sdr.cpp
void sdr_usage(void);
void sdr_cmd(int ch, char *optarg);
void sdr_set(cv4l_fd &fd);
void sdr_get(cv4l_fd &fd);
void sdr_list(cv4l_fd &fd);

// v4l2-ctl-meta.cpp
void meta_usage(void);
void meta_cmd(int ch, char *optarg);
void meta_set(cv4l_fd &fd);
void meta_get(cv4l_fd &fd);
void meta_list(cv4l_fd &fd);

// v4l2-ctl-subdev.cpp
void subdev_usage(void);
void subdev_cmd(int ch, char *optarg);
void subdev_set(cv4l_fd &fd);
void subdev_get(cv4l_fd &fd);
void subdev_list(cv4l_fd &fd);

// v4l2-ctl-selection.cpp
void selection_usage(void);
void selection_cmd(int ch, char *optarg);
void selection_set(cv4l_fd &fd);
void selection_get(cv4l_fd &fd);

// v4l2-ctl-misc.cpp
// This one is also used by the streaming code.
extern struct v4l2_decoder_cmd dec_cmd;
void misc_usage(void);
void misc_cmd(int ch, char *optarg);
void misc_set(cv4l_fd &fd);
void misc_get(cv4l_fd &fd);

// v4l2-ctl-streaming.cpp
void streaming_usage(void);
void streaming_cmd(int ch, char *optarg);
void streaming_set(cv4l_fd &fd, cv4l_fd &out_fd, cv4l_fd &exp_fd);
void streaming_list(cv4l_fd &fd, cv4l_fd &out_fd);

// v4l2-ctl-edid.cpp
void edid_usage(void);
void edid_cmd(int ch, char *optarg);
void edid_set(cv4l_fd &fd);
void edid_get(cv4l_fd &fd);

/* v4l2-ctl-modes.cpp */
bool calc_cvt_modeline(int image_width, int image_height,
		       int refresh_rate, int reduced_blanking,
		       bool interlaced, bool reduced_fps,
		       struct v4l2_bt_timings *cvt);

bool calc_gtf_modeline(int image_width, int image_height,
		       int refresh_rate, bool reduced_blanking,
		       bool interlaced, struct v4l2_bt_timings *gtf);
#endif

Privacy Policy