~ubuntu-branches/debian/sid/v4l-utils/sid

« back to all changes in this revision

Viewing changes to utils/v4l2-ctl/v4l2-ctl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gregor Jasny
  • Date: 2010-05-07 20:48:34 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100507204834-ga01cxhz3fekk47r
Tags: 0.8.0-1
* New upstream version
* Switch to 3.0 (quilt) source format
* Re-enable pristine-tar
* Split utils package into command line and the Qt based qv4l2
  (Closes: #576422)
* Update upstream URL

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
        OptGetOverlayCropCap,
135
135
        OptGetOutputOverlayCropCap,
136
136
        OptOverlay,
 
137
        OptSleep,
137
138
        OptGetJpegComp,
138
139
        OptSetJpegComp,
139
140
        OptGetModulator,
142
143
        OptGetOutputParm,
143
144
        OptSetOutputParm,
144
145
        OptQueryStandard,
 
146
        OptPollForEvent,
 
147
        OptWaitForEvent,
 
148
        OptGetPriority,
 
149
        OptSetPriority,
 
150
        OptListDvPresets,
 
151
        OptSetDvPreset,
 
152
        OptGetDvPreset,
 
153
        OptQueryDvPreset,
145
154
        OptLast = 256
146
155
};
147
156
 
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},
283
301
        {0, 0, 0, 0}
284
302
};
285
303
 
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"
456
 
               "\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"
 
481
               "                     eos, vsync\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");
461
494
        exit(0);
462
495
}
564
597
 
565
598
        while (def->flag) {
566
599
                if (val & def->flag) {
567
 
                        if (s.length()) s += " ";
 
600
                        if (s.length()) s += ", ";
568
601
                        s += def->str;
569
602
                        val &= ~def->flag;
570
603
                }
571
604
                def++;
572
605
        }
573
606
        if (val) {
574
 
                if (s.length()) s += " ";
 
607
                if (s.length()) s += ", ";
575
608
                s += num2s(val);
576
609
        }
577
610
        return s;
600
633
}
601
634
 
602
635
 
 
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" },
 
640
        { 0, NULL }
 
641
};
 
642
 
 
643
static std::string input_cap2s(__u32 capabilities)
 
644
{
 
645
        return capabilities ? flags2s(capabilities, input_cap_def) : "not defined";
 
646
}
 
647
 
 
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" },
 
652
        { 0, NULL }
 
653
};
 
654
 
 
655
static std::string output_cap2s(__u32 capabilities)
 
656
{
 
657
        return capabilities ? flags2s(capabilities, output_cap_def) : "not defined";
 
658
}
 
659
 
603
660
static void print_sliced_vbi_cap(struct v4l2_sliced_vbi_cap &cap)
604
661
{
605
662
        printf("\tType           : %s\n", buftype2s(cap.type).c_str());
704
761
                                queryctrl->default_value, ctrl->value);
705
762
                break;
706
763
        case V4L2_CTRL_TYPE_BUTTON:
707
 
                printf("%31s (button)\n", s.c_str());
 
764
                printf("%31s (btn)  :", s.c_str());
708
765
                break;
709
766
        default: break;
710
767
        }
744
801
                return 1;
745
802
        }
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);
 
807
                return 1;
 
808
        }
747
809
        ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(qctrl.id);
748
810
        ctrls.count = 1;
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);
1123
1187
        }
1124
1188
}
1125
1189
 
1126
 
static char *pts_to_string(char *str, unsigned long pts)
1127
 
