1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
--- pwcview.c.orig 2007-10-09 09:23:58.000000000 +0200
+++ pwcview.c 2010-09-09 16:42:31.000000000 +0200
@@ -37,11 +37,8 @@
#ifndef NOGUI
#include <SDL.h>
#endif
-#ifdef __FreeBSD__
-#include "videodev.h"
-#else
+#include <libv4l1.h>
#include <linux/videodev.h>
-#endif
#include "pwc-ioctl.h"
#include "pixels.h"
@@ -80,7 +77,7 @@
int fps;
struct video_window vw;
- if(ioctl(fd,VIDIOCGWIN,&vw) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGWIN,&vw) == -1) {
perror("Failed to get current framerate");
return -1;
}
@@ -90,9 +87,9 @@
if((dir == -1 && fps >= 9) ||(dir == 1 && fps <= 25)) {
fps += dir == -1 ? -5 : 5;
vw.flags = fps << PWC_FPS_SHIFT;
- if(ioctl(fd,VIDIOCSWIN,&vw) == -1)
+ if(v4l1_ioctl(fd,VIDIOCSWIN,&vw) == -1)
fprintf(stderr,"Failed to set framerate to %d fps: %s\n",fps,strerror(errno));
- if(ioctl(fd,VIDIOCGWIN,&vw) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGWIN,&vw) == -1) {
perror("Failed to get new framerate");
return -1;
}
@@ -106,16 +103,16 @@
{
int qual;
- if(ioctl(fd,VIDIOCPWCGCQUAL,&qual) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGCQUAL,&qual) == -1) {
perror("Failed to get current compression");
return -1;
}
if((dir == -1 && qual > 0) || (dir == 1 && qual < 3)) {
qual += dir == -1 ? -1 : 1;
- if(ioctl(fd,VIDIOCPWCSCQUAL,&qual) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSCQUAL,&qual) == -1)
perror("Failed to set compression");
- if(ioctl(fd,VIDIOCPWCGCQUAL,&qual) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGCQUAL,&qual) == -1) {
perror("Failed to get new compression");
return -1;
}
@@ -128,16 +125,16 @@
{
struct video_picture pict;
- if(ioctl(fd,VIDIOCGPICT,&pict) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGPICT,&pict) == -1) {
perror("Failed to get current brightness");
return -1;
}
if((dir == -1) || (dir == 1)) {
pict.brightness += dir == -1 ? -512 : 512;
- if(ioctl(fd,VIDIOCSPICT,&pict) == -1)
+ if(v4l1_ioctl(fd,VIDIOCSPICT,&pict) == -1)
perror("Failed to set brightness");
- if(ioctl(fd,VIDIOCGPICT,&pict) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGPICT,&pict) == -1) {
perror("Failed to get new brightness");
return -1;
}
@@ -150,16 +147,16 @@
{
struct video_picture pict;
- if(ioctl(fd,VIDIOCGPICT,&pict) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGPICT,&pict) == -1) {
perror("Failed to get current contrast");
return -1;
}
if((dir == -1) || (dir == 1)) {
pict.contrast += dir == -1 ? -1024 : 1024;
- if(ioctl(fd,VIDIOCSPICT,&pict) == -1)
+ if(v4l1_ioctl(fd,VIDIOCSPICT,&pict) == -1)
perror("Failed to set contrast");
- if(ioctl(fd,VIDIOCGPICT,&pict) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGPICT,&pict) == -1) {
perror("Failed to get new contrast");
return -1;
}
@@ -172,16 +169,16 @@
{
struct video_picture pict;
- if(ioctl(fd,VIDIOCGPICT,&pict) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGPICT,&pict) == -1) {
perror("Failed to get current saturation");
return -1;
}
if((dir == -1) || (dir == 1)) {
pict.colour += dir == -1 ? -327 : 327;
- if(ioctl(fd,VIDIOCSPICT,&pict) == -1)
+ if(v4l1_ioctl(fd,VIDIOCSPICT,&pict) == -1)
perror("Failed to set saturation");
- if(ioctl(fd,VIDIOCGPICT,&pict) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGPICT,&pict) == -1) {
perror("Failed to get new saturation");
return -1;
}
@@ -194,16 +191,16 @@
{
struct video_picture pict;
- if(ioctl(fd,VIDIOCGPICT,&pict) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGPICT,&pict) == -1) {
perror("Failed to get current gamma");
return -1;
}
if((dir == -1) ||(dir == 1)) {
pict.whiteness += dir == -1 ? -2048 : 2048;
- if(ioctl(fd,VIDIOCSPICT,&pict) == -1)
+ if(v4l1_ioctl(fd,VIDIOCSPICT,&pict) == -1)
perror("Failed to set gamma");
- if(ioctl(fd,VIDIOCGPICT,&pict) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGPICT,&pict) == -1) {
perror("Failed to get new gamma");
return -1;
}
@@ -236,7 +233,7 @@
snprintf(buf,80,"gain control: %d",agc >> 10);
}
- ioctl(fd,VIDIOCPWCSAGC,&val);
+ v4l1_ioctl(fd,VIDIOCPWCSAGC,&val);
return 0;
}
@@ -263,7 +260,7 @@
val = shutter;
snprintf(buf,80,"shutter speed: %d",shutter >> 8);
}
- ioctl(fd,VIDIOCPWCSSHUTTER,&val);
+ v4l1_ioctl(fd,VIDIOCPWCSSHUTTER,&val);
return 0;
}
@@ -274,7 +271,7 @@
char *names[] = { "indoor", "outdoor", "fluorescent","manual","auto" };
int *val = NULL;
- if(ioctl(fd,VIDIOCPWCGAWB,&wb) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGAWB,&wb) == -1) {
perror("Failed to get white balance");
return -1;
}
@@ -298,10 +295,10 @@
*val += 256;
}
- if(ioctl(fd,VIDIOCPWCSAWB,&wb) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSAWB,&wb) == -1)
perror("Failed to set white balance");
- if(ioctl(fd,VIDIOCPWCGAWB,&wb) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGAWB,&wb) == -1) {
perror("Failed to get white balance");
return -1;
}
@@ -317,16 +314,16 @@
{
struct pwc_wb_speed speed;
- if(ioctl(fd,VIDIOCPWCGAWBSPEED,&speed) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGAWBSPEED,&speed) == -1) {
perror("Failed to get current awb speed");
return -1;
}
if((dir == -1) || (dir == 1)) {
speed.control_speed += dir == -1 ? -2032 : 2032;
- if(ioctl(fd,VIDIOCPWCSAWBSPEED,&speed) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSAWBSPEED,&speed) == -1)
perror("Failed to set awb speed");
- if(ioctl(fd,VIDIOCPWCGAWBSPEED,&speed) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGAWBSPEED,&speed) == -1) {
perror("Failed to get new awb speed");
return -1;
}
@@ -339,16 +336,16 @@
{
struct pwc_wb_speed speed;
- if(ioctl(fd,VIDIOCPWCGAWBSPEED,&speed) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGAWBSPEED,&speed) == -1) {
perror("Failed to get current awb delay");
return -1;
}
if((dir == -1) || (dir == 1)) {
speed.control_delay += dir == -1 ? -1024 : 1024;
- if(ioctl(fd,VIDIOCPWCSAWBSPEED,&speed) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSAWBSPEED,&speed) == -1)
perror("Failed to set awb delay");
- if(ioctl(fd,VIDIOCPWCGAWBSPEED,&speed) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGAWBSPEED,&speed) == -1) {
perror("Failed to get new awb delay");
return -1;
}
@@ -377,13 +374,13 @@
else
val = contour;
- if(ioctl(fd,VIDIOCPWCSCONTOUR,&val) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSCONTOUR,&val) == -1)
perror("Failed to set contour");
if(contourmode == 1)
snprintf(buf,80,"contour: auto");
else {
- if(ioctl(fd,VIDIOCPWCGCONTOUR,&contour) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGCONTOUR,&contour) == -1) {
perror("Failed to get contour");
return -1;
}
@@ -396,17 +393,17 @@
{
int dynnoise;
- if(ioctl(fd,VIDIOCPWCGDYNNOISE,&dynnoise) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGDYNNOISE,&dynnoise) == -1) {
perror("Failed to get current dynamic noise reduction mode");
return -1;
}
if(dir == 2) {
if(++dynnoise == 4)
dynnoise = 0;
- if(ioctl(fd,VIDIOCPWCSDYNNOISE,&dynnoise) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSDYNNOISE,&dynnoise) == -1)
perror("Failed to set dynamic noise reduction mode");
- if(ioctl(fd,VIDIOCPWCGDYNNOISE,&dynnoise) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGDYNNOISE,&dynnoise) == -1) {
perror("Failed to get new dynamic noise reduction mode");
return -1;
}
@@ -419,16 +416,16 @@
{
int backlight;
- if(ioctl(fd,VIDIOCPWCGBACKLIGHT,&backlight) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGBACKLIGHT,&backlight) == -1) {
perror("Failed to get backlight mode");
return -1;
}
if(dir == 2) {
backlight = !backlight;
- if(ioctl(fd,VIDIOCPWCSBACKLIGHT,&backlight) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSBACKLIGHT,&backlight) == -1)
perror("Failed to set backlight mode");
- if(ioctl(fd,VIDIOCPWCGBACKLIGHT,&backlight) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGBACKLIGHT,&backlight) == -1) {
perror("Failed to get new backlight mode");
return -1;
}
@@ -441,16 +438,16 @@
{
int flicker;
- if(ioctl(fd,VIDIOCPWCGFLICKER,&flicker) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGFLICKER,&flicker) == -1) {
perror("Failed to get flicker mode");
return -1;
}
if(dir == 2) {
flicker = !flicker;
- if(ioctl(fd,VIDIOCPWCSFLICKER,&flicker) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSFLICKER,&flicker) == -1)
perror("Failed to set flicker mode");
- if(ioctl(fd,VIDIOCPWCGFLICKER,&flicker) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGFLICKER,&flicker) == -1) {
perror("Failed to get new flicker mode");
return -1;
}
@@ -463,16 +460,16 @@
{
int colour;
- if(ioctl(fd,VIDIOCPWCGCOLOUR,&colour) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGCOLOUR,&colour) == -1) {
perror("Failed to get colour mode");
return -1;
}
if(dir == 2) {
colour = !colour;
- if(ioctl(fd,VIDIOCPWCSCOLOUR,&colour) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSCOLOUR,&colour) == -1)
perror("Failed to set colour mode");
- if(ioctl(fd,VIDIOCPWCGCOLOUR,&colour) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCPWCGCOLOUR,&colour) == -1) {
perror("Failed to get new colour mode");
return -1;
}
@@ -487,7 +484,7 @@
snprintf(buf,80,"save user settings");
}
else if(dir == 2) {
- if(ioctl(fd,VIDIOCPWCSUSER) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSUSER) == -1)
snprintf(buf,80,"Error: %s",strerror(errno));
else
snprintf(buf,80,"User settings saved");
@@ -506,7 +503,7 @@
snprintf(buf,80,"restore user settings");
}
else if(dir == 2) {
- if(ioctl(fd,VIDIOCPWCRUSER) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCRUSER) == -1)
snprintf(buf,80,"Error: %s",strerror(errno));
else
snprintf(buf,80,"User settings restored");
@@ -523,7 +520,7 @@
snprintf(buf,80,"restore factory settings");
}
else if(dir == 2) {
- if(ioctl(fd,VIDIOCPWCFACTORY) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCFACTORY) == -1)
snprintf(buf,80,"Error: %s",strerror(errno));
else
snprintf(buf,80,"Factory settings restored");
@@ -537,12 +534,12 @@
struct pwc_leds led;
int ledon_handler(int fd, int dir, char *buf)
{
- ioctl(fd,VIDIOCPWCGLED,&led);
+ v4l1_ioctl(fd,VIDIOCPWCGLED,&led);
if((dir == -1) || (dir == 1)) {
led.led_on += (dir == -1) ? -100 : 100;
if(led.led_on < 0)
led.led_on = 0;
- if(ioctl(fd,VIDIOCPWCSLED,&led) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSLED,&led) == -1)
perror("Failed to set leds");
}
snprintf(buf,80,"led on: %d", led.led_on);
@@ -551,12 +548,12 @@
int ledoff_handler(int fd, int dir, char *buf)
{
- ioctl(fd,VIDIOCPWCGLED,&led);
+ v4l1_ioctl(fd,VIDIOCPWCGLED,&led);
if((dir == -1) || (dir == 1)) {
led.led_off += (dir == -1) ? -100 : 100;
if(led.led_off < 0)
led.led_off = 0;
- if(ioctl(fd,VIDIOCPWCSLED,&led) == -1)
+ if(v4l1_ioctl(fd,VIDIOCPWCSLED,&led) == -1)
perror("Failed to set leds");
}
snprintf(buf,80,"led off: %d", led.led_off);
@@ -837,6 +834,8 @@
jdata[1] = jimage[1];
jdata[2] = jimage[2];
+ cinfo->raw_data_in = TRUE;
+ cinfo->do_fancy_downsampling = FALSE;
jpeg_stdio_dest(cinfo, outfile);
jpeg_start_compress(cinfo, TRUE);
@@ -871,7 +870,7 @@
{
static int newbuf;
static int skip = 5;
- static uint32_t motionbuf[2][60][80];
+ static uint32_t motionbuf[2][150][200];
static int rectime;
uint32_t diff;
int line, col, motiondetected = 0;
@@ -888,7 +887,7 @@
}
}
- memset(motionbuf[newbuf],0,60*80*sizeof(uint32_t));
+ memset(motionbuf[newbuf],0,150*200*sizeof(uint32_t));
for(line = 0; line < height; ++line) {
int y = line / 8; tp = pt;
@@ -1041,7 +1040,10 @@
}
#endif
-#define PSZ_MAX 6
+#ifdef PSZ_MAX
+#undef PSZ_MAX
+#endif
+#define PSZ_MAX 10
struct {
char *name;
int width;
@@ -1052,7 +1054,11 @@
{ "qcif", 176, 144 },
{ "sif", 320, 240 },
{ "cif", 352, 288 },
- { "vga", 640, 480 }
+ { "vga", 640, 480 },
+ { "svga", 800, 600 },
+ { "xga", 1024, 768 },
+ { "sxga", 1280, 1024 },
+ { "uxga", 1600, 1200 }
};
int usage()
@@ -1184,7 +1190,7 @@
break;
if(i == PSZ_MAX) {
- fprintf(stderr,"Invalid size, valid sizes: sqcif, qsif, qcif, sif, cif, vga\n");
+ fprintf(stderr,"Invalid size, valid sizes: sqcif, qsif, qcif, sif, cif, vga, svga, xga, sxga, uxga\n");
return 1;
}
break;
@@ -1216,9 +1222,8 @@
vw.width = sizes[i].width;
vw.height= sizes[i].height;
vw.flags = fps << PWC_FPS_SHIFT;
- imgsize = (vw.width * vw.height * 3)/2;
- if((fd = open(device, O_RDONLY)) < 0) {
+ if((fd = v4l1_open(device, O_RDONLY)) < 0) {
if(errno == EBUSY)
fprintf(stderr,"Failed to access webcam: Device in use\n");
else {
@@ -1236,30 +1241,31 @@
}
fcntl(fd,F_SETFD,FD_CLOEXEC);
- if(ioctl(fd,VIDIOCGPICT,&vp) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCGPICT,&vp) == -1) {
perror("Failed to get current picture info");
exit(1);
}
vp.palette = VIDEO_PALETTE_YUV420P;
- if(ioctl(fd,VIDIOCSPICT,&vp) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCSPICT,&vp) == -1) {
perror("Failed to set palette to YUV420P");
exit(1);
}
- if(ioctl(fd,VIDIOCSWIN,&vw) == -1) {
+ if(v4l1_ioctl(fd,VIDIOCSWIN,&vw) == -1) {
fprintf(stderr,"Failed to set webcam to: %dx%d (%s) at %d fps (%s)\n",
vw.width,vw.height,sizes[i].name,fps,strerror(errno));
exit(1);
}
fprintf(stderr,"Webcam set to: %dx%d (%s) at %d fps\n",vw.width,vw.height,sizes[i].name,fps);
+ imgsize = (vw.width * vw.height * 3)/2;
if(headless && snapcnt == 0 && motionrecord == 0) { /* Done */
- close(fd);
+ v4l1_close(fd);
exit(0);
}
if(snapbtn) {
snapbtn = 0;
- if(ioctl(fd,VIDIOCPWCPROBE,&probe) != -1 &&
+ if(v4l1_ioctl(fd,VIDIOCPWCPROBE,&probe) != -1 &&
probe.type >= 720 && probe.type <= 740)
snapbtn = 1;
}
@@ -1327,7 +1333,7 @@
timerid = SDL_AddTimer(interval,cbtimer,NULL);
}
#endif
- while (frozen || ((size = read(fd,y,imgsize)) > 0) || (size == -1 && errno == EINTR)) {
+ while (frozen || ((size = v4l1_read(fd,y,imgsize)) > 0) || (size == -1 && errno == EINTR)) {
int snap = y[0] & 0x01;
if(!frozen && size != imgsize) {
if(size != -1) {
@@ -1498,7 +1504,7 @@
if(size != 0)
perror("Error reading from webcam");
- close(fd);
+ v4l1_close(fd);
jpeg_destroy_compress(&cinfo);
return 0;
}
|