annotate example/feed.c @ 17:5afb0aa410ec default tip

update to 2.6.34
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sun, 25 Jul 2010 23:29:20 +0900
parents 2fce9e157b8d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
1 /* feed.c
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
2 *
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
3 * Example program for videoloopback device.
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
4 * Copyright 2006 by Angel Carpintero (ack@telefonica.net)
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
5 * This software is distributed under the GNU public license version 2
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
6 * See also the file 'COPYING'.
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
7 *
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
8 */
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
9
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
10 #include <unistd.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
11 #include <stdlib.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
12 #include <stdio.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
13 #include <fcntl.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
14 #include <string.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
15 #include <errno.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
16 #include <sys/ioctl.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
17 #include <sys/mman.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
18 #include <signal.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
19 #include <sys/wait.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
20 #include <linux/videodev.h>
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
21
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
22
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
23 int fmt = 0;
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
24 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
25 int read_img = 0;
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
26
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
27 char *start_capture (int dev, int width, int height)
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
28 {
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
29 struct video_capability vid_caps;
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
30 struct video_window vid_win;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
31 struct video_mbuf vid_buf;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
32 char *map;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
33
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
34 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
35 printf ("ioctl (VIDIOCGCAP)\nError[%s]\n", strerror(errno));
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
36 return (NULL);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
37 }
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
38
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
39 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
40 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
41
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
42 if (ioctl (dev, VIDIOCGMBUF, &vid_buf) == -1) {
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
43 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
44
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
45 if (ioctl (dev, VIDIOCGWIN, &vid_win)== -1) {
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
46 printf ("ioctl VIDIOCGWIN\nError[%s]\n",strerror(errno));
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
47 return (NULL);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
48 }
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
49
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
50 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
51 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
52
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
53 if (ioctl (dev, VIDIOCSWIN, &vid_win)== -1) {
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
54 printf ("ioctl VIDIOCSWIN\nError[%s]\n",strerror(errno));
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
55 return (NULL);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
56 }
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
57
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
58 read_img = 1;
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
59 map = malloc(width * height * 3);
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
60 return (map);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
61 }
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
62
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
63 /* 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
64 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
65 map = mmap(0, vid_buf.size * 3, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0);
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
66 else
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
67 map = mmap(0, vid_buf.size, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0);
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
68
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
69 if ((unsigned char *)-1 == (unsigned char *)map)
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
70 return (NULL);
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
71
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
72 return map;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
73 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
74
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
75 int start_pipe (int dev, int width, int height)
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
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
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
78 struct video_window vid_win;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
79 struct video_picture vid_pic;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
80
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
81 if (ioctl (dev, VIDIOCGCAP, &vid_caps) == -1) {
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
82 printf ("ioctl (VIDIOCGCAP)\nError[%s]\n",strerror(errno));
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
83 return (1);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
84 }
7
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) {
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
87 printf ("ioctl VIDIOCGPICT\nError[%s]\n",strerror(errno));
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
88 return (1);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
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) {
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
94 printf ("ioctl VIDIOCSPICT\nError[%s]\n",strerror(errno));
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
95 return (1);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
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
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
99 printf ("ioctl VIDIOCGWIN");
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
100 return (1);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
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
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
107 printf ("ioctl VIDIOCSWIN");
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
108 return (1);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
109 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
110 return 0;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
111 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
112
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
113 char *next_capture (int dev, char *map, int width, int height)
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
114 {
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
115 int i;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
116 char *grey, *rgb;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
117 struct video_mmap vid_mmap;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
118
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
119 sigset_t set, old;
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
120
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
121 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
122
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
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
126 return NULL;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
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
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
130 return NULL;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
131 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
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
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
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
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
142
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
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
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
145 return (NULL);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
146 }
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
147
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
148 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
149 sigprocmask (SIG_UNBLOCK, &old, NULL);
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
150 return (NULL);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
151 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
152
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
153 sigprocmask(SIG_UNBLOCK, &old, NULL); //undo the signal blocking
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
154 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
155 /* 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
156 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
157 i= width * height;
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
158 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
159 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
160
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
161 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
162 *(rgb--) =*grey;
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
163 *(rgb--) =*grey;
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
164 *(rgb--) =*grey;
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
165 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
166 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
167 return map;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
168 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
169
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
170 int put_image(int dev, char *image, int width, int height)
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
171 {
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
172 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
173
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
174 if (write(dev, image, size) != size) {
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
175 printf("Error writing image to pipe!\nError[%s]\n", strerror(errno));
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
176 return 0;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
177 }
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
178
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
179 return 1;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
180 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
181
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
182 void sig_handler(int signo)
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
183 {
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
184 noexit = 0;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
185 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
186
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
187
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
188 int main (int argc, char **argv)
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
189 {
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
190 int devin, devout;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
191 int width;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
192 int height;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
193 char *image_new;
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
194 char palette[10] = {'\0'};
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
195
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
196 if (argc != 5) {
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
197 printf("Usage:\n\n");
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
198 printf("feed input output widthxheight(in) rgb24|yuv420p\n\n");
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
199 printf("example: feed /dev/video0 /dev/video1 352x288 yuv420p\n\n");
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
200 exit(1);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
201 }
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
202
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
203 sscanf(argv[3], "%dx%d", &width, &height);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
204 sscanf(argv[4], "%s", palette);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
205
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
206 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
207 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
208 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
209 fmt = VIDEO_PALETTE_YUV420P;
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
210 else fmt = VIDEO_PALETTE_RGB24;
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
211
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
212 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
213
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
214 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
215 printf ("Failed to open video device %s\nError[%s]\n", argv[1], strerror(errno));
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
216 exit(1);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
217 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
218
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
219 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
220
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
221 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
222 printf ("Failed to open video device%s \nError[%s]\n", argv[2], strerror(errno));
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
223 exit(1);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
224 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
225
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
226 image_new = start_capture(devin, width, height);
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
227
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
228 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
229 printf("Capture error\nError[%s]\n", strerror(errno));
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
230 exit(1);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
231 }
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
232
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
233 start_pipe(devout, width, height);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
234
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
235 signal(SIGTERM, sig_handler);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
236
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
237 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
238
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
239 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
240 if (put_image(devout, image_new, width, height) == 0)
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
241 exit(1);
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
242
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
243 }
7
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
244
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
245 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
246
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
247 close(devin);
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
248 close(devout);
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
249
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
250 if ((read_img) && (image_new))
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
251 free(image_new);
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
252 else 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
253 munmap(image_new, width * height * 3);
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
254 else
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
255 munmap(image_new, width * height);
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
256
2fce9e157b8d Added some work around to work with kernel 2.6.27-rc3, added debug param.
AngelCarpintero
parents: 0
diff changeset
257
0
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
258 exit(0);
5f21a4dddc0c Initial checkin
KennethLavrsen
parents:
diff changeset
259 }