278
287
{"set-jpeg-comp", required_argument, 0, OptSetJpegComp},
279
288
{"get-modulator", no_argument, 0, OptGetModulator},
280
289
{"set-modulator", required_argument, 0, OptSetModulator},
290
{"get-priority", no_argument, 0, OptGetPriority},
291
{"set-priority", required_argument, 0, OptSetPriority},
292
{"wait-for-event", required_argument, 0, OptWaitForEvent},
293
{"poll-for-event", required_argument, 0, OptPollForEvent},
281
294
{"overlay", required_argument, 0, OptOverlay},
295
{"sleep", required_argument, 0, OptSleep},
282
296
{"list-devices", no_argument, 0, OptListDevices},
297
{"list-dv-presets", no_argument, 0, OptListDvPresets},
298
{"set-dv-presets", required_argument, 0, OptSetDvPreset},
299
{"get-dv-presets", no_argument, 0, OptGetDvPreset},
300
{"query-dv-presets", no_argument, 0, OptQueryDvPreset},
320
338
" secam-X (X = B/G/H/D/K/L/Lc) or just 'secam' (V4L2_STD_SECAM)\n"
321
339
" --list-standards display supported video standards [VIDIOC_ENUMSTD]\n"
322
340
" --get-detected-standard\n"
323
" display video detected input video standard [VIDIOC_QUERYSTD]\n"
341
" display detected input video standard [VIDIOC_QUERYSTD]\n"
324
342
" -P, --get-parm display video parameters [VIDIOC_G_PARM]\n"
325
343
" -p, --set-parm=<fps>\n"
326
344
" set video framerate in <fps> [VIDIOC_S_PARM]\n"
450
468
" bilingual: Modulate as bilingual\n"
451
469
" mono-sap: Modulate as mono with Second Audio Program\n"
452
470
" stereo-sap: Modulate as stereo with Second Audio Program\n"
471
" --get-priority query the current access priority [VIDIOC_G_PRIORITY]\n"
472
" --set-priority=<prio>\n"
473
" set the new access priority [VIDIOC_S_PRIORITY]\n"
474
" <prio> is 1 (background), 2 (interactive) or 3 (record)\n"
453
475
" --get-output-parm display output video parameters [VIDIOC_G_PARM]\n"
454
476
" --set-output-parm=<fps>\n"
455
477
" set output video framerate in <fps> [VIDIOC_S_PARM]\n"
457
printf("Expert options:\n"
478
" --wait-for-event=<event>\n"
479
" wait for an event [VIDIOC_DQEVENT]\n"
480
" <event> is the event number or one of:\n"
482
" --poll-for-event=<event>\n"
483
" poll for an event [VIDIOC_DQEVENT]\n"
484
" see --wait-for-event for possible events\n"
485
" --list-dv-presets list supported digital video presets [VIDIOC_ENUM_DV_PRESETS]\n"
486
" --set-dv-preset=<num>\n"
487
" set the digital video preset to <num> [VIDIOC_S_DV_PRESET]\n"
488
" --get-dv-preset query the digital video preset in use [VIDIOC_G_DV_PRESET]\n"
489
" --query-dv-preset query the detected digital video preset [VIDIOC_QUERY_DV_PRESET]\n"
490
" --sleep=<secs> sleep for <secs> seconds, call QUERYCAP and close the file handle\n"
458
491
" --streamoff turn the stream off [VIDIOC_STREAMOFF]\n"
459
" --streamon turn the stream on [VIDIOC_STREAMOFF]\n"
492
" --streamon turn the stream on [VIDIOC_STREAMON]\n"
460
493
" --log-status log the board status in the kernel log [VIDIOC_LOG_STATUS]\n");
636
static const flag_def input_cap_def[] = {
637
{V4L2_IN_CAP_PRESETS, "DV presets" },
638
{V4L2_IN_CAP_CUSTOM_TIMINGS, "custom DV timings" },
639
{V4L2_IN_CAP_STD, "SD presets" },
643
static std::string input_cap2s(__u32 capabilities)
645
return capabilities ? flags2s(capabilities, input_cap_def) : "not defined";
648
static const flag_def output_cap_def[] = {
649
{V4L2_OUT_CAP_PRESETS, "DV presets" },
650
{V4L2_OUT_CAP_CUSTOM_TIMINGS, "custom DV timings" },
651
{V4L2_OUT_CAP_STD, "SD presets" },
655
static std::string output_cap2s(__u32 capabilities)
657
return capabilities ? flags2s(capabilities, output_cap_def) : "not defined";
603
660
static void print_sliced_vbi_cap(struct v4l2_sliced_vbi_cap &cap)
605
662
printf("\tType : %s\n", buftype2s(cap.type).c_str());
704
761
queryctrl->default_value, ctrl->value);
706
763
case V4L2_CTRL_TYPE_BUTTON:
707
printf("%31s (button)\n", s.c_str());
764
printf("%31s (btn) :", s.c_str());
746
803
ext_ctrl.id = qctrl.id;
804
if ((qctrl.flags & V4L2_CTRL_FLAG_WRITE_ONLY) ||
805
qctrl.type == V4L2_CTRL_TYPE_BUTTON) {
806
print_qctrl(fd, &qctrl, &ext_ctrl, show_menus);
747
809
ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(qctrl.id);
749
811
ctrls.controls = &ext_ctrl;
750
if (V4L2_CTRL_ID2CLASS(qctrl.id) != V4L2_CTRL_CLASS_USER &&
751
qctrl.id < V4L2_CID_PRIVATE_BASE) {
812
if (qctrl.type == V4L2_CTRL_TYPE_INTEGER64 ||
813
qctrl.type == V4L2_CTRL_TYPE_STRING ||
814
(V4L2_CTRL_ID2CLASS(qctrl.id) != V4L2_CTRL_CLASS_USER &&
815
qctrl.id < V4L2_CID_PRIVATE_BASE)) {
752
816
if (qctrl.type == V4L2_CTRL_TYPE_STRING) {
753
817
ext_ctrl.size = qctrl.maximum + 1;
754
818
ext_ctrl.string = (char *)malloc(ext_ctrl.size);
1126
static char *pts_to_string(char *str, unsigned long pts)
1128
static char buf[256];
1129
int hours, minutes, seconds, fracsec;
1132
char *p = (str) ? str : buf;
1134
static const int MPEG_CLOCK_FREQ = 90000;
1135
seconds = pts / MPEG_CLOCK_FREQ;
1136
fracsec = pts % MPEG_CLOCK_FREQ;
1138
minutes = seconds / 60;
1139
seconds = seconds % 60;
1141
hours = minutes / 60;
1142
minutes = minutes % 60;
1145
frame = (int)ceilf(((float)fracsec / (float)MPEG_CLOCK_FREQ) * fps);
1147
snprintf(p, sizeof(buf), "%d:%02d:%02d:%d", hours, minutes, seconds,
1152
1190
static const char *audmode2s(int audmode)
1154
1192
switch (audmode) {
1650
1688
return V4L2_FIELD_ANY;
1691
static void print_event(const struct v4l2_event *ev)
1693
printf("%ld.%06ld: event %u, pending %u: ",
1694
ev->timestamp.tv_sec, ev->timestamp.tv_nsec / 1000,
1695
ev->sequence, ev->pending);
1697
case V4L2_EVENT_VSYNC:
1698
printf("vsync %s\n", field2s(ev->u.vsync.field).c_str());
1700
case V4L2_EVENT_EOS:
1704
if (ev->type >= V4L2_EVENT_PRIVATE_START)
1705
printf("unknown private event (%08x)\n", ev->type);
1707
printf("unknown event (%08x)\n", ev->type);
1712
static __u32 parse_event(const char *e)
1717
event = strtoul(e, 0L, 0);
1718
else if (!strcmp(e, "eos"))
1719
event = V4L2_EVENT_EOS;
1720
else if (!strcmp(e, "vsync"))
1721
event = V4L2_EVENT_VSYNC;
1724
fprintf(stderr, "Unknown event\n");
1653
1730
static __u32 find_pixel_format(int fd, unsigned index)
1655
1732
struct v4l2_fmtdesc fmt;
1708
1785
struct v4l2_framebuffer fbuf; /* fbuf */
1709
1786
struct v4l2_jpegcompression jpegcomp; /* jpeg compression */
1710
1787
struct v4l2_streamparm parm; /* get/set parm */
1788
struct v4l2_dv_enum_preset dv_enum_preset; /* list_dv_preset */
1789
struct v4l2_dv_preset dv_preset; /* set_dv_preset/get_dv_preset/query_dv_preset */
1711
1790
int input; /* set_input/get_input */
1712
1791
int output; /* set_output/get_output */
1713
1792
int txsubchans = 0; /* set_modulator */
1720
1799
int overlay; /* overlay */
1721
1800
unsigned int *set_overlay_fmt_ptr = NULL;
1722
1801
struct v4l2_format *overlay_fmt_ptr = NULL;
1802
__u32 wait_for_event = 0; /* wait for this event */
1803
__u32 poll_for_event = 0; /* poll for this event */
1805
enum v4l2_priority prio = V4L2_PRIORITY_UNSET;
1723
1806
char short_options[26 * 2 * 2 + 1];
1749
1832
memset(&vs, 0, sizeof(vs));
1750
1833
memset(&fbuf, 0, sizeof(fbuf));
1751
1834
memset(&jpegcomp, 0, sizeof(jpegcomp));
1835
memset(&dv_preset, 0, sizeof(dv_preset));
1836
memset(&dv_enum_preset, 0, sizeof(dv_enum_preset));
1753
1838
if (argc == 1) {
2286
secs = strtoul(optarg, 0L, 0);
2288
case OptSetPriority:
2289
prio = (enum v4l2_priority)strtoul(optarg, 0L, 0);
2291
case OptWaitForEvent:
2292
wait_for_event = parse_event(optarg);
2293
if (wait_for_event == 0)
2296
case OptPollForEvent:
2297
poll_for_event = parse_event(optarg);
2298
if (poll_for_event == 0)
2200
2301
case OptListDevices:
2201
2302
list_devices();
2304
case OptSetDvPreset:
2305
dv_preset.preset = strtoul(optarg, 0L, 0);
2204
2308
fprintf(stderr, "Option `%s' requires a value\n",
2269
2373
options[OptGetCropCap] = 1;
2270
2374
options[OptGetOutputCropCap] = 1;
2271
2375
options[OptGetJpegComp] = 1;
2376
options[OptGetDvPreset] = 1;
2377
options[OptGetPriority] = 1;
2272
2378
options[OptSilent] = 1;
2291
2397
doioctl(fd, VIDIOC_STREAMOFF, &dummy, "VIDIOC_STREAMOFF");
2400
if (options[OptSetPriority]) {
2401
if (doioctl(fd, VIDIOC_S_PRIORITY, &prio, "VIDIOC_S_PRIORITY") >= 0) {
2402
printf("Priority set: %d\n", prio);
2294
2406
if (options[OptSetFreq]) {
2295
2407
double fac = 16;
2323
2435
printf("Standard set to %08llx\n", (unsigned long long)std);
2438
if (options[OptSetDvPreset]){
2439
if (doioctl(fd, VIDIOC_S_DV_PRESET, &dv_preset, "VIDIOC_S_DV_PRESET") >= 0) {
2440
printf("Preset set: %d\n", dv_preset.preset);
2327
2444
if (options[OptSetParm]) {
2328
2445
memset(&parm, 0, sizeof(parm));
2563
2679
if (options[OptSetCtrl] && !set_ctrls.empty()) {
2564
2680
struct v4l2_ext_controls ctrls = { 0 };
2565
2681
class2ctrls_map class2ctrls;
2682
bool use_ext_ctrls = false;
2567
2684
for (ctrl_set_map::iterator iter = set_ctrls.begin();
2568
2685
iter != set_ctrls.end(); ++iter) {
2569
2686
struct v4l2_ext_control ctrl = { 0 };
2571
2688
ctrl.id = ctrl_str2q[iter->first].id;
2689
if (ctrl_str2q[iter->first].type == V4L2_CTRL_TYPE_INTEGER64)
2690
use_ext_ctrls = true;
2572
2691
if (ctrl_str2q[iter->first].type == V4L2_CTRL_TYPE_STRING) {
2573
2692
unsigned len = iter->second.length();
2574
2693
unsigned maxlen = ctrl_str2q[iter->first].maximum;
2695
use_ext_ctrls = true;
2576
2696
ctrl.size = maxlen + 1;
2577
2697
ctrl.string = (char *)malloc(ctrl.size);
2578
2698
if (len > maxlen) {
2590
2710
for (class2ctrls_map::iterator iter = class2ctrls.begin();
2591
2711
iter != class2ctrls.end(); ++iter) {
2592
if (iter->first == V4L2_CTRL_CLASS_USER) {
2712
if (!use_ext_ctrls &&
2713
(iter->first == V4L2_CTRL_CLASS_USER ||
2714
iter->first == V4L2_CID_PRIVATE_BASE)) {
2593
2715
for (unsigned i = 0; i < iter->second.size(); i++) {
2594
2716
struct v4l2_control ctrl;
2815
if (options[OptQueryStandard]) {
2937
if (options[OptGetDvPreset]) {
2938
if (doioctl(fd, VIDIOC_G_DV_PRESET, &dv_preset, "VIDIOC_G_DV_PRESET") >= 0) {
2939
printf("Preset: %d\n", dv_preset.preset);
2943
if (options[OptQueryStandard]) {
2816
2944
if (doioctl(fd, VIDIOC_QUERYSTD, &std, "VIDIOC_QUERYSTD") == 0) {
2817
2945
printf("Video Standard = 0x%08llx\n", (unsigned long long)std);
2818
2946
print_v4lstd((unsigned long long)std);
2822
if (options[OptGetParm]) {
2950
if (options[OptQueryDvPreset]) {
2951
doioctl(fd, VIDIOC_QUERY_DV_PRESET, &dv_preset, "VIDIOC_QUERY_DV_PRESET");
2952
if (dv_preset.preset != V4L2_DV_INVALID) {
2953
printf("Preset: %d\n", dv_preset.preset);
2955
fprintf(stderr, "No active input detected\n");
2959
if (options[OptGetParm]) {
2823
2960
memset(&parm, 0, sizeof(parm));
2824
2961
parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2825
2962
if (doioctl(fd, VIDIOC_G_PARM, &parm, "VIDIOC_G_PARM") == 0) {
2866
3003
if (options[OptGetCtrl] && !get_ctrls.empty()) {
2867
3004
struct v4l2_ext_controls ctrls = { 0 };
2868
3005
class2ctrls_map class2ctrls;
3006
bool use_ext_ctrls = false;
2870
3008
for (ctrl_get_list::iterator iter = get_ctrls.begin();
2871
3009
iter != get_ctrls.end(); ++iter) {
2872
3010
struct v4l2_ext_control ctrl = { 0 };
2874
3012
ctrl.id = ctrl_str2q[*iter].id;
3013
if (ctrl_str2q[*iter].type == V4L2_CTRL_TYPE_INTEGER64)
3014
use_ext_ctrls = true;
2875
3015
if (ctrl_str2q[*iter].type == V4L2_CTRL_TYPE_STRING) {
3016
use_ext_ctrls = true;
2876
3017
ctrl.size = ctrl_str2q[*iter].maximum + 1;
2877
3018
ctrl.string = (char *)malloc(ctrl.size);
2878
3019
ctrl.string[0] = 0;
2882
3023
for (class2ctrls_map::iterator iter = class2ctrls.begin();
2883
3024
iter != class2ctrls.end(); ++iter) {
2884
if (iter->first == V4L2_CTRL_CLASS_USER) {
3025
if (!use_ext_ctrls &&
3026
(iter->first == V4L2_CTRL_CLASS_USER ||
3027
iter->first == V4L2_CID_PRIVATE_BASE)) {
2885
3028
for (unsigned i = 0; i < iter->second.size(); i++) {
2886
3029
struct v4l2_control ctrl;
3095
if (options[OptGetPriority]) {
3096
if (doioctl(fd, VIDIOC_G_PRIORITY, &prio, "VIDIOC_G_PRIORITY") == 0)
3097
printf("Priority: %d\n", prio);
2952
3100
if (options[OptLogStatus]) {
2953
3101
static char buf[40960];
2984
3132
while (ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0) {
2987
printf("\tInput : %d\n", vin.index);
2988
printf("\tName : %s\n", vin.name);
2989
printf("\tType : 0x%08X\n", vin.type);
2990
printf("\tAudioset: 0x%08X\n", vin.audioset);
2991
printf("\tTuner : 0x%08X\n", vin.tuner);
2992
printf("\tStandard: 0x%016llX (%s)\n", (unsigned long long)vin.std,
3135
printf("\tInput : %d\n", vin.index);
3136
printf("\tName : %s\n", vin.name);
3137
printf("\tType : 0x%08X\n", vin.type);
3138
printf("\tAudioset : 0x%08X\n", vin.audioset);
3139
printf("\tTuner : 0x%08X\n", vin.tuner);
3140
printf("\tStandard : 0x%016llX (%s)\n", (unsigned long long)vin.std,
2993
3141
std2s(vin.std).c_str());
2994
printf("\tStatus : 0x%08X (%s)\n", vin.status, status2s(vin.status).c_str());
3142
printf("\tStatus : 0x%08X (%s)\n", vin.status, status2s(vin.status).c_str());
3143
printf("\tCapabilities: 0x%08X (%s)\n", vin.capabilities, input_cap2s(vin.capabilities).c_str());
2999
3148
if (options[OptListOutputs]) {
3002
3151
while (ioctl(fd, VIDIOC_ENUMOUTPUT, &vout) >= 0) {
3003
3152
if (vout.index)
3005
printf("\tOutput : %d\n", vout.index);
3006
printf("\tName : %s\n", vout.name);
3007
printf("\tType : 0x%08X\n", vout.type);
3008
printf("\tAudioset: 0x%08X\n", vout.audioset);
3009
printf("\tStandard: 0x%016llX (%s)\n", (unsigned long long)vout.std,
3154
printf("\tOutput : %d\n", vout.index);
3155
printf("\tName : %s\n", vout.name);
3156
printf("\tType : 0x%08X\n", vout.type);
3157
printf("\tAudioset : 0x%08X\n", vout.audioset);
3158
printf("\tStandard : 0x%016llX (%s)\n", (unsigned long long)vout.std,
3010
3159
std2s(vout.std).c_str());
3160
printf("\tCapabilities: 0x%08X (%s)\n", vout.capabilities, output_cap2s(vout.capabilities).c_str());
3117
3267
list_controls(fd, 0);
3270
if (options[OptListDvPresets]) {
3271
dv_enum_preset.index = 0;
3272
printf("ioctl: VIDIOC_ENUM_DV_PRESETS\n");
3273
while (ioctl(fd, VIDIOC_ENUM_DV_PRESETS, &dv_enum_preset) >= 0) {
3274
if (dv_enum_preset.index)
3276
printf("\tIndex : %d\n", dv_enum_preset.index);
3277
printf("\tPreset : %d\n", dv_enum_preset.preset);
3278
printf("\tName : %s\n", dv_enum_preset.name);
3279
printf("\tWidth : %d\n", dv_enum_preset.width);
3280
printf("\tHeight : %d\n", dv_enum_preset.height);
3281
dv_enum_preset.index++;
3120
3284
if (options[OptStreamOn]) {
3122
3286
doioctl(fd, VIDIOC_STREAMON, &dummy, "VIDIOC_STREAMON");
3289
if (options[OptWaitForEvent]) {
3290
struct v4l2_event_subscription sub = { wait_for_event };
3291
struct v4l2_event ev;
3293
if (!doioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub, "VIDIOC_SUBSCRIBE_EVENT")) {
3294
if (!doioctl(fd, VIDIOC_DQEVENT, &ev, "VIDIOC_DQEVENT")) {
3300
if (options[OptPollForEvent]) {
3301
struct v4l2_event_subscription sub = { poll_for_event };
3302
struct v4l2_event ev;
3304
if (!doioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub, "VIDIOC_SUBSCRIBE_EVENT")) {
3307
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
3313
res = select(fd + 1, NULL, NULL, &fds, NULL);
3316
if (!doioctl(fd, VIDIOC_DQEVENT, &ev, "VIDIOC_DQEVENT")) {
3323
if (options[OptSleep]) {
3325
printf("Test VIDIOC_QUERYCAP:\n");
3326
if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) == 0)
3327
printf("\tDriver name : %s\n", vcap.driver);
3329
perror("VIDIOC_QUERYCAP");
3126
3333
exit(app_result);