• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "v4l2-ctl.h"
2 
3 static struct v4l2_format vfmt;	/* set_format/get_format */
4 
sdr_usage()5 void sdr_usage()
6 {
7 	printf("\nSDR Formats options:\n"
8 	       "  --list-formats-sdr display supported SDR capture formats [VIDIOC_ENUM_FMT]\n"
9 	       "  --get-fmt-sdr      query the SDR capture format [VIDIOC_G_FMT]\n"
10 	       "  --set-fmt-sdr <f>  set the SDR capture format [VIDIOC_S_FMT]\n"
11 	       "                     parameter is either the format index as reported by\n"
12 	       "                     --list-formats-sdr-cap, or the fourcc value as a string\n"
13 	       "  --try-fmt-sdr <f>  try the SDR capture format [VIDIOC_TRY_FMT]\n"
14 	       "                     parameter is either the format index as reported by\n"
15 	       "                     --list-formats-sdr-cap, or the fourcc value as a string\n"
16 	       "  --list-formats-sdr-out\n"
17 	       "                     display supported SDR output formats [VIDIOC_ENUM_FMT]\n"
18 	       "  --get-fmt-sdr-out  query the SDR output format [VIDIOC_G_FMT]\n"
19 	       "  --set-fmt-sdr-out <f>\n"
20 	       "                     set the SDR output format [VIDIOC_S_FMT]\n"
21 	       "                     parameter is either the format index as reported by\n"
22 	       "                     --list-formats-sdr-out, or the fourcc value as a string\n"
23 	       "  --try-fmt-sdr-out <f>\n"
24 	       "                     try the SDR output format [VIDIOC_TRY_FMT]\n"
25 	       "                     parameter is either the format index as reported by\n"
26 	       "                     --list-formats-sdr-out, or the fourcc value as a string\n"
27 	       );
28 }
29 
sdr_cmd(int ch,char * optarg)30 void sdr_cmd(int ch, char *optarg)
31 {
32 	switch (ch) {
33 	case OptSetSdrFormat:
34 	case OptTrySdrFormat:
35 	case OptSetSdrOutFormat:
36 	case OptTrySdrOutFormat:
37 		if (strlen(optarg) == 0) {
38 			sdr_usage();
39 			std::exit(EXIT_FAILURE);
40 		} else if (strlen(optarg) == 4) {
41 			vfmt.fmt.sdr.pixelformat = v4l2_fourcc(optarg[0],
42 					optarg[1], optarg[2], optarg[3]);
43 		} else {
44 			vfmt.fmt.sdr.pixelformat = strtol(optarg, nullptr, 0);
45 		}
46 		break;
47 	}
48 }
49 
sdr_set(cv4l_fd & _fd)50 void sdr_set(cv4l_fd &_fd)
51 {
52 	int fd = _fd.g_fd();
53 	int ret;
54 
55 	if (options[OptSetSdrFormat] || options[OptTrySdrFormat]) {
56 		struct v4l2_format in_vfmt;
57 
58 		in_vfmt.type = V4L2_BUF_TYPE_SDR_CAPTURE;
59 		in_vfmt.fmt.sdr.pixelformat = vfmt.fmt.sdr.pixelformat;
60 
61 		if (in_vfmt.fmt.sdr.pixelformat < 256) {
62 			struct v4l2_fmtdesc fmt = {};
63 
64 			fmt.index = in_vfmt.fmt.sdr.pixelformat;
65 			fmt.type = V4L2_BUF_TYPE_SDR_CAPTURE;
66 
67 			if (doioctl(fd, VIDIOC_ENUM_FMT, &fmt))
68 				fmt.pixelformat = 0;
69 
70 			in_vfmt.fmt.sdr.pixelformat = fmt.pixelformat;
71 		}
72 
73 		if (options[OptSetSdrFormat])
74 			ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
75 		else
76 			ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
77 		if (ret == 0 && (verbose || options[OptTrySdrFormat]))
78 			printfmt(fd, in_vfmt);
79 	}
80 	if (options[OptSetSdrOutFormat] || options[OptTrySdrOutFormat]) {
81 		struct v4l2_format in_vfmt;
82 
83 		in_vfmt.type = V4L2_BUF_TYPE_SDR_OUTPUT;
84 		in_vfmt.fmt.sdr.pixelformat = vfmt.fmt.sdr.pixelformat;
85 
86 		if (in_vfmt.fmt.sdr.pixelformat < 256) {
87 			struct v4l2_fmtdesc fmt = {};
88 
89 			fmt.index = in_vfmt.fmt.sdr.pixelformat;
90 			fmt.type = V4L2_BUF_TYPE_SDR_OUTPUT;
91 
92 			if (doioctl(fd, VIDIOC_ENUM_FMT, &fmt))
93 				fmt.pixelformat = 0;
94 
95 			in_vfmt.fmt.sdr.pixelformat = fmt.pixelformat;
96 		}
97 
98 		if (options[OptSetSdrOutFormat])
99 			ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
100 		else
101 			ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
102 		if (ret == 0 && (verbose || options[OptTrySdrOutFormat]))
103 			printfmt(fd, in_vfmt);
104 	}
105 }
106 
sdr_get(cv4l_fd & fd)107 void sdr_get(cv4l_fd &fd)
108 {
109 	if (options[OptGetSdrFormat]) {
110 		vfmt.type = V4L2_BUF_TYPE_SDR_CAPTURE;
111 		if (doioctl(fd.g_fd(), VIDIOC_G_FMT, &vfmt) == 0)
112 			printfmt(fd.g_fd(), vfmt);
113 	}
114 	if (options[OptGetSdrOutFormat]) {
115 		vfmt.type = V4L2_BUF_TYPE_SDR_OUTPUT;
116 		if (doioctl(fd.g_fd(), VIDIOC_G_FMT, &vfmt) == 0)
117 			printfmt(fd.g_fd(), vfmt);
118 	}
119 }
120 
sdr_list(cv4l_fd & fd)121 void sdr_list(cv4l_fd &fd)
122 {
123 	if (options[OptListSdrFormats]) {
124 		printf("ioctl: VIDIOC_ENUM_FMT\n");
125 		print_video_formats(fd, V4L2_BUF_TYPE_SDR_CAPTURE, 0);
126 	}
127 	if (options[OptListSdrOutFormats]) {
128 		printf("ioctl: VIDIOC_ENUM_FMT\n");
129 		print_video_formats(fd, V4L2_BUF_TYPE_SDR_OUTPUT, 0);
130 	}
131 }
132