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 >Video Standards</TITLE 6 ><META 7 NAME="GENERATOR" 8 CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK 9 REL="HOME" 10 TITLE="Video for Linux Two API Specification" 11 HREF="book1.htm"><LINK 12 REL="UP" 13 TITLE="Common API Elements" 14 HREF="c174.htm"><LINK 15 REL="PREVIOUS" 16 TITLE="Tuners and Modulators" 17 HREF="x394.htm"><LINK 18 REL="NEXT" 19 TITLE="User Controls" 20 HREF="x542.htm"></HEAD 21 ><BODY 22 CLASS="SECTION" 23 BGCOLOR="#FFFFFF" 24 TEXT="#000000" 25 LINK="#0000FF" 26 VLINK="#840084" 27 ALINK="#0000FF" 28 ><DIV 29 CLASS="NAVHEADER" 30 ><TABLE 31 SUMMARY="Header navigation table" 32 WIDTH="100%" 33 BORDER="0" 34 CELLPADDING="0" 35 CELLSPACING="0" 36 ><TR 37 ><TH 38 COLSPAN="3" 39 ALIGN="center" 40 >Video for Linux Two API Specification: Revision 0.24</TH 41 ></TR 42 ><TR 43 ><TD 44 WIDTH="10%" 45 ALIGN="left" 46 VALIGN="bottom" 47 ><A 48 HREF="x394.htm" 49 ACCESSKEY="P" 50 >Prev</A 51 ></TD 52 ><TD 53 WIDTH="80%" 54 ALIGN="center" 55 VALIGN="bottom" 56 >Chapter 1. Common API Elements</TD 57 ><TD 58 WIDTH="10%" 59 ALIGN="right" 60 VALIGN="bottom" 61 ><A 62 HREF="x542.htm" 63 ACCESSKEY="N" 64 >Next</A 65 ></TD 66 ></TR 67 ></TABLE 68 ><HR 69 ALIGN="LEFT" 70 WIDTH="100%"></DIV 71 ><DIV 72 CLASS="SECTION" 73 ><H1 74 CLASS="SECTION" 75 ><A 76 NAME="STANDARD" 77 >1.7. Video Standards</A 78 ></H1 79 ><P 80 >Video devices typically support one or more different video 81 standards or variations of standards. Each video input and output may 82 support another set of standards. This set is reported by the 83 <CODE 84 CLASS="STRUCTFIELD" 85 >std</CODE 86 > field of struct <A 87 HREF="r8936.htm#V4L2-INPUT" 88 >v4l2_input</A 89 > and 90 struct <A 91 HREF="r9149.htm#V4L2-OUTPUT" 92 >v4l2_output</A 93 > returned by the <A 94 HREF="r8936.htm" 95 ><CODE 96 CLASS="CONSTANT" 97 >VIDIOC_ENUMINPUT</CODE 98 ></A 99 > and 100 <A 101 HREF="r9149.htm" 102 ><CODE 103 CLASS="CONSTANT" 104 >VIDIOC_ENUMOUTPUT</CODE 105 ></A 106 > ioctl, respectively.</P 107 ><P 108 >V4L2 defines one bit for each analog video standard 109 currently in use worldwide, and sets aside bits for driver defined 110 standards, e. g. hybrid standards to watch NTSC video tapes on PAL TVs 111 and vice versa. Applications can use the predefined bits to select a 112 particular standard, although presenting the user a menu of supported 113 standards is preferred. To enumerate and query the attributes of the 114 supported standards applications use the <A 115 HREF="r9288.htm" 116 ><CODE 117 CLASS="CONSTANT" 118 >VIDIOC_ENUMSTD</CODE 119 ></A 120 > ioctl.</P 121 ><P 122 >Many of the defined standards are actually just variations 123 of a few major standards. The hardware may in fact not distinguish 124 between them, or do so internal and switch automatically. Therefore 125 enumerated standards also contain sets of one or more standard 126 bits.</P 127 ><P 128 >Assume a hypothetic tuner capable of demodulating B/PAL, 129 G/PAL and I/PAL signals. The first enumerated standard is a set of B 130 and G/PAL, switched automatically depending on the selected radio 131 frequency in UHF or VHF band. Enumeration gives a "PAL-B/G" or "PAL-I" 132 choice. Similar a Composite input may collapse standards, enumerating 133 "PAL-B/G/H/I", "NTSC-M" and "SECAM-D/K".<A 134 NAME="AEN463" 135 HREF="x448.htm#FTN.AEN463" 136 ><SPAN 137 CLASS="footnote" 138 >[1]</SPAN 139 ></A 140 ></P 141 ><P 142 >To query and select the standard used by the current video 143 input or output applications call the <A 144 HREF="r12265.htm" 145 ><CODE 146 CLASS="CONSTANT" 147 >VIDIOC_G_STD</CODE 148 ></A 149 > and 150 <A 151 HREF="r12265.htm" 152 ><CODE 153 CLASS="CONSTANT" 154 >VIDIOC_S_STD</CODE 155 ></A 156 > ioctl, respectively. The <SPAN 157 CLASS="emphasis" 158 ><I 159 CLASS="EMPHASIS" 160 >received</I 161 ></SPAN 162 > 163 standard can be sensed with the <A 164 HREF="r13641.htm" 165 ><CODE 166 CLASS="CONSTANT" 167 >VIDIOC_QUERYSTD</CODE 168 ></A 169 > ioctl. Note parameter of all these ioctls is a pointer to a <A 170 HREF="r9288.htm#V4L2-STD-ID" 171 >v4l2_std_id</A 172 > type (a standard set), <SPAN 173 CLASS="emphasis" 174 ><I 175 CLASS="EMPHASIS" 176 >not</I 177 ></SPAN 178 > an index into the standard enumeration.<A 179 NAME="AEN475" 180 HREF="x448.htm#FTN.AEN475" 181 ><SPAN 182 CLASS="footnote" 183 >[2]</SPAN 184 ></A 185 > Drivers must implement all video standard ioctls 186 when the device has one or more video inputs or outputs.</P 187 ><P 188 >Special rules apply to USB cameras where the notion of video 189 standards makes little sense. More generally any capture device, 190 output devices accordingly, which is <P 191 ></P 192 ><UL 193 ><LI 194 ><P 195 >incapable of capturing fields or frames at the nominal 196 rate of the video standard, or</P 197 ></LI 198 ><LI 199 ><P 200 >where <A 201 HREF="x5953.htm" 202 >timestamps</A 203 > refer 204 to the instant the field or frame was received by the driver, not the 205 capture time, or</P 206 ></LI 207 ><LI 208 ><P 209 >where <A 210 HREF="x5953.htm" 211 >sequence numbers</A 212 > 213 refer to the frames received by the driver, not the captured 214 frames.</P 215 ></LI 216 ></UL 217 > Here the driver shall set the 218 <CODE 219 CLASS="STRUCTFIELD" 220 >std</CODE 221 > field of struct <A 222 HREF="r8936.htm#V4L2-INPUT" 223 >v4l2_input</A 224 > and struct <A 225 HREF="r9149.htm#V4L2-OUTPUT" 226 >v4l2_output</A 227 > 228 to zero, the <CODE 229 CLASS="CONSTANT" 230 >VIDIOC_G_STD</CODE 231 >, 232 <CODE 233 CLASS="CONSTANT" 234 >VIDIOC_S_STD</CODE 235 >, 236 <CODE 237 CLASS="CONSTANT" 238 >VIDIOC_QUERYSTD</CODE 239 > and 240 <CODE 241 CLASS="CONSTANT" 242 >VIDIOC_ENUMSTD</CODE 243 > ioctls shall return the 244 <SPAN 245 CLASS="ERRORCODE" 246 >EINVAL</SPAN 247 > error code.<A 248 NAME="AEN507" 249 HREF="x448.htm#FTN.AEN507" 250 ><SPAN 251 CLASS="footnote" 252 >[3]</SPAN 253 ></A 254 ></P 255 ><DIV 256 CLASS="EXAMPLE" 257 ><A 258 NAME="AEN510" 259 ></A 260 ><P 261 ><B 262 >Example 1-5. Information about the current video standard</B 263 ></P 264 ><PRE 265 CLASS="PROGRAMLISTING" 266 ><A 267 HREF="r9288.htm#V4L2-STD-ID" 268 >v4l2_std_id</A 269 > std_id; 270 struct <A 271 HREF="r9288.htm#V4L2-STANDARD" 272 >v4l2_standard</A 273 > standard; 274 275 if (-1 == ioctl (fd, <A 276 HREF="r12265.htm" 277 ><CODE 278 CLASS="CONSTANT" 279 >VIDIOC_G_STD</CODE 280 ></A 281 >, &std_id)) { 282 /* Note when VIDIOC_ENUMSTD always returns EINVAL this 283 is no video device or it falls under the USB exception, 284 and VIDIOC_G_STD returning EINVAL is no error. */ 285 286 perror ("VIDIOC_G_STD"); 287 exit (EXIT_FAILURE); 288 } 289 290 memset (&standard, 0, sizeof (standard)); 291 standard.index = 0; 292 293 while (0 == ioctl (fd, <A 294 HREF="r9288.htm" 295 ><CODE 296 CLASS="CONSTANT" 297 >VIDIOC_ENUMSTD</CODE 298 ></A 299 >, &standard)) { 300 if (standard.id & std_id) { 301 printf ("Current video standard: %s\n", standard.name); 302 exit (EXIT_SUCCESS); 303 } 304 305 standard.index++; 306 } 307 308 /* EINVAL indicates the end of the enumeration, which cannot be 309 empty unless this device falls under the USB exception. */ 310 311 if (errno == EINVAL || standard.index == 0) { 312 perror ("VIDIOC_ENUMSTD"); 313 exit (EXIT_FAILURE); 314 } 315 </PRE 316 ></DIV 317 ><DIV 318 CLASS="EXAMPLE" 319 ><A 320 NAME="AEN519" 321 ></A 322 ><P 323 ><B 324 >Example 1-6. Listing the video standards supported by the current 325 input</B 326 ></P 327 ><PRE 328 CLASS="PROGRAMLISTING" 329 >struct <A 330 HREF="r8936.htm#V4L2-INPUT" 331 >v4l2_input</A 332 > input; 333 struct <A 334 HREF="r9288.htm#V4L2-STANDARD" 335 >v4l2_standard</A 336 > standard; 337 338 memset (&input, 0, sizeof (input)); 339 340 if (-1 == ioctl (fd, <A 341 HREF="r11217.htm" 342 ><CODE 343 CLASS="CONSTANT" 344 >VIDIOC_G_INPUT</CODE 345 ></A 346 >, &input.index)) { 347 perror ("VIDIOC_G_INPUT"); 348 exit (EXIT_FAILURE); 349 } 350 351 if (-1 == ioctl (fd, <A 352 HREF="r8936.htm" 353 ><CODE 354 CLASS="CONSTANT" 355 >VIDIOC_ENUMINPUT</CODE 356 ></A 357 >, &input)) { 358 perror ("VIDIOC_ENUM_INPUT"); 359 exit (EXIT_FAILURE); 360 } 361 362 printf ("Current input %s supports:\n", input.name); 363 364 memset (&standard, 0, sizeof (standard)); 365 standard.index = 0; 366 367 while (0 == ioctl (fd, <A 368 HREF="r9288.htm" 369 ><CODE 370 CLASS="CONSTANT" 371 >VIDIOC_ENUMSTD</CODE 372 ></A 373 >, &standard)) { 374 if (standard.id & input.std) 375 printf ("%s\n", standard.name); 376 377 standard.index++; 378 } 379 380 /* EINVAL indicates the end of the enumeration, which cannot be 381 empty unless this device falls under the USB exception. */ 382 383 if (errno != EINVAL || standard.index == 0) { 384 perror ("VIDIOC_ENUMSTD"); 385 exit (EXIT_FAILURE); 386 } 387 </PRE 388 ></DIV 389 ><DIV 390 CLASS="EXAMPLE" 391 ><A 392 NAME="AEN530" 393 ></A 394 ><P 395 ><B 396 >Example 1-7. Selecting a new video standard</B 397 ></P 398 ><PRE 399 CLASS="PROGRAMLISTING" 400 >struct <A 401 HREF="r8936.htm#V4L2-INPUT" 402 >v4l2_input</A 403 > input; 404 <A 405 HREF="r9288.htm#V4L2-STD-ID" 406 >v4l2_std_id</A 407 > std_id; 408 409 memset (&input, 0, sizeof (input)); 410 411 if (-1 == ioctl (fd, <A 412 HREF="r11217.htm" 413 ><CODE 414 CLASS="CONSTANT" 415 >VIDIOC_G_INPUT</CODE 416 ></A 417 >, &input.index)) { 418 perror ("VIDIOC_G_INPUT"); 419 exit (EXIT_FAILURE); 420 } 421 422 if (-1 == ioctl (fd, <A 423 HREF="r8936.htm" 424 ><CODE 425 CLASS="CONSTANT" 426 >VIDIOC_ENUMINPUT</CODE 427 ></A 428 >, &input)) { 429 perror ("VIDIOC_ENUM_INPUT"); 430 exit (EXIT_FAILURE); 431 } 432 433 if (0 == (input.std & V4L2_STD_PAL_BG)) { 434 fprintf (stderr, "Oops. B/G PAL is not supported.\n"); 435 exit (EXIT_FAILURE); 436 } 437 438 /* Note this is also supposed to work when only B 439 <SPAN 440 CLASS="emphasis" 441 ><I 442 CLASS="EMPHASIS" 443 >or</I 444 ></SPAN 445 > G/PAL is supported. */ 446 447 std_id = V4L2_STD_PAL_BG; 448 449 if (-1 == ioctl (fd, <A 450 HREF="r12265.htm" 451 ><CODE 452 CLASS="CONSTANT" 453 >VIDIOC_S_STD</CODE 454 ></A 455 >, &std_id)) { 456 perror ("VIDIOC_S_STD"); 457 exit (EXIT_FAILURE); 458 } 459 </PRE 460 ></DIV 461 ></DIV 462 ><H3 463 CLASS="FOOTNOTES" 464 >Notes</H3 465 ><TABLE 466 BORDER="0" 467 CLASS="FOOTNOTES" 468 WIDTH="100%" 469 ><TR 470 ><TD 471 ALIGN="LEFT" 472 VALIGN="TOP" 473 WIDTH="5%" 474 ><A 475 NAME="FTN.AEN463" 476 HREF="x448.htm#AEN463" 477 ><SPAN 478 CLASS="footnote" 479 >[1]</SPAN 480 ></A 481 ></TD 482 ><TD 483 ALIGN="LEFT" 484 VALIGN="TOP" 485 WIDTH="95%" 486 ><P 487 >Some users are already confused by technical terms PAL, 488 NTSC and SECAM. There is no point asking them to distinguish between 489 B, G, D, or K when the software or hardware can do that 490 automatically.</P 491 ></TD 492 ></TR 493 ><TR 494 ><TD 495 ALIGN="LEFT" 496 VALIGN="TOP" 497 WIDTH="5%" 498 ><A 499 NAME="FTN.AEN475" 500 HREF="x448.htm#AEN475" 501 ><SPAN 502 CLASS="footnote" 503 >[2]</SPAN 504 ></A 505 ></TD 506 ><TD 507 ALIGN="LEFT" 508 VALIGN="TOP" 509 WIDTH="95%" 510 ><P 511 >An alternative to the current scheme is to use pointers 512 to indices as arguments of <CODE 513 CLASS="CONSTANT" 514 >VIDIOC_G_STD</CODE 515 > and 516 <CODE 517 CLASS="CONSTANT" 518 >VIDIOC_S_STD</CODE 519 >, the struct <A 520 HREF="r8936.htm#V4L2-INPUT" 521 >v4l2_input</A 522 > and 523 struct <A 524 HREF="r9149.htm#V4L2-OUTPUT" 525 >v4l2_output</A 526 > <CODE 527 CLASS="STRUCTFIELD" 528 >std</CODE 529 > field would be a set of 530 indices like <CODE 531 CLASS="STRUCTFIELD" 532 >audioset</CODE 533 >.</P 534 ><P 535 >Indices are consistent with the rest of the API 536 and identify the standard unambiguously. In the present scheme of 537 things an enumerated standard is looked up by <A 538 HREF="r9288.htm#V4L2-STD-ID" 539 >v4l2_std_id</A 540 >. Now the 541 standards supported by the inputs of a device can overlap. Just 542 assume the tuner and composite input in the example above both 543 exist on a device. An enumeration of "PAL-B/G", "PAL-H/I" suggests 544 a choice which does not exist. We cannot merge or omit sets, because 545 applications would be unable to find the standards reported by 546 <CODE 547 CLASS="CONSTANT" 548 >VIDIOC_G_STD</CODE 549 >. That leaves separate enumerations 550 for each input. Also selecting a standard by <A 551 HREF="r9288.htm#V4L2-STD-ID" 552 >v4l2_std_id</A 553 > can be 554 ambiguous. Advantage of this method is that applications need not 555 identify the standard indirectly, after enumerating.</P 556 ><P 557 >So in 558 summary, the lookup itself is unavoidable. The difference is only 559 whether the lookup is necessary to find an enumerated standard or to 560 switch to a standard by <A 561 HREF="r9288.htm#V4L2-STD-ID" 562 >v4l2_std_id</A 563 >.</P 564 ></TD 565 ></TR 566 ><TR 567 ><TD 568 ALIGN="LEFT" 569 VALIGN="TOP" 570 WIDTH="5%" 571 ><A 572 NAME="FTN.AEN507" 573 HREF="x448.htm#AEN507" 574 ><SPAN 575 CLASS="footnote" 576 >[3]</SPAN 577 ></A 578 ></TD 579 ><TD 580 ALIGN="LEFT" 581 VALIGN="TOP" 582 WIDTH="95%" 583 ><P 584 >See <A 585 HREF="x5953.htm" 586 >Section 3.5</A 587 > for a rationale. Probably 588 even USB cameras follow some well known video standard. It might have 589 been better to explicitly indicate elsewhere if a device cannot live 590 up to normal expectations, instead of this exception.</P 591 ></TD 592 ></TR 593 ></TABLE 594 ><DIV 595 CLASS="NAVFOOTER" 596 ><HR 597 ALIGN="LEFT" 598 WIDTH="100%"><TABLE 599 SUMMARY="Footer navigation table" 600 WIDTH="100%" 601 BORDER="0" 602 CELLPADDING="0" 603 CELLSPACING="0" 604 ><TR 605 ><TD 606 WIDTH="33%" 607 ALIGN="left" 608 VALIGN="top" 609 ><A 610 HREF="x394.htm" 611 ACCESSKEY="P" 612 >Prev</A 613 ></TD 614 ><TD 615 WIDTH="34%" 616 ALIGN="center" 617 VALIGN="top" 618 ><A 619 HREF="book1.htm" 620 ACCESSKEY="H" 621 >Home</A 622 ></TD 623 ><TD 624 WIDTH="33%" 625 ALIGN="right" 626 VALIGN="top" 627 ><A 628 HREF="x542.htm" 629 ACCESSKEY="N" 630 >Next</A 631 ></TD 632 ></TR 633 ><TR 634 ><TD 635 WIDTH="33%" 636 ALIGN="left" 637 VALIGN="top" 638 >Tuners and Modulators</TD 639 ><TD 640 WIDTH="34%" 641 ALIGN="center" 642 VALIGN="top" 643 ><A 644 HREF="c174.htm" 645 ACCESSKEY="U" 646 >Up</A 647 ></TD 648 ><TD 649 WIDTH="33%" 650 ALIGN="right" 651 VALIGN="top" 652 >User Controls</TD 653 ></TR 654 ></TABLE 655 ></DIV 656 ></BODY 657 ></HTML 658 > 659