]> git.pld-linux.org Git - packages/xorg-driver-video-v4l.git/blob - support_v4l2_only_drivers.patch
- release 22 (by relup.sh)
[packages/xorg-driver-video-v4l.git] / support_v4l2_only_drivers.patch
1 diff --git a/src/v4l.c b/src/v4l.c
2 --- a/src/v4l.c
3 +++ b/src/v4l.c
4 @@ -1,6 +1,9 @@
5  /*
6 - *  video4linux Xv Driver 
7 + *  video4linux Xv Driver
8   *  based on Michael Schimek's permedia 2 driver.
9 + *
10 + * Copyright (c) 2011 Mauro Carvalho Chehab <mchehab@redhat.com> for:
11 + *     - Major rewrite, as driver got ported to V4L2 API
12   */
13  
14  #ifdef HAVE_CONFIG_H
15 @@ -9,12 +12,16 @@
16  
17  #include <sys/types.h>
18  #include <sys/stat.h>
19 +#include <ctype.h>
20 +
21  #include <fcntl.h>
22  #include <errno.h>
23  #include <string.h>
24  #include <stdio.h>
25 +#include <unistd.h>
26 +#include <sys/ioctl.h>
27  
28 -#include "videodev.h"
29 +#include "videodev2.h"
30  #include "xf86.h"
31  #include "xf86_OSproc.h"
32  #include "xf86Pci.h"
33 @@ -25,29 +32,32 @@
34  #include "regionstr.h"
35  #include "dgaproc.h"
36  #include "xf86str.h"
37 +#include "fourcc.h"
38  
39 -#include <asm/ioctl.h>         /* _IORW(xxx) #defines are here */
40 +#include <asm/ioctl.h>          /* _IORW(xxx) #defines are here */
41  
42 -#if 0
43 +#if 1
44  # define DEBUG(x) (x)
45  #else
46  # define DEBUG(x)
47  #endif
48  
49 +/***************************************************************************/
50 +
51  static void     V4LIdentify(int flags);
52  static Bool     V4LProbe(DriverPtr drv, int flags);
53  static const OptionInfoRec * V4LAvailableOptions(int chipid, int busid);
54  
55  _X_EXPORT DriverRec V4L = {
56 -        40000,
57 -        "v4l",
58 -        V4LIdentify, /* Identify*/
59 -        V4LProbe, /* Probe */
60 -       V4LAvailableOptions,
61 -        NULL,
62 -        0
63 -};    
64 -
65 +    .driverVersion = 50000,
66 +    .driverName = "v4l",
67 +    .Identify = V4LIdentify,
68 +    .Probe = V4LProbe,
69 +    .AvailableOptions = V4LAvailableOptions,
70 +    .module = NULL,
71 +    .refCount = 0,
72 +    .driverFunc = NULL,   /* FIXME: Need to implement for new probing mode */
73 +};
74  
75  #ifdef XFree86LOADER
76  
77 @@ -55,16 +65,16 @@ static MODULESETUPPROTO(v4lSetup);
78  
79  static XF86ModuleVersionInfo v4lVersRec =
80  {
81 -        "v4l",
82 -        MODULEVENDORSTRING,
83 -        MODINFOSTRING1,
84 -        MODINFOSTRING2,
85 -        XORG_VERSION_CURRENT,
86 -        0, 1, 1,
87 -        ABI_CLASS_VIDEODRV,
88 -        ABI_VIDEODRV_VERSION,
89 -        MOD_CLASS_NONE,
90 -        {0,0,0,0}
91 +    "v4l",
92 +    MODULEVENDORSTRING,
93 +    MODINFOSTRING1,
94 +    MODINFOSTRING2,
95 +    XORG_VERSION_CURRENT,
96 +    0, 1, 1,
97 +    ABI_CLASS_VIDEODRV,
98 +    ABI_VIDEODRV_VERSION,
99 +    MOD_CLASS_NONE,
100 +    {0,0,0,0}
101  };
102  
103  _X_EXPORT XF86ModuleData v4lModuleData = { &v4lVersRec, v4lSetup, NULL };
104 @@ -72,32 +82,32 @@ _X_EXPORT XF86ModuleData v4lModuleData =
105  static pointer
106  v4lSetup(pointer module, pointer opts, int *errmaj, int *errmin)
107  {
108 -        const char *osname;
109 -       static Bool setupDone = FALSE;
110 +    const char *osname;
111 +    static Bool setupDone = FALSE;
112  
113 -       if (setupDone) {
114 -           if (errmaj)
115 -               *errmaj = LDR_ONCEONLY;
116 -           return NULL;             
117 -       }
118 -       
119 -       setupDone = TRUE;
120 +    if (setupDone) {
121 +        if (errmaj)
122 +            *errmaj = LDR_ONCEONLY;
123 +        return NULL;
124 +    }
125  
126 -        /* Check that we're being loaded on a Linux system */
127 -        LoaderGetOS(&osname, NULL, NULL, NULL);
128 -        if (!osname || strcmp(osname, "linux") != 0) {
129 -                if (errmaj)
130 -                        *errmaj = LDR_BADOS;
131 -                if (errmin)
132 -                        *errmin = 0;
133 -                return NULL;
134 -        } else {
135 -                /* OK */
136 +    setupDone = TRUE;
137  
138 -               xf86AddDriver (&V4L, module, 0);   
139 -         
140 -                return (pointer)1;
141 -        }
142 +    /* Check that we're being loaded on a Linux system */
143 +    LoaderGetOS(&osname, NULL, NULL, NULL);
144 +    if (!osname || strcmp(osname, "linux") != 0) {
145 +        if (errmaj)
146 +            *errmaj = LDR_BADOS;
147 +        if (errmin)
148 +            *errmin = 0;
149 +        return NULL;
150 +    } else {
151 +        /* OK */
152 +
153 +        xf86AddDriver (&V4L, module, 0);
154 +
155 +        return (pointer)1;
156 +    }
157  }
158  
159  #else
160 @@ -112,25 +122,28 @@ v4lSetup(pointer module, pointer opts, i
161  #define VIDEO_YUV     2  /* yuv overlay (to offscreen memory + hw scaling) */
162  #define VIDEO_RECLIP  3  /* temporarly off, window clipping changes */
163  
164 +typedef struct _XvV4LCtrlRec {
165 +    struct v4l2_queryctrl       qctrl;
166 +    Atom                        xv;
167 +} XvV4LCtrlRec, *XvV4LCtrlPtr;
168 +
169  typedef struct _PortPrivRec {
170      ScrnInfoPtr                 pScrn;
171 -    FBAreaPtr                  pFBArea[2];
172 -    int                                VideoOn;
173 -    Bool                       StreamOn;
174 +    FBAreaPtr                   pFBArea[2];
175 +    int                         VideoOn;
176 +    Bool                        StreamOn;
177  
178      /* file handle */
179 -    int                        nr;
180 -    struct video_capability     cap;
181 +    int                         nr;
182 +    struct v4l2_capability      cap;
183  
184      /* RGB overlay */
185 -    struct video_buffer                rgb_fbuf;
186 -    struct video_window                rgb_win;
187 -    int                         rgbpalette;
188 +    struct v4l2_framebuffer     rgb_fbuf;
189 +    struct v4l2_window          rgb_win;
190      int                         rgbdepth;
191  
192      /* attributes */
193 -    struct video_picture       pict;
194 -    struct video_audio          audio;
195 +    CARD32                      pixelformat;
196  
197      XF86VideoEncodingPtr        enc;
198      int                         *input;
199 @@ -145,24 +158,21 @@ typedef struct _PortPrivRec {
200  
201      int                         yuv_width,yuv_height;
202      XF86SurfacePtr              surface;
203 -    struct video_buffer                yuv_fbuf;
204 -    struct video_window                yuv_win;
205 +    struct v4l2_framebuffer     yuv_fbuf;
206 +    struct v4l2_window          yuv_win;
207 +
208 +    struct v4l2_standard        *standard; /* FIXME: can be removed */
209 +
210 +    XvV4LCtrlPtr                XvV4LCtrl;
211 +    int                         n_qctrl;
212  } PortPrivRec, *PortPrivPtr;
213  
214 -#define XV_ENCODING    "XV_ENCODING"
215 -#define XV_BRIGHTNESS          "XV_BRIGHTNESS"
216 -#define XV_CONTRAST    "XV_CONTRAST"
217 -#define XV_SATURATION          "XV_SATURATION"
218 -#define XV_HUE         "XV_HUE"
219 +#define XV_ENCODING "XV_ENCODING"
220 +#define XV_FREQ     "XV_FREQ"
221  
222 -#define XV_FREQ                "XV_FREQ"
223 -#define XV_MUTE                "XV_MUTE"
224 -#define XV_VOLUME              "XV_VOLUME"
225 +#define MAKE_ATOM(a) MakeAtom(a, strlen(a), TRUE)
226  
227 -#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
228 -
229 -static Atom xvEncoding, xvBrightness, xvContrast, xvSaturation, xvHue;
230 -static Atom xvFreq, xvMute, xvVolume;
231 +static Atom xvEncoding, xvFreq;
232  
233  static XF86VideoFormatRec
234  InputVideoFormats[] = {
235 @@ -176,16 +186,8 @@ InputVideoFormats[] = {
236  
237  static const XF86AttributeRec Attributes[] = {
238      {XvSettable | XvGettable, -1000,    1000, XV_ENCODING},
239 -    {XvSettable | XvGettable, -1000,    1000, XV_BRIGHTNESS},
240 -    {XvSettable | XvGettable, -1000,    1000, XV_CONTRAST},
241 -    {XvSettable | XvGettable, -1000,    1000, XV_SATURATION},
242 -    {XvSettable | XvGettable, -1000,    1000, XV_HUE},
243  };
244 -static const XF86AttributeRec VolumeAttr = 
245 -    {XvSettable | XvGettable, -1000,    1000, XV_VOLUME};
246 -static const XF86AttributeRec MuteAttr = 
247 -    {XvSettable | XvGettable,     0,       1, XV_MUTE};
248 -static const XF86AttributeRec FreqAttr = 
249 +static const XF86AttributeRec FreqAttr =
250      {XvSettable | XvGettable,     0, 16*1000, XV_FREQ};
251  
252  
253 @@ -206,59 +208,247 @@ static struct V4L_DEVICE {
254  };
255  
256  /* ---------------------------------------------------------------------- */
257 -/* forward decl */
258  
259 -static void V4lQueryBestSize(ScrnInfoPtr pScrn, Bool motion,
260 -                short vid_w, short vid_h, short drw_w, short drw_h,
261 -                unsigned int *p_w, unsigned int *p_h, pointer data);
262 +static int SetV4LFmt(int fd, CARD32 pixelformat)
263 +{
264 +    struct v4l2_framebuffer fbuf;
265 +    char *p = (char *)&pixelformat;
266 +
267 +    memset(&fbuf, 0, sizeof(fbuf));
268 +    if (ioctl(fd, VIDIOC_G_FBUF, &fbuf) == -1) {
269 +        xf86Msg(X_ERROR, "v4l: Error %d: Can't get FBUF\n", errno);
270 +        return errno;
271 +    }
272 +    if (fbuf.fmt.pixelformat != pixelformat) {
273 +        fbuf.fmt.pixelformat = pixelformat;
274 +        if (ioctl(fd, VIDIOC_S_FBUF, &fbuf) == -1) {
275 +            xf86Msg(X_ERROR, "v4l: Error %d: Can't set FBUF to %c%c%c%c\n",
276 +                    errno, p[0], p[1], p[2], p[3]);
277 +            return errno;
278 +        }
279 +    }
280 +    DEBUG(xf86Msg(X_INFO, "v4l: Set overlay format to %c%c%c%c\n",
281 +                  p[0], p[1], p[2], p[3]));
282 +    return 0;
283 +}
284 +static int GetV4LFmt(int fd, CARD32 *pixelformat)
285 +{
286 +    struct v4l2_framebuffer fbuf;
287 +
288 +    memset(&fbuf, 0, sizeof(fbuf));
289 +    if (ioctl(fd, VIDIOC_G_FBUF, &fbuf) == -1) {
290 +        xf86Msg(X_ERROR, "v4l: Error %d: Can't get FBUF\n", errno);
291 +        return errno;
292 +    }
293 +
294 +    *pixelformat = fbuf.fmt.pixelformat;
295 +
296 +    return 0;
297 +}
298 +
299 +#define ATTR_NAME_PREFIX "XV_"
300 +static int AddControl(PortPrivPtr p, XF86AttributeRec **list, int *count,
301 +                      struct v4l2_queryctrl *qctrl, int *n)
302 +{
303 +    char *ptr;
304 +
305 +/* v4l_add_attr */
306 +    if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
307 +        return 0;
308 +    switch (qctrl->type) {
309 +    case V4L2_CTRL_TYPE_INTEGER:
310 +    case V4L2_CTRL_TYPE_BOOLEAN:
311 +    case V4L2_CTRL_TYPE_MENU:
312 +    case V4L2_CTRL_TYPE_BUTTON:
313 +        break;
314 +    default:
315 +        return 0;
316 +    }
317 +
318 +    p->XvV4LCtrl = realloc(p->XvV4LCtrl, sizeof(XvV4LCtrlRec) * (*n + 1));
319 +    if (!p->XvV4LCtrl) {
320 +        if (*list) {
321 +            free (*list);
322 +            *count = 0;
323 +            *n = 0;
324 +        }
325 +        return -1;
326 +    }
327 +
328 +    *list = realloc(*list, sizeof(XF86AttributeRec) * (*count + 1));
329 +    if (NULL == *list) {
330 +        if (p->XvV4LCtrl)
331 +            free (p->XvV4LCtrl);
332 +        *count = 0;
333 +        return -1;
334 +    }
335 +
336 +    memset(*list + *count, 0, sizeof(XF86AttributeRec));
337 +    (*list)[*count].flags = XvSettable | XvGettable;
338 +
339 +    if (qctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
340 +        (*list)[*count].flags &= ~XvSettable;
341 +    if (qctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
342 +        (*list)[*count].flags &= ~XvGettable;
343 +    (*list)[*count].min_value = qctrl->minimum;
344 +    (*list)[*count].max_value = qctrl->maximum;
345 +    (*list)[*count].name = malloc(strlen((char *)qctrl->name) + 1 + sizeof (ATTR_NAME_PREFIX));
346 +    strcpy((*list)[*count].name, ATTR_NAME_PREFIX);
347 +    strcat((*list)[*count].name, (char *)qctrl->name);
348 +    for (ptr = (*list)[*count].name; *ptr; ptr++) {
349 +        *ptr = toupper(*ptr);
350 +        if (*ptr == ' ')
351 +            *ptr = '_';
352 +    }
353 +
354 +    p->XvV4LCtrl[*n].xv = MAKE_ATOM((*list)[*count].name);
355 +    memcpy(&p->XvV4LCtrl[*n].qctrl, qctrl, sizeof(*qctrl));
356 +
357 +    xf86Msg(X_INFO, "v4l: add attr %s (Xv/GPA %d) (%d to %d)\n",
358 +            (*list)[*count].name, (int)p->XvV4LCtrl[*n].xv,
359 +            p->XvV4LCtrl[*n].qctrl.minimum,
360 +            p->XvV4LCtrl[*n].qctrl.maximum);
361 +
362 +    (*count)++;
363 +    (*n)++;
364 +
365 +    return 0;
366 +}
367 +
368 +static void AddAllV4LControls(PortPrivPtr p, XF86AttributeRec **list,
369 +                              int *count, int fd)
370 +{
371 +    int entries = 0;
372 +    CARD32 id;
373 +    struct v4l2_queryctrl qctrl;
374 +
375 +    memset(&qctrl, 0, sizeof(qctrl));
376 +    qctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
377 +    while (!ioctl(fd, VIDIOC_QUERYCTRL, &qctrl)) {
378 +        if (AddControl(p, list, count, &qctrl, &entries))
379 +            return;
380 +        qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
381 +    }
382 +    if (qctrl.id != V4L2_CTRL_FLAG_NEXT_CTRL)
383 +        return;
384 +    for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) {
385 +        qctrl.id = id;
386 +        if (!ioctl(fd, VIDIOC_QUERYCTRL, &qctrl)) {
387 +            if (AddControl(p, list, count, &qctrl, &entries))
388 +                return;
389 +        }
390 +    }
391 +    qctrl.id = V4L2_CID_PRIVATE_BASE;
392 +    while (!ioctl(fd, VIDIOC_QUERYCTRL, &qctrl)) {
393 +        if (AddControl(p, list, count, &qctrl, &entries))
394 +            return;
395 +        qctrl.id++;
396 +    }
397 +    p->n_qctrl = entries;
398 +}
399  
400  /* ---------------------------------------------------------------------- */
401  
402 +/* setup yuv overlay + hw scaling: look if we find some common video
403 +   format which both v4l driver and the X-Server can handle */
404 +static int v4l_check_yuv(ScrnInfoPtr pScrn, PortPrivPtr pPPriv,
405 +                          char *dev, int fd)
406 +{
407 +    static const struct {
408 +        CARD32        v4l_palette;
409 +        unsigned int  xv_id;
410 +        unsigned int  xv_format;
411 +    } yuvlist[] = {
412 +        { V4L2_PIX_FMT_YUYV, FOURCC_YUY2, XvPacked },
413 +        { V4L2_PIX_FMT_UYVY, FOURCC_UYVY, XvPacked },
414 +        { 0 /* end of list */ },
415 +    };
416 +    /* FIXME: Why pScrn->scrnIndex? */
417 +    ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
418 +    int fmt,i;
419 +
420 +    pPPriv->format = xf86XVQueryOffscreenImages(pScreen, &pPPriv->nformat);
421 +    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
422 +                   "v4l: Number of Xv formats: %d\n", pPPriv->nformat);
423 +    if (!pPPriv->nformat)
424 +        return FALSE;
425 +
426 +    for (fmt = 0; yuvlist[fmt].v4l_palette != 0; fmt++) {
427 +        pPPriv->pixelformat = yuvlist[fmt].v4l_palette;
428 +        if (-1 == SetV4LFmt(fd, pPPriv->pixelformat))
429 +            continue;
430 +        GetV4LFmt(fd, &pPPriv->pixelformat);
431 +        if (pPPriv->pixelformat != yuvlist[fmt].v4l_palette)
432 +            continue;
433 +        /* ... works, check available offscreen image formats now ... */
434 +        for (i = 0; i < pPPriv->nformat; i++) {
435 +            if (pPPriv->format[i].image->id == yuvlist[fmt].xv_id &&
436 +                pPPriv->format[i].image->format == yuvlist[fmt].xv_format) {
437 +                /* ... match found, good. */
438 +                pPPriv->yuv_format = yuvlist[fmt].v4l_palette;
439 +                pPPriv->myfmt = pPPriv->format+i;
440 +                xf86DrvMsg(pScrn->scrnIndex, X_INFO,
441 +                           "v4l[%s]: using hw video scaling [%4.4s].\n",
442 +                           dev,(char*)&(pPPriv->format[i].image->id));
443 +                return TRUE;
444 +            }
445 +        }
446 +    }
447 +    return TRUE;
448 +}
449 +
450  static int V4lOpenDevice(PortPrivPtr pPPriv, ScrnInfoPtr pScrn)
451  {
452      static int first = 1;
453  
454 +#if 0
455 +    /*
456 +     * It may be a good idea to probe here, but this would break
457 +     * some things, as initialization uses yuv_format
458 +     */
459 +    if (!pPPriv->yuv_format && first)
460 +        v4l_check_yuv(pScrn, pPPriv, V4L_NAME, V4L_FD);
461 +#endif
462      if (-1 == V4L_FD) {
463 -       V4L_FD = open(V4L_NAME, O_RDWR, 0);
464 +        V4L_FD = open(V4L_NAME, O_RDWR, 0);
465  
466 -       pPPriv->rgb_fbuf.width        = pScrn->virtualX;
467 -       pPPriv->rgb_fbuf.height       = pScrn->virtualY;
468 -       pPPriv->rgb_fbuf.depth        = pScrn->bitsPerPixel;
469 -       pPPriv->rgb_fbuf.bytesperline = pScrn->displayWidth * ((pScrn->bitsPerPixel + 7)/8);
470 -       pPPriv->rgb_fbuf.base         = (pointer)(pScrn->memPhysBase + pScrn->fbOffset);
471 -       if (first) {
472 -           first = 0;
473 -           xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
474 -                        "v4l: memPhysBase=0x%lx\n", pScrn->memPhysBase);
475 -       }
476 +        if (-1 == V4L_FD)
477 +            return errno;
478  
479 -       switch (pScrn->bitsPerPixel) {
480 -       case 16:
481 -           if (pScrn->weight.green == 5) {
482 -               pPPriv->rgbpalette = VIDEO_PALETTE_RGB555;
483 -               pPPriv->rgbdepth   = 16;
484 -           } else {
485 -               pPPriv->rgbpalette = VIDEO_PALETTE_RGB565;
486 -               pPPriv->rgbdepth   = 16;
487 -           }
488 -           break;
489 -       case 24:
490 -           pPPriv->rgbpalette = VIDEO_PALETTE_RGB24;
491 -           pPPriv->rgbdepth   = 24;
492 -           break;
493 -       case 32:
494 -           pPPriv->rgbpalette = VIDEO_PALETTE_RGB32;
495 -           pPPriv->rgbdepth   = 32;
496 -           break;
497 -       }
498 +        if (-1 == ioctl(V4L_FD, VIDIOC_G_FBUF, &pPPriv->rgb_fbuf)) {
499 +            xf86Msg(X_ERROR, "v4l: Error %d: Can't get FBUF\n", errno);
500 +            return errno;
501 +        }
502 +        pPPriv->rgb_fbuf.fmt.width        = pScrn->virtualX;
503 +        pPPriv->rgb_fbuf.fmt.height       = pScrn->virtualY;
504 +        pPPriv->rgb_fbuf.fmt.bytesperline = pScrn->displayWidth * ((pScrn->bitsPerPixel + 7)/8);
505 +        pPPriv->rgb_fbuf.base             = (pointer)(pScrn->memPhysBase + pScrn->fbOffset);
506 +        if (first) {
507 +            xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
508 +                           "v4l: memPhysBase=0x%lx\n", pScrn->memPhysBase);
509 +            first = 0;
510 +        }
511 +
512 +        switch (pScrn->bitsPerPixel) {
513 +        case 16:
514 +            if (pScrn->weight.green == 5) {
515 +                pPPriv->rgb_fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
516 +            } else {
517 +                pPPriv->rgb_fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
518 +            }
519 +            break;
520 +        case 24:
521 +            pPPriv->rgb_fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
522 +            break;
523 +        case 32:
524 +            pPPriv->rgb_fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
525 +            break;
526 +        }
527      }
528  
529 -    if (-1 == V4L_FD)
530 -       return errno;
531 -    
532      V4L_REF++;
533      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
534 -                        "Xv/open: refcount=%d\n",V4L_REF));
535 +                         "Xv/open: refcount=%d\n",V4L_REF));
536  
537      return 0;
538  }
539 @@ -267,10 +457,10 @@ static void V4lCloseDevice(PortPrivPtr p
540  {
541      V4L_REF--;
542      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
543 -                        "Xv/close: refcount=%d\n",V4L_REF));
544 +                         "Xv/close: refcount=%d\n",V4L_REF));
545      if (0 == V4L_REF && -1 != V4L_FD) {
546 -       close(V4L_FD);
547 -       V4L_FD = -1;
548 +        close(V4L_FD);
549 +        V4L_FD = -1;
550      }
551  }
552  
553 @@ -280,8 +470,10 @@ V4lPutVideo(ScrnInfoPtr pScrn,
554      short vid_w, short vid_h, short drw_w, short drw_h,
555      RegionPtr clipBoxes, pointer data, DrawablePtr pDraw)
556  {
557 +    struct v4l2_format fmt;
558 +
559      PortPrivPtr pPPriv = (PortPrivPtr) data;
560 -    struct video_clip *clip;
561 +    struct v4l2_clip *clip;
562      BoxPtr pBox;
563      RegionRec newReg;
564      BoxRec    newBox;
565 @@ -291,179 +483,214 @@ V4lPutVideo(ScrnInfoPtr pScrn,
566  
567      /* Open a file handle to the device */
568      if (VIDEO_OFF == pPPriv->VideoOn) {
569 -       if (V4lOpenDevice(pPPriv, pScrn))
570 -           return Success;
571 +        if (V4lOpenDevice(pPPriv, pScrn))
572 +            return Success;
573      }
574  
575      if (0 != pPPriv->yuv_format) {
576 -       DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/PV yuv\n"));
577 -       width  = pPPriv->enc[pPPriv->cenc].width;
578 +        DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/PV yuv\n"));
579 +        width  = pPPriv->enc[pPPriv->cenc].width;
580          height = pPPriv->enc[pPPriv->cenc].height/2; /* no interlace */
581 -       if (drw_w < width)
582 -           width = drw_w;
583 -       if (drw_h < height)
584 -           height = drw_h;
585 -       if ((height != pPPriv->yuv_height) || (width != pPPriv->yuv_width)) {
586 -           /* new size -- free old surface */
587 -           DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "  surface resize\n"));
588 -           if (pPPriv->surface) {
589 -               pPPriv->VideoOn = VIDEO_OFF;
590 -               pPPriv->myfmt->stop(pPPriv->surface);
591 -               pPPriv->myfmt->free_surface(pPPriv->surface);
592 -               xfree(pPPriv->surface);
593 -               pPPriv->surface    = NULL;
594 -           }
595 -           pPPriv->yuv_width  = width;
596 -           pPPriv->yuv_height = height;
597 -       }
598 -       if (!pPPriv->surface) {
599 -           /* allocate + setup offscreen surface */
600 -           if (NULL == (pPPriv->surface = xalloc(sizeof(XF86SurfaceRec))))
601 -               return FALSE;
602 -           if (Success != pPPriv->myfmt->alloc_surface
603 -               (pScrn,pPPriv->myfmt->image->id,
604 -                pPPriv->yuv_width,pPPriv->yuv_height,pPPriv->surface)) {
605 -               xfree(pPPriv->surface);
606 -               pPPriv->surface = NULL;
607 -               goto fallback_to_rgb;
608 -           }
609 -           pPPriv->yuv_fbuf.width        = pPPriv->surface->width;
610 -           pPPriv->yuv_fbuf.height       = pPPriv->surface->height;
611 -           pPPriv->yuv_fbuf.depth        = 16;
612 -           pPPriv->yuv_fbuf.bytesperline = pPPriv->surface->pitches[0];
613 -           pPPriv->yuv_fbuf.base         =
614 -               (pointer)(pScrn->memPhysBase + pPPriv->surface->offsets[0]);
615 -           DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "  surface: %p+%d = %p, %dx%d, pitch %d\n",
616 -                                pScrn->memPhysBase,pPPriv->surface->offsets[0],
617 -                                pScrn->memPhysBase+pPPriv->surface->offsets[0],
618 -                                pPPriv->surface->width,pPPriv->surface->height,
619 -                                pPPriv->surface->pitches[0]));
620 -           pPPriv->yuv_win.width         = pPPriv->surface->width;
621 -           pPPriv->yuv_win.height        = pPPriv->surface->height;
622 -       }
623 +        if (drw_w < width)
624 +            width = drw_w;
625 +        if (drw_h < height)
626 +            height = drw_h;
627 +        if ((height != pPPriv->yuv_height) || (width != pPPriv->yuv_width)) {
628 +            /* new size -- free old surface */
629 +            DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "  surface resize\n"));
630 +            if (pPPriv->surface) {
631 +                pPPriv->VideoOn = VIDEO_OFF;
632 +                pPPriv->myfmt->stop(pPPriv->surface);
633 +                pPPriv->myfmt->free_surface(pPPriv->surface);
634 +                free(pPPriv->surface);
635 +                pPPriv->surface    = NULL;
636 +            }
637 +            pPPriv->yuv_width  = width;
638 +            pPPriv->yuv_height = height;
639 +        }
640 +        if (!pPPriv->surface) {
641 +            /* allocate + setup offscreen surface */
642 +            if (NULL == (pPPriv->surface = malloc(sizeof(XF86SurfaceRec))))
643 +                return FALSE;
644 +            if (Success != pPPriv->myfmt->alloc_surface
645 +                (pScrn,pPPriv->myfmt->image->id,
646 +                pPPriv->yuv_width,pPPriv->yuv_height,pPPriv->surface)) {
647 +                free(pPPriv->surface);
648 +                pPPriv->surface = NULL;
649 +                goto fallback_to_rgb;
650 +            }
651  
652 -       /* program driver */
653 -       if (-1 == ioctl(V4L_FD,VIDIOCSFBUF,&(pPPriv->yuv_fbuf)))
654 -           perror("ioctl VIDIOCSFBUF");
655 -       if (-1 == ioctl(V4L_FD,VIDIOCGPICT,&pPPriv->pict))
656 -           perror("ioctl VIDIOCGPICT");
657 -       pPPriv->pict.palette = pPPriv->yuv_format;
658 -       pPPriv->pict.depth   = 16;
659 -       if (-1 == ioctl(V4L_FD,VIDIOCSPICT,&pPPriv->pict))
660 -           perror("ioctl VIDIOCSPICT");
661 -       if (-1 == ioctl(V4L_FD,VIDIOCSWIN,&(pPPriv->yuv_win)))
662 -           perror("ioctl VIDIOCSWIN");
663 -       if (-1 == ioctl(V4L_FD, VIDIOCCAPTURE, &one))
664 -           perror("ioctl VIDIOCCAPTURE(1)");
665 +            if (-1 == ioctl(V4L_FD, VIDIOC_G_FBUF, &pPPriv->yuv_fbuf)) {
666 +                xf86Msg(X_ERROR, "v4l: Error %d: Can't get FBUF\n", errno);
667 +                return errno;
668 +            }
669 +            pPPriv->yuv_fbuf.fmt.width        = pPPriv->surface->width;
670 +            pPPriv->yuv_fbuf.fmt.height       = pPPriv->surface->height;
671 +            pPPriv->yuv_fbuf.fmt.bytesperline = pPPriv->surface->pitches[0];
672 +            pPPriv->yuv_fbuf.fmt.pixelformat = pPPriv->yuv_format;
673 +            pPPriv->yuv_fbuf.base         =
674 +                (pointer)(pScrn->memPhysBase + pPPriv->surface->offsets[0]);
675 +            DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
676 +                                 "  surface: %p+%d = %p, %dx%d, pitch %d\n",
677 +                                (void *)pScrn->memPhysBase, pPPriv->surface->offsets[0],
678 +                                (void *)pScrn->memPhysBase+pPPriv->surface->offsets[0],
679 +                                pPPriv->surface->width, pPPriv->surface->height,
680 +                                pPPriv->surface->pitches[0]));
681 +            memset(&pPPriv->yuv_win, 0, sizeof(pPPriv->yuv_win));
682 +            pPPriv->yuv_win.w.left    = 0;
683 +            pPPriv->yuv_win.w.top     = 0;
684 +            pPPriv->yuv_win.w.width  = pPPriv->surface->width;
685 +            pPPriv->yuv_win.w.height = pPPriv->surface->height;
686 +        }
687  
688 -       if (0 == (pPPriv->myfmt->flags & VIDEO_INVERT_CLIPLIST)) {
689 -           /* invert cliplist */
690 -           newBox.x1 = drw_x;
691 -           newBox.y1 = drw_y;
692 -           newBox.x2 = drw_x + drw_w;
693 -           newBox.y2 = drw_y + drw_h;
694 +        /* program driver */
695 +        if (-1 == ioctl(V4L_FD, VIDIOC_S_FBUF, &pPPriv->yuv_fbuf)) {
696 +            xf86Msg(X_ERROR, "Error %d at VIDIOC_S_FBUF\n", errno);
697 +            return BadValue;
698 +        }
699 +        pPPriv->pixelformat = pPPriv->yuv_format;
700 +        if (-1 == SetV4LFmt(V4L_FD, pPPriv->pixelformat))
701 +            return BadValue;
702  
703 -           if (pPPriv->myfmt->flags & VIDEO_CLIP_TO_VIEWPORT) {
704 -               /* trim to the viewport */
705 -               if(newBox.x1 < pScrn->frameX0)
706 -                   newBox.x1 = pScrn->frameX0;
707 -               if(newBox.x2 > pScrn->frameX1)
708 -                   newBox.x2 = pScrn->frameX1;
709 -               
710 -               if(newBox.y1 < pScrn->frameY0)
711 -                   newBox.y1 = pScrn->frameY0;
712 -               if(newBox.y2 > pScrn->frameY1)
713 -                   newBox.y2 = pScrn->frameY1;
714 -           }
715 +        memset(&fmt, 0, sizeof(fmt));
716 +        fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
717 +        memcpy(&fmt.fmt.win, &pPPriv->yuv_win, sizeof(pPPriv->yuv_win));
718 +        if (-1 == ioctl(V4L_FD, VIDIOC_S_FMT, &fmt)) {
719 +            xf86Msg(X_ERROR, "Error %d at VIDIOC_S_FMT\n", errno);
720 +            return BadValue;
721 +        }
722 +        if (-1 == ioctl(V4L_FD, VIDIOC_OVERLAY, &one)) {
723 +            xf86Msg(X_ERROR, "v4l: Error %d while enabling Overlay\n", errno);
724 +            return BadValue;
725 +        }
726  
727 -           REGION_INIT(pScrn->pScreen, &newReg, &newBox, 1);
728 -           REGION_SUBTRACT(pScrn->pScreen, &newReg, &newReg, clipBoxes);
729 -           clipBoxes = &newReg;
730 -       }
731 -       
732 -       /* start overlay */
733 -       DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
734 -                            "over: - %d,%d -> %d,%d  (%dx%d) (yuv=%dx%d)\n",
735 -                            drw_x, drw_y,
736 -                            drw_x+drw_w, drw_y+drw_h,
737 -                            drw_w, drw_h,
738 -                            pPPriv->surface->width,pPPriv->surface->height));
739 -       pPPriv->myfmt->display(pPPriv->surface,
740 -                              0, 0, drw_x, drw_y,
741 -                              pPPriv->surface->width,
742 -                              pPPriv->surface->height,
743 -                              drw_w, drw_h,
744 -                              clipBoxes);
745 -       if (0 == (pPPriv->myfmt->flags & VIDEO_INVERT_CLIPLIST)) {
746 -           REGION_UNINIT(pScrn->pScreen, &newReg); 
747 -       }
748 -       pPPriv->VideoOn = VIDEO_YUV;
749 -       return Success;
750 +        if (0 == (pPPriv->myfmt->flags & VIDEO_INVERT_CLIPLIST)) {
751 +            /* invert cliplist */
752 +            newBox.x1 = drw_x;
753 +            newBox.y1 = drw_y;
754 +            newBox.x2 = drw_x + drw_w;
755 +            newBox.y2 = drw_y + drw_h;
756 +
757 +            if (pPPriv->myfmt->flags & VIDEO_CLIP_TO_VIEWPORT) {
758 +                /* trim to the viewport */
759 +                if(newBox.x1 < pScrn->frameX0)
760 +                    newBox.x1 = pScrn->frameX0;
761 +                if(newBox.x2 > pScrn->frameX1)
762 +                    newBox.x2 = pScrn->frameX1;
763 +
764 +                if(newBox.y1 < pScrn->frameY0)
765 +                    newBox.y1 = pScrn->frameY0;
766 +                if(newBox.y2 > pScrn->frameY1)
767 +                    newBox.y2 = pScrn->frameY1;
768 +            }
769 +
770 +            REGION_INIT(pScrn->pScreen, &newReg, &newBox, 1);
771 +            REGION_SUBTRACT(pScrn->pScreen, &newReg, &newReg, clipBoxes);
772 +            clipBoxes = &newReg;
773 +        }
774 +
775 +        /* start overlay */
776 +        DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
777 +                             "over: - %d,%d -> %d,%d  (%dx%d) (yuv=%dx%d)\n",
778 +                             drw_x, drw_y,
779 +                             drw_x+drw_w, drw_y+drw_h,
780 +                             drw_w, drw_h,
781 +                             pPPriv->surface->width,pPPriv->surface->height));
782 +        pPPriv->myfmt->display(pPPriv->surface,
783 +                               0, 0, drw_x, drw_y,
784 +                               pPPriv->surface->width,
785 +                               pPPriv->surface->height,
786 +                               drw_w, drw_h,
787 +                               clipBoxes);
788 +        if (0 == (pPPriv->myfmt->flags & VIDEO_INVERT_CLIPLIST)) {
789 +            REGION_UNINIT(pScrn->pScreen, &newReg);
790 +        }
791 +        pPPriv->VideoOn = VIDEO_YUV;
792 +        return Success;
793      }
794  
795 - fallback_to_rgb:
796 +fallback_to_rgb:
797      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/PV rgb\n"));
798      /* FIXME: vid-* is ignored for now, not supported by v4l */
799  
800      dw = (drw_w < pPPriv->enc[pPPriv->cenc].width) ?
801 -       drw_w : pPPriv->enc[pPPriv->cenc].width;
802 +        drw_w : pPPriv->enc[pPPriv->cenc].width;
803      dh = (drw_h < pPPriv->enc[pPPriv->cenc].height) ?
804 -       drw_h : pPPriv->enc[pPPriv->cenc].height;
805 +        drw_h : pPPriv->enc[pPPriv->cenc].height;
806      /* if the window is too big, center the video */
807      dx = drw_x + (drw_w - dw)/2;
808      dy = drw_y + (drw_h - dh)/2;
809      /* bttv prefeares aligned addresses */
810      dx &= ~3;
811 -    if (dx < drw_x) dx += 4;
812 -    if (dx+dw > drw_x+drw_w) dw -= 4;
813 +    if (dx < drw_x)
814 +        dx += 4;
815 +    if (dx+dw > drw_x+drw_w)
816 +        dw -= 4;
817  
818      /* window */
819      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "  win: %dx%d+%d+%d\n",
820 -               drw_w,drw_h,drw_x,drw_y));
821 +                         drw_w,drw_h,drw_x,drw_y));
822      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "  use: %dx%d+%d+%d\n",
823 -               dw,dh,dx,dy));
824 -    pPPriv->rgb_win.x      = dx;
825 -    pPPriv->rgb_win.y      = dy;
826 -    pPPriv->rgb_win.width  = dw;
827 -    pPPriv->rgb_win.height = dh;
828 -    pPPriv->rgb_win.flags  = 0;
829
830 +                         dw,dh,dx,dy));
831 +    memset(&pPPriv->rgb_win, 0, sizeof(pPPriv->rgb_win));
832 +    pPPriv->rgb_win.w.left   = dx;
833 +    pPPriv->rgb_win.w.top    = dy;
834 +    pPPriv->rgb_win.w.width  = dw;
835 +    pPPriv->rgb_win.w.height = dh;
836 +
837      /* clipping */
838      if (pPPriv->rgb_win.clips) {
839 -       xfree(pPPriv->rgb_win.clips);
840 -       pPPriv->rgb_win.clips = NULL;
841 +        free(pPPriv->rgb_win.clips);
842 +        pPPriv->rgb_win.clips = NULL;
843      }
844      pPPriv->rgb_win.clipcount = REGION_NUM_RECTS(clipBoxes);
845      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,"  clip: have #%d\n",
846 -               pPPriv->rgb_win.clipcount));
847 +                         pPPriv->rgb_win.clipcount));
848      if (0 != pPPriv->rgb_win.clipcount) {
849 -       pPPriv->rgb_win.clips = xalloc(pPPriv->rgb_win.clipcount*sizeof(struct video_clip));
850 -       if (NULL != pPPriv->rgb_win.clips) {
851 -           memset(pPPriv->rgb_win.clips,0,pPPriv->rgb_win.clipcount*sizeof(struct video_clip));
852 -           pBox = REGION_RECTS(clipBoxes);
853 -           clip = pPPriv->rgb_win.clips;
854 -           for (i = 0; i < REGION_NUM_RECTS(clipBoxes); i++, pBox++, clip++) {
855 -               clip->x  = pBox->x1 - dx;
856 -               clip->y      = pBox->y1 - dy;
857 -               clip->width  = pBox->x2 - pBox->x1;
858 -               clip->height = pBox->y2 - pBox->y1;
859 -           }
860 -       }
861 +        pPPriv->rgb_win.clips = malloc(pPPriv->rgb_win.clipcount*sizeof(struct v4l2_clip));
862 +        if (NULL != pPPriv->rgb_win.clips) {
863 +            memset(pPPriv->rgb_win.clips,0,pPPriv->rgb_win.clipcount*sizeof(struct v4l2_clip));
864 +            pBox = REGION_RECTS(clipBoxes);
865 +            clip = pPPriv->rgb_win.clips;
866 +
867 +            /*
868 +             * FIXME: This code currently does nothing, as we don't emulate
869 +             * The V4L1 clipping stuff
870 +             */
871 +            for (i = 0; i < REGION_NUM_RECTS(clipBoxes); i++, pBox++, clip++) {
872 +                clip->c.left   = pBox->x1 - dx;
873 +                clip->c.top    = pBox->y1 - dy;
874 +                clip->c.width  = pBox->x2 - pBox->x1;
875 +                clip->c.height = pBox->y2 - pBox->y1;
876 +            }
877 +        }
878      }
879  
880      /* start */
881 -    if (-1 == ioctl(V4L_FD,VIDIOCSFBUF,&(pPPriv->rgb_fbuf)))
882 -       perror("ioctl VIDIOCSFBUF");
883 -    if (-1 == ioctl(V4L_FD,VIDIOCGPICT,&pPPriv->pict))
884 -       perror("ioctl VIDIOCGPICT");
885 -    pPPriv->pict.palette = pPPriv->rgbpalette;
886 -    pPPriv->pict.depth   = pPPriv->rgbdepth;
887 -    if (-1 == ioctl(V4L_FD,VIDIOCSPICT,&pPPriv->pict))
888 -       perror("ioctl VIDIOCSPICT");
889 -    if (-1 == ioctl(V4L_FD,VIDIOCSWIN,&(pPPriv->rgb_win)))
890 -       perror("ioctl VIDIOCSWIN");
891 -    if (-1 == ioctl(V4L_FD, VIDIOCCAPTURE, &one))
892 -       perror("ioctl VIDIOCCAPTURE(1)");
893 +    if (-1 == ioctl(V4L_FD, VIDIOC_S_FBUF, &pPPriv->rgb_fbuf)) {
894 +        xf86Msg(X_ERROR, "Error %d at VIDIOC_S_FBUF\n", errno);
895 +        return BadValue;
896 +    }
897 +    if (-1 == GetV4LFmt(V4L_FD, &pPPriv->pixelformat)) {
898 +        xf86Msg(X_ERROR, "Error %d getting pixelformat\n", errno);
899 +        return BadValue;
900 +    }
901 +    pPPriv->pixelformat = pPPriv->rgb_fbuf.fmt.pixelformat;
902 +    if (-1 == SetV4LFmt(V4L_FD, pPPriv->pixelformat)) {
903 +        xf86Msg(X_ERROR, "Error %d getting pixelformat\n", errno);
904 +        return BadValue;
905 +    }
906 +    memset(&fmt, 0, sizeof(fmt));
907 +    fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
908 +    memcpy(&fmt.fmt.win, &pPPriv->rgb_win, sizeof(pPPriv->rgb_win));
909 +    if (-1 == ioctl(V4L_FD, VIDIOC_S_FMT, &fmt)) {
910 +        xf86Msg(X_ERROR, "Error %d at VIDIOC_S_FMT\n", errno);
911 +        return BadValue;
912 +    }
913 +    if (-1 == ioctl(V4L_FD, VIDIOC_OVERLAY, &one)) {
914 +        xf86Msg(X_ERROR, "v4l: Error %d while enabling Overlay\n", errno);
915 +        return BadValue;
916 +    }
917      pPPriv->VideoOn = VIDEO_RGB;
918  
919      return Success;
920 @@ -476,7 +703,7 @@ V4lPutStill(ScrnInfoPtr pScrn,
921      RegionPtr clipBoxes, pointer data, DrawablePtr pDraw)
922  {
923  #if 0
924 -    PortPrivPtr pPPriv = (PortPrivPtr) data;  
925 +    PortPrivPtr pPPriv = (PortPrivPtr) data;
926  #endif
927  
928      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/PS\n"));
929 @@ -488,177 +715,152 @@ V4lPutStill(ScrnInfoPtr pScrn,
930  static void
931  V4lStopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
932  {
933 -    PortPrivPtr pPPriv = (PortPrivPtr) data;  
934 +    PortPrivPtr pPPriv = (PortPrivPtr) data;
935      int zero=0;
936  
937      if (VIDEO_OFF == pPPriv->VideoOn) {
938 -       DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
939 -             "Xv/StopVideo called with video already off\n"));
940 -       return;
941 +        DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
942 +              "Xv/StopVideo called with video already off\n"));
943 +        return;
944      }
945      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/StopVideo shutdown=%d\n",shutdown));
946  
947      if (!shutdown) {
948 -       /* just reclipping, we have to stop DMA transfers to the visible screen */
949 -       if (VIDEO_RGB == pPPriv->VideoOn) {
950 -           if (-1 == ioctl(V4L_FD, VIDIOCCAPTURE, &zero))
951 -               perror("ioctl VIDIOCCAPTURE(0)");
952 -           pPPriv->VideoOn = VIDEO_RECLIP;
953 -       }
954 +        /* just reclipping, we have to stop DMA transfers to the visible screen */
955 +        if (VIDEO_RGB == pPPriv->VideoOn) {
956 +            if (-1 == ioctl(V4L_FD, VIDIOC_OVERLAY, &zero))
957 +                xf86Msg(X_ERROR, "v4l: Error %d while disabling Overlay\n", errno);
958 +            pPPriv->VideoOn = VIDEO_RECLIP;
959 +        }
960      } else {
961 -       /* video stop - turn off and free everything */
962 -       if (VIDEO_YUV == pPPriv->VideoOn) {
963 -           pPPriv->myfmt->stop(pPPriv->surface);
964 -           pPPriv->myfmt->free_surface(pPPriv->surface);
965 -           xfree(pPPriv->surface);
966 -           pPPriv->surface = NULL;
967 -       }
968 -       if (-1 == ioctl(V4L_FD, VIDIOCCAPTURE, &zero))
969 -           perror("ioctl VIDIOCCAPTURE(0)");
970 -       
971 -       V4lCloseDevice(pPPriv,pScrn);
972 -       pPPriv->VideoOn = VIDEO_OFF;
973 +        /* video stop - turn off and free everything */
974 +        if (VIDEO_YUV == pPPriv->VideoOn) {
975 +            pPPriv->myfmt->stop(pPPriv->surface);
976 +            pPPriv->myfmt->free_surface(pPPriv->surface);
977 +            free(pPPriv->surface);
978 +            pPPriv->surface = NULL;
979 +        }
980 +        if (-1 == ioctl(V4L_FD, VIDIOC_OVERLAY, &zero))
981 +            xf86Msg(X_ERROR, "v4l: Error %d while disabling Overlay\n", errno);
982 +
983 +        V4lCloseDevice(pPPriv,pScrn);
984 +        pPPriv->VideoOn = VIDEO_OFF;
985      }
986  }
987  
988 -/* v4l uses range 0 - 65535; Xv uses -1000 - 1000 */
989 -static int
990 -v4l_to_xv(int val) {
991 -    val = val * 2000 / 65536 - 1000;
992 -    if (val < -1000) val = -1000;
993 -    if (val >  1000) val =  1000;
994 -    return val;
995 -}
996 -static int
997 -xv_to_v4l(int val) {
998 -    val = val * 65536 / 2000 + 32768;
999 -    if (val <    -0) val =     0;
1000 -    if (val > 65535) val = 65535;
1001 -    return val;
1002 -}
1003 -
1004  static int
1005  V4lSetPortAttribute(ScrnInfoPtr pScrn,
1006      Atom attribute, INT32 value, pointer data)
1007  {
1008 -    PortPrivPtr pPPriv = (PortPrivPtr) data; 
1009 -    struct video_channel chan;
1010 -    int ret = Success;
1011 +    struct v4l2_control ctrl;
1012 +    PortPrivPtr pPPriv = (PortPrivPtr) data;
1013 +    int i, ret = BadValue;
1014  
1015      if (V4lOpenDevice(pPPriv, pScrn))
1016 -       return Success;
1017 +        return Success;
1018  
1019      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/SPA %d, %d\n",
1020 -                        attribute, value));
1021 +                        (int)attribute, (int)value));
1022  
1023      if (-1 == V4L_FD) {
1024 -       ret = Success;
1025 +        ret = Success;
1026      } else if (attribute == xvEncoding) {
1027 -       if (value >= 0 && value < pPPriv->nenc) {
1028 -           pPPriv->cenc = value;
1029 -           chan.channel = pPPriv->input[value];
1030 -           chan.norm    = pPPriv->norm[value];
1031 -           if (-1 == ioctl(V4L_FD,VIDIOCSCHAN,&chan))
1032 -               perror("ioctl VIDIOCSCHAN");
1033 -       } else {
1034 -           ret = BadValue;
1035 -       }
1036 -    } else if (attribute == xvBrightness ||
1037 -               attribute == xvContrast   ||
1038 -               attribute == xvSaturation ||
1039 -               attribute == xvHue) {
1040 -       ioctl(V4L_FD,VIDIOCGPICT,&pPPriv->pict);
1041 -       if (attribute == xvBrightness) pPPriv->pict.brightness = xv_to_v4l(value);
1042 -       if (attribute == xvContrast)   pPPriv->pict.contrast   = xv_to_v4l(value);
1043 -       if (attribute == xvSaturation) pPPriv->pict.colour     = xv_to_v4l(value);
1044 -       if (attribute == xvHue)        pPPriv->pict.hue        = xv_to_v4l(value);
1045 -       if (-1 == ioctl(V4L_FD,VIDIOCSPICT,&pPPriv->pict))
1046 -           perror("ioctl VIDIOCSPICT");
1047 -    } else if (attribute == xvMute ||
1048 -              attribute == xvVolume) {
1049 -       ioctl(V4L_FD,VIDIOCGAUDIO,&pPPriv->audio);
1050 -       if (attribute == xvMute) {
1051 -           if (value)
1052 -               pPPriv->audio.flags |= VIDEO_AUDIO_MUTE;
1053 -           else
1054 -               pPPriv->audio.flags &= ~VIDEO_AUDIO_MUTE;
1055 -       } else if (attribute == xvVolume) {
1056 -           if (pPPriv->audio.flags & VIDEO_AUDIO_VOLUME)
1057 -               pPPriv->audio.volume = xv_to_v4l(value);
1058 -       } else {
1059 -           ret = BadValue;
1060 -       }
1061 -       if (ret != BadValue)
1062 -           if (-1 == ioctl(V4L_FD,VIDIOCSAUDIO,&pPPriv->audio))
1063 -               perror("ioctl VIDIOCSAUDIO");
1064 +        if (value < 0 || value >= pPPriv->nenc)
1065 +            goto err;
1066 +        if (ioctl(V4L_FD, VIDIOC_S_INPUT, &pPPriv->input[value]) == -1) {
1067 +            xf86Msg(X_ERROR, "v4l: Error %d while setting input\n", errno);
1068 +            goto err;
1069 +        }
1070 +        if (ioctl(V4L_FD, VIDIOC_S_STD, &pPPriv->norm[value]) == -1) {
1071 +            xf86Msg(X_ERROR, "v4l: Error %d while setting standard\n", errno);
1072 +            goto err;
1073 +        }
1074 +        pPPriv->cenc = value;
1075 +        ret = Success;
1076      } else if (attribute == xvFreq) {
1077 -       unsigned long freq = value;
1078 -       if (-1 == ioctl(V4L_FD,VIDIOCSFREQ,&freq))
1079 -           perror("ioctl VIDIOCSFREQ");
1080 -    } else if (0 != pPPriv->yuv_format &&
1081 -              pPPriv->myfmt->setAttribute) {
1082 -       /* not mine -> pass to yuv scaler driver */
1083 -       ret = pPPriv->myfmt->setAttribute(pScrn, attribute, value);
1084 +        struct v4l2_frequency   freq;
1085 +        memset(&freq, 0, sizeof(freq));
1086 +        ioctl(V4L_FD, VIDIOC_G_FREQUENCY, &freq);
1087 +        freq.frequency = value;
1088 +        if (ioctl(V4L_FD, VIDIOC_S_FREQUENCY, &freq) == -1)
1089 +            xf86Msg(X_ERROR, "v4l: Error %d while setting frequency\n", errno);
1090 +        else
1091 +            ret = Success;
1092      } else {
1093 -       ret = BadValue;
1094 +        for (i = 0; i < pPPriv->n_qctrl; i++)
1095 +            if (pPPriv->XvV4LCtrl[i].xv == attribute)
1096 +                break;
1097 +        if (i == pPPriv->n_qctrl) {
1098 +            /* not mine -> pass to yuv scaler driver */
1099 +            if (0 != pPPriv->yuv_format && pPPriv->myfmt->setAttribute)
1100 +                ret = pPPriv->myfmt->setAttribute(pScrn, attribute, value);
1101 +            else
1102 +                ret = BadMatch;
1103 +            goto err;
1104 +        }
1105 +        if (pPPriv->XvV4LCtrl[i].qctrl.flags & V4L2_CTRL_FLAG_DISABLED)
1106 +            goto err;
1107 +        ctrl.id = pPPriv->XvV4LCtrl[i].qctrl.id;
1108 +        ctrl.value = value;
1109 +        if (ioctl(V4L_FD, VIDIOC_S_CTRL, &ctrl) != 1)
1110 +            ret = Success;
1111      }
1112  
1113 +err:
1114      V4lCloseDevice(pPPriv,pScrn);
1115      return ret;
1116  }
1117  
1118  static int
1119 -V4lGetPortAttribute(ScrnInfoPtr pScrn, 
1120 +V4lGetPortAttribute(ScrnInfoPtr pScrn,
1121      Atom attribute, INT32 *value, pointer data)
1122  {
1123 +    struct v4l2_control ctrl;
1124      PortPrivPtr pPPriv = (PortPrivPtr) data;
1125 -    int ret = Success;
1126 +    int i, ret = BadValue;
1127  
1128      if (V4lOpenDevice(pPPriv, pScrn))
1129 -       return Success;
1130 +        return Success;
1131  
1132      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/GPA %d\n",
1133 -                        attribute));
1134 +                        (int)attribute));
1135  
1136      if (-1 == V4L_FD) {
1137 -       ret = Success;
1138 +        ret = Success;
1139      } else if (attribute == xvEncoding) {
1140 -       *value = pPPriv->cenc;
1141 -    } else if (attribute == xvBrightness ||
1142 -               attribute == xvContrast   ||
1143 -               attribute == xvSaturation ||
1144 -               attribute == xvHue) {
1145 -       ioctl(V4L_FD,VIDIOCGPICT,&pPPriv->pict);
1146 -       if (attribute == xvBrightness) *value = v4l_to_xv(pPPriv->pict.brightness);
1147 -       if (attribute == xvContrast)   *value = v4l_to_xv(pPPriv->pict.contrast);
1148 -       if (attribute == xvSaturation) *value = v4l_to_xv(pPPriv->pict.colour);
1149 -       if (attribute == xvHue)        *value = v4l_to_xv(pPPriv->pict.hue);
1150 -    } else if (attribute == xvMute ||
1151 -              attribute == xvVolume) {
1152 -       ioctl(V4L_FD,VIDIOCGAUDIO,&pPPriv->audio);
1153 -       if (attribute == xvMute) {
1154 -           *value = (pPPriv->audio.flags & VIDEO_AUDIO_MUTE) ? 1 : 0;
1155 -       } else if (attribute == xvVolume) {
1156 -           if (pPPriv->audio.flags & VIDEO_AUDIO_VOLUME)
1157 -               *value = v4l_to_xv(pPPriv->audio.volume);
1158 -       } else {
1159 -           ret = BadValue;
1160 -       }
1161 +        *value = pPPriv->cenc;
1162 +        ret = Success;
1163      } else if (attribute == xvFreq) {
1164 -       unsigned long freq;
1165 -       ioctl(V4L_FD,VIDIOCGFREQ,&freq);
1166 -       *value = freq;
1167 -    } else if (0 != pPPriv->yuv_format &&
1168 -              pPPriv->myfmt->getAttribute) {
1169 -       /* not mine -> pass to yuv scaler driver */
1170 -       ret = pPPriv->myfmt->getAttribute(pScrn, attribute, value);
1171 +        struct v4l2_frequency   freq;
1172 +        memset(&freq, 0, sizeof(freq));
1173 +        if (ioctl(V4L_FD, VIDIOC_G_FREQUENCY, &freq) != -1) {
1174 +            *value = freq.frequency;
1175 +            ret = Success;
1176 +        }
1177      } else {
1178 -       ret = BadValue;
1179 +        for (i = 0; i < pPPriv->n_qctrl; i++)
1180 +            if (pPPriv->XvV4LCtrl[i].xv == attribute)
1181 +                break;
1182 +        if (i == pPPriv->n_qctrl) {
1183 +            /* not mine -> pass to yuv scaler driver */
1184 +            if (0 != pPPriv->yuv_format &&  pPPriv->myfmt->getAttribute)
1185 +                ret = pPPriv->myfmt->getAttribute(pScrn, attribute, value);
1186 +            else
1187 +                ret = BadMatch;
1188 +            goto err;
1189 +        }
1190 +        if (pPPriv->XvV4LCtrl[i].qctrl.flags & V4L2_CTRL_FLAG_DISABLED)
1191 +            goto err;
1192 +        ctrl.id = pPPriv->XvV4LCtrl[i].qctrl.id;
1193 +        if (ioctl(V4L_FD, VIDIOC_G_CTRL, &ctrl) != -1) {
1194 +            *value = ctrl.value;
1195 +            ret = Success;
1196 +        }
1197      }
1198 +    DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/GPA %d, %d\n",
1199 +        (int)attribute, (int)*value));
1200  
1201 -    DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/GPA %d, %d\n",
1202 -       attribute, *value));
1203 -
1204 +err:
1205      V4lCloseDevice(pPPriv,pScrn);
1206      return ret;
1207  }
1208 @@ -673,15 +875,15 @@ V4lQueryBestSize(ScrnInfoPtr pScrn, Bool
1209      int maxy = pPPriv->enc[pPPriv->cenc].height;
1210  
1211      if (0 != pPPriv->yuv_format) {
1212 -       *p_w = pPPriv->myfmt->max_width;
1213 -       *p_h = pPPriv->myfmt->max_height;
1214 +        *p_w = pPPriv->myfmt->max_width;
1215 +        *p_h = pPPriv->myfmt->max_height;
1216      } else {
1217 -       *p_w = (drw_w < maxx) ? drw_w : maxx;
1218 -       *p_h = (drw_h < maxy) ? drw_h : maxy;
1219 +        *p_w = (drw_w < maxx) ? drw_w : maxx;
1220 +        *p_h = (drw_h < maxy) ? drw_h : maxy;
1221      }
1222  
1223      DEBUG(xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "Xv/BS %d %dx%d %dx%d\n",
1224 -                        pPPriv->cenc,drw_w,drw_h,*p_w,*p_h));
1225 +                         pPPriv->cenc,drw_w,drw_h,*p_w,*p_h));
1226  }
1227  
1228  static const OptionInfoRec *
1229 @@ -693,132 +895,198 @@ V4LAvailableOptions(int chipid, int busi
1230  static void
1231  V4LIdentify(int flags)
1232  {
1233 -    xf86Msg(X_INFO, "v4l driver for Video4Linux\n");
1234 -}        
1235 +    xf86Msg(X_INFO, "v4l driver for Video4Linux overlay mode (V4L2)\n");
1236 +}
1237  
1238  static char*
1239  fixname(char *str)
1240  {
1241      int s,d;
1242      for (s=0, d=0;; s++) {
1243 -       if (str[s] == '-')
1244 -           continue;
1245 -       str[d++] = tolower(str[s]);
1246 -       if (0 == str[s])
1247 -           break;
1248 +        if (str[s] == '-')
1249 +            continue;
1250 +        str[d++] = tolower(str[s]);
1251 +        if (0 == str[s])
1252 +            break;
1253      }
1254      return str;
1255  }
1256  
1257  static int
1258 -v4l_add_enc(XF86VideoEncodingPtr enc, int i,
1259 -           char *norm, char *input, int width, int height, int n, int d)
1260 +AddV4LEnc(XF86VideoEncodingPtr enc, int entry,
1261 +            char *norm, char *input, int width, int height, int n, int d)
1262  {
1263 -    enc[i].id     = i;
1264 -    enc[i].name   = xalloc(strlen(norm)+strlen(input)+2);
1265 -    if (NULL == enc[i].name)
1266 -       return -1;
1267 -    enc[i].width  = width;
1268 -    enc[i].height = height;
1269 -    enc[i].rate.numerator   = n;
1270 -    enc[i].rate.denominator = d;
1271 -    sprintf(enc[i].name,"%s-%s",norm,fixname(input));
1272 +    enc->id     = entry;
1273 +    enc->name   = malloc(strlen(norm) + strlen(input) + 2);
1274 +    if (!enc->name)
1275 +        return -1;
1276 +
1277 +    enc->width  = width;
1278 +    enc->height = height;
1279 +    enc->rate.numerator   = n;
1280 +    enc->rate.denominator = d * 2; /* Refresh rate is twice, due to interlace */
1281 +    sprintf(enc->name,"%s-%s",norm,fixname(input));
1282 +
1283 +    xf86Msg(X_INFO, "v4l: adding input %s, %dx%d %d fps\n",
1284 +            enc->name, enc->width, enc->height, (d + n - 1)/n);
1285 +
1286      return 0;
1287  }
1288  
1289 +static int
1290 +V4LGetStd(PortPrivPtr p, int fd)
1291 +{
1292 +    struct v4l2_standard standard;
1293 +    int entries = 0;
1294 +
1295 +    /*
1296 +     * 128 is just an arbitrary large number. There aren't that many video stds
1297 +     * The max value is there just to avoid an endless loop, if the driver is
1298 +     * broken.
1299 +     */
1300 +    for (entries = 0; entries < 128; entries++) {
1301 +        memset(&standard, 0, sizeof(standard));
1302 +        standard.index = entries;
1303 +        if (-1 == ioctl(fd,VIDIOC_ENUMSTD, &standard))
1304 +            break;
1305 +        p->standard = realloc(p->standard, sizeof(standard) * (entries + 1));
1306 +        memcpy(&p->standard[entries], &standard, sizeof(standard));
1307 +    }
1308 +
1309 +    /*
1310 +     * Some webcam drivers don't implement VIDIOC_ENUMSTD. Fake it
1311 +     * This is currently unused, as no webcam driver allows OVERLAY mode,
1312 +     * but the code is here, in the case some webcam driver starts allowing
1313 +     * overlay.
1314 +     * FIXME: Webcam drivers may use VIDIOC_ENUM_FRAMESIZES and
1315 +     * VIDIOC_ENUM_FRAMEINTERVALS ioctl's that may help to fine-tune
1316 +     * their needs. Those ioctl's could be used here in order to better
1317 +     * support webcams.
1318 +     */
1319 +    if (!entries) {
1320 +        xf86Msg(X_INFO, "v4l: VIDIOC_ENUMSTD error %d.\n",errno);
1321 +        p->standard = realloc(p->standard, sizeof(standard) * (entries + 1));
1322 +        p->standard[0].id = V4L2_STD_ALL;
1323 +        strcpy((char *)p->standard[0].name, "CAMERA");
1324 +        p->standard[0].frameperiod.numerator = 1001;
1325 +        p->standard[0].frameperiod.denominator = 300001;
1326 +        p->standard[0].framelines = 480;
1327 +        entries++;
1328 +    }
1329 +    return entries;
1330 +}
1331 +
1332  static void
1333 -V4LBuildEncodings(PortPrivPtr p, int fd, int channels)
1334 +V4LBuildEncodings(PortPrivPtr p, int fd)
1335  {
1336 -    static struct video_channel     channel;
1337 -    int i,entries,have_bttv,bttv_ver;
1338 +    unsigned int inp, std, num_std;
1339  
1340 -#define BTTV_VERSION _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
1341 -    have_bttv = 0;
1342 -    if (-1 != ioctl(fd,BTTV_VERSION,&bttv_ver))
1343 -       have_bttv = 1;
1344 -       
1345 -    entries = (have_bttv ? 7 : 3) * channels;
1346 -    p->enc = xalloc(sizeof(XF86VideoEncodingRec) * entries);
1347 -    if (NULL == p->enc)
1348 -       goto fail;
1349 -    memset(p->enc,0,sizeof(XF86VideoEncodingRec) * entries);
1350 -    p->norm = xalloc(sizeof(int) * entries);
1351 -    if (NULL == p->norm)
1352 -       goto fail;
1353 -    memset(p->norm,0,sizeof(int) * entries);
1354 -    p->input = xalloc(sizeof(int) * entries);
1355 -    if (NULL == p->input)
1356 -       goto fail;
1357 -    memset(p->input,0,sizeof(int) * entries);
1358 +    num_std =  V4LGetStd(p, fd);
1359  
1360      p->nenc = 0;
1361 -    for (i = 0; i < channels; i++) {
1362 -       channel.channel = i;
1363 -       if (-1 == ioctl(fd,VIDIOCGCHAN,&channel)) {
1364 -           perror("ioctl VIDIOCGCHAN");
1365 -           continue;
1366 -       }
1367 -       
1368 -       v4l_add_enc(p->enc, p->nenc,"PAL", channel.name, 768,576, 1,50);
1369 -       p->norm[p->nenc]  = VIDEO_MODE_PAL;
1370 -       p->input[p->nenc] = i;
1371 -       p->nenc++;
1372 -       
1373 -       v4l_add_enc(p->enc,p->nenc,"NTSC", channel.name, 640,480, 1001,60000);
1374 -       p->norm[p->nenc]  = VIDEO_MODE_NTSC;
1375 -       p->input[p->nenc] = i;
1376 -       p->nenc++;
1377 -       
1378 -       v4l_add_enc(p->enc,p->nenc,"SECAM",channel.name, 768,576, 1,50);
1379 -       p->norm[p->nenc]  = VIDEO_MODE_SECAM;
1380 -       p->input[p->nenc] = i;
1381 -       p->nenc++;
1382  
1383 -       if (have_bttv) {
1384 -           /* workaround for a v4l design flaw:  The v4l API knows just pal,
1385 -              ntsc and secam.  But there are a few more norms (pal versions
1386 -              with a different timings used in south america for example).
1387 -              The bttv driver can handle these too. */
1388 -           if (0 != v4l_add_enc(p->enc,p->nenc,"PAL-Nc",channel.name,
1389 -                                640, 576, 1,50))
1390 -               goto fail;
1391 -           p->norm[p->nenc]  = 3;
1392 -           p->input[p->nenc] = i;
1393 -           p->nenc++;
1394 +    /*
1395 +     * 256 is just an arbitrary large number. There aren't that many video
1396 +     * inputs on any driver. The max value is there just to avoid an endless
1397 +     * loop, if the driver is broken.
1398 +     */
1399 +    for (inp = 0; inp < 256; inp++) {
1400 +        struct v4l2_input       input;
1401  
1402 -           if (0 != v4l_add_enc(p->enc,p->nenc,"PAL-M",channel.name,
1403 -                                640, 576, 1,50))
1404 -               goto fail;
1405 -           p->norm[p->nenc]  = 4;
1406 -           p->input[p->nenc] = i;
1407 -           p->nenc++;
1408 +        memset(&input, 0, sizeof(input));
1409 +        input.index = inp;
1410 +        if (ioctl(fd, VIDIOC_ENUMINPUT, &input) == -1)
1411 +            break;
1412  
1413 -           if (0 != v4l_add_enc(p->enc, p->nenc,"PAL-N", channel.name,
1414 -                                768,576, 1,50))
1415 -               goto fail;
1416 -           p->norm[p->nenc]  = 5;
1417 -           p->input[p->nenc] = i;
1418 -           p->nenc++;
1419 -           
1420 -           if (0 != v4l_add_enc(p->enc,p->nenc,"NTSC-JP", channel.name,
1421 -                                640,480, 1001,60000))
1422 -               goto fail;
1423 -           p->norm[p->nenc]  = 6;
1424 -           p->input[p->nenc] = i;
1425 -           p->nenc++;
1426 -       }
1427 +        for (std = 0; std < num_std; std++) {
1428 +            int width, height;
1429 +
1430 +           /*
1431 +            * Currently, this code is not reliable, due to driver
1432 +            * non-compliance on both saa7134 and bttv. So, instead,
1433 +            * just use the video standard information
1434 +            */
1435 +#if 0
1436 +           struct v4l2_framebuffer fbuf;
1437 +
1438 +            /* Some webcam drivers will fail here, but that's OK */
1439 +            ioctl(fd, VIDIOC_S_STD, &p->standard[std].id);
1440 +
1441 +            memset(&fbuf, 0, sizeof(fbuf));
1442 +            if (ioctl(fd, VIDIOC_G_FBUF, &fbuf) == -1) {
1443 +                xf86Msg(X_INFO, "v4l: Error %d: Can't get FBUF\n", errno);
1444 +                return;
1445 +            }
1446 +            height = fbuf.fmt.height;
1447 +            width = fbuf.fmt.width;
1448 +
1449 +            /*
1450 +             * If the overlay method fails, get the resolution
1451 +             * via checking V4L2_BUF_TYPE_VIDEO_CAPTURE
1452 +             */
1453 +            if (!height || !width) {
1454 +                struct v4l2_format format;
1455 +
1456 +                format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1457 +                if (ioctl(fd, VIDIOC_G_FMT, &format) == -1) {
1458 +                    /* Hmm... device doesn't support capture. */
1459 +                    height = p->standard[std].framelines;
1460 +                    if (height == 480)
1461 +                        width = 640;
1462 +                    else if (height == 576)
1463 +                        width = 768;
1464 +                    else
1465 +                        continue;
1466 +                } else {
1467 +                    height = format.fmt.pix.height;
1468 +                    width = format.fmt.pix.width;
1469 +                }
1470 +            }
1471 +#else
1472 +           if (p->standard[std].id & V4L2_STD_525_60) {
1473 +               height = 480;
1474 +               width = 640;
1475 +           } else {
1476 +               height = 576;
1477 +               width = 768;
1478 +           }
1479 +
1480 +#endif
1481 +            /* Fixup for some driver bug */
1482 +            if ((p->standard[std].id & V4L2_STD_525_60) && (height == 576))
1483 +                height = 480;
1484 +
1485 +            p->enc = realloc(p->enc, sizeof(XF86VideoEncodingRec) * (p->nenc + 1));
1486 +            p->norm = realloc(p->norm, sizeof(int) * (p->nenc + 1));
1487 +            p->input = realloc(p->input, sizeof(int) * (p->nenc + 1));
1488 +            if (!p->enc || !p->norm || !p->input)
1489 +                goto fail;
1490 +            if (AddV4LEnc(&p->enc[p->nenc], p->nenc,
1491 +                          (char *)p->standard[std].name,
1492 +                          (char *)input.name, width, height,
1493 +                          p->standard[std].frameperiod.numerator,
1494 +                          p->standard[std].frameperiod.denominator))
1495 +                goto fail;
1496 +            p->norm[p->nenc]  = p->standard[std].id;
1497 +            p->input[p->nenc] = inp;
1498 +            p->nenc++;
1499 +        }
1500      }
1501 +
1502 +    if (!p->nenc)
1503 +        xf86Msg(X_ERROR, "v4l: couldn't detect any valid input/standard\n");
1504      return;
1505 -    
1506 - fail:
1507 +
1508 +fail:
1509 +    xf86Msg(X_ERROR, "v4l: Fail to get standards: %d\n", errno);
1510      if (p->input)
1511 -       xfree(p->input);
1512 +        free(p->input);
1513      p->input = NULL;
1514      if (p->norm)
1515 -       xfree(p->norm);
1516 +        free(p->norm);
1517      p->norm = NULL;
1518      if (p->enc)
1519 -       xfree(p->enc);
1520 +        free(p->enc);
1521      p->enc = NULL;
1522      p->nenc = 0;
1523  }
1524 @@ -826,75 +1094,35 @@ V4LBuildEncodings(PortPrivPtr p, int fd,
1525  /* add a attribute a list */
1526  static void
1527  v4l_add_attr(XF86AttributeRec **list, int *count,
1528 -            const XF86AttributeRec *attr)
1529 +             const XF86AttributeRec *attr)
1530  {
1531      XF86AttributeRec *oldlist = *list;
1532      int i;
1533 +    Atom gpa;
1534  
1535      for (i = 0; i < *count; i++) {
1536 -       if (0 == strcmp((*list)[i].name,attr->name)) {
1537 -           DEBUG(xf86Msg(X_INFO, "v4l: skip dup attr %s\n",attr->name));
1538 -           return;
1539 -       }
1540 +        if (0 == strcmp((*list)[i].name,attr->name)) {
1541 +            DEBUG(xf86Msg(X_INFO, "v4l: skip dup attr %s\n",attr->name));
1542 +            return;
1543 +        }
1544      }
1545 -    
1546 -    DEBUG(xf86Msg(X_INFO, "v4l: add attr %s\n",attr->name));
1547 -    *list = xalloc((*count + 1) * sizeof(XF86AttributeRec));
1548 +
1549 +    *list = malloc((*count + 1) * sizeof(XF86AttributeRec));
1550      if (NULL == *list) {
1551 -       *count = 0;
1552 -       return;
1553 +        *count = 0;
1554 +        return;
1555      }
1556      if (*count)
1557 -       memcpy(*list, oldlist, *count * sizeof(XF86AttributeRec));
1558 +        memcpy(*list, oldlist, *count * sizeof(XF86AttributeRec));
1559      memcpy(*list + *count, attr, sizeof(XF86AttributeRec));
1560 +
1561 +    gpa = MAKE_ATOM((*list)[*count].name);
1562 +    xf86Msg(X_INFO, "v4l: add attr %s (Xv/GPA %d) (%d to %d)\n",
1563 +            attr->name, (int)gpa, attr->min_value, attr->max_value);
1564 +
1565      (*count)++;
1566  }
1567  
1568 -/* setup yuv overlay + hw scaling: look if we find some common video
1569 -   format which both v4l driver and the X-Server can handle */
1570 -static void v4l_check_yuv(ScrnInfoPtr pScrn, PortPrivPtr pPPriv,
1571 -                         char *dev, int fd)
1572 -{
1573 -    static const struct {
1574 -       unsigned int  v4l_palette;
1575 -       unsigned int  v4l_depth;
1576 -       unsigned int  xv_id;
1577 -       unsigned int  xv_format;
1578 -    } yuvlist[] = {
1579 -       { VIDEO_PALETTE_YUV422, 16, 0x32595559, XvPacked },
1580 -       { VIDEO_PALETTE_UYVY,   16, 0x59565955, XvPacked },
1581 -       { 0 /* end of list */ },
1582 -    };
1583 -    ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
1584 -    int fmt,i;
1585 -
1586 -    pPPriv->format = xf86XVQueryOffscreenImages(pScreen,&pPPriv->nformat);
1587 -    for (fmt = 0; yuvlist[fmt].v4l_palette != 0; fmt++) {
1588 -       /* check v4l ... */
1589 -       ioctl(fd,VIDIOCGPICT,&pPPriv->pict);
1590 -       pPPriv->pict.palette = yuvlist[fmt].v4l_palette;
1591 -       pPPriv->pict.depth   = yuvlist[fmt].v4l_depth;
1592 -       if (-1 == ioctl(fd,VIDIOCSPICT,&pPPriv->pict))
1593 -           continue;
1594 -       ioctl(fd,VIDIOCGPICT,&pPPriv->pict);
1595 -       if (pPPriv->pict.palette != yuvlist[fmt].v4l_palette)
1596 -           continue;
1597 -       /* ... works, check available offscreen image formats now ... */
1598 -       for (i = 0; i < pPPriv->nformat; i++) {
1599 -           if (pPPriv->format[i].image->id     == yuvlist[fmt].xv_id &&
1600 -               pPPriv->format[i].image->format == yuvlist[fmt].xv_format) {
1601 -               /* ... match found, good. */
1602 -               pPPriv->yuv_format = yuvlist[fmt].v4l_palette;
1603 -               pPPriv->myfmt = pPPriv->format+i;
1604 -               xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1605 -                          "v4l[%s]: using hw video scaling [%4.4s].\n",
1606 -                          dev,(char*)&(pPPriv->format[i].image->id));
1607 -               return;
1608 -           }
1609 -       }
1610 -    }
1611 -}
1612 -
1613  static int
1614  V4LInit(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr **adaptors)
1615  {
1616 @@ -904,118 +1132,114 @@ V4LInit(ScrnInfoPtr pScrn, XF86VideoAdap
1617      char dev[18];
1618      int  fd,i,j,d;
1619  
1620 -    DEBUG(xf86Msg(X_INFO, "v4l: init start\n"));
1621 +    for (i = 0, d = 0; d < MAX_V4L_DEVICES; d++) {
1622 +        sprintf(dev, "/dev/video%d", d);
1623 +        fd = open(dev, O_RDWR, 0);
1624 +        if (fd == -1) {
1625 +            sprintf(dev, "/dev/v4l/video%d", d);
1626 +            fd = open(dev, O_RDWR, 0);
1627 +            if (fd == -1)
1628 +                break;
1629 +        }
1630 +        DEBUG(xf86Msg(X_INFO,  "v4l: %s open ok\n",dev));
1631  
1632 -    for (i = 0, d = 0; d < MAX_V4L_DEVICES; d++) {
1633 -       sprintf(dev, "/dev/video%d", d);
1634 -       fd = open(dev, O_RDWR, 0);
1635 -       if (fd == -1) {
1636 -           sprintf(dev, "/dev/v4l/video%d", d);
1637 -           fd = open(dev, O_RDWR, 0);
1638 -           if (fd == -1)
1639 -               break;
1640 -       }
1641 -       DEBUG(xf86Msg(X_INFO,  "v4l: %s open ok\n",dev));
1642 +        /* our private data */
1643 +        pPPriv = malloc(sizeof(PortPrivRec));
1644 +        if (!pPPriv)
1645 +            return FALSE;
1646 +        memset(pPPriv,0,sizeof(PortPrivRec));
1647 +        pPPriv->nr = d;
1648  
1649 -       /* our private data */
1650 -       pPPriv = xalloc(sizeof(PortPrivRec));
1651 -       if (!pPPriv)
1652 -           return FALSE;
1653 -       memset(pPPriv,0,sizeof(PortPrivRec));
1654 -       pPPriv->nr = d;
1655 +        /* check device capabilities */
1656 +        memset(&pPPriv->cap, 0, sizeof(&pPPriv->cap));
1657 +        if (-1 == ioctl(fd, VIDIOC_QUERYCAP, &pPPriv->cap) ||
1658 +            0 == (pPPriv->cap.capabilities & V4L2_CAP_VIDEO_OVERLAY)) {
1659 +            xf86Msg(X_ERROR, "v4l: %s: no overlay support\n",dev);
1660 +            free(pPPriv);
1661 +            close(fd);
1662 +            continue;
1663 +        }
1664  
1665 -       /* check device */
1666 -       if (-1 == ioctl(fd,VIDIOCGCAP,&pPPriv->cap) ||
1667 -           0 == (pPPriv->cap.type & VID_TYPE_OVERLAY)) {
1668 -           DEBUG(xf86Msg(X_INFO,  "v4l: %s: no overlay support\n",dev));
1669 -           xfree(pPPriv);
1670 -           close(fd);
1671 -           continue;
1672 -       }
1673 -       strncpy(V4L_NAME, dev, 16);
1674 -       V4LBuildEncodings(pPPriv,fd,pPPriv->cap.channels);
1675 -       if (NULL == pPPriv->enc)
1676 -           return FALSE;
1677 -       v4l_check_yuv(pScrn,pPPriv,dev,fd);
1678 -       
1679 -       /* alloc VideoAdaptorRec */
1680 -       VAR = xrealloc(VAR,sizeof(XF86VideoAdaptorPtr)*(i+1));
1681 -       VAR[i] = xalloc(sizeof(XF86VideoAdaptorRec));
1682 -       if (!VAR[i])
1683 -           return FALSE;
1684 -       memset(VAR[i],0,sizeof(XF86VideoAdaptorRec));
1685 +        if (v4l_check_yuv(pScrn, pPPriv, dev, fd) == FALSE) {
1686 +                xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2,
1687 +                               "Xv Overlay not supported. Can't use v4l driver\n");
1688 +                free(pPPriv);
1689 +                close(fd);
1690 +                continue;
1691 +        }
1692  
1693 +        xf86Msg(X_INFO, "v4l: enabling overlay mode for %s.\n", dev);
1694 +        strncpy(V4L_NAME, dev, 16);
1695 +        V4LBuildEncodings(pPPriv, fd);
1696 +        if (NULL == pPPriv->enc)
1697 +            return FALSE;
1698  
1699 -       /* build attribute list */
1700 -       for (j = 0; j < V4L_ATTR; j++) {
1701 -           /* video attributes */
1702 -           v4l_add_attr(&VAR[i]->pAttributes, &VAR[i]->nAttributes,
1703 -                        &Attributes[j]);
1704 -       }
1705 -       if (0 == ioctl(fd,VIDIOCGAUDIO,&pPPriv->audio)) {
1706 -           /* audio attributes */
1707 -           if (pPPriv->audio.flags & VIDEO_AUDIO_VOLUME)
1708 -               v4l_add_attr(&VAR[i]->pAttributes, &VAR[i]->nAttributes,
1709 -                            &VolumeAttr);
1710 -           if (pPPriv->audio.flags & VIDEO_AUDIO_MUTABLE)
1711 -               v4l_add_attr(&VAR[i]->pAttributes, &VAR[i]->nAttributes,
1712 -                            &MuteAttr);
1713 -       }
1714 -       if (pPPriv->cap.type & VID_TYPE_TUNER) {
1715 -           /* tuner attributes */
1716 -           v4l_add_attr(&VAR[i]->pAttributes, &VAR[i]->nAttributes,
1717 -                        &FreqAttr);
1718 -       }
1719 -       if (0 != pPPriv->yuv_format) {
1720 -           /* pass throuth scaler attributes */
1721 -           for (j = 0; j < pPPriv->myfmt->num_attributes; j++) {
1722 -               v4l_add_attr(&VAR[i]->pAttributes, &VAR[i]->nAttributes,
1723 -                            pPPriv->myfmt->attributes+j);
1724 -           }
1725 -       }
1726 -       
1727 -       
1728 -       /* hook in private data */
1729 -       Private = xalloc(sizeof(DevUnion));
1730 -       if (!Private)
1731 -           return FALSE;
1732 -       memset(Private,0,sizeof(DevUnion));
1733 -       Private->ptr = (pointer)pPPriv;
1734 -       VAR[i]->pPortPrivates = Private;
1735 -       VAR[i]->nPorts = 1;
1736 +        /* alloc VideoAdaptorRec */
1737 +        VAR = realloc(VAR,sizeof(XF86VideoAdaptorPtr)*(i+1));
1738 +        VAR[i] = malloc(sizeof(XF86VideoAdaptorRec));
1739 +        if (!VAR[i])
1740 +            return FALSE;
1741 +        memset(VAR[i],0,sizeof(XF86VideoAdaptorRec));
1742  
1743 -       /* init VideoAdaptorRec */
1744 -       VAR[i]->type  = XvInputMask | XvWindowMask | XvVideoMask;
1745 -       VAR[i]->name  = "video4linux";
1746 -       VAR[i]->flags = VIDEO_INVERT_CLIPLIST;
1747 +        /* build attribute list */
1748 +        AddAllV4LControls(pPPriv, &VAR[i]->pAttributes, &VAR[i]->nAttributes, fd);
1749  
1750 -       VAR[i]->PutVideo = V4lPutVideo;
1751 -       VAR[i]->PutStill = V4lPutStill;
1752 -       VAR[i]->StopVideo = V4lStopVideo;
1753 -       VAR[i]->SetPortAttribute = V4lSetPortAttribute;
1754 -       VAR[i]->GetPortAttribute = V4lGetPortAttribute;
1755 -       VAR[i]->QueryBestSize = V4lQueryBestSize;
1756 +        for (j = 0; j < V4L_ATTR; j++) {
1757 +            /* Other video attributes */
1758 +            v4l_add_attr(&VAR[i]->pAttributes, &VAR[i]->nAttributes,
1759 +                         &Attributes[j]);
1760 +        }
1761 +        if (pPPriv->cap.capabilities & V4L2_CAP_TUNER) {
1762 +            /* tuner attributes */
1763 +            v4l_add_attr(&VAR[i]->pAttributes, &VAR[i]->nAttributes,
1764 +                         &FreqAttr);
1765 +        }
1766  
1767 -       VAR[i]->nEncodings = pPPriv->nenc;
1768 -       VAR[i]->pEncodings = pPPriv->enc;
1769 -       VAR[i]->nFormats =
1770 -               sizeof(InputVideoFormats) / sizeof(InputVideoFormats[0]);
1771 -       VAR[i]->pFormats = InputVideoFormats;
1772 +        /* Initialize yuv_format */
1773 +        if (0 != pPPriv->yuv_format) {
1774 +            /* pass throuth scaler attributes */
1775 +            for (j = 0; j < pPPriv->myfmt->num_attributes; j++) {
1776 +                v4l_add_attr(&VAR[i]->pAttributes, &VAR[i]->nAttributes,
1777 +                             pPPriv->myfmt->attributes+j);
1778 +            }
1779 +        }
1780  
1781 -       if (fd != -1)
1782 -           close(fd);
1783 -       i++;
1784 +        DEBUG(xf86Msg(X_INFO, "v4l: saving config into driver data\n"));
1785 +        /* hook in private data */
1786 +        Private = malloc(sizeof(DevUnion));
1787 +        if (!Private)
1788 +            return FALSE;
1789 +        memset(Private,0,sizeof(DevUnion));
1790 +        Private->ptr = (pointer)pPPriv;
1791 +        VAR[i]->pPortPrivates = Private;
1792 +        VAR[i]->nPorts = 1;
1793 +
1794 +        /* init VideoAdaptorRec */
1795 +        VAR[i]->type  = XvInputMask | XvWindowMask | XvVideoMask;
1796 +        VAR[i]->name  = "video4linux";
1797 +        VAR[i]->flags = VIDEO_INVERT_CLIPLIST;
1798 +
1799 +        VAR[i]->PutVideo = V4lPutVideo;
1800 +        VAR[i]->PutStill = V4lPutStill;
1801 +        VAR[i]->StopVideo = V4lStopVideo;
1802 +        VAR[i]->SetPortAttribute = V4lSetPortAttribute;
1803 +        VAR[i]->GetPortAttribute = V4lGetPortAttribute;
1804 +        VAR[i]->QueryBestSize = V4lQueryBestSize;
1805 +
1806 +        VAR[i]->nEncodings = pPPriv->nenc;
1807 +        VAR[i]->pEncodings = pPPriv->enc;
1808 +        VAR[i]->nFormats = sizeof(InputVideoFormats) / sizeof(InputVideoFormats[0]);
1809 +        VAR[i]->pFormats = InputVideoFormats;
1810 +
1811 +        if (fd != -1) {
1812 +            DEBUG(xf86Msg(X_INFO,  "v4l: %s init finished.\n",dev));
1813 +            close(fd);
1814 +        }
1815 +        i++;
1816      }
1817  
1818      xvEncoding   = MAKE_ATOM(XV_ENCODING);
1819 -    xvHue        = MAKE_ATOM(XV_HUE);
1820 -    xvSaturation = MAKE_ATOM(XV_SATURATION);
1821 -    xvBrightness = MAKE_ATOM(XV_BRIGHTNESS);
1822 -    xvContrast   = MAKE_ATOM(XV_CONTRAST);
1823 -
1824      xvFreq       = MAKE_ATOM(XV_FREQ);
1825 -    xvMute       = MAKE_ATOM(XV_MUTE);
1826 -    xvVolume     = MAKE_ATOM(XV_VOLUME);
1827  
1828      DEBUG(xf86Msg(X_INFO, "v4l: init done, %d device(s) found\n",i));
1829  
1830 @@ -1024,10 +1248,43 @@ V4LInit(ScrnInfoPtr pScrn, XF86VideoAdap
1831  }
1832  
1833  static Bool
1834 +V4LDetect(void)
1835 +{
1836 +    struct v4l2_capability cap;
1837 +    int fd, d, n = 0;
1838 +    char dev[18];
1839 +
1840 +    for (d = 0; d < MAX_V4L_DEVICES; d++) {
1841 +        sprintf(dev, "/dev/video%d", d);
1842 +        fd = open(dev, O_RDWR, 0);
1843 +        if (fd == -1) {
1844 +            sprintf(dev, "/dev/v4l/video%d", d);
1845 +            fd = open(dev, O_RDWR, 0);
1846 +            if (fd == -1)
1847 +                break;
1848 +        }
1849 +        close (fd);
1850 +        memset(&cap, 0, sizeof(cap));
1851 +        if (!ioctl(fd, VIDIOC_QUERYCAP, &cap) &&
1852 +            (cap.capabilities & V4L2_CAP_VIDEO_OVERLAY))
1853 +            n++;
1854 +    }
1855 +    xf86Msg(X_INFO, "v4l: %d video adapters with overlay support detected\n", n);
1856 +
1857 +    return (n > 0) ? TRUE : FALSE;
1858 +}
1859 +
1860 +static Bool
1861  V4LProbe(DriverPtr drv, int flags)
1862  {
1863 -    if (flags & PROBE_DETECT)
1864 -       return TRUE;
1865 +    /*
1866 +     * Don't try to register adapter at the detection phase, as Xv
1867 +     * extensions won't be there
1868 +     */
1869 +    if (flags == PROBE_DETECT)
1870 +        return V4LDetect();
1871 +
1872 +    DEBUG(xf86Msg(X_INFO, "v4l: Initiating device probe\n"));
1873  
1874      xf86XVRegisterGenericAdaptorDriver(V4LInit);
1875      drv->refCount++;
1876 diff --git a/src/videodev.h b/src/videodev.h
1877 deleted file mode 100644
1878 --- a/src/videodev.h
1879 +++ /dev/null
1880 @@ -1,254 +0,0 @@
1881 -#ifndef __LINUX_VIDEODEV_H
1882 -#define __LINUX_VIDEODEV_H
1883 -
1884 -/* Linux V4L API, Version 1
1885 - * videodev.h from v4l driver in Linux 2.2.3 
1886 - *
1887 - * Used here with the explicit permission of the original author, Alan Cox.
1888 - *                             <alan@lxorguk.ukuu.org.uk>
1889 - */
1890 -
1891 -#include <X11/Xmd.h>
1892 -
1893 -#define VID_TYPE_CAPTURE       1       /* Can capture */
1894 -#define VID_TYPE_TUNER         2       /* Can tune */
1895 -#define VID_TYPE_TELETEXT      4       /* Does teletext */
1896 -#define VID_TYPE_OVERLAY       8       /* Overlay onto frame buffer */
1897 -#define VID_TYPE_CHROMAKEY     16      /* Overlay by chromakey */
1898 -#define VID_TYPE_CLIPPING      32      /* Can clip */
1899 -#define VID_TYPE_FRAMERAM      64      /* Uses the frame buffer memory */
1900 -#define VID_TYPE_SCALES                128     /* Scalable */
1901 -#define VID_TYPE_MONOCHROME    256     /* Monochrome only */
1902 -#define VID_TYPE_SUBCAPTURE    512     /* Can capture subareas of the image */
1903 -
1904 -struct video_capability
1905 -{
1906 -       char name[32];
1907 -       int type;
1908 -       int channels;   /* Num channels */
1909 -       int audios;     /* Num audio devices */
1910 -       int maxwidth;   /* Supported width */
1911 -       int maxheight;  /* And height */
1912 -       int minwidth;   /* Supported width */
1913 -       int minheight;  /* And height */
1914 -};
1915 -
1916 -
1917 -struct video_channel
1918 -{
1919 -       int channel;
1920 -       char name[32];
1921 -       int tuners;
1922 -       CARD32  flags;
1923 -#define VIDEO_VC_TUNER         1       /* Channel has a tuner */
1924 -#define VIDEO_VC_AUDIO         2       /* Channel has audio */
1925 -       CARD16  type;
1926 -#define VIDEO_TYPE_TV          1
1927 -#define VIDEO_TYPE_CAMERA      2       
1928 -       CARD16 norm;                    /* Norm set by channel */
1929 -};
1930 -
1931 -struct video_tuner
1932 -{
1933 -       int tuner;
1934 -       char name[32];
1935 -       unsigned long rangelow, rangehigh;      /* Tuner range */
1936 -       CARD32 flags;
1937 -#define VIDEO_TUNER_PAL                1
1938 -#define VIDEO_TUNER_NTSC       2
1939 -#define VIDEO_TUNER_SECAM      4
1940 -#define VIDEO_TUNER_LOW                8       /* Uses KHz not MHz */
1941 -#define VIDEO_TUNER_NORM       16      /* Tuner can set norm */
1942 -#define VIDEO_TUNER_STEREO_ON  128     /* Tuner is seeing stereo */
1943 -       CARD16 mode;                    /* PAL/NTSC/SECAM/OTHER */
1944 -#define VIDEO_MODE_PAL         0
1945 -#define VIDEO_MODE_NTSC                1
1946 -#define VIDEO_MODE_SECAM       2
1947 -#define VIDEO_MODE_AUTO                3
1948 -       CARD16 signal;                  /* Signal strength 16bit scale */
1949 -};
1950 -
1951 -struct video_picture
1952 -{
1953 -       CARD16  brightness;
1954 -       CARD16  hue;
1955 -       CARD16  colour;
1956 -       CARD16  contrast;
1957 -       CARD16  whiteness;      /* Black and white only */
1958 -       CARD16  depth;          /* Capture depth */
1959 -       CARD16   palette;       /* Palette in use */
1960 -#define VIDEO_PALETTE_GREY     1       /* Linear greyscale */
1961 -#define VIDEO_PALETTE_HI240    2       /* High 240 cube (BT848) */
1962 -#define VIDEO_PALETTE_RGB565   3       /* 565 16 bit RGB */
1963 -#define VIDEO_PALETTE_RGB24    4       /* 24bit RGB */
1964 -#define VIDEO_PALETTE_RGB32    5       /* 32bit RGB */ 
1965 -#define VIDEO_PALETTE_RGB555   6       /* 555 15bit RGB */
1966 -#define VIDEO_PALETTE_YUV422   7       /* YUV422 capture */
1967 -#define VIDEO_PALETTE_YUYV     8
1968 -#define VIDEO_PALETTE_UYVY     9       /* The great thing about standards is ... */
1969 -#define VIDEO_PALETTE_YUV420   10
1970 -#define VIDEO_PALETTE_YUV411   11      /* YUV411 capture */
1971 -#define VIDEO_PALETTE_RAW      12      /* RAW capture (BT848) */
1972 -#define VIDEO_PALETTE_YUV422P  13      /* YUV 4:2:2 Planar */
1973 -#define VIDEO_PALETTE_YUV411P  14      /* YUV 4:1:1 Planar */
1974 -#define VIDEO_PALETTE_YUV420P  15      /* YUV 4:2:0 Planar */
1975 -#define VIDEO_PALETTE_YUV410P  16      /* YUV 4:1:0 Planar */
1976 -#define VIDEO_PALETTE_PLANAR   13      /* start of planar entries */
1977 -#define VIDEO_PALETTE_COMPONENT 7      /* start of component entries */
1978 -};
1979 -
1980 -struct video_audio
1981 -{
1982 -       int     audio;          /* Audio channel */
1983 -       CARD16  volume;         /* If settable */
1984 -       CARD16  bass, treble;
1985 -       CARD32  flags;
1986 -#define VIDEO_AUDIO_MUTE       1
1987 -#define VIDEO_AUDIO_MUTABLE    2
1988 -#define VIDEO_AUDIO_VOLUME     4
1989 -#define VIDEO_AUDIO_BASS       8
1990 -#define VIDEO_AUDIO_TREBLE     16      
1991 -       char    name[16];
1992 -#define VIDEO_SOUND_MONO       1
1993 -#define VIDEO_SOUND_STEREO     2
1994 -#define VIDEO_SOUND_LANG1      4
1995 -#define VIDEO_SOUND_LANG2      8
1996 -        CARD16   mode;
1997 -        CARD16 balance;        /* Stereo balance */
1998 -        CARD16 step;           /* Step actual volume uses */
1999 -};
2000 -
2001 -struct video_clip
2002 -{
2003 -       INT32   x,y;
2004 -       INT32   width, height;
2005 -       struct  video_clip *next;       /* For user use/driver use only */
2006 -};
2007 -
2008 -struct video_window
2009 -{
2010 -       CARD32  x,y;                    /* Position of window */
2011 -       CARD32  width,height;           /* Its size */
2012 -       CARD32  chromakey;
2013 -       CARD32  flags;
2014 -       struct  video_clip *clips;      /* Set only */
2015 -       int     clipcount;
2016 -#define VIDEO_WINDOW_INTERLACE 1
2017 -#define VIDEO_CLIP_BITMAP      -1
2018 -/* bitmap is 1024x625, a '1' bit represents a clipped pixel */
2019 -#define VIDEO_CLIPMAP_SIZE     (128 * 625)
2020 -};
2021 -
2022 -struct video_capture
2023 -{
2024 -       CARD32  x,y;                    /* Offsets into image */
2025 -       CARD32  width, height;          /* Area to capture */
2026 -       CARD16  decimation;             /* Decimation divder */
2027 -       CARD16  flags;                  /* Flags for capture */
2028 -#define VIDEO_CAPTURE_ODD              0       /* Temporal */
2029 -#define VIDEO_CAPTURE_EVEN             1
2030 -};
2031 -
2032 -struct video_buffer
2033 -{
2034 -       void    *base;
2035 -       int     height,width;
2036 -       int     depth;
2037 -       int     bytesperline;
2038 -};
2039 -
2040 -struct video_mmap
2041 -{
2042 -       unsigned        int frame;              /* Frame (0 - n) for double buffer */
2043 -       int             height,width;
2044 -       unsigned        int format;             /* should be VIDEO_PALETTE_* */
2045 -};
2046 -
2047 -struct video_key
2048 -{
2049 -       CARD8   key[8];
2050 -       CARD32  flags;
2051 -};
2052 -
2053 -
2054 -#define VIDEO_MAX_FRAME                32
2055 -
2056 -struct video_mbuf
2057 -{
2058 -       int     size;           /* Total memory to map */
2059 -       int     frames;         /* Frames */
2060 -       int     offsets[VIDEO_MAX_FRAME];
2061 -};
2062 -       
2063 -
2064 -#define        VIDEO_NO_UNIT   (-1)
2065 -
2066 -       
2067 -struct video_unit
2068 -{
2069 -       int     video;          /* Video minor */
2070 -       int     vbi;            /* VBI minor */
2071 -       int     radio;          /* Radio minor */
2072 -       int     audio;          /* Audio minor */
2073 -       int     teletext;       /* Teletext minor */
2074 -};
2075 -
2076 -#define VIDIOCGCAP             _IOR('v',1,struct video_capability)     /* Get capabilities */
2077 -#define VIDIOCGCHAN            _IOWR('v',2,struct video_channel)       /* Get channel info (sources) */
2078 -#define VIDIOCSCHAN            _IOW('v',3,struct video_channel)        /* Set channel  */
2079 -#define VIDIOCGTUNER           _IOWR('v',4,struct video_tuner)         /* Get tuner abilities */
2080 -#define VIDIOCSTUNER           _IOW('v',5,struct video_tuner)          /* Tune the tuner for the current channel */
2081 -#define VIDIOCGPICT            _IOR('v',6,struct video_picture)        /* Get picture properties */
2082 -#define VIDIOCSPICT            _IOW('v',7,struct video_picture)        /* Set picture properties */
2083 -#define VIDIOCCAPTURE          _IOW('v',8,int)                         /* Start, end capture */
2084 -#define VIDIOCGWIN             _IOR('v',9, struct video_window)        /* Set the video overlay window */
2085 -#define VIDIOCSWIN             _IOW('v',10, struct video_window)       /* Set the video overlay window - passes clip list for hardware smarts , chromakey etc */
2086 -#define VIDIOCGFBUF            _IOR('v',11, struct video_buffer)       /* Get frame buffer */
2087 -#define VIDIOCSFBUF            _IOW('v',12, struct video_buffer)       /* Set frame buffer - root only */
2088 -#define VIDIOCKEY              _IOR('v',13, struct video_key)          /* Video key event - to dev 255 is to all - cuts capture on all DMA windows with this key (0xFFFFFFFF == all) */
2089 -#define VIDIOCGFREQ            _IOR('v',14, unsigned long)             /* Set tuner */
2090 -#define VIDIOCSFREQ            _IOW('v',15, unsigned long)             /* Set tuner */
2091 -#define VIDIOCGAUDIO           _IOR('v',16, struct video_audio)        /* Get audio info */
2092 -#define VIDIOCSAUDIO           _IOW('v',17, struct video_audio)        /* Audio source, mute etc */
2093 -#define VIDIOCSYNC             _IOW('v',18, int)                       /* Sync with mmap grabbing */
2094 -#define VIDIOCMCAPTURE         _IOW('v',19, struct video_mmap)         /* Grab frames */
2095 -#define VIDIOCGMBUF            _IOR('v', 20, struct video_mbuf)        /* Memory map buffer info */
2096 -#define VIDIOCGUNIT            _IOR('v', 21, struct video_unit)        /* Get attached units */
2097 -#define VIDIOCGCAPTURE         _IOR('v',22, struct video_capture)      /* Get frame buffer */
2098 -#define VIDIOCSCAPTURE         _IOW('v',23, struct video_capture)      /* Set frame buffer - root only */
2099 -
2100 -#define BASE_VIDIOCPRIVATE     192             /* 192-255 are private */
2101 -
2102 -
2103 -#define VID_HARDWARE_BT848     1
2104 -#define VID_HARDWARE_QCAM_BW   2
2105 -#define VID_HARDWARE_PMS       3
2106 -#define VID_HARDWARE_QCAM_C    4
2107 -#define VID_HARDWARE_PSEUDO    5
2108 -#define VID_HARDWARE_SAA5249   6
2109 -#define VID_HARDWARE_AZTECH    7
2110 -#define VID_HARDWARE_SF16MI    8
2111 -#define VID_HARDWARE_RTRACK    9
2112 -#define VID_HARDWARE_ZOLTRIX   10
2113 -#define VID_HARDWARE_SAA7146    11
2114 -#define VID_HARDWARE_VIDEUM    12      /* Reserved for Winnov videum */
2115 -#define VID_HARDWARE_RTRACK2   13
2116 -#define VID_HARDWARE_PERMEDIA2 14      /* Reserved for Permedia2 */
2117 -#define VID_HARDWARE_RIVA128   15      /* Reserved for RIVA 128 */
2118 -#define VID_HARDWARE_PLANB     16      /* PowerMac motherboard video-in */
2119 -#define VID_HARDWARE_BROADWAY  17      /* Broadway project */
2120 -#define VID_HARDWARE_GEMTEK    18
2121 -#define VID_HARDWARE_TYPHOON   19
2122 -#define VID_HARDWARE_VINO      20      /* Reserved for SGI Indy Vino */
2123 -
2124 -/*
2125 - *     Initialiser list
2126 - */
2127
2128 -struct video_init
2129 -{
2130 -       char *name;
2131 -       int (*init)(struct video_init *);
2132 -};
2133 -
2134 -#endif
2135 diff --git a/src/videodev2.h b/src/videodev2.h
2136 new file mode 100644
2137 --- /dev/null
2138 +++ b/src/videodev2.h
2139 @@ -0,0 +1,1929 @@
2140 +/*
2141 + *  Video for Linux Two header file
2142 + *
2143 + *  Copyright (C) 1999-2007 the contributors
2144 + *
2145 + *  This program is free software; you can redistribute it and/or modify
2146 + *  it under the terms of the GNU General Public License as published by
2147 + *  the Free Software Foundation; either version 2 of the License, or
2148 + *  (at your option) any later version.
2149 + *
2150 + *  This program is distributed in the hope that it will be useful,
2151 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
2152 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2153 + *  GNU General Public License for more details.
2154 + *
2155 + *  Alternatively you can redistribute this file under the terms of the
2156 + *  BSD license as stated below:
2157 + *
2158 + *  Redistribution and use in source and binary forms, with or without
2159 + *  modification, are permitted provided that the following conditions
2160 + *  are met:
2161 + *  1. Redistributions of source code must retain the above copyright
2162 + *     notice, this list of conditions and the following disclaimer.
2163 + *  2. Redistributions in binary form must reproduce the above copyright
2164 + *     notice, this list of conditions and the following disclaimer in
2165 + *     the documentation and/or other materials provided with the
2166 + *     distribution.
2167 + *  3. The names of its contributors may not be used to endorse or promote
2168 + *     products derived from this software without specific prior written
2169 + *     permission.
2170 + *
2171 + *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2172 + *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2173 + *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2174 + *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2175 + *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2176 + *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
2177 + *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2178 + *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2179 + *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2180 + *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2181 + *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2182 + *
2183 + *     Header file for v4l or V4L2 drivers and applications
2184 + * with public API.
2185 + * All kernel-specific stuff were moved to media/v4l2-dev.h, so
2186 + * no #if __KERNEL tests are allowed here
2187 + *
2188 + *     See http://linuxtv.org for more info
2189 + *
2190 + *     Author: Bill Dirks <bill@thedirks.org>
2191 + *             Justin Schoeman
2192 + *              Hans Verkuil <hverkuil@xs4all.nl>
2193 + *             et al.
2194 + */
2195 +#ifndef __LINUX_VIDEODEV2_H
2196 +#define __LINUX_VIDEODEV2_H
2197 +
2198 +#include <linux/ioctl.h>
2199 +#include <linux/types.h>
2200 +#include <sys/time.h>
2201 +
2202 +/*
2203 + * Common stuff for both V4L1 and V4L2
2204 + * Moved from videodev.h
2205 + */
2206 +#define VIDEO_MAX_FRAME               32
2207 +#define VIDEO_MAX_PLANES               8
2208 +
2209 +/* These defines are V4L1 specific and should not be used with the V4L2 API!
2210 +   They will be removed from this header in the future. */
2211 +
2212 +#define VID_TYPE_CAPTURE       1       /* Can capture */
2213 +#define VID_TYPE_TUNER         2       /* Can tune */
2214 +#define VID_TYPE_TELETEXT      4       /* Does teletext */
2215 +#define VID_TYPE_OVERLAY       8       /* Overlay onto frame buffer */
2216 +#define VID_TYPE_CHROMAKEY     16      /* Overlay by chromakey */
2217 +#define VID_TYPE_CLIPPING      32      /* Can clip */
2218 +#define VID_TYPE_FRAMERAM      64      /* Uses the frame buffer memory */
2219 +#define VID_TYPE_SCALES                128     /* Scalable */
2220 +#define VID_TYPE_MONOCHROME    256     /* Monochrome only */
2221 +#define VID_TYPE_SUBCAPTURE    512     /* Can capture subareas of the image */
2222 +#define VID_TYPE_MPEG_DECODER  1024    /* Can decode MPEG streams */
2223 +#define VID_TYPE_MPEG_ENCODER  2048    /* Can encode MPEG streams */
2224 +#define VID_TYPE_MJPEG_DECODER 4096    /* Can decode MJPEG streams */
2225 +#define VID_TYPE_MJPEG_ENCODER 8192    /* Can encode MJPEG streams */
2226 +
2227 +/*
2228 + *     M I S C E L L A N E O U S
2229 + */
2230 +
2231 +/*  Four-character-code (FOURCC) */
2232 +#define v4l2_fourcc(a, b, c, d)\
2233 +       ((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))
2234 +
2235 +/*
2236 + *     E N U M S
2237 + */
2238 +enum v4l2_field {
2239 +       V4L2_FIELD_ANY           = 0, /* driver can choose from none,
2240 +                                        top, bottom, interlaced
2241 +                                        depending on whatever it thinks
2242 +                                        is approximate ... */
2243 +       V4L2_FIELD_NONE          = 1, /* this device has no fields ... */
2244 +       V4L2_FIELD_TOP           = 2, /* top field only */
2245 +       V4L2_FIELD_BOTTOM        = 3, /* bottom field only */
2246 +       V4L2_FIELD_INTERLACED    = 4, /* both fields interlaced */
2247 +       V4L2_FIELD_SEQ_TB        = 5, /* both fields sequential into one
2248 +                                        buffer, top-bottom order */
2249 +       V4L2_FIELD_SEQ_BT        = 6, /* same as above + bottom-top order */
2250 +       V4L2_FIELD_ALTERNATE     = 7, /* both fields alternating into
2251 +                                        separate buffers */
2252 +       V4L2_FIELD_INTERLACED_TB = 8, /* both fields interlaced, top field
2253 +                                        first and the top field is
2254 +                                        transmitted first */
2255 +       V4L2_FIELD_INTERLACED_BT = 9, /* both fields interlaced, top field
2256 +                                        first and the bottom field is
2257 +                                        transmitted first */
2258 +};
2259 +#define V4L2_FIELD_HAS_TOP(field)      \
2260 +       ((field) == V4L2_FIELD_TOP      ||\
2261 +        (field) == V4L2_FIELD_INTERLACED ||\
2262 +        (field) == V4L2_FIELD_INTERLACED_TB ||\
2263 +        (field) == V4L2_FIELD_INTERLACED_BT ||\
2264 +        (field) == V4L2_FIELD_SEQ_TB   ||\
2265 +        (field) == V4L2_FIELD_SEQ_BT)
2266 +#define V4L2_FIELD_HAS_BOTTOM(field)   \
2267 +       ((field) == V4L2_FIELD_BOTTOM   ||\
2268 +        (field) == V4L2_FIELD_INTERLACED ||\
2269 +        (field) == V4L2_FIELD_INTERLACED_TB ||\
2270 +        (field) == V4L2_FIELD_INTERLACED_BT ||\
2271 +        (field) == V4L2_FIELD_SEQ_TB   ||\
2272 +        (field) == V4L2_FIELD_SEQ_BT)
2273 +#define V4L2_FIELD_HAS_BOTH(field)     \
2274 +       ((field) == V4L2_FIELD_INTERLACED ||\
2275 +        (field) == V4L2_FIELD_INTERLACED_TB ||\
2276 +        (field) == V4L2_FIELD_INTERLACED_BT ||\
2277 +        (field) == V4L2_FIELD_SEQ_TB ||\
2278 +        (field) == V4L2_FIELD_SEQ_BT)
2279 +
2280 +enum v4l2_buf_type {
2281 +       V4L2_BUF_TYPE_VIDEO_CAPTURE        = 1,
2282 +       V4L2_BUF_TYPE_VIDEO_OUTPUT         = 2,
2283 +       V4L2_BUF_TYPE_VIDEO_OVERLAY        = 3,
2284 +       V4L2_BUF_TYPE_VBI_CAPTURE          = 4,
2285 +       V4L2_BUF_TYPE_VBI_OUTPUT           = 5,
2286 +       V4L2_BUF_TYPE_SLICED_VBI_CAPTURE   = 6,
2287 +       V4L2_BUF_TYPE_SLICED_VBI_OUTPUT    = 7,
2288 +#if 1
2289 +       /* Experimental */
2290 +       V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY = 8,
2291 +#endif
2292 +       V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = 9,
2293 +       V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE  = 10,
2294 +       V4L2_BUF_TYPE_PRIVATE              = 0x80,
2295 +};
2296 +
2297 +#define V4L2_TYPE_IS_MULTIPLANAR(type)                 \
2298 +       ((type) == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE   \
2299 +        || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
2300 +
2301 +#define V4L2_TYPE_IS_OUTPUT(type)                              \
2302 +       ((type) == V4L2_BUF_TYPE_VIDEO_OUTPUT                   \
2303 +        || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE         \
2304 +        || (type) == V4L2_BUF_TYPE_VIDEO_OVERLAY               \
2305 +        || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY        \
2306 +        || (type) == V4L2_BUF_TYPE_VBI_OUTPUT                  \
2307 +        || (type) == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT)
2308 +
2309 +enum v4l2_tuner_type {
2310 +       V4L2_TUNER_RADIO             = 1,
2311 +       V4L2_TUNER_ANALOG_TV         = 2,
2312 +       V4L2_TUNER_DIGITAL_TV        = 3,
2313 +};
2314 +
2315 +enum v4l2_memory {
2316 +       V4L2_MEMORY_MMAP             = 1,
2317 +       V4L2_MEMORY_USERPTR          = 2,
2318 +       V4L2_MEMORY_OVERLAY          = 3,
2319 +};
2320 +
2321 +/* see also http://vektor.theorem.ca/graphics/ycbcr/ */
2322 +enum v4l2_colorspace {
2323 +       /* ITU-R 601 -- broadcast NTSC/PAL */
2324 +       V4L2_COLORSPACE_SMPTE170M     = 1,
2325 +
2326 +       /* 1125-Line (US) HDTV */
2327 +       V4L2_COLORSPACE_SMPTE240M     = 2,
2328 +
2329 +       /* HD and modern captures. */
2330 +       V4L2_COLORSPACE_REC709        = 3,
2331 +
2332 +       /* broken BT878 extents (601, luma range 16-253 instead of 16-235) */
2333 +       V4L2_COLORSPACE_BT878         = 4,
2334 +
2335 +       /* These should be useful.  Assume 601 extents. */
2336 +       V4L2_COLORSPACE_470_SYSTEM_M  = 5,
2337 +       V4L2_COLORSPACE_470_SYSTEM_BG = 6,
2338 +
2339 +       /* I know there will be cameras that send this.  So, this is
2340 +        * unspecified chromaticities and full 0-255 on each of the
2341 +        * Y'CbCr components
2342 +        */
2343 +       V4L2_COLORSPACE_JPEG          = 7,
2344 +
2345 +       /* For RGB colourspaces, this is probably a good start. */
2346 +       V4L2_COLORSPACE_SRGB          = 8,
2347 +};
2348 +
2349 +enum v4l2_priority {
2350 +       V4L2_PRIORITY_UNSET       = 0,  /* not initialized */
2351 +       V4L2_PRIORITY_BACKGROUND  = 1,
2352 +       V4L2_PRIORITY_INTERACTIVE = 2,
2353 +       V4L2_PRIORITY_RECORD      = 3,
2354 +       V4L2_PRIORITY_DEFAULT     = V4L2_PRIORITY_INTERACTIVE,
2355 +};
2356 +
2357 +struct v4l2_rect {
2358 +       __s32   left;
2359 +       __s32   top;
2360 +       __s32   width;
2361 +       __s32   height;
2362 +};
2363 +
2364 +struct v4l2_fract {
2365 +       __u32   numerator;
2366 +       __u32   denominator;
2367 +};
2368 +
2369 +/*
2370 + *     D R I V E R   C A P A B I L I T I E S
2371 + */
2372 +struct v4l2_capability {
2373 +       __u8    driver[16];     /* i.e. "bttv" */
2374 +       __u8    card[32];       /* i.e. "Hauppauge WinTV" */
2375 +       __u8    bus_info[32];   /* "PCI:" + pci_name(pci_dev) */
2376 +       __u32   version;        /* should use KERNEL_VERSION() */
2377 +       __u32   capabilities;   /* Device capabilities */
2378 +       __u32   reserved[4];
2379 +};
2380 +
2381 +/* Values for 'capabilities' field */
2382 +#define V4L2_CAP_VIDEO_CAPTURE         0x00000001  /* Is a video capture device */
2383 +#define V4L2_CAP_VIDEO_OUTPUT          0x00000002  /* Is a video output device */
2384 +#define V4L2_CAP_VIDEO_OVERLAY         0x00000004  /* Can do video overlay */
2385 +#define V4L2_CAP_VBI_CAPTURE           0x00000010  /* Is a raw VBI capture device */
2386 +#define V4L2_CAP_VBI_OUTPUT            0x00000020  /* Is a raw VBI output device */
2387 +#define V4L2_CAP_SLICED_VBI_CAPTURE    0x00000040  /* Is a sliced VBI capture device */
2388 +#define V4L2_CAP_SLICED_VBI_OUTPUT     0x00000080  /* Is a sliced VBI output device */
2389 +#define V4L2_CAP_RDS_CAPTURE           0x00000100  /* RDS data capture */
2390 +#define V4L2_CAP_VIDEO_OUTPUT_OVERLAY  0x00000200  /* Can do video output overlay */
2391 +#define V4L2_CAP_HW_FREQ_SEEK          0x00000400  /* Can do hardware frequency seek  */
2392 +#define V4L2_CAP_RDS_OUTPUT            0x00000800  /* Is an RDS encoder */
2393 +
2394 +/* Is a video capture device that supports multiplanar formats */
2395 +#define V4L2_CAP_VIDEO_CAPTURE_MPLANE  0x00001000
2396 +/* Is a video output device that supports multiplanar formats */
2397 +#define V4L2_CAP_VIDEO_OUTPUT_MPLANE   0x00002000
2398 +
2399 +#define V4L2_CAP_TUNER                 0x00010000  /* has a tuner */
2400 +#define V4L2_CAP_AUDIO                 0x00020000  /* has audio support */
2401 +#define V4L2_CAP_RADIO                 0x00040000  /* is a radio device */
2402 +#define V4L2_CAP_MODULATOR             0x00080000  /* has a modulator */
2403 +
2404 +#define V4L2_CAP_READWRITE              0x01000000  /* read/write systemcalls */
2405 +#define V4L2_CAP_ASYNCIO                0x02000000  /* async I/O */
2406 +#define V4L2_CAP_STREAMING              0x04000000  /* streaming I/O ioctls */
2407 +
2408 +/*
2409 + *     V I D E O   I M A G E   F O R M A T
2410 + */
2411 +struct v4l2_pix_format {
2412 +       __u32                   width;
2413 +       __u32                   height;
2414 +       __u32                   pixelformat;
2415 +       enum v4l2_field         field;
2416 +       __u32                   bytesperline;   /* for padding, zero if unused */
2417 +       __u32                   sizeimage;
2418 +       enum v4l2_colorspace    colorspace;
2419 +       __u32                   priv;           /* private data, depends on pixelformat */
2420 +};
2421 +
2422 +/*      Pixel format         FOURCC                          depth  Description  */
2423 +
2424 +/* RGB formats */
2425 +#define V4L2_PIX_FMT_RGB332  v4l2_fourcc('R', 'G', 'B', '1') /*  8  RGB-3-3-2     */
2426 +#define V4L2_PIX_FMT_RGB444  v4l2_fourcc('R', '4', '4', '4') /* 16  xxxxrrrr ggggbbbb */
2427 +#define V4L2_PIX_FMT_RGB555  v4l2_fourcc('R', 'G', 'B', 'O') /* 16  RGB-5-5-5     */
2428 +#define V4L2_PIX_FMT_RGB565  v4l2_fourcc('R', 'G', 'B', 'P') /* 16  RGB-5-6-5     */
2429 +#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R', 'G', 'B', 'Q') /* 16  RGB-5-5-5 BE  */
2430 +#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R', 'G', 'B', 'R') /* 16  RGB-5-6-5 BE  */
2431 +#define V4L2_PIX_FMT_BGR666  v4l2_fourcc('B', 'G', 'R', 'H') /* 18  BGR-6-6-6    */
2432 +#define V4L2_PIX_FMT_BGR24   v4l2_fourcc('B', 'G', 'R', '3') /* 24  BGR-8-8-8     */
2433 +#define V4L2_PIX_FMT_RGB24   v4l2_fourcc('R', 'G', 'B', '3') /* 24  RGB-8-8-8     */
2434 +#define V4L2_PIX_FMT_BGR32   v4l2_fourcc('B', 'G', 'R', '4') /* 32  BGR-8-8-8-8   */
2435 +#define V4L2_PIX_FMT_RGB32   v4l2_fourcc('R', 'G', 'B', '4') /* 32  RGB-8-8-8-8   */
2436 +
2437 +/* Grey formats */
2438 +#define V4L2_PIX_FMT_GREY    v4l2_fourcc('G', 'R', 'E', 'Y') /*  8  Greyscale     */
2439 +#define V4L2_PIX_FMT_Y4      v4l2_fourcc('Y', '0', '4', ' ') /*  4  Greyscale     */
2440 +#define V4L2_PIX_FMT_Y6      v4l2_fourcc('Y', '0', '6', ' ') /*  6  Greyscale     */
2441 +#define V4L2_PIX_FMT_Y10     v4l2_fourcc('Y', '1', '0', ' ') /* 10  Greyscale     */
2442 +#define V4L2_PIX_FMT_Y16     v4l2_fourcc('Y', '1', '6', ' ') /* 16  Greyscale     */
2443 +
2444 +/* Palette formats */
2445 +#define V4L2_PIX_FMT_PAL8    v4l2_fourcc('P', 'A', 'L', '8') /*  8  8-bit palette */
2446 +
2447 +/* Luminance+Chrominance formats */
2448 +#define V4L2_PIX_FMT_YVU410  v4l2_fourcc('Y', 'V', 'U', '9') /*  9  YVU 4:1:0     */
2449 +#define V4L2_PIX_FMT_YVU420  v4l2_fourcc('Y', 'V', '1', '2') /* 12  YVU 4:2:0     */
2450 +#define V4L2_PIX_FMT_YUYV    v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16  YUV 4:2:2     */
2451 +#define V4L2_PIX_FMT_YYUV    v4l2_fourcc('Y', 'Y', 'U', 'V') /* 16  YUV 4:2:2     */
2452 +#define V4L2_PIX_FMT_YVYU    v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */
2453 +#define V4L2_PIX_FMT_UYVY    v4l2_fourcc('U', 'Y', 'V', 'Y') /* 16  YUV 4:2:2     */
2454 +#define V4L2_PIX_FMT_VYUY    v4l2_fourcc('V', 'Y', 'U', 'Y') /* 16  YUV 4:2:2     */
2455 +#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4', '2', '2', 'P') /* 16  YVU422 planar */
2456 +#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4', '1', '1', 'P') /* 16  YVU411 planar */
2457 +#define V4L2_PIX_FMT_Y41P    v4l2_fourcc('Y', '4', '1', 'P') /* 12  YUV 4:1:1     */
2458 +#define V4L2_PIX_FMT_YUV444  v4l2_fourcc('Y', '4', '4', '4') /* 16  xxxxyyyy uuuuvvvv */
2459 +#define V4L2_PIX_FMT_YUV555  v4l2_fourcc('Y', 'U', 'V', 'O') /* 16  YUV-5-5-5     */
2460 +#define V4L2_PIX_FMT_YUV565  v4l2_fourcc('Y', 'U', 'V', 'P') /* 16  YUV-5-6-5     */
2461 +#define V4L2_PIX_FMT_YUV32   v4l2_fourcc('Y', 'U', 'V', '4') /* 32  YUV-8-8-8-8   */
2462 +#define V4L2_PIX_FMT_YUV410  v4l2_fourcc('Y', 'U', 'V', '9') /*  9  YUV 4:1:0     */
2463 +#define V4L2_PIX_FMT_YUV420  v4l2_fourcc('Y', 'U', '1', '2') /* 12  YUV 4:2:0     */
2464 +#define V4L2_PIX_FMT_HI240   v4l2_fourcc('H', 'I', '2', '4') /*  8  8-bit color   */
2465 +#define V4L2_PIX_FMT_HM12    v4l2_fourcc('H', 'M', '1', '2') /*  8  YUV 4:2:0 16x16 macroblocks */
2466 +
2467 +/* two planes -- one Y, one Cr + Cb interleaved  */
2468 +#define V4L2_PIX_FMT_NV12    v4l2_fourcc('N', 'V', '1', '2') /* 12  Y/CbCr 4:2:0  */
2469 +#define V4L2_PIX_FMT_NV21    v4l2_fourcc('N', 'V', '2', '1') /* 12  Y/CrCb 4:2:0  */
2470 +#define V4L2_PIX_FMT_NV16    v4l2_fourcc('N', 'V', '1', '6') /* 16  Y/CbCr 4:2:2  */
2471 +#define V4L2_PIX_FMT_NV61    v4l2_fourcc('N', 'V', '6', '1') /* 16  Y/CrCb 4:2:2  */
2472 +
2473 +/* two non contiguous planes - one Y, one Cr + Cb interleaved  */
2474 +#define V4L2_PIX_FMT_NV12M   v4l2_fourcc('N', 'M', '1', '2') /* 12  Y/CbCr 4:2:0  */
2475 +#define V4L2_PIX_FMT_NV12MT  v4l2_fourcc('T', 'M', '1', '2') /* 12  Y/CbCr 4:2:0 64x32 macroblocks */
2476 +
2477 +/* three non contiguous planes - Y, Cb, Cr */
2478 +#define V4L2_PIX_FMT_YUV420M v4l2_fourcc('Y', 'M', '1', '2') /* 12  YUV420 planar */
2479 +
2480 +/* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
2481 +#define V4L2_PIX_FMT_SBGGR8  v4l2_fourcc('B', 'A', '8', '1') /*  8  BGBG.. GRGR.. */
2482 +#define V4L2_PIX_FMT_SGBRG8  v4l2_fourcc('G', 'B', 'R', 'G') /*  8  GBGB.. RGRG.. */
2483 +#define V4L2_PIX_FMT_SGRBG8  v4l2_fourcc('G', 'R', 'B', 'G') /*  8  GRGR.. BGBG.. */
2484 +#define V4L2_PIX_FMT_SRGGB8  v4l2_fourcc('R', 'G', 'G', 'B') /*  8  RGRG.. GBGB.. */
2485 +#define V4L2_PIX_FMT_SBGGR10 v4l2_fourcc('B', 'G', '1', '0') /* 10  BGBG.. GRGR.. */
2486 +#define V4L2_PIX_FMT_SGBRG10 v4l2_fourcc('G', 'B', '1', '0') /* 10  GBGB.. RGRG.. */
2487 +#define V4L2_PIX_FMT_SGRBG10 v4l2_fourcc('B', 'A', '1', '0') /* 10  GRGR.. BGBG.. */
2488 +#define V4L2_PIX_FMT_SRGGB10 v4l2_fourcc('R', 'G', '1', '0') /* 10  RGRG.. GBGB.. */
2489 +       /* 10bit raw bayer DPCM compressed to 8 bits */
2490 +#define V4L2_PIX_FMT_SGRBG10DPCM8 v4l2_fourcc('B', 'D', '1', '0')
2491 +       /*
2492 +        * 10bit raw bayer, expanded to 16 bits
2493 +        * xxxxrrrrrrrrrrxxxxgggggggggg xxxxggggggggggxxxxbbbbbbbbbb...
2494 +        */
2495 +#define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2') /* 16  BGBG.. GRGR.. */
2496 +
2497 +/* compressed formats */
2498 +#define V4L2_PIX_FMT_MJPEG    v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG   */
2499 +#define V4L2_PIX_FMT_JPEG     v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG     */
2500 +#define V4L2_PIX_FMT_DV       v4l2_fourcc('d', 'v', 's', 'd') /* 1394          */
2501 +#define V4L2_PIX_FMT_MPEG     v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4    */
2502 +
2503 +/*  Vendor-specific formats   */
2504 +#define V4L2_PIX_FMT_CPIA1    v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */
2505 +#define V4L2_PIX_FMT_WNVA     v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */
2506 +#define V4L2_PIX_FMT_SN9C10X  v4l2_fourcc('S', '9', '1', '0') /* SN9C10x compression */
2507 +#define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0') /* SN9C20x YUV 4:2:0 */
2508 +#define V4L2_PIX_FMT_PWC1     v4l2_fourcc('P', 'W', 'C', '1') /* pwc older webcam */
2509 +#define V4L2_PIX_FMT_PWC2     v4l2_fourcc('P', 'W', 'C', '2') /* pwc newer webcam */
2510 +#define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E', '6', '2', '5') /* ET61X251 compression */
2511 +#define V4L2_PIX_FMT_SPCA501  v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */
2512 +#define V4L2_PIX_FMT_SPCA505  v4l2_fourcc('S', '5', '0', '5') /* YYUV per line */
2513 +#define V4L2_PIX_FMT_SPCA508  v4l2_fourcc('S', '5', '0', '8') /* YUVY per line */
2514 +#define V4L2_PIX_FMT_SPCA561  v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */
2515 +#define V4L2_PIX_FMT_PAC207   v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */
2516 +#define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */
2517 +#define V4L2_PIX_FMT_SN9C2028 v4l2_fourcc('S', 'O', 'N', 'X') /* compressed GBRG bayer */
2518 +#define V4L2_PIX_FMT_SQ905C   v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */
2519 +#define V4L2_PIX_FMT_PJPG     v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */
2520 +#define V4L2_PIX_FMT_OV511    v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */
2521 +#define V4L2_PIX_FMT_OV518    v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */
2522 +#define V4L2_PIX_FMT_STV0680  v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */
2523 +#define V4L2_PIX_FMT_TM6000   v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */
2524 +#define V4L2_PIX_FMT_CIT_YYVYUY v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */
2525 +#define V4L2_PIX_FMT_KONICA420  v4l2_fourcc('K', 'O', 'N', 'I') /* YUV420 planar in blocks of 256 pixels */
2526 +
2527 +/*
2528 + *     F O R M A T   E N U M E R A T I O N
2529 + */
2530 +struct v4l2_fmtdesc {
2531 +       __u32               index;             /* Format number      */
2532 +       enum v4l2_buf_type  type;              /* buffer type        */
2533 +       __u32               flags;
2534 +       __u8                description[32];   /* Description string */
2535 +       __u32               pixelformat;       /* Format fourcc      */
2536 +       __u32               reserved[4];
2537 +};
2538 +
2539 +#define V4L2_FMT_FLAG_COMPRESSED 0x0001
2540 +#define V4L2_FMT_FLAG_EMULATED   0x0002
2541 +
2542 +#if 1
2543 +       /* Experimental Frame Size and frame rate enumeration */
2544 +/*
2545 + *     F R A M E   S I Z E   E N U M E R A T I O N
2546 + */
2547 +enum v4l2_frmsizetypes {
2548 +       V4L2_FRMSIZE_TYPE_DISCRETE      = 1,
2549 +       V4L2_FRMSIZE_TYPE_CONTINUOUS    = 2,
2550 +       V4L2_FRMSIZE_TYPE_STEPWISE      = 3,
2551 +};
2552 +
2553 +struct v4l2_frmsize_discrete {
2554 +       __u32                   width;          /* Frame width [pixel] */
2555 +       __u32                   height;         /* Frame height [pixel] */
2556 +};
2557 +
2558 +struct v4l2_frmsize_stepwise {
2559 +       __u32                   min_width;      /* Minimum frame width [pixel] */
2560 +       __u32                   max_width;      /* Maximum frame width [pixel] */
2561 +       __u32                   step_width;     /* Frame width step size [pixel] */
2562 +       __u32                   min_height;     /* Minimum frame height [pixel] */
2563 +       __u32                   max_height;     /* Maximum frame height [pixel] */
2564 +       __u32                   step_height;    /* Frame height step size [pixel] */
2565 +};
2566 +
2567 +struct v4l2_frmsizeenum {
2568 +       __u32                   index;          /* Frame size number */
2569 +       __u32                   pixel_format;   /* Pixel format */
2570 +       __u32                   type;           /* Frame size type the device supports. */
2571 +
2572 +       union {                                 /* Frame size */
2573 +               struct v4l2_frmsize_discrete    discrete;
2574 +               struct v4l2_frmsize_stepwise    stepwise;
2575 +       };
2576 +
2577 +       __u32   reserved[2];                    /* Reserved space for future use */
2578 +};
2579 +
2580 +/*
2581 + *     F R A M E   R A T E   E N U M E R A T I O N
2582 + */
2583 +enum v4l2_frmivaltypes {
2584 +       V4L2_FRMIVAL_TYPE_DISCRETE      = 1,
2585 +       V4L2_FRMIVAL_TYPE_CONTINUOUS    = 2,
2586 +       V4L2_FRMIVAL_TYPE_STEPWISE      = 3,
2587 +};
2588 +
2589 +struct v4l2_frmival_stepwise {
2590 +       struct v4l2_fract       min;            /* Minimum frame interval [s] */
2591 +       struct v4l2_fract       max;            /* Maximum frame interval [s] */
2592 +       struct v4l2_fract       step;           /* Frame interval step size [s] */
2593 +};
2594 +
2595 +struct v4l2_frmivalenum {
2596 +       __u32                   index;          /* Frame format index */
2597 +       __u32                   pixel_format;   /* Pixel format */
2598 +       __u32                   width;          /* Frame width */
2599 +       __u32                   height;         /* Frame height */
2600 +       __u32                   type;           /* Frame interval type the device supports. */
2601 +
2602 +       union {                                 /* Frame interval */
2603 +               struct v4l2_fract               discrete;
2604 +               struct v4l2_frmival_stepwise    stepwise;
2605 +       };
2606 +
2607 +       __u32   reserved[2];                    /* Reserved space for future use */
2608 +};
2609 +#endif
2610 +
2611 +/*
2612 + *     T I M E C O D E
2613 + */
2614 +struct v4l2_timecode {
2615 +       __u32   type;
2616 +       __u32   flags;
2617 +       __u8    frames;
2618 +       __u8    seconds;
2619 +       __u8    minutes;
2620 +       __u8    hours;
2621 +       __u8    userbits[4];
2622 +};
2623 +
2624 +/*  Type  */
2625 +#define V4L2_TC_TYPE_24FPS             1
2626 +#define V4L2_TC_TYPE_25FPS             2
2627 +#define V4L2_TC_TYPE_30FPS             3
2628 +#define V4L2_TC_TYPE_50FPS             4
2629 +#define V4L2_TC_TYPE_60FPS             5
2630 +
2631 +/*  Flags  */
2632 +#define V4L2_TC_FLAG_DROPFRAME         0x0001 /* "drop-frame" mode */
2633 +#define V4L2_TC_FLAG_COLORFRAME                0x0002
2634 +#define V4L2_TC_USERBITS_field         0x000C
2635 +#define V4L2_TC_USERBITS_USERDEFINED   0x0000
2636 +#define V4L2_TC_USERBITS_8BITCHARS     0x0008
2637 +/* The above is based on SMPTE timecodes */
2638 +
2639 +struct v4l2_jpegcompression {
2640 +       int quality;
2641 +
2642 +       int  APPn;              /* Number of APP segment to be written,
2643 +                                * must be 0..15 */
2644 +       int  APP_len;           /* Length of data in JPEG APPn segment */
2645 +       char APP_data[60];      /* Data in the JPEG APPn segment. */
2646 +
2647 +       int  COM_len;           /* Length of data in JPEG COM segment */
2648 +       char COM_data[60];      /* Data in JPEG COM segment */
2649 +
2650 +       __u32 jpeg_markers;     /* Which markers should go into the JPEG
2651 +                                * output. Unless you exactly know what
2652 +                                * you do, leave them untouched.
2653 +                                * Inluding less markers will make the
2654 +                                * resulting code smaller, but there will
2655 +                                * be fewer applications which can read it.
2656 +                                * The presence of the APP and COM marker
2657 +                                * is influenced by APP_len and COM_len
2658 +                                * ONLY, not by this property! */
2659 +
2660 +#define V4L2_JPEG_MARKER_DHT (1<<3)    /* Define Huffman Tables */
2661 +#define V4L2_JPEG_MARKER_DQT (1<<4)    /* Define Quantization Tables */
2662 +#define V4L2_JPEG_MARKER_DRI (1<<5)    /* Define Restart Interval */
2663 +#define V4L2_JPEG_MARKER_COM (1<<6)    /* Comment segment */
2664 +#define V4L2_JPEG_MARKER_APP (1<<7)    /* App segment, driver will
2665 +                                       * allways use APP0 */
2666 +};
2667 +
2668 +/*
2669 + *     M E M O R Y - M A P P I N G   B U F F E R S
2670 + */
2671 +struct v4l2_requestbuffers {
2672 +       __u32                   count;
2673 +       enum v4l2_buf_type      type;
2674 +       enum v4l2_memory        memory;
2675 +       __u32                   reserved[2];
2676 +};
2677 +
2678 +/**
2679 + * struct v4l2_plane - plane info for multi-planar buffers
2680 + * @bytesused:         number of bytes occupied by data in the plane (payload)
2681 + * @length:            size of this plane (NOT the payload) in bytes
2682 + * @mem_offset:                when memory in the associated struct v4l2_buffer is
2683 + *                     V4L2_MEMORY_MMAP, equals the offset from the start of
2684 + *                     the device memory for this plane (or is a "cookie" that
2685 + *                     should be passed to mmap() called on the video node)
2686 + * @userptr:           when memory is V4L2_MEMORY_USERPTR, a userspace pointer
2687 + *                     pointing to this plane
2688 + * @data_offset:       offset in the plane to the start of data; usually 0,
2689 + *                     unless there is a header in front of the data
2690 + *
2691 + * Multi-planar buffers consist of one or more planes, e.g. an YCbCr buffer
2692 + * with two planes can have one plane for Y, and another for interleaved CbCr
2693 + * components. Each plane can reside in a separate memory buffer, or even in
2694 + * a completely separate memory node (e.g. in embedded devices).
2695 + */
2696 +struct v4l2_plane {
2697 +       __u32                   bytesused;
2698 +       __u32                   length;
2699 +       union {
2700 +               __u32           mem_offset;
2701 +               unsigned long   userptr;
2702 +       } m;
2703 +       __u32                   data_offset;
2704 +       __u32                   reserved[11];
2705 +};
2706 +
2707 +/**
2708 + * struct v4l2_buffer - video buffer info
2709 + * @index:     id number of the buffer
2710 + * @type:      buffer type (type == *_MPLANE for multiplanar buffers)
2711 + * @bytesused: number of bytes occupied by data in the buffer (payload);
2712 + *             unused (set to 0) for multiplanar buffers
2713 + * @flags:     buffer informational flags
2714 + * @field:     field order of the image in the buffer
2715 + * @timestamp: frame timestamp
2716 + * @timecode:  frame timecode
2717 + * @sequence:  sequence count of this frame
2718 + * @memory:    the method, in which the actual video data is passed
2719 + * @offset:    for non-multiplanar buffers with memory == V4L2_MEMORY_MMAP;
2720 + *             offset from the start of the device memory for this plane,
2721 + *             (or a "cookie" that should be passed to mmap() as offset)
2722 + * @userptr:   for non-multiplanar buffers with memory == V4L2_MEMORY_USERPTR;
2723 + *             a userspace pointer pointing to this buffer
2724 + * @planes:    for multiplanar buffers; userspace pointer to the array of plane
2725 + *             info structs for this buffer
2726 + * @length:    size in bytes of the buffer (NOT its payload) for single-plane
2727 + *             buffers (when type != *_MPLANE); number of elements in the
2728 + *             planes array for multi-plane buffers
2729 + * @input:     input number from which the video data has has been captured
2730 + *
2731 + * Contains data exchanged by application and driver using one of the Streaming
2732 + * I/O methods.
2733 + */
2734 +struct v4l2_buffer {
2735 +       __u32                   index;
2736 +       enum v4l2_buf_type      type;
2737 +       __u32                   bytesused;
2738 +       __u32                   flags;
2739 +       enum v4l2_field         field;
2740 +       struct timeval          timestamp;
2741 +       struct v4l2_timecode    timecode;
2742 +       __u32                   sequence;
2743 +
2744 +       /* memory location */
2745 +       enum v4l2_memory        memory;
2746 +       union {
2747 +               __u32           offset;
2748 +               unsigned long   userptr;
2749 +               struct v4l2_plane *planes;
2750 +       } m;
2751 +       __u32                   length;
2752 +       __u32                   input;
2753 +       __u32                   reserved;
2754 +};
2755 +
2756 +/*  Flags for 'flags' field */
2757 +#define V4L2_BUF_FLAG_MAPPED   0x0001  /* Buffer is mapped (flag) */
2758 +#define V4L2_BUF_FLAG_QUEUED   0x0002  /* Buffer is queued for processing */
2759 +#define V4L2_BUF_FLAG_DONE     0x0004  /* Buffer is ready */
2760 +#define V4L2_BUF_FLAG_KEYFRAME 0x0008  /* Image is a keyframe (I-frame) */
2761 +#define V4L2_BUF_FLAG_PFRAME   0x0010  /* Image is a P-frame */
2762 +#define V4L2_BUF_FLAG_BFRAME   0x0020  /* Image is a B-frame */
2763 +/* Buffer is ready, but the data contained within is corrupted. */
2764 +#define V4L2_BUF_FLAG_ERROR    0x0040
2765 +#define V4L2_BUF_FLAG_TIMECODE 0x0100  /* timecode field is valid */
2766 +#define V4L2_BUF_FLAG_INPUT     0x0200  /* input field is valid */
2767 +
2768 +/*
2769 + *     O V E R L A Y   P R E V I E W
2770 + */
2771 +struct v4l2_framebuffer {
2772 +       __u32                   capability;
2773 +       __u32                   flags;
2774 +/* FIXME: in theory we should pass something like PCI device + memory
2775 + * region + offset instead of some physical address */
2776 +       void                    *base;
2777 +       struct v4l2_pix_format  fmt;
2778 +};
2779 +/*  Flags for the 'capability' field. Read only */
2780 +#define V4L2_FBUF_CAP_EXTERNOVERLAY    0x0001
2781 +#define V4L2_FBUF_CAP_CHROMAKEY                0x0002
2782 +#define V4L2_FBUF_CAP_LIST_CLIPPING     0x0004
2783 +#define V4L2_FBUF_CAP_BITMAP_CLIPPING  0x0008
2784 +#define V4L2_FBUF_CAP_LOCAL_ALPHA      0x0010
2785 +#define V4L2_FBUF_CAP_GLOBAL_ALPHA     0x0020
2786 +#define V4L2_FBUF_CAP_LOCAL_INV_ALPHA  0x0040
2787 +#define V4L2_FBUF_CAP_SRC_CHROMAKEY    0x0080
2788 +/*  Flags for the 'flags' field. */
2789 +#define V4L2_FBUF_FLAG_PRIMARY         0x0001
2790 +#define V4L2_FBUF_FLAG_OVERLAY         0x0002
2791 +#define V4L2_FBUF_FLAG_CHROMAKEY       0x0004
2792 +#define V4L2_FBUF_FLAG_LOCAL_ALPHA     0x0008
2793 +#define V4L2_FBUF_FLAG_GLOBAL_ALPHA    0x0010
2794 +#define V4L2_FBUF_FLAG_LOCAL_INV_ALPHA 0x0020
2795 +#define V4L2_FBUF_FLAG_SRC_CHROMAKEY   0x0040
2796 +
2797 +struct v4l2_clip {
2798 +       struct v4l2_rect        c;
2799 +       struct v4l2_clip        *next;
2800 +};
2801 +
2802 +struct v4l2_window {
2803 +       struct v4l2_rect        w;
2804 +       enum v4l2_field         field;
2805 +       __u32                   chromakey;
2806 +       struct v4l2_clip        *clips;
2807 +       __u32                   clipcount;
2808 +       void                    *bitmap;
2809 +       __u8                    global_alpha;
2810 +};
2811 +
2812 +/*
2813 + *     C A P T U R E   P A R A M E T E R S
2814 + */
2815 +struct v4l2_captureparm {
2816 +       __u32              capability;    /*  Supported modes */
2817 +       __u32              capturemode;   /*  Current mode */
2818 +       struct v4l2_fract  timeperframe;  /*  Time per frame in .1us units */
2819 +       __u32              extendedmode;  /*  Driver-specific extensions */
2820 +       __u32              readbuffers;   /*  # of buffers for read */
2821 +       __u32              reserved[4];
2822 +};
2823 +
2824 +/*  Flags for 'capability' and 'capturemode' fields */
2825 +#define V4L2_MODE_HIGHQUALITY  0x0001  /*  High quality imaging mode */
2826 +#define V4L2_CAP_TIMEPERFRAME  0x1000  /*  timeperframe field is supported */
2827 +
2828 +struct v4l2_outputparm {
2829 +       __u32              capability;   /*  Supported modes */
2830 +       __u32              outputmode;   /*  Current mode */
2831 +       struct v4l2_fract  timeperframe; /*  Time per frame in seconds */
2832 +       __u32              extendedmode; /*  Driver-specific extensions */
2833 +       __u32              writebuffers; /*  # of buffers for write */
2834 +       __u32              reserved[4];
2835 +};
2836 +
2837 +/*
2838 + *     I N P U T   I M A G E   C R O P P I N G
2839 + */
2840 +struct v4l2_cropcap {
2841 +       enum v4l2_buf_type      type;
2842 +       struct v4l2_rect        bounds;
2843 +       struct v4l2_rect        defrect;
2844 +       struct v4l2_fract       pixelaspect;
2845 +};
2846 +
2847 +struct v4l2_crop {
2848 +       enum v4l2_buf_type      type;
2849 +       struct v4l2_rect        c;
2850 +};
2851 +
2852 +/*
2853 + *      A N A L O G   V I D E O   S T A N D A R D
2854 + */
2855 +
2856 +typedef __u64 v4l2_std_id;
2857 +
2858 +/* one bit for each */
2859 +#define V4L2_STD_PAL_B          ((v4l2_std_id)0x00000001)
2860 +#define V4L2_STD_PAL_B1         ((v4l2_std_id)0x00000002)
2861 +#define V4L2_STD_PAL_G          ((v4l2_std_id)0x00000004)
2862 +#define V4L2_STD_PAL_H          ((v4l2_std_id)0x00000008)
2863 +#define V4L2_STD_PAL_I          ((v4l2_std_id)0x00000010)
2864 +#define V4L2_STD_PAL_D          ((v4l2_std_id)0x00000020)
2865 +#define V4L2_STD_PAL_D1         ((v4l2_std_id)0x00000040)
2866 +#define V4L2_STD_PAL_K          ((v4l2_std_id)0x00000080)
2867 +
2868 +#define V4L2_STD_PAL_M          ((v4l2_std_id)0x00000100)
2869 +#define V4L2_STD_PAL_N          ((v4l2_std_id)0x00000200)
2870 +#define V4L2_STD_PAL_Nc         ((v4l2_std_id)0x00000400)
2871 +#define V4L2_STD_PAL_60         ((v4l2_std_id)0x00000800)
2872 +
2873 +#define V4L2_STD_NTSC_M         ((v4l2_std_id)0x00001000)
2874 +#define V4L2_STD_NTSC_M_JP      ((v4l2_std_id)0x00002000)
2875 +#define V4L2_STD_NTSC_443       ((v4l2_std_id)0x00004000)
2876 +#define V4L2_STD_NTSC_M_KR      ((v4l2_std_id)0x00008000)
2877 +
2878 +#define V4L2_STD_SECAM_B        ((v4l2_std_id)0x00010000)
2879 +#define V4L2_STD_SECAM_D        ((v4l2_std_id)0x00020000)
2880 +#define V4L2_STD_SECAM_G        ((v4l2_std_id)0x00040000)
2881 +#define V4L2_STD_SECAM_H        ((v4l2_std_id)0x00080000)
2882 +#define V4L2_STD_SECAM_K        ((v4l2_std_id)0x00100000)
2883 +#define V4L2_STD_SECAM_K1       ((v4l2_std_id)0x00200000)
2884 +#define V4L2_STD_SECAM_L        ((v4l2_std_id)0x00400000)
2885 +#define V4L2_STD_SECAM_LC       ((v4l2_std_id)0x00800000)
2886 +
2887 +/* ATSC/HDTV */
2888 +#define V4L2_STD_ATSC_8_VSB     ((v4l2_std_id)0x01000000)
2889 +#define V4L2_STD_ATSC_16_VSB    ((v4l2_std_id)0x02000000)
2890 +
2891 +/* FIXME:
2892 +   Although std_id is 64 bits, there is an issue on PPC32 architecture that
2893 +   makes switch(__u64) to break. So, there's a hack on v4l2-common.c rounding
2894 +   this value to 32 bits.
2895 +   As, currently, the max value is for V4L2_STD_ATSC_16_VSB (30 bits wide),
2896 +   it should work fine. However, if needed to add more than two standards,
2897 +   v4l2-common.c should be fixed.
2898 + */
2899 +
2900 +/* some merged standards */
2901 +#define V4L2_STD_MN    (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC)
2902 +#define V4L2_STD_B     (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B)
2903 +#define V4L2_STD_GH    (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
2904 +#define V4L2_STD_DK    (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)
2905 +
2906 +/* some common needed stuff */
2907 +#define V4L2_STD_PAL_BG                (V4L2_STD_PAL_B         |\
2908 +                                V4L2_STD_PAL_B1        |\
2909 +                                V4L2_STD_PAL_G)
2910 +#define V4L2_STD_PAL_DK                (V4L2_STD_PAL_D         |\
2911 +                                V4L2_STD_PAL_D1        |\
2912 +                                V4L2_STD_PAL_K)
2913 +#define V4L2_STD_PAL           (V4L2_STD_PAL_BG        |\
2914 +                                V4L2_STD_PAL_DK        |\
2915 +                                V4L2_STD_PAL_H         |\
2916 +                                V4L2_STD_PAL_I)
2917 +#define V4L2_STD_NTSC           (V4L2_STD_NTSC_M       |\
2918 +                                V4L2_STD_NTSC_M_JP     |\
2919 +                                V4L2_STD_NTSC_M_KR)
2920 +#define V4L2_STD_SECAM_DK              (V4L2_STD_SECAM_D       |\
2921 +                                V4L2_STD_SECAM_K       |\
2922 +                                V4L2_STD_SECAM_K1)
2923 +#define V4L2_STD_SECAM         (V4L2_STD_SECAM_B       |\
2924 +                                V4L2_STD_SECAM_G       |\
2925 +                                V4L2_STD_SECAM_H       |\
2926 +                                V4L2_STD_SECAM_DK      |\
2927 +                                V4L2_STD_SECAM_L       |\
2928 +                                V4L2_STD_SECAM_LC)
2929 +
2930 +#define V4L2_STD_525_60                (V4L2_STD_PAL_M         |\
2931 +                                V4L2_STD_PAL_60        |\
2932 +                                V4L2_STD_NTSC          |\
2933 +                                V4L2_STD_NTSC_443)
2934 +#define V4L2_STD_625_50                (V4L2_STD_PAL           |\
2935 +                                V4L2_STD_PAL_N         |\
2936 +                                V4L2_STD_PAL_Nc        |\
2937 +                                V4L2_STD_SECAM)
2938 +#define V4L2_STD_ATSC           (V4L2_STD_ATSC_8_VSB    |\
2939 +                                V4L2_STD_ATSC_16_VSB)
2940 +
2941 +#define V4L2_STD_UNKNOWN        0
2942 +#define V4L2_STD_ALL            (V4L2_STD_525_60       |\
2943 +                                V4L2_STD_625_50)
2944 +
2945 +struct v4l2_standard {
2946 +       __u32                index;
2947 +       v4l2_std_id          id;
2948 +       __u8                 name[24];
2949 +       struct v4l2_fract    frameperiod; /* Frames, not fields */
2950 +       __u32                framelines;
2951 +       __u32                reserved[4];
2952 +};
2953 +
2954 +/*
2955 + *     V I D E O       T I M I N G S   D V     P R E S E T
2956 + */
2957 +struct v4l2_dv_preset {
2958 +       __u32   preset;
2959 +       __u32   reserved[4];
2960 +};
2961 +
2962 +/*
2963 + *     D V     P R E S E T S   E N U M E R A T I O N
2964 + */
2965 +struct v4l2_dv_enum_preset {
2966 +       __u32   index;
2967 +       __u32   preset;
2968 +       __u8    name[32]; /* Name of the preset timing */
2969 +       __u32   width;
2970 +       __u32   height;
2971 +       __u32   reserved[4];
2972 +};
2973 +
2974 +/*
2975 + *     D V     P R E S E T     V A L U E S
2976 + */
2977 +#define                V4L2_DV_INVALID         0
2978 +#define                V4L2_DV_480P59_94       1 /* BT.1362 */
2979 +#define                V4L2_DV_576P50          2 /* BT.1362 */
2980 +#define                V4L2_DV_720P24          3 /* SMPTE 296M */
2981 +#define                V4L2_DV_720P25          4 /* SMPTE 296M */
2982 +#define                V4L2_DV_720P30          5 /* SMPTE 296M */
2983 +#define                V4L2_DV_720P50          6 /* SMPTE 296M */
2984 +#define                V4L2_DV_720P59_94       7 /* SMPTE 274M */
2985 +#define                V4L2_DV_720P60          8 /* SMPTE 274M/296M */
2986 +#define                V4L2_DV_1080I29_97      9 /* BT.1120/ SMPTE 274M */
2987 +#define                V4L2_DV_1080I30         10 /* BT.1120/ SMPTE 274M */
2988 +#define                V4L2_DV_1080I25         11 /* BT.1120 */
2989 +#define                V4L2_DV_1080I50         12 /* SMPTE 296M */
2990 +#define                V4L2_DV_1080I60         13 /* SMPTE 296M */
2991 +#define                V4L2_DV_1080P24         14 /* SMPTE 296M */
2992 +#define                V4L2_DV_1080P25         15 /* SMPTE 296M */
2993 +#define                V4L2_DV_1080P30         16 /* SMPTE 296M */
2994 +#define                V4L2_DV_1080P50         17 /* BT.1120 */
2995 +#define                V4L2_DV_1080P60         18 /* BT.1120 */
2996 +
2997 +/*
2998 + *     D V     B T     T I M I N G S
2999 + */
3000 +
3001 +/* BT.656/BT.1120 timing data */
3002 +struct v4l2_bt_timings {
3003 +       __u32   width;          /* width in pixels */
3004 +       __u32   height;         /* height in lines */
3005 +       __u32   interlaced;     /* Interlaced or progressive */
3006 +       __u32   polarities;     /* Positive or negative polarity */
3007 +       __u64   pixelclock;     /* Pixel clock in HZ. Ex. 74.25MHz->74250000 */
3008 +       __u32   hfrontporch;    /* Horizpontal front porch in pixels */
3009 +       __u32   hsync;          /* Horizontal Sync length in pixels */
3010 +       __u32   hbackporch;     /* Horizontal back porch in pixels */
3011 +       __u32   vfrontporch;    /* Vertical front porch in pixels */
3012 +       __u32   vsync;          /* Vertical Sync length in lines */
3013 +       __u32   vbackporch;     /* Vertical back porch in lines */
3014 +       __u32   il_vfrontporch; /* Vertical front porch for bottom field of
3015 +                                * interlaced field formats
3016 +                                */
3017 +       __u32   il_vsync;       /* Vertical sync length for bottom field of
3018 +                                * interlaced field formats
3019 +                                */
3020 +       __u32   il_vbackporch;  /* Vertical back porch for bottom field of
3021 +                                * interlaced field formats
3022 +                                */
3023 +       __u32   reserved[16];
3024 +} __attribute__ ((packed));
3025 +
3026 +/* Interlaced or progressive format */
3027 +#define        V4L2_DV_PROGRESSIVE     0
3028 +#define        V4L2_DV_INTERLACED      1
3029 +
3030 +/* Polarities. If bit is not set, it is assumed to be negative polarity */
3031 +#define V4L2_DV_VSYNC_POS_POL  0x00000001
3032 +#define V4L2_DV_HSYNC_POS_POL  0x00000002
3033 +
3034 +
3035 +/* DV timings */
3036 +struct v4l2_dv_timings {
3037 +       __u32 type;
3038 +       union {
3039 +               struct v4l2_bt_timings  bt;
3040 +               __u32   reserved[32];
3041 +       };
3042 +} __attribute__ ((packed));
3043 +
3044 +/* Values for the type field */
3045 +#define V4L2_DV_BT_656_1120    0       /* BT.656/1120 timing type */
3046 +
3047 +/*
3048 + *     V I D E O   I N P U T S
3049 + */
3050 +struct v4l2_input {
3051 +       __u32        index;             /*  Which input */
3052 +       __u8         name[32];          /*  Label */
3053 +       __u32        type;              /*  Type of input */
3054 +       __u32        audioset;          /*  Associated audios (bitfield) */
3055 +       __u32        tuner;             /*  Associated tuner */
3056 +       v4l2_std_id  std;
3057 +       __u32        status;
3058 +       __u32        capabilities;
3059 +       __u32        reserved[3];
3060 +};
3061 +
3062 +/*  Values for the 'type' field */
3063 +#define V4L2_INPUT_TYPE_TUNER          1
3064 +#define V4L2_INPUT_TYPE_CAMERA         2
3065 +
3066 +/* field 'status' - general */
3067 +#define V4L2_IN_ST_NO_POWER    0x00000001  /* Attached device is off */
3068 +#define V4L2_IN_ST_NO_SIGNAL   0x00000002
3069 +#define V4L2_IN_ST_NO_COLOR    0x00000004
3070 +
3071 +/* field 'status' - sensor orientation */
3072 +/* If sensor is mounted upside down set both bits */
3073 +#define V4L2_IN_ST_HFLIP       0x00000010 /* Frames are flipped horizontally */
3074 +#define V4L2_IN_ST_VFLIP       0x00000020 /* Frames are flipped vertically */
3075 +
3076 +/* field 'status' - analog */
3077 +#define V4L2_IN_ST_NO_H_LOCK   0x00000100  /* No horizontal sync lock */
3078 +#define V4L2_IN_ST_COLOR_KILL  0x00000200  /* Color killer is active */
3079 +
3080 +/* field 'status' - digital */
3081 +#define V4L2_IN_ST_NO_SYNC     0x00010000  /* No synchronization lock */
3082 +#define V4L2_IN_ST_NO_EQU      0x00020000  /* No equalizer lock */
3083 +#define V4L2_IN_ST_NO_CARRIER  0x00040000  /* Carrier recovery failed */
3084 +
3085 +/* field 'status' - VCR and set-top box */
3086 +#define V4L2_IN_ST_MACROVISION 0x01000000  /* Macrovision detected */
3087 +#define V4L2_IN_ST_NO_ACCESS   0x02000000  /* Conditional access denied */
3088 +#define V4L2_IN_ST_VTR         0x04000000  /* VTR time constant */
3089 +
3090 +/* capabilities flags */
3091 +#define V4L2_IN_CAP_PRESETS            0x00000001 /* Supports S_DV_PRESET */
3092 +#define V4L2_IN_CAP_CUSTOM_TIMINGS     0x00000002 /* Supports S_DV_TIMINGS */
3093 +#define V4L2_IN_CAP_STD                        0x00000004 /* Supports S_STD */
3094 +
3095 +/*
3096 + *     V I D E O   O U T P U T S
3097 + */
3098 +struct v4l2_output {
3099 +       __u32        index;             /*  Which output */
3100 +       __u8         name[32];          /*  Label */
3101 +       __u32        type;              /*  Type of output */
3102 +       __u32        audioset;          /*  Associated audios (bitfield) */
3103 +       __u32        modulator;         /*  Associated modulator */
3104 +       v4l2_std_id  std;
3105 +       __u32        capabilities;
3106 +       __u32        reserved[3];
3107 +};
3108 +/*  Values for the 'type' field */
3109 +#define V4L2_OUTPUT_TYPE_MODULATOR             1
3110 +#define V4L2_OUTPUT_TYPE_ANALOG                        2
3111 +#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY      3
3112 +
3113 +/* capabilities flags */
3114 +#define V4L2_OUT_CAP_PRESETS           0x00000001 /* Supports S_DV_PRESET */
3115 +#define V4L2_OUT_CAP_CUSTOM_TIMINGS    0x00000002 /* Supports S_DV_TIMINGS */
3116 +#define V4L2_OUT_CAP_STD               0x00000004 /* Supports S_STD */
3117 +
3118 +/*
3119 + *     C O N T R O L S
3120 + */
3121 +struct v4l2_control {
3122 +       __u32                id;
3123 +       __s32                value;
3124 +};
3125 +
3126 +struct v4l2_ext_control {
3127 +       __u32 id;
3128 +       __u32 size;
3129 +       __u32 reserved2[1];
3130 +       union {
3131 +               __s32 value;
3132 +               __s64 value64;
3133 +               char *string;
3134 +       };
3135 +} __attribute__ ((packed));
3136 +
3137 +struct v4l2_ext_controls {
3138 +       __u32 ctrl_class;
3139 +       __u32 count;
3140 +       __u32 error_idx;
3141 +       __u32 reserved[2];
3142 +       struct v4l2_ext_control *controls;
3143 +};
3144 +
3145 +/*  Values for ctrl_class field */
3146 +#define V4L2_CTRL_CLASS_USER 0x00980000        /* Old-style 'user' controls */
3147 +#define V4L2_CTRL_CLASS_MPEG 0x00990000        /* MPEG-compression controls */
3148 +#define V4L2_CTRL_CLASS_CAMERA 0x009a0000      /* Camera class controls */
3149 +#define V4L2_CTRL_CLASS_FM_TX 0x009b0000       /* FM Modulator control class */
3150 +
3151 +#define V4L2_CTRL_ID_MASK                (0x0fffffff)
3152 +#define V4L2_CTRL_ID2CLASS(id)    ((id) & 0x0fff0000UL)
3153 +#define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)
3154 +
3155 +enum v4l2_ctrl_type {
3156 +       V4L2_CTRL_TYPE_INTEGER       = 1,
3157 +       V4L2_CTRL_TYPE_BOOLEAN       = 2,
3158 +       V4L2_CTRL_TYPE_MENU          = 3,
3159 +       V4L2_CTRL_TYPE_BUTTON        = 4,
3160 +       V4L2_CTRL_TYPE_INTEGER64     = 5,
3161 +       V4L2_CTRL_TYPE_CTRL_CLASS    = 6,
3162 +       V4L2_CTRL_TYPE_STRING        = 7,
3163 +};
3164 +
3165 +/*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
3166 +struct v4l2_queryctrl {
3167 +       __u32                id;
3168 +       enum v4l2_ctrl_type  type;
3169 +       __u8                 name[32];  /* Whatever */
3170 +       __s32                minimum;   /* Note signedness */
3171 +       __s32                maximum;
3172 +       __s32                step;
3173 +       __s32                default_value;
3174 +       __u32                flags;
3175 +       __u32                reserved[2];
3176 +};
3177 +
3178 +/*  Used in the VIDIOC_QUERYMENU ioctl for querying menu items */
3179 +struct v4l2_querymenu {
3180 +       __u32           id;
3181 +       __u32           index;
3182 +       __u8            name[32];       /* Whatever */
3183 +       __u32           reserved;
3184 +};
3185 +
3186 +/*  Control flags  */
3187 +#define V4L2_CTRL_FLAG_DISABLED                0x0001
3188 +#define V4L2_CTRL_FLAG_GRABBED         0x0002
3189 +#define V4L2_CTRL_FLAG_READ_ONLY       0x0004
3190 +#define V4L2_CTRL_FLAG_UPDATE          0x0008
3191 +#define V4L2_CTRL_FLAG_INACTIVE        0x0010
3192 +#define V4L2_CTRL_FLAG_SLIDER          0x0020
3193 +#define V4L2_CTRL_FLAG_WRITE_ONLY      0x0040
3194 +
3195 +/*  Query flag, to be ORed with the control ID */
3196 +#define V4L2_CTRL_FLAG_NEXT_CTRL       0x80000000
3197 +
3198 +/*  User-class control IDs defined by V4L2 */
3199 +#define V4L2_CID_BASE                  (V4L2_CTRL_CLASS_USER | 0x900)
3200 +#define V4L2_CID_USER_BASE             V4L2_CID_BASE
3201 +/*  IDs reserved for driver specific controls */
3202 +#define V4L2_CID_PRIVATE_BASE          0x08000000
3203 +
3204 +#define V4L2_CID_USER_CLASS            (V4L2_CTRL_CLASS_USER | 1)
3205 +#define V4L2_CID_BRIGHTNESS            (V4L2_CID_BASE+0)
3206 +#define V4L2_CID_CONTRAST              (V4L2_CID_BASE+1)
3207 +#define V4L2_CID_SATURATION            (V4L2_CID_BASE+2)
3208 +#define V4L2_CID_HUE                   (V4L2_CID_BASE+3)
3209 +#define V4L2_CID_AUDIO_VOLUME          (V4L2_CID_BASE+5)
3210 +#define V4L2_CID_AUDIO_BALANCE         (V4L2_CID_BASE+6)
3211 +#define V4L2_CID_AUDIO_BASS            (V4L2_CID_BASE+7)
3212 +#define V4L2_CID_AUDIO_TREBLE          (V4L2_CID_BASE+8)
3213 +#define V4L2_CID_AUDIO_MUTE            (V4L2_CID_BASE+9)
3214 +#define V4L2_CID_AUDIO_LOUDNESS                (V4L2_CID_BASE+10)
3215 +#define V4L2_CID_BLACK_LEVEL           (V4L2_CID_BASE+11) /* Deprecated */
3216 +#define V4L2_CID_AUTO_WHITE_BALANCE    (V4L2_CID_BASE+12)
3217 +#define V4L2_CID_DO_WHITE_BALANCE      (V4L2_CID_BASE+13)
3218 +#define V4L2_CID_RED_BALANCE           (V4L2_CID_BASE+14)
3219 +#define V4L2_CID_BLUE_BALANCE          (V4L2_CID_BASE+15)
3220 +#define V4L2_CID_GAMMA                 (V4L2_CID_BASE+16)
3221 +#define V4L2_CID_WHITENESS             (V4L2_CID_GAMMA) /* Deprecated */
3222 +#define V4L2_CID_EXPOSURE              (V4L2_CID_BASE+17)
3223 +#define V4L2_CID_AUTOGAIN              (V4L2_CID_BASE+18)
3224 +#define V4L2_CID_GAIN                  (V4L2_CID_BASE+19)
3225 +#define V4L2_CID_HFLIP                 (V4L2_CID_BASE+20)
3226 +#define V4L2_CID_VFLIP                 (V4L2_CID_BASE+21)
3227 +
3228 +/* Deprecated; use V4L2_CID_PAN_RESET and V4L2_CID_TILT_RESET */
3229 +#define V4L2_CID_HCENTER               (V4L2_CID_BASE+22)
3230 +#define V4L2_CID_VCENTER               (V4L2_CID_BASE+23)
3231 +
3232 +#define V4L2_CID_POWER_LINE_FREQUENCY  (V4L2_CID_BASE+24)
3233 +enum v4l2_power_line_frequency {
3234 +       V4L2_CID_POWER_LINE_FREQUENCY_DISABLED  = 0,
3235 +       V4L2_CID_POWER_LINE_FREQUENCY_50HZ      = 1,
3236 +       V4L2_CID_POWER_LINE_FREQUENCY_60HZ      = 2,
3237 +};
3238 +#define V4L2_CID_HUE_AUTO                      (V4L2_CID_BASE+25)
3239 +#define V4L2_CID_WHITE_BALANCE_TEMPERATURE     (V4L2_CID_BASE+26)
3240 +#define V4L2_CID_SHARPNESS                     (V4L2_CID_BASE+27)
3241 +#define V4L2_CID_BACKLIGHT_COMPENSATION        (V4L2_CID_BASE+28)
3242 +#define V4L2_CID_CHROMA_AGC                     (V4L2_CID_BASE+29)
3243 +#define V4L2_CID_COLOR_KILLER                   (V4L2_CID_BASE+30)
3244 +#define V4L2_CID_COLORFX                       (V4L2_CID_BASE+31)
3245 +enum v4l2_colorfx {
3246 +       V4L2_COLORFX_NONE       = 0,
3247 +       V4L2_COLORFX_BW         = 1,
3248 +       V4L2_COLORFX_SEPIA      = 2,
3249 +       V4L2_COLORFX_NEGATIVE = 3,
3250 +       V4L2_COLORFX_EMBOSS = 4,
3251 +       V4L2_COLORFX_SKETCH = 5,
3252 +       V4L2_COLORFX_SKY_BLUE = 6,
3253 +       V4L2_COLORFX_GRASS_GREEN = 7,
3254 +       V4L2_COLORFX_SKIN_WHITEN = 8,
3255 +       V4L2_COLORFX_VIVID = 9,
3256 +};
3257 +#define V4L2_CID_AUTOBRIGHTNESS                        (V4L2_CID_BASE+32)
3258 +#define V4L2_CID_BAND_STOP_FILTER              (V4L2_CID_BASE+33)
3259 +
3260 +#define V4L2_CID_ROTATE                                (V4L2_CID_BASE+34)
3261 +#define V4L2_CID_BG_COLOR                      (V4L2_CID_BASE+35)
3262 +
3263 +#define V4L2_CID_CHROMA_GAIN                    (V4L2_CID_BASE+36)
3264 +
3265 +#define V4L2_CID_ILLUMINATORS_1                        (V4L2_CID_BASE+37)
3266 +#define V4L2_CID_ILLUMINATORS_2                        (V4L2_CID_BASE+38)
3267 +
3268 +/* last CID + 1 */
3269 +#define V4L2_CID_LASTP1                         (V4L2_CID_BASE+39)
3270 +
3271 +/*  MPEG-class control IDs defined by V4L2 */
3272 +#define V4L2_CID_MPEG_BASE                     (V4L2_CTRL_CLASS_MPEG | 0x900)
3273 +#define V4L2_CID_MPEG_CLASS                    (V4L2_CTRL_CLASS_MPEG | 1)
3274 +
3275 +/*  MPEG streams */
3276 +#define V4L2_CID_MPEG_STREAM_TYPE              (V4L2_CID_MPEG_BASE+0)
3277 +enum v4l2_mpeg_stream_type {
3278 +       V4L2_MPEG_STREAM_TYPE_MPEG2_PS   = 0, /* MPEG-2 program stream */
3279 +       V4L2_MPEG_STREAM_TYPE_MPEG2_TS   = 1, /* MPEG-2 transport stream */
3280 +       V4L2_MPEG_STREAM_TYPE_MPEG1_SS   = 2, /* MPEG-1 system stream */
3281 +       V4L2_MPEG_STREAM_TYPE_MPEG2_DVD  = 3, /* MPEG-2 DVD-compatible stream */
3282 +       V4L2_MPEG_STREAM_TYPE_MPEG1_VCD  = 4, /* MPEG-1 VCD-compatible stream */
3283 +       V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD = 5, /* MPEG-2 SVCD-compatible stream */
3284 +};
3285 +#define V4L2_CID_MPEG_STREAM_PID_PMT           (V4L2_CID_MPEG_BASE+1)
3286 +#define V4L2_CID_MPEG_STREAM_PID_AUDIO                 (V4L2_CID_MPEG_BASE+2)
3287 +#define V4L2_CID_MPEG_STREAM_PID_VIDEO                 (V4L2_CID_MPEG_BASE+3)
3288 +#define V4L2_CID_MPEG_STREAM_PID_PCR           (V4L2_CID_MPEG_BASE+4)
3289 +#define V4L2_CID_MPEG_STREAM_PES_ID_AUDIO      (V4L2_CID_MPEG_BASE+5)
3290 +#define V4L2_CID_MPEG_STREAM_PES_ID_VIDEO      (V4L2_CID_MPEG_BASE+6)
3291 +#define V4L2_CID_MPEG_STREAM_VBI_FMT           (V4L2_CID_MPEG_BASE+7)
3292 +enum v4l2_mpeg_stream_vbi_fmt {
3293 +       V4L2_MPEG_STREAM_VBI_FMT_NONE = 0,  /* No VBI in the MPEG stream */
3294 +       V4L2_MPEG_STREAM_VBI_FMT_IVTV = 1,  /* VBI in private packets, IVTV format */
3295 +};
3296 +
3297 +/*  MPEG audio */
3298 +#define V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ      (V4L2_CID_MPEG_BASE+100)
3299 +enum v4l2_mpeg_audio_sampling_freq {
3300 +       V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100 = 0,
3301 +       V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000 = 1,
3302 +       V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000 = 2,
3303 +};
3304 +#define V4L2_CID_MPEG_AUDIO_ENCODING           (V4L2_CID_MPEG_BASE+101)
3305 +enum v4l2_mpeg_audio_encoding {
3306 +       V4L2_MPEG_AUDIO_ENCODING_LAYER_1 = 0,
3307 +       V4L2_MPEG_AUDIO_ENCODING_LAYER_2 = 1,
3308 +       V4L2_MPEG_AUDIO_ENCODING_LAYER_3 = 2,
3309 +       V4L2_MPEG_AUDIO_ENCODING_AAC     = 3,
3310 +       V4L2_MPEG_AUDIO_ENCODING_AC3     = 4,
3311 +};
3312 +#define V4L2_CID_MPEG_AUDIO_L1_BITRATE                 (V4L2_CID_MPEG_BASE+102)
3313 +enum v4l2_mpeg_audio_l1_bitrate {
3314 +       V4L2_MPEG_AUDIO_L1_BITRATE_32K  = 0,
3315 +       V4L2_MPEG_AUDIO_L1_BITRATE_64K  = 1,
3316 +       V4L2_MPEG_AUDIO_L1_BITRATE_96K  = 2,
3317 +       V4L2_MPEG_AUDIO_L1_BITRATE_128K = 3,
3318 +       V4L2_MPEG_AUDIO_L1_BITRATE_160K = 4,
3319 +       V4L2_MPEG_AUDIO_L1_BITRATE_192K = 5,
3320 +       V4L2_MPEG_AUDIO_L1_BITRATE_224K = 6,
3321 +       V4L2_MPEG_AUDIO_L1_BITRATE_256K = 7,
3322 +       V4L2_MPEG_AUDIO_L1_BITRATE_288K = 8,
3323 +       V4L2_MPEG_AUDIO_L1_BITRATE_320K = 9,
3324 +       V4L2_MPEG_AUDIO_L1_BITRATE_352K = 10,
3325 +       V4L2_MPEG_AUDIO_L1_BITRATE_384K = 11,
3326 +       V4L2_MPEG_AUDIO_L1_BITRATE_416K = 12,
3327 +       V4L2_MPEG_AUDIO_L1_BITRATE_448K = 13,
3328 +};
3329 +#define V4L2_CID_MPEG_AUDIO_L2_BITRATE                 (V4L2_CID_MPEG_BASE+103)
3330 +enum v4l2_mpeg_audio_l2_bitrate {
3331 +       V4L2_MPEG_AUDIO_L2_BITRATE_32K  = 0,
3332 +       V4L2_MPEG_AUDIO_L2_BITRATE_48K  = 1,
3333 +       V4L2_MPEG_AUDIO_L2_BITRATE_56K  = 2,
3334 +       V4L2_MPEG_AUDIO_L2_BITRATE_64K  = 3,
3335 +       V4L2_MPEG_AUDIO_L2_BITRATE_80K  = 4,
3336 +       V4L2_MPEG_AUDIO_L2_BITRATE_96K  = 5,
3337 +       V4L2_MPEG_AUDIO_L2_BITRATE_112K = 6,
3338 +       V4L2_MPEG_AUDIO_L2_BITRATE_128K = 7,
3339 +       V4L2_MPEG_AUDIO_L2_BITRATE_160K = 8,
3340 +       V4L2_MPEG_AUDIO_L2_BITRATE_192K = 9,
3341 +       V4L2_MPEG_AUDIO_L2_BITRATE_224K = 10,
3342 +       V4L2_MPEG_AUDIO_L2_BITRATE_256K = 11,
3343 +       V4L2_MPEG_AUDIO_L2_BITRATE_320K = 12,
3344 +       V4L2_MPEG_AUDIO_L2_BITRATE_384K = 13,
3345 +};
3346 +#define V4L2_CID_MPEG_AUDIO_L3_BITRATE                 (V4L2_CID_MPEG_BASE+104)
3347 +enum v4l2_mpeg_audio_l3_bitrate {
3348 +       V4L2_MPEG_AUDIO_L3_BITRATE_32K  = 0,
3349 +       V4L2_MPEG_AUDIO_L3_BITRATE_40K  = 1,
3350 +       V4L2_MPEG_AUDIO_L3_BITRATE_48K  = 2,
3351 +       V4L2_MPEG_AUDIO_L3_BITRATE_56K  = 3,
3352 +       V4L2_MPEG_AUDIO_L3_BITRATE_64K  = 4,
3353 +       V4L2_MPEG_AUDIO_L3_BITRATE_80K  = 5,
3354 +       V4L2_MPEG_AUDIO_L3_BITRATE_96K  = 6,
3355 +       V4L2_MPEG_AUDIO_L3_BITRATE_112K = 7,
3356 +       V4L2_MPEG_AUDIO_L3_BITRATE_128K = 8,
3357 +       V4L2_MPEG_AUDIO_L3_BITRATE_160K = 9,
3358 +       V4L2_MPEG_AUDIO_L3_BITRATE_192K = 10,
3359 +       V4L2_MPEG_AUDIO_L3_BITRATE_224K = 11,
3360 +       V4L2_MPEG_AUDIO_L3_BITRATE_256K = 12,
3361 +       V4L2_MPEG_AUDIO_L3_BITRATE_320K = 13,
3362 +};
3363 +#define V4L2_CID_MPEG_AUDIO_MODE               (V4L2_CID_MPEG_BASE+105)
3364 +enum v4l2_mpeg_audio_mode {
3365 +       V4L2_MPEG_AUDIO_MODE_STEREO       = 0,
3366 +       V4L2_MPEG_AUDIO_MODE_JOINT_STEREO = 1,
3367 +       V4L2_MPEG_AUDIO_MODE_DUAL         = 2,
3368 +       V4L2_MPEG_AUDIO_MODE_MONO         = 3,
3369 +};
3370 +#define V4L2_CID_MPEG_AUDIO_MODE_EXTENSION     (V4L2_CID_MPEG_BASE+106)
3371 +enum v4l2_mpeg_audio_mode_extension {
3372 +       V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4  = 0,
3373 +       V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8  = 1,
3374 +       V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12 = 2,
3375 +       V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16 = 3,
3376 +};
3377 +#define V4L2_CID_MPEG_AUDIO_EMPHASIS           (V4L2_CID_MPEG_BASE+107)
3378 +enum v4l2_mpeg_audio_emphasis {
3379 +       V4L2_MPEG_AUDIO_EMPHASIS_NONE         = 0,
3380 +       V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS = 1,
3381 +       V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17    = 2,
3382 +};
3383 +#define V4L2_CID_MPEG_AUDIO_CRC                (V4L2_CID_MPEG_BASE+108)
3384 +enum v4l2_mpeg_audio_crc {
3385 +       V4L2_MPEG_AUDIO_CRC_NONE  = 0,
3386 +       V4L2_MPEG_AUDIO_CRC_CRC16 = 1,
3387 +};
3388 +#define V4L2_CID_MPEG_AUDIO_MUTE               (V4L2_CID_MPEG_BASE+109)
3389 +#define V4L2_CID_MPEG_AUDIO_AAC_BITRATE                (V4L2_CID_MPEG_BASE+110)
3390 +#define V4L2_CID_MPEG_AUDIO_AC3_BITRATE                (V4L2_CID_MPEG_BASE+111)
3391 +enum v4l2_mpeg_audio_ac3_bitrate {
3392 +       V4L2_MPEG_AUDIO_AC3_BITRATE_32K  = 0,
3393 +       V4L2_MPEG_AUDIO_AC3_BITRATE_40K  = 1,
3394 +       V4L2_MPEG_AUDIO_AC3_BITRATE_48K  = 2,
3395 +       V4L2_MPEG_AUDIO_AC3_BITRATE_56K  = 3,
3396 +       V4L2_MPEG_AUDIO_AC3_BITRATE_64K  = 4,
3397 +       V4L2_MPEG_AUDIO_AC3_BITRATE_80K  = 5,
3398 +       V4L2_MPEG_AUDIO_AC3_BITRATE_96K  = 6,
3399 +       V4L2_MPEG_AUDIO_AC3_BITRATE_112K = 7,
3400 +       V4L2_MPEG_AUDIO_AC3_BITRATE_128K = 8,
3401 +       V4L2_MPEG_AUDIO_AC3_BITRATE_160K = 9,
3402 +       V4L2_MPEG_AUDIO_AC3_BITRATE_192K = 10,
3403 +       V4L2_MPEG_AUDIO_AC3_BITRATE_224K = 11,
3404 +       V4L2_MPEG_AUDIO_AC3_BITRATE_256K = 12,
3405 +       V4L2_MPEG_AUDIO_AC3_BITRATE_320K = 13,
3406 +       V4L2_MPEG_AUDIO_AC3_BITRATE_384K = 14,
3407 +       V4L2_MPEG_AUDIO_AC3_BITRATE_448K = 15,
3408 +       V4L2_MPEG_AUDIO_AC3_BITRATE_512K = 16,
3409 +       V4L2_MPEG_AUDIO_AC3_BITRATE_576K = 17,
3410 +       V4L2_MPEG_AUDIO_AC3_BITRATE_640K = 18,
3411 +};
3412 +
3413 +/*  MPEG video */
3414 +#define V4L2_CID_MPEG_VIDEO_ENCODING           (V4L2_CID_MPEG_BASE+200)
3415 +enum v4l2_mpeg_video_encoding {
3416 +       V4L2_MPEG_VIDEO_ENCODING_MPEG_1     = 0,
3417 +       V4L2_MPEG_VIDEO_ENCODING_MPEG_2     = 1,
3418 +       V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC = 2,
3419 +};
3420 +#define V4L2_CID_MPEG_VIDEO_ASPECT             (V4L2_CID_MPEG_BASE+201)
3421 +enum v4l2_mpeg_video_aspect {
3422 +       V4L2_MPEG_VIDEO_ASPECT_1x1     = 0,
3423 +       V4L2_MPEG_VIDEO_ASPECT_4x3     = 1,
3424 +       V4L2_MPEG_VIDEO_ASPECT_16x9    = 2,
3425 +       V4L2_MPEG_VIDEO_ASPECT_221x100 = 3,
3426 +};
3427 +#define V4L2_CID_MPEG_VIDEO_B_FRAMES           (V4L2_CID_MPEG_BASE+202)
3428 +#define V4L2_CID_MPEG_VIDEO_GOP_SIZE           (V4L2_CID_MPEG_BASE+203)
3429 +#define V4L2_CID_MPEG_VIDEO_GOP_CLOSURE        (V4L2_CID_MPEG_BASE+204)
3430 +#define V4L2_CID_MPEG_VIDEO_PULLDOWN           (V4L2_CID_MPEG_BASE+205)
3431 +#define V4L2_CID_MPEG_VIDEO_BITRATE_MODE       (V4L2_CID_MPEG_BASE+206)
3432 +enum v4l2_mpeg_video_bitrate_mode {
3433 +       V4L2_MPEG_VIDEO_BITRATE_MODE_VBR = 0,
3434 +       V4L2_MPEG_VIDEO_BITRATE_MODE_CBR = 1,
3435 +};
3436 +#define V4L2_CID_MPEG_VIDEO_BITRATE            (V4L2_CID_MPEG_BASE+207)
3437 +#define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK       (V4L2_CID_MPEG_BASE+208)
3438 +#define V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (V4L2_CID_MPEG_BASE+209)
3439 +#define V4L2_CID_MPEG_VIDEO_MUTE               (V4L2_CID_MPEG_BASE+210)
3440 +#define V4L2_CID_MPEG_VIDEO_MUTE_YUV           (V4L2_CID_MPEG_BASE+211)
3441 +
3442 +/*  MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */
3443 +#define V4L2_CID_MPEG_CX2341X_BASE                             (V4L2_CTRL_CLASS_MPEG | 0x1000)
3444 +#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE        (V4L2_CID_MPEG_CX2341X_BASE+0)
3445 +enum v4l2_mpeg_cx2341x_video_spatial_filter_mode {
3446 +       V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL = 0,
3447 +       V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO   = 1,
3448 +};
3449 +#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER             (V4L2_CID_MPEG_CX2341X_BASE+1)
3450 +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE   (V4L2_CID_MPEG_CX2341X_BASE+2)
3451 +enum v4l2_mpeg_cx2341x_video_luma_spatial_filter_type {
3452 +       V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF                  = 0,
3453 +       V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR               = 1,
3454 +       V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT              = 2,
3455 +       V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE      = 3,
3456 +       V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE = 4,
3457 +};
3458 +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE         (V4L2_CID_MPEG_CX2341X_BASE+3)
3459 +enum v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type {
3460 +       V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF    = 0,
3461 +       V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR = 1,
3462 +};
3463 +#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE       (V4L2_CID_MPEG_CX2341X_BASE+4)
3464 +enum v4l2_mpeg_cx2341x_video_temporal_filter_mode {
3465 +       V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL = 0,
3466 +       V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO   = 1,
3467 +};
3468 +#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER            (V4L2_CID_MPEG_CX2341X_BASE+5)
3469 +#define V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE                 (V4L2_CID_MPEG_CX2341X_BASE+6)
3470 +enum v4l2_mpeg_cx2341x_video_median_filter_type {
3471 +       V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF      = 0,
3472 +       V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR      = 1,
3473 +       V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT     = 2,
3474 +       V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT = 3,
3475 +       V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG     = 4,
3476 +};
3477 +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM  (V4L2_CID_MPEG_CX2341X_BASE+7)
3478 +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP     (V4L2_CID_MPEG_CX2341X_BASE+8)
3479 +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM        (V4L2_CID_MPEG_CX2341X_BASE+9)
3480 +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP   (V4L2_CID_MPEG_CX2341X_BASE+10)
3481 +#define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS        (V4L2_CID_MPEG_CX2341X_BASE+11)
3482 +
3483 +/*  Camera class control IDs */
3484 +#define V4L2_CID_CAMERA_CLASS_BASE     (V4L2_CTRL_CLASS_CAMERA | 0x900)
3485 +#define V4L2_CID_CAMERA_CLASS          (V4L2_CTRL_CLASS_CAMERA | 1)
3486 +
3487 +#define V4L2_CID_EXPOSURE_AUTO                 (V4L2_CID_CAMERA_CLASS_BASE+1)
3488 +enum  v4l2_exposure_auto_type {
3489 +       V4L2_EXPOSURE_AUTO = 0,
3490 +       V4L2_EXPOSURE_MANUAL = 1,
3491 +       V4L2_EXPOSURE_SHUTTER_PRIORITY = 2,
3492 +       V4L2_EXPOSURE_APERTURE_PRIORITY = 3
3493 +};
3494 +#define V4L2_CID_EXPOSURE_ABSOLUTE             (V4L2_CID_CAMERA_CLASS_BASE+2)
3495 +#define V4L2_CID_EXPOSURE_AUTO_PRIORITY                (V4L2_CID_CAMERA_CLASS_BASE+3)
3496 +
3497 +#define V4L2_CID_PAN_RELATIVE                  (V4L2_CID_CAMERA_CLASS_BASE+4)
3498 +#define V4L2_CID_TILT_RELATIVE                 (V4L2_CID_CAMERA_CLASS_BASE+5)
3499 +#define V4L2_CID_PAN_RESET                     (V4L2_CID_CAMERA_CLASS_BASE+6)
3500 +#define V4L2_CID_TILT_RESET                    (V4L2_CID_CAMERA_CLASS_BASE+7)
3501 +
3502 +#define V4L2_CID_PAN_ABSOLUTE                  (V4L2_CID_CAMERA_CLASS_BASE+8)
3503 +#define V4L2_CID_TILT_ABSOLUTE                 (V4L2_CID_CAMERA_CLASS_BASE+9)
3504 +
3505 +#define V4L2_CID_FOCUS_ABSOLUTE                        (V4L2_CID_CAMERA_CLASS_BASE+10)
3506 +#define V4L2_CID_FOCUS_RELATIVE                        (V4L2_CID_CAMERA_CLASS_BASE+11)
3507 +#define V4L2_CID_FOCUS_AUTO                    (V4L2_CID_CAMERA_CLASS_BASE+12)
3508 +
3509 +#define V4L2_CID_ZOOM_ABSOLUTE                 (V4L2_CID_CAMERA_CLASS_BASE+13)
3510 +#define V4L2_CID_ZOOM_RELATIVE                 (V4L2_CID_CAMERA_CLASS_BASE+14)
3511 +#define V4L2_CID_ZOOM_CONTINUOUS               (V4L2_CID_CAMERA_CLASS_BASE+15)
3512 +
3513 +#define V4L2_CID_PRIVACY                       (V4L2_CID_CAMERA_CLASS_BASE+16)
3514 +
3515 +#define V4L2_CID_IRIS_ABSOLUTE                 (V4L2_CID_CAMERA_CLASS_BASE+17)
3516 +#define V4L2_CID_IRIS_RELATIVE                 (V4L2_CID_CAMERA_CLASS_BASE+18)
3517 +
3518 +/* FM Modulator class control IDs */
3519 +#define V4L2_CID_FM_TX_CLASS_BASE              (V4L2_CTRL_CLASS_FM_TX | 0x900)
3520 +#define V4L2_CID_FM_TX_CLASS                   (V4L2_CTRL_CLASS_FM_TX | 1)
3521 +
3522 +#define V4L2_CID_RDS_TX_DEVIATION              (V4L2_CID_FM_TX_CLASS_BASE + 1)
3523 +#define V4L2_CID_RDS_TX_PI                     (V4L2_CID_FM_TX_CLASS_BASE + 2)
3524 +#define V4L2_CID_RDS_TX_PTY                    (V4L2_CID_FM_TX_CLASS_BASE + 3)
3525 +#define V4L2_CID_RDS_TX_PS_NAME                        (V4L2_CID_FM_TX_CLASS_BASE + 5)
3526 +#define V4L2_CID_RDS_TX_RADIO_TEXT             (V4L2_CID_FM_TX_CLASS_BASE + 6)
3527 +
3528 +#define V4L2_CID_AUDIO_LIMITER_ENABLED         (V4L2_CID_FM_TX_CLASS_BASE + 64)
3529 +#define V4L2_CID_AUDIO_LIMITER_RELEASE_TIME    (V4L2_CID_FM_TX_CLASS_BASE + 65)
3530 +#define V4L2_CID_AUDIO_LIMITER_DEVIATION       (V4L2_CID_FM_TX_CLASS_BASE + 66)
3531 +
3532 +#define V4L2_CID_AUDIO_COMPRESSION_ENABLED     (V4L2_CID_FM_TX_CLASS_BASE + 80)
3533 +#define V4L2_CID_AUDIO_COMPRESSION_GAIN                (V4L2_CID_FM_TX_CLASS_BASE + 81)
3534 +#define V4L2_CID_AUDIO_COMPRESSION_THRESHOLD   (V4L2_CID_FM_TX_CLASS_BASE + 82)
3535 +#define V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME (V4L2_CID_FM_TX_CLASS_BASE + 83)
3536 +#define V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME        (V4L2_CID_FM_TX_CLASS_BASE + 84)
3537 +
3538 +#define V4L2_CID_PILOT_TONE_ENABLED            (V4L2_CID_FM_TX_CLASS_BASE + 96)
3539 +#define V4L2_CID_PILOT_TONE_DEVIATION          (V4L2_CID_FM_TX_CLASS_BASE + 97)
3540 +#define V4L2_CID_PILOT_TONE_FREQUENCY          (V4L2_CID_FM_TX_CLASS_BASE + 98)
3541 +
3542 +#define V4L2_CID_TUNE_PREEMPHASIS              (V4L2_CID_FM_TX_CLASS_BASE + 112)
3543 +enum v4l2_preemphasis {
3544 +       V4L2_PREEMPHASIS_DISABLED       = 0,
3545 +       V4L2_PREEMPHASIS_50_uS          = 1,
3546 +       V4L2_PREEMPHASIS_75_uS          = 2,
3547 +};
3548 +#define V4L2_CID_TUNE_POWER_LEVEL              (V4L2_CID_FM_TX_CLASS_BASE + 113)
3549 +#define V4L2_CID_TUNE_ANTENNA_CAPACITOR                (V4L2_CID_FM_TX_CLASS_BASE + 114)
3550 +
3551 +/*
3552 + *     T U N I N G
3553 + */
3554 +struct v4l2_tuner {
3555 +       __u32                   index;
3556 +       __u8                    name[32];
3557 +       enum v4l2_tuner_type    type;
3558 +       __u32                   capability;
3559 +       __u32                   rangelow;
3560 +       __u32                   rangehigh;
3561 +       __u32                   rxsubchans;
3562 +       __u32                   audmode;
3563 +       __s32                   signal;
3564 +       __s32                   afc;
3565 +       __u32                   reserved[4];
3566 +};
3567 +
3568 +struct v4l2_modulator {
3569 +       __u32                   index;
3570 +       __u8                    name[32];
3571 +       __u32                   capability;
3572 +       __u32                   rangelow;
3573 +       __u32                   rangehigh;
3574 +       __u32                   txsubchans;
3575 +       __u32                   reserved[4];
3576 +};
3577 +
3578 +/*  Flags for the 'capability' field */
3579 +#define V4L2_TUNER_CAP_LOW             0x0001
3580 +#define V4L2_TUNER_CAP_NORM            0x0002
3581 +#define V4L2_TUNER_CAP_STEREO          0x0010
3582 +#define V4L2_TUNER_CAP_LANG2           0x0020
3583 +#define V4L2_TUNER_CAP_SAP             0x0020
3584 +#define V4L2_TUNER_CAP_LANG1           0x0040
3585 +#define V4L2_TUNER_CAP_RDS             0x0080
3586 +#define V4L2_TUNER_CAP_RDS_BLOCK_IO    0x0100
3587 +#define V4L2_TUNER_CAP_RDS_CONTROLS    0x0200
3588 +
3589 +/*  Flags for the 'rxsubchans' field */
3590 +#define V4L2_TUNER_SUB_MONO            0x0001
3591 +#define V4L2_TUNER_SUB_STEREO          0x0002
3592 +#define V4L2_TUNER_SUB_LANG2           0x0004
3593 +#define V4L2_TUNER_SUB_SAP             0x0004
3594 +#define V4L2_TUNER_SUB_LANG1           0x0008
3595 +#define V4L2_TUNER_SUB_RDS             0x0010
3596 +
3597 +/*  Values for the 'audmode' field */
3598 +#define V4L2_TUNER_MODE_MONO           0x0000
3599 +#define V4L2_TUNER_MODE_STEREO         0x0001
3600 +#define V4L2_TUNER_MODE_LANG2          0x0002
3601 +#define V4L2_TUNER_MODE_SAP            0x0002
3602 +#define V4L2_TUNER_MODE_LANG1          0x0003
3603 +#define V4L2_TUNER_MODE_LANG1_LANG2    0x0004
3604 +
3605 +struct v4l2_frequency {
3606 +       __u32                 tuner;
3607 +       enum v4l2_tuner_type  type;
3608 +       __u32                 frequency;
3609 +       __u32                 reserved[8];
3610 +};
3611 +
3612 +struct v4l2_hw_freq_seek {
3613 +       __u32                 tuner;
3614 +       enum v4l2_tuner_type  type;
3615 +       __u32                 seek_upward;
3616 +       __u32                 wrap_around;
3617 +       __u32                 spacing;
3618 +       __u32                 reserved[7];
3619 +};
3620 +
3621 +/*
3622 + *     R D S
3623 + */
3624 +
3625 +struct v4l2_rds_data {
3626 +       __u8    lsb;
3627 +       __u8    msb;
3628 +       __u8    block;
3629 +} __attribute__ ((packed));
3630 +
3631 +#define V4L2_RDS_BLOCK_MSK      0x7
3632 +#define V4L2_RDS_BLOCK_A        0
3633 +#define V4L2_RDS_BLOCK_B        1
3634 +#define V4L2_RDS_BLOCK_C        2
3635 +#define V4L2_RDS_BLOCK_D        3
3636 +#define V4L2_RDS_BLOCK_C_ALT    4
3637 +#define V4L2_RDS_BLOCK_INVALID          7
3638 +
3639 +#define V4L2_RDS_BLOCK_CORRECTED 0x40
3640 +#define V4L2_RDS_BLOCK_ERROR    0x80
3641 +
3642 +/*
3643 + *     A U D I O
3644 + */
3645 +struct v4l2_audio {
3646 +       __u32   index;
3647 +       __u8    name[32];
3648 +       __u32   capability;
3649 +       __u32   mode;
3650 +       __u32   reserved[2];
3651 +};
3652 +
3653 +/*  Flags for the 'capability' field */
3654 +#define V4L2_AUDCAP_STEREO             0x00001
3655 +#define V4L2_AUDCAP_AVL                        0x00002
3656 +
3657 +/*  Flags for the 'mode' field */
3658 +#define V4L2_AUDMODE_AVL               0x00001
3659 +
3660 +struct v4l2_audioout {
3661 +       __u32   index;
3662 +       __u8    name[32];
3663 +       __u32   capability;
3664 +       __u32   mode;
3665 +       __u32   reserved[2];
3666 +};
3667 +
3668 +/*
3669 + *     M P E G   S E R V I C E S
3670 + *
3671 + *     NOTE: EXPERIMENTAL API
3672 + */
3673 +#if 1
3674 +#define V4L2_ENC_IDX_FRAME_I    (0)
3675 +#define V4L2_ENC_IDX_FRAME_P    (1)
3676 +#define V4L2_ENC_IDX_FRAME_B    (2)
3677 +#define V4L2_ENC_IDX_FRAME_MASK (0xf)
3678 +
3679 +struct v4l2_enc_idx_entry {
3680 +       __u64 offset;
3681 +       __u64 pts;
3682 +       __u32 length;
3683 +       __u32 flags;
3684 +       __u32 reserved[2];
3685 +};
3686 +
3687 +#define V4L2_ENC_IDX_ENTRIES (64)
3688 +struct v4l2_enc_idx {
3689 +       __u32 entries;
3690 +       __u32 entries_cap;
3691 +       __u32 reserved[4];
3692 +       struct v4l2_enc_idx_entry entry[V4L2_ENC_IDX_ENTRIES];
3693 +};
3694 +
3695 +
3696 +#define V4L2_ENC_CMD_START      (0)
3697 +#define V4L2_ENC_CMD_STOP       (1)
3698 +#define V4L2_ENC_CMD_PAUSE      (2)
3699 +#define V4L2_ENC_CMD_RESUME     (3)
3700 +
3701 +/* Flags for V4L2_ENC_CMD_STOP */
3702 +#define V4L2_ENC_CMD_STOP_AT_GOP_END    (1 << 0)
3703 +
3704 +struct v4l2_encoder_cmd {
3705 +       __u32 cmd;
3706 +       __u32 flags;
3707 +       union {
3708 +               struct {
3709 +                       __u32 data[8];
3710 +               } raw;
3711 +       };
3712 +};
3713 +
3714 +#endif
3715 +
3716 +
3717 +/*
3718 + *     D A T A   S E R V I C E S   ( V B I )
3719 + *
3720 + *     Data services API by Michael Schimek
3721 + */
3722 +
3723 +/* Raw VBI */
3724 +struct v4l2_vbi_format {
3725 +       __u32   sampling_rate;          /* in 1 Hz */
3726 +       __u32   offset;
3727 +       __u32   samples_per_line;
3728 +       __u32   sample_format;          /* V4L2_PIX_FMT_* */
3729 +       __s32   start[2];
3730 +       __u32   count[2];
3731 +       __u32   flags;                  /* V4L2_VBI_* */
3732 +       __u32   reserved[2];            /* must be zero */
3733 +};
3734 +
3735 +/*  VBI flags  */
3736 +#define V4L2_VBI_UNSYNC                (1 << 0)
3737 +#define V4L2_VBI_INTERLACED    (1 << 1)
3738 +
3739 +/* Sliced VBI
3740 + *
3741 + *    This implements is a proposal V4L2 API to allow SLICED VBI
3742 + * required for some hardware encoders. It should change without
3743 + * notice in the definitive implementation.
3744 + */
3745 +
3746 +struct v4l2_sliced_vbi_format {
3747 +       __u16   service_set;
3748 +       /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field
3749 +          service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field
3750 +                                (equals frame lines 313-336 for 625 line video
3751 +                                 standards, 263-286 for 525 line standards) */
3752 +       __u16   service_lines[2][24];
3753 +       __u32   io_size;
3754 +       __u32   reserved[2];            /* must be zero */
3755 +};
3756 +
3757 +/* Teletext World System Teletext
3758 +   (WST), defined on ITU-R BT.653-2 */
3759 +#define V4L2_SLICED_TELETEXT_B          (0x0001)
3760 +/* Video Program System, defined on ETS 300 231*/
3761 +#define V4L2_SLICED_VPS                 (0x0400)
3762 +/* Closed Caption, defined on EIA-608 */
3763 +#define V4L2_SLICED_CAPTION_525         (0x1000)
3764 +/* Wide Screen System, defined on ITU-R BT1119.1 */
3765 +#define V4L2_SLICED_WSS_625             (0x4000)
3766 +
3767 +#define V4L2_SLICED_VBI_525             (V4L2_SLICED_CAPTION_525)
3768 +#define V4L2_SLICED_VBI_625             (V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625)
3769 +
3770 +struct v4l2_sliced_vbi_cap {
3771 +       __u16   service_set;
3772 +       /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field
3773 +          service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field
3774 +                                (equals frame lines 313-336 for 625 line video
3775 +                                 standards, 263-286 for 525 line standards) */
3776 +       __u16   service_lines[2][24];
3777 +       enum v4l2_buf_type type;
3778 +       __u32   reserved[3];    /* must be 0 */
3779 +};
3780 +
3781 +struct v4l2_sliced_vbi_data {
3782 +       __u32   id;
3783 +       __u32   field;          /* 0: first field, 1: second field */
3784 +       __u32   line;           /* 1-23 */
3785 +       __u32   reserved;       /* must be 0 */
3786 +       __u8    data[48];
3787 +};
3788 +
3789 +/*
3790 + * Sliced VBI data inserted into MPEG Streams
3791 + */
3792 +
3793 +/*
3794 + * V4L2_MPEG_STREAM_VBI_FMT_IVTV:
3795 + *
3796 + * Structure of payload contained in an MPEG 2 Private Stream 1 PES Packet in an
3797 + * MPEG-2 Program Pack that contains V4L2_MPEG_STREAM_VBI_FMT_IVTV Sliced VBI
3798 + * data
3799 + *
3800 + * Note, the MPEG-2 Program Pack and Private Stream 1 PES packet header
3801 + * definitions are not included here.  See the MPEG-2 specifications for details
3802 + * on these headers.
3803 + */
3804 +
3805 +/* Line type IDs */
3806 +#define V4L2_MPEG_VBI_IVTV_TELETEXT_B     (1)
3807 +#define V4L2_MPEG_VBI_IVTV_CAPTION_525    (4)
3808 +#define V4L2_MPEG_VBI_IVTV_WSS_625        (5)
3809 +#define V4L2_MPEG_VBI_IVTV_VPS            (7)
3810 +
3811 +struct v4l2_mpeg_vbi_itv0_line {
3812 +       __u8 id;        /* One of V4L2_MPEG_VBI_IVTV_* above */
3813 +       __u8 data[42];  /* Sliced VBI data for the line */
3814 +} __attribute__ ((packed));
3815 +
3816 +struct v4l2_mpeg_vbi_itv0 {
3817 +       __le32 linemask[2]; /* Bitmasks of VBI service lines present */
3818 +       struct v4l2_mpeg_vbi_itv0_line line[35];
3819 +} __attribute__ ((packed));
3820 +
3821 +struct v4l2_mpeg_vbi_ITV0 {
3822 +       struct v4l2_mpeg_vbi_itv0_line line[36];
3823 +} __attribute__ ((packed));
3824 +
3825 +#define V4L2_MPEG_VBI_IVTV_MAGIC0      "itv0"
3826 +#define V4L2_MPEG_VBI_IVTV_MAGIC1      "ITV0"
3827 +
3828 +struct v4l2_mpeg_vbi_fmt_ivtv {
3829 +       __u8 magic[4];
3830 +       union {
3831 +               struct v4l2_mpeg_vbi_itv0 itv0;
3832 +               struct v4l2_mpeg_vbi_ITV0 ITV0;
3833 +       };
3834 +} __attribute__ ((packed));
3835 +
3836 +/*
3837 + *     A G G R E G A T E   S T R U C T U R E S
3838 + */
3839 +
3840 +/**
3841 + * struct v4l2_plane_pix_format - additional, per-plane format definition
3842 + * @sizeimage:         maximum size in bytes required for data, for which
3843 + *                     this plane will be used
3844 + * @bytesperline:      distance in bytes between the leftmost pixels in two
3845 + *                     adjacent lines
3846 + */
3847 +struct v4l2_plane_pix_format {
3848 +       __u32           sizeimage;
3849 +       __u16           bytesperline;
3850 +       __u16           reserved[7];
3851 +} __attribute__ ((packed));
3852 +
3853 +/**
3854 + * struct v4l2_pix_format_mplane - multiplanar format definition
3855 + * @width:             image width in pixels
3856 + * @height:            image height in pixels
3857 + * @pixelformat:       little endian four character code (fourcc)
3858 + * @field:             field order (for interlaced video)
3859 + * @colorspace:                supplemental to pixelformat
3860 + * @plane_fmt:         per-plane information
3861 + * @num_planes:                number of planes for this format
3862 + */
3863 +struct v4l2_pix_format_mplane {
3864 +       __u32                           width;
3865 +       __u32                           height;
3866 +       __u32                           pixelformat;
3867 +       enum v4l2_field                 field;
3868 +       enum v4l2_colorspace            colorspace;
3869 +
3870 +       struct v4l2_plane_pix_format    plane_fmt[VIDEO_MAX_PLANES];
3871 +       __u8                            num_planes;
3872 +       __u8                            reserved[11];
3873 +} __attribute__ ((packed));
3874 +
3875 +/**
3876 + * struct v4l2_format - stream data format
3877 + * @type:      type of the data stream
3878 + * @pix:       definition of an image format
3879 + * @pix_mp:    definition of a multiplanar image format
3880 + * @win:       definition of an overlaid image
3881 + * @vbi:       raw VBI capture or output parameters
3882 + * @sliced:    sliced VBI capture or output parameters
3883 + * @raw_data:  placeholder for future extensions and custom formats
3884 + */
3885 +struct v4l2_format {
3886 +       enum v4l2_buf_type type;
3887 +       union {
3888 +               struct v4l2_pix_format          pix;     /* V4L2_BUF_TYPE_VIDEO_CAPTURE */
3889 +               struct v4l2_pix_format_mplane   pix_mp;  /* V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE */
3890 +               struct v4l2_window              win;     /* V4L2_BUF_TYPE_VIDEO_OVERLAY */
3891 +               struct v4l2_vbi_format          vbi;     /* V4L2_BUF_TYPE_VBI_CAPTURE */
3892 +               struct v4l2_sliced_vbi_format   sliced;  /* V4L2_BUF_TYPE_SLICED_VBI_CAPTURE */
3893 +               __u8    raw_data[200];                   /* user-defined */
3894 +       } fmt;
3895 +};
3896 +
3897 +/*     Stream type-dependent parameters
3898 + */
3899 +struct v4l2_streamparm {
3900 +       enum v4l2_buf_type type;
3901 +       union {
3902 +               struct v4l2_captureparm capture;
3903 +               struct v4l2_outputparm  output;
3904 +               __u8    raw_data[200];  /* user-defined */
3905 +       } parm;
3906 +};
3907 +
3908 +/*
3909 + *     E V E N T S
3910 + */
3911 +
3912 +#define V4L2_EVENT_ALL                         0
3913 +#define V4L2_EVENT_VSYNC                       1
3914 +#define V4L2_EVENT_EOS                         2
3915 +#define V4L2_EVENT_PRIVATE_START               0x08000000
3916 +
3917 +/* Payload for V4L2_EVENT_VSYNC */
3918 +struct v4l2_event_vsync {
3919 +       /* Can be V4L2_FIELD_ANY, _NONE, _TOP or _BOTTOM */
3920 +       __u8 field;
3921 +} __attribute__ ((packed));
3922 +
3923 +struct v4l2_event {
3924 +       __u32                           type;
3925 +       union {
3926 +               struct v4l2_event_vsync vsync;
3927 +               __u8                    data[64];
3928 +       } u;
3929 +       __u32                           pending;
3930 +       __u32                           sequence;
3931 +       struct timespec                 timestamp;
3932 +       __u32                           reserved[9];
3933 +};
3934 +
3935 +struct v4l2_event_subscription {
3936 +       __u32                           type;
3937 +       __u32                           reserved[7];
3938 +};
3939 +
3940 +/*
3941 + *     A D V A N C E D   D E B U G G I N G
3942 + *
3943 + *     NOTE: EXPERIMENTAL API, NEVER RELY ON THIS IN APPLICATIONS!
3944 + *     FOR DEBUGGING, TESTING AND INTERNAL USE ONLY!
3945 + */
3946 +
3947 +/* VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER */
3948 +
3949 +#define V4L2_CHIP_MATCH_HOST       0  /* Match against chip ID on host (0 for the host) */
3950 +#define V4L2_CHIP_MATCH_I2C_DRIVER 1  /* Match against I2C driver name */
3951 +#define V4L2_CHIP_MATCH_I2C_ADDR   2  /* Match against I2C 7-bit address */
3952 +#define V4L2_CHIP_MATCH_AC97       3  /* Match against anciliary AC97 chip */
3953 +
3954 +struct v4l2_dbg_match {
3955 +       __u32 type; /* Match type */
3956 +       union {     /* Match this chip, meaning determined by type */
3957 +               __u32 addr;
3958 +               char name[32];
3959 +       };
3960 +} __attribute__ ((packed));
3961 +
3962 +struct v4l2_dbg_register {
3963 +       struct v4l2_dbg_match match;
3964 +       __u32 size;     /* register size in bytes */
3965 +       __u64 reg;
3966 +       __u64 val;
3967 +} __attribute__ ((packed));
3968 +
3969 +/* VIDIOC_DBG_G_CHIP_IDENT */
3970 +struct v4l2_dbg_chip_ident {
3971 +       struct v4l2_dbg_match match;
3972 +       __u32 ident;       /* chip identifier as specified in <media/v4l2-chip-ident.h> */
3973 +       __u32 revision;    /* chip revision, chip specific */
3974 +} __attribute__ ((packed));
3975 +
3976 +/*
3977 + *     I O C T L   C O D E S   F O R   V I D E O   D E V I C E S
3978 + *
3979 + */
3980 +#define VIDIOC_QUERYCAP                 _IOR('V',  0, struct v4l2_capability)
3981 +#define VIDIOC_RESERVED                  _IO('V',  1)
3982 +#define VIDIOC_ENUM_FMT         _IOWR('V',  2, struct v4l2_fmtdesc)
3983 +#define VIDIOC_G_FMT           _IOWR('V',  4, struct v4l2_format)
3984 +#define VIDIOC_S_FMT           _IOWR('V',  5, struct v4l2_format)
3985 +#define VIDIOC_REQBUFS         _IOWR('V',  8, struct v4l2_requestbuffers)
3986 +#define VIDIOC_QUERYBUF                _IOWR('V',  9, struct v4l2_buffer)
3987 +#define VIDIOC_G_FBUF           _IOR('V', 10, struct v4l2_framebuffer)
3988 +#define VIDIOC_S_FBUF           _IOW('V', 11, struct v4l2_framebuffer)
3989 +#define VIDIOC_OVERLAY          _IOW('V', 14, int)
3990 +#define VIDIOC_QBUF            _IOWR('V', 15, struct v4l2_buffer)
3991 +#define VIDIOC_DQBUF           _IOWR('V', 17, struct v4l2_buffer)
3992 +#define VIDIOC_STREAMON                 _IOW('V', 18, int)
3993 +#define VIDIOC_STREAMOFF        _IOW('V', 19, int)
3994 +#define VIDIOC_G_PARM          _IOWR('V', 21, struct v4l2_streamparm)
3995 +#define VIDIOC_S_PARM          _IOWR('V', 22, struct v4l2_streamparm)
3996 +#define VIDIOC_G_STD            _IOR('V', 23, v4l2_std_id)
3997 +#define VIDIOC_S_STD            _IOW('V', 24, v4l2_std_id)
3998 +#define VIDIOC_ENUMSTD         _IOWR('V', 25, struct v4l2_standard)
3999 +#define VIDIOC_ENUMINPUT       _IOWR('V', 26, struct v4l2_input)
4000 +#define VIDIOC_G_CTRL          _IOWR('V', 27, struct v4l2_control)
4001 +#define VIDIOC_S_CTRL          _IOWR('V', 28, struct v4l2_control)
4002 +#define VIDIOC_G_TUNER         _IOWR('V', 29, struct v4l2_tuner)
4003 +#define VIDIOC_S_TUNER          _IOW('V', 30, struct v4l2_tuner)
4004 +#define VIDIOC_G_AUDIO          _IOR('V', 33, struct v4l2_audio)
4005 +#define VIDIOC_S_AUDIO          _IOW('V', 34, struct v4l2_audio)
4006 +#define VIDIOC_QUERYCTRL       _IOWR('V', 36, struct v4l2_queryctrl)
4007 +#define VIDIOC_QUERYMENU       _IOWR('V', 37, struct v4l2_querymenu)
4008 +#define VIDIOC_G_INPUT          _IOR('V', 38, int)
4009 +#define VIDIOC_S_INPUT         _IOWR('V', 39, int)
4010 +#define VIDIOC_G_OUTPUT                 _IOR('V', 46, int)
4011 +#define VIDIOC_S_OUTPUT                _IOWR('V', 47, int)
4012 +#define VIDIOC_ENUMOUTPUT      _IOWR('V', 48, struct v4l2_output)
4013 +#define VIDIOC_G_AUDOUT                 _IOR('V', 49, struct v4l2_audioout)
4014 +#define VIDIOC_S_AUDOUT                 _IOW('V', 50, struct v4l2_audioout)
4015 +#define VIDIOC_G_MODULATOR     _IOWR('V', 54, struct v4l2_modulator)
4016 +#define VIDIOC_S_MODULATOR      _IOW('V', 55, struct v4l2_modulator)
4017 +#define VIDIOC_G_FREQUENCY     _IOWR('V', 56, struct v4l2_frequency)
4018 +#define VIDIOC_S_FREQUENCY      _IOW('V', 57, struct v4l2_frequency)
4019 +#define VIDIOC_CROPCAP         _IOWR('V', 58, struct v4l2_cropcap)
4020 +#define VIDIOC_G_CROP          _IOWR('V', 59, struct v4l2_crop)
4021 +#define VIDIOC_S_CROP           _IOW('V', 60, struct v4l2_crop)
4022 +#define VIDIOC_G_JPEGCOMP       _IOR('V', 61, struct v4l2_jpegcompression)
4023 +#define VIDIOC_S_JPEGCOMP       _IOW('V', 62, struct v4l2_jpegcompression)
4024 +#define VIDIOC_QUERYSTD         _IOR('V', 63, v4l2_std_id)
4025 +#define VIDIOC_TRY_FMT         _IOWR('V', 64, struct v4l2_format)
4026 +#define VIDIOC_ENUMAUDIO       _IOWR('V', 65, struct v4l2_audio)
4027 +#define VIDIOC_ENUMAUDOUT      _IOWR('V', 66, struct v4l2_audioout)
4028 +#define VIDIOC_G_PRIORITY        _IOR('V', 67, enum v4l2_priority)
4029 +#define VIDIOC_S_PRIORITY        _IOW('V', 68, enum v4l2_priority)
4030 +#define VIDIOC_G_SLICED_VBI_CAP _IOWR('V', 69, struct v4l2_sliced_vbi_cap)
4031 +#define VIDIOC_LOG_STATUS         _IO('V', 70)
4032 +#define VIDIOC_G_EXT_CTRLS     _IOWR('V', 71, struct v4l2_ext_controls)
4033 +#define VIDIOC_S_EXT_CTRLS     _IOWR('V', 72, struct v4l2_ext_controls)
4034 +#define VIDIOC_TRY_EXT_CTRLS   _IOWR('V', 73, struct v4l2_ext_controls)
4035 +#if 1
4036 +#define VIDIOC_ENUM_FRAMESIZES _IOWR('V', 74, struct v4l2_frmsizeenum)
4037 +#define VIDIOC_ENUM_FRAMEINTERVALS _IOWR('V', 75, struct v4l2_frmivalenum)
4038 +#define VIDIOC_G_ENC_INDEX       _IOR('V', 76, struct v4l2_enc_idx)
4039 +#define VIDIOC_ENCODER_CMD      _IOWR('V', 77, struct v4l2_encoder_cmd)
4040 +#define VIDIOC_TRY_ENCODER_CMD  _IOWR('V', 78, struct v4l2_encoder_cmd)
4041 +#endif
4042 +
4043 +#if 1
4044 +/* Experimental, meant for debugging, testing and internal use.
4045 +   Only implemented if CONFIG_VIDEO_ADV_DEBUG is defined.
4046 +   You must be root to use these ioctls. Never use these in applications! */
4047 +#define        VIDIOC_DBG_S_REGISTER    _IOW('V', 79, struct v4l2_dbg_register)
4048 +#define        VIDIOC_DBG_G_REGISTER   _IOWR('V', 80, struct v4l2_dbg_register)
4049 +
4050 +/* Experimental, meant for debugging, testing and internal use.
4051 +   Never use this ioctl in applications! */
4052 +#define VIDIOC_DBG_G_CHIP_IDENT _IOWR('V', 81, struct v4l2_dbg_chip_ident)
4053 +#endif
4054 +
4055 +#define VIDIOC_S_HW_FREQ_SEEK   _IOW('V', 82, struct v4l2_hw_freq_seek)
4056 +#define        VIDIOC_ENUM_DV_PRESETS  _IOWR('V', 83, struct v4l2_dv_enum_preset)
4057 +#define        VIDIOC_S_DV_PRESET      _IOWR('V', 84, struct v4l2_dv_preset)
4058 +#define        VIDIOC_G_DV_PRESET      _IOWR('V', 85, struct v4l2_dv_preset)
4059 +#define        VIDIOC_QUERY_DV_PRESET  _IOR('V',  86, struct v4l2_dv_preset)
4060 +#define        VIDIOC_S_DV_TIMINGS     _IOWR('V', 87, struct v4l2_dv_timings)
4061 +#define        VIDIOC_G_DV_TIMINGS     _IOWR('V', 88, struct v4l2_dv_timings)
4062 +#define        VIDIOC_DQEVENT           _IOR('V', 89, struct v4l2_event)
4063 +#define        VIDIOC_SUBSCRIBE_EVENT   _IOW('V', 90, struct v4l2_event_subscription)
4064 +#define        VIDIOC_UNSUBSCRIBE_EVENT _IOW('V', 91, struct v4l2_event_subscription)
4065 +
4066 +#define BASE_VIDIOC_PRIVATE    192             /* 192-255 are private */
4067 +
4068 +#endif /* __LINUX_VIDEODEV2_H */
This page took 0.639837 seconds and 3 git commands to generate.