Home | History | Annotate | Download | only in spec
      1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
      2 <HTML
      3 ><HEAD
      4 ><TITLE
      5 >ioctl VIDIOC_G_FMT, VIDIOC_S_FMT,
      6 VIDIOC_TRY_FMT</TITLE
      7 ><META
      8 NAME="GENERATOR"
      9 CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
     10 REL="HOME"
     11 TITLE="Video for Linux Two API Specification"
     12 HREF="book1.htm"><LINK
     13 REL="UP"
     14 TITLE="Function Reference"
     15 HREF="r7624.htm"><LINK
     16 REL="PREVIOUS"
     17 TITLE="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"
     18 HREF="r10595.htm"><LINK
     19 REL="NEXT"
     20 TITLE="ioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY"
     21 HREF="r11094.htm"></HEAD
     22 ><BODY
     23 CLASS="REFENTRY"
     24 BGCOLOR="#FFFFFF"
     25 TEXT="#000000"
     26 LINK="#0000FF"
     27 VLINK="#840084"
     28 ALINK="#0000FF"
     29 ><DIV
     30 CLASS="NAVHEADER"
     31 ><TABLE
     32 SUMMARY="Header navigation table"
     33 WIDTH="100%"
     34 BORDER="0"
     35 CELLPADDING="0"
     36 CELLSPACING="0"
     37 ><TR
     38 ><TH
     39 COLSPAN="3"
     40 ALIGN="center"
     41 >Video for Linux Two API Specification: Revision 0.24</TH
     42 ></TR
     43 ><TR
     44 ><TD
     45 WIDTH="10%"
     46 ALIGN="left"
     47 VALIGN="bottom"
     48 ><A
     49 HREF="r10595.htm"
     50 ACCESSKEY="P"
     51 >Prev</A
     52 ></TD
     53 ><TD
     54 WIDTH="80%"
     55 ALIGN="center"
     56 VALIGN="bottom"
     57 ></TD
     58 ><TD
     59 WIDTH="10%"
     60 ALIGN="right"
     61 VALIGN="bottom"
     62 ><A
     63 HREF="r11094.htm"
     64 ACCESSKEY="N"
     65 >Next</A
     66 ></TD
     67 ></TR
     68 ></TABLE
     69 ><HR
     70 ALIGN="LEFT"
     71 WIDTH="100%"></DIV
     72 ><H1
     73 ><A
     74 NAME="VIDIOC-G-FMT"
     75 ></A
     76 >ioctl VIDIOC_G_FMT, VIDIOC_S_FMT,
     77 VIDIOC_TRY_FMT</H1
     78 ><DIV
     79 CLASS="REFNAMEDIV"
     80 ><A
     81 NAME="AEN10948"
     82 ></A
     83 ><H2
     84 >Name</H2
     85 >VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT&nbsp;--&nbsp;Get or set the data format, try a format</DIV
     86 ><DIV
     87 CLASS="REFSYNOPSISDIV"
     88 ><A
     89 NAME="AEN10953"
     90 ></A
     91 ><H2
     92 >Synopsis</H2
     93 ><DIV
     94 CLASS="FUNCSYNOPSIS"
     95 ><P
     96 ></P
     97 ><A
     98 NAME="AEN10954"
     99 ></A
    100 ><P
    101 ><CODE
    102 ><CODE
    103 CLASS="FUNCDEF"
    104 >int ioctl</CODE
    105 >(int fd, int request, struct v4l2_format
    106 *argp);</CODE
    107 ></P
    108 ><P
    109 ></P
    110 ></DIV
    111 ></DIV
    112 ><DIV
    113 CLASS="REFSECT1"
    114 ><A
    115 NAME="AEN10964"
    116 ></A
    117 ><H2
    118 >Arguments</H2
    119 ><P
    120 ></P
    121 ><DIV
    122 CLASS="VARIABLELIST"
    123 ><DL
    124 ><DT
    125 ><CODE
    126 CLASS="PARAMETER"
    127 >fd</CODE
    128 ></DT
    129 ><DD
    130 ><P
    131 >File descriptor returned by <A
    132 HREF="r14090.htm"
    133 ><CODE
    134 CLASS="FUNCTION"
    135 >open()</CODE
    136 ></A
    137 >.</P
    138 ></DD
    139 ><DT
    140 ><CODE
    141 CLASS="PARAMETER"
    142 >request</CODE
    143 ></DT
    144 ><DD
    145 ><P
    146 >VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT</P
    147 ></DD
    148 ><DT
    149 ><CODE
    150 CLASS="PARAMETER"
    151 >argp</CODE
    152 ></DT
    153 ><DD
    154 ><P
    155 ></P
    156 ></DD
    157 ></DL
    158 ></DIV
    159 ></DIV
    160 ><DIV
    161 CLASS="REFSECT1"
    162 ><A
    163 NAME="AEN10984"
    164 ></A
    165 ><H2
    166 >Description</H2
    167 ><P
    168 >These ioctls are used to negotiate the format of data
    169 (typically image format) exchanged between driver and
    170 application.</P
    171 ><P
    172 >To query the current parameters applications set the
    173 <CODE
    174 CLASS="STRUCTFIELD"
    175 >type</CODE
    176 > field of a struct
    177 <CODE
    178 CLASS="STRUCTNAME"
    179 >v4l2_format</CODE
    180 > to the respective buffer (stream)
    181 type. For example video capture devices use
    182 <CODE
    183 CLASS="CONSTANT"
    184 >V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE
    185 >. When the application
    186 calls the <CODE
    187 CLASS="CONSTANT"
    188 >VIDIOC_G_FMT</CODE
    189 > ioctl with a pointer to
    190 this structure the driver fills the respective member of the
    191 <CODE
    192 CLASS="STRUCTFIELD"
    193 >fmt</CODE
    194 > union. In case of video capture devices
    195 that is the struct&nbsp;<A
    196 HREF="c2030.htm#V4L2-PIX-FORMAT"
    197 >v4l2_pix_format</A
    198 > <CODE
    199 CLASS="STRUCTFIELD"
    200 >pix</CODE
    201 > member.
    202 When the requested buffer type is not supported drivers return an
    203 <SPAN
    204 CLASS="ERRORCODE"
    205 >EINVAL</SPAN
    206 > error code.</P
    207 ><P
    208 >To change the current format parameters applications
    209 initialize the <CODE
    210 CLASS="STRUCTFIELD"
    211 >type</CODE
    212 > field and all
    213 fields of the respective <CODE
    214 CLASS="STRUCTFIELD"
    215 >fmt</CODE
    216 >
    217 union member. For details see the documentation of the various devices
    218 types in <A
    219 HREF="c6488.htm"
    220 >Chapter 4</A
    221 >. Good practice is to query the
    222 current parameters first, and to
    223 modify only those parameters not suitable for the application. When
    224 the application calls the <CODE
    225 CLASS="CONSTANT"
    226 >VIDIOC_S_FMT</CODE
    227 > ioctl
    228 with a pointer to a <CODE
    229 CLASS="STRUCTNAME"
    230 >v4l2_format</CODE
    231 > structure
    232 the driver checks
    233 and adjusts the parameters against hardware abilities. Drivers
    234 should not return an error code unless the input is ambiguous, this is
    235 a mechanism to fathom device capabilities and to approach parameters
    236 acceptable for both the application and driver. On success the driver
    237 may program the hardware, allocate resources and generally prepare for
    238 data exchange.
    239 Finally the <CODE
    240 CLASS="CONSTANT"
    241 >VIDIOC_S_FMT</CODE
    242 > ioctl returns the
    243 current format parameters as <CODE
    244 CLASS="CONSTANT"
    245 >VIDIOC_G_FMT</CODE
    246 > does.
    247 Very simple, inflexible devices may even ignore all input and always
    248 return the default parameters. However all V4L2 devices exchanging
    249 data with the application must implement the
    250 <CODE
    251 CLASS="CONSTANT"
    252 >VIDIOC_G_FMT</CODE
    253 > and
    254 <CODE
    255 CLASS="CONSTANT"
    256 >VIDIOC_S_FMT</CODE
    257 > ioctl. When the requested buffer
    258 type is not supported drivers return an <SPAN
    259 CLASS="ERRORCODE"
    260 >EINVAL</SPAN
    261 > error code on a
    262 <CODE
    263 CLASS="CONSTANT"
    264 >VIDIOC_S_FMT</CODE
    265 > attempt. When I/O is already in
    266 progress or the resource is not available for other reasons drivers
    267 return the <SPAN
    268 CLASS="ERRORCODE"
    269 >EBUSY</SPAN
    270 > error code.</P
    271 ><P
    272 >The <CODE
    273 CLASS="CONSTANT"
    274 >VIDIOC_TRY_FMT</CODE
    275 > ioctl is equivalent
    276 to <CODE
    277 CLASS="CONSTANT"
    278 >VIDIOC_S_FMT</CODE
    279 > with one exception: it does not
    280 change driver state. It can also be called at any time, never
    281 returning <SPAN
    282 CLASS="ERRORCODE"
    283 >EBUSY</SPAN
    284 >. This function is provided to
    285 negotiate parameters, to learn about hardware limitations, without
    286 disabling I/O or possibly time consuming hardware preparations.
    287 Although strongly recommended drivers are not required to implement
    288 this ioctl.</P
    289 ><DIV
    290 CLASS="TABLE"
    291 ><A
    292 NAME="V4L2-FORMAT"
    293 ></A
    294 ><P
    295 ><B
    296 >Table 1. struct <CODE
    297 CLASS="STRUCTNAME"
    298 >v4l2_format</CODE
    299 ></B
    300 ></P
    301 ><TABLE
    302 BORDER="0"
    303 FRAME="void"
    304 WIDTH="100%"
    305 CLASS="CALSTABLE"
    306 ><COL
    307 WIDTH="25%"
    308 TITLE="C1"><COL
    309 WIDTH="25%"
    310 TITLE="C2"><COL
    311 WIDTH="25%"
    312 TITLE="C3"><COL
    313 WIDTH="25%"
    314 TITLE="C4"><TBODY
    315 VALIGN="TOP"
    316 ><TR
    317 ><TD
    318 >enum&nbsp;<A
    319 HREF="x5953.htm#V4L2-BUF-TYPE"
    320 >v4l2_buf_type</A
    321 ></TD
    322 ><TD
    323 ><CODE
    324 CLASS="STRUCTFIELD"
    325 >type</CODE
    326 ></TD
    327 ><TD
    328 >&nbsp;</TD
    329 ><TD
    330 >Type of the data stream, see <A
    331 HREF="x5953.htm#V4L2-BUF-TYPE"
    332 >Table 3-2</A
    333 >.</TD
    334 ></TR
    335 ><TR
    336 ><TD
    337 >union</TD
    338 ><TD
    339 ><CODE
    340 CLASS="STRUCTFIELD"
    341 >fmt</CODE
    342 ></TD
    343 ><TD
    344 >&nbsp;</TD
    345 ><TD
    346 >&nbsp;</TD
    347 ></TR
    348 ><TR
    349 ><TD
    350 >&nbsp;</TD
    351 ><TD
    352 >struct&nbsp;<A
    353 HREF="c2030.htm#V4L2-PIX-FORMAT"
    354 >v4l2_pix_format</A
    355 ></TD
    356 ><TD
    357 ><CODE
    358 CLASS="STRUCTFIELD"
    359 >pix</CODE
    360 ></TD
    361 ><TD
    362 >Definition of an image format, see <A
    363 HREF="c2030.htm"
    364 >Chapter 2</A
    365 >, used by video capture and output
    366 devices.</TD
    367 ></TR
    368 ><TR
    369 ><TD
    370 >&nbsp;</TD
    371 ><TD
    372 >struct&nbsp;<A
    373 HREF="x6570.htm#V4L2-WINDOW"
    374 >v4l2_window</A
    375 ></TD
    376 ><TD
    377 ><CODE
    378 CLASS="STRUCTFIELD"
    379 >win</CODE
    380 ></TD
    381 ><TD
    382 >Definition of an overlaid image, see <A
    383 HREF="x6570.htm"
    384 >Section 4.2</A
    385 >, used by video overlay devices.</TD
    386 ></TR
    387 ><TR
    388 ><TD
    389 >&nbsp;</TD
    390 ><TD
    391 >struct&nbsp;<A
    392 HREF="x7013.htm#V4L2-VBI-FORMAT"
    393 >v4l2_vbi_format</A
    394 ></TD
    395 ><TD
    396 ><CODE
    397 CLASS="STRUCTFIELD"
    398 >vbi</CODE
    399 ></TD
    400 ><TD
    401 >Raw VBI capture or output parameters. This is
    402 discussed in more detail in <A
    403 HREF="x7013.htm"
    404 >Section 4.7</A
    405 >. Used by raw VBI
    406 capture and output devices.</TD
    407 ></TR
    408 ><TR
    409 ><TD
    410 >&nbsp;</TD
    411 ><TD
    412 >struct&nbsp;<A
    413 HREF="x7236.htm#V4L2-SLICED-VBI-FORMAT"
    414 >v4l2_sliced_vbi_format</A
    415 ></TD
    416 ><TD
    417 ><CODE
    418 CLASS="STRUCTFIELD"
    419 >sliced</CODE
    420 ></TD
    421 ><TD
    422 >Sliced VBI capture or output parameters. See
    423 <A
    424 HREF="x7236.htm"
    425 >Section 4.8</A
    426 > for details. Used by sliced VBI
    427 capture and output devices.</TD
    428 ></TR
    429 ><TR
    430 ><TD
    431 >&nbsp;</TD
    432 ><TD
    433 >__u8</TD
    434 ><TD
    435 ><CODE
    436 CLASS="STRUCTFIELD"
    437 >raw_data</CODE
    438 >[200]</TD
    439 ><TD
    440 >Place holder for future extensions and custom
    441 (driver defined) formats with <CODE
    442 CLASS="STRUCTFIELD"
    443 >type</CODE
    444 >
    445 <CODE
    446 CLASS="CONSTANT"
    447 >V4L2_BUF_TYPE_PRIVATE</CODE
    448 > and higher.</TD
    449 ></TR
    450 ></TBODY
    451 ></TABLE
    452 ></DIV
    453 ></DIV
    454 ><DIV
    455 CLASS="REFSECT1"
    456 ><A
    457 NAME="AEN11074"
    458 ></A
    459 ><H2
    460 >Return Value</H2
    461 ><P
    462 >On success <SPAN
    463 CLASS="RETURNVALUE"
    464 >0</SPAN
    465 > is returned, on error <SPAN
    466 CLASS="RETURNVALUE"
    467 >-1</SPAN
    468 > and the <CODE
    469 CLASS="VARNAME"
    470 >errno</CODE
    471 > variable is set appropriately:</P
    472 ><P
    473 ></P
    474 ><DIV
    475 CLASS="VARIABLELIST"
    476 ><DL
    477 ><DT
    478 ><SPAN
    479 CLASS="ERRORCODE"
    480 >EBUSY</SPAN
    481 ></DT
    482 ><DD
    483 ><P
    484 >The data format cannot be changed at this
    485 time, for example because I/O is already in progress.</P
    486 ></DD
    487 ><DT
    488 ><SPAN
    489 CLASS="ERRORCODE"
    490 >EINVAL</SPAN
    491 ></DT
    492 ><DD
    493 ><P
    494 >The struct&nbsp;<A
    495 HREF="r10944.htm#V4L2-FORMAT"
    496 >v4l2_format</A
    497 > <CODE
    498 CLASS="STRUCTFIELD"
    499 >type</CODE
    500 >
    501 field is invalid, the requested buffer type not supported, or
    502 <CODE
    503 CLASS="CONSTANT"
    504 >VIDIOC_TRY_FMT</CODE
    505 > was called and is not
    506 supported with this buffer type.</P
    507 ></DD
    508 ></DL
    509 ></DIV
    510 ></DIV
    511 ><DIV
    512 CLASS="NAVFOOTER"
    513 ><HR
    514 ALIGN="LEFT"
    515 WIDTH="100%"><TABLE
    516 SUMMARY="Footer navigation table"
    517 WIDTH="100%"
    518 BORDER="0"
    519 CELLPADDING="0"
    520 CELLSPACING="0"
    521 ><TR
    522 ><TD
    523 WIDTH="33%"
    524 ALIGN="left"
    525 VALIGN="top"
    526 ><A
    527 HREF="r10595.htm"
    528 ACCESSKEY="P"
    529 >Prev</A
    530 ></TD
    531 ><TD
    532 WIDTH="34%"
    533 ALIGN="center"
    534 VALIGN="top"
    535 ><A
    536 HREF="book1.htm"
    537 ACCESSKEY="H"
    538 >Home</A
    539 ></TD
    540 ><TD
    541 WIDTH="33%"
    542 ALIGN="right"
    543 VALIGN="top"
    544 ><A
    545 HREF="r11094.htm"
    546 ACCESSKEY="N"
    547 >Next</A
    548 ></TD
    549 ></TR
    550 ><TR
    551 ><TD
    552 WIDTH="33%"
    553 ALIGN="left"
    554 VALIGN="top"
    555 >ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF</TD
    556 ><TD
    557 WIDTH="34%"
    558 ALIGN="center"
    559 VALIGN="top"
    560 ><A
    561 HREF="r7624.htm"
    562 ACCESSKEY="U"
    563 >Up</A
    564 ></TD
    565 ><TD
    566 WIDTH="33%"
    567 ALIGN="right"
    568 VALIGN="top"
    569 >ioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY</TD
    570 ></TR
    571 ></TABLE
    572 ></DIV
    573 ></BODY
    574 ></HTML
    575 >
    576