Mercurial > vloopback
annotate example/resize.c @ 13:5971a90f2459
Fix some gcc warnings
author | AngelCarpintero |
---|---|
date | Tue, 20 Jan 2009 12:23:52 +0000 |
parents | 2fce9e157b8d |
children |
rev | line source |
---|---|
0 | 1 /* resize.c |
2 * | |
3 * Example program for videoloopback device. | |
4 * Copyright 2000 by Jeroen Vreeken (pe1rxq@amsat.org) | |
5 * Copyright 2005 by Angel Carpintero (ack@telefonica.net) | |
6 * This software is distributed under the GNU public license version 2 | |
7 * See also the file 'COPYING'. | |
8 * | |
9 */ | |
10 | |
11 #include <unistd.h> | |
12 #include <stdlib.h> | |
13 #include <stdio.h> | |
14 #include <fcntl.h> | |
15 #include <string.h> | |
16 #include <errno.h> | |
17 #include <sys/ioctl.h> | |
18 #include <sys/mman.h> | |
19 #include <signal.h> | |
20 #include <sys/wait.h> | |
21 #include <linux/videodev.h> | |
22 | |
23 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
24 int fmt = 0; |
0 | 25 int noexit = 1; |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
26 int read_img = 0; |
0 | 27 |
28 char *start_capture (int dev, int width, int height) | |
29 { | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
30 struct video_capability vid_caps; |
0 | 31 struct video_window vid_win; |
32 struct video_mbuf vid_buf; | |
33 char *map; | |
34 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
35 if (ioctl(dev, VIDIOCGCAP, &vid_caps) == -1) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
36 printf ("ioctl (VIDIOCGCAP)\nError[%s]\n", strerror(errno)); |
0 | 37 return (NULL); |
38 } | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
39 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
40 if (vid_caps.type & VID_TYPE_MONOCHROME) |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
41 fmt = VIDEO_PALETTE_GREY; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
42 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
43 if (ioctl(dev, VIDIOCGMBUF, &vid_buf) == -1) { |
0 | 44 fprintf(stderr, "no mmap falling back on read\n"); |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
45 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
46 if (ioctl(dev, VIDIOCGWIN, &vid_win)== -1) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
47 printf ("ioctl VIDIOCGWIN\nError[%s]\n", strerror(errno)); |
0 | 48 return (NULL); |
49 } | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
50 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
51 vid_win.width = width; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
52 vid_win.height = height; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
53 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
54 if (ioctl(dev, VIDIOCSWIN, &vid_win)== -1) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
55 printf ("ioctl VIDIOCSWIN\nError[%s]\n", strerror(errno)); |
0 | 56 return (NULL); |
57 } | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
58 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
59 read_img = 1; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
60 map = malloc(width * height * 3); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
61 |
0 | 62 return (map); |
63 } | |
64 /* If we are going to capture greyscale we need room to blow the image up */ | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
65 if (fmt == VIDEO_PALETTE_GREY) |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
66 map=mmap(0, vid_buf.size * 3, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0); |
0 | 67 else |
68 map=mmap(0, vid_buf.size, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0); | |
69 | |
70 if ((unsigned char *)-1 == (unsigned char *)map) | |
71 return (NULL); | |
72 return map; | |
73 } | |
74 | |
75 int start_pipe (int dev, int width, int height) | |
76 { | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
77 struct video_capability vid_caps; |
0 | 78 struct video_window vid_win; |
79 struct video_picture vid_pic; | |
80 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
81 if (ioctl(dev, VIDIOCGCAP, &vid_caps) == -1) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
82 printf ("ioctl (VIDIOCGCAP)\nError[%s]\n", strerror(errno)); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
83 return (1); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
84 } |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
85 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
86 if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
87 printf ("ioctl VIDIOCGPICT\nError[%s]\n", strerror(errno)); |
0 | 88 return (1); |
89 } | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
90 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
91 vid_pic.palette = fmt; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
92 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
93 if (ioctl(dev, VIDIOCSPICT, &vid_pic) == -1) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
94 printf ("ioctl VIDIOCSPICT\nError[%s]\n", strerror(errno)); |
0 | 95 return (1); |
96 } | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
97 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
98 if (ioctl(dev, VIDIOCGWIN, &vid_win) == -1) { |
0 | 99 printf ("ioctl VIDIOCGWIN"); |
100 return (1); | |
101 } | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
102 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
103 vid_win.width = width; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
104 vid_win.height = height; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
105 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
106 if (ioctl(dev, VIDIOCSWIN, &vid_win)== -1) { |
0 | 107 printf ("ioctl VIDIOCSWIN"); |
108 return (1); | |
109 } | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
110 |
0 | 111 return 0; |
112 } | |
113 | |
114 char *next_capture (int dev, char *map, int width, int height) | |
115 { | |
116 int i; | |
117 char *grey, *rgb; | |
118 struct video_mmap vid_mmap; | |
119 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
120 sigset_t set, old; |
0 | 121 |
122 if (read_img) { | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
123 if (fmt == VIDEO_PALETTE_GREY) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
124 size_t size = width * height; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
125 if (read(dev, map, size) != size) |
0 | 126 return NULL; |
127 } else { | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
128 size_t size = width * height * 3; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
129 if (read(dev, map, size) != size) |
0 | 130 return NULL; |
131 } | |
132 } else { | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
133 vid_mmap.format = fmt; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
134 vid_mmap.frame = 0; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
135 vid_mmap.width = width; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
136 vid_mmap.height = height; |
0 | 137 |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
138 sigemptyset (&set); //BTTV hates signals during IOCTL |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
139 sigaddset (&set, SIGCHLD); //block SIGCHLD & SIGALRM |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
140 sigaddset (&set, SIGALRM); //for the time of ioctls |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
141 sigprocmask (SIG_BLOCK, &set, &old); |
0 | 142 |
143 if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
144 sigprocmask (SIG_UNBLOCK, &old, NULL); |
0 | 145 return (NULL); |
146 } | |
147 if (ioctl(dev, VIDIOCSYNC, &vid_mmap) == -1) { | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
148 sigprocmask (SIG_UNBLOCK, &old, NULL); |
0 | 149 return (NULL); |
150 } | |
151 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
152 sigprocmask(SIG_UNBLOCK, &old, NULL); //undo the signal blocking |
0 | 153 } |
154 /* Blow up a grey */ | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
155 if (fmt == VIDEO_PALETTE_GREY) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
156 i = width * height; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
157 grey = map + i - 1; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
158 rgb = map + i * 3; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
159 for (; i >= 0; i--, grey--) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
160 *(rgb--) =*grey; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
161 *(rgb--) =*grey; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
162 *(rgb--) =*grey; |
0 | 163 } |
164 } | |
165 return map; | |
166 } | |
167 | |
168 int put_image(int dev, char *image, int width, int height) | |
169 { | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
170 if (write(dev, image, width * height * 3) != width * height * 3) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
171 printf("Error writing image to pipe!\nError[%s]\n", strerror(errno)); |
0 | 172 return 0; |
173 } | |
174 return 1; | |
175 } | |
176 | |
177 void sig_handler(int signo) | |
178 { | |
179 noexit = 0; | |
180 } | |
181 | |
182 int main (int argc, char **argv) | |
183 { | |
184 int x, y, devin, devout; | |
185 int width, realwidth; | |
186 int height; | |
187 int widthout, realwidthout; | |
188 int heightout; | |
189 int **newy, **newx, **line; | |
190 char *image_out, *image_new; | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
191 char palette[10] = {'\0'}; |
0 | 192 |
193 if (argc != 6) { | |
194 printf("Usage:\n\n"); | |
195 printf("resize input output widthxheight(in) widthxheight(out) rgb24|yuv420p\n\n"); | |
196 printf("example: resize /dev/video0 /dev/video1 352x288 176x144 yuv420p\n\n"); | |
197 exit(1); | |
198 } | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
199 |
0 | 200 sscanf(argv[3], "%dx%d", &width, &height); |
201 sscanf(argv[4], "%dx%d", &widthout, &heightout); | |
202 sscanf(argv[5], "%s", palette); | |
203 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
204 if (!strcmp(palette,"rgb24")) |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
205 fmt = VIDEO_PALETTE_RGB24; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
206 else if (!strcmp(palette,"yuv420p")) |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
207 fmt = VIDEO_PALETTE_YUV420P; |
0 | 208 else fmt = VIDEO_PALETTE_RGB24; |
209 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
210 realwidth = width * 3; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
211 realwidthout = widthout * 3; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
212 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
213 image_out = malloc(widthout * heightout * 3); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
214 line = malloc(sizeof(int*) * heightout); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
215 newy = malloc(sizeof(int*) * heightout); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
216 newx = malloc(sizeof(int*) * realwidthout); |
0 | 217 |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
218 for (y = 0; y < heightout; y++) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
219 line[y] = malloc(sizeof(int)); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
220 line[y][0] = y * realwidthout; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
221 newy[y] = malloc(sizeof(int)); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
222 newy[y][0] = y * height / heightout * realwidth; |
0 | 223 } |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
224 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
225 for (x = 0; x < widthout; x++) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
226 newx[x *3] = malloc(sizeof(int)); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
227 newx[x *3 + 1] = malloc(sizeof(int)); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
228 newx[x *3 + 2] = malloc(sizeof(int)); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
229 newx[x *3][0] = x * width / widthout * 3; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
230 newx[x *3 + 1][0] = x * width / widthout * 3 + 1; |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
231 newx[x * 3 + 2][0] = x * width / widthout * 3 + 2; |
0 | 232 } |
233 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
234 devin = open(argv[1], O_RDWR); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
235 |
0 | 236 if (devin < 0) { |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
237 printf ("Failed to open video device %s\nError[%s]\n", argv[1], strerror(errno)); |
0 | 238 exit(1); |
239 } | |
240 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
241 devout = open(argv[2], O_RDWR); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
242 |
0 | 243 if (devout < 0) { |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
244 printf ("Failed to open video device%s \nError[%s]\n", argv[2], strerror(errno)); |
0 | 245 exit(1); |
246 } | |
247 | |
248 image_new=start_capture (devin, width, height); | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
249 |
0 | 250 if (!image_new) { |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
251 printf("Capture error\nError[%s]\n", strerror(errno)); |
0 | 252 exit(1); |
253 } | |
254 | |
255 start_pipe(devout, widthout, heightout); | |
256 signal(SIGTERM, sig_handler); | |
257 printf("Starting video stream.\n"); | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
258 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
259 while ((next_capture(devin, image_new, width, height)) && (noexit)) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
260 for (y = 0; y < heightout; y++) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
261 for (x = 0; x < realwidthout; x++) |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
262 image_out[line[y][0] + x] = image_new[newy[y][0] + newx[x][0]]; |
0 | 263 } |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
264 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
265 if (put_image(devout, image_out, widthout, heightout) == 0) |
0 | 266 exit(1); |
267 } | |
268 | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
269 printf("You bought vaporware!\nError[%s]\n", strerror(errno)); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
270 close(devin); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
271 close(devout); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
272 |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
273 for (y = 0; y < heightout; y++) { |
0 | 274 free(line[y]); |
275 free(newy[y]); | |
276 } | |
7
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
277 for (x = 0; x < widthout; x++) { |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
278 free(newx[x * 3]); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
279 free(newx[x * 3 + 1]); |
2fce9e157b8d
Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents:
0
diff
changeset
|
280 free(newx[x * 3 + 2]); |
0 | 281 } |
282 | |
283 free(line); | |
284 free(newx); | |
285 free(newy); | |
286 | |
287 free(image_out); | |
288 exit(0); | |
289 } |