Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <unistd.h>
  4 #include <string.h>
  5 #include <errno.h>
  6 #include <fcntl.h>
  7 #include <inttypes.h>
  8 #include <ctype.h>
  9 
 10 #include <sys/time.h>
 11 #include <sys/ioctl.h>
 12 
 13 #include "videodev.h"
 14 #include "videodev2.h"
 15 
 16 #include "struct-dump.h"
 17 #include "struct-v4l.h"
 18 #include "struct-v4l2.h"
 19 
 20 /* --------------------------------------------------------------------- */
 21 /* v4l(1)                                                                */
 22 
 23 static int dump_v4l(int fd, int tab)
 24 {
 25         struct video_capability  capability;
 26         struct video_channel     channel;
 27         struct video_tuner       tuner;
 28         struct video_audio       audio;
 29         struct video_picture     picture;
 30         struct video_buffer      buffer;
 31         struct video_window      window;
 32         unsigned int i;
 33 
 34         printf("general info\n");
 35         memset(&capability,0,sizeof(capability));
 36         if (-1 == ioctl(fd,VIDIOCGCAP,&capability))
 37                 return -1;
 38         printf("    VIDIOCGCAP\n");
 39         print_struct(stdout,desc_video_capability,&capability,"",tab);
 40         printf("\n");
 41 
 42         printf("channels\n");
 43         for (i = 0; i < capability.channels; i++) {
 44                 memset(&channel,0,sizeof(channel));
 45                 channel.channel = i;
 46                 if (-1 == ioctl(fd,VIDIOCGCHAN,&channel)) {
 47                         perror("ioctl VIDIOCGCHAN");
 48                         continue;
 49                 }
 50                 printf("    VIDIOCGCHAN(%d)\n",i);
 51                 print_struct(stdout,desc_video_channel,&channel,"",tab);
 52         }
 53         printf("\n");
 54 
 55         printf("tuner\n");
 56         memset(&tuner,0,sizeof(tuner));
 57         if (-1 == ioctl(fd,VIDIOCGTUNER,&tuner)) {
 58                 perror("ioctl VIDIOCGTUNER");
 59         } else {
 60                 printf("    VIDIOCGTUNER\n");
 61                 print_struct(stdout,desc_video_tuner,&tuner,"",tab);
 62         }
 63         printf("\n");
 64 
 65         printf("audio\n");
 66         memset(&audio,0,sizeof(audio));
 67         if (-1 == ioctl(fd,VIDIOCGAUDIO,&audio)) {
 68                 perror("ioctl VIDIOCGAUDIO");
 69         } else {
 70                 printf("    VIDIOCGAUDIO\n");
 71                 print_struct(stdout,desc_video_audio,&audio,"",tab);
 72         }
 73         printf("\n");
 74 
 75         printf("picture\n");
 76         memset(&picture,0,sizeof(picture));
 77         if (-1 == ioctl(fd,VIDIOCGPICT,&picture)) {
 78                 perror("ioctl VIDIOCGPICT");
 79         } else {
 80                 printf("    VIDIOCGPICT\n");
 81                 print_struct(stdout,desc_video_picture,&picture,"",tab);
 82         }
 83         printf("\n");
 84 
 85         printf("buffer\n");
 86         memset(&buffer,0,sizeof(buffer));
 87         if (-1 == ioctl(fd,VIDIOCGFBUF,&buffer)) {
 88                 perror("ioctl VIDIOCGFBUF");
 89         } else {
 90                 printf("    VIDIOCGFBUF\n");
 91                 print_struct(stdout,desc_video_buffer,&buffer,"",tab);
 92         }
 93         printf("\n");
 94 
 95         printf("window\n");
 96         memset(&window,0,sizeof(window));
 97         if (-1 == ioctl(fd,VIDIOCGWIN,&window)) {
 98                 perror("ioctl VIDIOCGWIN");
 99         } else {
100                 printf("    VIDIOCGWIN\n");
101                 print_struct(stdout,desc_video_window,&window,"",tab);
102         }
103         printf("\n");
104 
105         return 0;
106 }
107 
108 /* --------------------------------------------------------------------- */
109 /* v4l2                                                                  */
110 
111 static int dump_v4l2(int fd, int tab)
112 {
113         struct v4l2_capability  capability;
114         struct v4l2_standard    standard;
115         struct v4l2_input       input;
116         struct v4l2_tuner       tuner;
117         struct v4l2_fmtdesc     fmtdesc;
118         struct v4l2_format      format;
119         struct v4l2_framebuffer fbuf;
120         struct v4l2_queryctrl   qctrl;
121         int i;
122 
123         printf("general info\n");
124         memset(&capability,0,sizeof(capability));
125         if (-1 == ioctl(fd,VIDIOC_QUERYCAP,&capability))
126                 return -1;
127         printf("    VIDIOC_QUERYCAP\n");
128         print_struct(stdout,desc_v4l2_capability,&capability,"",tab);
129         printf("\n");
130 
131         printf("standards\n");
132         for (i = 0;; i++) {
133                 memset(&standard,0,sizeof(standard));
134                 standard.index = i;
135                 if (-1 == ioctl(fd,VIDIOC_ENUMSTD,&standard))
136                         break;
137                 printf("    VIDIOC_ENUMSTD(%d)\n",i);
138                 print_struct(stdout,desc_v4l2_standard,&standard,"",tab);
139         }
140         printf("\n");
141 
142         printf("inputs\n");
143         for (i = 0;; i++) {
144                 memset(&input,0,sizeof(input));
145                 input.index = i;
146                 if (-1 == ioctl(fd,VIDIOC_ENUMINPUT,&input))
147                         break;
148                 printf("    VIDIOC_ENUMINPUT(%d)\n",i);
149                 print_struct(stdout,desc_v4l2_input,&input,"",tab);
150         }
151         printf("\n");
152 
153         if (capability.capabilities & V4L2_CAP_TUNER) {
154                 printf("tuners\n");
155                 for (i = 0;; i++) {
156                         memset(&tuner,0,sizeof(tuner));
157                         tuner.index = i;
158                         if (-1 == ioctl(fd,VIDIOC_G_TUNER,&tuner))
159                                 break;
160                         printf("    VIDIOC_G_TUNER(%d)\n",i);
161                         print_struct(stdout,desc_v4l2_tuner,&tuner,"",tab);
162                 }
163                 printf("\n");
164         }
165 
166         if (capability.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
167                 printf("video capture\n");
168                 for (i = 0;; i++) {
169                         memset(&fmtdesc,0,sizeof(fmtdesc));
170                         fmtdesc.index = i;
171                         fmtdesc.type  = V4L2_BUF_TYPE_VIDEO_CAPTURE;
172                         if (-1 == ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc))
173                                 break;
174                         printf("    VIDIOC_ENUM_FMT(%d,VIDEO_CAPTURE)\n",i);
175                         print_struct(stdout,desc_v4l2_fmtdesc,&fmtdesc,"",tab);
176                 }
177                 memset(&format,0,sizeof(format));
178                 format.type  = V4L2_BUF_TYPE_VIDEO_CAPTURE;
179                 if (-1 == ioctl(fd,VIDIOC_G_FMT,&format)) {
180                         perror("VIDIOC_G_FMT(VIDEO_CAPTURE)");
181                 } else {
182                         printf("    VIDIOC_G_FMT(VIDEO_CAPTURE)\n");
183                         print_struct(stdout,desc_v4l2_format,&format,"",tab);
184                 }
185                 printf("\n");
186         }
187 
188         if (capability.capabilities & V4L2_CAP_VIDEO_OVERLAY) {
189                 printf("video overlay\n");
190                 for (i = 0;; i++) {
191                         memset(&fmtdesc,0,sizeof(fmtdesc));
192                         fmtdesc.index = i;
193                         fmtdesc.type  = V4L2_BUF_TYPE_VIDEO_OVERLAY;
194                         if (-1 == ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc))
195                                 break;
196                         printf("    VIDIOC_ENUM_FMT(%d,VIDEO_OVERLAY)\n",i);
197                         print_struct(stdout,desc_v4l2_fmtdesc,&fmtdesc,"",tab);
198                 }
199                 memset(&format,0,sizeof(format));
200                 format.type  = V4L2_BUF_TYPE_VIDEO_OVERLAY;
201                 if (-1 == ioctl(fd,VIDIOC_G_FMT,&format)) {
202                         perror("VIDIOC_G_FMT(VIDEO_OVERLAY)");
203                 } else {
204                         printf("    VIDIOC_G_FMT(VIDEO_OVERLAY)\n");
205                         print_struct(stdout,desc_v4l2_format,&format,"",tab);
206                 }
207                 memset(&fbuf,0,sizeof(fbuf));
208                 if (-1 == ioctl(fd,VIDIOC_G_FBUF,&fbuf)) {
209                         perror("VIDIOC_G_FBUF");
210                 } else {
211                         printf("    VIDIOC_G_FBUF\n");
212                         print_struct(stdout,desc_v4l2_framebuffer,&fbuf,"",tab);
213                 }
214                 printf("\n");
215         }
216 
217         if (capability.capabilities & V4L2_CAP_VBI_CAPTURE) {
218                 printf("vbi capture\n");
219                 for (i = 0;; i++) {
220                         memset(&fmtdesc,0,sizeof(fmtdesc));
221                         fmtdesc.index = i;
222                         fmtdesc.type  = V4L2_BUF_TYPE_VBI_CAPTURE;
223                         if (-1 == ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc))
224                                 break;
225                         printf("    VIDIOC_ENUM_FMT(%d,VBI_CAPTURE)\n",i);
226                         print_struct(stdout,desc_v4l2_fmtdesc,&fmtdesc,"",tab);
227                 }
228                 memset(&format,0,sizeof(format));
229                 format.type  = V4L2_BUF_TYPE_VBI_CAPTURE;
230                 if (-1 == ioctl(fd,VIDIOC_G_FMT,&format)) {
231                         perror("VIDIOC_G_FMT(VBI_CAPTURE)");
232                 } else {
233                         printf("    VIDIOC_G_FMT(VBI_CAPTURE)\n");
234                         print_struct(stdout,desc_v4l2_format,&format,"",tab);
235                 }
236                 printf("\n");
237         }
238 
239         printf("controls\n");
240         for (i = 0;; i++) {
241                 memset(&qctrl,0,sizeof(qctrl));
242                 qctrl.id = V4L2_CID_BASE+i;
243                 if (-1 == ioctl(fd,VIDIOC_QUERYCTRL,&qctrl))
244                         break;
245                 if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED)
246                         continue;
247                 printf("    VIDIOC_QUERYCTRL(BASE+%d)\n",i);
248                 print_struct(stdout,desc_v4l2_queryctrl,&qctrl,"",tab);
249         }
250         for (i = 0;; i++) {
251                 memset(&qctrl,0,sizeof(qctrl));
252                 qctrl.id = V4L2_CID_PRIVATE_BASE+i;
253                 if (-1 == ioctl(fd,VIDIOC_QUERYCTRL,&qctrl))
254                         break;
255                 if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED)
256                         continue;
257                 printf("    VIDIOC_QUERYCTRL(PRIVATE_BASE+%d)\n",i);
258                 print_struct(stdout,desc_v4l2_queryctrl,&qctrl,"",tab);
259         }
260         return 0;
261 }
262 
263 /* --------------------------------------------------------------------- */
264 /* main                                                                  */
265 
266 int main(int argc, char *argv[])
267 {
268         char dummy[256];
269         char *device = "/dev/video0";
270         int tab = 1, ok = 0;
271         int fd;
272 
273         if (argc > 1)
274                 device = argv[1];
275         
276         fd = open(device,O_RDONLY);
277         if (-1 == fd) {
278                 fprintf(stderr,"open %s: %s\n",device,strerror(errno));
279                 exit(1);
280         };
281 
282         if (-1 != ioctl(fd,VIDIOC_QUERYCAP,dummy)) {
283                 printf("\n### v4l2 device info [%s] ###\n",device);
284                 dump_v4l2(fd,tab);
285                 ok = 1;
286         }
287 
288         if (-1 != ioctl(fd,VIDIOCGCAP,dummy)) {
289                 printf("\n### video4linux device info [%s] ###\n",device);
290                 dump_v4l(fd,tab);
291                 ok = 1;
292         }
293 
294         if (!ok) {
295                 fprintf(stderr,"%s: not an video4linux device\n",device);
296                 exit(1);
297         }
298         return 0;
299 }
300 /*
301  * Local variables:
302  * c-basic-offset: 8
303  * End:
304  */
305 
  This page was automatically generated by the LXR engine.