2
* Copyright 1994-2012 Olivier Girondel
4
* This file is part of lebiniou.
6
* lebiniou is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 2 of the License, or
9
* (at your option) any later version.
11
* lebiniou is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
22
static struct v4l2_queryctrl queryctrl;
23
static struct v4l2_querymenu querymenu;
27
enumerate_menu(const webcam_t *cam)
29
memset(&querymenu, 0, sizeof(querymenu));
30
querymenu.id = queryctrl.id;
32
for (querymenu.index = queryctrl.minimum;
33
querymenu.index <= (unsigned)queryctrl.maximum;
35
if (0 == ioctl(cam->fd, VIDIOC_QUERYMENU, &querymenu))
36
printf ("[i] - %s\n", querymenu.name);
38
xperror("VIDIOC_QUERYMENU");
43
enumerate_base_cids(const webcam_t *cam)
45
memset(&queryctrl, 0, sizeof(queryctrl));
47
for (queryctrl.id = V4L2_CID_BASE;
48
queryctrl.id < V4L2_CID_LASTP1;
50
if (0 == ioctl(cam->fd, VIDIOC_QUERYCTRL, &queryctrl)) {
51
if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
54
printf("[i] * %s\n", queryctrl.name);
56
if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
62
xperror("VIDIOC_QUERYCTRL");
69
enumerate_private_cids(webcam_t *cam)
71
memset(&queryctrl, 0, sizeof (queryctrl));
73
for (queryctrl.id = V4L2_CID_PRIVATE_BASE;
76
if (0 == ioctl(cam->fd, VIDIOC_QUERYCTRL, &queryctrl)) {
77
if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
80
printf ("[i] * %s\n", queryctrl.name);
82
if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
88
xperror("VIDIOC_QUERYCTRL");
95
enumerate_cids(webcam_t *cam)
97
printf("[i] Webcam %d: base controls\n", cam->cam_no);
98
enumerate_base_cids(cam);
99
printf("[i] Webcam %d: private controls\n", cam->cam_no);
100
enumerate_private_cids(cam);
105
set_ctrl(int fd, const int ctrl, const int value)
107
struct v4l2_queryctrl queryctrl;
108
struct v4l2_control control;
110
memset(&queryctrl, 0, sizeof(queryctrl));
113
if (-1 == xioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
114
if (errno != EINVAL) {
115
xerror("VIDIOC_QUERYCTRL\n");
117
printf("V4L2_CID_BRIGHTNESS is not supported\n");
119
} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
120
printf("%s is not supported\n",
121
(ctrl == V4L2_CID_VFLIP) ? "V4L2_CID_VFLIP" : "V4L2_CID_HFLIP");
123
memset(&control, 0, sizeof(control));
125
control.value = queryctrl.default_value;
127
if (-1 == xioctl(fd, VIDIOC_S_CTRL, &control)) {
128
xerror("VIDIOC_S_CTRL\n");
132
printf("[i] %s: default= %d",
133
((ctrl == V4L2_CID_VFLIP) ? "V4L2_CID_VFLIP" : "V4L2_CID_HFLIP"),
136
memset(&control, 0, sizeof (control));
139
if (0 == xioctl(fd, VIDIOC_G_CTRL, &control)) {
140
control.value = value;
142
if (-1 == xioctl(fd, VIDIOC_S_CTRL, &control)
143
&& errno != ERANGE) {
144
xerror("VIDIOC_S_CTRL\n");
146
printf(" set: %d\n", value);
147
/* Ignore if V4L2_CID_CONTRAST is unsupported */
148
} else if (errno != EINVAL) {
149
xerror("VIDIOC_G_CTRL\n");
155
cam_hflip(int fd, const int value)
157
set_ctrl(fd, V4L2_CID_HFLIP, value);
162
cam_vflip(int fd, const int value)
164
set_ctrl(fd, V4L2_CID_VFLIP, value);
169
list_inputs(const webcam_t *cam)
171
struct v4l2_input inputs;
176
while (ioctl(fd, VIDIOC_ENUMINPUT, &inputs) == 0) {
177
printf("[i] Webcam %d: input #%d\n", cam->cam_no, index);
178
printf("[i] * Name: %s\n", inputs.name);
180
printf("[i] * Type: ");
181
if (inputs.type == V4L2_INPUT_TYPE_CAMERA)
183
else if (inputs.type == V4L2_INPUT_TYPE_TUNER)
188
printf("[i] * Video standard: %d\n", (int)inputs.std);
190
inputs.index = index;