comparison example/dummy.c @ 7:2fce9e157b8d

Added some work around to work with kernel 2.6.27-rc3, added debug param.
author AngelCarpintero
date Sun, 24 Aug 2008 02:20:51 +0000
parents 5f21a4dddc0c
children 5971a90f2459
comparison
equal deleted inserted replaced
6:d3fdefea8bce 7:2fce9e157b8d
27 #define MAXIOCTL 1024 27 #define MAXIOCTL 1024
28 #define MAXWIDTH 640 28 #define MAXWIDTH 640
29 #define MAXHEIGHT 480 29 #define MAXHEIGHT 480
30 int width; 30 int width;
31 int height; 31 int height;
32 int fmt=0; 32 int fmt = 0;
33 char ioctlbuf[MAXIOCTL]; 33 char ioctlbuf[MAXIOCTL];
34 int v4ldev; 34 int v4ldev;
35 char *image_out; 35 char *image_out;
36 36 int noexit = 1;
37 37
38 int get_frame(void) 38 int get_frame(void)
39 { 39 {
40 int i; 40 int i;
41 char colour = 0; 41 char colour = 0;
42 42
43 memset(image_out, 0x128, width*height*3); 43 memset(image_out, 0x128, width * height * 3);
44 44
45 for (i=10; i<width-10; i++) { 45 for (i = 10; i < width - 10; i++) {
46 image_out[10*width*3+i*3]=colour++; 46 image_out[10 *width *3 + i *3] = colour++;
47 image_out[10*width*3+i*3+1]=0; 47 image_out[10 *width *3 + i *3 + 1] = 0;
48 image_out[10*width*3+i*3+2]=-colour; 48 image_out[10 *width *3 + i *3 + 2] =-colour;
49 } 49 }
50 for (i=10; i<width-10; i++) { 50
51 image_out[(height-10)*width*3+i*3]=colour; 51 for (i = 10; i < width - 10; i++) {
52 image_out[(height-10)*width*3+i*3+1]=0; 52 image_out[(height - 10) * width *3 + i * 3] = colour;
53 image_out[(height-10)*width*3+i*3+2]=-colour++; 53 image_out[(height - 10) * width *3 + i * 3 + 1] = 0;
54 } 54 image_out[(height - 10) * width *3 + i * 3 + 2] =-colour++;
55 /* 55 }
56 */ 56
57 usleep(500); /* BIG XXX */ 57 usleep(500); /* BIG XXX */
58 return 0; 58 return 0;
59 } 59 }
60 60
61 char *v4l_create (int dev, int memsize) 61 char *v4l_create (int dev, int memsize)
62 { 62 {
63 char *map; 63 char *map;
64 64
65 map=mmap(0, memsize, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0); 65 map = mmap(0, memsize, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0);
66
66 if ((unsigned char *)-1 == (unsigned char *)map) 67 if ((unsigned char *)-1 == (unsigned char *)map)
67 return NULL; 68 return NULL;
69
68 return map; 70 return map;
69 } 71 }
70 72
71 int v4l_ioctl(unsigned long int cmd, void *arg) 73 int v4l_ioctl(unsigned long int cmd, void *arg)
72 { 74 {
73 int i; 75 int i;
74 switch (cmd) { 76 switch (cmd) {
75 case VIDIOCGCAP: 77 case VIDIOCGCAP:
76 { 78 {
77 struct video_capability *vidcap=arg; 79 struct video_capability *vidcap = arg;
78 80
79 sprintf(vidcap->name, "Jeroen's dummy v4l driver"); 81 sprintf(vidcap->name, "Jeroen's dummy v4l driver");
80 vidcap->type= VID_TYPE_CAPTURE; 82 vidcap->type = VID_TYPE_CAPTURE;
81 vidcap->channels=1; 83 vidcap->channels = 1;
82 vidcap->audios=0; 84 vidcap->audios = 0;
83 vidcap->maxwidth=MAXWIDTH; 85 vidcap->maxwidth = MAXWIDTH;
84 vidcap->maxheight=MAXHEIGHT; 86 vidcap->maxheight = MAXHEIGHT;
85 vidcap->minwidth=20; 87 vidcap->minwidth = 20;
86 vidcap->minheight=20; 88 vidcap->minheight = 20;
87 return 0; 89 return 0;
88 } 90 }
89 case VIDIOCGCHAN: 91 case VIDIOCGCHAN:
90 { 92 {
91 struct video_channel *vidchan= (struct video_channel *)arg; 93 struct video_channel *vidchan = (struct video_channel *)arg;
92 94
93 printf("VIDIOCGCHAN called\n"); 95 printf("VIDIOCGCHAN called\n");
94 if (vidchan->channel!=0) 96 if (vidchan->channel != 0)
95 ;//return 1; 97 ;//return 1;
96 vidchan->channel=0; 98 vidchan->channel = 0;
97 vidchan->flags=0; 99 vidchan->flags = 0;
98 vidchan->tuners=0; 100 vidchan->tuners = 0;
99 vidchan->norm=0; 101 vidchan->norm = 0;
100 vidchan->type=VIDEO_TYPE_CAMERA; 102 vidchan->type = VIDEO_TYPE_CAMERA;
101 strcpy(vidchan->name, "Loopback"); 103 strcpy(vidchan->name, "Loopback");
102 104
103 return 0; 105 return 0;
104 } 106 }
105 case VIDIOCSCHAN: 107 case VIDIOCSCHAN:
106 { 108 {
107 int *v=arg; 109 int *v = arg;
108 110
109 if (v[0]!=0) 111 if (v[0] != 0)
110 return 1;
111 return 0;
112 }
113 case VIDIOCGTUNER:
114 {
115 struct video_tuner *v = arg;
116
117 if(v->tuner) {
118 printf("VIDIOCGTUNER: Invalid Tuner, was %d\n", v->tuner);
119 //return -EINVAL;
120 }
121 v->tuner=0;
122 strcpy(v->name, "Format");
123 v->rangelow=0;
124 v->rangehigh=0;
125 v->flags=0;
126 v->mode=VIDEO_MODE_AUTO;
127 return 1; 112 return 1;
128 } 113 return 0;
129 case VIDIOCGPICT: 114 }
130 { 115 case VIDIOCGTUNER:
131 struct video_picture *vidpic=arg; 116 {
132 117 struct video_tuner *v = arg;
133 vidpic->colour=0x8000; 118
134 vidpic->hue=0x8000; 119 if (v->tuner) {
135 vidpic->brightness=0x8000; 120 printf("VIDIOCGTUNER: Invalid Tuner, was %d\n", v->tuner);
136 vidpic->contrast=0x8000; 121 //return -EINVAL;
137 vidpic->whiteness=0x8000; 122 }
138 vidpic->depth=0x8000; 123 v->tuner = 0;
139 vidpic->palette=fmt; 124 strcpy(v->name, "Format");
140 return 0; 125 v->rangelow = 0;
141 } 126 v->rangehigh = 0;
142 case VIDIOCSPICT: 127 v->flags = 0;
143 { 128 v->mode = VIDEO_MODE_AUTO;
144 struct video_picture *vidpic=arg; 129 return 1;
130 }
131 case VIDIOCGPICT:
132 {
133 struct video_picture *vidpic = arg;
134
135 vidpic->colour = 0x8000;
136 vidpic->hue = 0x8000;
137 vidpic->brightness = 0x8000;
138 vidpic->contrast = 0x8000;
139 vidpic->whiteness = 0x8000;
140 vidpic->depth = 0x8000;
141 vidpic->palette = fmt;
142 return 0;
143 }
144 case VIDIOCSPICT:
145 {
146 struct video_picture *vidpic = arg;
147
148 if (vidpic->palette != fmt)
149 return 1;
150 return 0;
151 }
152 case VIDIOCGWIN:
153 {
154 struct video_window *vidwin = arg;
155
156 vidwin->x = 0;
157 vidwin->y = 0;
158 vidwin->width = width;
159 vidwin->height = height;
160 vidwin->chromakey = 0;
161 vidwin->flags = 0;
162 vidwin->clipcount = 0;
163 return 0;
164 }
165 case VIDIOCSWIN:
166 {
167 struct video_window *vidwin = arg;
145 168
146 if (vidpic->palette!=fmt) 169 if (vidwin->width > MAXWIDTH ||
147 return 1; 170 vidwin->height > MAXHEIGHT )
148 return 0; 171 return 1;
149 } 172 if (vidwin->flags)
150 case VIDIOCGWIN: 173 return 1;
151 { 174 width = vidwin->width;
152 struct video_window *vidwin=arg; 175 height = vidwin->height;
153 176 printf("new size: %dx%d\n", width, height);
154 vidwin->x=0; 177 return 0;
155 vidwin->y=0; 178 }
156 vidwin->width=width; 179 case VIDIOCGMBUF:
157 vidwin->height=height; 180 {
158 vidwin->chromakey=0; 181 struct video_mbuf *vidmbuf = arg;
159 vidwin->flags=0; 182
160 vidwin->clipcount=0; 183 vidmbuf->size = width * height * 3;
161 return 0; 184 vidmbuf->frames = 1;
162 } 185 for (i = 0; i < vidmbuf->frames; i++)
163 case VIDIOCSWIN: 186 vidmbuf->offsets[i] = i * vidmbuf->size;
164 { 187 return 0;
165 struct video_window *vidwin=arg; 188 }
166 189 case VIDIOCMCAPTURE:
167 if (vidwin->width > MAXWIDTH || 190 {
168 vidwin->height > MAXHEIGHT ) 191 struct video_mmap *vidmmap = arg;
169 return 1; 192
170 if (vidwin->flags) 193 //return 0;
171 return 1; 194 if (vidmmap->height>MAXHEIGHT ||
172 width=vidwin->width; 195 vidmmap->width>MAXWIDTH ||
173 height=vidwin->height; 196 vidmmap->format != fmt )
197 return 1;
198 if (vidmmap->height != height ||
199 vidmmap->width != width) {
200 height = vidmmap->height;
201 width = vidmmap->width;
174 printf("new size: %dx%d\n", width, height); 202 printf("new size: %dx%d\n", width, height);
175 return 0; 203 }
176 } 204 // check if 'vidmmap->frame' is valid
177 case VIDIOCGMBUF: 205 // initiate capture for 'vidmmap->frame' frames
178 { 206 return 0;
179 struct video_mbuf *vidmbuf=arg; 207 }
180 208 case VIDIOCSYNC:
181 vidmbuf->size=width*height*3; 209
182 vidmbuf->frames=1; 210 //struct video_mmap *vidmmap=arg;
183 for (i=0; i<vidmbuf->frames; i++) 211
184 vidmbuf->offsets[i]=i*vidmbuf->size; 212 // check if frames are ready.
185 return 0; 213 // wait until ready.
186 } 214 get_frame();
187 case VIDIOCMCAPTURE: 215 return 0;
188 { 216
189 struct video_mmap *vidmmap=arg; 217 default:
190 218 printf("unknown ioctl: %ld\n", cmd & 0xff);
191 //return 0; 219 return 1;
192 if (vidmmap->height>MAXHEIGHT || 220
193 vidmmap->width>MAXWIDTH ||
194 vidmmap->format!=fmt )
195 return 1;
196 if (vidmmap->height!=height ||
197 vidmmap->width!=width) {
198 height=vidmmap->height;
199 width=vidmmap->width;
200 printf("new size: %dx%d\n", width, height);
201 }
202 // check if 'vidmmap->frame' is valid
203 // initiate capture for 'vidmmap->frame' frames
204 return 0;
205 }
206 case VIDIOCSYNC:
207 {
208 //struct video_mmap *vidmmap=arg;
209
210 // check if frames are ready.
211 // wait until ready.
212 get_frame();
213 return 0;
214 }
215 default:
216 {
217 printf("unknown ioctl: %ld\n", cmd & 0xff);
218 return 1;
219 }
220 } 221 }
221 return 0; 222 return 0;
222 } 223 }
223 224
224 #define VIDIOCSINVALID _IO('v',BASE_VIDIOCPRIVATE+1) 225 #define VIDIOCSINVALID _IO('v',BASE_VIDIOCPRIVATE+1)
226
227 void sighandler_exit(int signo)
228 {
229 noexit = 0;
230 }
225 231
226 void sighandler(int signo) 232 void sighandler(int signo)
227 { 233 {
228 int size, ret; 234 int size, ret;
229 unsigned long int cmd; 235 unsigned long int cmd;
230 struct pollfd ufds; 236 struct pollfd ufds;
231 237
232 if (signo!=SIGIO) 238 if (signo != SIGIO)
233 return; 239 return;
234 ufds.fd=v4ldev; 240
235 ufds.events=POLLIN; 241 ufds.fd = v4ldev;
236 ufds.revents=0; 242 ufds.events = POLLIN;
243 ufds.revents = 0;
237 poll(&ufds, 1, 1000); 244 poll(&ufds, 1, 1000);
245
238 if (!ufds.revents & POLLIN) { 246 if (!ufds.revents & POLLIN) {
239 printf("Received signal but got negative on poll?!?!?!?\n"); 247 printf("Received signal but got negative on poll?!?!?!?\n");
240 return; 248 return;
241 } 249 }
242 size=read(v4ldev, ioctlbuf, MAXIOCTL); 250
251 size = read(v4ldev, ioctlbuf, MAXIOCTL);
252
243 if (size >= sizeof(unsigned long int)) { 253 if (size >= sizeof(unsigned long int)) {
244 memcpy(&cmd, ioctlbuf, sizeof(unsigned long int)); 254 memcpy(&cmd, ioctlbuf, sizeof(unsigned long int));
245 if (cmd==0) { 255 if (cmd == 0) {
246 printf("Client closed device\n"); 256 printf("Client closed device\n");
247 return; 257 return;
248 } 258 }
249 ret=v4l_ioctl(cmd, ioctlbuf+sizeof(unsigned long int)); 259 ret = v4l_ioctl(cmd, ioctlbuf+sizeof(unsigned long int));
250 if (ret) { 260 if (ret) {
251 memset(ioctlbuf+sizeof(unsigned long int), MAXIOCTL-sizeof(unsigned long int), 0xff); 261 memset(ioctlbuf + sizeof(unsigned long int), MAXIOCTL - sizeof(unsigned long int), 0xff);
252 printf("ioctl %lx unsuccesfull, lets issue VIDIOCSINVALID (%x)\n", cmd, VIDIOCSINVALID); 262 printf("ioctl %lx unsuccesfull, lets issue VIDIOCSINVALID (%x)\n", cmd, VIDIOCSINVALID);
253 ioctl(v4ldev, VIDIOCSINVALID); 263 ioctl(v4ldev, VIDIOCSINVALID);
254 } else 264 } else {
255 ioctl(v4ldev, cmd, ioctlbuf+sizeof(unsigned long int)); 265 ioctl(v4ldev, cmd, ioctlbuf + sizeof(unsigned long int));
266 }
256 } 267 }
257 return; 268 return;
258 } 269 }
270
259 271
260 int open_vidpipe(void) 272 int open_vidpipe(void)
261 { 273 {
262 int pipe_fd = -1; 274 int pipe_fd = -1;
263 FILE *vloopbacks; 275 FILE *vloopbacks;
271 char *major; 283 char *major;
272 char *minor; 284 char *minor;
273 struct utsname uts; 285 struct utsname uts;
274 286
275 if (uname(&uts) < 0) { 287 if (uname(&uts) < 0) {
276 printf("Unable to execute uname\nError[%s]\n",strerror(errno)); 288 printf("Unable to execute uname\nError[%s]\n", strerror(errno));
277 return -1; 289 return -1;
278 } 290 }
279 291
280 major = strtok(uts.release, "."); 292 major = strtok(uts.release, ".");
281 minor = strtok(NULL, "."); 293 minor = strtok(NULL, ".");
283 printf("Unable to decipher OS version\n"); 295 printf("Unable to decipher OS version\n");
284 return -1; 296 return -1;
285 } 297 }
286 298
287 if (strcmp(minor, "5") < 0) { 299 if (strcmp(minor, "5") < 0) {
288 300 vloopbacks = fopen("/proc/video/vloopback/vloopbacks", "r");
289 vloopbacks=fopen("/proc/video/vloopback/vloopbacks", "r");
290 if (!vloopbacks) { 301 if (!vloopbacks) {
291 printf ("Failed to open '/proc/video/vloopback/vloopbacks"); 302 printf ("Failed to open '/proc/video/vloopback/vloopbacks");
292 return -1; 303 return -1;
293 } 304 }
305
294 /* Read vloopback version */ 306 /* Read vloopback version */
295 fgets(buffer, 255, vloopbacks); 307 fgets(buffer, 255, vloopbacks);
296 printf("%s", buffer); 308 printf("%s", buffer);
309
297 /* Read explaination line */ 310 /* Read explaination line */
298 fgets(buffer, 255, vloopbacks); 311 fgets(buffer, 255, vloopbacks);
312
299 while (fgets(buffer, 255, vloopbacks)) { 313 while (fgets(buffer, 255, vloopbacks)) {
300 if (strlen(buffer)>1) { 314
301 buffer[strlen(buffer)-1]=0; 315 if (strlen(buffer)>1) {
302 loop=strtok(buffer, "\t"); 316 buffer[strlen(buffer)-1] = 0;
303 input=strtok(NULL, "\t"); 317 loop = strtok(buffer, "\t");
304 istatus=strtok(NULL, "\t"); 318 input = strtok(NULL, "\t");
305 output=strtok(NULL, "\t"); 319 istatus = strtok(NULL, "\t");
306 ostatus=strtok(NULL, "\t"); 320 output = strtok(NULL, "\t");
307 if (istatus[0]=='-') { 321 ostatus = strtok(NULL, "\t");
322
323 if (istatus[0] == '-') {
308 sprintf(pipepath, "/dev/%s", input); 324 sprintf(pipepath, "/dev/%s", input);
309 pipe_fd=open(pipepath, O_RDWR); 325 pipe_fd = open(pipepath, O_RDWR);
310 if (pipe_fd>=0) { 326
327 if (pipe_fd >= 0) {
311 printf("Input: /dev/%s\n", input); 328 printf("Input: /dev/%s\n", input);
312 printf("Output: /dev/%s\n", output); 329 printf("Output: /dev/%s\n", output);
313 return pipe_fd; 330 return pipe_fd;
314 } 331 }
315 } 332 }
316 } 333 }
317 } 334 }
318 335 } else {
319 }else{
320 DIR *dir; 336 DIR *dir;
321 struct dirent *dirp; 337 struct dirent *dirp;
322 const char prefix[]="/sys/class/video4linux/"; 338 const char prefix[] = "/sys/class/video4linux/";
323 char *ptr, *io; 339 char *ptr, *io;
324 int fd; 340 int fd;
325 int low=9999; 341 int low = 9999;
326 int tfd; 342 int tfd;
327 int tnum; 343 int tnum;
328 344
329 if ((dir=opendir(prefix))== NULL) { 345 if ((dir = opendir(prefix)) == NULL) {
330 printf( "Failed to open '%s'", prefix); 346 printf( "Failed to open '%s'", prefix);
331 return -1; 347 return -1;
332 } 348 }
333 349
334 while ((dirp=readdir(dir)) != NULL) { 350 while ((dirp = readdir(dir)) != NULL) {
335 if (!strncmp(dirp->d_name, "video", 5)) { 351 if (!strncmp(dirp->d_name, "video", 5)) {
336 strcpy(buffer, prefix); 352 strcpy(buffer, prefix);
337 strcat(buffer, dirp->d_name); 353 strcat(buffer, dirp->d_name);
338 strcat(buffer, "/name"); 354 strcat(buffer, "/name");
339 if ((fd=open(buffer, O_RDONLY)) >= 0) { 355
340 if ((read(fd, buffer, sizeof(buffer)-1))<0) { 356 if ((fd = open(buffer, O_RDONLY)) >= 0) {
341 close(fd); 357 if ((read(fd, buffer, sizeof(buffer)-1)) < 0) {
342 continue; 358 close(fd);
343 } 359 continue;
344 ptr = strtok(buffer, " "); 360 }
345 if (strcmp(ptr,"Video")) { 361
346 close(fd); 362 ptr = strtok(buffer, " ");
347 continue; 363
348 } 364 if (strcmp(ptr, "Video")) {
349 major = strtok(NULL, " "); 365 close(fd);
350 minor = strtok(NULL, " "); 366 continue;
351 io = strtok(NULL, " \n"); 367 }
352 if (strcmp(major, "loopback") || strcmp(io, "input")) { 368
353 close(fd); 369 major = strtok(NULL, " ");
354 continue; 370 minor = strtok(NULL, " ");
355 } 371 io = strtok(NULL, " \n");
356 if ((ptr=strtok(buffer, " "))==NULL) { 372
357 close(fd); 373 if (strcmp(major, "loopback") || strcmp(io, "input")) {
358 continue; 374 close(fd);
359 } 375 continue;
360 tnum = atoi(minor); 376 }
361 if (tnum < low) { 377
362 strcpy(buffer, "/dev/"); 378 if ((ptr=strtok(buffer, " ")) == NULL) {
363 strcat(buffer, dirp->d_name); 379 close(fd);
364 if ((tfd=open(buffer, O_RDWR))>=0) { 380 continue;
365 strcpy(pipepath, buffer); 381 }
366 if (pipe_fd>=0) { 382
367 close(pipe_fd); 383 tnum = atoi(minor);
368 } 384 if (tnum < low) {
369 pipe_fd = tfd; 385 strcpy(buffer, "/dev/");
370 low = tnum; 386 strcat(buffer, dirp->d_name);
371 } 387 if ((tfd = open(buffer, O_RDWR)) >= 0) {
372 } 388 strcpy(pipepath, buffer);
373 close(fd); 389 if (pipe_fd >= 0)
374 } 390 close(pipe_fd);
391
392 pipe_fd = tfd;
393 low = tnum;
375 } 394 }
395 }
396 close(fd);
376 } 397 }
398 }
399 }
377 400
378 401
379 closedir(dir); 402 closedir(dir);
380 if (pipe_fd >= 0) 403 if (pipe_fd >= 0)
381 printf("Opened input of %s", pipepath); 404 printf("Opened input of %s", pipepath);
382 } 405 }
383 406
384 return pipe_fd; 407 return pipe_fd;
385 } 408 }
386 409
387 int main (int argc, char **argv) 410 int main (int argc, char **argv)
388 { 411 {
389 char palette[10]={'\0'}; 412 char palette[10] = {'\0'};
390 413
391 if (argc != 3) { 414 if (argc != 3) {
392 printf("dummy.c\n"); 415 printf("dummy.c\n");
393 printf("A example for using a video4linux loopback in zero-copy mode\n"); 416 printf("A example for using a video4linux loopback in zero-copy mode\n");
394 printf("Written by Jeroen Vreeken, 2000\n"); 417 printf("Written by Jeroen Vreeken, 2000\n");
395 printf("Updated to vloopback API v0.97\n\n"); 418 printf("Updated to vloopback API v1.1\n\n");
396 printf("Usage:\n\n"); 419 printf("Usage:\n\n");
397 printf("dummy widthxheight rgb24|yuv420p\n\n"); 420 printf("dummy widthxheight rgb24|yuv420p\n\n");
398 printf("example: dummy 352x288 yuv420p\n\n"); 421 printf("example: dummy 352x288 yuv420p\n\n");
399 exit(1); 422 exit(1);
400 } 423 }
401 424
402 sscanf(argv[1], "%dx%d", &width, &height); 425 sscanf(argv[1], "%dx%d", &width, &height);
403 sscanf(argv[2], "%s", palette); 426 sscanf(argv[2], "%s", palette);
404 427
405 if (!strcmp(palette,"rgb24")) fmt = VIDEO_PALETTE_RGB24; 428 if (!strcmp(palette, "rgb24"))
406 else if (!strcmp(palette,"yuv420p")) fmt = VIDEO_PALETTE_YUV420P; 429 fmt = VIDEO_PALETTE_RGB24;
430 else if (!strcmp(palette, "yuv420p"))
431 fmt = VIDEO_PALETTE_YUV420P;
407 else fmt = VIDEO_PALETTE_RGB24; 432 else fmt = VIDEO_PALETTE_RGB24;
408 433
409 /* Default startup values, nothing special 434 /* Default startup values, nothing special
410 width=352; 435 width=352;
411 height=288; 436 height=288;
412 */ 437 */
413 438
414 v4ldev=open_vidpipe(); 439 v4ldev = open_vidpipe();
440
415 if (v4ldev < 0) { 441 if (v4ldev < 0) {
416 printf ("Failed to open video loopback device\nError[%s]\n",strerror(errno)); 442 printf ("Failed to open video loopback device\nError[%s]\n", strerror(errno));
417 exit(1); 443 exit(1);
418 } 444 }
419 image_out=v4l_create(v4ldev, MAXWIDTH*MAXHEIGHT*3); 445
446 image_out = v4l_create(v4ldev, MAXWIDTH * MAXHEIGHT * 3);
447
420 if (!image_out) { 448 if (!image_out) {
421 exit(1); 449 exit(1);
422 printf ("Failed to set device to zero-copy mode\nError[%s]\n",strerror(errno)); 450 printf ("Failed to set device to zero-copy mode\nError[%s]\n", strerror(errno));
423 } 451 }
424 452
425 signal (SIGIO, sighandler); 453 signal(SIGIO, sighandler);
454 signal(SIGTERM, sighandler_exit);
455 signal(SIGINT, sighandler_exit);
426 456
427 printf("\nListening.\n"); 457 printf("\nListening.\n");
428 while (1) { 458
459 while (noexit)
429 sleep(1000); 460 sleep(1000);
430 } 461
431 462 close(v4ldev);
432 close (v4ldev); 463 munmap(image_out, MAXWIDTH * MAXHEIGHT * 3);
433 free(image_out); 464
465 printf("\nBye Bye ...\n");
466
434 exit(0); 467 exit(0);
435 } 468 }