{
1128
 
        static char buf[256];
1129
 
        int hours, minutes, seconds, fracsec;
1130
 
        float fps;
1131
 
        int frame;
1132
 
        char *p = (str) ? str : buf;
1133
 
 
1134
 
        static const int MPEG_CLOCK_FREQ = 90000;
1135
 
        seconds = pts / MPEG_CLOCK_FREQ;
1136
 
        fracsec = pts % MPEG_CLOCK_FREQ;
1137
 
 
1138
 
        minutes = seconds / 60;
1139
 
        seconds = seconds % 60;
1140
 
 
1141
 
        hours = minutes / 60;
1142
 
        minutes = minutes % 60;
1143
 
 
1144
 
        fps = 30;
1145
 
        frame = (int)ceilf(((float)fracsec / (float)MPEG_CLOCK_FREQ) * fps);
1146
 
 
1147
 
        snprintf(p, sizeof(buf), "%d:%02d:%02d:%d", hours, minutes, seconds,
1148
 
                 frame);
1149
 
        return p;
1150
 
}
1151
 
 
1152
1190
static const char *audmode2s(int audmode)
1153
1191
{
1154
1192
        switch (audmode) {
1650
1688
        return V4L2_FIELD_ANY;
1651
1689
}
1652
1690
 
 
1691
static void print_event(const struct v4l2_event *ev)
 
1692
{
 
1693
        printf("%ld.%06ld: event %u, pending %u: ",
 
1694
                        ev->timestamp.tv_sec, ev->timestamp.tv_nsec / 1000,
 
1695
                        ev->sequence, ev->pending);
 
1696
        switch (ev->type) {
 
1697
        case V4L2_EVENT_VSYNC:
 
1698
                printf("vsync %s\n", field2s(ev->u.vsync.field).c_str());
 
1699
                break;
 
1700
        case V4L2_EVENT_EOS:
 
1701
                printf("eos\n");
 
1702
                break;
 
1703
        default:
 
1704
                if (ev->type >= V4L2_EVENT_PRIVATE_START)
 
1705
                        printf("unknown private event (%08x)\n", ev->type);
 
1706
                else
 
1707
                        printf("unknown event (%08x)\n", ev->type);
 
1708
                break;
 
1709
        }
 
1710
}
 
1711
 
 
1712
static __u32 parse_event(const char *e)
 
1713
{
 
1714
        __u32 event = 0;
 
1715
 
 
1716
        if (isdigit(e[0]))
 
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;
 
1722
 
 
1723
        if (event == 0) {
 
1724
                fprintf(stderr, "Unknown event\n");
 
1725
                usage();
 
1726
        }
 
1727
        return event;
 
1728
}
 
1729
 
1653
1730
static __u32 find_pixel_format(int fd, unsigned index)
1654
1731
{
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 */
 
1804
        unsigned secs = 0;
 
1805
        enum v4l2_priority prio = V4L2_PRIORITY_UNSET;
1723
1806
        char short_options[26 * 2 * 2 + 1];
1724
1807
        int idx = 0;
1725
1808
        int ret;
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));
1752
1837
 
1753
1838
        if (argc == 1) {
1754
1839
                usage();
2197
2282
                        }
2198
2283
                        break;
2199
2284
                }
 
2285
                case OptSleep:
 
2286
                        secs = strtoul(optarg, 0L, 0);
 
2287
                        break;
 
2288
                case OptSetPriority:
 
2289
                        prio = (enum v4l2_priority)strtoul(optarg, 0L, 0);
 
2290
                        break;
 
2291
                case OptWaitForEvent:
 
2292
                        wait_for_event = parse_event(optarg);
 
2293
                        if (wait_for_event == 0)
 
2294
                                return 1;
 
2295
                        break;
 
2296
                case OptPollForEvent:
 
2297
                        poll_for_event = parse_event(optarg);
 
2298
                        if (poll_for_event == 0)
 
2299
                                return 1;
 
2300
                        break;
2200
2301
                case OptListDevices:
2201
2302
                        list_devices();
2202
2303
                        break;
 
2304
                case OptSetDvPreset:
 
2305
                        dv_preset.preset = strtoul(optarg, 0L, 0);
 
2306
                        break;
2203
2307
                case ':':
2204
2308
                        fprintf(stderr, "Option `%s' requires a value\n",
2205
2309
                                argv[optind]);
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;
2273
2379
        }
2274
2380
 
2291
2397
                doioctl(fd, VIDIOC_STREAMOFF, &dummy, "VIDIOC_STREAMOFF");
2292
2398
        }
2293
2399
 
 
2400
        if (options[OptSetPriority]) {
 
2401
                if (doioctl(fd, VIDIOC_S_PRIORITY, &prio, "VIDIOC_S_PRIORITY") >= 0) {
 
2402
                        printf("Priority set: %d\n", prio);
 
2403
                }
 
2404
        }
 
2405
 
2294
2406
        if (options[OptSetFreq]) {
2295
2407
                double fac = 16;
2296
2408
 
2323
2435
                        printf("Standard set to %08llx\n", (unsigned long long)std);
2324
2436
        }
2325
2437
 
 
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);
 
2441
                }
 
2442
        }
2326
2443
 
2327
2444
        if (options[OptSetParm]) {
2328
2445
                memset(&parm, 0, sizeof(parm));
2429
2546
                                printfmt(in_vfmt);
2430
2547
                }
2431
2548
        }
2432
 
set_vid_fmt_error:
2433
2549
 
2434
2550
        if (options[OptSetVideoOutFormat] || options[OptTryVideoOutFormat]) {
2435
2551
                struct v4l2_format in_vfmt;
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;
2566
2683
 
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 };
2570
2687
 
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;
2575
2694
 
 
2695
                                use_ext_ctrls = true;
