Lines 23-29
Link Here
|
23 |
#include <fcntl.h> |
23 |
#include <fcntl.h> |
24 |
#include <unistd.h> |
24 |
#include <unistd.h> |
25 |
#define _LINUX_TIME_H 1 /* to get things compile on kernel 2.6.x */ |
25 |
#define _LINUX_TIME_H 1 /* to get things compile on kernel 2.6.x */ |
26 |
#include <linux/videodev.h> |
26 |
#include <linux/videodev2.h> |
27 |
|
27 |
|
28 |
#include "pwc-ioctl.h" |
28 |
#include "pwc-ioctl.h" |
29 |
|
29 |
|
Lines 61-71
Link Here
|
61 |
printf("of your webcam and the driver.\n"); |
61 |
printf("of your webcam and the driver.\n"); |
62 |
} |
62 |
} |
63 |
|
63 |
|
|
|
64 |
void dump_current_settings_ctrl(int fd, const char *prefix, int id) |
65 |
{ |
66 |
struct v4l2_control vctrl; |
67 |
struct v4l2_queryctrl qctrl; |
68 |
struct v4l2_querymenu qmenu; |
69 |
const char *flags[10]; |
70 |
int flags_cnt = 0; |
71 |
memset(&vctrl, 0, sizeof(vctrl)); |
72 |
memset(&qctrl, 0, sizeof(qctrl)); |
73 |
vctrl.id = id; |
74 |
qctrl.id = id; |
75 |
if (ioctl(fd, VIDIOC_G_CTRL, &vctrl) == -1) { |
76 |
printf("%s: VIDIOC_G_CTRL failed: %s\n", prefix, strerror(errno)); |
77 |
return; |
78 |
} |
79 |
if (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == -1) { |
80 |
printf("%s: VIDIOC_QUERYCTRL failed: %s\n", prefix, strerror(errno)); |
81 |
return; |
82 |
} |
83 |
if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) |
84 |
flags[flags_cnt++] = "disabled"; |
85 |
if (qctrl.flags & V4L2_CTRL_FLAG_GRABBED) |
86 |
flags[flags_cnt++] = "grabbed"; |
87 |
if (qctrl.flags & V4L2_CTRL_FLAG_READ_ONLY) |
88 |
flags[flags_cnt++] = "read-only"; |
89 |
if (qctrl.flags & V4L2_CTRL_FLAG_UPDATE) |
90 |
flags[flags_cnt++] = "update"; |
91 |
if (qctrl.flags & V4L2_CTRL_FLAG_INACTIVE) |
92 |
flags[flags_cnt++] = "inactive"; |
93 |
if (qctrl.flags & V4L2_CTRL_FLAG_SLIDER) |
94 |
flags[flags_cnt++] = "slider"; |
95 |
flags[flags_cnt] = NULL; |
96 |
switch (qctrl.type) { |
97 |
case V4L2_CTRL_TYPE_INTEGER: |
98 |
printf("%s: %s\n", prefix, qctrl.name); |
99 |
printf(" Value: %d\n", vctrl.value); |
100 |
printf(" Minimum: %d\n", qctrl.minimum); |
101 |
printf(" Maximum: %d\n", qctrl.maximum); |
102 |
printf(" Step: %d\n", qctrl.step); |
103 |
printf(" Default: %d\n", qctrl.default_value); |
104 |
printf(" Flags: "); |
105 |
for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) |
106 |
printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); |
107 |
printf("\n"); |
108 |
break; |
109 |
case V4L2_CTRL_TYPE_BOOLEAN: |
110 |
printf("%s: %s\n", prefix, qctrl.name); |
111 |
printf(" Value: %s\n", vctrl.value ? "enabled" : "disabled"); |
112 |
printf(" Default: %s\n", qctrl.default_value ? "enabled" : "disabled"); |
113 |
printf(" Flags: "); |
114 |
for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) |
115 |
printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); |
116 |
printf("\n"); |
117 |
break; |
118 |
case V4L2_CTRL_TYPE_MENU: |
119 |
printf("%s: %s\n", prefix, qctrl.name); |
120 |
memset(&qmenu, 0, sizeof(qmenu)); |
121 |
qmenu.id = id; |
122 |
qmenu.index = vctrl.value; |
123 |
if (ioctl(fd, VIDIOC_QUERYMENU, &qmenu) == -1) |
124 |
printf(" Value: ??? (%d)\n", vctrl.value); |
125 |
else |
126 |
printf(" Value: %s (%d)\n", qmenu.name, vctrl.value); |
127 |
memset(&qmenu, 0, sizeof(qmenu)); |
128 |
qmenu.id = id; |
129 |
qmenu.index = qctrl.default_value; |
130 |
if (ioctl(fd, VIDIOC_QUERYMENU, &qmenu) == -1) |
131 |
printf(" Default: ??? (%d)\n", qctrl.default_value); |
132 |
else |
133 |
printf(" Default: %s (%d)\n", qmenu.name, qctrl.default_value); |
134 |
printf(" Flags: "); |
135 |
for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) |
136 |
printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); |
137 |
printf("\n"); |
138 |
break; |
139 |
case V4L2_CTRL_TYPE_BUTTON: |
140 |
printf("%s: %s\n", prefix, qctrl.name); |
141 |
printf(" Unsupport type: button\n"); |
142 |
printf(" Flags: "); |
143 |
for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) |
144 |
printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); |
145 |
printf("\n"); |
146 |
break; |
147 |
case V4L2_CTRL_TYPE_INTEGER64: |
148 |
printf("%s: %s\n", prefix, qctrl.name); |
149 |
printf(" Unsupport type: integer64\n"); |
150 |
printf(" Flags: "); |
151 |
for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) |
152 |
printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); |
153 |
printf("\n"); |
154 |
break; |
155 |
case V4L2_CTRL_TYPE_CTRL_CLASS: |
156 |
printf("%s: %s\n", prefix, qctrl.name); |
157 |
printf(" Unsupport type: class\n"); |
158 |
printf(" Flags: "); |
159 |
for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) |
160 |
printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); |
161 |
printf("\n"); |
162 |
break; |
163 |
case V4L2_CTRL_TYPE_STRING: |
164 |
printf("%s: %s\n", prefix, qctrl.name); |
165 |
printf(" Unsupport type: string\n"); |
166 |
printf(" Flags: "); |
167 |
for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) |
168 |
printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); |
169 |
printf("\n"); |
170 |
break; |
171 |
} |
172 |
} |
173 |
|
64 |
void dump_current_settings(int fd) |
174 |
void dump_current_settings(int fd) |
65 |
{ |
175 |
{ |
66 |
struct video_capability vcap; |
176 |
struct v4l2_capability vcap; |
67 |
struct video_window vwin; |
177 |
struct v4l2_format pixfmt; |
68 |
struct video_picture vpic; |
|
|
69 |
struct pwc_probe pwcp; |
178 |
struct pwc_probe pwcp; |
70 |
int dummy; |
179 |
int dummy; |
71 |
struct pwc_whitebalance pwcwb; |
180 |
struct pwc_whitebalance pwcwb; |
Lines 75-88
Link Here
|
75 |
struct pwc_serial ps; |
184 |
struct pwc_serial ps; |
76 |
|
185 |
|
77 |
/* get name */ |
186 |
/* get name */ |
78 |
if (ioctl(fd, VIDIOCGCAP, &vcap) == -1) |
187 |
if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) == -1) |
79 |
error_exit("VIDIOCGCAP"); |
188 |
error_exit("VIDIOC_QUERYCAP"); |
80 |
printf("Current device: %s\n", vcap.name); |
189 |
printf("Current device: %s (%s @ %s)\n", (const char *)vcap.card, (const char *)vcap.driver, (const char *)vcap.bus_info); |
81 |
|
190 |
|
82 |
/* verify that it IS a Philips Webcam */ |
191 |
/* verify that it IS a Philips Webcam */ |
83 |
if (ioctl(fd, VIDIOCPWCPROBE, &pwcp) == -1) |
192 |
if (ioctl(fd, VIDIOCPWCPROBE, &pwcp) == -1) |
84 |
error_exit("VIDIOCPWCPROBE"); |
193 |
error_exit("VIDIOCPWCPROBE"); |
85 |
if (strcmp(vcap.name, pwcp.name) != 0) |
194 |
if (strcmp((const char *)vcap.card, pwcp.name) != 0) |
86 |
printf("Warning: this might not be a Philips compatible webcam!\n"); |
195 |
printf("Warning: this might not be a Philips compatible webcam!\n"); |
87 |
printf("VIDIOCPWCPROBE returns: %s - %d\n", pwcp.name, pwcp.type); |
196 |
printf("VIDIOCPWCPROBE returns: %s - %d\n", pwcp.name, pwcp.type); |
88 |
|
197 |
|
Lines 91-163
Link Here
|
91 |
printf("Serial number: %s\n", ps.serial); |
200 |
printf("Serial number: %s\n", ps.serial); |
92 |
|
201 |
|
93 |
/* get resolution/framerate */ |
202 |
/* get resolution/framerate */ |
94 |
if (ioctl(fd, VIDIOCGWIN, &vwin) == -1) |
203 |
memset(&pixfmt, 0, sizeof(pixfmt)); |
95 |
error_exit("VIDIOCGWIN"); |
204 |
pixfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
96 |
printf("Resolution (x, y): %d, %d\n", vwin.width, vwin.height); |
205 |
if (ioctl(fd, VIDIOC_G_FMT, &pixfmt) == -1) |
97 |
printf("Offset: %d, %d\n", vwin.x, vwin.y); |
206 |
error_exit("VIDIOC_G_FMT"); |
98 |
if (vwin.flags & PWC_FPS_FRMASK) |
207 |
printf("Resolution (x, y): %d, %d\n", pixfmt.fmt.pix.width, pixfmt.fmt.pix.height); |
99 |
printf("Framerate: %d\n", (vwin.flags & PWC_FPS_FRMASK) >> PWC_FPS_SHIFT); |
208 |
if (pixfmt.fmt.pix.priv & PWC_FPS_FRMASK) |
|
|
209 |
printf("Framerate: %d\n", (pixfmt.fmt.pix.priv & PWC_FPS_FRMASK) >> PWC_FPS_SHIFT); |
100 |
|
210 |
|
101 |
/* color (etc.) settings */ |
211 |
/* color (etc.) settings */ |
102 |
if (ioctl(fd, VIDIOCGPICT, &vpic) == -1) |
212 |
dump_current_settings_ctrl(fd, "Brightness", V4L2_CID_BRIGHTNESS); |
103 |
error_exit("VIDIOCGPICT"); |
213 |
dump_current_settings_ctrl(fd, "Hue", V4L2_CID_HUE); |
104 |
printf("Brightness: %d\n", vpic.brightness); |
214 |
dump_current_settings_ctrl(fd, "Colour", V4L2_CID_SATURATION); |
105 |
printf("Hue: %d\n", vpic.hue); |
215 |
dump_current_settings_ctrl(fd, "Contrast", V4L2_CID_CONTRAST); |
106 |
printf("Colour: %d\n", vpic.colour); |
216 |
dump_current_settings_ctrl(fd, "Whiteness", V4L2_CID_WHITENESS); |
107 |
printf("Contrast: %d\n", vpic.contrast); |
|
|
108 |
printf("Whiteness: %d\n", vpic.whiteness); |
109 |
printf("Palette: "); |
217 |
printf("Palette: "); |
110 |
switch(vpic.palette) { |
218 |
switch(pixfmt.fmt.pix.pixelformat) { |
111 |
case VIDEO_PALETTE_GREY: |
219 |
case V4L2_PIX_FMT_GREY: |
112 |
printf("Linear intensity grey scale (255 is brightest).\n"); |
220 |
printf("Linear intensity grey scale (255 is brightest).\n"); |
113 |
break; |
221 |
break; |
114 |
case VIDEO_PALETTE_HI240: |
222 |
case V4L2_PIX_FMT_HI240: |
115 |
printf("The BT848 8bit colour cube.\n"); |
223 |
printf("The BT848 8bit colour cube.\n"); |
116 |
break; |
224 |
break; |
117 |
case VIDEO_PALETTE_RGB565: |
225 |
case V4L2_PIX_FMT_RGB565: |
118 |
printf("RGB565 packed into 16 bit words.\n"); |
226 |
printf("RGB565 packed into 16 bit words.\n"); |
119 |
break; |
227 |
break; |
120 |
case VIDEO_PALETTE_RGB555: |
228 |
case V4L2_PIX_FMT_RGB555: |
121 |
printf("RGV555 packed into 16 bit words, top bit undefined.\n"); |
229 |
printf("RGV555 packed into 16 bit words, top bit undefined.\n"); |
122 |
break; |
230 |
break; |
123 |
case VIDEO_PALETTE_RGB24: |
231 |
case V4L2_PIX_FMT_BGR24: |
124 |
printf("RGB888 packed into 24bit words.\n"); |
232 |
printf("RGB888 packed into 24bit words.\n"); |
125 |
break; |
233 |
break; |
126 |
case VIDEO_PALETTE_RGB32: |
234 |
case V4L2_PIX_FMT_BGR32: |
127 |
printf("RGB888 packed into the low 3 bytes of 32bit words. The top 8bits are undefined.\n"); |
235 |
printf("RGB888 packed into the low 3 bytes of 32bit words. The top 8bits are undefined.\n"); |
128 |
break; |
236 |
break; |
129 |
case VIDEO_PALETTE_YUV422: |
237 |
case V4L2_PIX_FMT_YUYV: |
130 |
printf("Video style YUV422 - 8bits packed 4bits Y 2bits U 2bits V\n"); |
238 |
printf("Video style YUV422 - 8bits packed 4bits Y 2bits U 2bits V\n"); |
131 |
break; |
239 |
break; |
132 |
case VIDEO_PALETTE_YUYV: |
240 |
case V4L2_PIX_FMT_UYVY: |
133 |
printf("Describe me\n"); |
|
|
134 |
break; |
135 |
case VIDEO_PALETTE_UYVY: |
136 |
printf("Describe me\n"); |
241 |
printf("Describe me\n"); |
137 |
break; |
242 |
break; |
138 |
case VIDEO_PALETTE_YUV420: |
243 |
case V4L2_PIX_FMT_Y41P: |
139 |
printf("YUV420 capture\n"); |
|
|
140 |
break; |
141 |
case VIDEO_PALETTE_YUV411: |
142 |
printf("YUV411 capture\n"); |
244 |
printf("YUV411 capture\n"); |
143 |
break; |
245 |
break; |
144 |
case VIDEO_PALETTE_RAW: |
246 |
case V4L2_PIX_FMT_YUV422P: |
145 |
printf("RAW capture (BT848)\n"); |
|
|
146 |
break; |
147 |
case VIDEO_PALETTE_YUV422P: |
148 |
printf("YUV 4:2:2 Planar\n"); |
247 |
printf("YUV 4:2:2 Planar\n"); |
149 |
break; |
248 |
break; |
150 |
case VIDEO_PALETTE_YUV411P: |
249 |
case V4L2_PIX_FMT_YUV411P: |
151 |
printf("YUV 4:1:1 Planar\n"); |
250 |
printf("YUV 4:1:1 Planar\n"); |
152 |
break; |
251 |
break; |
153 |
case VIDEO_PALETTE_YUV420P: |
252 |
case V4L2_PIX_FMT_YVU420: |
154 |
printf("YUV 4:2:0 Planar\n"); |
253 |
printf("YUV 4:2:0 Planar\n"); |
155 |
break; |
254 |
break; |
156 |
case VIDEO_PALETTE_YUV410P: |
255 |
case V4L2_PIX_FMT_YVU410: |
157 |
printf("YUV 4:1:0 Planar\n"); |
256 |
printf("YUV 4:1:0 Planar\n"); |
158 |
break; |
257 |
break; |
159 |
default: |
258 |
default: |
160 |
printf("Unknown! (%d)\n", vpic.palette); |
259 |
printf("Unknown! (%d - %c%c%c%c)\n", pixfmt.fmt.pix.pixelformat, pixfmt.fmt.pix.pixelformat & 0xff, (pixfmt.fmt.pix.pixelformat >> 8) & 0xff, (pixfmt.fmt.pix.pixelformat >> 16) & 0xff, (pixfmt.fmt.pix.pixelformat >> 24) & 0xff); |
161 |
} |
260 |
} |
162 |
|
261 |
|
163 |
if (ioctl(fd, VIDIOCPWCGCQUAL, &dummy) == -1) |
262 |
if (ioctl(fd, VIDIOCPWCGCQUAL, &dummy) == -1) |
Lines 285-310
Link Here
|
285 |
|
384 |
|
286 |
void set_dimensions_and_framerate(int fd, int w, int h, int framerate) |
385 |
void set_dimensions_and_framerate(int fd, int w, int h, int framerate) |
287 |
{ |
386 |
{ |
288 |
struct video_window vwin; |
387 |
struct v4l2_format pixfmt; |
289 |
|
388 |
|
290 |
/* get resolution/framerate */ |
389 |
/* get resolution/framerate */ |
291 |
if (ioctl(fd, VIDIOCGWIN, &vwin) == -1) |
390 |
if (ioctl(fd, VIDIOC_G_FMT, &pixfmt) == -1) |
292 |
error_exit("VIDIOCGWIN"); |
391 |
error_exit("VIDIOC_G_FMT"); |
293 |
|
392 |
|
294 |
if (w > 0 && h > 0) |
393 |
if (w > 0 && h > 0) |
295 |
{ |
394 |
{ |
296 |
vwin.width = w; |
395 |
pixfmt.fmt.pix.width = w; |
297 |
vwin.height = h; |
396 |
pixfmt.fmt.pix.height = h; |
298 |
} |
397 |
} |
299 |
|
398 |
|
300 |
if (vwin.flags & PWC_FPS_FRMASK) |
399 |
if (pixfmt.fmt.pix.priv & PWC_FPS_FRMASK) |
301 |
{ |
400 |
{ |
302 |
/* set new framerate */ |
401 |
/* set new framerate */ |
303 |
vwin.flags &= ~PWC_FPS_FRMASK; |
402 |
pixfmt.fmt.pix.priv &= ~PWC_FPS_FRMASK; |
304 |
vwin.flags |= (framerate << PWC_FPS_SHIFT); |
403 |
pixfmt.fmt.pix.priv |= (framerate << PWC_FPS_SHIFT); |
305 |
|
404 |
|
306 |
if (ioctl(fd, VIDIOCSWIN, &vwin) == -1) |
405 |
if (ioctl(fd, VIDIOC_S_FMT, &pixfmt) == -1) |
307 |
error_exit("VIDIOCSWIN"); |
406 |
error_exit("VIDIOC_S_FMT"); |
308 |
} |
407 |
} |
309 |
else |
408 |
else |
310 |
{ |
409 |
{ |