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