2576
2696
                                ctrl.size = maxlen + 1;
2577
2697
                                ctrl.string = (char *)malloc(ctrl.size);
2578
2698
                                if (len > maxlen) {
2589
2709
                }
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;
2595
2717
 
2812
2934
                }
2813
2935
        }
2814
2936
 
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);
 
2940
                }
 
2941
        }
 
2942
 
 
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);
2819
2947
                }
2820
2948
        }
2821
2949
 
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);
 
2954
                } else {
 
2955
                        fprintf(stderr, "No active input detected\n");
 
2956
                }
 
2957
        }
 
2958
 
 
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;
2869
3007
 
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 };
2873
3011
 
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;
2881
3022
                }
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;
2887
3030
 
2949
3092
                }
2950
3093
        }
2951
3094
 
 
3095
        if (options[OptGetPriority]) {
 
3096
                if (doioctl(fd, VIDIOC_G_PRIORITY, &prio, "VIDIOC_G_PRIORITY") == 0)
 
3097
                        printf("Priority: %d\n", prio);
 
3098
        }
 
3099
 
2952
3100
        if (options[OptLogStatus]) {
2953
3101
                static char buf[40960];
2954
3102
                int len;
2961
3109
                                char *q;
2962
3110
 
2963
3111
                                buf[len] = 0;
2964
 
                                while ((q = strstr(p, "START STATUS CARD #"))) {
 
3112
                                while ((q = strstr(p, "START STATUS"))) {
2965
3113
                                        p = q + 1;
2966
3114
                                }
2967
3115
                                if (p) {
2984
3132
                while (ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0) {
2985
3133
                        if (vin.index)
2986
3134
                                printf("\n");
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());
2995
 
                        vin.index++;
2996
 
                }
 
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());
 
3144
                        vin.index++;
 
3145
                }
2997
3146
        }
2998
3147
 
2999
3148
        if (options[OptListOutputs]) {
3002
3151
                while (ioctl(fd, VIDIOC_ENUMOUTPUT, &vout) >= 0) {
3003
3152
                        if (vout.index)
3004
3153
                                printf("\n");
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());
3011
3161
                        vout.index++;
3012
3162
                }
3013
3163
        }
3117
3267
                list_controls(fd, 0);
3118
3268
        }
3119
3269
 
 
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)
 
3275
                                printf("\n");
 
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++;
 
3282
                }
 
3283
        }
3120
3284
        if (options[OptStreamOn]) {
3121
3285
                int dummy = 0;
3122
3286
                doioctl(fd, VIDIOC_STREAMON, &dummy, "VIDIOC_STREAMON");
3123
3287
        }
3124
3288
 
 
3289
        if (options[OptWaitForEvent]) {
 
3290
                struct v4l2_event_subscription sub = { wait_for_event };
 
3291
                struct v4l2_event ev;
 
3292
 
 
3293
                if (!doioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub, "VIDIOC_SUBSCRIBE_EVENT")) {
 
3294
                        if (!doioctl(fd, VIDIOC_DQEVENT, &ev, "VIDIOC_DQEVENT")) {
 
3295
                                print_event(&ev);
 
3296
                        }
 
3297
                }
 
3298
        }
 
3299
 
 
3300
        if (options[OptPollForEvent]) {
 
3301
                struct v4l2_event_subscription sub = { poll_for_event };
 
3302
                struct v4l2_event ev;
 
3303
 
 
3304
                if (!doioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub, "VIDIOC_SUBSCRIBE_EVENT")) {
 
3305
                        fd_set fds;
 
3306
 
 
3307
                        fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
 
3308
                        while (1) {
 
3309
                                int res;
 
3310
 
 
3311
                                FD_ZERO(&fds);
 
3312
                                FD_SET(fd, &fds);
 
3313
                                res = select(fd + 1, NULL, NULL, &fds, NULL);
 
3314
                                if (res <= 0)
 
3315
                                        break;
 
3316
                                if (!doioctl(fd, VIDIOC_DQEVENT, &ev, "VIDIOC_DQEVENT")) {
 
3317
                                        print_event(&ev);
 
3318
                                }
 
3319
                        }
 
3320
                }
 
3321
        }
 
3322
 
 
3323
        if (options[OptSleep]) {
 
3324
                sleep(secs);
 
3325
                printf("Test VIDIOC_QUERYCAP:\n");
 
3326
                if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) == 0)
 
3327
                        printf("\tDriver name   : %s\n", vcap.driver);
 
3328
                else
 
3329
                        perror("VIDIOC_QUERYCAP");
 
3330
        }
 
3331
 
3125
3332
        close(fd);
3126
3333
        exit(app_result);
3127
3334
}