Home
PDF file - LinuxTV.org
Contents
1. define V4L2 CID MPEG CX2341X BASE VAL2 CTRL CLASS MPEG define V4L2 CID MPEG CX2341X VIDEO SPATIAL FILTER MODE VAL2 CID MPEG CX2341X B enum v412 mpeg cx2341x video spatial filter mode VA4L2 MPEG CX2341X VIDEO SPATIAL FILTER MODE MANUAL 0 V4L2 MPEG CX2341X VIDEO SPATIAL FILTER MODE AUTO 1 define V4L2 CID MPEG CX2341X VIDEO SPATIAL FILTER VAL2 CID MPEG CX2341X B define V4L2 CID MPEG CX2341X VIDEO LUMA SPATIAL FILTER TYPE VAL2 CID MPEG CX2341X B enum v412 mpeg cx2341x video luma spatial filter type V4L2 MPEG CX2341X VIDEO LUMA SPATIAL FILTER TYPE OFF 240 VA4L2 MPEG CX2341X VIDEO LUMA SPATIAL FILTER TYPE 1D HOR ES V4L2 MPEG CX2341X VIDEO LUMA SPATIAL FILTER TYPE 1D VERT 2 V4L2 MPEG CX2341X VIDEO LUMA SPATIAL FILTER TYPE 2D HV SEPARABLE 3 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE 4 define V4L2 CID MPEG CX2341X VIDEO CHROMA SPATIAL FILTER TYPF VAL2 CID MPEG CX2341X B enum v412 mpeg cx2341x video chroma spatial filter type VA4L2 MPEG CX2341X VIDEO CHROMA SPATIAL FILTER TYPE OFF 0 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR 1 i define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE V4L2_CID_MPEG_CX2341X_B enum v412_mpeg_cx2341x_video_temporal_filter_mode V4L2_MPEG_CX2341X_VID
2. define V4L2 FIELD HAS TOP field N field V4L2 FIELD TOP LEX field V4L2 FIELD INTERLACED l N field V4L2 FIELD INTERLACED TB N field V4L2 FIELD INTERLACED BT N field VA4L2 FIELD SEQ TB LIN field VA4L2 FIELD SEO BT define V4L2 FIELD HAS BOTTOM field N field V4L2 FIELD BOTTOM LIN field V4L2 FIELD INTERLACED field V4L2 FIELD INTERLACED TB N field V4L2 FIELD INTERLACED BT N field VA4L2 FIELD SEQ TB LIN field VA4L2 FIELD SEO BT define V4L2 FIELD HAS BOTH field amp field V4A4L2 FIELD I RLACED field V4L2 FIELD INTERLACED TB N field V4L2 FIELD INTERLACED BT N field VAL2 FIELD SEQ TB field VA4L2 FIELD SEO BT enum v412 buf type V4L2 BUE YPE VIDEO CAPTURE 1 V4L2_BUF YPE_VIDEO_OUTPUT 2 V4L2_BUF YPE VIDEO OVERLAY 3 V4L2_BUE YPE_VBI_CAPTURE 4 V4L2_BUEF YPE_VBI_OUTPUT m5 VA4L2 BUE YPE SLICED VBI CAPTURE 6 V4L2_BUEF YPE_SLICED_VBI_OUTPUT 7 if 1 KEEP Experimental x V4L2_BUE YPE_VIDEO_OUTPUT_OVERLAY 8 endif V4L2_BUF_TYPE_PRIVATE 0x80 H enum v412 ctrl type VA4L2 CTRL TYPE INTEGER VA4L2 CTRL TYPE BOOLEAN VA4L2 CTR
3. control id VA4L2 CID AUDIO MUTE control value TRUE silence x Errors ignored ioctl fd VIDIOC 5 CTRL amp control 1 9 Extended Controls 1 9 1 Introduction The control mechanism as originally designed was meant to be used for user settings brightness saturation etc However it turned out to be a very useful model for implementing more complicated driver APIs where each driver implements only a subset of a larger API The MPEG encoding API was the driving force behind designing and implementing this extended control mechanism the MPEG standard is quite large and the currently supported hardware MPEG encoders each only implement a subset of this standard Further more many parameters relating to how the video is encoded into an MPEG stream are specific to the MPEG encoding chip since the MPEG standard only defines the format of the resulting MPEG stream not how the video is actually encoded into that format 14 Chapter 1 Common API Elements Unfortunately the original control API lacked some features needed for these new uses and so it was extended into the not terribly originally named extended control API 1 9 2 The Extended Control API Three new ioctls are available VIDIOC G EXT CTRLS VIDIOC S EXT CTRLS and VIDIOC TRY EXT CTRLS These ioctls act on arrays of controls as opposed to the VIDIOC G CTRL and VIDIOC S CTRL ioctls that act on a single cont
4. CID_MPEG_VIDEO_MUTE_YUV integer Sets the mute color of the video The supplied 32 bit integer is interpreted as follows bit 0 least significant ENTRYTBL not supported 1 9 5 2 CX2341x MPEG Controls The following MPEG class controls deal with MPEG encoding settings that are specific to the Conexant CX23415 and CX23416 MPEG encoding chips Table 1 3 CX2341x Control IDs ID Type Description V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE enum Sets the Spatial Filter mode default MANUAL Possible values are ENTRYTBL not supported V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER integer 0 15 The setting for the Spatial Filter 0 off 15 maximum Default is 0 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE enum Select the algorithm to use for the Luma Spatial Filter default 1D_HOR Possible values ENTRYTBL not supported V4L2 CID MPEG CX2341X VIDEO CHROMA SPATIAL FILTER TYPE enum Select the algorithm for the Chroma Spatial Filter default 1D HOR Possible values are 19 Chapter 1 Common API Elements ID Type Description ENTRYTBL not supported VA4L2 CID MPEG CX2341X VIDEO TEMPORAL FILTER MODE enum Sets the Temporal Filter mode default MANUAL Possible values are ENTRYTBL not supported V4L2 CID MPEG CX2341X VIDEO TEMPORAL FILTER integer 0 31
5. or more menu type controls Example 1 8 Enumerating all controls struct v412 queryctrl queryctrl struct v412 querymenu querymenu static void enumerate menu void printf Menu items n memset amp querymenu 0 sizeof querymenu id queryctrl id querymenu for querymenu index queryctrl minimum querymenu index lt queryctrl maximum querymenu index if 0 ioctl fd VIDIOC QUERYMENU amp querymenu printf else sWXn querymenu name perror VIDIOC QUERYMENU exit EXIT FAILURE 12 Chapter 1 Common API Elements memset amp queryctrl 0 sizeof queryctrl for queryctrl id V4L2_CID_BASE queryctrl id lt V4L2_CID_LASTP1 queryctrl idt if 0 ioctl fd VIDIOC QUERYCTRL amp queryctrl if queryctrl flags amp V4L2 CTRL FLAG DISABLED continue printf Control s n queryctrl name if queryctrl type V4L2 CTRL TYPE MENU enumerate menu else if errno EINVAL continue perror VIDIOC_QUERYCTRL exit EXIT_FAILURE for queryctrl id VA4L2 CID PRIVATE BASE queryctrl idt if 0 ioctl fd VIDIOC QUERYCTRL amp queryctrl if queryctrl flags amp V4L2 CTRL FLAG DISABLED continue printf Control s n queryctrl name if queryctrl type V4L
6. 2 The ioctls VIDIOC_ENUM_FRAMESIZES and VIDIOC ENUM FRAMEINTERVALS were added 3 A new pixel format VAL2 PIX FMT RGBA444 Table 2 1 was added 6 2 25 V4L2 spec erratum 2006 10 12 Draft 0 17 1 VAL2 PIX FMT HM12 Table 2 8 is a YUV 4 2 0 not 4 2 2 format 6 2 26 V4L2 in Linux 2 6 21 1 The videodev2 h header file is now dual licensed under GNU General Public License version two or later and under a 3 clause BSD style license 221 Chapter 6 Changes 6 2 27 V4L2 in Linux 2 6 22 1 Two new field orders VAL2 FIELD INTERLACED TB and VAL2 FIELD INTERLACED BT were added See Table 3 8 for details 2 Three new clipping blending methods with a global or straight or inverted local alpha value were added to the video overlay interface See the description of the VIDIOC_G_FBUF and VIDIOC S FBUF ioctls for details A new global alpha field was added to v412 window extending the structure This may break compatibility with applications using a struct v412 window directly However the VIDIOC_G S TRY_FMT ioctls which take a pointer to a v412 format parent structure with padding bytes at the end are not affected 3 The format of the chromakey field in struct v412 window changed from host order RGB32 to a pixel value in the same format as the framebuffer This may break compatibility with existing applications Drivers supporting the host order RGB32 format
7. sss 83 4 0 Teletext Interfacez un a E RaR 84 2 10 Radio Interface eo creed ect em ei de t edat 85 4 10 1 Querying Capabilities ienei A E ESEE trementes 85 4 10 2 Supplemental Functions Ue tied inita eie P Uere eerbcns 85 4 10 3 Programming esee eere eret Eee EE eie Per eret 85 4 11 RDS Interface eee oer eric ec ie aeree eden eee te ee ee eee 85 L Function Reference 87 MALE2 close ue situ eme us un eue 89 b pAMUge CE 90 IoctI VIDIOC CROPGAD nitet RUE AREE RS 92 ioctl VIDIOC DBG G REGISTER VIDIOC DBG S REGISTER 94 ioctl VIDIOC ENCODER CMD VIDIOC TRY ENCODER CMD eee 97 ioctl VIDIOC ENUMBAUDIO ite ea ode ea e ERR EA ea Sube 99 ioctl VIDIOC_ENUMAUDOUT esseseseeeeeeeneenre enhn nennen eren sinere nnne sentire nn nenn 100 ioctl VIDIOC_ENUM_FM1 c ccccccsssssssscsssecssesssecsesecesssesecessecesseesecessecessesaecessenesesaeeeneees 101 ioctl VIDIOC_LENUM_FRAMESIZES esses enne eren ernst nnne rn serene 103 ioctl VIDIOC ENUM FRAMEINTERVALS cccccccccsssessscesceceeeeeseseseeceecessesesseseeesseseneees 106 ioctl VIDIOC ENUMINPUT ccccccssssssscsssecsseeesecessecssceeseceseeceseeeseceseeceesesuecesseseseaeeenaens 109 ioctl VIDIOC ENUMQOUTPUT eese enne nennen etes stes etes e enses etes entr senten te nen 112 ioctl VIDIOC ENUMSTD D ASEE E E S A A EE 114 ioc
8. The 32 bit qct rl id value is subdivided into three bit ranges the top 4 bits are reserved for flags e g VAL2 CTRL FLAG NEXT CTRL and are not actually part of the ID The remaining 28 bits form the control ID of which the most significant 12 bits define the control class and the least significant 16 bits identify the control within the control class It is guaranteed that these last 16 bits are always non zero for controls The range of 0x1000 and up are reserved for driver specific controls The macro V4L2_CTRL_ID2CLASS id returns the control class ID based on a control ID If the driver does not support extended controls then VIDIOC_QUERYCTRL will fail when used in combination with VAL2 CTRL FLAG NEXT CTRL lIn that case the old method of enumerating control should be used see 1 8 But if it is supported then it is guaranteed to enumerate over all controls including driver private controls 1 9 4 Creating Control Panels It is possible to create control panels for a graphical user interface where the user can select the various controls Basically you will have to iterate over all controls using the method described above Each control class starts with a control of type V4AL2 CTRL TYPE CTRL CLASS VIDIOC_QUERYCTRL Will return the name of this control class which can be used as the title of a tab page within a control panel The flags field of struct v412_queryctrl also contains hints on t
9. 92 struct v4I2 rect bounds struct v4I2 rect defrect struct v412_fract pixelaspect Table 2 struct v4I2 rect 832 left 32 top 32 width 832 height Return Value ioctl VIDIOC CROPCAP Defines the window within capturing or output is possible this may exclude for example the horizontal and vertical blanking areas The cropping rectangle cannot exceed these limits Width and height are defined in pixels the driver writer is free to choose origin and units of the coordinate system in the analog domain Default cropping rectangle it shall cover the whole picture Assuming pixel aspect 1 1 this could be for example a 640 x 480 rectangle for NTSC a 768 x 576 rectangle for PAL and SECAM centered over the active picture area The same co ordinate system as for bounds is used This is the pixel aspect y x when no scaling is applied the ratio of the actual sampling frequency and the frequency required to get square pixels When cropping coordinates refer to square pixels the driver sets pixelaspect to 1 1 Other common values are 54 59 for PAL and SECAM 11 10 for NTSC sampled according to ITU BT 601 Horizontal offset of the top left corner of the rectangle in pixels Vertical offset of the top left corner of the rectangle in pixels Width of the rectangle in pixels Height of the rectangle in pixels Width and height cannot be negative the fields are signed for hysterical reasons On
10. 11 12 Chapter 6 Changes Old defines enum v4I2 buf type VAL2 BUF TYPE EFFECTSIN Omitted for now VAL2 BUF TYPE EFFECTSIN2 Omitted for now VAL2 BUF TYPE EFFECTSOUT Omitted for now V4L2 BUF TYPE VIDEOOUT V4L2 BUF TYPE VIDEO OUTPUT VAL2 BUF TYPE VIDEO OVERLAY zx IVAL2 BUF TYPE VBI CAPTURE IVAL2 BUF TYPE VBI OUTPUT LH VAL2 BUF TYPE SLICED VBI CAPTUR VAL2 BUF TYPE SLICED VBI OUTPUT VAL2 BUF TYPE PRIVATE BASE VAL2 BUF TYPE PRIVATE In struct v412_fmtdesc a enum v412 buf type field named t ype was added as in struct v412 format The VIDIOC ENUM FBUFFMT ioctl is no longer needed and was removed These calls can be replaced by VIDIOC_ENUM_FMT with type V4L2 BUF TYPE VIDEO OVERLAY In struct v412 pix format the depth field was removed assuming applications which recognize the format by its four character code already know the color depth and others do not care about it The same rationale lead to the removal of the v4L2_FMT_FLAG_COMPRESSED flag The VAL2 FMT FLAG SWCONVECOMPRESSED flag was removed because drivers are not supposed to convert images in kernel space A user library of conversion functions should be provided instead The v4L2 FMT FLAG BYTESPERLINE flag was redundant Applications can set the bytesp
11. 8 RGB 3 3 2 4 16 xxxxrrrr ggggbbbb O 16 RGB 5 5 5 P 16 RGB 5 6 5 Q 16 RGB 5 5 5 BE x R 16 RGB 5 6 5 BE x 3 24 BGR 8 8 8 3 24 RGB 8 8 8 4 x 32 BGR 8 8 8 8 229 Appendix A Video For Linux Two Header File define V4L2 PIX FMT RGB32 v412 fourcc R G B 4 x 32 RGB 8 8 8 8 define V4L2 PIX FMT GREY v412 fourcc G R E Y x 8 Greyscale x define VA4L2 PIX FMT Y16 v412 fourcc Y 1 6 x 16 Greyscale define VA4L2 PIX FMT PALS8 v412 fourcc P A L 8 8 8 bit palette x define V4L2 PIX FMT YVU410 v412 fourcc Y V U 9 x 9 YVU 4 1 0 x define V4L2_PIX_FMT_YVU420 v412 fourcc Y V 1 2 x 12 YVU 4 2 0 x define V4L2 PIX FMT YUYV vy412 fourcc Y U Y N Y fe T6 YXUV 49222 x define VA4L2 PIX FMT UYVY v4l2 fourcc u LNT Vt Ux Y x VE YUV 4 222 x define VAL2 PIX FMT YUV422P v412 fourcc 4 2 2 P x 16 YVU422 planar define V4L2_PIX_FMT_YUV411P uro m DE 16 YVU411 planar define V4L2_PIX_FMT_Y41P v4l2 tourcec t t4 t10 npfy Zx X2 MUN WT x define VA4AL2 PIX FMT YUV444 v412 fourcc Y 4 4 4 x 16 xxxxyyyy uuuuvvvv x define V4L2 PIX FMT YUV555 v412 fourcc Y U V O 16 YUV 5 5 5 define VA4L2 PIX FMT YUV565 v412 fourcc Y U V P x 16 YUV 5 6 5 define V4L2_PIX_FMT_YUV32 v412 fourcc Y U V 4 32 YUV 8 8 8 8 x two planes one
12. Frame intervals and frame rates The V4L2 API uses frame intervals instead of frame rates Given the frame interval the frame rate can be computed as follows frame rate 1 frame interval Structs In the structs below IN denotes a value that has to be filled in by the application OUT denotes values that the driver fills in The application should zero out all members except for the JN fields Table 1 struct v412 frmival stepwise struct v412 fract min Minimum frame interval s struct v412_fract max Maximum frame interval s struct v412_fract step Frame interval step size s Table 2 struct v412_frmivalenum u32 index IN Index of the given frame interval in the enumeration u32 pixel format IN Pixel format for which the frame intervals are enumerated u32 width IN Frame width for which the frame intervals are enumerated u32 height IN Frame height for which the frame intervals are enumerated 107 u32 union u32 Enums ioctl VIDIOC ENUM FRAMEINTERVALS type OUT Frame interval type the device supports OUT Frame interval with the given index struct v412_fract discrete Frame interval s struct v412_frmival_stepwasepwise reserved 2 Reserved space for future use Table 3 enum v4l2 frmivaltypes VAL2 FRMIVAL VAL2 FRMIVAL VAL2 FRMIVAL YPE DISCRETE Discrete frame interval YPE_CONTINUOUS2 Continuous frame interval YPE_STEPWISE 3
13. Return Value ioctl VIDIOC ENUM FRAMESIZES Reserved space for future use Discrete frame size Continuous frame size Step wise defined frame size On success 0 is returned on error 1 and the errno variable is set appropriately See the description section above for a list of return values that errno can have 105 ioctl VIDIOC ENUM FRAMEINTERVALS Name VIDIOC ENUM FRAMEINTERVALS Enumerate frame intervals Synopsis int ioctl int fd int request struct v412 frmivalenum xargp Arguments fd File descriptor returned by open request VIDIOC ENUM FRAMEINTERVALS argp Pointer to a struct v412_frmivalenum structure that contains a pixel format and size and receives a frame interval Description This ioctl allows applications to enumerate all frame intervals that the device supports for the given pixel format and frame size The supported pixel formats and frame sizes can be obtained by using the VIDIOC_ENUM_FMT and VIDIOC ENUM FRAMESIZES functions The return value and the content of the v412 rmivalenum type field depend on the type of frame intervals the device supports Here are the semantics of the function for the different cases Discrete The function returns success if the given index value zero based is valid The application should increase the index by one for each call until EINVAL is returned The v4 2 frmivalenum type field is set to VAL2 FRMIVAL TYP
14. V4L2 TC TYPE 24FPS 1 V4L2 TC TYPE 25FPS 2 VA4L2 TC TYPE 30FPS 3 V4L2 TC TYPE 50FPS 4 V4L2 TC TYPE 60FPS 5 VAL2 TC FLAG DROPFRAM Ed V4L2 TC FLAG COLORFRAME 0x0002 V4L2 TC USERBITS field 0x000C V4L2 TC USERBITS USERDEFINED 0x0000 V4L2 TC USERBITS 8BITCHARS 0x0008 bove is based on SMPTE timecodes x struct v412 jpegcompression int quality int APPn x Number of APP se x must be 0 15 int APP len Length of data i gment 0x0001 drop frame mode to be written n JPEG APPn segment x 232 char APP data 60 int COM len char COM data 60 u32 jpeg markers Da Da Appendix A Video For Linux Two Header File output you do Inluding less markers will make the resulting code smaller ta in the JPEG APPn segment Length of data in JPEG COM segment ta in JPEG CO segment x Which markers should go into the JPEG Unless you exactly know what leave them untouched but there will be fewer aplications which can read it The presenc of the APP and COM marker is influenced by APP len and COM len not by this property Define Huffman Tables Define Quantization Tables x Define Restart Interval Comment segment App segment driver will allways use APPO x BUFFERS ONLY
15. crop c cropcap defrect memset amp format 0 sizeof format format fmt type V4L2_BUF_TYPE_VIDEO_CAPTURE ET if 1 ioctl fd VIDIOC G FMT amp format perror VIDIOC G FMT exit EXIT FAILURE The scaling applied by the driver hscale format fmt pix width double crop c width vscale format fmt pix height double crop c height aspect cropcap pixelaspect numerator double cropcap pixelaspect denominator aspect aspect hscale vscale Devices following ITU R BT 601 do not capture Square pixels For playback on a computer monitor we should scale the images to this size x dwidth format fmt pix width aspect dheight format fmt pix height 1 12 Streaming Parameters Streaming parameters are intended to optimize the video capture process as well as I O Presently applications can request a high quality capture mode with the VIDIOC_S_PARM ioctl The current video standard determines a nominal number of frames per second If less than this number of frames is to be captured or output applications can request frame skipping or duplicating on the driver side This is especially useful when using the read or write which are not augmented by timestamps or sequence counters and to avoid unneccessary data copying Finally these ioctls can be used to determine the number of buffers used internally by a driver in read write mode For implicatio
16. eese nennen 62 3 2 Field Order Bottom Field First Transmitted esses eene 63 4 1 Line synchronization n eret eere Terent e dae eR EAT eee EE PER Me eee A e TI 4 2 ITU R 525 line numbering M NTSC and M PAL eeeeeeereeenen ene 77 4 3 ITU R 625 line numbering eee e E e ER reee E E S E E R IE 79 Introduction Video For Linux Two is the second version of the Video For Linux API a kernel interface for analog radio and video capture and output drivers Early drivers used ad hoc interfaces These were replaced in Linux 2 2 by Alan Cox V4L API based on the interface of the bttv driver In 1999 Bill Dirks started the development of V4L2 to fix some shortcomings of VAL and to support a wider range of devices The API was revised again in 2002 prior to its inclusion in Linux 2 5 2 6 and work continues on improvements and additions while maintaining compatibility with existing drivers and applications In 2006 2007 efforts began on FreeBSD drivers with a V4L2 interface This book documents the V4L2 API Intended audience are driver and application writers If you have questions or ideas regarding the API please write to the Video4Linux mailing list https listman redhat com mailman listinfo video4linux list For inquiries about the V4L2 specification contact the maintainer mschimek gmx at mailto mschimek gmx at The latest version of this document and the DocBook SGML source
17. u32 u32 u32 struct v4I2 ext control controls value value64 Identifies the control set by the application Reserved for future extensions Drivers and applications must set the array to Zero New value or current value New value or current value reserved Reserved for future pointer type ctrl class count error idx reserved 2 Table 3 Control classes V4L2 CTRL CLASS USER VAL2 CTRL CLASS MPI EG Return Value 0x980000 0x990000 controls Currently unused The control class to which all controls belong see Table 3 The number of controls in the controls array May also be zero Set by the driver in case of an error It is the index of the control causing the error or equal to count when the error is not associated with a particular control Undefined when the ioctl returns 0 success Reserved for future extensions Drivers and applications must set the array to zero Pointer to an array of count v412 ext control structures Ignored if count equals zero The class containing user controls These controls are described in Section 1 8 All controls that can be set using the VIDIOC S CTRL and VIDIOC G CTRL ioctl belong to this class The class containing MPEG compression controls These controls are described in section Section 1 9 5 On success 0 is returned on error 1 and the errno variable is set appropriately 133 ioctl VIDIOC G EXT CTRLS
18. 3032 index name 32 capability mode reserved 2 NOTE if 1 KEE define define define define RI ENTAL API Px V4L2_ENC V4L2 V4L2 V4L2 DX DX DX DX FRAM FRAM FRAM FRAM Tj Q Ij Q H HHH Tj X pp pp od NC MAS RVIC field 0x00001 0x00002 field 0x00001 Gl 02 K 245 Appendix A Video For Linux Two Header File struct v412 enc idx entry u64 offset u64 pts u32 length u32 flags u32 reserved 2 F define V4L2_ENC_IDX_ENTRIES 64 struct v412 enc idx u32 entries u32 entries cap u32 reserved 4 struct v412 enc idx entry entry V4L2 ENC IDX ENTRIES define V4L2 ENC CMD START 0 define V4L2 ENC CMD STOP 1 define V4L2 ENC CMD PAUSE 2 define V4L2 ENC CMD RESUME 3 Flags for VA4L2 ENC CMD STOP x define V4L2 ENC CMD STOP AT GOP END 1 struct v412 encoder cmd 0 4832 cmd u32 flags union struct u32 data 8 raw hi fendif DATA SERVICES VBI Data services API by Michael Schimek Raw VBI x struct v412 vbi format u32 sampling rate in 1 Hz x u32 offset 2 samples per line u32 sample format x VAL2 PIX FMT 832 start 2 u32 count 2 u32 flags VAL
19. L2 PRIORI struct v412 rect 332 us32 832 i832 iF struct v412_fract u32 u32 HH Y DEFAULT left top width height numerator denominator th 0 1 2 3 7 is is 8 probably a good start not initialized VAL2 PRIORITY INT ERACTIV 228 Appendix A Video For Linux Two Header File DRIVER CAPAB ILILITIIES struct v412 capability us driver 16 i e ie bttv u8 card 32 i e ie Hauppauge WinTV x u8 bus info 32 PCI pci name pci dev u32 version should use KERNEL VERSION x ae capabilities Device capabilities u32 reserved 4 x Values for capabilities field define V4L2 CAP VIDEO CAPTURE 0x00000001 x Is a video capture device define VA4L2 CAP VIDEO OUTPUT 0x00000002 x Is a video output device x define V4L2 CAP VIDEO OVERLAY 0x00000004 x Can do video overlay define V4L2 CAP VBI CAPTURE 0x00000010 Is a raw VBI capture device define V4L2 CAP VBI OUTPUT 0x00000020 Is a raw VBI output device define V4L2 CAP SLICED VBI CAPTURE 0x00000040 x Is a sliced VBI capture device x define V4L2 CAP SLICED VBI OUTPUT 0x00000080 x Is a sliced VBI output device define V4L2 CAP RDS CAPTURE 0x00000100 x RDS data capture define V4L2 CAP VI
20. VIDIOC_STREAMON VIDIOC_STREAMOFF argp Description The VIDIOC_STREAMON and VIDIOC_STREAMOFF ioctl start and stop the capture or output process during streaming memory mapping or user pointer I O Specifically the capture hardware is disabled and no input buffers are filled if there are any empty buffers in the incoming queue until VIDIOC_STREAMON has been called Accordingly the output hardware is disabled no video signal is produced until VIDIOC_STREAMON has been called The ioctl will succeed only when at least one output buffer is in the incoming queue The VIDIOC_STREAMOFF ioctl apart of aborting or finishing any DMA in progress unlocks any user pointer buffers locked in physical memory and it removes all buffers from the incoming and outgoing queues That means all images captured but not dequeued yet will be lost likewise all images enqueued for output but not transmitted yet I O returns to the same state as after calling VIDIOC_REQBUFS and can be restarted accordingly Both ioctls take a pointer to an integer the desired buffer or stream type This is the same as struct v412_requestbuffers type 186 ioctl VIDIOC STREAMON VIDIOC STREAMOFF Note applications can be preempted for unknown periods right before or after the VIDIOC STRI EAMON Or VIDIOC STRI EAMOFF calls there is no notion of starting or stopping now Buffer timestamps can be used to synchronize with other events Retu
21. argp Description To query the attributes of a video outputs applications initialize the index field of struct v412 output and call the VIDIOC_ENUMOUTPUT ioctl with a pointer to this structure Drivers fill the rest of the structure or return an EINVAL error code when the index is out of bounds To enumerate all outputs applications shall begin at index zero incrementing by one until the driver returns EINVAL Table 1 struct v4l2 output u32 index Identifies the output set by the application u8 name 32 Name of the video output a NUL terminated ASCII string for example Vout This information is intended for the user preferably the connector label on the device itself u32 type Type of the output see Table 2 112 u32 audioset u32 modulator v412 std id std u32 reserved 4 Table 2 Output Type VA4L2 OUTPUT TYPE MODULATOR 1 V4L2 OUTPUT TYPE ANALOG 2 VA4L2 OUTPUT TYPE ANALOGVGAOV RLAY Return Value ioctl VIDIOC ENUMOUTPUT Drivers can enumerate up to 32 video and audio outputs This field shows which audio outputs were selectable as the current output if this was the currently selected video output It is a bit mask The LSB corresponds to audio output 0 the MSB to output 31 Any number of bits can be set or none When the driver does not enumerate audio outputs no bits must be set Applications shall not interpret this as lack of audio support Drivers may a
22. NO COLOR Analog Video 0x00000001 Attached device is off 0x00000002 0x00000004 The hardware supports color decoding but does not detect color modulation in the signal 110 VA4L2 IN ST NO H LOCK VAL2 IN ST COLOR KILL Digital Video VAL2 IN ST NO SYNC VA4L2 IN ST NO EQU VAL2 IN ST NO CARRIER VCR and Set Top Box V4L2 IN ST V4L2 IN ST VAL2 IN ST _MACROVISION NO ACCESS _VTR Return Value 0x00000100 0x00000200 0x00010000 0x00020000 0x00040000 0x01000000 0x02000000 0x04000000 ioctl VIDIOC_ENUMINPUT No horizontal sync lock A color killer circuit automatically disables color decoding when it detects no color modulation When this flag is set the color killer is enabled and has shut off color decoding No synchronization lock No equalizer lock Carrier recovery failed Macrovision is an analog copy prevention system mangling the video signal to confuse video recorders When this flag is set Macrovision has been detected Conditional access denied VTR time constant On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The struct v412 input index is out of bounds 111 ioctl VIDIOC ENUMOUTPUT Name VIDIOC ENUMOUTPUT Enumerate video outputs Synopsis int ioctl int fd int request struct v412 output argp Arguments fd File descriptor returned by open request VIDIOC ENUMOUTPUT
23. Name of the modulator a NUL terminated ASCII string This information is intended for the user Modulator capability flags No flags are defined for this field the tuner flags in struct v412 tuner are used accordingly The audio flags indicate the ability to encode audio subprograms They will not change for example with the current video standard The lowest tunable frequency in units of 62 5 KHz or if the capability flag V4L2_TUNER_CAP_LOW is set in units of 62 5 Hz The highest tunable frequency in units of 62 5 KHz or if the capability flag VA4L2 TUNER CAP LOW is set in units of 62 5 Hz With this field applications can determine how audio sub carriers shall be modulated It contains a set of flags as defined in Table 2 Note the tuner rxsubchans flags are reused but the semantics are different Video output devices are assumed to have an analog or PCM audio input with 1 3 channels The txsubchans flags select one or more channels for modulation together with some audio subprogram indicator for example a stereo pilot tone Reserved for future extensions Drivers and applications must set the array to zero Modulate channel 1 as mono audio when the input has more channels a down mix of channel 1 and 2 This flag does not combine with V4L2 TUNER SUB STEREO or VA4L2 TUNER SUB LANGI Modulate channel 1 and 2 as left and right channel of a stereo audio signal When the input h
24. T6 struct VIDIOC ENCODER CMD _IOWR V 77 struct VIDIOC TRY ENCODER CMD _IOWR V 78 struct define VIDIOC DBG S REGISTER IOW V define VIDIOC DBG G REGISTER _IOWR V define VIDIOC G CHIP IDEN _IOWR V endif ifdef OLD VIDIOC for compatibility will go away some day define VIDIOC OVERLAY OLD _IOWR V define VIDIOC S PARM OLD IOW CNT S define VIDIOC_S_CTRL_OLD IOW RENS define VIDIOC_G_AUDIO_OLD _IOWR V define VIDIOC G AUDOUT OLD _IOWR V define VIDIOC CROPCAP OLD IOR Iw endif define BASE VIDIOC PRIVATE 192 endif X LINUX VIDEODEV2 H x Local variables C basic offset x End 8 69 struct 70 71 42 Struct o Cruct top SELUGE only implemented if CONFIG_VIDEO_ADV_ 79 80 Cruct Cruct 81 struct x 14 int 22 St uC 28 struct 33 struct 49 struct 58 struct v4 v4 v4 v4 v4 v4 v4 v4 v4 12 sliced vbi cap l2 ext controls l2 ext controls 12 ext controls l2 frmsizeenum struct v412 frmivalenum 12 enc idx l2 encoder cmd l2 encoder cmd EBUG is defined 12 register 12 register v4 12 chip ident v412 streamparm v412 control v412 audio v412 audioout v412 cropcap 192 255 are private 250 Appendix B Video Capture Example x V4L2 video cap
25. The setting for the Temporal Filter 0 off 31 maximum Default is 8 for full scale capturing and 0 for scale V4L2 CID MPEG CX2341X VIDEO MEDIAN FILTER TYPE enum Median Filter Type default OFF Possible values are ENTRYTBL not supported V4L2 CID MPEG CX2341X VIDEO LUMA MEDIAN FILTER BOTTOM integer 0 255 Threshold above which the luminance median filter is enabled default 0 V4L2 CID MPEG CX2341X VIDEO LUMA MEDIAN FILTER TOP integer 0 255 Threshold below which the luminance median filter is enabled default 255 V4L2 CID MPEG CX2341X VIDEO CHROMA MEDIAN FILTER BOTTOM integer 0 255 Threshold above which the chroma median filter is enabled default 0 V4L2 CID MPEG CX2341X VIDEO CHROMA MEDIAN FILTER TOP integer 0 255 Threshold below which the chroma median filter is enabled default 255 V4L2 CID MPEG CX2341X STREAM INSERT NAV PACKETS bool The CX2341X MPEG encoder can insert one empty MPEG 2 PES packet into the stream between every four vi 1 9 6 Camera Control Reference The Camera class includes controls for mechanical or equivalent digital features of a device such as controllable lenses or sensors 20 Chapter 1 Common API Elements Table 1 4 Camera Control IDs ID Type Description V4L2 CID CAMERA CLASS V4L2 CID EXPOSURE AUTO V4L2 CID EXPOSURE ABSOLUTI V4L2 CID EXP
26. V4L2 CID AUDIO MUTE boolean Mute audio i e set the volume to zero however without affecting VAL2 CID AUDIO VOLUME Like ALSA drivers VAL2 drivers must mute at load time to avoid excessive noise Actually the entire device should be reset to a low power consumption state 10 ID VAL2 CID AUDIO VAL2 CID BLACK OU DNESS EV V4L2 CID AUTO WHITI E BALA V4L2 CID DO WHITE BALANCE V4AL2 CID RED BALANCE VAL2 CID BLUE BALANCE VAL2 CID GAMI VAL2 CID WHIT ENESS VA4L2 CID EXPOSURE V4L2_CID_AUTOGAI V4L2_CID_GAIN V4L2_CID_HFLIP V4L2_CID_VFLIP Type boolean integer CE boolean button integer integer integer integer integer boolean integer boolean boolean V4L2_CID_HCENT ER_D EPRECAT ED integer formerly V4L2_CID_HCENTER V4L2_CID_VCENT ER_D EPRECAT formerly V4L2_CID_VCENTER ED integer V4L2_CID_POWER_LIN ENCinteger Chapter 1 Common API Elements Description Loudness mode bass boost Another name for brightness not a synonym of V4L2_CID_BRIGHTNESS This control is deprecated and should not be used in new drivers and applications Automatic white balance cameras This is an action control When set the value is ignored the device will do a white balance
27. __u32 a lt lt 0 __u32 b 8 u32 c 16 __u32 u32 reserved 4 Reserved for future extensions Drivers must set the array to zero Table 2 Image Format Description Flags V4L2 FMT FLAG COMPRESSED 0x0001 This is a compressed format Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The struct v412_fmtdesc type is not supported or the index is out of bounds 102 ioctl VIDIOC ENUM FRAMESIZES Name VIDIOC ENUM FRAMESIZES Enumerate frame sizes Synopsis int ioctl int fd int request struct v412 frmsizeenum xargp Arguments fd File descriptor returned by open request VIDIOC ENUM FRAMESIZES argp Pointer to a struct v412 frmsizeenum that contains an index and pixel format and receives a frame width and height Description Experimental This is an experimental interface and may change in the future This ioctl allows applications to enumerate all frame sizes 1 e width and height in pixels that the device supports for the given pixel format The supported pixel formats can be obtained by using the VIDIOC_ENUM_FMT function The return value and the content of the v412 rmsizeenum type field depend on the type of frame sizes the device supports Here are the semantics of the function for the different cases Discrete The function returns success if the given index value zero b
28. amp cropcap 0 sizeof cropcap cropcap type V4L2 BUF TYPE VIDEO CAPTURE if 1 ioctl fd VIDIOC CROPCAP amp cropcap perror VIDIOC CROPCAP exit EXIT_FAILURE memset amp crop 0 sizeof crop crop type V4L2_BUF_TYPE_VIDEO_CAPTURE crop c cropcap defrect Em Ignore if cropping is not supported EINVAL x if 1 ioctl fd VIDIOC S CROP amp crop amp amp errno EINVAL perror VIDIOC S CROP exit EXIT FAILURE Example 1 11 Simple downscaling A video capture device is assumed struct v412 cropcap cropcap struct v412 format format reset cropping parameters Scale down to 1 4 size of full picture memset amp format 0 sizeof format defaults format type V4L2 BUF TYPE VIDEO CAPTURE EM format fmt pix width cropcap defrect width gt gt 1 format fmt pix height cropcap defrect height gt gt 1 format fmt pix pixelformat VA4L2 PIX FMT YUYV if 1 ioctl fd VIDIOC S FMT amp format perror VIDIOC S FORMAT exit EXIT_FAILURE We could check the actual image size now the actual scaling factor or if the driver can scale at all 25 Chapter 1 Common API Elements Example 1 12 Selecting an output area struct v412 cropcap cropcap struct v412 crop crop memset amp cropcap 0 sizeof cropcap cropcap ty
29. define V4L2 JPEG MARKER DHT 1 3 define V4L2 JPEG MARKER DQT 1 lt lt 4 define V4L2_JPEG_MARKER_DRI 1 lt lt 5 define V4L2 JPEG MARKER COM 1 lt lt 6 define V4L2 JPEG MARKER APP 1 lt lt 7 MEMORY MAPPING x struct v412 requestbuffers HH c 2032 enum v412 buf type enum v412 memory u32 struct v412 buffer count type memory reserved 2 F u32 index enum v412 buf type type 32 bytesused u32 flags enum v412 field field struct timeval timestamp struct v412 timecode timecode u32 sequence memory location x enum v412 memory memory union u32 offset unsigned long userptr m u32 length u32 input u32 reserved Flags for flags field 233 Appendix A Video For Linux Two Header File define V4L2 BUF FLAG MAPPED 0x0001 Buffer is mapped flag define V4L2 BUF FLAG QUEUED 0x0002 x Buffer is queued for processing x define V4L2 BUF FLAG DONE 0x0004 x Buffer is ready define V4AL2 BUF FLAG KEYFRAME 0x0008 Image is a keyframe I frame x define V4L2 BUF FLAG PFRAME 0x0010 Image is a P frame define V4L2 BUF FLAG BFRAME 0x0020 Image is a B frame define V4L2 BUF FLAG TIMECODE 0x0100 x timecode field is valid define V4L2 BUF FLAG INPUT 0x0200 input field is valid x OVERLAY PREVIEW x struct v412_framebuffe
30. else errno exit VIDIOC QUERYCAP if cap capabilities amp V4L2 CAP VIDEO CAPTURE fprintf stderr s is no video capture device n dev name exit EXIT FAILURE switch io case IO METHOD READ if cap capabilities amp V4L2 CAP READWRITE fprintf stderr s does not support read i o n dev name exit EXIT FAILURE break case IO METHOD MMAP case IO METHOD USERPTR if cap capabilities amp V4L2 CAP STREAMING fprintf stderr s does not support streaming i o n dev name exit EXIT FAILURE break Select video input video standard and tune here CLEAR cropcap cropcap type VA4L2 BUF TYPE VIDEO CAPTURE if 0 xioctl fd VIDIOC CROPCAP amp cropcap crop type V4L2 BUF TYPE VIDEO CAPTURE crop c cropcap defrect reset to default if 1 xioctl fd VIDIOC_S_CROP amp crop switch errno case EINVAL Cropping not supported break default Errors ignored break else 259 Appendix B Video Capture Example Errors ignored CLEAR fmt fmt type VA4L2 BUF TYPE VIDEO CAPTURE fmt fmt pix width 640 fmt fmt pix height 480 fmt fmt pix pixelformat V4L2 PIX FMT YUYV fmt fmt pix field V4L2 FIELD INTERLACED if 1 xi
31. ioctl fd VIDIOC ENUMINPUT amp input perror VIDIOC ENUM INPUT exit EXIT FAILURE T Chapter 1 Common API Elements printf Current input s supports Mn input name memset amp standard 0 sizeof standargad standard index 0 while 0 ioctl fd VIDIOC ENUMSTD amp standard if standard id amp input std printf Ss n standard name standard indext EINVAL indicates the end of the enumeration which cannot be empty unless this device falls under the USB exception x if errno EINVAL standard index 0 perror VIDIOC_ENUMSTD exit EXIT_FAILURE Example 1 7 Selecting a new video standard struct v412 input input v412_std_id std_id memset amp input 0 sizeof input if 1 ioctl fd VIDIOC_G_INPUT amp input index perror VIDIOC G INPUT exit EXIT FAILURE if 1 ioctl fd VIDIOC ENUMINPUT amp input perror VIDIOC ENUM INPUT exit EXIT FAILURE T if 0 input std amp V4L2_STD_PAL_BG fprintf stderr Oops B G PAL is not supported n exit EXIT_FAILURE Note this is also supposed to work when only B or G PAL is supported x std id VA4L2 STD PAL BG if 1 ioctl fd VIDIOC S STD amp std id perror VIDIOC S STD exit EXIT FAILURE Chapter 1 Common API Elements 1 8 User Controls D
32. 23 Y 33 Croi Cru Cri Cri Q aO OO 42 Mu uuo VAL2 PIX FMT UYVY UYVY Name V4L2 PIX FMT UYVY Variation of VAL2 PIX FMT YUYV With different order of samples in memory Description In this format each four bytes is two pixels Each four bytes is two Y s a Cb and a Cr Each Y goes to one of the pixels and the Cb and Cr belong to both pixels As you can see the Cr and Cb components have half the horizontal resolution of the Y component Example 2 1 vaAL2 PIX FMT UYVY 4 x 4 pixel image Byte Order Each cell is one byte start 4 0 Cboo Y oo Croo Y oi Cbo Y o Croi Y o start 4 8 Cbio Y 10 Crio Yu Cbi Yr Cri Yu start 4 16 Cboo Y o Cr2o Yn Cboi Y Cra Y start 4 24 Cb30 Y 30 Cr3o Yar Cbs31 Y Crs1 Ys Color Sample Location Ww N Cc KKK KO CY e 0 KKK KR KKK KN OnE Ase KK KK 43 V4L2 PIX FMT Y41P Y41P Name VAL2 PIX FMT Y41P Format with horizontal chroma resolution also known as YUV 4 1 1 Description In this format each 12 bytes is eight pixels In the twelve bytes are two CbCr pairs and eight Y s The first CbCr pair goes with the first four Y s and the second CbCr pair goes with the other four Y s The Cb and Cr components have one fourth the horizontal resolution of the Y component Do not confuse this format with vVaL2 PIX FMT YUV411P Y41P is derived from YUV 4 1 1 packed while YUV411P stands for YUV 4 1 1 planar Example 2 1 va 2 PIX FMT Y41P
33. 24 Croo Croi start 26 Crio Cru start 28 Cr20 Cra start 30 Cr30 Cr3i Color Sample Location W N e O KKK KO OO KKK KKK KN Q0o00n0n 47 Mu uuo VAL2 PIX FMT YUV411P 411P Name VAL2 PIX FMT YUVA411P Format with 4 horizontal chroma resolution also known as YUV 4 1 1 Planar layout as opposed to VAL2 PIX FMT Y41P Description This format is not commonly used This is a planar format similar to the 4 2 2 planar format except with half as many chroma The three components are separated into three sub images or planes The Y plane is first The Y plane has one byte per pixel The Cb plane immediately follows the Y plane in memory The Cb plane is 1 4 the width of the Y plane and of the image Each Cb belongs to 4 pixels all on the same row For example Cb belongs to Y Yor Yo and Y Following the Cb plane is the Cr plane just like the Cb plane If the Y plane has pad bytes after each row then the Cr and Cb planes have 4 as many pad bytes after their rows In other words four C x rows including padding is exactly as long as one Y row including padding Example 2 1 VAL2 PIX FMT YUV411P 4 x 4 pixel image Byte Order Each cell is one byte start 0 Y oo Y a Y o Y os start 4 Y 10 Yu Y a Y is start 8 Y 20 Y n Y n Y a start 12 Y 30 Y a Y a Y ss start 4 16 Cboo start 17 Cbio start 4 18 Cboo start 4 19 Cb30 start 20 Croo start 21 Crio start 22 Cr2
34. 243 define define define define define define define define define define define v4 v4 v4 v4 v4 v4 v4 v4 v4 v4 v4 T L2 CI L2 CL D_FOCUS_RELATIV UNING struct v412_tuner HH u32 u8 enum v412 tuner type u32 u32 u32 232 5032 2 992 S92 u32 struct v412 modulator D_FOCUS_AUTO 50 32 u8 u32 u32 u32 u32 u32 Flags for the capability define V4L2 TUNER CAP LOW define V4L2 TUNER CAP NORM define V4L2 TUNER CAP STEREO define V4L2 TUNER CAP LANG2 define V4L2 TUNER CAP SAP define V4L2 TUNER CAP LANG Flags for the rxsubchans define V4L2 TUNER SUB MONO define V4L2 TUNER SUB STEREO define V4L2 TUNER SUB LANG2 define V4L2 TUNER SUB SAP 2 CID EXPOSURE ABSOLUTE 2 CID EXPOSURE AUTO PRIORITY L2 CID PAN RELATIVE L2 CID TILT RELATIVE L2 CID PAN RESE L2 CID TILT RESE L2 CID PAN ABSOLUTE L2 CID TILT ABSOLUTE L2 CID FOCUS ABSOLUTI index name 32 type Appendix A Video For Linux Two Header File capability rangelow rangehigh rxsubchans audmode signal afc reserved 4 index name 32 capability rangelow rangehigh txsubchans reserved
35. An ioctl request has encoded in it whether the argument is an input output or read write parameter and the size of the argument argp in bytes Macros and defines specifying VAL2 ioctl requests are located in the videodev h header file Applications should use their own copy not include the version in the kernel sources on the system they compile on All V4L2 ioctl requests their respective function and parameters are specified in Reference I Function Reference Return Value On success the ioct1 function returns 0 and does not reset the errno variable On failure 1 is returned when the ioctl takes an output or read write parameter it remains unmodified and the errno Variable is set appropriately See below for possible error codes Generic errors like EBADF or EFAULT are not listed in the sections discussing individual ioctl requests Note ioctls may return undefined error codes Since errors may have side effects such as a driver reset applications should abort on unexpected errors 90 V4L2 ioctl EBADF dis not a valid open file descriptor EBUSY The property cannot be changed right now Typically this error code is returned when I O is in progress or the driver supports multiple opens and another process locked the property EFAULT argp references an inaccessible memory area ENOTTY fd is not associated with a character special device EINVAL The request or the data pointed to by argp is not valid This is
36. EINVAL The buffer t ype is not supported or the index is out of bounds 173 ioctl VIDIOC QUERYCAP Name VIDIOC_QUERYCAP Query device capabilities Synopsis int ioctl int fd int request struct v412 capability xargp Arguments fd File descriptor returned by open request VIDIOC QUERYCAP argp Description All V4L2 devices support the VIDIOC_QUERYCAP ioctl It is used to identify kernel devices compatible with this specification and to obtain information about driver and hardware capabilities The ioctl takes a pointer to a struct v412 capability which is filled by the driver When the driver is not compatible with this specification the ioctl returns an EINVAL error code Table 1 struct v412 capability u8 driver 16 Name of the driver a unique NUL terminated ASCII string For example bttv Driver specific applications can use this information to verify the driver identity It is also useful to work around known bugs or to identify drivers in error reports The driver version is stored in the version field Storing strings in fixed sized arrays is bad practice but unavoidable here Drivers and applications should take precautions to never read or write beyond the end of the array and to make sure the strings are properly NUL terminated 174 ioctl VIDIOC QUERYCAP u8 card 32 Name of the device a NUL terminated ASCII string For example Yoyodyne TV FM One driver may support
37. LOG STATUS 4e eiecit pietre pr pn re 168 ioctl VIDIOC OVEBRLEAY titer ten e ter RERO ni tesa Reiner 169 ioctl VIDIOC_QBUF VIDIOC DQBUPF essere enne nennen nennen nennen 170 ioctl VIDIOE QUERY BUE eaea ierit tete PRU Eaa E EAEE EEEE 172 ioctl VIDIOC QUERYCGCALD nee irre rnt re Uere eror pepepievnatelevder dees 174 ioctl VIDIOC QUERYCTRL VIDIOC_QUERYMENU eere 177 ioctl VIDIOC QUERY STD iret rte reete RR eee et Ee RR ERREUR ER RR R REA eI 182 ioctl VIDIOC REOBULPS tee erii fret tee e E e i ae ie rs 184 ioctl VIDIOC STREAMON VIDIOC STREAMOPFF ccccccccsssccessecesseeeesseeeesnseecnseeeees 186 A ANAuIntiubm cc 188 VAEZ mM NMap eet eect ae RI e ere ea eee 190 VAEZ Open C 191 vi VAE2 poll nup ESO ERU e BE I EE 193 VALE2 tead 4 isset te spe t te ees pet te een 195 VALE2 select uice evene cimus i ee 197 NAE2 Wote 1 ero ettet ettet tete ce eet inediti t berto te etes tte treu 199 5 V4L2 Driver Programming e eeeee eese eese eese e esta eta sta setae ta etas eo setas ease etse tn etas en seas etas eoe spesa 201 jnOrn 202 6 1 Differences between V4L and V4AL2 sse nennen nenne enne 202 6 1 1 Opening and Closing Devices eseseeeeeeeeeneeeeeeenee eene 202 6 1 2 Querying Capabilities ee cenis ee eee gen iue 202 6 1 3 Video
38. On error 1 is returned and the errno variable is set appropriately Possible error codes are EACCES The caller has no permission to access the device EBUSY The driver does not support multiple opens and the device is already in use 191 V4L2 open ENXIO No device corresponding to this device special file exists ENOMEM Not enough kernel memory was available to complete the request EMFILE The process already has the maximum number of files open ENFILE The limit on the total number of files open on the system has been reached 192 V4L2 poll Name v412 poll Wait for some event on a file descriptor Synopsis finclude lt sys poll h gt int poll struct pollfd xufds unsigned int nfds int timeout Description With the po11 function applications can suspend execution until the driver has captured data or is ready to accept data for output When streaming I O has been negotiated this function waits until a buffer has been filled or displayed and can be dequeued with the VIDIOC_DQBUF ioctl When buffers are already in the outgoing queue of the driver the function returns immediately On success poll returns the number of file descriptors that have been selected that is file descriptors for which the revents field of the respective pollfd structure is non zero Capture devices set the POLLIN and POLLRDNORM flags in the revents field output devices the POLLOUT and POLLWRNORM flags Wh
39. The Video4Linux Book 2000 About VAL driver programming This book is part of the Linux kernel DocBook documentation for example at http kernelnewbies org documents SGML sources are included in the kernel sources 271
40. The data format is similar to uncompressed video images a number of lines times a number of samples per line we call this a VBI image Conventionally V4L2 VBI devices are accessed through character device special files named dev vbi and dev vbi0 to dev vbi31 with major number 81 and minor numbers 224 to 255 dev vbi is typically a symbolic link to the preferred VBI device This convention applies to both input and output devices To address the problems of finding related video and VBI devices VBI capturing and output is also available as device function under dev video To capture or output raw VBI data with these devices applications must call the VIDIOC_S_FMT ioctl Accessed as dev vbi raw VBI capturing or output is the default device function 4 7 1 Querying Capabilities Devices supporting the raw VBI capturing or output API set the vV4AL2 CAP VBI CAPTURE or VAL2 CAP VBI OUTPUT flags respectively in the capabilities field of struct v412 capability returned by the VIDIOC_QUERYCAP ioctl At least one of the read write streaming or asynchronous I O methods must be supported VBI devices may or may not have a tuner or modulator 4 7 2 Supplemental Functions VBI devices shall support video input or output tuner or modulator and controls ioctls as needed The video standard ioctls provide information vital to program a VBI device therefore must be supported 4 7 3 Raw VBI Format Negotiation Raw VBI sampling ab
41. The window can extend the frame buffer width and height the x and y coordinates can be negative and it can lie completely outside the frame buffer The driver clips the window accordingly or if that is not possible modifies its size and or position Applications set this field to determine which video field shall be overlaid typically one of V4L2 FIELD ANY 0 VAL2 FIELD TOP V4L2 FIELD BOTTOM or V4L2 FIELD INTERLACED Drivers may have to choose a different field order and return the actual setting here When chroma keying has been negotiated with VIDIOC S FBUF applications set this field to the desired pixel value for the chroma key The format is the same as the pixel format of the framebuffer struct v412 framebuffer fmt pixelformat field with bytes in host order E g for VA4L2 PIX FMT BGR24 the value should be OxRRGGBB on a little endian OXBBGGRR on a big endian host When chroma keying has not been negotiated and VIDIOC G FBUF indicated this capability applications can set this field to point to an array of clipping rectangles Like the window coordinates w clipping rectangles are defined relative to the top left corner of the frame buffer Howe u32 clipcount void bitmap When the application set the clips field this field must contain the number of clipping rectangles in the list When clip lists are not supported the driver ignores this field its contents af
42. V4L2 PEG_AUDIO_L2_BITRATE_160K 8 V4L2 MPEG AUDIO L2 BITRATE 192K 9 V4L2 MPEG AUDIO L2 BITRATE 224K 10 V4L2 MPEG AUDIO L2 BITRATE 256K 11 V4L2 MPEG AUDIO L2 BITRATE 320K 12 V4L2 PEG AUDIO L2 BITRATE 384K 13 i define V4L2 CID MPEG AUDIO L3 BITRATE VAL2 CID MPEG BASE 104 enum v412 mpeg audio 13 bitrate V4L2 MPEG AUDIO L3 BITRATE 32K 0 V4L2 MPEG AUDIO L3 BITRATE 40K 1 V4L2 MPEG AUDIO L3 BITRATE 48K 2 V4L2 MPEG AUDIO L3 BITRATE 56K 3 V4L2 MPEG AUDIO L3 BITRATE 64K 4 V4L2 MPEG AUDIO L3 BITRATE 80K 5 V4L2 MPEG AUDIO L3 BITRATE 96K 6 V4L2 PEG AUDIO L3 BITRATE 112K 7 241 Appendix A Video For Linux Two Header File V4L2 MPEG AUDIO L3 BITRATE 128K 8 V4L2 MPEG AUDIO L3 BITRATE 160K 9 V4L2 MPEG AUDIO L3 BITRATE 192K 10 V4L2 MPEG AUDIO L3 BITRATE 224K 11 V4L2 MPEG AUDIO L3 BITRATE 256K 12 V4L2 MPEG AUDIO L3 BITRATE 320K 13 define V4L2 CID MPEG AUDIO MODE VAL2 CID MPEG BASE 105 enum v412 mpeg audio mode V4L2 MPEG AUDIO MODE STEREO 0 V4L2_MPEG_AUDIO_MODE_JOINT_STEREO 1 V4L2_MPEG_AUDIO_MODE_DUAL 2 V4L2_MPEG_AUDIO_MODE_MONO 3 define V4L2 CID MPEG AUDIO MODE EXTENSION
43. VIDIOC S EXT CTRLS VIDIOC TRY EXT CTRLS EINVAL The struct v412 ext control id is invalid or the struct v412 ext controls ctr1 classis invalid This error code is also returned by the vibroC S EXT CTRLS and VIDIOC TRY EXT CTRLS 1octls if two or more control values are in conflict ERANGE The struct v412 ext control value is out of bounds EBUSY The control is temporarily not changeable possibly because another applications took over control of the device function this control belongs to 134 ioctl VIDIOC G FBUF VIDIOC S FBUF Name VIDIOC G FBUF VIDIOC S FBUF Get or set frame buffer overlay parameters Synopsis int ioctl int fd int request struct v412 framebuffer xargp int ioctl int fd int request const struct v412 framebuffer xargp Arguments fd File descriptor returned by open request VIDIOC_G_FBUF VIDIOC S FBUF argp Description Applications can use the VIDIOC G FBUF and VIDIOC S FBUF ioctl to get and set the framebuffer parameters for a Video Overlay or Video Output Overlay OSD The type of overlay is implied by the device type capture or output device and can be determined with the VIDIOC_QUERYCAP ioctl One dev videoN device must not support both kinds of overlay The V4L2 API distinguishes destructive and non destructive overlays A destructive overlay copies captured video images into the video memory of a graphics card A non destructive overlay blends video ima
44. VIDIOC S FREQ VIDIOC S INPUT VIDIOC S OUTPUT VIDIOC S EFFECT For example err ioctl fd VIDIOC XXX VA4L2 XXX becomes int a VA4L2 XXX err ioctl fd VIDIOC XXX amp a All the different get and set format commands were swept into one VIDIOC G FMT and VIDIOC S FMT ioctl taking a union and a type field selecting the union member as parameter Purpose is to simplify the API by eliminating several ioctls and to allow new and driver private data streams without adding new ioctls This change obsoletes the following ioctls vVIDIOC S INFMT VIDIOC_G_INFMT VIDIOC S OUTFMT VIDIOC_G_OUTFMT VIDIOC S VBIFMT and VIDIOC_G_VBIFMT The image format structure v412 format was renamed to struct v412 pix format while struct v412 format is now the envelopping structure for all format negotiations Similar to the changes above the VIDIOC G PARM and VIDIOC_S_PARM ioctls were merged with VIDIOC G OUTPARM and VIDIOC S OUTPARM A type field in the new struct v412 streamparm selects the respective union member This change obsoletes the VIDIOC_G_OUTPARM and VIDIOC S OUTPARM ioctls Control enumeration was simplified and two new control flags were introduced and one dropped The catname field was replaced by a group field Drivers can now flag unsupported and temporarily unavailable controls with V4AL2 CTRL FLAG DISABLED and V4L2 CTRL FLAG GRABBED respectively The group name indicates a possibly narrower classification
45. flag when the VIDIOC_QUERYBUF VIDIOC_QBUF or VIDIOC_DQBUF ioctl is called Set by the driver 58 VA4L2 BUF FLAG QUEUED 0x0002 VAL2 BUF FLAG DONE 0x0004 VA4L2 BUF FLAG KEYFRAME 0x0008 V4L2_BUF_FLAG_PFRAME 0x0010 V4L2_BUF_FLAG_BFRAME 0x0020 V4L2_BUF_FLAG_TIMECODE 0x0100 V4L2_BUF_FLAG_INPUT 0x0200 Table 3 4 enum v4l2 memory VAL2 MI VAL2 MI VAL2 MI EMORY USI EMORY OV EMORY MMAP ERPTR ERLAY 3 3 5 1 Timecodes Chapter 3 Input Output Internally drivers maintain two buffer queues an incoming and outgoing queue When this flag is set the buffer is currently on the incoming queue It automatically moves to the outgoing queue after the buffer has been filled capture devices or displayed output devices Drivers set or clear this flag when the VIDIOC_QUERYBUF ioctl is called After successful calling the VIDIOC_QBUF ioctl it is always set and after VIDIOC DOBUF always cleared When this flag is set the buffer is currently on the outgoing queue ready to be dequeued from the driver Drivers set or clear this flag when the VIDIOC_QUERYBUF ioctl is called After calling the VIDIOC OBUF or VIDIOC_DQBUF it is always cleared Of course a buffer cannot be on both queues at the same time the V4L2_BUF_FLAG_QUEUED and V4L2_BUF_FLAG_DONE flag are mutually exclusive They can be both cleared however then the buffer is in dequeued state in the
46. help Print this message n m mmap Use memory mapped buffers Vn ES read Use read calls n s userp Use application allocated buffers Mn un argv 01 static const char short options d hmru static const struct option LI long options device required argument NULL Cute ca help no argument NULL SC Ey mmap no argument NULL rme pg read no argument NULL mpl gy userp no argument NULL rut O07 Qui iF int main int argc char xx argv dev_name dev video for 77 int index int c c getopt_long argc argv 261 Appendix B Video Capture Example short options long options amp index if 1 c break switch c case 0 getopt long flag break case d dev name optarg break case h usage stdout argc argv exit EXIT SUCCESS case m io IO METHOD MMAP break case r io IO METHOD READ break case u io IO METHOD USERPTR break default usage stderr argc argv exit EXIT FAILURE 0 open device init device start capturing mainloop stop capturing 0 uninit device close device exit EXIT SUCCESS return 0 262 Appendix C GNU Free Documentation License C 1 0 PREAMBLE The purpose of this License is to make a manual textbook or other written document free i
47. 2 Image Format Enumeration esses eene enne enne nnntn nennen 22 1 11 Image Cropping Insertion and Scaling esee enne 23 1 TT T Croppitig Structure sia con reete HERB a e rt s 23 1 1 2 Scaling Adjustments tere et eerte ertet ro uere gerente 24 T TT 3 Exaimples ei ee e ERE NEU T CREER REED 24 1 12 Streaming Parameters coa icon tance irte iors terete Eee E E EU ete aie 27 2 TMA GE FOPMALS d 29 2 1 Standard Image Formats eene it eee te eerte e a e e eee don 29 2 2 COOLS Paces eei pd pute dt POBRE kee tee 30 2 3 Indexed Pormiat cci ee eei ee bee Ned ee eet e dieto eee 33 244 RGB Form ts 55 enn nn RHEIN ERR ER E OE 34 Packed RGB tfornmiats uere et aere eee ee ee ere REC epe oe 34 VAL2 PIX FMT SBGGRS BABI Jonnen EE ne ee nrs ESE ioy 37 VAL2 PIX FMT SBGGRI6 BA82 eepe ee E Ee Ee EENES 38 2 5 YUV Formats eaan a Sa sve a a a endi EH WEE RR s 39 Packed YUV formats eS Et te est eec e e S 39 VAL2 PIX FMT GREY GREY ccssssccscesssnccsosescetcescessenccescenseseeseesseessescenseaseess 40 NVAE2 PIX CRM TY T6 Y 16 7 use eee ete etie 41 VAL2 PIX FMT YUYV CYUXMWM 3 us eee ip ened tree seeded sesso tebe spel eet inet 42 VAE2 PIX EMT UYVY UYVY aesti eO RUE REI 43 V42 PIX EMT YAIR C Y P neptis 44 VAL2 PIX FMT YVUA420 YV12 VAL2 PIX FMT YUVA420 CYUI 45 VAL2 PIX FMT YVUA 410 YVU95 VAL
48. 4 field field 0x0001 0x0002 0x0010 0x0020 0x0020 0x0040 0x0001 0x0002 0x0004 0x0004 L2 L2 L2 L2 L2 L2 L2 L2 BASE BASE BAS BAS BAS DU USC DO BAS BAS Ei ea BAS BAS BAS CID CAMERA CLASS CID CAMERA CLASS CID CAMERA CLASS CID CAMERA CLASS CID CAMERA CLASS CID CAMERA CLASS CID CAMERA CLASS CID CAMERA CLASS CID CAMERA CLASS CID CAMERA CLASS CID CAMERA CLASS E p BH BAS 244 2 3 4 5 6 7 8 Appendix A Video For Linux Two Header File define V4L2 TUNER SUB LANG1 0x0008 Values for the audmode field define V4L2 TUNER MODE MONO 0x0000 define V4L2 TUNER MODE STEREO 0x0001 define V4L2 TUNER MODE LANG2 0x0002 define V4L2 TUNER MODE SAP 0x0002 define V4L2 TUNER MODE LANG 0x0003 define V4L2 UNER MODE LANG1 LANG2 0x0004 struct v412 frequency 32 tuner enum v412 tuner type type Bx frequency u32 reserved 8 AUDIO x struct v412 audio u32 u8 u32 zau z 3032 index name 32 capability mode reserved 2 Flags for the capability define V4L2 AUDCAP STEREO define V4L2 AUDCAP AVL Flags for the mode define V4L2 AUDMODE AVL struct v412 audioout u32 u8 u32 032
49. 6 Compressed Formats Table 2 7 Compressed Image Formats Chapter 2 Image Formats Identifier Code Details V4L2 PIX FMT JPEG JPEG TBD See also VIDIOC_G_JPEGCOMP VIDIOC S JPEGCOMP V4L2 PIX FMT MPEG MPEG MPEG stream The actual format is determined by extended control V4L2 CID MPEG STREAM TYPE see Table 1 2 2 7 Reserved Format Identifiers These formats are not defined by this specification they are just listed for reference and to avoid naming conflicts If you want to register your own format send an e mail to the VAL mailing list https listman redhat com mailman listinfo video4linux list for inclusion in the videodev h file If you want to share your format with other developers add a link to your documentation and send a copy to the maintainer of this document Michael Schimek lt mschimek gmx at gt for inclusion in this section If you think your format should be listed in a standard format section please make a proposal on the V4L mailing list Table 2 8 Reserved Image Formats Identifier Code Details VA4L2 PIX FMT DV dvsd unknown V4L2 PIX FMT ET61X251 E625 Compressed format of the ET61X251 driver V4L2 PIX FMT HI240 gt HI24 8 bit RGB format used by the BTTV driver http bytesex org bttv V4L2_PIX_FMT_HM12 HMI2 YUV 4 2 0 format used by the IVTV driver http www ivtvdriver org The for mat is documented in the kernel sources in the
50. Audio flags indi The lowest tunable frequency in units of 62 5 kHz The highest tunable frequency in units of 62 5 kHz Some tuners or audio decoders can determine the re V4L2_TUNER_SUB_MONO receiving mono at STEREO SAP receiving stereo al MONO STEREO receiving mono ot LANG1 LANG2 receiving bilingua MONO STEREO LANG1 receiving mono S LANG2 When the V4L2 TUNER CAP STEREO _LANG1 I The selected audio mode see Table 5 for valid valu The signal strength if known ranging from 0 to 655 Automatic frequency control When the afc value i Reserved for future extensions Drivers and applicat When set tuning frequencies are expressed in units of 62 5 Hz otherwise in units of 62 5 kHz This is a multi standard tuner the video standard can or must be switched B G PAL tuners for example are typically not considered multi standard because the video standard is automatically determined from the frequency band The set of supported video standards is V4L2 TUNER CAP LOW 0x0001 V4L2 TUNER CAP NORM 0x0002 V4L2 TUNER CAP STEREO 0x0010 V4L2 TUNER CAP LANG1 0x0040 available from the struct v412 input pointing to this tuner see the description of ioctl VIDIOC ENUMINPUT for details Only V4L2 TUNER ANALOG TV tuners can have this capability Stereo audio reception is supported Reception of the primary language of a bilingual
51. CID MPEG BASE 100 enum v4l2 mpeg audio sampling freq V4L2 MPEG AUDIO SAMPLING FREQ 44100 O0 V4L2 MPEG AUDIO SAMPLING FREQ 48000 1 V4L2 MPEG AUDIO SAMPLING FREQ 32000 2 define V4L2 CID MPEG AUDIO ENCODING VAL2 CID MPEG BASE 101 enum v412 mpeg audio encoding V4L2 MPEG AUDIO ENCODING LAYER 1 0 V4L2 MPEG AUDIO ENCODING LAYER 2 1 V4L2 MPEG AUDIO ENCODING LAYER 3 2 define V4L2 CID MPEG AUDIO L1 BITRATE VAL2 CID MPEG BASE 102 enum v4l12 mpeg audio 11 bitrate V4L2 MPEG AUDIO L1 BITRATE 32K 0 V4L2 MPEG AUDIO L1 BITRATE 64K 1 V4L2 MPEG AUDIO L1 BITRATE 96K 2 V4L2 MPEG AUDIO L1 BITRATE 128K 3 V4L2 PEG AUDIO L1 BITRATE 160K 4 V4L2 MPEG AUDIO L1 BITRATE 192K 5 V4L2 MPEG AUDIO L1 BITRATE 224K 6 V4L2 PEG AUDIO L1 BITRATE 256K 7 V4L2 PEG_AUDIO_L1_BITRATE_288K 8 V4L2 PEG AUDIO L1 BITRATE 320K 9 V4L2 MPEG AUDIO L1 BITRATE 352K 10 V4L2 MPEG AUDIO L1 BITRATE 384K 11 V4L2 MPEG AUDIO L1 BITRATE 416K 12 V4L2 PEG_AUDIO_L1_BITRATE_448K 13 define V4L2 CID MPEG AUDIO L2 BITRATE VAL2 CID MPEG BASE 103 enum v412 mpeg audio 12 bitrate V4L2 MPEG AUDIO L2 BITRATE 32K 0 V4L2 MPEG AUDIO L2 BITRATE 48K 1 V4L2 MPEG AUDIO L2 BITRATE 56K 2 V4L2 MPEG AUDIO L2 BITRATE 64K 3 V4L2 MPEG AUDIO L2 BITRATE 80K 4 V4L2 MPEG AUDIO L2 BITRATE 96K 5 V4L2 MPEG AUDIO L2 BITRATE 112K 6 V4L2 MPEG AUDIO L2 BITRATE 128K 7
52. Chapter 3 for details In struct v412 buffer the type field was properly defined as enum v412_buf_type Buffer types changed as mentioned above A field field of type enum v412 field was added to indicate if a buffer contains a top or bottom field The old field flags were removed Since no unadjusted system time clock was added to the kernel as planned the timestamp field changed back from type stamp t an unsigned 64 bit integer expressing the sample time in nanoseconds to struct timeval With the addition of a second memory mapping method the o set field moved into union m and a new memory field of type enum v412 memory was added to distinguish between I O methods See Chapter 3 for details The v4L2 BUF REO CONTIG flag was used by the VAL compatibility layer after changes to this code it was no longer needed The v4 2 BUF ATTR DEVICEMEM flag would indicate if the buffer was indeed allocated in device memory rather than DMA able system memory It was barely useful and so was removed In struct v412 framebuffer the base 3 array anticipating double and triple buffering in off screen video memory however without defining a synchronization mechanism was replaced by a single pointer The V4L2_FBUF_CAP_SCALEUP and V4L2 FBUF CAP SCALEDOWN flags were removed Applications can determine this capability more accurately using the new cropping and scaling interface The v4L2 FBUF CAP CLIPPING flag was replaced by VAL2 F
53. NTSC 443 VAL2 STD PAL N V4L2 STD PAL N N VA4L2 STD PAL Nc N VAL2 STD SECAM VAL2 STD ATSC 8 VSB N VA4L2 STD ATSC 16 VSB VAL2 STD 525 60 IN VA4L2 STD 625 50 u32 index v412 std id id ug name 24 struct v412 fract frameperiod u32 framelines ENS reserved 4 di AOI GE EGO lI NP UIS x struct v412 input u32 index us name 32 u32 type 23 2 audioset 032 tuner X412 std id std u32 status u32 reserved 4 Values for the type field x define V4L2_INPUT_TYPE_TUNER 1 define V4L2_INPUT_TYPE_CAMERA 2 field status general define VA4L2 IN ST NO POWER 0x00000001 define VA4L2 IN ST NO SIGNAL 0x00000002 define V4L2 IN ST NO COLOR 0x00000004 field status analog define VA4L2 IN ST NO H LOCK 0x00000100 define VA4L2 IN ST COLOR KILL 0x00000200 field status digital x Frames not fields Which input x Label x Type of input Associated audios bitfield Associated tuner x Attached device is off No horizontal sync lock Color killer is active 237 define VA4L2 I define VA4L2 I field stat define VA4L2 I define VA4L2 I define V4L2 I VI x struct v412 ou D 32 u8 u32 u32 I 232 v412 s u32 E Values for define V4L2_0 define V4L2_0 define V4L2_0 CON x struct v412 co 32 332 struct
54. PIX FMT YUYV and VAL2 PIX FMT UYVY and the VA4L2 PIX FMT PALS format are also permitted The behavior of the driver when an application requests a compressed format is undefined See Chapter 2 for information on pixel formats Drivers and applications shall ignore this field If applicable the field order is selected with the VIDIOC S FMT ioctl using the ield field of struct v412_ window Distance in bytes between the leftmost pixels in two adjacent lines This field is irrelevant to non destructive Video Overlays For destructive Video Overlays both applications and drivers u32 sizeimage enum v4l2 colorspaeelorspace u32 priv Notes This field is irrelevant to non destructive Video Overlays For destructive Video Overlays applications must initialize this field For Video Output Overlays the driver must return a valid format Together with base it defines the framebuffer memory accessible by the driver This information supplements the pixelformat and must be set by the driver see Section 2 2 Reserved for additional information about custom driver defined formats When not used drivers and applications must set this field to zero 137 Table 2 Frame Buffer Capability Flags VAL2 FBUF CAP EF XTERNOVERLAY 0x0001 VAL2 FBUF CAP CHROMAKEY 0x0002 V4L2 V4L2 V4L2 V4L2 V4L2 FBUF CAP LIST_CLIPPING 0x0004 FBUF CAP BITMAP_CLIPPIN x0008 FBUF C
55. Reference Lines usually This array is reserved for future extensions Applications and drivers Payload VAL2 SLICED TELETEXUx0901 Teletext System B V4L2_SLICED_VPS 0x0400 V4L2_SLICED_CAPTIONDXI H0 V4L2_SLICED_WSS_ 6230x4000 V4L2_SLICED_VBI_5230x1000 V4L2_SLICED_VBI_ 6200x4401 Return Value ETS 300 706PAL SECAM line 7 22 ITU BT 653 320 335 second field 7 22 ETS 300 23 IPAL line 16 EIA 608 B NTSC line 21 284 second field 21 EN 300 294 PAL SECAM line 23 ITU BT 1119 Set of services applicable to 525 line Set of services applicable to 625 line Last 42 of the 45 byte Teletext packet that is without clock run in and framing code lsb first transmitted Byte number 3 to 15 according to Figure 9 of ETS 300 231 Isb first transmitted Two bytes in transmission order including parity bit lsb first transmitted Byte 0 t msb lsb 76543210 msb Bit x x 13 12 systems systems On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The device does not support sliced VBI capturing or output or the value in the type field is wrong 161 ioctl VIDIOC G STD VIDIOC S STD Name VIDIOC G STD VIDIOC S STD Query or select the video standard of the current input Synopsis int ioctl int fd int request v412 std id xargp int ioctl int fd int request const v412 std id argp Arguments fd Fi
56. STD SECAM G define V4L2 STD SECAM H define V4L2 STD SECAM K define V4L2 STD SECAM K1 define V4L2 STD SECAM define V4L2 STD SECA C ATSC HDTV x define V4L2 STD ATSC 8 VSB define V4L2 STD ATSC 16 VSB 12 s 12 s 12 56 T2 W2 6 12 s 12 s 12 s 12 s 12 s td id 0x0001 td id 0x0002 td id 0x0004 0x0008 td id 0x0010 td id 0x0020 td id 0x0040 td id 0x0080 td id td id 0x0100 td id 0x0200 Oo G ioctl VIDIOC ENUMSTD std id 0x00008000 V4L2 STD ATSC 8 VSB and V4L2 STD ATSC 16 VSB are U S terrestrial digital TV standards Presently the V4L2 API does not support digital TV See also the Linux DVB API at http linuxtv org define V4L2 STD PAL BG define VA4L2 STD B define V4L2 STD GH define V4L2 STD PAL DK define V4L2 STD PAL define V4L2 STD NTSC define V4L2 STD MN define V4L2 STD SECAM DK define V4L2 STD DK define V4L2 STD SECAM VAL2 STD PAL B VA4L2 STD PAL B1 VAL2 STD PAL G VAL2 STD PAL B VA4L2 STD PAL B1 VAL2 STD SECAM B VAL2 STD PAL G VAL2 STD PAL H VAL2 STD S VAL2 STD S VAL2 STD PAL D VA4L2 STD PAL D1 VAL2 STD PAL K VAL2 STD PAL BG VAL2 STD PAL DK VAL2 STD PAL H VAL2 STD PAL I VAL2 STD NTSC M VAL2 STD NTSC M JP VAL2 STD NTSC M KR VAL2 STD PAL VAL2 STD PAL VA
57. Sources a ete e o c ee ei eL Soa ty i deis 204 6 14 T nng o a Ret POE RN gH 205 6 1 5 Image Properties 2 5 eere REED RU abe ge 205 6 1 6 Audio sere eieteibee eee erbe 206 6 1 7 Frame Buffer Overlay eet icti eti ite e sees 207 6 18 Croppin tone tO e PPP Rees 207 6 1 9 Reading Images Memory Mapping sese 208 6 1 9 1 Capturing using the read method sss 208 6 1 9 2 Capturing using memory mapping seeeeeeeeeeneeeee eee 208 6 1 10 Reading Raw VBI Data eee eee trees 209 6 1 HE Miscellaneous in mte ie E EROR EUR IER ERR 210 6 2 Changes of the VAILQ APD rra a reee arrea onarena onere ratse E a ue eno crei 210 6 2 1 Early Versions as etie t et i e E e e UD a ES 210 6 2 2 V4L2 Version 0 16 1999 01 31 seiis esre seia seeen 211 6 2 3 V4L2 Version 0 18 1999 03 16 nennen nen 211 6 2 4 VAL2 Version 0 19 1999 06 05 sette een tbc 211 6 2 5 V4L2 Version 0 20 1999 09 10 eese ene 211 6 2 6 V4L2 Version 0 20 incremental changes eee 212 6 2 7 VAL2 Version 0 20 2000 11 23 cssssssssssseseeeseeeeeeneee nennen 213 6 2 8 VAL2 Version 0 20 2002 07 25 ise eei terrass eaoat ne rieira 214 6 2 9 VAL2 in Linux 2 5 46 2002 10 nennen eren en 214 6 2 10 VAE2 2003 06 19 intente PIDE eee 217 62112 VAE2 2003 11 05 trie etre esie e REM RRE 218 6 2 12 V4L2 in Linux 2 6 6 2004 05 00 isses eene 218 6 2 13
58. Step wise defined frame interval Return Value On success 0 is returned on error 1 and the errno variable is set appropriately See the description section above for a list of return values that errno can have 108 ioctl VIDIOC ENUMINPUT Name VIDIOC ENUMINPUT Enumerate video inputs Synopsis int ioctl int fd int request struct v412 input xargp Arguments fd File descriptor returned by open request VIDIOC ENUMINPUT argp Description To query the attributes of a video input applications initialize the index field of struct v412_input and call the VIDIOC_ENUMINPUT ioctl with a pointer to this structure Drivers fill the rest of the structure or return an EINVAL error code when the index is out of bounds To enumerate all inputs applications shall begin at index zero incrementing by one until the driver returns EINVAL Table 1 struct v4l2 input u32 index Identifies the input set by the application u8 name 32 Name of the video input a NUL terminated ASCII string for example Vin Composite 2 This information is intended for the user preferably the connector label on the device itself u32 type Type of the input see Table 2 109 u32 audioset u32 tuner v412 std id std u32 status u32 reserved 4 Table 2 Input Types VA4L2 INPUT TYPE TUNER V4L2 INPUT TYPE CAMERA 2 Table 3 Input Status Flags General ioctl V
59. Telecommunication Union http www itu ch ITU R Recommendation BT 601 5 Studio Encoding Parameters of Digital Television for Standard 4 3 and Wide Screen 16 9 Aspect Ratios ITU BT 653 International Telecommunication Union http www itu ch ITU R Recommendation BT 653 3 Teletext systems ITU BT 709 International Telecommunication Union http www itu ch ITU R Recommendation BT 709 5 Parameter values for the HDTV standards for production and international programme exchange ITU BT 1119 International Telecommunication Union http www itu ch ITU R Recommendation BT 1119 625 line television Wide Screen Signalling WSS JFIF Independent JPEG Group http www ijg org JPEG File Interchange Format Version 1 02 SMPTE 12M Society of Motion Picture and Television Engineers http www smpte org SMPTE 12M 1999 Television Audio and Film Time and Control Code SMPTE 170M Society of Motion Picture and Television Engineers http www smpte org SMPTE 170M 1999 Television Composite Analog Video Signal NTSC for Studio Applications SMPTE 240M Society of Motion Picture and Television Engineers http www smpte org SMPTE 240M 1999 Television Signal Parameters 1125 Line High Definition Production VAL Alan Cox Video4Linux API Specification 270 References This file is part of the Linux kernel sources under Documentation video4linux VALPROG Alan Cox Video4Linux Programming a k a
60. The hardware may in fact not distinguish between them or do so internal and switch automatically Therefore enumerated standards also contain sets of one or more standard bits Assume a hypothetic tuner capable of demodulating B PAL G PAL and I PAL signals The first enumerated standard is a set of B and G PAL switched automatically depending on the selected radio frequency in UHF or VHF band Enumeration gives a PAL B G or PAL I choice Similar a Composite input may collapse standards enumerating PAL B G H T NTSC M and SECAM D K To query and select the standard used by the current video input or output applications call the VIDIOC G STD and VIDIOC S STD ioctl respectively The received standard can be sensed with the VIDIOC_QUERYSTD ioctl Note parameter of all these ioctls is a pointer to a v412 std id type a standard set not an index into the standard enumeration Drivers must implement all video standard ioctls when the device has one or more video inputs or outputs Special rules apply to USB cameras where the notion of video standards makes little sense More generally any capture device output devices accordingly which is incapable of capturing fields or frames at the nominal rate of the video standard or where timestamps refer to the instant the field or frame was received by the driver not the capture time or Chapter 1 Common API Elements where sequence numbers refer to the frames received by
61. The video capture interface is supported VID TYPE TUNER VA4L2 CAP TUNER The device has a tuner or modulator VID TYPE TELETEXT VA4L2 CAP VBI CAPTURE The raw VBI capture interface is supported VID TYPE OVERLAY VAL2 CAP VIDEO OVERLAY The video overlay interface is supported VID TYPE CHROMAKEY VAL2 FBUF CAP CHROMAKEY inWhether chromakey overlay is supported For more information on overlay see Section 4 2 IVID TYPE CLIPPING V4L2 FBUF CAP LIST CLIPPI and V4L2 FBUF CAP BITMAP CLIP in field capability of struct v412 framebuffer Whether clipping the overlaid image is supported see Section wb PNG VID TYPE FRAMERAM VAL2 FBUF CAP EXTERNOVERIMMhether overlay overwrites not set in field capability of Iframe buffer memory see struct v412_framebuffer Section 4 2 VID TYPE SCALES This flag indicates if the hardware can scale images The IVAL2 API implies the scale factor by setting the cropping dimensions and image size with he VIDIOC S CROP and VIDIOC S FMT ioctl respectively The driver returns the closest sizes possible For more information on cropping and scaling see Section 1 11 IVID TYPE MONOCHROMI Fl Applications can enumerate the supported image formats with the IVIDIOC ENUM FMT ioctl to determine if the device supports erey scale capturing only For more information on image formats see Chapter 2 203
62. USERBITS field 0x000C C USERBITS USERDEFINEDOx0000 C USERBITS 8BITCHARS 0x0008 VAL2 3 6 Field Order Chapter 3 Input Output Frame rate the timecodes are based on see Table 3 6 Timecode flags see Table 3 7 Frame count 0 23 24 29 49 59 depending on the type of timecode Seconds count 0 59 This is a binary not BCD number Minutes count 0 59 This is a binary not BCD number Hours count 0 29 This is a binary not BCD number The user group bits from the timecode 24 frames per second i e film 25 frames per second i e PAL or SECAM video 30 frames per second i e NTSC video Indicates drop frame semantics for counting frames in 29 97 fps material When set frame numbers 0 and 1 at the start of each minute except minutes 0 10 20 30 40 50 are omitted from the count The color frame flag Field mask for the binary group flags Unspecified format 8 bit ISO characters We have to distinguish between progressive and interlaced video Progressive video transmits all lines of a video image sequentially Interlaced video divides an image into two fields containing only the odd and even lines of the image respectively Alternating the so called odd and even field are transmitted and due to a small delay between fields a cathode ray TV displays the lines interleaved yielding the original frame This curious technique was invented because at refresh rates
63. VAL2 CID MPEG BASE 106 enum v412 mpeg audio mode extension V4L2 MPEG AUDIO MODE EXTENSION BOUND 4 0 V4L2 MPEG AUDIO MOD EXTENSION BOUND 8 1 V4L2 MPEG AUDIO MODE EXTENSION BOUND 12 2 V4L2 MPEG AUDIO MOD EXTENSION BOUND 16 3 define V4L2 CID MPEG AUDIO EMPHASIS V4L2_CID_MPEG_BASE 107 enum v412 mpeg audio emphasis V4L2 MPEG AUDIO EMPHASIS NONE 20 V4L2 MPEG AUDIO EMPHASIS 50 DIV 15 uS 1 V4L2 MPEG AUDIO EMPHASIS CCITT J17 uo hi define V4L2 CID MPEG AUDIO CRC VAL2 CID MPEG BASE 108 enum v412 mpeg audio crc V4L2 MPEG AUDIO CRC NONE 0 V4L2 MPEG AUDIO CRC CRC16 1 H define V4L2 CID MPEG AUDIO MUT Fl V4L2_CID_MPEG_BASE 109 MPEG video x define V4L2 CID MPEG VIDEO ENCODING VAL2 CID MPEG BASE 200 enum v412 mpeg video encoding V4L2 MPEG VIDEO ENCODING MP V4L2 MPEG VIDEO ENCODING MP I I define V4L2_CID MPEG VIDEO ASPECT VAL2 CID MPEG BASE 201 enum v412 mpeg video aspect VA4L2 MPEG VIDEO ASPECT 1x1 V4L2_MPEG_VIDEO_ASPECT_4x3 V4L2_MPEG_VIDEO_ASPECT_16x9 VAL2 MPEG VIDEO ASPECT 221x100 ll WNrFR OO hi define V4L2_CI define V4L2_CI MPEG_VIDEO_B_FRAMES MPEG_VIDEO_GOP_SIZE define V4L2_CID_MPEG_VIDEO_GOP_CLOSURE define V4L2_CID_MPEG_VIDEO_PULLDOWN define V4L2 CID MPEG
64. VIDIOC OVERLAY OLD The old ioctl will be removed in the future Until further the videodev kernel module will automatically translate to the new version so drivers must be recompiled but not applications 5 Section 4 2 incorrectly stated that clipping rectangles define regions where the video can be seen Correct is that clipping rectangles define regions where no video shall be displayed and so the graphics surface can be seen 6 The VIDIOC_S_PARM and VIDIOC S CTRL ioctls were defined with write only parameter inconsistent with other ioctls modifying their argument They were changed to write read while a OLD suffix was added to the write only versions The old ioctls will be removed in the future Drivers and applications assuming a constant parameter need an update 6 2 11 V4L2 2003 11 05 1 In Section 2 4 the following pixel formats were incorrectly transferred from Bill Dirks V4L2 specification Descriptions below refer to bytes in memory in ascending address order Symbol In this document prior to Corrected revision 0 5 IVAL2 PIX FMT RGB24 B G R R G B V4L2_PIX_FMT_BGR24 R G B B G R V4L2_PIX_FMT_RGB32 B G R X R G B X V4L2_PIX_FMT_BGR32 R G B X B G R X The v4L2_PIX_FMT_BGR24 example was always correct In Section 6 1 5 the mapping of the V4L vIDEO PALETTE RGB24 and VIDEO PALETT E RGB32 formats to V4L2 pixel formats was ac
65. VIDIOC S PRIORITY eres eene eee eere eee tn etn oto ae tne toes tata 158 ioctl VIDIOC G SLICED VBI CAP neta ere eene r aeta ona etn realen ot ee ba beta el nei o ena e iota ooa e gan 160 ioctl VIDIOC G STD VIDIOC S STD eese esee eee ee eee eo etos tone eae ee sese esee tn sens eo s eoe eese neEa 162 ioctl VIDIOC G TUNER VIDIOC S TUNER eee ee eee eee ento eene ene te tto tn sens eo setae eee ee neta 163 ioctl VIDIOC LOG STATUS reos retta bo rator a oae PY orla oaa oak tho Va lo oi toi ern SUE aek keen aea tos eoa etian 168 ioctl VIDIOC OVERLAY eene eee beast rotta bor Fete a one orae rl auia rona eth s Palos oi toot lea ola ek een aea tos ie ooa di engan 169 ioctl VIDIOC QBUF VIDIOC DQBUF eere ee eee eee eene tne to oto e eae ee sete esee ene en aeos etae eese neta 170 ioctl VIDIOC QUERY BUR iisscseccccsccstsssctececesevecseccecsnssccssseosessetescuscsccesverseccocseasscsecesdescoseccvacs cest sess 172 ioctl VIDIO C2 QUERY CAP rerit tee es eee eax castescssesscves codsesiecakosacsstssvatueesuctwasansaessassbuewesscvesesetss 174 ioctl VIDIOC QUERYCTRL VIDIOC_QUERYMENU e ecce eee eere senso seno tuse tae tees neta 177 ioctl VIDIOC QUERYSTD rn ssisscssscesecsvcestesnssosssesesensessetenosststesveaessussvsosusasessassbbawessovesessess 182 ioctl VIDIOG RE QBUES cvcscscsccccscessscecceossceesvecsevenssossesuecescessecesssecucsesvscs
66. and then hold the current setting Contrast this with the boolean V4L2_CID_AUTO_WHITE_BALANCE which when activated keeps adjusting the white balance Red chroma balance Blue chroma balance Gamma adjust Whiteness for grey scale devices This is a synonym for V4L2_CID_GAMMA This control is deprecated and should not be used in new drivers and applications Exposure cameras Unit Automatic gain exposure control Gain control Mirror the picture horizontally Mirror the picture vertically Horizontal image centering This control is deprecated New drivers and applications should use the Camera class controls V4L2_CID_PAN_ABSOLUTE VA4L2 CID PAN RELATIVE and VA4L2 CID PAN RESET instead Vertical image centering Centering is intended to physically adjust cameras For image cropping see Section 1 11 for clipping Section 4 2 This control is deprecated New drivers and applications should use the Camera class controls VA4L2 CID TILT ABSOLUTE VA4L2 CID TILT RELATIVE and VA4L2 CID TILT RESET instead Enables a power line frequency filter to avoid flicker Possible values are V4L2 CID POWER LINE FREQUENCY DISABLED 0 VAL2 CID POWER LINE FREQUENCY 50HZ 1 and V4L2 CID POWER INE FREQUENCY 60HZ 2 Il ID Type V4L2 CID HUE AUTO boolean T V4L2 CID WHITE BALANC
67. and private controls after hardware detection without the trouble of reordering control arrays and indices EINVAL cannot be used to skip private controls because it would prematurely end th numeration ioctl VIDIOC QUERYSTD Name VIDIOC QUERYSTID Sense the video standard received by the current input Synopsis int ioctl int fd int request v412 std id xargp Arguments fd File descriptor returned by open request VIDIOC_QUERYSTD argp Description The hardware may be able to detect the current video standard automatically To do so applications call VIDIOC_QUERYSTD with a pointer to a v4 2_std_id type The driver stores here a set of candidates this can be a single flag or a set of supported standards if for example the hardware can only distinguish between 50 and 60 Hz systems When detection is not possible or fails the set must contain all standards supported by the current video input or output Return Value On success 0 is returned on error 1 and the errno variable is set appropriately 182 ioctl VIDIOC QUERYSTD EINVAL This ioctl is not supported 183 ioctl VIDIOC REQBUFS Name VIDIOC_REQBUEF S Initiate Memory Mapping or User Pointer I O Synopsis int ioctl int fd int request struct v412 requestbuffers argp Arguments fd File descriptor returned by open request VIDIOC REQBUFS argp Description This ioctl is used to initiate mem
68. are not known 6 2 28 V4L2 in Linux 2 6 24 1 The pixel formats VAL2 PIX FMT PAL8 V4L2 PIX FMT YUV444 V4L2 PIX FMT YUV555 V4L2 PIX FMT YUV565 and V4L2 PIX FMT YUV32 were added 6 2 29 V4L2 in Linux 2 6 25 1 The pixel formats v4AL2 PIX FMT Y16 and V4L2 PIX FMT SBGGR16 were added 2 New controls VAL2 CID POWER LINE FREQUENCY V4L2 CID HUE AUTO V4L2 CID WHITE BALANCE TEMPERATURE V4L2_CID_SHARPNESS and V4L2 CID BACKLIGHT COMPENSATION were added The controls v4 2 CID BLACK LEVEL V4L2_CID_WHITENESS V4AL2 CID HCENTER and V4L2 CID VCENTER were deprecated 3 A Camera controls class was added with the new controls v4 2 CID EXPOSURE AUTO V4L2 CID EXPOSURE ABSOLUTE VAL2 CID EXPOSURE AUTO PRIORITY V4L2 CID PAN RELATIVE V4L2_CID_TILT_RELATIVE VAL2 CID PAN RESET V4L2 CID TILT RESET VAL2 CID PAN ABSOLUTE V4L2 CID TILT ABSOLUTE V4L2 CID FOCUS ABSOLUTE V4L2 CID FOCUS RELATIVE and V4L2 CID FOCUS AUTO 4 The viDIOC G MPEGCOMP and VIDIOC S MPEGCOMP ioctls which were superseded by the extended controls interface in Linux 2 6 18 where finally removed from the videodev2 h header file 6 3 Relation of V4L2 to other Linux multimedia APIs 6 3 1 X Video Extension The X Video Extension abbreviated XVideo or just Xv is a
69. been started yet After a STOP command read calls will read the remaining data buffered by the driver When the buffer is empty read will return zero and the next read call will restart the encoder A close call sends an immediate STOP to the encoder and all buffered data is discarded These ioctls are optional not all drivers may support them They were introduced in Linux 2 6 21 97 ioctl VIDIOC ENCODER CMD VIDIOC TRY ENCODER CMD Table 1 struct v4l2 encoder cmd u32 u32 u32 cmd flags data 8 Table 2 Encoder Commands VAL2 VAL2 VAL2 VAL2 ENC CMD START ENC CMD STOP ENC CMD PAUSE ENC CMD RESUME Table 3 Encoder Command Flags V4L2 ENC CMD STOP AT GOP ENDOx0001 Return Value The encoder command see Table 2 Flags to go with the command see Table 3 If no flags are defined for this command drivers and applications must set this field to zero Reserved for future extensions Drivers and applications must set the array to zero Start the encoder When the encoder is already running or paused this command does nothing No flags are defined for this command Stop the encoder When the V4L2_ENC_CMD_STOP_AT_GOP_END flag is set encoding will continue until the end of the current Group Of Pictures otherwise encoding will stop immediately When the encoder is already stopped this command does nothing Pau
70. bit representing another video standard as listed below and in Table 4 The 32 most significant bits are reserved for custom driver defined video standards define V4L2 STD PAL B v412 std id 0x00000001 define VA4L2 STD PAL B1 v412 std id 0x00000002 define V4L2 STD PAL G v412 std id 0x00000004 define V4L2 STD PAL H v412 std id 0x00000008 define VA4L2 STD PAL I v412 std id 0x00000010 define V4L2 STD PAL D v412 std id 0x00000020 define VA4L2 STD PAL D1 v412 std id 0x00000040 define V4L2 STD PAL K v412 std id 0x00000080 define V4L2 STD PAL M v412 std id 0x00000100 define V4L2 STD PAL N v412 std id 0x00000200 define VA4L2 STD PAL NC v412 std id 0x00000400 define V4L2 STD PAL 60 v412 std id 0x00000800 V4L2 STD PAL 60 is a hybrid standard with 525 lines 60 Hz refresh rate and PAL color modulation with a 4 43 MHz color subcarrier Some PAL video recorders can play back NTSC tapes in this mode for display on a 50 60 Hz agnostic PAL TV define V4L2 STD NTSC M v412 std id 0x00001000 define V4L2 STD NTSC M JP v412 std id 0x00002000 define V4L2 STD NTSC 443 v412 std id 0x00004000 V4L2 STD NTSC 443 is a hybrid standard with 525 lines 60 Hz refresh rate and NTSC color modulation with a 4 43 MHz color subcarrier 115 define V4L2 STD NTSC M KR define V4L2 STD SECAM B define V4L2 STD SECAM D define V4L2
71. c rounding 30 bits wide if needed to add more than two standards x some merged standards define V4L2 STD MN VAL2 STD PAL M V4L2 STD PAL N V4L2 STD PAL Nc V4L2 STD NTSC define V4L2 STD B VAL2 STD PAL B V4L2 STD PAL B1 V4L2 STD SECAM B define V4L2 STD GH VAL2 STD PAL G V4L2 STD PAL H V4L2 STD SECAM G V4L2 STD SECAM H define V4L2 STD DK VAL2 STD PAL DK V4L2 STD SECAM DK some common needed stuff x define V4L2 STD PAL BG VAL2 STD PAL B X V4L2_STD_PAL_B1 N V4L2 STD PAL G define V4L2 STD PAL DK VAL2 STD PAL D N V4L2 STD PAL D1 N V4L2 STD PAL K define V4L2 STD PAL VAL2 STD PAL BG N VAL2 STD PAL DK N VA4L2 STD PAL H N V4L2 STD PAL I define V4L2 STD NTSC VAL2 STD NTSC M N VA4L2 STD NTSC M JP N V4L2 STD NTSC M KR define V4L2 STD SECAM DK VAL2 STD SECAM D N V4L2 STD SECAM K N V4L2 STD SECAM K1 define V4L2 STD SECAM VAL2 STD SECAM B N VA4L2 STD SECAM G N V4L2 STD SECAM H N VA4L2 STD SECAM DK N 236 define V4L2 STD 525 60 define V4L2 STD 625 50 define V4L2 STD ATSC define V4L2 STD UNKNOWN define V4L2 STD ALL struct v412 standard Appendix A Video For Linux Two Header File V4L2_STD_SECAM_L V4L2_STD_SECAM_LC VAL2 STD PAL M N VAL2 STD PAL 60 N VA4L2 STD NTSC N V4L2 STD
72. char dev_name 16 struct fb fix screeninfo si snprintf dev name sizeof dev name dev fb u i fb fd open dev name O_RDWR if 1 fb fd switch errno case ENOENT no such file x case ENXIO x no driver x continue default perror open exit EXIT FAILURE if 0 ioctl fb fd FBIOGET FSCREENINFO amp si if si smem start unsigned long fbuf base break else Apparently not a framebuffer device close fb fd fb fd 1 fb fd is the file descriptor of the framebuffer devic for the video output overlay or 1 if no device was found x 4 4 3 Overlay Window and Scaling The overlay is controlled by source and target rectangles The source rectangle selects a subsection of the framebuffer image to be overlaid the target rectangle an area in the outgoing video signal where the image will appear Drivers may or may not support scaling and arbitrary sizes and positions of these rectangles Further drivers may support any or none of the clipping blending methods defined for the Video Overlay interface A struct v412 window defines the size of the source rectangle its position in the framebuffer and the clipping blending method to be used for the overlay To get the current parameters applications set the type field of a struct v412 format to V4AL2 BUF TYPE VIDEO OUTPUT OVERLAY and call the VIDIOC G FMT ioctl The d
73. define VIDIOC G MODULATOR _IOWR V 54 struct v412 modulator define VIDIOC S MODULATOR _IOw V 55 struct v412 modulator define VIDIOC G FREQUENCY _IOWR V 56 struct v412 frequency define VIDIOC S FREQUENCY IOW V 57 struct v412 frequency define VIDIOC CROPCAP _IOWR V 58 struct v412 cropcap define VIDIOC G CROP _IOWR V 59 struct v412 crop define VIDIOC S CROP _IOw V 60 struct v412 crop define VIDIOC G JPEGCOMP _IOR V 61 struct v412 jpegcompression define VIDIOC S JPEGCOMP _IOW V 62 struct v412 jpegcompression define VIDIOC QUERYSTD _IOR V 63 v412 std id define VIDIOC TRY FMT _IOWR V 64 struct v412 format define VIDIOC ENUMAUDIO _IOWR V 65 struct v412 audio define VIDIOC ENUMAUDOUT _IOWR V 66 struct v412_audioout define VIDIOC G PRIORITY _IOR V 67 enum v412 priority define VIDIOC S PRIORITY IOW V 68 enum v412 priority 249 define define define define define define define define define define if 1 xKEEP Experimental Appendix A Video For Linux Two Header File VIDIOC G SLICED VBI CAP IOWR V VIDIOC LOG STATUS IO v VIDIOC G EXT CTRLS _IOWR V VIDIOC S EXT CTRLS _IOWR V VIDIOC TRY EXT CTRLS _IOWR V VIDIOC ENUM FRAMESIZES IOWR V 74 struct VIDIOC ENUM FRAMEINTERVALS ATOWR Vi ATS VIDIOC_G_ENC_INDEX LOR Vft
74. devices the coordinates of the top left corner width and height of the area which can be sampled is given by the bounds substructure of the struct v412_cropcap returned by the 23 Chapter 1 Common API Elements VIDIOC_CROPCAP ioctl To support a wide range of hardware this specification does not define an origin or units However by convention drivers should horizontally count unscaled samples relative to OH the leading edge of the horizontal sync pulse see Figure 4 1 Vertically ITU R line numbers of the first field Figure 4 2 Figure 4 3 multiplied by two if the driver can capture both fields The top left corner width and height of the source rectangle that is the area actually sampled is given by struct v412_crop using the same coordinate system as struct v412_cropcap Applications can use the VIDIOC G CROP and VIDIOC S CROP ioctls to get and set this rectangle It must lie completely within the capture boundaries and the driver may further adjust the requested size and or position according to hardware limitations Each capture device has a default source rectangle given by the de rect substructure of struct v412_cropcap The center of this rectangle shall align with the center of the active picture area of the video signal and cover what the driver writer considers the complete picture Drivers shall reset the source rectangle to the default when the driver is first loaded but not later For output devices these structures and
75. efficient than capturing images and displaying them by other means In the old days when only nuclear power plants needed cooling towers this used to be the only way to put live video into a window Video overlay devices are accessed through the same character special files as video capture devices Note the default function of a dev video device is video capturing The overlay function is only available after calling the VIDIOC_S_FMT ioctl The driver may support simultaneous overlay and capturing using the read write and streaming I O methods If so operation at the nominal frame rate of the video standard is not guaranteed Frames may be directed away from overlay to capture or one field may be used for overlay and the other for capture if the capture parameters permit this Applications should use different file descriptors for capturing and overlay This must be supported by all drivers capable of simultaneous capturing and overlay Optionally these drivers may also permit capturing and overlay with a single file descriptor for compatibility with V4L and earlier versions of V4L2 4 2 1 Querying Capabilities Devices supporting the video overlay interface set the v4 2 CAP VIDEO OVERLAY flag in the capabilities field of struct v412 capability returned by the VIDIOC_QUERYCAP ioctl The overlay I O method specified below must be supported Tuners and audio inputs are optional 4 2 2 Supplemental Functions Video overlay d
76. example when the name or id imply a particular unit and the hardware actually accepts only multiples of said unit If so drivers must take care values are properly rounded when scaling such that errors will not accumulate on repeated read write cycles This field gives the smallest change of an integer control actually affecting hardware Often the information is needed when the user can change controls by keyboard or GUI buttons rather than a slider When for example a hardware register accepts values 0 511 and the driver reports 0 65535 step should be 128 Note although signed the step value is supposed to be always positive The default value of a V4L2 CTRL TYPE INTEGER BOOLEAN or MENU control Not valid for other types of controls Drivers reset controls only when the driver is loaded not later in particular not when the func open is called Control flags see Table 4 Reserved for future extensions Drivers must set the array to zero Identifies the control set by the application from the respective struct v412 queryctrl id Index of the menu item starting at zero set by the application Name of the menu item a NUL terminated ASCII string This information is intended for the user Reserved for future extensions Drivers must set the array to zero 179 Type ioctl VIDIOC QUERYCTRL VIDIOC QUERYMENU Description minisinspmaximum V4L2 CTRL
77. fd set xwritefds fd set xexceptfds struct timeval xtimeout Description With the select function applications can suspend execution until the driver has captured data or is ready to accept data for output When streaming I O has been negotiated this function waits until a buffer has been filled or displayed and can be dequeued with the VIDIOC_DQBUF ioctl When buffers are already in the outgoing queue of the driver the function returns immediately On success select returns the total number of bits set in the fd sets When the function timed out it returns a value of zero On failure it returns 1 and the errno variable is set appropriately When the application did not call VIDIOC_QBUF or VIDIOC_STREAMON yet the select function succeeds setting the bit of the file descriptor in readfds or writefds but subsequent VIDIOC DQBUF calls will fail When use of the read function has been negotiated and the driver does not capture yet the select function starts capturing When that fails select returns successful and a subsequent read call which also attempts to start capturing will return an appropriate error code When the driver captures continuously as opposed to for example still images and data is already available the select function returns immediately When use of the write function has been negotiated the select function just waits until the driver is ready for a non blocking write call
78. file Documentation video4linux cx2341x README hm12 V4L2_PIX_FMT_MJPEG MJPG Compressed format used by the Zoran driver V4L2_PIX_FMT_PWC1 PWC Compressed format of the PWC driver V4L2_PIX_FMT_PWC2 PWC2 Compressed format of the PWC driver VA4L2 PIX FMT SN9C10X 910 Compressed format of the SN9C102 driver V4L2_PIX_FMT_WNVA WNVA Used by the Winnov Videum driver http www thedirks org winnov V4L2_PIX_FMT_YYUV YYUV unknown 50 Chapter 3 Input Output The V4L2 API defines several different methods to read from or write to a device All drivers exchanging data with applications must support at least one of them The classic I O method using the read and write function is automatically selected after opening a V4L2 device When the driver does not support this method attempts to read or write will fail at any time Other methods must be negotiated To select the streaming I O method with memory mapped or user buffers applications call the VIDIOC_REQBUFS ioctl The asynchronous I O method is not defined yet Video overlay can be considered another I O method although the application does not directly receive the image data It is selected by initiating video overlay with the VIDIOC_S_FMT ioctl For more information see Section 4 2 Generally exactly one I O method including overlay is associated with each file descriptor The only exceptions are applications not exchanging data with a driver panel a
79. fourcc P W C 1 pwc older webcam x define V4L2 PIX FMT PWC2 v412 fourcc P W C 2 x pwc newer webcam x define VA4AL2 PIX FMT ET61X251 v412 fourcc E 6 2 5 ET61X251 compression FORMAT ENUMERATION struct v412_fmtdesc 32 index Format number enum v412 buf type type buffer type u32 flags u8 description 32 x Description string x u32 pixelformat Format fourcc u32 reserved 4 H 230 define V4L2 FMT FLAG COMPRESSE if 1 KEEP FRAME S I A E F x enum v412 frmsizetypes Appendix A Video For Linux Two Header File D 0x0001 NUME VA4L2 FRMSIZE TYPE DISCRETE S52 V4L2_FRMSIZE_TYPE_CONTINUOUS 2 V4L2_FRMSIZE_TYPE_STEPWISE 3 struct v412 frmsize discrete u32 width s u32 height struct v412 frmsize stepwise 132 251192 u32 u32 zau 3032 struct v412 frmsizeenum min_width max_width step width min height max height step height 2232 index u32 pixel_format u32 type union struct v412 frmsize discrete struct v412 frmsize stepwis M32 reserved 2 hi FRAME RATE ENUMERAT x Experimental Frame Size and frame rate enumeration RATION Frame width pixel x Frame height pixel x Minimum frame width pixel Maximum frame width pixel Fra
80. individually can be determined from the struct v412 buffer sequence field Image sizes refer to the frame not fields This format cannot be selected when using the read write I O method Images contain both fields interleaved line by line top field first The top field is transmitted first Images contain both fields interleaved line by line top field first The bottom field is transmitted first 62 Chapter 3 Input Output Figure 3 1 Field Order Top Field First Transmitted Temporal order top field first transmitted e g BG PAL V4AL2 FIELD TOP V4L2 FIELD BOTTOM Em V4L2 FIELD ALTERNATE E EN v4l2_buffer field V4L2_FIELD_TOP V4L2_FIELD_BOTTOM V4L2_FIELD_TOP V4L2_FIELD_BOTTOM V4L2_FIELD_TOP V V4L2 FIELD INTERLACED V4L2 FIELD INTERLACED TB V4AL2 FIELD INTERLACED BT misaligned V4L2 FIELD SEQ TB Chapter 3 Input Output Figure 3 2 Field Order Bottom Field First Transmitted Temporal order bottom field first transmitted e g M NTSC V4AL2 FIELD TOP Em E V4L2 FIELD BOTTOM V4AL2 FIELD ALTERNATE m v4l2_buffer field V4L2_FIELD_BOTTOM V4L2_FIELD_TOP V4L2_FIELD_BOTTOM V4L2_FIELD_TOP V4L2_FIELD_BOTTOM V4L2 FIELD INTERLACED V4L2 FIELD INTERLACED BT VA4L2 FIELD INTERLACED TB misaligned V4L2 FIELD SEQ BT Notes Chapter 3 Input Output It would be desirable if applications could depend on drivers supporting all I O interfaces but as muc
81. int request struct v412 sliced vbi cap xargp Arguments fd File descriptor returned by open request VIDIOC G SLICED VBI CAP argp Description To find out which data services are supported by a sliced VBI capture or output device applications initialize the type field of a struct v412 sliced vbi cap clear the reserved array and call the VIDIOC G SLIC ED VBI CAP ioctl The driver fills in the remaining fields or returns an EINVAL error code if the sliced VBI API is unsupported or t ype is invalid Note the type field was added and the ioctl changed from read only to write read in Linux 2 6 19 Table 1 struct v412 sliced vbi cap ul6 ul6 service set A set of all data services supported by the driver Equal to the union service lines 2 24 Each element of this array contains a set of data services the hardwa Element 525 line systems 625 line systems service lines O 1 1 1 service lines 0 2323 23 service lines l 1P64 314 service lines l 23 86 336 160 enum v412 buf type type u32 Table 2 Sliced VBI services Symbol Value reserved 3 ioctl VIDIOC G SLICED VBI CAP The number of VBI lines the hardware can capture or output per frar Drivers must set service lines 0 0 and service 1ines 1 0 Type of the data stream see Table 3 2 Should be V4L2 BUF TYPE SLIC ED VBI CAPTURE or V4L2 BUF TYPE SLIC ED VBI OUTPUT
82. ioctls They do not support the video input or output audio input or output video standard cropping and scaling compression and streaming parameter or overlay ioctls All other ioctls and I O methods are reserved for future extensions 4 10 3 Programming Radio devices may have a couple audio controls as discussed in Section 1 8 such as a volume control possibly custom controls Further all radio devices have one tuner these are discussed in Section 1 6 with index number zero to select the radio frequency and to determine if a monaural or FM stereo program is received Drivers switch automatically between AM and FM depending on the selected frequency The VIDIOC_G_TUNER ioctl reports the supported frequency range 85 Chapter 4 Interfaces 4 11 RDS Interface Notes The Radio Data System transmits supplementary information in binary format for example the station name or travel information on a inaudible audio subcarrier of a radio program This interface aims at devices capable of receiving and decoding RDS information The VAL API defines its RDS API as follows From radio devices supporting it RDS data can be read with the read function The data is packed in groups of three as follows 1 First Octet Least Significant Byte of RDS Block 2 Second Octet Most Significant Byte of RDS Block 3 Third Octet Bit 7 Error bit Indicates that an uncorrectable error occurred during reception of this block Bit 6 Corr
83. ioctls are used accordingly defining the target rectangle where the images will be inserted into the video signal 1 11 2 Scaling Adjustments Video hardware can have various cropping insertion and scaling limitations It may only scale up or down support only discrete scaling factors or have different scaling abilities in horizontal and vertical direction Also it may not support scaling at all At the same time the struct v412 crop rectangle may have to be aligned and both the source and target rectangles may have arbitrary upper and lower size limits In particular the maximum width and height in struct v4l2 crop may be smaller than the struct v412_cropcap bounds area Therefore as usual drivers are expected to adjust the requested parameters and return the actual values selected Applications can change the source or the target rectangle first as they may prefer a particular image size or a certain area in the video signal If the driver has to adjust both to satisfy hardware limitations the last requested rectangle shall take priority and the driver should preferably adjust the opposite one The VIDIOC_TRY_FMT ioctl however shall not change the driver state and therefore only adjust the requested rectangle Suppose scaling on a video capture device is restricted to a factor 1 1 or 2 1 in either direction and the target image size must be a multiple of 16 x 16 pixels The source cropping rectangle is set to defaults which are also the
84. may need to fr the buffers here x printf Not enough buffer memory n exit EXIT FAILURE 52 Chapter 3 Input Output buffers calloc reqbuf count sizeof buffers assert buffers NULL for i 0 i reqbuf count i struct v412 buffer buffer memset amp buffer 0 sizeof buffer buffer type regqbuf type buffer memory V4L2_MEMORY_MMAP buffer index i if 1 ioctl fd VIDIOC QUERYBUF amp buffer perror VIDIOC QUERYBUF exit EXIT FAILURE buffers i length buffer length x remember for munmap x buffers i start mmap NULL buffer length PROT READ PROT WRITE x recommended MAP SHARED recommended fd buffer m offset if MAP FAILED buffers i start If you do not exit here you should unmap and free the buffers mapped so far perror mmap exit EXIT FAILURE Cleanup for i 0 i reqbuf count i munmap buffers i start buffers i length Conceptually streaming drivers maintain two buffer queues an incoming and an outgoing queue They separate the synchronous capture or output operation locked to a video clock from the application which is subject to random disk or network delays and preemption by other processes thereby reducing the probability of data loss The queues are organized as FIFOs buffers will be output in the order enqueued in the incoming FIF
85. mode 119 Table 1 struct v412_audio u32 u8 u32 u32 u32 index name 32 capability mode reserved 2 Table 2 Audio Capability Flags V4L2_AUDCAP_STERE V4L2_AUDCAP_AVL O 0x00001 0x00002 Table 3 Audio Mode Flags V4L2_AUDMOD Return Value E AVL 0x00001 ioctl VIDIOC G AUDIO VIDIOC S AUDIO Identifies the audio input set by the driver or application Name of the audio input a NUL terminated ASCII string for example Line In This information is intended for the user preferably the connector label on the device itself Audio capability flags see Table 2 Audio mode flags set by drivers and applications on VIDIOC S AUDIO ioctl see Table 3 Reserved for future extensions Drivers and applications must set the array to zero This is a stereo input The flag is intended to automatically disable stereo recording etc when the signal is always monaural The API provides no means to detect if stereo is received unless the audio input belongs to a tuner Automatic Volume Level mode is supported AVL mode is on On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL No audio inputs combine with the current video input or the number of the selected audio input is out of bounds or it does not combine or there are no audio inputs at all and the ioctl is not supported EBUSY I O is in progress the input can
86. n_buffers start errno exit mmap 257 Appendix B Video Capture Example static void init userp unsigned int buffer size struct v412 requestbuffers req unsigned int page size page size getpagesize buffer size buffer size page siz 1 amp page size 1 CLEAR req req count 4 req type V4L2 BUF TYPE VIDEO CAPTURE req memory V4L2 MEMORY USERPTR if 1 xioctl fd VIDIOC REQBUFS amp reqg if EINVAL errno fprintf stderr Ss does not support user pointer i o n dev name exit EXIT FAILURE else errno exit VIDIOC REQBUFS buffers calloc 4 sizeof buffers if buffers fprintf stderr Out of memory n exit EXIT FAILURE for n buffers 0 n buffers lt 4 c n buffers buffers n buffers length buffer size buffers n buffers start memalign boundary page size buffer size if buffers n buffers start fprintf stderr Out of memory n exit EXIT FAILURE static void init device void struct v412 capability cap struct v412 cropcap cropcap struct v412 crop crop struct v412 format fmt unsigned int min if 1 xioctl fd VIDIOC QUERYCAP amp cap if EINVAL errno fprintf stderr s is no V4L2 device n 258 Appendix B Video Capture Example dev name exit EXIT FAILURE
87. of the top left corner of the rectangle in pixels Offsets increase to the right and down Width of the rectangle in pixels Height of the rectangle in pixels Width and height cannot be negative the fields are signed for hysterical reasons To start or stop the frame buffer overlay applications call the VIDIOC_OVERLAY ioctl 4 3 Video Output Interface Video output devices encode stills or image sequences as analog video signal With this interface 70 Chapter 4 Interfaces applications can control the encoding process and move images from user space to the driver Conventionally VAL2 video output devices are accessed through character device special files named dev video and dev video0 to dev video63 with major number 81 and minor numbers 0 to 63 dev video is typically a symbolic link to the preferred video device Note the same device files are used for video capture devices 4 3 1 Querying Capabilities Devices supporting the video output interface set the v4 2 CAP VIDEO OUTPUT flag in the capabilities field of struct v412 capability returned by the VIDIOC_QUERYCAP ioctl As secondary device functions they may also support the raw VBI output VAL2 CAP VBI OUTPUT interface At least one of the read write or streaming I O methods must be supported Modulators and audio outputs are optional 4 3 2 Supplemental Functions Video output devices shall support audio output modulator controls cropping and scal
88. outputs and audios were removed These properties can be determined as described in Section 1 4 and Section 1 5 The somewhat volatile and therefore barely useful fields maxwidth maxheight minwidth minheight maxframerate were removed This information is available as described in Section 1 10 and Section 1 7 VAL2 FLAG SELECT was removed We believe the select function is important enough to require support of it in all VAL2 drivers exchanging data with applications The redundant VAL2 FLAG MONOCHROME flag was removed this information is available as described in Section 1 10 4 In struct v412 input the assoc audio field and the capability field and its only flag VAL2 INPUT CAP AUDIO was replaced by the new audioset field Instead of linking one video input to one audio input this field reports all audio inputs this video input combines with 214 Chapter 6 Changes New fields are tuner reversing the former link from tuners to video inputs std and status Accordingly struct v412 output lost its capability and assoc audio fields audioset modulator and std where added instead The struct v412 audio field audio was renamed to index for consistency with other structures A new capability flag vaL2 AUDCAP STEREO Was added to indicated if the audio input in question supports stereo sound VAL2 AUDCAP EFFECTS and the corresponding VAL2 AUDMODE flags where removed This can be easily implemented using con
89. prepares for user pointer I O when this I O method is not supported the ioctl returns an EINVAL error code 184 Table 1 struct v412_requestbuffers u32 enum v4 2 buf type enum v4 2 memory u32 Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EBUSY count type memory reserved 2 ioctl VIDIOC REQBUFS The number of buffers requested or granted This field is only used when memory is set to V4L2 MEMORY MMAP Type of the stream or buffers this is the same as the struct v412 format t ype field See Table 3 2 for valid values Applications set this field to vVAL2 Mi or V4L2 MEMORY USERPTR EMORY MMAP A place holder for future extensions and custom driver defined buffer types VAL2 BUF TYPE PRIVATI E and higher The driver supports multiple opens and I O is already in progress or reallocation of buffers was attempted although one or more are still mapped EINVAL The buffer type t ype field or the requested I O method memory is not supported 185 Notes 1 For example video output requires at least two buffers one displayed and one filled by the application ioctl VIDIOC STREAMON VIDIOC STREAMOFF Name VIDIOC STREAMON VIDIOC STREAMOFF Start or stop streaming I O Synopsis int ioctl int fd int request const int xargp Arguments fd File descriptor returned by open request
90. priority in an enum v412 priority variable and call VIDIOC_S_PRIORITY ioctl with a pointer to this variable Table 1 enum v4l2 priority V4L2 PRIORITY UNSET 0 V4L2 PRIORITY BACKGROUND 1 Lowest priority usually applications running in background for example monitoring VBI transmissions A proxy application running in user space will be necessary if multiple applications want to read from a device at this priority V4L2_PRIORITY_INTERACTIVE 2 158 ioctl VIDIOC G PRIORITY VIDIOC S PRIORITY V4L2 PRIORITY DEFAULT 2 Medium priority usually applications started and interactively controlled by the user For example TV viewers Teletext browsers or just panel applications to change the channel or video controls This is the default priority unless an application requests another V4L2 PRIORITY RECORD 3 Highest priority Only one file descriptor can have this priority it blocks any other fd from changing device properties Usually applications which must not be interrupted like video recording Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The requested priority value is invalid or the driver does not support access priorities EBUSY Another application already requested higher priority 159 ioctl VIDIOC G SLICED VBlI CAP Name VIDIOC G SLI Synopsis int ioctl int CED VBI CAP Query sliced VBI capabilities fd
91. similar to film the image would fade out too quickly Transmitting fields reduces the flicker without the necessity of doubling the frame rate and with it the bandwidth required for each channel 60 Chapter 3 Input Output It is important to understand a video camera does not expose one frame at a time merely transmitting the frames separated into fields The fields are in fact captured at two different instances in time An object on screen may well move between one field and the next For applications analysing motion it is of paramount importance to recognize which field of a frame is older the temporal order When the driver provides or accepts images field by field rather than interleaved it is also important applications understand how the fields combine to frames We distinguish between top and bottom fields the spatial order The first line of the top field is the first line of an interlaced frame the first line of the bottom field is the second line of that frame However because fields were captured one after the other arguing whether a frame commences with the top or bottom field is pointless Any two successive top and bottom or bottom and top fields yield a valid frame Only when the source was progressive to begin with e g when transferring film to video two fields may come from the same frame creating a natural order Counter to intuition the top field is not necessarily the older field Whether the older field contains
92. struct v412 format type field is invalid the requested buffer type not supported or VIDIOC TRY FMT was called and is not supported with this buffer type 142 ioctl VIDIOC G FREQUENCY VIDIOC S FREQUENCY Name VIDIOC G FREQUENCY VIDIOC S FREQUENCY Get or set tuner or modulator radio frequency Synopsis int ioctl int fd int request struct v412 frequency xargp int ioctl int fd int request const struct v412 frequency argp Arguments fd File descriptor returned by open request VIDIOC G FREQUENCY VIDIOC 5 FREQUENCY argp Description To get the current tuner or modulator radio frequency applications set the tuner field of a struct v4I2 frequency to the respective tuner or modulator number only input devices have tuners only output devices have modulators zero out the reserved array and call the VIDIOC G FREQUENCY ioctl with a pointer to this structure The driver stores the current frequency in the requency field To change the current tuner or modulator radio frequency applications initialize the tuner type and frequency fields and the reserved array of a struct v4I2 frequency and call the VIDIOC S FREQUENCY ioctl with a pointer to this structure When the requested frequency is not possible the driver assumes the closest possible value However VIDIOC_S_FREQUENCY is a write only ioctl it does not return the actual new frequency
93. supported 100 ioctl VIDIOC ENUM FMT Name VIDIOC ENUM FMT Enumerate image formats Synopsis int ioctl int fd int request struct v412 fmtdesc xargp Arguments fd File descriptor returned by open request VIDIOC ENUM FMT argp Description To enumerate image formats applications initialize the t ype and index field of struct v412 fmtdesc and call the VIDIOC_ENUM_FMT ioctl with a pointer to this structure Drivers fill the rest of the structure or return an EINVAL error code All formats are enumerable by beginning at index zero and incrementing by one until EINVAL is returned Table 1 struct v412_fmtdesc u32 index Number of the format in the enumeration set by the application This is in no way related to the pixelformat field enum v4 2 buf type type Type of the data stream set by the application Only these types are valid here VAL2 BUF TYPE VIDEO CAPTURE VA4L2 BUF TYPE VIDEO OUTPUT V4L2 BUF TYPE VIDEO OVERLAY and custom driver defined types with code V4L2 BUF TYPE PRIVATE and higher u32 flags See Table 2 u8 description 32 Description of the format a NUL terminated ASCII string This information is intended for the user for example YUV 4 2 2 101 ioctl VIDIOC ENUM FMT u32 pixelformat The image format identifier This is a four character code as computed by the v412_fourcc macro define v412 fourcc a b c d
94. the copyright notices and the license notice saying this License applies to the Document are reproduced in all copies and that you add no other conditions whatsoever to those of this License You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute However you may accept compensation in exchange for copies If you distribute a large enough number of copies you must also follow the conditions in section 3 You may also lend copies under the same conditions stated above and you may publicly display copies C 4 3 COPYING IN QUANTITY If you publish printed copies of the Document numbering more than 100 and the Document s license notice requires Cover Texts you must enclose the copies in covers that carry clearly and legibly all these Cover Texts Front Cover Texts on the front cover and Back Cover Texts on the back cover Both covers must also clearly and legibly identify you as the publisher of these copies The front cover must present the full title with all words of the title equally prominent and visible You may add other material on the covers in addition Copying with changes limited to the covers as long as they preserve the title of the Document and satisfy these conditions can be treated as verbatim copying in other respects If the required texts for either cover are too voluminous to fit legibly you should put the first ones listed as many as fit reasonabl
95. the top or bottom lines is a convention determined by the video standard Hence the distinction between temporal and spatial order of fields The diagrams below should make this clearer All video capture and output devices must report the current field order Some drivers may permit the selection of a different order to this end applications initialize the field field of struct v4I2 pix format before calling the vIDIOC_S_FMT ioctl If this is not desired it should have the value VAL2 FIELD ANY 0 Table 3 8 enum v412_ field V4L2_FIELD_ANY 0 Applications request this field order when any one of the V4L2_FIELD_NONE V4L2_FIELD_TOP V4L2_FIELD_BOTTOM or VA4L2 FIELD INTERLACED formats is acceptable Drivers choose depending on hardware capabilities or e g the requested image size and return the actual field order struct v412 buffer field can never be VA4L2 FIELD ANY V4L2 FIELD NONE 1 Images are in progressive format not interlaced The driver may also indicate this order when it cannot distinguish between V4L2 FIELD TOP and V4L2 FIELD BOTTOM V4L2 FIELD TOP 2 Images consist of the top field only I I V4L2 FIELD BOTTOM 3 Images consist of the bottom field only Applications may wish to prevent a device from capturing interlaced images because they will have comb or feathering artefacts around moving objects VA4L2 FIELD INTERLA
96. to by the controls fields To get the current value of a set of controls applications initialize the id field of each struct v412_ext_control and call the VIDIOC_G_EXT_CTRLS ioctl To change the value of a set of controls applications initialize the id and value fields of a struct v412_ext_control and call the VIDIOC_S_EXT_CTRLS ioctl The controls will only be set if all control values are valid To check if the a set of controls have correct values applications initialize the id and value fields of a struct v412_ext_control and call the VIDIOC_TRY_EXT_CTRLS ioctl It is up to the driver whether wrong values are automatically adjusted to a valid value or if an error is returned When the idor ctrl classis invalid drivers return an EINVAL error code When the value is out of bounds drivers can choose to take the closest valid value or return an ERANGE error code whatever seems more appropriate In the first case the new value is set in struct v412 ext control 132 ioctl VIDIOC G EXT CTRLS VIDIOC S EXT CTRLS VIDIOC TRY EXT CTRLS The driver will only set get these controls if all control values are correct This prevents the situation where only some of the controls were set get Only low level errors e g a failed i2c command can still cause this situation Table 1 struct v412 ext control u32 id u32 reserved2 2 union anonymous s32 S64 void Table 2 struct v4l2 ext controls u32
97. v412 ex u32 u32 union __attribute__ struct v412 ex N32 MSZ u32 u32 struct hi Values for define VA4L2 IN Appendix A Video For Linux Two Header File ST NO SYNC 0x00010000 ST NO EQU 0x00020000 ST NO CARRIER 0x00040000 us VCR and set top box x N ST MACROVISION 0x01000000 N ST NO ACCESS 0x02000000 ST VTR 0x04000000 EGO OUTPUT tput index name 32 type audioset modulator td id std reserved 4 the type field UTPUT TYPE MODULATOR UTPUT TYPE ANALOG UTPUT TYPE ANALOGVGAOVERLAY T OG X 55 ntrol id value t control ids reserved2 2 S32 value S64 value64 void xreserved packed t controls ctrl class count error idx reserved 2 v412 ext control xcontrols ctrl class field No synchronization lock x No equalizer lock x Carrier recovery failed Macrovision detected x Conditional access denied x VTR time constant Which output Label x Type of output Associated audios bitfield Associated modulator 238 define define define define define define v4 v4 v4 v4 v4 v4 2 CTRL C 2 CTRL C ASS MP 2 CTRL C ASS CAI L2 CTRL ID MASK 2 CTRL ID2C ASS i 2 CTRL DRIVER Used in the VIDIO
98. v4I2 rect c UP E_PRIVATE and higher Cropping rectangle The same co ordinate system as for struct v412_cropcap bounds is used Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL Cropping is not supported 127 ioctl VIDIOC G CTRL VIDIOC S CTRL Name VIDIOC G CTRL VIDIOC S CTRL Get or set the value of a control Synopsis int ioctl int fd int request struct v412 control xargp Arguments fd File descriptor returned by open request VIDIOC G CTRL VIDIOC 5 CTRL argp Description To get the current value of a control applications initialize the id field of a struct v4l2 control and call the vIDIOC G CTRL ioctl with a pointer to this structure To change the value of a control applications initialize the id and value fields of a struct v412 control and call the vIDIOC S CTRL ioctl When the id is invalid drivers return an EINVAL error code When the value is out of bounds drivers can choose to take the closest valid value or return an ERANGE error code whatever seems more appropriate However VIDIOC_S_CTRL is a write only ioctl it does not return the actual new value These ioctls work only with user controls For other control classes the VIDIOC_G_EXT_CTRLS VIDIOC_S_EXT_CTRLS or VIDIOC_TRY_EXT_CTRLS must be used Table 1 struct v412_ control u32 id Identifies the control set by the application 832 val
99. with lower values oriented towards the black level Do not assume any other correlation of values with the signal level For example the MSB does not necessarily indicate if the signal is high or low because 128 may not be the mean value of the signal Drivers shall not convert the sample format by software This is the scanning system line number associated with the first line of the VBI image of the first and the second field respectively See Figure 4 2 and Figure 4 3 for valid values VBI input drivers can return start values 0 if the hardware cannot reliable identify scanning lines VBI acquisition may not require this information The number of lines in the first and second field image respectively See Table 4 5 below Currently only drivers set flags applications must set this field to zero This array is reserved for future extensions Drivers and applications must set it to zero 76 V4L2 VBI UNSYNC VAL2 VBI INTERLACE 0x0001 0x0002 Chapter 4 Interfaces This flag indicates hardware which does not properly distinguish between fields Normally the VBI image stores the first field lower scanning line numbers first in memory This may be a top or bottom field depending on the video standard When this flag is set the first or second field may be stored first however the fields are still in correct temporal order with the older field first in memory a By default the two field images w
100. x2 y2 with width x2 x1 and height y2 y1 so one cannot pass X11 clip lists directly 3 ASK Amplitude Shift Keying A high signal level represents a 1 bit a low level a 0 bit 86 I Function Reference Table of Contents M bTI E 89 Mb eens 90 rei BA DI 61638 CROR CAP n 92 ioctl VIDIOC DBG G REGISTER VIDIOC DBG S REGISTER eere eee eene 94 ioctl VIDIOC ENCODER CMD VIDIOC TRY ENCODER CMD e c eeee eene ee enenne 97 ioctl VIDIOC ENUMAUDJO ees eae eno rana ore euo cao na get ev baeo eS eo eS oi raa ba Sa ue Sos UE ae eS e Te VR Vel Tae En nae enE 99 ioctl VIDIOC ENUMAUDOUD aivcsscssnsscsssdsssosnecassssescesesetcsvetseossceasesspaseascuetsensssosssecccssasevscscesveonss 100 ioctl VIDIOC ENUM FM Ditssacscsssccccssassosssdoasosnacastssesceesesesesvetseossteasesssadeascuetsonsssesssectessasevscsinstesnss 101 ioctl VIDIOC ENUM FRAMESILZES e eeeee eerte een etes tn setae tasas tone tas tte sets to etas en seas etos etes pasa 103 ioctl VIDIOC G AUDIO VIDIOC S AUDIO eee ee esee en nete seen eene enata seen sens tn sete sen seinen 119 ioctl VIDIOC G AUDOUT VIDIOC S AUDOJUT eee eee ee eee teens en etn etn ea en seno tn sete ense tuc 121 ioctl VIDIOC G CHIP IDENT sssceccssscceselaccssdenscsseecesceceacac
101. 1 For the purpose of this specification field 2 starts in line 264 and not 263 5 because half line capturing is not supported 79 Figure 4 3 ITU R 625 line numbering 621 308 309 309 622 309 310 310 Chapter 4 Interfaces 0 623 624 625 2 3 4 5 6 7 8 22 310 311 312 2 3 4 5 6 7 8 22 1st field 311 312 313 4 315 316 317 318 319 320 321 335 311 312 313 2 3 4 5 6 T 8 22 1 2nd field Chapter 4 Interfaces 1 For the purpose of this specification field 2 starts in line 314 and not 313 5 because half line capturing is not supported Remember the VBI image format depends on the selected video standard therefore the application must choose a new standard or query the current standard first Attempts to read or write data ahead of format negotiation or after switching the video standard which may invalidate the negotiated VBI parameters should be refused by the driver A format change during active I O is not permitted 4 7 4 Reading and writing VBI images To assure synchronization with the field number and easier implementation the smallest unit of data passed at a time is one frame consisting of two fields of VBI images immediately following in memory The total size of a frame computes as follows count 0 count 1 x samples per line sample size in bytes The sample size is most likely always one byte applications must check the sa
102. 16 bits for example 10 bits per pixel with values in range 0 to 1023 Example 2 1 VAL2 PIX FMT SBGGR16 4 x 4 pixel image Byte Order Each cell is one byte start 4 0 Bootow start 8 Giolow start 16 Bootow start 4 24 Ga30low Boonigh G10high Boonigh G30high Gottow Ritlow Gattow R3tlow Gothigh Rithigh Goihigh R3thigh 38 Boziow Bozhigh Gostow Giatow G12high Ri3iow B22Iow B22high G231ow G321ow G32high R3310w 2 5 YUV Formats YUV is the format native to TV broadcast and composite video signals It separates the brightness information Y from the color information U and V or Cb and Cr The color information consists of red and blue color difference signals this way the green component can be reconstructed by subtracting from the brightness component See Section 2 2 for conversion examples YUV was chosen because early television would only transmit brightness information To add color in a way compatible with existing receivers a new signal carrier was added to transmit the color difference signals Secondary in the YUV format the U and V components usually have lower resolution than the Y component This is an analog video compression technique taking advantage of a property of the human visual system being more sensitive to brightness information Packed YUV formats Name Packed YUV formats Packed YUV formats Description Similar to the packed RGB formats these formats store the Y Cb and
103. 2 Changes of the V4L2 API Soon after the VAL API was added to the kernel it was criticised as too inflexible In August 1998 Bill Dirks proposed a number of improvements and began to work on documentation example drivers and applications With the help of other volunteers this eventually became the VAL2 API not just an extension but a replacement for the VAL API However it took another four years and two stable kernel releases until the new API was finally accepted for inclusion into the kernel in its present form 6 2 1 Early Versions 1998 08 20 First version 1998 08 27 The select function was introduced 1998 09 10 New video standard interface 1998 09 18 The VIDIOC_NONCAP ioctl was replaced by the otherwise meaningless O_TRUNC open flag and the aliases o NONCAP and o NOIO were defined Applications can set this flag if they intend to access controls only as opposed to capture applications which need exclusive access The VIDEO_STD_Xxx identifiers are now ordinals instead of flags and the video_std_construct helper function takes id and transmission arguments 1998 09 28 Revamped video standard Made video controls individually enumerable 1998 10 02 The id field was removed from struct video_standard and the color subcarrier fields were renamed The VIDIOC_QUERYSTD ioctl was renamed to VIDIOC_ENUMSTD VIDIOC_G_INPUT to VIDIOC_ENUMINPUT A first draft of the Codec API was released 1998 11 08 Many mino
104. 2 crop The decimation field was dropped In the V4L2 API the scaling factor is implied by the size of the cropping rectangle and the size of the captured or overlaid image The VIDEO CAPTURE ODD and VIDEO CAPTURE EVEN flags to capture only the odd or even field respectively were replaced by v4L2 FIELD TOP and V4L2 FIELD BOTTOM in the field named field of struct v4 2 pix format and struct v412 window These structures are used to select a capture or overlay format with the VIDIOC S FMT ioctl 6 1 9 Reading Images Memory Mapping 6 1 9 1 Capturing using the read method There is no essential difference between reading images from a VAL or V4L2 device using the read function however V4L2 drivers are not required to support this I O method Applications can determine if the function is available with the VIDIOC_QUERYCAP ioctl All V4L2 devices exchanging data with applications must support the select and po11 functions To select an image format and size VAL provides the VIDIOCSPICT and VIDIOCSWIN ioctls V4L2 uses the general purpose data format negotiation ioctls vVIDIOC G FMT and VIDIOC S FMT They take a pointer to a struct v412 format as argument here the struct v412 pix format named pix of its fmt union is used For more information about the V4L2 read interface see Section 3 1 6 1 9 2 Capturing using memory mapping Applications can read from VAL devices by mapping buffers in device
105. 2 CTRL TYPE MENU enumerate menu else if errno EINVAL break perror VIDIOC_QUERYCTRL exit EXIT FAILURE Example 1 9 Changing controls struct v412 queryctrl queryctrl Struct v4l2 control control memset amp queryctrl 0 sizeof queryctrl queryctrl id V4L2_CID_BRIGHTNESS if 1 ioctl fd VIDIOC QUERYCTRL amp queryctrl if errno EINVAL perror VIDIOC_QUERYCTRL exit EXIT_FAILURE else printf V4L2_CID_BRIGHTNESS is not supported n 13 Chapter 1 Common API Elements else if queryctrl flags amp V4L2_CTRL_FLAG_DISABLED printf V4L2_CID_BRIGHTNESS is not supported n else memset amp control 0 sizeof control control id V4L2_CID_BRIGHTNESS control value queryctrl default_value if 1 ioctl fd VIDIOC S CTRL amp control perror VIDIOC S CTRL exit EXIT FAILURE memset amp control 0 sizeof control control id V4L2 CID CONTRAST if 0 ioctl fd VIDIOC G CTRL amp control control value 1 The driver may clamp the value or return ERANGE ignored here x if 1 ioctl fd VIDIOC S CTRL amp control amp amp errno ERANGE perror VIDIOC_S_CTRL exit EXIT_FAILURE Ignore if V4L2_CID_CONTRAST is unsupported x else if errno EINVAL perror VIDIOC G CTRL exit EXIT FAILURE
106. 2 PIX FMT YUVA10 YUVO 46 VAL2 PIX FMT YUVA422P 422P cessere eene nennen rene enne 47 V4E2 PIX FMT YUVA P ATTP y iniret nee ttes 48 VAL2 PIX FMT NVI2 NV12 V4AL2 PIX FMT NV21 CNV21 woe 49 2 6 Compressed Formats eir e ORDER Or pea eterni 50 2 7 Reserved Format Identifiers isinin nesnese ee TE E Ere ETE E enne nennen nene 50 3 Input Output aeii oiia in EEE AAEREN EEEE EEE OAE E 51 3 Read Wnte uU HU RR ERE RR URS 51 32 Streaming I O Memory Mapping essent enne nennen 51 3 3 Streaming I O User Pointers cinniri eret tee I CREER Eee Here en 54 3 4 Asynchronous W O oreet ee t be PO ORE heiter 55 3 5 B ffers aiite ete em Ret uM 55 3 5 T Imiecodes neat d ore ge eet drei 59 3 6 Field Order ntt o et e pere en ric I ee 60 4 Interfaces 66 4 1 Video Capture Interface oeste n Deere cr eb ESEE AR E EEEE 66 4 1 1 Querying Capabilities 5 rne ett dre pee the eres 66 4 1 2 Supplemental Functions eeseseeseeeeeeeeeree eren enne enne nre 66 4 1 3 Image Format Negotiation eren ennen entren enne nene 66 4 T4 Reading Images eret iet eet ees 67 4 2 Video Overlay Interface 3 tiet rie ea tee E reser pp ie 67 4 2 1 Querying Capabilities ee eene eee mre tet 67 4 2 2 Supplemental Functions reote pie qtiae e tiep tes 67 CUIUS 67 4 2 4 Overlay Window nein pt deepe
107. 2 VBI x u32 reserved 2 must be zero x H 246 VBI flags x define V4L2_VBI_UNSYNC define V4L2_VBI_INTERLAC ED Sliced VBI struct v412 sliced vbi format 21 6 service lines Service set OT escas T Pasa service lines u16 service lines 2 u32 io size u32 reserved 2 Appendix A Video For Linux Two Header File 1 0 1 1 This implements is a proposal V4L2 API to allow SLICED VBI required for some hardware encoders It should change without notice in the definitive implementation 1 23 used of the first field 1 23 used of the second field equals frame lines 313 336 for 625 line video 263 286 for 525 line standards Specifies lines 0 23 Specifies lines 0 23 standards 24 must be zero x Teletext World System Teletext WST defined on ITU R BT 653 2 x define V4L2 SLICED TELETEXT B 0x0001 Video Program System defined on ETS 300 231x define VA4L2 SLICED VPS 0x0400 Closed Caption defined on EIA 608 define V4L2 SLICED CAPTION 525 0x1000 Wide Screen System defined on ITU R BT1119 1 define VA4L2 SLICED WSS 625 0x4000 define V4L2_SLICED VBI 525 VAL2 SLICED CAPTION 525 define V4L2 SLICED VBI 625 VAL2 SLICED TELETEXT B V4L2 SLICED VPS V4L2 struct v412 sliced v
108. 21 ioctl VIDIOC G AUDOUT VIDIOC S AUDOUT u8 name 32 Name of the audio output a NUL terminated ASCII string for example Line Out This information is intended for the user preferably the connector label on the device itself u32 capability Audio capability flags none defined yet Drivers must set this field to zero u32 mode Audio mode none defined yet Drivers and applications on VIDIOC S AUDOUT must set this field to zero u32 reserved 2 Reserved for future extensions Drivers and applications must set the array to zero Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL No audio outputs combine with the current video output or the number of the selected audio output is out of bounds or it does not combine or there are no audio outputs at all and the ioctl is not supported EBUSY I O is in progress the output cannot be switched 122 ioctl VIDIOC G CHIP IDENT Name VIDIOC G CHIP IDENT Identify the chips on a TV card Synopsis int ioctl int fd int request struct v412 chip ident xargp Arguments fd File descriptor returned by open request VIDIOC G CHIP IDENT argp Description Experimental This is an experimental interface and may change in the future For driver debugging purposes this ioctl allows test applications to query the driver about the chips present on the TV card Regular applications should n
109. 300 294 msb lsb msb Bit 7678 43 2 1 0 xx 1 V4L2_SLICED_VBI_5230x1000 Set of services applicable to 525 line systems V4L2_SLICED_VBI_ 6210x4401 Set of services applicable to 625 line systems Drivers may return an EINVAL error code when applications attempt to read or write data without prior format negotiation after switching the video standard which may invalidate the negotiated VBI parameters and after switching the video input which may change the video standard as a side effect The VIDIOC_S_FMT ioctl may return an EBUSY error code when applications attempt to change the format while i o is in progress between a VIDIOC_STREAMON and VIDIOC_STREAMOFF call and after the first read or write call 4 8 4 Reading and writing sliced VBI data A single read or write call must pass all data belonging to one video frame That is an array of v412_sliced_vbi_data structures with one or more elements and a total size not exceeding io size bytes Likewise in streaming I O mode one buffer of io size bytes must contain data of one video frame The id of unused v412_sliced_vbi_data elements must be zero 83 Chapter 4 Interfaces Table 4 8 struct v4l12 sliced vbi data u32 id A flag from Table 2 identifying the type of data in this packet Only a single bit must be set When the id of a captured packet is zero the packet is empty and the contents of other fields are undefined Applications shall ignore empty pac
110. 4L2 BUF TYPE VBI CAPTURE 4 VA4L2 BUF TYPE VBI OUTPUT 5 V4L2 BUF TYPE SLICED VBI CAP URE V4L2 BUF TYPE SLICED VBI OUTPUT V4L2 BU E VIDEO OUTPUT OSERLAY Hj K U V4L2 BU Hj K U PE_PRIVATE 0x80 Table 3 3 Buffer Flags V4L2_BUF_FLAG_MAPPED 0x0001 Chapter 3 Input Output Some video capture drivers support rapid and synchronous video input changes a function useful for example in video surveillance applications For this purpose applications set the V4L2_BUF_FLAG_INPUT flag and this field to the number of a video input as in struct v412_input field index A place holder for future extensions and custom driver defined buffer types VAL2 BUF TYPE PRIVATE and higher Buffer of a video capture stream see Section 4 1 Buffer of a video output stream see Section 4 3 Buffer for video overlay see Section 4 2 Buffer of a raw VBI capture stream see Section 4 7 Buffer of a raw VBI output stream see Section 4 7 Buffer of a sliced VBI capture stream see Section 4 8 Buffer of a sliced VBI output stream see Section 4 8 Buffer for video output overlay OSD see Section 4 4 Status Experimental This and higher values are reserved for custom driver defined buffer types The buffer resides in device memory and has been mapped into the application s address space see Section 3 2 for details Drivers set or clear this
111. A VAL2 codec can compress decompress transform or otherwise convert video data from one format into another format in memory Applications send data to be converted to the driver through a write call and receive the converted data through a read call For efficiency a driver may also support streaming I O to do 4 6 Effect Devices Interface Suspended This interface has been be suspended from the V4L2 API implemented in Linux 2 6 until we have more experience with effect device interfaces A VAL2 video effect device can do image effects filtering or combine two or more images or image streams For example video transitions or wipes Applications send data to be processed and receive the result data either with read and write functions or through the streaming I O mechanism to do 4 7 Raw VBI Data Interface VBl is an abbreviation of Vertical Blanking Interval a gap in the sequence of lines of an analog video signal During VBI no picture information is transmitted allowing some time while the electron beam of a cathode ray tube TV returns to the top of the screen Using an oscilloscope you will find here the vertical synchronization pulses and short data packages ASK modulated onto the video signal These are transmissions of services such as Teletext or Closed Caption 74 Chapter 4 Interfaces Subject of this interface type is raw VBI data as sampled off a video signal or to be added to a signal for output
112. AL2 FBUF FLAG OVERLAY was never quite clear Most drivers see VAL2 FBUF FLAG CHROMAKEY 0x0004 Use chroma keying The chroma key color is determined by the chromakey field of struct v412_window and negotiated with the VIDIOC S FMT ioctl see Section 4 2 and Section 4 4 There are no flags to enable clipping using a list of clip rectangles or a bitmap These methods are negotiated with the 5 V4L2 FBUF FLAG LOCAL ALPHA 0x0008 Use the alpha channel of the framebuffer to clip or blend framebuffer pixels with video images The blend function is output framebuffer pixel alpha video pixel 1 alpha The actual alpha depth depends on the framebuffer pixel format 138 VAL2 FBUF FLAG GLOBAL ALPHA 0x0010 VAL2 FBUF FLAG LOCAL INV ALP x0020 Return Value ioctl VIDIOC G FBUF VIDIOC S FBUF Use a global alpha value to blend the framebuffer with video images The blend function is output framebuffer pixel alpha video pixel 255 alpha 255 The alpha value is determined by the g21obal alpha field of struct v412 window and negotiated with the VIDIOC_S_FMT ioctl see Section 4 2 and Section 4 4 Like V4L2 FBUF FLAG LOCAL ALPHA use the alpha channel of the framebuffer to clip or blend framebuffer pixels with video images but with an inverted alpha value The blend function is output framebuffer pixel 1 alpha video pixel alpha The actual alpha depth depends on the framebu
113. AP LOCAL ALPHA 0x0010 FBUF CAP GLOBAL ALPHA 0x0020 FBUF CAP LOCAL_INV_ALPHAx0040 Table 3 Frame Buffer Flags V4L2_FBUF_FI V4L2_FBUF_F LAG PRIMARY 0x0001 AG_OVERLAY 0x0002 ioctl VIDIOC_G_FBUF VIDIOC_S_FBUF The device is capable of non destructive overlays When the driver clears this flag only destructive overlays are supported There are no drivers yet which support both destructive and non destructive overlays The device supports clipping by chroma keying the images That is image pixels replace pixels in the VGA or video signal only where the latter assume a certain color Chroma keying makes no sense for destructive overlays The device supports clipping using a list of clip rectangles The device supports clipping using a bit mask The device supports clipping blending using the alpha channel of the framebuffer or VGA signal Alpha blending makes no sense for destructive overlays The device supports alpha blending using a global alpha value Alpha blending makes no sense for destructive overlays The device supports clipping blending using the inverted alpha channel of the framebuffer or VGA signal Alpha blending makes no sense for destructive overlays The framebuffer is the primary graphics surface In other words the overlay is destructive The frame buffer is an overlay surface the same size as the capture The purpose of VAL2 FBUF FLAG PRIMARY and V
114. All drivers implementing the read or write function or streaming I O must also support the select function For more details see the select manual page Return Value On success select returns the number of descriptors contained in the three returned descriptor sets which will be zero if the timeout expired On error 1 is returned and the errno variable is set appropriately the sets and t imeout are undefined Possible error codes are 197 EBADF One or more of the file descriptor sets specified a file descriptor that is not open EBUSY V4L2 select The driver does not support multiple read or write streams and the device is already in use EFAULT The readfds writefds except fds or timeout pointer references an inaccessible memory area EINTR The call was interrupted by a signal EINVAL The nfds argument is less than zero or greater than FD_S ETSIZE 198 Notes 1 The Linux kernel implements select like the poll function but select cannot return a POLLERR V4L2 write Name v412 write Write to a VAL2 device Synopsis include lt unistd h gt Ssize t write int fd void buf size t count Arguments fd File descriptor returned by open buf count Description write writes up to count bytes to the device referenced by the file descriptor fd from the buffer starting at buf When the hardware outputs are not active yet this function
115. B formats Name Packed RGB formats Packed RGB formats Description These formats are designed to match the pixel formats of typical PC graphics frame buffers They occupy 8 16 24 or 32 bits per pixel These are all packed pixel formats meaning all the data for a pixel lie next to each other in memory When one of these formats is used drivers shall report the colorspace V4L2 COLORSPACE SRGB Table 2 1 Packed RGB Image Formats Identifi amp yte 0 in memory Byte 1 Byte 2 Byte 3 Code 76543210 76543210 76543210 76543210 Bit VAL2 PbxbrMTgRGB 22 ro RGBI VAL2 PgXgrMTgRbBb4bibo a aza ao r3 r2 ri ro R444 VAL2 PEXgFMTIRGB 5 ro a b4 bs b2b bo ga gs RGBO VAL2 PEXgFMTIRGBS 5 ro b4 b3 b2 bi bo gs g4 g3 RGBP VAL2 PIxXxbrhrbmbBb5gxgs gogigora r3 r2 r ro RGBQ VAL2 PbxbrhrbnbBg6gXgs gogigora r3 r2 r ro RGBR VAL2 PbxbrhrbsbmRb4bibo g7 Go gs g4 g3 g2 g go 17 To r5 r4 r3 r2 ri ro BGR3 34 Packed RGB formats Identifi amp yte 0 in memory Byte 1 Byte 2 Byte 3 Code 76543210 76543210 76543210 76543210 Bit V4L2_PIKI MTLREBTAT ro g7g6g5g2g3g2gigo _b7 bo bs b4 b3 bz bi bo RGB3 VAL2 PbxbrhrbsbRb2bibo g7 g6 gs g4 g3 g2 g go r7 re rs r4 r3 r2 r ro a7 Ao AS a a aza ao BGR4A VAL2 PIXIMSIRGB 2T ro g7 g6 gs g4 g3 g2gi go brbebsbabsbobibo az ao as a as a2 al ao RGB4 Bit 7 is the most significant bit The value of a alpha bits is undefined when reading
116. BUF CAP LIST CLIPPING and V4L2 FBUF CAP BITMAP CLIPPING In struct v412 clip the x y width and height field moved into a c substructure of type struct v412 rect The x and y fields were renamed to left and top i e offsets to a context dependent origin In struct v412 window the x y width and height field moved into a w substructure as above A field field of type v412 field was added to distinguish between field and frame interlaced overlay The digital zoom interface including struct v412_zoomcap struct v412 zoom VAL2 ZOOM NONCAP and V4L2 ZOOM WHILESTREAMING was replaced by a new cropping and scaling interface The previously unused struct v412_cropcap and v412 crop where redefined for this purpose See Section 1 11 for details In struct v4l2 vbi format the SAMPLE FORMAT field now contains a four character code as used to identify video image formats and vVAL2 PIX FMT GREY replaces the VAL2 VBI SF UBYTE define The reserved field was extended In struct v412 captureparm the type of the timeperframe field changed from unsigned long to struct v412 fract This allows the accurate expression of multiples of the NTSC M frame rate 30000 1001 A new field readbuffers was added to control the driver behaviour in read I O mode Similar changes were made to struct v412_outputparm The struct v412 performance and vIDIOC G PERF ioctl were dropped Except when using the read writ
117. C QU struct v412 queryctrl HH u32 enum v412 ctrl type u8 s32 s32 s32 s32 u32 u32 Used in the VIDIOC_QU PRIV id ASS USER 0x00980000 x Old style user EG 0x00990000 MPEG compression controls x ERA 0x009a0000 Appendix A Video For Linux Two Header File controls Camera class controls OxOfffffff d id type name 32 minimum maximum step id id amp OxOfff0000UL amp Oxffff gt 0x1000 ERYCTRL ioctl for querying controls x Whatever x Note signedness default value flags reserved 2 ERYM struct v412 querymenu ENU ioctl for querying menu items x 2 Las 32 index us name 32 Whatever x u32 reserved Control flags define V4L2 CTRL FLAG DISABLED 0x0001 define V4L2 CTRL FLAG GRABBED 0x0002 define V4L2 CTRL FLAG READ ONLY 0x0004 define V4L2 CTRL FLAG UPDATE 0x0008 define V4L2 CTRL FLAG INACTIVE 0x0010 define V4L2 CTRL FLAG SLIDER 0x0020 Query flag to be ORed with the control ID x define VA4L2 CTRL FLAG NEXT CTRL 0x80000000 User class control IDs defined by V4L2 define V4L2 CID BASE VAL2 CTRL CLASS USER 0x900 define V4L2 CID USER BASE VA4L2 CID BASE IDs reserved for driver specific contr
118. CED 4 Images contain both fields interleaved line by line The temporal order of the fields whether the top or bottom field is first transmitted depends on the current video standard M NTSC transmits the bottom field first all other standards the top field first 61 V4L2 FIELD TB VAL2 FIE VAL2 FI ELD ALT ERNATE ERLACE VAL2 FI ELD INT Dis TB VAL2 FI ELD INT ERLACE BT Chapter 3 Input Output Images contain both fields the top field lines are stored first in memory immediately followed by the bottom field lines Fields are always stored in temporal order the older one first in memory Image sizes refer to the frame not fields Images contain both fields the bottom field lines are stored first in memory immediately followed by the top field lines Fields are always stored in temporal order the older one first in memory Image sizes refer to the frame not fields The two fields of a frame are passed in separate buffers in temporal order i e the older one first To indicate the field parity whether the current field is a top or bottom field the driver or application depending on data direction must set struct v4I2 buffer field to VAL2 FIELD TOP or V4L2 FIELD BOTTOM Any two successive fields pair to build a frame If fields are successive without any dropped fields between them fields can drop
119. Chapter 6 Changes struct video capability type struct v4l2 capability Purpose capabilities flags IVID TYPE SUBCAPTUR Al Applications can call the VIDIOC G CROP ioctl to determine if the device supports capturing a subsection of the full picture cropping in V4L2 If not the ioctl returns the EINVAL error code For more information on cropping and scaling see Section 1 11 VID_TYPE_MPEG_DECODER Applications can enumerate the supported image formats with the IVIDIOC ENUM FMT ioctl to determine if the device supports IMPEG streams VID TYPE MPEG ENCODER See above VID TYPE MJPEG DECODER See above VID TYPE MJPEG ENCODER See above The audios field was replaced by capabilities flag V4AL2 CAP AUDIO indicating if the device has any audio inputs or outputs To determine their number applications can enumerate audio inputs with the VIDIOC G AUDIO ioctl The audio ioctls are described in Section 1 5 The maxwidth maxheight minwidth and minheight fields were removed Calling the VIDIOC S FMT or VIDIOC TRY FMT ioctl with the desired dimensions returns the closest size possible taking into account the current video standard cropping and scaling limitations 6 1 3 Video Sources VAL provides the VIDIOCGCHAN and VIDIOCSCHAN ioctl using struct video channel to enumerate the video inputs of a VAL device The equival
120. Cr component of each pixel in one 16 or 32 bit word Table 2 1 Packed YUV Image Formats Identifi amp yte 0 in memory Byte 1 Byte 2 Byte 3 Code 76543210 76543210 76543210 76543210 Bit VAL2 PIX FMT YUVA444 a3 a2 al ao YA44b b bCberCrCr Cro Y Y X Y o VAL2 PIX FMT YUV555 a YUNOCbCberCrCrCrCro Y Y Y Y Y Cb bs VA4L2 PIX FMT YUV565 YUNBXbCberCrCrCrCro YA Y X Y Cbebcbs VA4L2 P XasHsravu va ai ao Cro YUVE YXA X Y X YX NY 0 Cb b be bCbe be bCbo CrCrCrCrCrCrCri Bit 7 is the most significant bit The value of a alpha bits is undefined when reading from the driver ignored when writing to the driver except when alpha blending has been negotiated for a Video Overlay or Video Output Overlay 39 VAL2 PIX FMT GREY GREY Name V4L2 PIX FMT GREY Grey scale image Description This is a grey scale image It is really a degenerate Y CbCr format which simply contains no Cb or Cr data Example 2 1 VAL2 PIX FMT GREY 4 x 4 pixel image Byte Order Each cell is one byte start 0 start 4 start 8 start 12 Y oo Y io Y 20 Y 3o Yo Yu Y n Y s Y o Yn Y 2 Y o Y o YB Y s Y a 40 VA4L2 PIX FMT Y16 Y16 Name V4L2 PIX FMT Y16 Grey scale image Description This is a grey scale image with a depth of 16 bits per pixel The least significant byte is stored at lower memory addresses little endian Note the actual sampling precisi
121. DEO OUTPUT OVERLAY 0x00000200 Can do video output overlay define V4L2 CAP TUNER 0x00010000 has a tuner define V4L2 CAP AUDIO 0x00020000 has audio support define V4L2 CAP RADIO 0x00040000 is a radio device x define V4L2 CAP READWRITE 0x01000000 x read write systemcalls define V4L2_CAP_ASYNCIO 0x02000000 async I O define V4L2_CAP_STREAMING 0x04000000 x streaming I O ioctls VIDEO IMAGE FORMA T x struct v412 pix format u32 u32 u32 enum v412 field 32 32 enum v412_colorspace u32 Pixel format define V4L2 PIX FMT RGB332 define VA4L2 PIX FMT RGB444 define VA4L2 PIX FMT RGB555 define VA4L2 PIX FMT RGB565 define VA4L2 PIX FMT RGB555X define V4L2 PIX FMT RGB565X define V4L2 PIX FMT BGR24 define V4L2 PIX FMT RGB24 define V4L2 PIX FMT BGR32 width height pixelformat field bytesperline Sizeimage colorspace priv FOURCC v4 v4 v4 L2 tource 12 fourcc 12 fourcc 12 fourcc 12 fourcc L2 fource 12 fourcc 12 fourcc R TREY ERE R R ng 12 fourcc 7 mar 1 G mar G mar G mar G for padding private data AT r 4 mar G mar G mar G mar G Bt UB B B CBC IR B CB 4 zero if unused depends on pixelformat depth Description 1
122. E DISCRETE by the driver Of the union only the discrete member is valid Step wise The function returns success if the given index value is zero and EINVAL for any other index value The v412_frmivalenum type field is set to VAL2 FRMIVAL TYPE STEPWISE by the driver Of the union only the stepwise member is valid Continuous This is a special case of the step wise type above The function returns success if the given index value is zero and EINVAL for any other index value The v4212 frmivalenum type field is set to vVAL2 FRMIVAL TYPE CONTINUOUS by the driver Of the union only the stepwise member is valid and the step value is set to 1 106 ioctl VIDIOC ENUM FRAMEINTERVALS When the application calls the function with index zero it must check the t ype field to determine the type of frame interval enumeration the device supports Only for the V4L2 FRMIVAL TYPE DISCRETE type does it make sense to increase the index value to receive more frame intervals Note that the order in which the frame intervals are returned has no special meaning In particular does it not say anything about potential default frame intervals Applications can assume that the enumeration data does not change without any interaction from the application itself This means that the enumeration data is consistent if the application does not perform any other ioctl calls while it runs the frame interval enumeration Notes
123. E TEMPERIHGSHIE V4L2 CID SHARPNESS integer V4L2_CID_BACKLIGHT_COMPENSATimieger V4L2_CID_LASTP1 V4L2_CID_PRIVATE_BASE Chapter 1 Common API Elements Description Enables automatic hue control by the device The effect of setting VAL2 CID HUE while automatic hue control is enabled is undefined drivers should ignore such request This control specifies the white balance settings as a color temperature in Kelvin A driver should have a minimum of 2800 incandescent to 6500 daylight For more information about color temperature see Wikipedia http en wikipedia org wiki Color temperature Adjusts the sharpness filters in a camera The minimum value disables the filters higher values give a sharper picture Adjusts the backlight compensation in a camera The minimum value disables backlight compensation End of the predefined control IDs currently V4L2 CID BACKLIGHT COMPENSATION 1 ID of the first custom driver specific control Applications depending on particular custom controls should check the driver name and version see Section 1 2 Applications can enumerate the available controls with the VIDIOC_QUERYCTRL and VIDIOC_QUERYMENU ioctls get and set a control value with the VIDIOC_G_CTRL and VIDIOC S CTRL ioctls Drivers must implement VIDIOC QUERYCTRL VIDIOC G CTRL and VIDIOC S CTRL when the device has one or more controls VIDIOC QUERYMENU when it has one
124. E VIDEO OVERLAY and call the VIDIOC_G_FMT ioctl The driver fills the v412 window substructure named win It is not possible to retrieve a previously programmed clipping list or bitmap To program the overlay window applications set the t ype field of a struct v4I2 format to VA4L2 BUF TYPE VIDEO OVERLAY initialize the win substructure and call the VIDIOC S FMT ioctl The driver adjusts the parameters against hardware limits and returns the actual parameters as VIDIOC G FMT does Like VIDIOC_S_FMT the VIDIOC TRY FMT ioctl can be used to learn about 68 Chapter 4 Interfaces driver capabilities without actually changing driver state Unlike VIDIOC S FMT this also works after the overlay has been enabled The scaling factor of the overlaid image is implied by the width and height given in struct v412_window and the size of the cropping rectangle For more information see Section 1 11 When simultaneous capturing and overlay is supported and the hardware prohibits different image and window sizes the size requested first takes precedence The attempt to capture or overlay as well VIDIOC_S_FMT may fail with an EBUSY error code or return accordingly modified parameters Table 4 1 struct v4l2 window struct v412_ rect w enum v412_ field field u32 chromakey struct vAI2 clip clips Size and position of the window relative to the top left corner of the frame buffer defined with VIDIOC S FBUF
125. EO_TEMPORAL_FILTER_MODE_MANUAL 0 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO 1 define V4L2 CID MPEG CX2341X VIDEO TEMPORAL FILTER VAL2 CID MPEG CX2341X B define V4L2 CID MPEG CX2341X VIDEO MEDIAN FILTER TYPE VAL2 CID MPEG CX2341X B enum v4l12 mpeg cx2341x video median filter type VA4L2 MPEG CX2341X VIDEO MEDIAN FILTER TYPE OFF zu VA4L2 MPEG CX2341X VIDEO MEDIAN FILTER TYPE HOR E VA4L2 MPEG CX2341X VIDEO MEDIAN FILTER TYPE VERT 2 V4L2 MPEG CX2341X VIDEO MEDIAN FILTER TYPE HOR VERT 3 V4L2 MPEG CX2341X VIDEO MEDIAN FILTER TYPE DIAG 4 i define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM V4L2_CID_MPEG_CX2341X_B define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP V4L2_CID_MPEG_CX2341X_B define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM V4L2_CID_MPEG_CX2341X_B define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP V4L2_CID_MPEG_CX2341X_B define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS V4L2_CID_MPEG_CX2341X_B Camera class control IDs define V4L2 CID CAMERA CLASS BASE VAL2 CTRL CLASS CAMERA 0x900 define V4L2 CID CAMERA CLASS VAL2 CTRL CLASS CAMERA 1 define V4L2 CID EXPOSURE AUTO VAL2 CID CAMERA CLASS BASE 1 enum v412 exposure auto type V4L2 EXPOSURE AUTO 0 V4AL2 EXPOSURE MANUAL 1 V4L2 EXPOSURE SHUTTER PRIORITY 2 V4L2 EXPOSURE APERTURE PRIORITY 3 HH
126. G DECODER 1024 Can decode MPEG streams x define VID TYPE MPEG ENCODER 2048 Can encode MPEG streams define VID TYPE MJPEG DECODER 4096 Can decode MJPEG streams x define VID TYPE MJPEG ENCODER 8192 Can encode MJPEG streams M T1 S CHE LL A EOUS x Four character code FOURCC x define v412 fourcc a b c d N C 032 a lt lt 0 __u32 5 lt lt 8 __u32 0 lt lt 16 __u32 a lt lt 24 ENUMS x enum v412 field V4L2 FIELD ANY 0 driver can choose from none top bottom interlaced depending on whatever it thinks is approximate x VA4L2 FIELD NONE 1 x this device has no fields x VA4AL2 FIELD TOP 2 top field only V4L2 FIELD BOTTOM 3 bottom field only VAL2 FIELD INTERLACED 4 both fields interlaced VA4L2 FIELD SEQ TB 5 x both fields sequential into one buffer top bottom order x VA4L2 FIELD SEQ B 6 same as above bottom top order 226 VAL2 FIELD ALTERNATE 7 V4L2_FIELD_INTERLACED_TB 8 V4L2_FIELD_IN RLACED_BT 9 H Appendix A Video For Linux Two Header File both fields alternating into separate buffers x both fields interlaced top field first and the top field is transmitted first x both fields interlaced top field first and the bottom field is transmitted first
127. GAMMA V4L2_CID_BASE 16 define V4L2_CID_WHITENESS V4L2_CID_GAMMA Deprecated x define V4L2_CID_EXPOSURE V4L2_CID_BASE 17 define V4L2_CID_AUTOGAIN V4L2_CID_BASE 18 define V4L2_CID_GAIN V4L2_CID_BASE 19 define V4L2_CID_HFLIP V4L2_CID_BASE 20 define V4L2_CID_VFLIP V4L2_CID_BASE 21 Deprecated use V4L2_CID_PAN_RESET and V4L2_CID_TILT_RESET define V4L2_CID_HCENTER_DEPRECATED V4L2_CID_BASE 22 define V4L2_CID_VCENTER_DEPRECATED V4L2_CID_BASE 23 define V4L2_CID_POWER_LINE_FREQUENCY V4L2_CID_BASE 24 enum v412_power_line_frequency V4L2_CID_POWER_LINE_FREQUENCY_DISABLED 0 V4L2_CID_POWER_LINE_FREQUENCY_50HZ Say V4L2_CID_POWER_LINE_FREQUENCY_60HZ 2 i define V4L2_CID_HUE_AUTO V4L2_CID_BASE 25 define V4L2_CID_WHITE_BALANCE_TEMPERATURE V4L2_CID_BASE 26 define V4L2_CID_SHARPNESS V4L2_CID_BASE 27 define V4L2 CID BACKLIGHT COMPENSATION V4L2_CID_BASE 28 define V4L2_CID_LASTP1 V4L2_CID_BASE 29 x last CID 1 x MPEG class control IDs defined by V4L2 define V4L2 CID MPEG BASE VAL2 CTRL CLASS MPEG 0x900 define V4L2 CID MPEG CLASS VAL2 CTRL CLASS MPEG 1 MPEG streams define V4L2 CID MPEG STREAM TYPE V4L2_CID_MPEG_BASE 0 enum v412_mpeg_stream_type V4L2_MPEG_STREAM_TYPE_MPEG2_PS 0 MPEG 2 program stream V4L2_MPEG_STREAM_TYPE_MPEG2_TS 1 MPEG 2 transport stream V4L2 MPEG STREAM TYPE MPEGl1 SS 2 MPEG 1 system stream x VAL2 MPEG STREAM TYPE MPEG2 DVD 3 MPEG 2 DVD compati
128. HIP MATCH I2C ADDR 2 Match a chip by its 7 bit bC bus address Table 3 Chip Identifiers V4L2 IDENT NONE 0 No chip matched V4L2 IDENT AMBIGUOUS 1 Multiple chips matched V4L2 IDENT UNKNOWN 2 A chip is present at this address but the driver could not identify it Return Value On success 0 is returned on error 1 and the errno variable is set appropriately 124 ioctl VIDIOC G CHIP IDENT EINVAL The driver does not support this ioctl or the match type is invalid 125 ioctl VIDIOC G CROP VIDIOC S CROP Name VIDIOC G CROP VIDIOC S CROP Get or set the current cropping rectangle Synopsis int ioctl int fd int request struct v412 crop argp int ioctl int fd int request const struct v412 crop xargp Arguments fd File descriptor returned by open request VIDIOC G CROP VIDIOC 5 CROP argp Description To query the cropping rectangle size and position applications set the type field of a v412_crop structure to the respective buffer stream type and call the vzibroc G CROP ioctl with a pointer to this structure The driver fills the rest of the structure or returns the EINVAL error code if cropping is not supported To change the cropping rectangle applications initialize the t ype and struct v412 rect substructure named c of a v412 crop structure and call the vIDIOC S CROP ioctl with a pointer to this structure The driver first adjusts the requested dimensions agai
129. IDIOC ENUMINPUT Drivers can enumerate up to 32 video and audio inputs This field shows which audio inputs were selectable as audio source if this was the currently selected video input It is a bit mask The LSB corresponds to audio input 0 the MSB to input 31 Any number of bits can be set or none When the driver does not enumerate audio inputs no bits must be set Applications shall not interpret this as lack of audio support Some drivers automatically select audio sources and do not enumerate them since there is no choice anyway For details on audio inputs and how to select the current input see Section 1 5 Capture devices can have zero or more tuners RF demodulators When the type is set to V4L2 INPUT TYPE TUNER this is an RF connector and this field identifies the tuner It corresponds to struct v412 tuner field index For details on tuners see Section 1 6 Every video input supports one or more different video standards This field is a set of all supported standards For details on video standards and how to switch see Section 1 7 This field provides status information about the input See Table 3 for flags status is only valid when this is the current input Reserved for future extensions Drivers must set the array to zero This input uses a tuner RF demodulator Analog baseband input for example CVBS Composite Video S Video RGB VAL2 IN ST NO POWER VAL2 IN ST NO SIGNAL V4L2 IN ST
130. INVAL See ioctl VIDIOC G AUDIO VIDIOC S AUDIO 2 for a description of struct v412 audio Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The number of the audio input is out of bounds or there are no audio inputs at all and this ioctl is not supported 99 ioctl VIDIOC ENUMAUDOUT Name VIDIOC ENUMAUDOUT Enumerate audio outputs Synopsis int ioctl int fd int request struct v412 audioout xargp Arguments fd File descriptor returned by open request VIDIOC ENUMAUDOUT argp Description To query the attributes of an audio output applications initialize the index field and zero out the reserved array of a struct v412_audioout and call the VIDIOC_G_AUDOUT ioctl with a pointer to this structure Drivers fill the rest of the structure or return an EINVAL error code when the index is out of bounds To enumerate all audio outputs applications shall begin at index zero incrementing by one until the driver returns EINVAL Note connectors on a TV card to loop back the received audio signal to a sound card are not audio outputs in this sense See ioctl VIDIOC G AUDOUT VIDIOC_S_AUDOUT 2 for a description of struct v412_audioout Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The number of the audio output is out of bounds or there are no audio outputs at all and this ioctl is not
131. L TYPE MENU V4L2 CTRL TYPE BUTTO VA4L2 CTRL TYPE INTEGER64 V4L2 CTRL TYPE CTRL CLASS hi enum v412_tuner_type V4L2_TUNER_RADIO V4L2_TUNER_ANALOG_TV os NON No F WNP 227 VAL2 TUN HH enum v412 memory v4 VAL VAL iF see also h enum v412 colorspace V4 v4 V4 V4 x v4 v4 zj 1j 1j ER DIGITAL TV ORY MMAP ORY USERPTR ORY OVERLAY ttp vektor theorem ca graphics ycbcr ITU R 601 broadcast NTSC PAL x 2 COLORSPACE SMPTE170M 1 1125 Line US HDTV x 2 COLORSPACE SMPTE240M 2 HD and modern captures 2 COLORSPACE REC709 3 broken BT878 extents 601 luma range 16 253 instead of 16 235 2 COLORSPACE BT878 4 These should be useful Assume 601 extents 2 COLORSPACE 470 SYSTEM M 5 2 COLORSPACE 470 SYSTEM BG 6 I know there will be cameras that send this So Appendix A Video For Linux Two Header File 3 this is unspecified chromaticities and full 0 255 on each of the Y CbCr componen v4 V4 hi i2 ORSPACE CS EG LSCQ JP For RGB colourspaces 2 CO enum v412 priority v4 v4 v4 v4 v4 L2_PRIORI L2 PRIORI L2 PRIORI L2 PRIORI jORSPACE SRGB Y UNSET lr Y BACKGROUND Y INTERACTIVFE Y RECORD
132. L2 STD PAL Nc VAL2 STD NTSC VAL2 STD SECAM D VAL2 STD SECAM K VAL2 STD SECAM K1 VAL2 STD PAL DK VAL2 STD SECAM DK VAL2 STD SECAM B V4L2 STD SECA V4L2 STD SECAM H VAL2 STD SECAM DK V4L2 STD SECA i V4L2 STD SECA iC a a an an 116 ioctl VIDIOC ENUMSTD define V4L2 STD 525 60 VAL2 STD PAL M N VA4L2 STD PAL 60 N VA4L2 STD NTSC N V4L2 STD NTSC 443 define V4L2 STD 625 50 VAL2 STD PAL N VAL2 STD PAL N N V4L2 STD PAL Nc N VAL2 STD SECAM define VA4L2 STD UNKNOWN 0 define VA4L2 STD ALL VAL2 STD 525 60 IN VA4L2 STD 625 50 Table 4 Video Standards based on ITU BT 470 CharacteristicM PAL N PAL B B1 D D1 H PAL I PAL B D M NTSC G PAL K PAL G SECAWBECAM SEQASECAM Frame 525 lines Frame 1001 30000 period s Chrominance 4433618 75 5 Sub 3579545357961 1493618 75 4433618 75 carrier 10 10 3 1 fre 3582056 25 quency 5 Hz Nomina 6 6 6 B 7 8 8 8 8 8 8 8 radio B1 G frequendy 8 channel band width MHz Sound 45 4 55 4 5 5 5 65 5 5 55 65 65 65 carrier 0 001 0 001 5 9996 0 001 0 001 relative c d e f 0 0005 to vision carrier MHz Notes a Japan uses a standard similar to M NTSC VAL2 STD NTSC M JP b The values in brackets apply to 1 R
133. L2 TUNER SUB STEREO in field rxsubchans This field also permits the detection of monaural and bilingual audio see the definition of struct v412 tuner for details Presently no replacement exists for the VIDEO TUNER RDS ON and VIDEO TUNER MBS ON flags The VIDEO TUNER LOW flag was renamed to VAL2 TUNER CAP LOW in the struct v412 tuner capability field The VIDIOCGFREQ and VIDIOCSFREQ ioctl to change the tuner frequency where renamed to VIDIOC G FREQUENCY and VIDIOC S FREQUENCY They take a pointer to a struct v412_ frequency instead of an unsigned long integer 6 1 5 Image Properties V4L2 has no equivalent of the VIDIOCGPICT and VIDIOCSPICT ioctl and struct video picture The following fields where replaced by VAL2 controls accessible with the VIDIOC_QUERYCTRL VIDIOC G CTRL and VIDIOC S CTRL ioctls struct video picture V4L2 Control ID brightness V4L2_CID_BRIGHTNESS hue V4L2_CID_HUE colour VA4L2 CID SATURATION contrast VA4L2 CID CONTRAST whiteness VA4L2 CID WHITENESS 205 Chapter 6 Changes The V4L picture controls are assumed to range from 0 to 65535 with no particular reset value The V4L2 API permits arbitrary limits and defaults which can be queried with the VIDIOC_QUERYCTRL ioctl For general information about controls see Section 1 8 The depth average number of bits per pi
134. LAG TIMECODE flag is set in 1ags this structure contains a frame timecode In VAL2 FIELD ALTERNATE mode the top and bottom field contain the same timecode Timecodes are intended to help video editing and are typically recorded on video tapes but also embedded in compressed formats like MPEG This field is independent of the timestamp and sequence fields Set by the driver counting the frames in the sequence In VAL2 FIELD ALTERNATE mode the top and bottom field have the same sequence number The count starts at zer enum v4l2 memorymemory union m u32 unsigned long u32 length offset userptr This field must be set by applications and or drivers in accordance with the selected I O method When memory is VAL2 MEMORY MMAP this is the offset of the buffer from the start of the device memory The value is returned by the driver and apart of serving as parameter to the mmap function not useful for applications See Section 3 2 for details When memory is V4L2 MEMORY USERPTR this is a pointer to the buffer casted to unsigned long type in virtual memory set by the application See Section 3 3 for details Size of the buffer not the payload in bytes 57 u32 input u32 reserved Table 3 2 enum v4l2 buf type VAL2 BUF TYPE VIDEO CAPTURE 1 VA4L2 BUF TYPE VIDEO OUTPUT 2 VA4L2 BUF TYPE VIDEO OVERLAY 3 VA
135. O and were captured in the order dequeued from the outgoing FIFO The driver may require a minimum number of buffers enqueued at all times to function apart of this no limit exists on the number of buffers applications can enqueue in advance or dequeue and process They can also enqueue in a different order than buffers have been dequeued and the driver can fill enqueued empty buffers in any order The index number of a buffer struct v412 buffer index plays no role here it only identifies the buffer Initially all mapped buffers are in dequeued state inaccessible by the driver For capturing applications it is customary to first enqueue all mapped buffers then to start capturing and enter the read loop Here the application waits until a filled buffer can be dequeued and re enqueues the buffer when the data is no longer needed Output applications fill and enqueue buffers when enough buffers are stacked up the output is started with VIDIOC_STREAMON In the write loop when the application runs out of free buffers it must wait until an empty buffer can be dequeued and reused 53 Chapter 3 Input Output To enqueue and dequeue a buffer applications use the VIDIOC_QBUF and VIDIOC_DQBUF ioctl The status of a buffer being mapped enqueued full or empty can be determined at any time using the VIDIOC_QUERYBUF ioctl Two methods exist to suspend execution of the application until one or more buffers can be dequeued By default viproc poB
136. O ioctl and struct video audio are used to enumerate the audio inputs of a VAL device The equivalent V4L2 ioctls are vIDIOC G AUDIO and VIDIOC S AUDIO using struct v4 2 audio as discussed in Section 1 5 The audio channel number field counting audio inputs was renamed to index On VIDIOCSAUDIO the mode field selects one of the VIDEO SOUND MONO VIDEO SOUND STEREO VIDEO SOUND LANGI1 or VIDEO SOUND LANG2 audio demodulation modes When the current audio standard is BTSC vibEO SOUND LANG2 refers to SAP and VIDEO SOUND LANGI is meaningless Also undocumented in the VAL specification there is no way to query the selected mode On vIDIOCGAUDIO the driver returns the actually received audio programmes in this field In the VAL2 API this information is stored in the struct v4I2 tuner rxsubchans and audmode fields 206 Chapter 6 Changes respectively See Section 1 6 for more information on tuners Related to audio modes struct v412 audio also reports if this is a mono or stereo input regardless if the source is a tuner The following fields where replaced by V4L2 controls accessible with the VIDIOC_QUERYCTRL VIDIOC G CTRL and VIDIOC S CTRL ioctls struct video audio V4L2 Control ID volume V4L2 CID AUDIO VOLUME bass V4L2_CID_AUDIO_BASS treble V4L2_CID_AUDIO_TREBLE balance V4L2_CID_AUDIO_BALANCE To determine which of these controls are supported by a driver V4L
137. OSURE AUTO PRIORITY VAL2 CID PAN RELATIVE VAL2 CID TILT RELATIVE VAL2 CID PAN RESET VAL2 CID TILT RESET VAL2 CID PAN ABSOLUTE VAL2 CID TILT ABSOLUTI V4L2 CID FOCUS ABSOLUTE class The Camera class descriptor Calling VIDIOC_QUERYCTRIL for this control will return a description of this contr integer Enables automatic adjustments of the exposure time and or iris aperture The effect of manual changes of the ex ENTRYTBL not supported LH integer Determines the exposure time of the camera sensor The exposure time is limited by the frame interval Drivers s boolean When V4L2 CID EXPOSURE AUTO is set to AUTO or SHUTTER PRIORITY this control determines if the device integer This control turns the camera horizontally by the specified amount The unit is undefined A positive value move integer This control turns the camera vertically by the specified amount The unit is undefined A positive value moves t boolean When this control is set to TRUE 1 the camera moves horizontally to the default position boolean When this control is set to TRUE 1 the camera moves vertically to the default position integer This control turns the camera horizontally to the specified position Positive values move the camera to the right LH integer This control turns the camera vertically to the specified position Pos
138. PCM audio support must be implemented as ALSA or OSS interface For more information on audio inputs and outputs see Section 1 5 0x00040000 This is a radio receiver 0x01000000 The device supports the read and or write I O methods 0x02000000 The device supports the asynchronous I O methods 0x04000000 The device supports the streaming I O method Notes a The struct v412_framebuffer lacks an enum v412 buf type field therefore the type of overlay is implied by t Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The device is not compatible with this specification 176 ioctl VIDIOC QUERYCTRL VIDIOC QUERYMENU Name VIDIOC QUERYCTRL VIDIOC QUERYMENU Enumerate controls and menu control items Synopsis int ioctl int fd int request struct v412 queryctrl xargp int ioctl int fd int request struct v412 querymenu xargp Arguments fd File descriptor returned by open request VIDIOC_QUERYCTRL VIDIOC_QUERYMENU argp Description To query the attributes of a control applications set the id field of a struct v412_queryctrl and call the VIDIOC_QUERYCTRL ioctl with a pointer to this structure The driver fills the rest of the structure or returns an EINVAL error code when the id is invalid It is possible to enumerate controls by calling VIDIOC_QUERYCTRL with successive id values starting from V4L2_CID_BASE up to a
139. R x define V4L2 CHIP MATCH HOST 0 x Match against chip ID on host 0 for the host define V4L2 CHIP MATCH I2C DRIVER 1 x Match against I2C driver ID x define V4L2 CHIP MATCH I2C ADDR 2 Match against I2C 7 bit address x struct v412 register u32 match type Match type u32 match chip Match this chip meaning determined by match type x u64 reg u64 val VIDIOC G CHIP IDENT x struct v412 chip ident u32 match type x Match type x u32 match chip Match this chip meaning determined by match type x u32 ident chip identifier as specified in media v412 chip ident h 248 Appendix A Video For Linux Two Header File u32 revision chip revision chip specific i Il QI C QUUD E FOR VIDEO DEVICES x define VIDIOC QUERYCAP _IOR GEVE Y 0 struct v412 capability define VIDIOC RESERVED IO SII VS TE define VIDIOC ENUM FMT _IOWR V 2 struct v412 fmtdesc define VIDIOC G FMT _IOWR V 4 struct v412 format define VIDIOC S FMT _IOWR V 5 struct v412 format define VIDIOC REQBUFS _IOWR V 8 struct v412 requestbuffers define VIDIOC QUERYBUF _IOWR V 9 struct v412 buffer define VIDIOC G FBUF _IOR V 10 struct v412 framebuffer
140. S x 4 pixel image Byte Order Each cell is one byte start 0 Cbo Y o Cro Y or Cbo Yor Cro Yo Y a Y o Y o Y o start 12 Cbo Y io Cro Yu Con Yr Cri Ys Yu Ys Yew Yu start 24 Cbo Y 20 Cro Yo Cba Ya Cra Yz Y Yz Y Y m start 36 Cbso Y soo Cro Ys Cbu Y Cri Y 33 Y 34 Ys Yo Y m Color Sample Location coco KKK KO KKK KR Q0000 KKK on o KKK on oo KKK KA KKK KY Q0000 Hon oH on o 44 KKK KN V4L2 PIX FMT YVU420 YV12 V4L2 PIX FMT YUV420 YU12 Name VA4L2 PIX FMT YVU420 VA4L2 PIX FMT YUV420 Planar formats with horizontal and vertical chroma resolution also known as YUV 4 2 0 Description These are planar formats as opposed to a packed format The three components are separated into three sub images or planes The Y plane is first The Y plane has one byte per pixel For VAL2 PIX FMT YVU420 the Cr plane immediately follows the Y plane in memory The Cr plane is half the width and half the height of the Y plane and of the image Each Cr belongs to four pixels a two by two square of the image For example Cr belongs to Y Yor Y ip and Y Following the Cr plane is the Cb plane just like the Cr plane v4L2_P1X_FMT_YUV420 is the same except the Cb plane comes first then the Cr plane If the Y plane has pad bytes after each row then the Cr and Cb planes have half as many pad bytes after their rows In other words two Cx rows including padding is exactly as long as one Y row
141. TYPE INTEGER any any any An integer valued control ranging from minimum to V4L2 CTRL TYPE BOOLEAN 0 VAL2 CTRL TYPE ME NU 0 V4L2 CTRL TYPE BUTTON 0 VA4L2 CTRL TYPE INTEGER6OH a V4L2 CTRL TYPE C TRL CLAB A Table 4 Control Flags VAL2 CTRL FLAG D ISABLED VAL2 CTRL FLAG GRABBED V4L2 CTRL FLAG RI EAD ONLY VAL2 CTRL FLAG UPDATE VAL2 CTRL FLAG INACTIVE n a n a n a n a 0x0001 0x0002 0x0004 0x0008 0x0010 maximum inclusive The step value indicates the increment between values which are actually different on the hardware A boolean valued control Zero corresponds to disabled and one means enabled The control has a menu of N choices The names of the menu items can be enumerated with the VIDIOC_QUERYMENU ioctl A control which performs an action when set Drivers must ignore the value passed with VIDIOC_S_CTRL and return an EINVAL error code on a VIDIOC_G_CTRL attempt A 64 bit integer valued control Minimum maximum and step size cannot be queried This is not a control When VIDIOC_QUERYCTRL is called with a control ID equal to a control class code see Table 3 the ioctl returns the name of the control class and this control type Older drivers which do not support this feature return an EINVAL error code This control is permanently disabled and should be ignored by the applicati
142. Table 1 struct v4l2 frequency 143 ioctl VIDIOC G FREQUENCY VIDIOC S FREQUENCY u32 tuner The tuner or modulator index number This is the same value as in the struct v412 input tuner field and the struct v412 tuner index field or the struct v4I2 output modulator field and the struct v412_ modulator index field enum v4l2_ tuner type type The tuner type This is the same value as in the struct v412_tuner type field The field is not applicable to modulators i e ignored by drivers u32 frequency Tuning frequency in units of 62 5 kHz or if the struct v412_tuner or struct v412_ modulator capabilities flag VAL2 TUNER CAP LOW is set in units of 62 5 Hz u32 reserved 8 Reserved for future extensions Drivers and applications must set the array to zero Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The tuner index is out of bounds or the value in the t ype field is wrong 144 ioctl VIDIOC G INPUT VIDIOC S INPUT Name VIDIOC G INPUT VIDIOC S INPUT Query or select the current video input Synopsis int ioctl int fd int request int xargp Arguments fd File descriptor returned by open request VIDIOC G INPUT VIDIOC S INPUT argp Description To query the current video input applications call the VIDIOC_G_INPUT ioctl with a pointer to an integer where the driver stores the number of the input as in the struct v412 inp
143. This flag was a later addition together with the norm field and has been removed in the meantime V4L2 has a similar albeit more comprehensive approach to video standards see Section 1 7 for more information 6 1 4 Tuning The VAL VIDIOCGTUNER and VIDIOCSTUNER ioctl and struct video tuner can be used to enumerate the tuners of a VAL TV or radio device The equivalent V4L2 ioctls are vVIDIOC G TUNER and VIDIOC S TUNER using struct v4 2 tuner Tuners are covered in Section 1 6 The tuner field counting tuners was renamed to index The fields name rangelow and rangehigh remained unchanged The VIDEO TUNER PAL VIDEO TUNER NTSC and VIDEO TUNER SECAM flags indicating the supported video standards were dropped This information is now contained in the associated struct v4I2 input No replacement exists for the VIDEO TUNER NORM flag indicating whether the video standard can be switched The mode field to select a different video standard was replaced by a whole new set of ioctls and structures described in Section 1 7 Due to its ubiquity it should be mentioned the BTTV driver supports several standards in addition to the regular VIDEO MODE PAL 0 VIDEO MODE NTSC VIDEO MODE SECAM and VIDEO MODE AUTO 3 Namely N PAL Argentina M PAL N PAL and NTSC Japan with numbers 3 6 sic The vibEO TUNER STEREO ON flag indicating stereo reception became V4
144. VAE2 m E mux 2 0 8 eet ec P e E RED de uie iere 2 9 6 2 14 V4L2 spec erratum 2004 08 01 essent nennen 219 6 2 15 VAL m Emux 2 06 14 irent peret e ette ddp eed 219 6 2 16 VAE24n Emx 2 6 15 eee ERU evene 219 6 2 17 V4L2 spec erratum 2005 11 27 eee sees 219 6 2 18 V4L2 spec erratum 2006 01 10 eene 220 6 2 19 V4L2 spec erratum 2006 02 03 nennen ener en 220 6 2 20 V4L2 spec erratum 2006 02 04 enne nennen eerte nen 220 6 221 VAUD mTmux 2 06 17 4 eiie ueteri Oe Pe eee re ds 220 6 2 22 V4L2 spec erratum 2006 09 23 Draft 0 15 essere 220 6 223 VAL m Em ux 2 06 18 iren eei cedido eio ete cete nte 221 0 2 24 VAE 25 EmU 2 6 19 epar tebe SER ee Beni ae ae 221 6 2 25 V4L2 spec erratum 2006 10 12 Draft 0 17 sesseeeneeen 221 6 2 26 VAL2 3n Linux 2 6 2 crei eeecte rete tis R OERIEN ea ak 221 6 227 VAE2 m I2mux 2 06 22 er een i teret ie eei ut 221 6 2 28 VAEZ M E1n x 26 24 aee erepto Der ee p te eerte 222 6 229 VALE 2 1 Emux2 6 25 1 eei Eee EU Uu ER ete irecin 222 6 3 Relation of V4L2 to other Linux multimedia APIS sese 222 vii 6 3 1 X Video Extension uoce n eere POR MERO ERE RETE Eer es 6 3 2 Digital Vid o tpe iet ete e ae dpt t ed 6 3 3 Audio Interfaces user aen wate cad Gia lev EVE een 641 Experimental APL Elements eiit ee ue peter eee de te Ur tiere pen 6 5 Obsolete API Elements eer reete eret ere EE erret v
145. VBI section He also contributed VIDIOC LOC Revision 0 8 2004 10 04 Revised by mhs Somehow a piece of junk slipped into the capture example removed Revision 0 7 2004 09 19 Revised by mhs Fixed video standard selection control enumeration downscaling and aspect example Added read and user pointer i o to video cag Revision 0 6 2004 08 01 Revised by mhs v412_buffer changes added video capture example various corrections Revision 0 5 2003 11 05 Revised by mhs Pixel format erratum Revision 0 4 2003 09 17 Revised by mhs Corrected source and Makefile to generate a PDF SGML fixes Added latest API changes Closed gaps in the history chapter Revision 0 3 2003 02 05 Revised by mhs Another draft more corrections Revision 0 2 2003 01 15 Revised by mhs Second draft with corrections pointed out by Gerd Knorr Revision 0 1 2002 12 01 Revised by mhs First draft based on documentation by Bill Dirks and discussions on the VAL mailing list Table of Contents Introduction 1 Common API Elemennts ecce eere eterne reete neenon enn eo toto so stas etae ta sepa eaae tasse siss tn eta Sprie risos 1 1 1 Opening and Closing Devices sess eei eee thee to eene iden eee 1 1 1 1 Device Naming iere deer ER TRE En es Redes 1 1 12 Related IDDevIC8S eei iere tet re eee He cate ees EEEE 2 1 13 Multiple Opens irre der erento esee eret debe hber dores tte 2 1 1 4 Shared D ta Sire amp ams aene eee e
146. VIDEO BITRATE MODE lt uw L2_CID_MPEG_BASE 202 L2_CID_MPEG_BASE 203 L2_CID_MPEG_BASE 204 L2_CID_MPEG_BASE 205 L2_CID_MPEG_BASE 206 lt Ds UU UU UD lt Ds prc uo dm Ds lt Ds enum v412 mpeg video bitrate mode V4L2 MPEG VIDEO BITRATE MODE VBR V4L2 MPEG VIDEO BITRATE MODE CBR ll o ll p H define V4L2 CID MPEG VIDEO BITRATE VAL2 CID MPEG BASE 207 242 Appendix A Video For Linux Two Header File define V4L2 CID MPEG VIDEO BITRATE PEAK VAL2 CID MPEG BASE 208 define V4L2 CID MPEG VIDEO TEMPORAL DECIMATION V4L2 CID MPEG BASE 4209 define V4L2 CID MPEG VIDEO MUTE VAL2 CID MPEG BASE 210 define V4L2 CID MPEG VIDEO MUTE YUV VAL2 CID MPEG BASE4211 MPEG class control IDs specific to the CX2584x driver as defined by V4L2 x
147. VIDEO integer Video ID for MPEG PES CID MP EG STR EAM VBI FMT enum Some cards can embed VBI data e g Closed Caption Teletext into the MPEG stream This control selects wh ENTRYTBL not supported CID MPI EG AUDIO SAMPLING FREO enum MPEG Audio sampling frequency Possible values are ENTRYTBL not supported CID MPI EG AUDIO ENCODING enum MPEG Audio encoding Possible values are ENTRYTBL not supported CID MPI EG AUD IO L1 BITRATE enum Layer I bitrate Possible values are ENTRYTBL not supported CID MPI EG AUD IO L2 BITRATE enum Layer II bitrate Possible values are ENTRYTBL not supported CID MPI EG AUD IO L3 BITRATE enum Layer III bitrate Possible values are ENTRYTBL not supported 17 Chapter 1 Common API Elements ID Type Description VA4L2 CID MPEG AUDIO MODE enum MPEG Audio mode Possible values are ENTRYTBL not supported V4L2 CID MPEG AUDIO MODE EXTENSION enum Joint Stereo audio mode extension In Layer I and II they indicate which subbands are in intensity stereo All oth ENTRYTBL not supported V4L2 CID MPEG AUDIO EMPHASIS enum Audio Emphasis Possible values are ENTRYTBL not supported V4L2 CID MPEG AUDIO CRC enum CRC method Possible values are ENTRYTBL not supported V4L2 CID MPEG AUDIO MUTE bool Mutes the audio when c
148. Video for Linux Two API Specification Revision 0 24 Michael H Schimek mschimek 2gmx at Bill Dirks Hans Verkuil Martin Rubli Video for Linux Two API Specification Revision 0 24 by Michael H Schimek Bill Dirks Hans Verkuil and Martin Rubli Copyright 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 Bill Dirks Michael H Schimek Hans Verkuil Martin Rubli This document is copyrighted O 1999 2008 by Bill Dirks Michael H Schimek Hans Verkuil and Martin Rubli Permission is granted to copy distribute and or modify this document under the terms of the GNU Free Documentation License Version 1 1 or any later version published by the Free Software Foundation with no Invariant Sections with no Front Cover Texts and with no Back Cover Texts A copy of the license is included in the appendix entitled GNU Free Documentation License Programming examples can be used and distributed without restrictions Revision History Revision 0 24 2008 03 04 Revised by mhs Added pixel format Y16 and SBGGR16 new controls and a camera controls class Removed VIDIOC_G S_MPEGCOMP Revision 0 23 2007 08 30 Revised by mhs Fixed a typo in VIDIOC DBG G S REGISTER Clarified the byte order of packed pixel formats Revision 0 22 2007 08 29 Revised by mhs Added the Video Output Overlay interface new MPEG controls VAL2 FIELD INTERLACED TB and V4L2 FIELD INTERL Revision 0 21 2006 12 19 Revised by mhs Fixed a link in the VIDIOC G E
149. XT CTRLS section Revision 0 20 2006 11 24 Revised by mhs Clarified the purpose of the audioset field in struct v412 input and v412 output Revision 0 19 2006 10 19 Revised by mhs Documented V4L2 PIX FMT RGBA444 Revision 0 18 2006 10 18 Revised by mhs Added the description of extended controls by Hans Verkuil Linked V4L2 PIX FMT MPEG to VAL2 CID MPEG STREAM 7 Revision 0 17 2006 10 12 Revised by mhs Corrected VAL2 PIX FMT HMI2 description Revision 0 16 2006 10 08 Revised by mhs VIDIOC ENUM FRAMESIZES and VIDIOC ENUM FRAMEINTERVALS are now part of the API Revision 0 15 2006 09 23 Revised by mhs Cleaned up the bibliography added BT 653 and BT 1119 capture c start capturing for user pointer I O did not initialize the buffe Revision 0 14 2006 09 14 Revised by mr Added VIDIOC ENUM FRAMESIZES and VIDIOC ENUM FRAMEINTERVALS proposal for frame format enumeration of d Revision 0 13 2006 04 07 Revised by mhs Corrected the description of struct v412 window clips New V4L2_STD_ and VAL2 TUNER MODE LANGI LANG2 defines Revision 0 12 2006 02 03 Revised by mhs Corrected the description of struct v412_captureparm and v412_outputparm Revision 0 11 2006 01 27 Revised by mhs Improved the description of struct v412 tuner Revision 0 10 2006 01 10 Revised by mhs VIDIOC G INPUT and VIDIOC S PARM clarifications Revision 0 9 2005 11 27 Revised by mhs Improved the 525 line numbering diagram Hans Verkuil and I rewrote the sliced
150. Y one Cr Cb interleaved define VA4L2 PIX FMT NV12 v412 fourcc N V 1 2 x 12 Y CbCr 4 2 0 x define VA4L2 PIX FMT NV21 v 4l2 fourcc N v t2t ty Je T2 YX CrCb 4 2 0 AA The following formats are not defined in the V4L2 specification define VA4L2 PIX FMT YUV410 v412 fourcc Y U V 9 9 YUV 4 1 0 define V4L2 PIX FMT YUV420 v412 fourcc Y U 1 2 x 12 YUV 4 2 0 x define V4L2_PIX_FMT_YYUV v4l2 foure ON r Yep OM J Cx T6 YUV A22 x define V4L2_PIX_FMT_HI240 v412 fourcc H I 2 4 8 8 bit color define V4L2 PIX FMT HM12 v412 fourcc H M 1 2 8 YUV 4 2 0 16x16 macrobl see http www siliconimaging com RGB 20Bayer htm x define V4L2 PIX FMT SBGGR8 v412 fourcc B A 8 1 8 BGBG GRGR x define V4L2 PIX FMT SBGGR16 v412 fourcc B Y R 2 x 16 BGBG GRGR compressed formats x define V4L2 PIX FMT MJPEG v412 fourcc M J P G x Motion JPEG x define V4L2 PIX FMT JPEG v412 fourcc J P E G x JFIF JPEG x define VA4L2 PIX FMT DV v412 fourcce d vt s d y Jf 1394 define V4L2 PIX FMT MPEG v412 fourcc M P E G x MPEG 1 2 4 x Vendor specific formats x define V4L2_PIX_FMT_WNVA v412 fourcc W N V A x Winnov hw compress x define VA4AL2 PIX FMT SN9C10X v412 fourcc S 9 1 0 SN9C10x compression define VA4L2 PIX FMT PWC1 v412
151. _QUERYBUF Query the status of a buffer Synopsis int ioctl int fd int request struct v412 buf Arguments fd File descriptor returned by open request VIDIOC_QUERYBUF argp Description fer xargp This ioctl is part of the memory mapping I O method It can be used to query the status of a buffer at any time after buffers have been allocated with the VIDIOC RI EQBUFS ioctl Applications set the type field of a struct v412 buffer to the same buffer type as previously struct v412_format t ype and struct v412 requestbuffers t ype and the index field Valid index numbers range from zero to the number of buffers allocated with VIDIOC_REQBUFS struct v412_requestbuffers count minus one After calling v this structure drivers return an error code or fill the rest of the structure IDIOC QUERYBUF with a pointer to In the flags field the V4L2_BUF_FLAG_MAPPED V4L2 BUF FLAG QUEUED and V4L2 BUF FLAG DONE flags will be valid The memory field will be set to V4L2_MEMORY_MMAP the m offset contains the offset of the buffer from the start of the device memory the length field its size The driver may or may not set the remaining fields and flags they are meaningless in this context The v412 buffer structure is specified in Section 3 5 Return Value On success 0 is returned on error 1 and the errno variable is set appropriately 172 ioctl VIDIOC QUERYBUF
152. a control of type V4L2_CTRL_TYPE_MENU may not be supported VIDIOC QUERYMENU will return an error A good example is the list of supported MPEG audio bitrates Some drivers only support one or two bitrates others support a wider range 1 9 3 Enumerating Extended Controls The recommended way to enumerate over the extended controls is by using VIDIOC QUERYCTRL in combination with the vV4L2 CTRL FLAG NEXT CTRL flag struct v412 queryctrl qctrl qctrl id V4L2 CTRL FLAG NEXT CTRL while 0 ioctl fd VIDIOC QUERYCTRL amp qctrl 22 x qctrl id V4L2 CTRL FLAG NEXT CTRL The initial control ID is set to 0 ORed with the vVaL2 CTRL FLAG NEXT CTRL flag The VIDIOC QUERYCTRL ioctl will return the first control with a higher ID than the specified one When no such controls are found an error is returned If you want to get all controls within a specific control class then you can set the initial qct r1 id value to the control class and add an extra check to break out of the loop when a control of another control class is found 15 Chapter 1 Common API Elements qctrl id V4L2 CTRL CLASS MPEG V4L2 CTRL FLAG NEXT CTRL while 0 ioctl fd VIDIOC QUERYCTRL amp qctrl if V4L2 CTRL ID2CLASS qctrl id V4L2 CTRL CLASS MPEG break IE ce e qctrl id V4L2 CTRL FLAG NEXT CTRL
153. a very common error code see the individual ioctl requests listed in Reference I Function Reference for actual causes ENOMEM Not enough physical or virtual memory was available to complete the request ERANGE The application attempted to set a control with the vIDIOC S CTRL ioctl to a value which is out of bounds 91 ioctl VIDIOC CROPCAP Name VIDIOC CROPCAP Information about the video cropping and scaling abilities Synopsis int ioctl int fd int request struct v412 cropcap xargp Arguments fd File descriptor returned by open request VIDIOC CROPCAP argp Description Applications use this function to query the cropping limits the pixel aspect of images and to calculate scale factors They set the type field of a v412_cropcap structure to the respective buffer stream type and call the VIDIOC_CROPCAP ioctl with a pointer to this structure Drivers fill the rest of the structure The results are constant except when switching the video standard Remember this switch can occur implicit when switching the video input or output Table 1 struct v4l2 cropcap enum v4 2 buf type type Type of the data stream set by the application Only these types are valid here V4L2 BUE YPE VIDEO CAPTURE V4L2 BUE YPE VIDEO OUTPUT V4L2 BUE YPE VIDEO_OVERLAY and custom driver defined types with code V4L2_BUF_ YP E_PRIVATE and higher
154. alent to VIDIOC_S_FMT with one exception it does not change driver state It can also be called at any time never returning EBUSY This function is provided to negotiate parameters to learn about hardware limitations without disabling I O or possibly time consuming hardware preparations Although strongly recommended drivers are not required to implement this ioctl Table 1 struct v412_ format enum v4 2 buf type type union fmt struct v41l2 pix format pix struct v412_ window win struct v4l2 vbi format vbi struct v412_sliced_vbi_fosmated u8 raw data 200 Return Value Type of the data stream see Table 3 2 Definition of an image format see Chapter 2 used by video capture and output devices Definition of an overlaid image see Section 4 2 used by video overlay devices Raw VBI capture or output parameters This is discussed in more detail in Section 4 7 Used by raw VBI capture and output devices Sliced VBI capture or output parameters See Section 4 8 for details Used by sliced VBI capture and output devices Place holder for future extensions and custom driver defined formats with type V4L2 BUF TYPE PRIVATE and higher On success 0 is returned on error 1 and the errno variable is set appropriately 141 ioctl VIDIOC G FMT VIDIOC S FMT VIDIOC TRY FMT EBUSY The data format cannot be changed at this time for example because I O is already in progress EINVAL The
155. an be assigned to a file descriptor the exception being drivers permitting simultaneous video capturing and overlay using the same file descriptor for compatibility with V4L and earlier versions of VAL2 Switching the logical stream or returning into panel mode is possible by closing and reopening the device Drivers may support a switch using VIDIOC S FMT All drivers exchanging data with applications must support the VIDIOC G FMT and VIDIOC S FMT ioctl Implementation of the VIDIOC_TRY_FMT is highly recommended but optional 1 10 2 Image Format Enumeration Apart of the generic format negotiation functions a special ioctl to enumerate all image formats supported by video capture overlay or output devices is available The VIDIOC_ENUM_FMT ioctl must be supported by all drivers exchanging image data with applications Important Drivers are not supposed to convert image formats in kernel space They must enumerate only formats directly supported by the hardware If necessary driver writers should publish an example conversion routine or library for integration into applications 22 Chapter 1 Common API Elements 1 11 Image Cropping Insertion and Scaling Some video capture devices can sample a subsection of the picture and shrink or enlarge it to an image of arbitrary size We call these abilities cropping and scaling Some video output devices can scale an image up or down and insert it at an arbitrary scan line and horizontal of
156. application domain to say so Drivers set or clear this flag when calling the VIDIOC DOBUF ioctl It may be set by video capture devices when the buffer contains a compressed image which is a key frame or field 1 e can be decompressed on its own Similar to VAL2 BUF FLAG KEYFRAME this flags predicted frames or fields which contain only differences to a previous key frame Similar to V4L2 BUF FLAG PFRAME this is a bidirectional predicted frame or field ooc tbd The timecode field is valid Drivers set or clear this flag when the VIDIOC_DQBUF ioctl is called The input field is valid Applications set or clear this flag before calling the VIDIOC_QBUF ioctl The buffer is used for memory mapping I O The buffer is used for user pointer I O to do The v412 timecode structure is designed to hold a SMPTE 12M or similar timecode struct timeval timestamps are stored in struct v412 buffer field timestamp 59 Table 3 5 struct v412 timecode u32 u32 u8 us us us u8 type flags frames seconds minutes hours userbits 4 Table 3 6 Timecode Types VAL2 VAL2 VAL2 VAL2 VAL2 V4L2_1 VAL2 VAL2 C TYPE 24FPS 1 C TYPE 25FPS 2 C TYPE 30FPS 3 C TYPE 50FPS 4 C TYPE 60FPS 5 Table 3 7 Timecode Flags V4L2 TC FLAG DROPFRAME 0x0001 C FLAG COLORFRAME 0x0002 C
157. apturing This is not done by muting audio hardware which can still produce a slight his V4L2 CID MPEG VIDEO ENCODING enum MPEG Video encoding method Possible values are ENTRYTBL not supported V4L2 CID MPEG VIDEO ASPECT enum Video aspect Possible values are ENTRYTBL not supported V4L2 CID MPEG VIDEO B FRAMES integer Number of B Frames default 2 V4L2 CID MPEG VIDEO GOP SIZE integer GOP size default 12 VA4L2 CID MPEG VIDEO GOP CLOSURE bool GOP closure default 1 VA4L2 CID MPEG VIDEO PULLDOWN bool Enable 3 2 pulldown default 0 V4L2 CID MPEG VIDEO BITRATE MODE enum Video bitrate mode Possible values are 18 V4L2 V4L2 V4L2 V4L2 V4L2 Chapter 1 Common API Elements Type Description ENTRYTBL not supported CID_MPEG_VIDEO_BITRATE integer Video bitrate in bits per second CID_MPEG_VIDEO_BITRATE_PEAK integer Peak video bitrate in bits per second Must be larger or equal to the average video bitrate It is ignored if the vide CID_MPEG_VIDEO_TEMPORAL_DECIMATION integer For every captured frame skip this many subsequent frames default 0 CID_MPEG_VIDEO_MUTE bool Mutes the video to a fixed color when capturing This is useful for testing to produce a fixed video bitstream
158. arameters and finally return the actual parameters as VIDIOC G FMT does Like VIDIOC S rFMT the VIDIOC TRY FMT ioctl can be used to learn about hardware limitations without disabling I O or possibly time consuming hardware preparations The contents of struct v4l2 pix format are discussed in Chapter 2 See also the specification of the VIDIOC G FMT VIDIOC_S_FMT and VIDIOC TRY FMT ioctls for details Video output devices must implement both the VIDIOC_G_FMT and VIDIOC S FMT ioctl even if VIDIOC S FMT ignores all requests and always returns default parameters as VIDIOC G FMT does VIDIOC TRY FMT is optional 71 Chapter 4 Interfaces 4 3 4 Writing Images A video output device may support the write function and or streaming memory mapping or user pointer I O See Chapter 3 for details 4 4 Video Output Overlay Interface Experimental This is an experimental interface and may change in the future Some video output devices can overlay a framebuffer image onto the outgoing video signal Applications can set up such an overlay using this interface which borrows structures and ioctls of the Video Overlay interface The OSD function is accessible through the same character special file as the Video Output function Note the default function of such a dev video device is video capturing or output The OSD function is only available after calling the VIDIOC_S_FMT ioctl 4 4 1 Querying Capabilities Devices supporting the Video O
159. argp Arguments fd File descriptor returned by open request VIDIOC G MODULATOR VIDIOC 5 MODULATOR argp Description To query the attributes of a modulator applications initialize the index field and zero out the reserved array of a struct v412 modulator and call the VIDIOC_G_MODULATOR ioctl with a pointer to this structure Drivers fill the rest of the structure or return an EINVAL error code when the index is out of bounds To enumerate all modulators applications shall begin at index zero incrementing by one until the driver returns EINVAL Modulators have two writable properties an audio modulation set and the radio frequency To change the modulated audio subprograms applications initialize the index and txsubchans fields and the reserved array and call the vIDIOC S MODULATOR ioctl Drivers may choose a different audio modulation if the request cannot be satisfied However this is a write only ioctl it does not return the actual audio modulation selected To change the radio frequency the vib1OC S FREQUENCY ioctl is available 149 ioctl VIDIOC G MODULATOR VIDIOC S MODULATOR Table 1 struct v4l2 modulator u32 index u8 name 32 u32 capability u32 rangelow u32 rangehigh u32 txsubchans u32 reserved 4 Table 2 Modulator Audio Transmission Flags V4L2 TUNER SUB MONO 0x0001 V4L2 TUNER SUB STEREO 0x0002 Identifies the modulator set by the application
160. ary device functions they may also support the video overlay V4L2 CAP VIDEO OVERLAY and the raw VBI capture V4L2 CAP VBI CAPTURE interface At least one of the read write or streaming I O methods must be supported Tuners and audio inputs are optional 4 1 2 Supplemental Functions Video capture devices shall support audio input tuner controls cropping and scaling and streaming parameter ioctls as needed The video input and video standard ioctls must be supported by all video capture devices 4 1 3 Image Format Negotiation The result of a capture operation is determined by cropping and image format parameters The former select an area of the video picture to capture the latter how images are stored in memory i e in RGB or YUV format the number of bits per pixel or width and height Together they also define how images are scaled in the process As usual these parameters are not reset at open time to permit Unix tool chains programming a device and then reading from it as if it was a plain file Well written V4L2 applications ensure they really get what they want including cropping and scaling Cropping initialization at minimum requires to reset the parameters to defaults An example is given in Section 1 11 To query the current image format applications set the t ype field of a struct v4I2 format to V4L2 BUF TYPE VIDEO CAPTURE and call the viDIOC G FMT ioctl with a pointer to this structure Drivers fill the str
161. as only one channel or two channels and V4L2 TUNER SUB SAP is also set channel 1 is encoded as left and right channel This flag does not combine with vV4L2 TUNER SUB MONO or V4L2 TUNER SUB LANGI When the driver does not support stereo audio it shall fall back to mono 150 V4AL2 TUN ER SUB LANG1 UN VAL2 VAL2 ER SUB LANG2 UNI ER SUB SAP Return Value ioctl VIDIOC G MODULATOR VIDIOC S MODULATOR 0x0008 0x0004 0x0004 Modulate channel 1 and 2 as primary and secondary language of a bilingual audio signal When the input has only one channel it is used for both languages It is not possible to encode the primary or secondary language only This flag does not combine with V4L2 TUNER SUB MONO or V4L2 TUNER SUB STEREO If the hardware does not support the respective audio matrix or the current video standard does not permit bilingual audio the vIDIOC S MODULATOR ioctl shall return an EINVAL error code and the driver shall fall back to mono or stereo mode Same effect as VAL2 TUNER SUB LANGI When combined with vV4L2 TUNER SUB MONO the first channel is encoded as mono audio the last channel as Second Audio Program When the input has only one channel it is used for both audio tracks When the input has three channels the mono track is a down mix of channel 1 and 2 When combined with V4L2 TUNER SUB STEREO channel 1 and 2 are encoded as l
162. ased is valid The application should increase the index by one for each call until EINVAL is returned The v412 frmsizeenum type field is set to VAL2 FRMSIZE TYPE DISCRETE by the driver Of the union only the discrete member is valid Step wise The function returns success if the given index value is zero and EINVAL for any other index value The v412_frmsizeenum type field is set to VAL2 FRMSIZE TYPE STEPWISE by the driver Of the union only the stepwise member is valid Continuous This is a special case of the step wise type above The function returns success if the given index value is zero and EINVAL for any other index value The v4212 frmsizeenum type 103 ioctl VIDIOC ENUM FRAMESIZES field is set to vVAL2 FRMSIZE TYPE CONTINUOUS by the driver Of the union only the stepwise member is valid and the step widthand step height values are set to 1 When the application calls the function with index zero it must check the t ype field to determine the type of frame size enumeration the device supports Only for the VaL2 FRMSIZE TYPE DISCRETE type does it make sense to increase the index value to receive more frame sizes Note that the order in which the frame sizes are returned has no special meaning In particular does it not say anything about potential default format sizes Applications can assume that the enumeration data does not change without any i
163. audio program is supported Bilingual audio is a feature of two channel systems transmitting the primary language monaural on the main audio carrier and a secondary language monaural on a second carrier Only V4L2 TUNER ANALOG TV tuners can have this capability 164 V4L2 TUNER CAP LANG2 VAL2 TUN ER CAP SAP 0x0020 0x0020 Table 4 Tuner Audio Reception Flags VAL2 TUNI VAL2 TUNI VAL2 TUN ER SUB MONO ER SUB STEREO ER SUB LANG1 VAL2 TUN ER SUB LANG2 VAL2 TUN Table 5 Tuner Audio Modes ER SUB SAP VAL2 TUN ER MOD E MONO 0x0001 0x0002 0x0008 0x0004 0x0004 ioctl VIDIOC G TUNER VIDIOC S TUNER Reception of the secondary language of a bilingual audio program is supported Only VA4L2 TUNER ANALOG TV tuners can have this capability Reception of a secondary audio program is supported This is a feature of the BTSC system which accompanies the NTSC video standard Two audio carriers are available for mono or stereo transmissions of a primary language and an independent third carrier for a monaural secondary language Only V4L2 TUNER ANALOG TV tuners can have this capability Note the V4L2 TUNER CAP LANG2 and VA4L2 TUNER CAP SAP flags are synonyms VAL2 TUNER CAP SAP applies when the tuner supports the V4AL2 STD NTSC M video standard The tuner receives a mon
164. bi cap ule Service set service lines 0 specifies lines 0 23 1 23 used of the first field service lines 1 specifies lines 0 23 1 23 used of the second field u16 service lines 2 enum v412 buf type type 132 reserved 3 H struct v412 sliced vbi data ERR idy u32 field u32 line u32 reserved u8 data 48 HH equals frame lines 313 336 for 625 line video standards 263 286 for 525 line standards x 24 must be 0 0 first field 1 1 23 x must be 0 x second field 247 Appendix A Video For Linux Two Header File AGGREGATE S TR UG CU RES x Stream data format x struct v412_format enum v412_buf_type type union struct v412_pix_format pix V4L2_BUF_TYPE_VIDEO_CAPTURE struct v412 window win NAL2 BUF TYPE VIDEO OVERLAY struct v412 vbi format vbi NAL2 BUF TYPE VBI CAPTURE struct v412 sliced vbi format sliced V4L2 BUF TYPE SLICED VBI CAP u8 raw data 200 user defined fmt hi Stream type dependent parameters struct v412 streamparm enum v412_buf_type type union struct v412 captureparm capture struct v412 outputparm output u8 raw data 200 user defined parm i ADVA CG By DEBUGGING NOTE EXPERIMENTAL API VIDIOC DBG G REGISTER and VIDIOC DBG S REGISTE
165. ble for input 263 Appendix C GNU Free Documentation License to text formatters or for automatic translation to a variety of formats suitable for input to text formatters A copy made in an otherwise Transparent file format whose markup has been designed to thwart or discourage subsequent modification by readers is not Transparent A copy that is not Transparent is called Opaque Examples of suitable formats for Transparent copies include plain ASCII without markup Texinfo input format LaTeX input format SGML or XML using a publicly available DTD and standard conforming simple HTML designed for human modification Opaque formats include PostScript PDF proprietary formats that can be read and edited only by proprietary word processors SGML or XML for which the DTD and or processing tools are not generally available and the machine generated HTML produced by some word processors for output purposes only The Title Page means for a printed book the title page itself plus such following pages as are needed to hold legibly the material this License requires to appear in the title page For works in formats which do not have any title page as such Title Page means the text near the most prominent appearance of the work s title preceding the beginning of the body of the text C 3 2 VERBATIM COPYING You may copy and distribute the Document in any medium either commercially or noncommercially provided that this License
166. ble stream VAL2 MPEG STREAM TYPE MPEGI1 VCD 4 MPEG 1 VCD compatible stream x VAL2 MPEG STREAM TYPE MPEG2 SVCD 5 MPEG 2 SVCD compatible stream x i define V4L2_CID_MPEG_STREAM_PID_PMT V4L2_CID_MPEG_BASE 1 define V4L2 CID PEG STREAM PID AUDIO VA4L2 CID MPEG BASE 2 define V4L2_CID PEG STREAM PID VIDEO VA4L2 CID MPEG BASE 3 define V4L2 CID PEG STREAM PID PCR VAL2 CID MPEG BASE 4 define V4L2_CID PEG STREAM PES ID AUDIO VAL2 CID MPEG BASE 5 define V4L2 CID PEG STREAM PES ID VIDEO VAL2 CID MPEG BASE 6 define V4L2_CID PEG STREAM VBI FMT VAL2 CID MPEG BASE 7 enum v4l12 mpeg stream vbi fmt V4L2 MPEG STREAM VBI F NONE O0 No VBI in the MPEG stream lt V4L2 MPEG STREAM VBI F IVIV 1 VBI in private packets IVTV format H 240 Appendix A Video For Linux Two Header File MPEG audio define V4L2 CID MPEG AUDIO SAMPLING FREQ VAL2
167. buffer buf unsigned int i switch io case IO METHOD READ if 1 read fd buffers 0 start buffers 0 length switch errno case EAGAIN return 0 case EIO Could ignore EIO see spec fall through default errno exit read process image buffers 0 start break case IO METHOD MMAP CLEAR buf buf type VA4L2 BUF TYPE VIDEO CAPTURE buf memory V4L2 MEMORY MMAP Em 252 Appendix B Video Capture Example if 1 xioctl fd VIDIOC DOBUF amp buf switch errno case EAGAIN return 0 case EIO Could ignore EIO see spec fall through default errno exit VIDIOC DQBUF assert buf index n buffers process image buffers buf index start if 1 xioctl fd VIDIOC_QBUF amp buf errno exit VIDIOC QBUF break case IO METHOD USERPTR CLEAR buf buf type VA4L2 BUF TYPE VIDEO CAPTURE buf memory V4L2 MEMORY USERPTR if 1 xioctl fd VIDIOC_DQBUF amp buf switch errno case EAGAIN return 0 case EIO Could ignore EIO see spec fall through default errno exit VIDIOC DQBUF for i 0 i lt n buffers i if buf m userptr unsigned long buffers i start amp amp buf length buffers i length break assert i lt n_buffers process image vo
168. buffers 0 length buffer size buffers 0 start malloc buffer size if buffers 0 start fprintf stderr Out of memory n exit EXIT_FAILURE static void 256 Appendix B Video Capture Example init mmap void struct v412 requestbuffers req CLEAR req req count 4 req type V4L2_BUF_TYPE_VIDEO_CAPTURE req memory V4L2_MEMORY_MMAP if 1 xioctl fd VIDIOC_REQBUFS amp req if EINVAL errno fprintf stderr Ss does not support memory mapping n dev name exit EXIT FAILURE else errno exit VIDIOC REQBUFS if req count lt 2 fprintf stderr Insufficient buffer memory on s n dev name exit EXIT FAILURE buffers calloc req count sizeof xbuffers if buffers fprintf stderr Out of memory n exit EXIT FAILURE for n buffers 0 n buffers lt req count n buffers struct v412 buffer buf CLEAR buf buf type VAL2 BUF TYPE VIDEO CAPTURE buf memory V4L2 MEMORY MMAP buf index n buffers if 1 xioctl fd VIDIOC QUERYBUF amp buf errno exit VIDIOC QUERYBUF buffers n buffers length buf length buffers n buffers start mmap NULL start anywhere x buf length PROT READ PROT WRITE required MAP SHARED recommended x fd buf m offset if MAP FAILED buffers
169. c pee ree 3 1 5 b nctions on aer erben roe nibste dee ie ode 3 1 2 Queryang Capabilities tee o eiie elu vette idest 3 1 3 Application Priority iie eene eene 3 1 4 Video Inputs and Outputs 15 6 eret eto eode teet Penis 4 1 5 Audio Inputs and Outputs eese enne enne nennen tenerent eren nee 2 1 6 Tuners and Modulators sessi r n N esset tense sentina sae eta rna n seen 6 SESTA MB ISCRITTI pr S 6 16 2 Modulators 45 ote teda d Madam D 6 1 6 3 Radio Erequency ecco oe qtue ie puse Cre ete ie etit trou Tn 7 TOA Satellite Recelyvers etate en editis 7 1 7 Mid o Stand ards use eee REEF PER AE ISIN UC 7 1 8 User Controls 4355315 otis Ee at tus SLM ELLO LE ise 9 1 9 Extended Controls zn ca a eBook tote AE Deda Aiea Ree sce 14 1395 T Introduction ie Ness RS eae TAR EEE ES 14 1 9 2 The Extended Control ARE irn a A E e S EE ESS 15 1 9 3 Enumerating Extended Controls eene 15 1 9 4 Creating Control Panels esee entnehmen nens 16 1 9 5 MPEG Control Referensnr eminin E E eene een A nene E er tnn 16 1 9 5 1 Generic MPEG Controls esses ener enne rne 16 1 9 5 2 CX2341x MPEG Controls sees eene eene eene 19 1 9 6 Camera Control Reference ae ate E RO eicit 20 L40 Data Formats fcr cists eek nek T ttt eee UBI ID 22 1 10 1 Data Format Negotiation sees enne nnn ennnen nnne nnne nenne 22 1 10
170. ced VBI API however the default function here is video capturing or output Different file descriptors must be used to pass raw and sliced VBI data simultaneously if this is supported by the driver 4 8 1 Querying Capabilities Devices supporting the sliced VBI capturing or output API set the V4L2_CAP_SLICED_VBI_CAPTURE OrV4L2 CAP SLICED VBI OUTPUT flag respectively in the capabilities field of struct v412 capability returned by the VIDIOC_QUERYCAP ioctl At least 1 Chapter 4 Interfaces one of the read write streaming or asynchronous I O methods must be supported Sliced VBI devices may have a tuner or modulator 4 8 2 Supplemental Functions Sliced VBI devices shall support video input or output and tuner or modulator ioctls if they have these capabilities and they may support control ioctls The video standard ioctls provide information vital to program a sliced VBI device therefore must be supported 4 8 3 Sliced VBI Format Negotiation To find out which data services are supported by the hardware applications can call the VIDIOC G SLICED VBI CAP ioctl All drivers implementing the sliced VBI interface must support this ioctl The results may differ from those of the VIDIOC_S_FMT ioctl when the number of VBI lines the hardware can capture or output per frame or the number of services it can identify on a given line are limited For example on PAL line 16 the hardware may be able to look for a VPS or Teletext s
171. cordingly corrected 2 Unrelated to the fixes above drivers may still interpret some V4L2 RGB pixel formats differently These issues have yet to be addressed for details see Section 2 4 218 Chapter 6 Changes 6 2 12 V4L2 in Linux 2 6 6 2004 05 09 1 The VIDIOC_CROPCAP ioctl was incorrectly defined with read only parameter It is now defined as write read ioctl while the read only version was renamed to VIDIOC_CROPCAP_OLD The old ioctl will be removed in the future 6 2 13 V4L2 in Linux 2 6 8 1 A new field input former reserved 0 was added to the struct v412_ buffer structure Purpose of this field is to alternate between video inputs e g cameras in step with the video capturing process This function must be enabled with the new V4L2_BUF_FLAG_INPUT flag The 1ags field is no longer read only 6 2 14 VAL2 spec erratum 2004 08 01 1 The return value of the V4L2 open 2 function was incorrectly documented 2 Audio output ioctls end in AUDOUT not AUDIOOUT 3 In the Current Audio Input example the viDIOC G AUDIO ioctl took the wrong argument 4 The documentation of the VIDIOC_QBUF and VIDIOC DOBUF ioctls did not mention the struct v412 buffer memory field It was also missing from examples Also on the VIDIOC DOBUF page the EIO error code was not documented 6 2 15 V4L2 in Linux 2 6 14 1 A new sliced VBI interface was added It is documented in Section 4 8 and replaces the interface first propose
172. d frame period drivers return the actual frame period which must be greater or equal to the nominal frame period determined by the current video standard struct v412 standard rameperiod field Changing the video standard also implicitly by switching the video input may reset this parameter to the nominal frame period To reset manually applications can just set this field to Zero Drivers support this function only when they set the V4AL2 CAP TIMEPERFRAME flag in the capability field Custom driver specific streaming parameters When unused applications and drivers must set this field to zero Applications using this field should check the driver name and version see Section 1 2 Applications set this field to the desired number of buffers used internally by the driver in read mode Drivers return the actual number of buffers When an application requests zero buffers drivers should just return the current setting rather than the minimum or an error code For details see Section 3 1 Reserved for future extensions Drivers and applications must set the array to zero 155 u32 capability u32 outputmode struct v412 fract timeperframe ioctl VIDIOC G PARM VIDIOC S8 PARM See Table 4 Set by drivers and applications see Table 5 This is is the desired period between successive frames output by the driver in seconds The field is intended to repeat frames on the driver side in write mo
173. d id was added as machine readable identifier also replacing the transmission field The misleading framerate field was renamed to frameperiod The now obsolete co1orstandard information originally needed to distguish between variations of standards were removed Struct v412_enumstd ceased to be VIDIOC_ENUMSTD now takes a pointer to a struct v412 standard directly The information which standards are supported by a particular video input or output moved into struct v4I2 input and struct v412 output fields named sta respectively The struct v412 queryctrl fields category and group did not catch on and or were not implemented as expected and therefore removed The VIDIOC_TRY_FMT ioctl was added to negotiate data formats as with VIDIOC S FMT but without the overhead of programming the hardware and regardless of I O in progress In struct v412 format the fmt union was extended to contain struct v412 window All image format negotiations are now possible with VIDIOC G FMT VIDIOC S FMT and VIDIOC TRY FMT ioctl The VIDIOC_G_WIN and VIDIOC S WIN ioctls to prepare for a video overlay were removed The type field changed to type enum v412 buf type and the buffer type names changed as follows Old defines enum v4I2 buf type V4L2 BUF TYPE CAPTURE V4L2 BUF TYPE VIDEO CAPTURE VAL2 BUF TYPE CODECI Omitted for now VAL2 BUF TYPE CODECOUT Omitted for now 215 10
174. d in V4L2 specification 0 8 6 2 16 V4L2 in Linux 2 6 15 1 The viDIOC LOG STATUS ioctl was added 2 New video standards V4L2 STD NTSC 443 VAL2 STD SECAM LC VAL2 STD SECAM DK a set of SECAM D K and K1 and VAL2 STD ATSC a set of VAL2 STD ATSC 8 VSB and V4L2 STD ATSC 16 VSB were defined Note the vVAL2 STD 525 60 set now includes VA4L2 STD NTSC 443 See also Table 3 3 The VIDIOC_G_COMP and VIDIOC S COMP ioctl were renamed to VIDIOC G MPEGCOMP and VIDIOC S MPEGCOMP respectively Their argument was replaced by a struct v4AI2 mpeg compression pointer The VIDIOC_G_MPEGCOMP and VIDIOC S MPEGCOMP ioctls where removed in Linux 2 6 25 219 Chapter 6 Changes 6 2 17 VAL2 spec erratum 2005 11 27 The capture example in Appendix B called the viproc s CROP ioctl without checking if cropping is supported In the video standard selection example in Section 1 7 the VIDIOC_S_STD call used the wrong argument type 6 2 18 V4L2 spec erratum 2006 01 10 1 The V4AL2 IN ST COLOR KILL flag in struct v412 input not only indicates if the color killer is enabled but also if it is active The color killer disables color decoding when it detects no color in the video signal to improve the image quality 2 VIDIOC S PARMis a write read ioctl not write only as stated on its reference page The ioctl changed in 2003 as noted above 6 2 19 V4L2 spec erratum 2006 02 03 1 In struct v412_cap
175. d not identify the standard indirectly after enumerating So in summary the lookup itself is unavoidable The difference is only whether the lookup is necessary to find an enumerated standard or to switch to a standard by v412 std id See Section 3 5 for a rationale Probably even USB cameras follow some well known video standard It might have been better to explicitly indicate elsewhere if a device cannot live up to normal expectations instead of this exception It will be more convenient for applications if drivers make use of the VAL2 CTRL FLAG DISABLED flag but that was never required Applications could call an ioctl to request events After another process called VIDIOC_S_CTRL or another ioctl changing shared properties the select function would indicate readability until any ioctl querying the properties is called Enumerating formats an application has no a priori knowledge of otherwise it could explicitely ask for them and need not enumerate seems useless but there are applications serving as proxy between drivers and the actual video applications for which this is useful 28 Chapter 2 Image Formats The V4L2 API was primarily designed for devices exchanging image data with applications The v412 pix format structure defines the format and layout of an image in memory Image formats are negotiated with the vibroc s rwr ioctl The explanations here focus on video capturing and output for overlay frame buffer for
176. de in streaming mode timestamps can be used u32 extendedmode u32 writebuffers u32 reserved 4 Table 4 Streaming Parameters Capabilites V4L2 CAP TIMEPERFRAME 0x1000 Table 5 Capture Parameters Flags Custom driver specific streaming parameters When unused applications and drivers must set this field to zero Applications using this field should check the driver name and version see Section 1 2 Applications set this field to the desired number of buffers used internally by the driver in write mode Drivers return the actual number of buffers When an application requests zero buffers drivers should just return the current setting rather than the minimum or an error code For details see Section 3 1 Reserved for future extensions Drivers and applications must set the array to zero The frame skipping repeating controlled by the timeperframe field is supported 156 ioctl VIDIOC G PARM VIDIOC S8 PARM V4L2 MODE HIGHQUALITY 0x0001 High quality imaging mode High quality mode is intended for still imaging applications The idea is to get the best possible image quality that the hardware can deliver It is not defined how the driver writer may achieve that it will depend on the hardware and the ingenuity of the driver writer High quality mode is a different mode from the the regular motion video capture modes In high quality mode The driver may be able to capture higher resolutions than
177. decoder dev vtx dev vtx0 to 192 223 dev vtx31 IRaw VBI capture dev vbi dev vbi0 to 224 255 dev vbi31 Notes a According to Documentation devices txt these should be symbolic links to dev videoO Note the origina VAL prohibits or used to prohibit multiple opens of a device file V4L2 drivers may support multiple opens see Section 1 1 for details and consequences VAL drivers respond to V4L2 ioctls with an EINVAL error code The compatibility layer in the V4L2 videodev module can translate VAL ioctl requests to their VAL2 counterpart however a VAL2 driver usually needs more preparation to become fully VAL compatible This is covered in more detail in Chapter 5 202 6 1 2 Querying Capabilities The VAL vIDIOCGCAP ioctl is equivalent to V4L2 s VIDIOC QUI Chapter 6 Changes ERYCAP The name field in struct video capability became card in struct v412 capability type was replaced by capabilities Note V4L2 does not distinguish between device types like this better think of basic video input video output and radio devices supporting a set of related functions like video capturing video overlay and VBI capturing See Section 1 1 for an introduction struct video capability type struct v4l2 capability capabilities flags Purpose field capability of struct v412_framebuffer VID TYPE CAPTURE V4L2 CAP VIDEO CAPTURE
178. define VIDIOC S FBUF _IOW V 11 struct v412 framebuffer define VIDIOC OVERLAY IOW V 14 int define VIDIOC QBUF _IOWR V 15 struct v412 buffer define VIDIOC DQBUF _IOWR V 17 struct v412 buffer define VIDIOC STREAMON STOW V 18 int define VIDIOC STREAMOFF JIOW V 19 int define VIDIOC G PARM _IOWR V 21 struct v412 streamparm define VIDIOC S PARM _IOWR V 22 struct v412 streamparm define VIDIOC G STD TOR fW 23 v412 std xd define VIDIOC S STD IOW V 24 v412 std id define VIDIOC ENUMSTD _IOWR V 25 struct v412 standard define VIDIOC ENUMINPUT _IOWR V 26 struct v412 input define VIDIOC G CTRL _IOWR V 27 struct v412 control define VIDIOC S CTRL _IOWR V 28 struct v412 control define VIDIOC G TUNER _IOWR V 29 struct v412 tuner define VIDIOC S TUNER _Iow V 30 struct v412 tuner define VIDIOC G AUDIO IOR V 33 struct v4l12 audio define VIDIOC S AUDIO _IOw V 34 struct v412 audio define VIDIOC QUERYCTRL _IOWR V 36 struct v412 queryctrl define VIDIOC QUERYMENU _IOWR V 37 struct v412 querymenu define VIDIOC G INPUT _IOR V 385 nt define VIDIOC S INPUT _IOWR V 39 int define VIDIOC G OUTPUT _IOR V 46 int define VIDIOC S OUTPUT _IOWR V 47 int define VIDIOC ENUMOUTPUT _IOWR V 48 struct v412 output define VIDIOC G AUDOUT STOR V 49 struct v412 audioout define VIDIOC S AUDOUT _IOW V 50 struct v4l2 audioout
179. determine the number of buffers used internally by a driver in read write mode For implications see the section discussing the read function To get and set the streaming parameters applications call the vVIDIOC G PARM and VIDIOC S PARM ioctl respectively They take a pointer to a struct v412_streamparm which contains a union holding separate parameters for input and output devices Table 1 struct v4l2 streamparm enum v4lI2 buf typetype union parm struct v412_captureparmt ure The buffer stream type same as struct v412_format type set by the application Parameters for capture devices used when type is V4L2_BUF_TYPE_VIDEO_CAPTURE 154 struct v412_outputpaom t put u8 Table 2 struct v4l2 captureparm u32 capability u32 capturemode struct v412 fract timeperframe u32 extendedmode u32 readbuffers u32 reserved 4 Table 3 struct v412_outputparm raw data 200 ioctl VIDIOC_G_PARM VIDIOC S8 PARM Parameters for output devices used when type is VAL2 BUF TYPE VIDEO OUTPUT A place holder for future extensions and custom driver defined buffer types VAL2 BUF TYPE PRIVATE and higher See Table 4 Set by drivers and applications see Table 5 This is is the desired period between successive frames captured by the driver in seconds The field is intended to skip frames on the driver side saving I O bandwidth Applications store here the desire
180. dev h so allowed her no dif _ KERNEL tests ar See http linuxtv o rg for more info Author Bill Dirks lt bill thedirks org gt Justin Schoe Hans Verkuil et al man lt hverkuil xs4all nl gt 225 ifndef X LINUX VIDEODEV2 H define _ LINUX VIDEODEV2 H ifdef KERNEL include lt linux time h gt else define _ user include lt sys time h gt endif include linux ioctl h include lt linux types h gt Common stuff for both V4L1 and V4L2 Moved from videodev h Appendix A Video For Linux Two Header File need struct timeval x include lt linux compiler h gt need X user x define VIDEO MAX FRAME 32 define VID TYPE CAPTURE 1 Can capture x define VID TYPE TUNER 2 Can tune x define VID TYPE TELETEXT 4 Does teletext define VID TYPE OVERLAY 8 Overlay onto frame buffer x define VID TYPE CHROMAKE 16 Overlay by chromakey define VID TYPE CLIPPING 32 Can clip x define VID TYPE FRAMERA 64 Uses the frame buffer memory define VID TYPE SCALES 128 Scalable define VID_TYPE_MONOCHROME 256 x Monochrome only x define VID_TYPE_SUBCAPTURE 512 Can capture subareas of the image define VID_TYPE_MPE
181. dev vtx and dev vttuner with device number 83 0 and 83 16 respectively A similar interface exists for the Philips SAA5249 Teletext decoder specification with character device file names dev t1kN device number 102 N Eventually the Teletext API was integrated into the VAL API with character device file names dev vtx0 to dev vtx31 device major number 81 minor numbers 192 to 223 For reference the VAL Teletext API specification is reproduced here in full Teletext interfaces talk the existing VTX API Teletext devices with major number 83 and 102 will be removed in Linux 2 6 There are no plans to replace the Teletext API or to integrate it into VAL2 Please write to the Video4Linux mailing list https listman redhat com mailman listinfo video4linux list when the need arises 4 10 Radio Interface This interface is intended for AM and FM analog radio receivers Conventionally V4L2 radio devices are accessed through character device special files named dev radio and dev radio0 to dev radio63 with major number 81 and minor numbers 64 to 127 4 10 1 Querying Capabilities Devices supporting the radio interface set the vVAL2 CAP RADIO and VAL2 CAP TUNER flag in the capabilities field of struct v412 capability returned by the VIDIOC_QUERYCAP ioctl Other combinations of capability flags are reserved for future extensions 4 10 2 Supplemental Functions Radio devices can support controls and must support the tuner
182. different brands or models of video hardware This information is intended for users for example in a menu of available devices Since multiple TV cards of the same brand may be installed which are supported by the same driver this name should be combined with the character device file name e g dev video2 or the bus info string to avoid ambiguities u8 bus info 32 Location of the device in the system a NUL terminated ASCII string For example PCI Slot 4 This information is intended for users to distinguish multiple identical devices If no such information is available the field may simply count the devices controlled by the driver or contain the empty string bus info 0 0 u32 version Version number of the driver Together with the driver field this identifies a particular driver The version number is formatted using the KERNEL VERSION macro define KERNEL VERSION a b c a lt lt 16 b lt lt 8 c u32 version KE u32 capabilities Device capabilities see Table 2 u32 reserved 4 Reserved for future extensions Drivers must set this array to zero Table 2 Device Capabilities Flags V4L2 CAP VIDEO CAPTURE 0x00000001 The device supports the Video Capture interface V4L2 CAP VIDEO OUTPUT 0x00000002 The device supports the Video Output interface VA4L2 CAP VIDEO OVERLAY 0x00000004 The device supports the Video Overlay interface A video overlay dev
183. ds argument is greater than OPEN_MAX 194 V4L2 read Name v412 read Read from a V4L2 device Synopsis include lt unistd h gt ssize_t read int fd void buf size t count Arguments fd File descriptor returned by open buf count Description read attempts to read up to count bytes from file descriptor fd into the buffer starting at buf The layout of the data in the buffer is discussed in the respective device interface section see If count is Zero read returns zero and has no other results If count is greater than SSIZE MAX the result is unspecified Regardless of the count value each read call will provide at most one frame two fields worth of data By default read blocks until data becomes available When the oO NONBLOCK flag was given to the open function it returns immediately with an EAGAIN error code when no data is available The select or po11 functions can always be used to suspend execution until data becomes available All drivers supporting the read function must also support select and po11 Drivers can implement read functionality in different ways using a single or multiple buffers and discarding the oldest or newest frames once the internal buffers are filled read never returns a snapshot of a buffer being filled Using a single buffer the driver will stop capturing when the application starts reading the buffer until the read is finished Thus on
184. e mono or stereo Only V4L2 TUNER ANALOG TV tuners support this mode Play the secondary language mono When the tuner receives no bilingual audio or SAP or their reception is not supported the driver shall fall back to mono or stereo mode Only V4L2 TUNER ANALOG TV tuners support this mode Play the Second Audio Program When the tuner receives no bilingual audio or SAP or their reception is not supported the driver shall fall back to mono or stereo mode Only V4L2 TUNER ANALOG TV tuners support this mode Note the vV4L2 TUNER MODE LANG2 and VA4L2 TUNER MODE SAP are synonyms Play the primary language on the left channel the secondary language on the right channel When the tuner receives no bilingual audio or SAP it shall fall back to MODE LANG1 or MODE MONO Only V4L2 TUNER ANALOG TV tuners support this mode Received MONO STEREO LANG1 LANG2 SAP LANG1_LANG2a V4L2_TUNER_SUB _ ONO Mono Mono Mono Mono Mono Mono Mono ONO SAP Mono Mono Mono Mono SAP Mono SAP preferred or IMono Mono 166 ioctl VIDIOC G TUNER VIDIOC S TUNER Received MONO STEREO LANG1 LANG2 SAP LANG1_LANG2a V4L2_TUNER_SUB_ STEREO L R L R Stereo L R Stereo L R L R preferred preferred or preferred or jor L R L R Mono L R Mono L R STEREO SAP L R L R Stereo L R SAP L R SAP prefer
185. e I O method which is limited anyway this information is already available to applications The example transformation from RGB to YCbCr color space in the old V4L2 documentation was inaccurate this has been corrected in Chapter 2 217 Chapter 6 Changes 6 2 10 V4L2 2003 06 19 1 A new capability flag v4L2_CAP_RADIO was added for radio devices Prior to this change radio devices would identify solely by having exactly one tuner whose type field reads V4L2_TUNER_RADIO 2 An optional driver access priority mechanism was added see Section 1 3 for details 3 The audio input and output interface was found to be incomplete Previously the viDIOC G AUDIO ioctl would enumerate the available audio inputs An ioctl to determine the current audio input if more than one combines with the current video input did not exist So VIDIOC G AUDIO was renamed to VIDIOC G AUDIO OLD this ioctl will be removed in the future The VIDIOC_ENUMAUDTIO ioctl was added to enumerate audio inputs while VIDIOC G AUDIO now reports the current audio input The same changes were made to VIDIOC G AUDOUT and VIDIOC ENUMAUDOUT Until further the videodev module will automatically translate between the old and new ioctls but drivers and applications must be updated to successfully compile again 4 The VIDIOC_OVERLAY ioctl was incorrectly defined with write read parameter It was changed to write only while the write read version was renamed to
186. e Order Each cell is one byte start 0 Y 00 Y oi Y o Y os start 4 Y io Yu Yr Y 13 start 8 Y o Y Y 2 Y start 12 Y 30 Y s Y Y 33 start 16 Croo start 17 Cboo Color Sample Location 0 1 2 0 Y 1 Y Y Y C 2 Y Y Y 3 Y Y Y 46 VA4L2 PIX FMT YUV422P 422P Name VAL2 PIX FMT YUV422P Format with 2 horizontal chroma resolution also known as YUV 4 2 2 Planar layout as opposed to VAL2 PIX FMT YUYV Description This format is not commonly used This is a planar version of the YUYV format The three components are separated into three sub images or planes The Y plane is first The Y plane has one byte per pixel The Cb plane immediately follows the Y plane in memory The Cb plane is half the width of the Y plane and of the image Each Cb belongs to two pixels For example Cb belongs to Y Y 9 Following the Cb plane is the Cr plane just like the Cb plane 00 If the Y plane has pad bytes after each row then the Cr and Cb planes have half as many pad bytes after their rows In other words two Cx rows including padding is exactly as long as one Y row including padding Example 2 1 VAL2 PIX FMT YUV422P 4 x 4 pixel image Byte Order Each cell is one byte start 4 0 Y oo Y oi Y o Y os start 4 Y 10 Yu Yr Yi start 8 Y o Yn Y Y start 4 12 Y 30 Y si Y 32 Ys start 4 16 Cboo Cbo start 18 Cbio Cbii start 4 20 Cboo Cboi start 4 22 Cb30 Cbs start
187. e VIDIOC_REQBUFS ioctl with the desired number of buffers and buffer type for example V4L2 BUF TYPE VIDEO CAPTURE This ioctl can also be used to change the number of buffers or to free the allocated memory provided none of the buffers are still mapped Before applications can access the buffers they must map them into their address space with the mmap function The location of the buffers in device memory can be determined with the VIDIOC_QUERYBUF ioctl The m offset and length returned in a struct vAI2 buffer are passed as sixth and second parameter to the mmap function The offset and length values must not be modified Remember the buffers are allocated in physical memory as opposed to virtual memory which can be swapped out to disk Applications should free the buffers as soon as possible with the munmap function Example 3 1 Mapping buffers struct v412 requestbuffers reqbuf SUrudot void xstart Size t length xbuffers unsigned int i memset amp reqbuf 0 sizeof reqbuf reqbuf type V4L2_BUF_TYPE_VIDEO_CAPTURE reqbuf memory V4L2_MEMORY_MMAP reqbuf count 20 E if 1 ioctl fd VIDIOC_REQBUFS amp reqbuf if errno EINVAL printf Video capturing or mmap streaming is not supported n else perror VIDIOC_REQBUFS exit EXIT_FAILURE We want at least five buffers x if regbuf count lt 5 You
188. e dequeued with the vibroc poBur ioctl The driver can unlock the memory pages at any time between the completion of the DMA and this ioctl The memory is also unlocked when VIDIOC_STREAMOFF is called VIDIOC REQBUFS or when the device is closed Applications must take care not to free buffers without dequeuing For once the buffers remain locked until further wasting physical memory Second the driver will not be notified when the memory is returned to the application s free list and subsequently reused for other purposes possibly completing the requested DMA and overwriting valuable data For capturing applications it is customary to enqueue a number of empty buffers to start capturing and enter the read loop Here the application waits until a filled buffer can be dequeued and re enqueues the buffer when the data is no longer needed Output applications fill and enqueue buffers when enough buffers are stacked up output is started In the write loop when the application runs out of free buffers it must wait until an empty buffer can be dequeued and reused Two methods exist to suspend execution of the application until one or more buffers can be dequeued By default VIDIOC_DQBUF blocks when no buffer is in the outgoing queue When the O_NONBLOCK flag was given to the open function VIDIOC DOBUF returns immediately with an EAGAIN error code when no buffer is available The select or po11 function are always available To start and st
189. e in virtual or shared memory Only pointers to data are exchanged these pointers and meta information are passed in struct v412 buffer The driver must be switched into user pointer I O mode by calling the VIDIOC_REQBUF S with the desired buffer type No buffers are allocated beforehands consequently they are not indexed and cannot be queried like mapped buffers with the VIDIOC_QUERYBUF ioctl Example 3 2 Initiating streaming I O with user pointers struct v412 requestbuffers reqbuf memset amp reqbuf 0 sizeof reqbuf reqbuf type V4L2_BUF_TYPE_VIDEO_CAPTURE reqbuf memory V4L2_MEMORY_USERPTR EM if ioctl fd VIDIOC REOBUFS amp reqbuf 1 if errno EINVAL printf Video capturing or user pointer streaming is not supported n else perror VIDIOC_REQBUFS exit EXIT_FAILURE Buffer addresses and sizes are passed on the fly with the VIDIOC_QBUF ioctl Although buffers are commonly cycled applications can pass different addresses and sizes at each VIDIOC_QBUF call If 54 Chapter 3 Input Output required by the hardware the driver swaps memory pages within physical memory to create a continuous area of memory This happens transparently to the application in the virtual memory subsystem of the kernel When buffer pages have been swapped out to disk they are brought back and finally locked in physical memory for DMA Filled or displayed buffers ar
190. ected bit Indicates that an error was corrected for this data block Bits 5 3 Received Offset Indicates the offset received by the sync system Bits 2 0 Offset Name Indicates the offset applied to this data It was argued the RDS API should be extended before integration into V4L2 no new API has been devised yet Please write to the Video4Linux mailing list for discussion https listman redhat com mailman listinfo video4linux list Meanwhile no V4L2 driver should set the V4L2_CAP_RDS_CAPTURE capability flag 1 A common application of two file descriptors is the XFree86 Xv V4L interface driver and a VAL2 application While the X server controls video overlay the application can take advantage of memory mapping and DMA In the opinion of the designers of this API no driver writer taking the efforts to support simultaneous capturing and overlay will restrict this ability by requiring a single file descriptor as in V4L and earlier versions of V4L2 Making this optional means applications depending on two file descriptors need backup routines to be compatible with all drivers which is considerable more work than using two fds in applications which do not Also two fd s fit the general concept of one file descriptor for each logical stream Hence as a complexity trade off drivers must support two file descriptors and may support single fd operation 2 The X Window system defines regions which are vectors of struct BoxRec short x1 yl
191. edcessetssossctacdensdsdeeseies cescacedcesscuesesssnsctsess 123 ioctl VIDIOC G CROP VIDIOC S CRODB e eeeee cesse esee en nete ete en sene tasa sten essen sese en se tuea 126 ioctl VIDIOC G CTRL VIDIOC S CTRL eeeee cesse eee ense te ete en eene tasto seen sens en ette en ne tnea 128 ioctl VIDIOC G ENC INDEX eei ecteeceetoseees eve concaceddestetcectsasecdensassnetetes sesvacedeestecssesuavecdsase 130 ioctl VIDIOC G EXT CTRLS VIDIOC S EXT CTRLS VIDIOC TRY EXT CTRLS 132 ioctl VIDIOC G FBUF VIDIOC S FBUF eeeeeee eee ee esee ense te tenens ene tn state ens en sense te sense tue 135 ioctl VIDIOC G FMT VIDIOC S FMT VIDIOC TRY FMT ee eeeeee eee eee eene toes nata 140 ioctl VIDIOC G FREQUENCY VIDIOC S FREQUENT Y eee eeee eese eee en eene ene ene s neta 143 ioctl VIDIOC_G_INPUT VIDIOC S INPUT e eee eee ee eee eee eo etos e ene ene ettet to tens tasto setae sees neta 145 ioctl VIDIOC G JPEGCOMP VIDIOC S JPEGCOMBP eeeeee serene teen etna tn netos ene sonato 147 ioctl VIDIOC G MODULATOR VIDIOC S MODULATOR eee eese ee eee eene ene ene eset 149 ioctl VIDIOC G OUTPUT VIDIOC S OUTPUT eeeeeeee eee ee eee eoe e ete tn etos tn stu setae tees neta 152 ioctl VIDIOC G PARM VIDIOC S PARM ssssssssssssssscsssssssssssssssccesssessscssscsssseassassosseeses 154 ioctl VIDIOC G PRIORITY
192. eft and right stereo audio channel 3 as Second Audio Program When the input has only two channels the first is encoded as left and right channel and the second as SAP When the input has only one channel it is used for all audio tracks It is not possible to encode a Second Audio Program only This flag must combine with V4L2 TUNER SUB MONO or V4L2 TUNER SUB STEREO If the hardware does not support the respective audio matrix or the current video standard does not permit SAP the VIDIOC S MODULATOR ioctl shall return an EINVAL error code and driver shall fall back to mono or stereo mode On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The struct v412 modulator index is out of bounds 151 ioctl VIDIOC G OUTPUT VIDIOC S OUTPUT Name VIDIOC G OUTPUT VIDIOC S OUTPUT Query or select the current video output Synopsis int ioctl int fd int request int xargp Arguments fd File descriptor returned by open request VIDIOC G OUTPUT VIDIOC S OUTPUT argp Description To query the current video output applications call the VIDIOC_G_OUTPUT ioctl with a pointer to an integer where the driver stores the number of the output as in the struct v412 output index field This ioctl will fail only when there are no video outputs returning the EINVAL error code To select a video output applications store the number of the desired outp
193. electing a new data format The data formats supported by the VAL2 API are covered in the respective device section in Chapter 4 For a closer look at image formats see Chapter 2 The vIDIOC_S_FMT ioctl is a major turning point in the initialization sequence Prior to this point multiple panel applications can access the same device concurrently to select the current input change controls or modify other properties The first vIDIOC S FMT assigns a logical stream video data VBI data etc exclusively to one file descriptor Exclusive means no other application more precisely no other file descriptor can grab this stream or change device properties inconsistent with the negotiated parameters A video standard change for example when the new standard uses a different number of scan lines can invalidate the selected image format Therefore only the file descriptor owning the stream can make invalidating changes Accordingly multiple file descriptors which grabbed different logical streams prevent each other from interfering with their settings When for example video overlay is about to start or already in progress simultaneous video capturing may be restricted to the same cropping and image size When applications omit the vIDIOC S FMT ioctl its locking side effects are implied by the next step the selection of an I O method with the vVIDIOC_REQBUFS ioctl or implicit with the first read or write call Generally only one logical stream c
194. eliable scan for loaded or installed drivers The user must enter a device name or the application can try the conventional device names Under the device filesystem devfs the minor number options are ignored V4L2 drivers or by proxy the videodev module automatically create the required device files in the dev v41 directory using the conventional device names above 1 1 2 Related Devices Devices can support several related functions For example video capturing video overlay and VBI capturing are related because these functions share amongst other the same video input and tuner frequency V4L and earlier versions of V4L2 used the same device name and minor number for video capturing and overlay but different ones for VBI Experience showed this approach has several problems and to make things worse the V4L videodev module used to prohibit multiple opens of a device As a remedy the present version of the V4L2 API relaxed the concept of device types with specific names and minor numbers For compatibility with old applications drivers must still register different minor numbers to assign a default function to the device But if related functions are supported by the driver they must be available under all registered minor numbers The desired function can be selected after opening the device as described in Chapter 4 Imagine a driver supporting video capturing video overlay raw VBI capturing and FM radio reception It register
195. ements The following VAL2 API elements were superseded by new interfaces and should not be implemented in new drivers Notes l VIDIOC_G_MPEGCOMP and VIDIOC_S_MP This is not implemented in XFree86 EGCOMP ioctls Use Extended Controls Section 1 9 224 Appendix A Video For Linux Two Header File Video for Linux Two header file Copyright C 1999 2007 his program is free sof T it under the terms of th the Free Software Founda at your option any lat his program is distribu ut WITHOUT ANY WARRANTY the contributors tware you can redistribute it and or modify e GNU General Public License as published by tion either version 2 of the License or er version ted in the hope that it will be useful without even the implied warranty of ERCHANTABILITY or FITNE U General Public Licen Qs OH E Alternatively you can re BSD license as stated be Redistribution and use i modification are permit are met 1 Redistributions of so notice this list of 2 Redistributions in bi notice this list of the documentation and distribution 3 The names of its cont products derived from permission SS FOR A PARTICULAR PURPOSE See the se for more details distribute this file under the terms of the low n source and binary forms with or without ted provided that the following conditions urce code must retain the above copyright condit
196. en the function timed out it returns a value of zero on failure it returns 1 and the errno variable is set appropriately When the application did not call VIDIOC_QBUF or VIDIOC STREAMON yet the po11 function succeeds but sets the POLLERR flag in the revents field When use of the read function has been negotiated and the driver does not capture yet the poll function starts capturing When that fails it returns a POLLERR as above Otherwise it waits until data has been captured and can be read When the driver captures continuously as opposed to for example still images the function may return immediately When use of the write function has been negotiated the po11 function just waits until the driver is ready for a non blocking write call All drivers implementing the read or write function or streaming I O must also support the poll function For more details see the po11 manual page Return Value On success poll returns the number structures which have non zero revent s fields or zero if the call timed out On error 1 is returned and the errno variable is set appropriately EBADF One or more of the u ds members specify an invalid file descriptor 193 VAL2 poll EBUSY The driver does not support multiple read or write streams and the device is already in use EFAULT ufds references an inaccessible memory area EINTR The call was interrupted by a signal EINVAL The nf
197. enables them When count is Zero write returns 0 without any other effect When the application does not provide more data in time the previous video frame raw VBI image sliced VPS or WSS data is displayed again Sliced Teletext or Closed Caption data is not repeated the driver inserts a blank line instead Return Value On success the number of bytes written are returned Zero indicates nothing was written On error is returned and the errno variable is set appropriately In this case the next write will start at the beginning of a new frame Possible error codes are 199 V4L2 write EAGAIN Non blocking I O has been selected using the O_NONBLOCK flag and no buffer space was available to write the data immediately EBADF fd is not a valid file descriptor or is not open for writing EBUSY The driver does not support multiple write streams and the device is already in use EFAULT buf references an inaccessible memory area EINTR The call was interrupted by a signal before any data was written EIO I O error This indicates some hardware problem EINVAL The write function is not supported by this driver not on this device or generally not on this type of device 200 Chapter 5 V4L2 Driver Programming to do Chapter 6 Changes The following chapters document the evolution of the VAL2 API errata or extensions They are also intended to help application and driver writers to port or u
198. ense is given a distinguishing version number If the Document specifies that a particular numbered version of this License or any later version applies to it you have the option of following the terms and conditions either of that specified version or of any later version that has 267 Appendix C GNU Free Documentation License been published not as a draft by the Free Software Foundation If the Document does not specify a version number of this License you may choose any version ever published not as a draft by the Free Software Foundation C 12 Addendum To use this License in a document you have written include a copy of the License in the document and put the following copyright and license notices just after the title page Copyright O YEAR YOUR NAME Permission is granted to copy distribute and or modify this document under the terms of the GNU Free Documentation License Version 1 1 or any later version published by the Free Software Foundation with the Invariant Sections being LIST THEIR TITLES with the Front Cover Texts being LIST and with the Back Cover Texts being LIST A copy of the license is included in the section entitled GNU Free Documentation License If you have no Invariant Sections write with no Invariant Sections instead of saying which ones are invariant If you have no Front Cover Texts write no Front Cover Texts instead of Front Cover Texts being LIST likewise for Back Cover Tex
199. ent V4L2 ioctls are VIDIOC_ENUMINPUT VIDIOC G INPUT and VIDIOC S INPUT using struct v412 input as discussed in Section 1 4 The channe1 field counting inputs was renamed to index the video input types were renamed as follows struct video channel type struct v4l2 input type VIDEO TYPE TV VA4L2 INPUT TYPE TUNER IVIDEO TYPE CAMERA VAL2 INPUT TYPE CAMERA Unlike the tuners field expressing the number of tuners of this input VAL2 assumes each video input is connected to at most one tuner However a tuner can have more than one input i e RF connectors and a device can have multiple tuners The index number of the tuner associated with the input if any is stored in field tuner of struct v4I2 input Enumeration of tuners is discussed in Section 1 6 The redundant vibEO vc TUNER flag was dropped Video inputs associated with a tuner are of type V4L2 INPUT TYPE TUNER The viDEO VC AUDIO flag was replaced by the audioset field 204 Chapter 6 Changes V4L2 considers devices with up to 32 audio inputs Each set bit in the audioset field represents one audio input this video input combines with For information about audio inputs and how to switch between them see Section 1 5 The norm field describing the supported video standards was replaced by sta The VAL specification mentions a flag VIDEO VC NORM indicating whether the standard can be changed
200. ent requested video overlay Restrictions of simultaneous capturing and overlay are discussed in Section 4 2 apply Only marginally related to V4L2 XFree86 extended Xv to support hardware YUV to RGB conversion and scaling for faster video playback and added an interface to MPEG 2 decoding hardware This API is useful to display images captured with V4L2 devices 6 3 2 Digital Video VAL2 does not support digital terrestrial cable or satellite broadcast A separate project aiming at digital receivers exists You can find its homepage at http linuxtv org The Linux DVB API has no connection to the V4L2 API except that drivers for hybrid hardware may support both 6 3 3 Audio Interfaces to do OSS ALSA 6 4 Experimental API Elements The following VAL2 API elements are currently experimental and may change in the future Video Output Overlay OSD Interface Section 4 4 VA4L2 BUF TYPE VIDEO OUTPUT OVERLAY enum v412 buf type Table 3 2 e VA4L2 CAP VIDEO OUTPUT OVERLAY VIDIOC QUERYCAP ioctl Table 2 223 VI VI VI VI VI DIOC EN DIOC G ENC INDEX ioctl Chapter 6 Changes UM FRAMESIZES and VIDIOC ENUM FRAMEINTERVALS ioctls DIOC ENCODER CMD and VIDIOC TRY ENCODER CMD ioctls DIOC DBG G REGISTER and VIDIOC DBG S REGISTER ioctls DIOC G CHIP IDENT ioctl 6 5 Obsolete API El
201. equire a search for a device file with a particular major and minor number Drivers could recognize the O_EXCL open flag Presently this is not required so applications cannot know if it really works Actually struct v412_audio ought to have a tuner field like struct v412 input not only making the API more consistent but also permitting radio devices with multiple tuners Some users are already confused by technical terms PAL NTSC and SECAM There is no point asking them to distinguish between B G D or K when the software or hardware can do that automatically An alternative to the current scheme is to use pointers to indices as arguments of VIDIOC G STD and VIDIOC S STD the struct v412 input and struct v412 output std field would be a set of indices like audioset Indices are consistent with the rest of the API and identify the standard unambiguously In the present scheme of things an enumerated standard is looked up by v412 std id Now the standards supported by the inputs of a device can overlap Just assume the tuner and composite input in the example above both exist on a device An enumeration of PAL B G PAL H I suggests a choice which does not exist We cannot merge or omit sets because applications would be unable to find the standards reported by vIDIOC G STD That leaves separate enumerations for each input Also selecting a standard by v412 std id can be ambiguous Advantage of this method is that applications nee
202. er applications can call the ioctl multiple times and thus have multiple outstanding capture requests The VIDIOCSYNC ioctl suspends execution until a particular buffer has been filled Drivers maintain an incoming and outgoing queue VIDIOC_QBUF enqueues any empty buffer into the incoming queue Filled buffers are dequeued from the outgoing queue with the VIDIOC_DQBUF ioctl To wait until filled buffers become available this function select or poll can be used The VIDIOC_STREAMON ioctl must be called once after enqueuing one or more buffers to start capturing Its counterpart VIDIOC_STREAMOFF stops capturing and dequeues all buffers from both queues Applications can query the signal status if known with the VIDIOC ENUMINPUT ioctl For a more in depth discussion of memory mapping and examples see Section 3 2 6 1 10 Reading Raw VBI Data Originally the V4L API did not specify a raw VBI capture interface only the device file dev vbi was reserved for this purpose The only driver supporting this interface was the BTTV driver de facto defining the VAL VBI interface Reading following parameters from the device yields a raw VBI image with the struct v4l2 vbi format VAL BTTV driver sampling rate 28636363 Hz NTSC or any other 525 line standard 35468950 Hz PAL and SECAM 625 line standards loffset samples per line 2048 sample format VAL2 PIX FMT GREY The las
203. er number and the vai field the value to be written into the register 94 ioctl VIDIOC DBG G REGISTER VIDIOC DBG S REGISTER To read a register applications must initialize the match type match chip and reg fields and call VIDIOC DBG G REGISTER with a pointer to this structure On success the driver stores the register value in the va field On failure the structure remains unchanged When match typeis VAL2 CHIP MATCH HOST match chip selects the nth non PC chip on the TV card Drivers may also interpret match chip as a random ID but we recommend against that The number zero always selects the host chip e g the chip connected to the PCI bus You can find out which chips are present with the VIDIOC G CHIP IDENT ioctl When match typeis VAL2 CHIP MATCH I2C DRIVER match chip contains a driver ID as defined in the 1inux i2c id h header file For instance 12C_DRIVERID_SAA7127 will match any chip supported by the saa7127 driver regardless of its C bus address When multiple chips supported by the same driver are present the effect of these ioctls is undefined Again with the VIDIOC G CHIP IDENT ioctl you can find out which PC chips are present When match typeis VAL2 CHIP MATCH I2C ADDR match chip selects a chip by its 7 bit PC bus address Success not guaranteed Due to a flaw in the Linux I C bus driver these ioctls may return successfully without actually reading or writing a regis
204. erear ae vere ed A Video For Linux Two Header File B Video Capture Example 4 eeeeee eese eese eese eee te tenete staat tn etae tn aetas oios ossos sso ss sossss orison C GNU Free Documentation License 4 ee ee eee eee eee eee ee ene etn sete setae etna testae sense tees ense etas ena 263 GI 0 PREAMBEE tee ette delevit itinere iere reete e 263 C 2 1 APPLICABILITY AND DEFINITIONS eee nennen nnne 263 C32 VERBATIM COPYN G iei toten toe terere vette ca cete rte rdiet bets 264 C 4 3 COPYING IN QUANTITY e n E E E E E E ernst nne ernst reser entren 264 25 4 MODIFICATIONS evite tu eee te oett eee tes 265 C 6 5 COMBINING DOCUMENTS cccccccsssccsscessecesceesecessecseecsecessecessesuecssecenseesseeessees 266 C 7 6 COLLECTIONS OF DOCUMENTS eren nnne etrne erret nnne nnnen 266 C 8 7 AGGREGATION WITH INDEPENDENT WORKS eeeeeee 267 29 8 TRANS A ON dette iecit et Medi teet deleti egi 267 C 10 9 TERMINATION oo cecceccccccccesccsssccsccssseceseccseceseecsseesecessecsseccaecessecsssesuecesseessenseeessees 267 C 11 10 FUTURE REVISIONS OF THIS LICENSE een 267 12 Addendutin etr Rh nee 268 List of Ty Pe C 269 hiuc e C 270 viii List of Figures 1 1 Image Cropping Insertion and Scaling eese eene 23 3 1 Field Order Top Field First Transmitted
205. erline field to zero to get a reasonable default Since the remaining flags were replaced as well the flags field itself was removed The interlace flags were replaced by a enum v412 field value in a newly added field field Old flag enum v4I2 field V4L2 FMT FLAG NOT INTERLACED V4L2_FMT_FLAG_INTERLACED V4L2_FIELD_INTERLACED V4L2_FMT_FLAG_COMBINED V4L2_FMT_FLAG_TOPFIELD V4L2_FIELD_TOP V4L2_FMT_FLAG_ODDFIELD V4L2_FMT_FLAG_BOTFIELD V4L2_FIELD_BOTTOM V4L2_FMT_FLAG_EVENFIELD V4AL2 FIELD SEQ TB V4AL2 FIELD SEQ BT VAL2 FIELD ALTERNATE The color space flags were replaced by a enum v412 colorspace value in a newly added colorspace field where one of V4L2_COLORSPACE_SMPTE170M VAL2 COLORSPACE BT878 V4L2 COLORSPACE 470 SYSTEM MOFr VAL2 COLORSPACE 470 SYSTEM BGreplaces VAL2 FMT CS 601YUV In struct v412 requestbuffers the type field was properly defined as enum v412 buf type Buffer types changed as mentioned above A new memory field of type enum v4l2 memory was added to distinguish between I O methods using buffers allocated by the driver or the 216 1 1 1 1 1 1 1 2 2 Uo 4 Nn 6 oo o Chapter 6 Changes application See
206. et by the driver see Table 2 u32 flags Overlay control flags set by application and driver see Table 3 void base Physical base address of the framebuffer that is the address of the pixel in the top left corner of the framebuffer This field is irrelevant to non destructive Video Overlays For destructive Video Overlays applications must provide a base address The driver may accept only base addresses which are a multiple of two four or eight bytes For Video Output Overlays the driver must return a valid base address so applications can find the corresponding Linux framebuffer device see Section 4 4 struct v412_pix_formatt Layout of the frame buffer The v412_pix_format structure is defined in Chapter 2 for clarification the fields and acceptable values are listed below u32 width Width of the frame buffer in pixels u32 height Height of the frame buffer in pixels 136 u32 pixelformat enum v412 field field u32 bytesperline ioctl VIDIOC_G_FBUF VIDIOC S8 FBUF The pixel format of the framebuffer For non destructive Video Overlays this field only defines a format for the struct v4l2 window chromakey field For destructive Video Overlays applications must initialize this field For Video Output Overlays the driver must return a valid format Usually this is an RGB format for example V4AL2 PIX FMT RGB565 but YUV formats only packed YUV formats when chroma keying is used not including V4L2
207. eturn Value On success 0 is returned on error 1 and the errno variable is set appropriately 117 ioctl VIDIOC ENUMSTD EINVAL The struct v412 standard index is out of bounds 118 Notes 1 The supported standards may overlap and we need an unambiguous set to find the current standard returned by VIDIOC_G_STD ioctl VIDIOC G AUDIO VIDIOC S AUDIO Name VIDIOC G AUDIO VIDIOC S AUDIO Query or select the current audio input and its attributes Synopsis int ioctl int fd int request struct v412 audio xargp int ioctl int fd int request const struct v412 audio xargp Arguments fd File descriptor returned by open request VIDIOC G AUDIO VIDIOC S AUDIO argp Description To query the current audio input applications zero out the reserved array of a struct v412 audio and call the vIDIOC G AUDIO ioctl with a pointer to this structure Drivers fill the rest of the structure or return an EINVAL error code when the device has no audio inputs or none which combine with the current video input Audio inputs have one writable property the audio mode To select the current audio input and change the audio mode applications initialize the index and mode fields and the reserved array of a v412 audio structure and call the VIDIOC_S_AUDIO ioctl Drivers may switch to a different audio mode if the request cannot be satisfied However this is a write only ioctl it does not return the actual new audio
208. evices shall support audio input tuner controls cropping and scaling and streaming parameter ioctls as needed The video input and video standard ioctls must be supported by all video overlay devices 67 Chapter 4 Interfaces 4 2 3 Setup Before overlay can commence applications must program the driver with frame buffer parameters namely the address and size of the frame buffer and the image format for example RGB 5 6 5 The VIDIOC G FBUF and VIDIOC S FBUF ioctls are available to get and set these parameters respectively The VIDIOC_S_FBUF ioctl is privileged because it allows to set up DMA into physical memory bypassing the memory protection mechanisms of the kernel Only the superuser can change the frame buffer address and size Users are not supposed to run TV applications as root or with SUID bit set A small helper application with suitable privileges should query the graphics system and program the V4L2 driver at the appropriate time Some devices add the video overlay to the output signal of the graphics card In this case the frame buffer is not modified by the video device and the frame buffer address and pixel format are not needed by the driver The viDIOC S FBUF ioctl is not privileged An application can check for this type of device by calling the VIDIOC_G_FBUF ioctl A driver may support any or none of five clipping blending methods 1 Chroma keying displays the overlaid image only where pixels in the primary graph
209. evices typically have a number of user settable controls such as brightness saturation and so on which would be presented to the user on a graphical user interface But different devices will have different controls available and furthermore the range of possible values and the default value will vary from device to device The control ioctls provide the information and a mechanism to create a nice user interface for these controls that will work correctly with any device All controls are accessed using an ID value VAL2 defines several IDs for specific purposes Drivers can also implement their own custom controls using V4AL2 CID PRIVATE BASE and higher values The pre defined control IDs have the prefix v4L2_CID_ and are listed in Table 1 1 The ID is used when querying the attributes of a control and when getting or setting the current value Generally applications should present controls to the user without assumptions about their purpose Each control comes with a name string the user is supposed to understand When the purpose is non intuitive the driver writer should provide a user manual a user interface plug in or a driver specific panel application Predefined IDs were introduced to change a few controls programmatically for example to mute a device during a channel switch Drivers may enumerate different controls after switching the current video input or output tuner or modulator or audio input or output Different in
210. ffer buf CLEAR buf buf type VA4L2 BUF TYPE VIDEO CAPTURE buf memory V4L2 MEMORY MMAP buf index i if 1 xioctl fd VIDIOC QBUF amp buf errno_exit VIDIOC_QBUF type V4L2_BUF_TYPE_VIDEO_CAPTURE if 1 xioctl fd VIDIOC STREAMON amp type errno exit VIDIOC STREAMON break case IO METHOD USERPTR for i 0 i lt n buffers i struct v412 buffer buf CLEAR buf buf type VA4L2 BUF TYPE VIDEO CAPTURE buf memory VAL2 MEMORY USERPTR buf index i buf m userptr unsigned long buffers i start buf length buffers i length if 1 xioctl fd VIDIOC_QBUF amp buf 255 Appendix B Video Capture Example errno exit VIDIOC QBUF type V4L2 BUF TYPE VIDEO CAPTURE if 1 xioctl fd VIDIOC STREAMON amp type errno exit VIDIOC STREAMON break static void uninit_device void unsigned int i switch io case IO_METHOD_READ free buffers 0 start break case IO_METHOD_MMAP for i 0 i lt n buffers i if 1 munmap buffers i start buffers i length errno exit munmap break case IO METHOD USERPTR for i 0 i lt n buffers i free buffers i start break free buffers static void init read unsigned int buffer size buffers calloc 1 sizeof x buffers if buffers fprintf stderr Out of memory n exit EXIT FAILURE
211. ffer pixel format On success 0 is returned on error 1 and the errno variable is set appropriately EPERM VIDIOC S FBUF can only be called by a privileged user to negotiate the parameters for a destructive overlay EBUSY The framebuffer parameters cannot be changed at this time because overlay is already enabled or capturing is enabled and the hardware cannot capture and overlay simultaneously EINVAL The ioctl is not supported or the vVIDIOC S FBUF parameters are unsuitable 139 ioctl VIDIOC G FMT VIDIOC S FMT VIDIOC TRY FMT Name VIDIOC G FMT VIDIOC S FMT VIDIOC TRY FMT Get or set the data format try a format Synopsis int ioctl int fd int request struct v412 format xargp Arguments fd File descriptor returned by open request VIDIOC_G_FMT VIDIOC_S_FMT VIDIOC_TRY_FMT argp Description These ioctls are used to negotiate the format of data typically image format exchanged between driver and application To query the current parameters applications set the type field of a struct v412_ format to the respective buffer stream type For example video capture devices use V4L2 BUF TYPE VIDEO CAPTURE When the application calls the VIDIOC_G_FMT ioctl with a pointer to this structure the driver fills the respective member of the mt union In case of video capture devices that is the struct v412 pix format pix member When the requested buffer type is not supported drivers return a
212. field will contain a chip ID from the Linux media v412 chip ident h header file and the revision field will contain a driver specific value or zero if no particular revision is associated with this chip When the driver could not identify the selected chip ident will contain VAL2 IDENT UNKNOWN When no chip matched match type and match chip the ioctl will succeed but the ident field will contain V4L2_IDENT_NONE If multiple chips matched ident will contain V4L2 IDENT AMBIGUOUS In all these cases the revision field remains unchanged This ioctl is optional not all drivers may support it It was introduced in Linux 2 6 21 We recommended the v412 dbg utility over calling this ioctl directly It is available from the LinuxTV v4l dvb repository see http linuxtv org repo for access instructions Table 1 struct v4l2 chip ident u32 match type See Table 2 for a list of possible types u32 match chip Match a chip by this number interpreted according to the match type field u32 ident A chip identifier as defined in the Linux media v412 chip ident h header file or one of the values from Table 3 u32 revision A chip revision chip and driver specific Table 2 Chip Match Types V4L2 CHIP MATCH HOST 0 Match the nth chip on the card zero for the host chip Does not match DC chips VA4L2 CHIP MATCH I2C DRIVER 1 Match an LC chip by its driver ID from the linux i2c id h header file VA4L2 C
213. for motion capture The driver may support fewer pixel formats than motion capture eg true color The driver may capture and arithmetically combine multiple successive fields or frames to remove color edge artifacts and reduce the noise in the video data The driver may capture images in slices like a scanner in order to handle larger format images than would otherwise be possible Animage capture operation may be significantly slower than motion capture Moving objects in the image might have excessive motion blur Capture might only work through the read call Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL This ioctl is not supported 157 ioctl VIDIOC G PRIORITY VIDIOC S PRIORITY Name VIDIOC G PRIORITY VIDIOC S PRIORITY Query or request the access priority associated with a file descriptor Synopsis int ioctl int fd int request enum v412 priority argp int ioctl int fd int request const enum v412 priority xargp Arguments fd File descriptor returned by open request VIDIOC G PRIORITY VIDIOC 5 PRIORITY argp Pointer to an enum v4l2 priority type Description To query the current access priority applications call the VIDIOC_G_PRIORITY ioctl with a pointer to an enum v4l2 priority variable where the driver stores the current priority To request an access priority applications store the desired
214. from the driver ignored when writing to the driver except when alpha blending has been negotiated for a Video Overlay or Video Output Overlay Example 2 1 VAL2 PIX FMT BGR24 4 x 4 pixel image Byte Order Each cell is one byte start 4 0 Bo Goo Roo Bor Go Ro Bo Goro Ro Bo Gos Ro start 4 12 Bio Go Ro Bi Gu Ru Bo Gr Ro Bs Gs Re start 4 24 Bo Go Ro Ba Ga Ra B2 Gr R2 B Gz R start 36 B3 Gso R Bu Gs Ra Bo Gx Rx Bs Gs Rx Important Drivers may interpret these formats differently Some RGB formats above are uncommon and were probably defined in error Drivers may interpret them as in Table 2 2 Table 2 2 Packed RGB Image Formats corrected Identifi amp yte 0 in memory Byte 1 Byte 2 Byte 3 Code 76543210 76543210 76543210 76543210 Bit VAL2 PIXrFMTgRGBSGb bo RGBI 35 Identifi amp yte 0 in memory Code 76543210 Bit V4L2_P8XgF MT gRbBb4 b bo R4A44 VAL2 PgXgrMTbRbBb5bi bo RGBO VAL2 PgXgrMrbRbSb bi bo RGBP VA4L2 PIXIFMNIRGBS6S Xgs RGBQ V4L2 PIKrFNTIRGPESSXgs RGBR VAL2 PbxbmrhsbBbRb4 bi bo gt BGR3 V4L2_PIKIEMLLREBIA TI ro gt RGB3 V4L2_Pbxbrbz bebRbB 2 bi bo BGR4 VAL2 PaXagFHSTaRaBPA a ao RGB4 Byte 1 76543210 a3 a2 al ao r3 I2 r ro a T4 I3 I2 Ti ro g4 g3 T4 I3 I2 Tl To gs g4 g3 g2 gi go b4 bs b bi bo g2 gi go b4 bs b bi bo 87 ge 85 84 83 2 81 80 87 ge 85 84 83 82 81 80 87 86 85 84 83 82 81 80 I7 r6 r5 r4 r3 r2
215. fset into a video signal Applications can use the following API to select an area in the video signal query the default area and the hardware limits Despite their name the VIDIOC_CROPCAP VIDIOC G CROP and VIDIOC S CROP ioctls apply to input as well as output devices Scaling requires a source and a target On a video capture or overlay device the source is the video signal and the cropping ioctls determine the area actually sampled The target are images read by the application or overlaid onto the graphics screen Their size and position for an overlay is negotiated with the VIDIOC_G_FMT and VIDIOC S FMT ioctls On a video output device the source are the images passed in by the application and their size is again negotiated with the VIDIOC_G S_FMT ioctls or may be encoded in a compressed video stream The target is the video signal and the cropping ioctls determine the area where the images are inserted Source and target rectangles are defined even if the device does not support scaling or the VIDIOC G S CROP ioctls Their size and position where applicable will be fixed in this case All capture and output device must support the VIDIOC CROPCAP ioctl such that applications can determine if scaling takes place 1 11 1 Cropping Structures Figure 1 1 Image Cropping Insertion and Scaling v4I2 cropcap defrect crucis v4l2_crop c v4l2_format v4l2_cropcap bounds For capture
216. ges into a VGA signal or graphics into a video signal Video Output Overlays are always non destructive To get the current parameters applications call the VIDIOC_G_FBUF ioctl with a pointer to a v4I2 framebuffer structure The driver fills all fields of the structure or returns an EINVAL error code when overlays are not supported To set the parameters for a Video Output Overlay applications must initialize the 1ags field of a struct v412 framebuffer Since the framebuffer is implemented on the TV card all other parameters are determined by the driver When an application calls VIDIOC_S_FBUF with a pointer to this structure the driver prepares for the overlay and returns the framebuffer parameters as VIDIOC G FBUF does or it returns an error code 135 ioctl VIDIOC_G_FBUF VIDIOC S FBUF To set the parameters for a non destructive Video Overlay applications must initialize the 1ags field the fmt substructure and call VIDIOC_S_FBUF Again the driver prepares for the overlay and returns the framebuffer parameters as VIDIOC G FBUF does or it returns an error code For a destructive Video Overlay applications must additionally provide a base address Setting up a DMA to a random memory location can jeopardize the system security its stability or even damage the hardware therefore only the superuser can set the parameters for a destructive video overlay Table 1 struct v412_framebuffer u32 capability Overlay capability flags s
217. h as the complex memory mapping I O can be inadequate for some devices we have no reason to require this interface which is most useful for simple applications capturing still images At the driver level select and po11 are the same and select is too important to be optional One could use one file descriptor and set the buffer type field accordingly when calling VIDIOC QBUF etc but it makes the select function ambiguous We also like the clean approach of one file descriptor per logical stream Video overlay for example is also a logical stream although the CPU is not needed for continuous operation Random enqueue order permits applications processing images out of order such as video codecs to return buffers earlier reducing the probability of data loss Random fill order allows drivers to reuse buffers on a LIFO basis taking advantage of caches holding scatter gather lists and the like At the driver level select and po11 are the same and select is too important to be optional The rest should be evident We expect that frequently used buffers are typically not swapped out Anyway the process of swapping locking or generating scatter gather lists may be time consuming The delay can be masked by the depth of the incoming buffer queue and perhaps by maintaining caches assuming a buffer will be soon enqueued again On the other hand to optimize memory usage drivers can limit the number of buffers locked in adva
218. he returned parameters are valid but the required resources are currently not available That may happen for instance when the video and VBI areas to capture would overlap or when the driver supports multiple opens and another process already requested VBI capturing or output Anyway applications 75 Chapter 4 Interfaces must expect other resource allocation points which may return EBUSY at the VIDIOC_STREAMON ioctl and the first read write and select call VBI devices must implement both the VIDIOC_G_FMT and VIDIOC S FMT ioctl even if VIDIOC_S_FMT ignores all requests and always returns default parameters as VIDIOC G FMT does VIDIOC TRY FMT is optional Table 4 4 struct v412 vbi format u32 sampling rate u32 offset u32 samples per line u32 sample format u32 start 2 u32 count 2 Drivers should be as flexibility as possible For example it may be possible to extend or move the VBI capture window u32 flags u32 reserved 2 Notes Table 4 5 Raw VBI Format Flags Samples per second i e unit 1 Hz Horizontal offset of the VBI image relative to the leading edge of the line synchronization pulse and counted in samples The first sample in the VBI image will be located offset sampling rate seconds following the leading edge See also Figure 4 1 Defines the sample format as in Chapter 2 a four character code a Usually this is V4L2_PIX_FMT_GREY i e each sample consists of 8 bits
219. he behavior of the control See the VIDIOC_QUERYCTRL documentation for more details 1 9 5 MPEG Control Reference Below all controls within the MPEG control class are described First the generic controls then controls specific for certain hardware 1 9 5 1 Generic MPEG Controls Table 1 2 MPEG Control IDs ID Type Description V4L2 CID MPEG CLASS class The MPEG class descriptor Calling VIDIOC_QUERYCTRI for this control will return a description of this contro V4L2 CID MPEG STREAM TYPE enum The MPEG 1 2 or 4 output stream type One cannot assume anything here Each hardware MPEG encoder ten ENTRYTBL not supported 16 V4L2 V4L2 V4L2 V4L2 V4L2 V4L2 V4L2 V4L2 V4L2 V4L2 V4L2 V4L2 Description Chapter 1 Common API Elements Type CID_MP EG_STR EAM PID PMT integer Program Map Table Packet ID for the MPEG transport stream default 16 CID MP EG STR EAM PID AUDIO integer Audio Packet ID for the MPEG transport stream default 256 CID MP EG STR EAM PID VIDEO integer Video Packet ID for the MPEG transport stream default 260 CID MP EG STR EAM PID PCR integer Packet ID for the MPEG transport stream carrying PCR fields default 259 CID MP EG STR EAM PES ID AUDIO integer Audio ID for MPEG PES CID MP EG STR EAM PES ID
220. he discarding policy is not reported and cannot be changed For minimum requirements see Chapter 4 Return Value On success the number of bytes read is returned It is not an error if this number is smaller than the number of bytes requested or the amount of data required for one frame This may happen for example because read was interrupted by a signal On error 1 is returned and the errno variable is set appropriately In this case the next read will start at the beginning of a new frame Possible error codes are EAGAIN Non blocking I O has been selected using O NONBLOCK and no data was immediately available for reading EBADF dis not a valid file descriptor or is not open for reading or the process already has the maximum number of files open EBUSY The driver does not support multiple read streams and the device is already in use EFAULT buf references an inaccessible memory area EINTR The call was interrupted by a signal before any data was read EIO I O error This indicates some hardware problem or a failure to communicate with a remote device USB camera etc EINVAL The read function is not supported by this driver not on this device or generally not on this type of device 196 V4L2 select Name v412 select Synchronous I O multiplexing Synopsis finclude lt sys time h gt include lt sys types h gt include lt unistd h gt int select int nfds fd set readfds
221. he mmap function asks to map length bytes starting at o set in the memory of the device specified by d into the application address space preferably at address start This latter address is a hint only and is usually specified as 0 Suitable length and offset parameters are queried with the VIDIOC_QUERYBUF ioctl Buffers must be allocated with the VIDIOC_REQBUFS ioctl before they can be queried To unmap buffers the munmap function is used Return Value On success mmap returns a pointer to the mapped buffer On error MAP FAILED 1 is returned and the errno variable is set appropriately Possible error codes are EBADF dis not a valid file descriptor EACCES fd is not open for reading and writing EINVAL The start or length or offset are not suitable E g they are too large or not aligned on a PAGESIZE boundary The 1ags or prot value is not supported No buffers have been allocated with the VIDIOC_REQBUFS ioctl ENOMEM Not enough physical or virtual memory was available to complete the request 189 V4L2 munmap Name v412 munmap Unmap device memory Synopsis include lt unistd h gt include lt sys mman h gt int munmap void xstart size_t length Arguments start Address of the mapped buffer as returned by the mmap function length Length of the mapped buffer This must be the same value as given to mmap and returned by the driver in
222. he tuner of the current video input or a radio tuner is queried Note that VIDIOC S TUNER does not switch the current tuner when there is more than one at all The tuner is solely determined by the current video input Drivers must support both ioctls and set the V4L2 CAP TUNER flag in the struct v412 capability returned by the vIDIOC QUERYCAP ioctl when the device has one or more tuners 1 6 2 Modulators Video output devices can have one or more modulators uh modulating a video signal for radiation or connection to the antenna input of a TV set or video recorder Each modulator is associated with one or more video outputs depending on the number of RF connectors on the modulator The type field of the respective struct v412 output returned by the VIDIOC_ENUMOUTPUT ioctl is set to V4L2 OUTPUT TYPE MODULATOR and its modulator field contains the index number of the modulator This specification does not define radio output devices To query and change modulator properties applications use the vVIDIOC G MODULATOR and VIDIOC S MODULATOR ioctl Note that VIDIOC S MODULATOR does not switch the current modulator when there is more than one at all The modulator is solely determined by the current video output Drivers must support both ioctls and set the v4L2 CAP TUNER sic flag in the Chapter 1 Common API Elements struct v4I2 capability returned by the VIDIOC_QUERYCAP ioctl when the device has one or more modulato
223. hold up to entries cap entries This number can be lower or higher than V4L2_ENC_IDX_ENTRIES but not zero When the application fails to read the meta data in time the oldest entries will be lost When the buffer is empty or no capturing encoding is in progress ent ries will be zero Currently this ioctl is only defined for MPEG 2 program streams and video elementary streams Table 1 struct v412_enc_idx 130 u32 u32 u32 struct v412 enc idx entrentry VA4L2 Table 2 struct v4l2 enc idx entry u64 u64 u32 u32 u32 entries entries cap ioctl VIDIOC G ENC INDEX The number of entries the driver stored in the entry array The number of entries the driver can buffer Must be greater than zero Reserved for future extensions Drivers must set the array to zero offset pts length flags reserved 2 Table 3 Index Entry Flags V4L2_ENC_IDX_FRAME_I V4L2_ENC_IDX_FRAME_P V4L2_ENC_IDX_FRAME_B V4L2_ENC_IDX_FRAME_MASK Return Value 0x00 0x01 0x02 OxOF ENC_IDX_Mfeta data about a compressed video stream Each element of the array corresponds to one picture sorted in ascending order by their offset The offset in bytes from the beginning of the compressed video stream to the beginning of this picture that is a PES packet header as defined in ISO 13818 1 or a picture header as defined in ISO 13818 2 When the encoder i
224. ication of the Modified Version to whoever possesses a copy of it In addition you must do these things in the Modified Version e A Use in the Title Page and on the covers if any a title distinct from that of the Document and from those of previous versions which should if there were any be listed in the History section of the Document You may use the same title as a previous version if the original publisher of that version gives permission e B List on the Title Page as authors one or more persons or entities responsible for authorship of the modifications in the Modified Version together with at least five of the principal authors of the Document all of its principal authors if it has less than five e C State on the Title Page the name of the publisher of the Modified Version as the publisher D Preserve all the copyright notices of the Document E Add an appropriate copyright notice for your modifications adjacent to the other copyright notices e F Include immediately after the copyright notices a license notice giving the public permission to use the Modified Version under the terms of this License in the form shown in the Addendum below G Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document s license notice H Include an unaltered copy of this License e I Preserve the section entitled History and its title and add to it an item
225. ice typically stores captured images directly in the video memory of a graphics card with hardware clipping and scaling V4L2 CAP VBI CAPTURE 0x00000010 The device supports the Raw VBI Capture interface providing Teletext and Closed Caption data V4L2 CAP VBI OUTPUT 0x00000020 The device supports the Raw VBI Output interface V4L2 CAP SLICED VBI CAPTURE 0x00000040The device supports the Sliced VBI Capture interface VA4L2 CAP SLICED VBI OUTPUT 0x00000080The device supports the Sliced VBI Output interface V4L2 CAP RDS CAPTURE 0x00000100 to be defined 175 ioctl VIDIOC QUERYCAP V4L2 CAP VIDEO OUTPUT OVERLAGx00000200The device supports the Video Output Overlay OSD interface Unlike the Video Overlay interface this is a secondary function of video output devices and overlays an image onto an outgoing video signal When the driver sets this flag it must clear the V4L2 CAP TUNER V4L2 CAP AUDIO V4L2 CAP RADIO VAL2 CAP READWRITE V4L2 CAP ASYNCIO V4L2 CAP STREAMING VAL2 CAP VID EO OV ERLAY flag and vice versa a 0x00010000 The device has some sort of tuner or modulator to receive or emit RF modulated video signals For more information about tuner and modulator programming see Section 1 6 0x00020000 The device has audio inputs or outputs It may or may not support audio recording or playback in PCM or compressed formats
226. ics surface assume a certain color 2 A bitmap can be specified where each bit corresponds to a pixel in the overlaid image When the bit is set the corresponding video pixel is displayed otherwise a pixel of the graphics surface 3 A list of clipping rectangles can be specified In these regions no video is displayed so the graphics surface can be seen here 4 The framebuffer has an alpha channel that can be used to clip or blend the framebuffer with the video 5 A global alpha value can be specified to blend the framebuffer contents with video images When simultaneous capturing and overlay is supported and the hardware prohibits different image and frame buffer formats the format requested first takes precedence The attempt to capture VIDIOC_S_FMT or overlay VIDIOC S FBUF may fail with an EBUSY error code or return accordingly modified parameters 4 2 4 Overlay Window The overlaid image is determined by cropping and overlay window parameters The former select an area of the video picture to capture the latter how images are overlaid and clipped Cropping initialization at minimum requires to reset the parameters to defaults An example is given in Section 1 11 The overlay window is described by a struct v412 window It defines the size of the image its position over the graphics surface and the clipping to be applied To get the current parameters applications set the type field of a struct v412_format to VAL2 BUF TYP
227. ict in title with any Invariant Section If the Modified Version includes new front matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document you may at your option designate some or all of these sections as invariant To do this add their titles to the list of Invariant Sections in the Modified Version s license notice These titles must be distinct from any other section titles You may add a section entitled Endorsements provided it contains nothing but endorsements of your Modified Version by various parties for example statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard You may add a passage of up to five words as a Front Cover Text and a passage of up to 25 words as a Back Cover Text to the end of the list of Cover Texts in the Modified Version Only one passage of Front Cover Text and one of Back Cover Text may be added by or through arrangements made by any one entity If the Document already includes a cover text for the same cover previously added by you or by arrangement made by the same entity you are acting on behalf of you may not add another but you may replace the old one on explicit permission from the previous publisher that added the old one The author s and publisher s of the Document do not by this License give permission to use their names for publicity for or to assert or imply endo
228. id x buf m userptr if 1 xioctl fd VIDIOC_QBUF amp buf errno exit VIDIOC QBUF 253 break return 1 static void mainloop unsigned int count count 100 count gt 0 a7 while for Appendix B Video Capture Example void fd_set fds struct timeval tv int r FD_ZERO amp fds FD_SET fd amp fds Timeout x tv tv sec 2 tv tv usec 0 r select fd 1 amp fds NULL NULL amp tv if 1 r if EINTR errno continue errno exit select if 0 r fprintf stderr select timeout n exit EXIT_FAILURE if read_frame break EAGAIN continue select loop x static void stop capturing enum v412_buf_type type io ETHOD_R switch EAD case IO M x Nothing to do break void 254 Appendix B Video Capture Example case IO METHOD MMAP case IO METHOD USERPTR type V4L2 BUF TYPE VIDEO CAPTURE if 1 xioctl fd VIDIOC STREAMOFF amp type errno exit VIDIOC STREAMOFF break static void start_capturing void unsigned int i enum v412_buf_type type switch io case IO_METHOD_READ Nothing to do break case IO_METHOD_MMAP for 1 5 0 LI n bufters i 1 struct v412 bu
229. ideodev h file in Linux 2 2 x with devfs patches applied was fixed 2001 03 02 Certain VAL ioctls which pass data in both direction although they are defined with read only parameter did not work correctly through the backward compatibility layer Solution 2001 04 13 Big endian 16 bit RGB formats were added 2001 09 17 New YUV formats and the VIDIOC G FREQUENCY and VIDIOC S FREQUENCY ioctls were added The old VIDIOC_G_FREQ and VIDIOC_S_FREQ ioctls did not take multiple tuners into account 2000 09 18 vaL2 BUF TYPE VBI was added This may break compatibility as the VIDIOC_G_FMT and VIDIOC S FMT ioctls may fail now if the struct v412 fmt type field does not contain VA4L2 BUF TYPE VBI In the documentation of the struct v412 vbi format offset field the ambiguous phrase rising edge was changed to leading edge 6 2 7 VAL2 Version 0 20 2000 11 23 A number of changes were made to the raw VBI interface 1 Figures clarifying the line numbering scheme were added to the V4L2 API specification The start 0 and start 1 fields no longer count line numbers beginning at zero Rationale a The previous definition was unclear b The start values are ordinal numbers c There is no point in inventing a new line numbering scheme We now use line number as defined by ITU R period Compatibility Add one to the start values Applications depending on the previous semantics may not function correctly N The restricti
230. ignal but not both at the same time To determine the currently selected services applications set the type field of struct v412 format to V4L2 BUF TYPE SLICED VBI CAPTURE OrV4L2 BUF TYPE SLICED VBI OUTPUT and the VIDIOC G FMT ioctl fills the fmt sliced member a struct v412 sliced vbi format Applications can request different parameters by initializing or modifying the fmt sliced member and calling the VIDIOC_S_FMT ioctl with a pointer to the v412 format structure The sliced VBI API is more complicated than the raw VBI API because the hardware must be told which VBI service to expect on each scan line Not all services may be supported by the hardware on all lines this is especially true for VBI output where Teletext is often unsupported and other services can only be inserted in one specific line In many cases however it is sufficient to just set the service set field to the required services and let the driver fill the service lines array according to hardware capabilities Only if more precise control is needed should the programmer set the service lines array explicitly The vIDIOC_S_FMT ioctl returns an EINVAL error code only when the given parameters are ambiguous otherwise it modifies the parameters according to hardware capabilities When the driver allocates resources at this point it may return an EBUSY error code if the required resources are temporarily unavailable Other resource a
231. ilities can vary in particular the sampling frequency To properly interpret the data V4L2 specifies an ioctl to query the sampling parameters Moreover to allow for some flexibility applications can also suggest different parameters As usual these parameters are not reset at open time to permit Unix tool chains programming a device and then reading from it as if it was a plain file Well written V4L2 applications should always ensure they really get what they want requesting reasonable parameters and then checking if the actual parameters are suitable To query the current raw VBI capture parameters applications set the t ype field of a struct v412 format to V4AL2 BUF TYPE VBI CAPTURE or V4L2 BUF TYPE VBI OUTPUT and call the viDIOC G FMT ioctl with a pointer to this structure Drivers fill the struct v412 vbi format vbi member of the mt union To request different parameters applications set the type field of a struct v412 format as above and initialize all fields of the struct v412 vbi format vbi member of the fmt union or better just modify the results of VIDIOC_G_FMT and call the VIDIOC_S_FMT ioctl with a pointer to this structure Drivers return an EINVAL error code only when the given parameters are ambiguous otherwise they modify the parameters according to the hardware capabilites and return the actual parameters When the driver allocates resources at this point it may return an EBUSY error code to indicate t
232. ill be passed sequentially all lines of the first field followed by all lines of the second field compare Section 3 6 VAL2 FIELD SEQ TB and V4L2 FIELD SEQ BT whether the top or bottom field is first in memory depends on the video standard When this flag is set the two fields are interlaced cf v4 2 FIELD INTERLACED The first line of the first field followed by the first line of the second field then the two second lines and so on Such a layout may be necessary when the hardware has been programmed to capture or output interlaced video images and is unable to separate the fields for VBI capturing at the same time For simplicity setting this flag implies that both count values are equal and non zero Notes a Most VBI services transmit on both fields but some have different semantics depending on the field numbei Figure 4 1 Line synchronization offset lt gt Line synchr pulse I a H Line blanking White Level Black Level Sync Level 77 Figure 4 2 ITU R 525 line numbering M NTSC and M PAL Chapter 4 Interfaces 524 525 1 2 3 4 5 6 7 8 9 10 11 12 261 262 1 2 3 4 5 6 7 8 9 10 11 12 e B oy Te atti 1st field 262 263 264 265 266 267 268 269 270 271 272 273 274 275 262 263 1 2 3 4 5 6 v4 8 9 10 11 12 LaL 0 P4 LILTLILLEATYTTT 2nd field 78 Chapter 4 Interfaces
233. including padding Example 2 1 vVAL2 PIX FMT YVU4204 x 4 pixel image Byte Order Each cell is one byte start 4 0 Y oo Y oi Y o Y os start 4 Y io Yu Yr Y 13 start 8 Y 20 Y n Y Y start 4 12 Y 30 Y s Y Y 33 start 16 Croo Croi start 18 Crio Cru start 20 Cboo Cbo start 22 Cbio Cbii Color Sample Location 0 1 2 0 Y C C 1 Y Y Y 2 Y Y Y C C 3 Y Y Y 45 VAL2 PIX FMT YVUA410 YVU9 V4L2 PIX FMT YUV410 YUV9 Name VAL2 PIX FMT YVU410 VA4L2 PIX FMT YUV410 Planar formats with 4 horizontal and vertical chroma resolution also known as YUV 4 1 0 Description These are planar formats as opposed to a packed format The three components are separated into three sub images or planes The Y plane is first The Y plane has one byte per pixel For VAL2 PIX FMT YVU410 the Cr plane immediately follows the Y plane in memory The Cr plane is 14 the width and the height of the Y plane and of the image Each Cr belongs to 16 pixels a four by four square of the image Following the Cr plane is the Cb plane just like the Cr plane V4L2 PIX FMT YUV410 is the same except the Cb plane comes first then the Cr plane If the Y plane has pad bytes after each row then the Cr and Cb planes have 4 as many pad bytes after their rows In other words four Cx rows including padding are exactly as long as one Y row including padding Example 2 1 v4L2_PIX_FMT_yvu410 4 x 4 pixel image Byt
234. ing and streaming parameter ioctls as needed The video output and video standard ioctls must be supported by all video output devices 4 3 3 Image Format Negotiation The output is determined by cropping and image format parameters The former select an area of the video picture where the image will appear the latter how images are stored in memory i e in RGB or YUV format the number of bits per pixel or width and height Together they also define how images are scaled in the process As usual these parameters are not reset at open time to permit Unix tool chains programming a device and then writing to it as if it was a plain file Well written V4L2 applications ensure they really get what they want including cropping and scaling Cropping initialization at minimum requires to reset the parameters to defaults An example is given in Section 1 11 To query the current image format applications set the t ype field of a struct v4I2 format to V4L2 BUF TYPE VIDEO OUTPUT and call the VIDIOC_G_FMT ioctl with a pointer to this structure Drivers fill the struct v412 pix format pix member of the fmt union To request different parameters applications set the type field of a struct v412 format as above and initialize all fields of the struct v412 pix format vbi member of the fmt union or better just modify the results of VIDIOC_G_FMT and call the VIDIOC_S_FMT ioctl with a pointer to this structure Drivers may adjust the p
235. ion of it either copied verbatim or with modifications and or translated into another language A Secondary Section is a named appendix or a front matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document s overall subject or to related matters and contains nothing that could fall directly within that overall subject For example if the Document is in part a textbook of mathematics a Secondary Section may not explain any mathematics The relationship could be a matter of historical connection with the subject or with related matters or of legal commercial philosophical ethical or political position regarding them The Invariant Sections are certain Secondary Sections whose titles are designated as being those of Invariant Sections in the notice that says that the Document is released under this License The Cover Texts are certain short passages of text that are listed as Front Cover Texts or Back Cover Texts in the notice that says that the Document is released under this License A Transparent copy of the Document means a machine readable copy represented in a format whose specification is available to the general public whose contents can be viewed and edited directly and straightforwardly with generic text editors or for images composed of pixels generic paint programs or for drawings some widely available drawing editor and that is suita
236. ions and the following disclaimer nary form must reproduce the above copyright conditions and the following disclaimer in or other materials provided with the ributors may not be used to endorse or promote this software without specific prior written THIS SOFTWARE IS PROVIDE AS IS AND ANY EXPRESS LIMITED TO THE IMPLIED A PARTICULAR PURPOSE ARE D BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS OR IMPLIED WARRANTIES INCLUDING BUT NOT WARRANTIES OF MERCHANTABILITY AND FITNESS FOR DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT xj P OWNER OR CONTRIBUTORS BE SPECIAL EXEMPLARY OR C TABLE FOR ANY DIRECT INDIRECT INCIDENTAL ONSEQUENTIAL DAMAGES INCLUDING BUT NOT LIMITED TO PROCUREME OF SUBST PROFITS OR BUSINESS INT LIABILITY WHETHER IN CO NEGLIGENCE OR OTHERWISE ITUTE GOODS OR SERVICES LOSS OF USE DATA OR ERRUPTION HOWEVER CAUSED AND ON ANY THEORY OF NTRACT STRICT LIABILITY OR TORT INCLUDING ARISING IN ANY WAY OUT OF THE USE OF THIS I SOFTWARE EV IF ADVISE Header file for v4l with public API All kernel specific stuff D OF THE POSSIBILITY OF SUCH DAMAGE or V4L2 drivers and applications were moved to media v412
237. ith a single 266 Appendix C GNU Free Documentation License copy that is included in the collection provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects You may extract a single document from such a collection and dispbibute it individually under this License provided you insert a copy of this License into the extracted document and follow this License in all other respects regarding verbatim copying of that document C 8 7 AGGREGATION WITH INDEPENDENT WORKS A compilation of the Document or its derivatives with other separate and independent documents or works in or on a volume of a storage or distribution medium does not as a whole count as a Modified Version of the Document provided no compilation copyright is claimed for the compilation Such a compilation is called an aggregate and this License does not apply to the other self contained works thus compiled with the Document on account of their being thus compiled if they are not themselves derivative works of the Document If the Cover Text requirement of section 3 is applicable to these copies of the Document then if the Document is less than one quarter of the entire aggregate the Document s Cover Texts may be placed on covers that surround only the Document within the aggregate Otherwise they must appear on covers around the whole aggregate C 9 8 TRANSLATION Translation is considered a kind of
238. itive values move the camera up negative v integer This control sets the focal point of the camera to the specified position The unit is undefined Positive values set V4L2 CID FOCUS RELATIVE integer This control moves the focal point of the camera by the specified amount The unit is undefined Positive values V4L2 CID FOCUS AUTO boolean Enables automatic focus adjustments The effect of manual focus adjustments while this feature is enabled is un 21 Chapter 1 Common API Elements 1 10 Data Formats 1 10 1 Data Format Negotiation Different devices exchange different kinds of data with applications for example video images raw or sliced VBI data RDS datagrams Even within one kind many different formats are possible in particular an abundance of image formats Although drivers must provide a default and the selection persists across closing and reopening a device applications should always negotiate a data format before engaging in data exchange Negotiation means the application asks for a particular format and the driver selects and reports the best the hardware can do to satisfy the request Of course applications can also just query the current selection A single mechanism exists to negotiate all data formats using the aggregate struct v412 format and the viDIOC G FMT and VIDIOC S FMT ioctls Additionally the vib1roC TRY FMT ioctl can be used to examine what the hardware could do without actually s
239. ivers 1999 03 31 Better compatibility for v41 memory capture ioctls Requires changes to drivers to fully support new compatibility features see Driver Writer s Guide and v4l2cap c Added new control IDs V4L2_CID_HFLIP _VFLIP Changed V4AL2 PIX FMT YUV422P to _YUV422P and _YUV411P to YUVATIP 1999 04 04 Added a few more control IDs 1999 04 07 Added the button control type 1999 05 02 Fixed a typo in videodev h and added the V4L2_CTRL_FLAG_GRAYED later V4L2 CTRL FLAG GRABBED flag 1999 05 20 Definition of VIDIOC G CTRL was wrong causing a malfunction of this ioctl 1999 06 05 Changed the value of V4L2_CID_WHITENESS 6 2 5 VAL2 Version 0 20 1999 09 10 Version 0 20 introduced a number of changes which were not backward compatible with 0 19 and earlier versions Purpose of these changes was to simplify the API while making it more extensible and following common Linux driver API conventions 1 Some typos in vVAL2 FMT FLAG symbols were fixed struct v412 clip was changed for compatibility with v41 1999 08 30 2 VAL2 TUNER SUB LANG1 was added 1999 09 05 211 3 EIN CA oO Chapter 6 Changes All ioctl commands that used an integer argument now take a pointer to an integer Where it makes sense ioctls will return the actual new value in the integer pointed to by the argument a common convention in the V4L2 API The affected ioctls are VIDIOC PREVIEW VIDIOC_STREAMON VIDIOC_STREAMOFF
240. k Buffers remain locked until dequeued until the vIDIOC STREAMOFF or VIDIOC REQBUFS ioctl are called or until the device is closed Applications call the VIDIOC_DQBUF ioctl to dequeue a filled capturing or displayed output buffer from the driver s outgoing queue They just set the type and memory fields of a struct v412_buffer as above when vIDIOC DOBUF is called with a pointer to this structure the driver fills the remaining fields or returns an error code By default VIDIOC_DQBUF blocks when no buffer is in the outgoing queue When the O NONBLOCK flag was given to the open function VIDIOC DOBUF returns immediately with an EAGAIN error code when no buffer is available The v412 buffer structure is specified in Section 3 5 Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EAGAIN Non blocking I O has been selected using O_NONBLOCK and no buffer was in the outgoing queue EINVAL The buffer t ype is not supported or the index is out of bounds or no buffers have been allocated yet or the userptr or length are invalid ENOMEM Not enough physical or virtual memory was available to enqueue a user pointer buffer EIO VIDIOC DOBUF failed due to an internal error Can also indicate temporary problems like signal loss Note the driver might dequeue an empty buffer despite returning an error or even stop capturing 171 ioctl VIDIOC QUERYBUF Name VIDIOC
241. kernel was not compiled with the CONFIG VIDEO ADV DEBUG option or the match type is invalid or the selected chip or register does not exist EPERM Insufficient permissions Root privileges are required to execute these ioctls 96 ioctl VIDIOC ENCODER CMD VIDIOC TRY ENCODER CMD Name VIDIOC ENCODER CMD VIDIOC TRY ENCODER CMD Execute an encoder command Synopsis int ioctl int fd int request struct v412 encoder cmd xargp Arguments fd File descriptor returned by open request VIDIOC ENCODER CMD VIDIOC TRY ENCODER CMD argp Description Experimental This is an experimental interface and may change in the future These ioctls control an audio video usually MPEG encoder VIDIOC ENCODER CMD sends a command to the encoder VIDIOC TRY ENCODER CMD can be used to try a command without actually executing it To send a command applications must initialize all fields of a struct v412 encoder cmd and call VIDIOC ENCODER CMD Or VIDIOC TRY ENCODER CMD with a pointer to this structure The cmd field must contain the command code The flags field is currently only used by the STOP command and contains one bit If the v4 2 ENC CMD STOP AT GOP END flag is set encoding will continue until the end of the current Group Of Pictures otherwise it will stop immediately A read call sends a START command to the encoder if it has not
242. kets When the id of a packet for output is zero the contents of the data field are undefined and the driver must no longer insert data on the requested fieldand line u32 field The video field number this data has been captured from or shall be inserted at 0 for the first field 1 for the second field u32 line The field as opposed to frame line number this data has been captured from or shall be inserted at See Figure 4 2 and Figure 4 3 for valid values Sliced VBI capture devices can set the line number of all packets to 0 if the hardware cannot reliably identify scan lines The field number must always be valid u32 reserved This field is reserved for future extensions Applications and drivers must set it to zero u8 data 48 The packet payload See Table 2 for the contents and number of bytes passed for each data type The contents of padding bytes at the end of this array are undefined drivers and applications shall ignore them Packets are always passed in ascending line number order without duplicate line numbers The write function and the VIDIOC OBUF ioctl must return an EINVAL error code when applications violate this rule They must also return an EINVAL error code when applications pass an incorrect field or line number or a combination of field line and id which has not been negotiated with the VIDIOC G FMT or VIDIOC_S_FMT ioctl When the line numbers are unknown the driver must pass the packets in transmi
243. ld to a 64 bit integer and I will change the v412 masterclock gettime function used only by drivers to return a 64 bit integer A sequence field was added to struct v412 buffer The sequence field counts captured frames it is ignored by output devices When a capture driver drops a frame the sequence number of that frame is skipped 212 Chapter 6 Changes 6 2 6 V4L2 Version 0 20 incremental changes 1999 12 23 In struct v412 vbi format the reserved1 field became offset Previously drivers were required to clear the reserved1 field 2000 01 13 The V4L2 FMT FLAG NOT INTERLACED flag was added 2000 07 31 The 1inux poll h header is now included by videodev h for compatibility with the original videodev h file 2000 11 20 v4 2000 11 25 v4 N YPE VBI OUTPUT and V4L2 PIX FMT Y41P were added N YPE VBI INPUT was added 2000 12 04 A couple typos in symbol names were fixed 2001 01 18 To avoid namespace conflicts the fourcc macro defined in the videodev h header file was renamed to v412 fourcc 2001 01 25 A possible driver level compatibility problem between the videodev h file in Linux 2 4 0 and the videodev h file included in the videodevx patch was fixed Users of an earlier version of videodevx on Linux 2 4 0 should recompile their VAL and VAL2 drivers 2001 01 26 A possible kernel level incompatibility between the videodev h file in the videodevx patch and the v
244. le descriptor returned by open request VIDIOC G STD VIDIOC S STD argp Description To query and select the current video standard applications use the viDIOC G STD and VIDIOC S STD ioctls which take a pointer to a v412 std id type as argument vIDIOC G STD can return a single flag or a set of flags as in struct v4I2 standard field id The flags must be unambiguous such that they appear in only one enumerated v412 standard structure VIDIOC S STD accepts one or more flags being a write only ioctl it does not return the actual new standard as VIDIOC_G_STD does When no flags are given or the current input does not support the requested standard the driver returns an EINVAL error code When the standard set is ambiguous drivers may return EINVAL or choose any of the requested standards Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL This ioctl is not supported or the vIDIOC S STD parameter was unsuitable 162 ioctl VIDIOC G TUNER VIDIOC S TUNER Name VIDIOC G TUNER VIDIOC S TUNER Get or set tuner attributes Synopsis int ioctl int fd int request struct v412 tuner xargp int ioctl int fd int request const struct v412 tuner xargp Arguments fd File descriptor returned by open request VIDIOC G TUNER VIDIOC S5 TUNER argp Description To query the attributes of a tuner applications initialize the index field and zero out
245. llocation points which may return EBUSY can be the VIDIOC STREAMON ioctl and the first read write and select call Table 4 6 struct v412 sliced vbi format u32 service set If service setis non zero when passed with VIDIOC S FMT or V ul6 service lines 2 24 Applications initialize this array with sets of data services the driver Element 525 line systems 625 line systems service lines 0 l 1 1 service lines 0 2323 23 service lines l 164 314 82 Chapter 4 Interfaces service lines l 23 56 336 Drivers must set service lines 0 0 and service 1ines 1 0 u32 io size Maximum number of bytes passed by one read or write call u32 reserved 2 This array is reserved for future extensions Applications and drivers Notes Table 4 7 Sliced VBI services Symbol Value Reference Lines usually Payload VAL2 SLICED TELETEXUx0901 ETS 300 706PAL SECAM line 7 22 Last 42 of the 45 byte Teletext System B ITU BT 653 320 335 second field Teletext packet that is 7 22 without clock run in and framing code lsb first transmitted V4L2_SLICED_VPS 0x0400 ETS 300 231PAL line 16 Byte number 3 to 15 according to Figure 9 of ETS 300 231 Isb first transmitted V4L2_SLICED_CAPTIONDXIHH0 EIA 608 B NTSC line 21 284 Two bytes in second field 21 transmission order including parity bit lsb first transmitted V4L2_SLICED_WSS_6250x4000 ITU BT 111 AL SECAM line 23 Byte 0 1 EN
246. ls Note device memory accesses e g the memory on a graphics card with video capturing hardware may incur a performance penalty compared to main memory accesses or reads may be significantly slower than writes or vice versa Other I O methods may be more efficient in this case flags The flags parameter specifies the type of the mapped object mapping options and whether modifications made to the mapped copy of the page are private to the process or are to be shared with other references MAP FIXED requests that the driver selects no other address than the one specified If the specified address cannot be used mmap will fail If MAP FIXED is specified start must bea multiple of the pagesize Use of this option is discouraged 188 V4L2 mmap One of the MAP SHARED or MAP PRIVATE flags must be set MAP SHARED allows applications to share the mapped memory with other e g child processes Note the Linux video buf module which is used by the bttv saa7134 saa7146 cx88 and vivi driver supports only MAP SHARED MAP PRIVATE requests copy on write semantics VAL2 applications should not set the MAP PRIVATE MAP DENYWRITE MAP EXECUTABLE Or MAP ANON flag fd File descriptor returned by open offset Offset of the buffer in device memory This must be the same value as returned by the driver in the struct v412 buffer m union offset field Description T
247. ly the period of the vertical blanking interval is available for reading or the capture rate must fall below the nominal frame rate of the video standard The behavior of read when called during the active picture period or the vertical blanking separating the top and bottom field depends on the discarding policy A driver discarding the oldest frames keeps capturing into an internal buffer continuously overwriting the previously not read frame and returns the frame being received at the time of the read call as soon as it is complete 195 V4L2 read A driver discarding the newest frames stops capturing until the next read call The frame being received at read time is discarded returning the following frame instead Again this implies a reduction of the capture rate to one half or less of the nominal frame rate An example of this model is the video read mode of the bttv driver initiating a DMA to user memory when read is called and returning when the DMA finished In the multiple buffer model drivers maintain a ring of internal buffers automatically advancing to the next free buffer This allows continuous capturing when the application can empty the buffers fast enough Again the behavior when the driver runs out of free buffers depends on the discarding policy Applications can get and set the number of buffers used internally by the driver with the VIDIOC G PARM and VIDIOC S PARM ioctls They are optional however T
248. mats see also VIDIOC G FBUF Table 2 1 struct v4l2 pix format u32 width Image width in pixels u32 height Image height in pixels Applications set these fields to request an image size drivers return the closest possible values In case of planar forma u32 pixelformat The pixel format or type of compression set by the application This is a little endian four character code V4L2 defines standard RGB formats in Table 2 1 YUV formats in Section 2 5 and reserved codes in Table 2 8 enum v412 field field Video images are typically interlaced Applications can request to capture or output only the top or bottom field or both fields interlaced or sequentially stored in one buffer or alternating in separate buffers Drivers return the actual field order selected For details see Section 3 6 u32 bytesperline Distance in bytes between the leftmost pixels in two adjacent lines Both applications and drivers can set this field to request padding bytes at the end of each line Drivers however may ig u32 sizeimage Size in bytes of the buffer to hold a complete image set by the driver Usually this is bytesperline times height When the image consists of variable length compressed data this is the maximum number of bytes required to hold an image enum v4l2 colorspace colorspace This information supplements the pixel format and must be set by the driver see Section 2 2 u32 priv Reserved for custom driver defined additi
249. me width step size pixel Minimum frame height pixel Maximum frame height pixel Frame height step size pixel Frame size number Pixel format Frame size type the device supports Frame size x discrete enum v412 frmivaltypes V4L2_FRMIVAL_TYPE_DISCRETE EU VA4L2 FRMIVAL TYPE CONTINUOUS 2 V4L2_FRMIVAL_TYPE_STEPWISE EOR struct v412 frmival stepwise struct v412_fract min stepwise Reserved space for future use x Minimum frame interval x s 231 Appendix A Video For Linux Two Header File struct v412 fract max Maximum frame interval s struct v412 fract step x Frame interval step size s struct v412 frmivalenum u32 index Frame format index x u32 pixel format Pixel format u32 width Frame width x u32 height Frame height u32 type x Frame interval type the device suppor union Frame interval x struct v412 fract discrete struct v412 frmival stepwis stepwis z u32 reserved 2 x Reserved space for future use x endif TIMECOD ti struct v412 timecode Type define define define define define define define define define define The a Flags u32 type u32 flags u8 frames u8 seconds u8 minutes u8 hours u8 userbits 4
250. memory or more often just buffers allocated in DMA able system memory into their address space This avoids the data copying overhead of the read method V4L2 supports memory mapping as well with a few differences V4L V4L2 The image format must be selected before buffers are allocated with the VIDIOC_S_FMT ioctl When no format is selected the driver may use the last possibly by another application requested format Applications cannot change the number of The vIDIOC_REQBUFS ioctl allocates the desired buffers The it is built into the driver unless it has number of buffers this is a required step in the a module option to change the number when the initialization sequence driver module is loaded 208 Chapter 6 Changes V4L V4L2 memory The VIDIOCGMBUF ioctl is available to query the number of buffers the offset of each buffer from the start of the virtual file and the overall amount of memory used which can be used as arguments for the mmap function Drivers map all buffers as one contiguous range ofBuffers are individually mapped The offset and size of each buffer can be determined with the VIDIOC QUERYBUF ioctl The VIDIOCMCAPTURE ioctl prepares a buffer for capturing It also determines the image format for this buffer The ioctl returns immediately eventually with an EAGAIN error code if no video signal had been detected When the driver supports more than one buff
251. modification so you may distribute translations of the Document under the terms of section 4 Replacing Invariant Sections with translations requires special permission from their copyright holders but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections You may include a translation of this License provided that you also include the original English version of this License In case of a disagreement between the translation and the original English version of this License the original English version will prevail C 10 9 TERMINATION You may not copy modify sublicense or distribute the Document except as expressly provided for under this License Any other attempt to copy modify sublicense or distribute the Document is void and will automatically terminate your rights under this License However parties who have received copies or rights from you under this License will not have their licenses terminated so long as such parties remain in full compliance C 11 10 FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation http www gnu org fsf fsf html may publish new revised versions of the GNU Free Documentation License from time to time Such new versions will be similar in spirit to the present version but may differ in detail to address new problems or concerns See http www gnu org copyleft http www gnu org copyleft Each version of the Lic
252. mp1e format field though to function properly with other drivers A VBI device may support read write and or streaming memory mapping or user pointer I O The latter bears the possibility of synchronizing video and VBI data by using buffer timestamps Remember the VIDIOC STREAMON ioctl and the first read write and select call can be resource allocation points returning an EBUSY error code if the required hardware resources are temporarily unavailable for example the device is already in use by another process 4 8 Sliced VBI Data Interface VBI stands for Vertical Blanking Interval a gap in the sequence of lines of an analog video signal During VBI no picture information is transmitted allowing some time while the electron beam of a cathode ray tube TV returns to the top of the screen Sliced VBI devices use hardware to demodulate data transmitted in the VBI V4L2 drivers shall not do this by software see also the raw VBI interface The data is passed as short packets of fixed size covering one scan line each The number of packets per video frame is variable Sliced VBI capture and output devices are accessed through the same character special files as raw VBI devices When a driver supports both interfaces the default function of a dev vbi device is raw VBI capturing or output and the sliced VBI function is only available after calling the VIDIOC_S_FMT ioctl as defined below Likewise a dev video device may support the sli
253. must initialize the tuner t ype field of struct v412 frequency before calling VIDIOC S FREQUENCY Nn The reserved array in struct v412_requestbuffers has 2 elements not 32 fon In Section 4 3 and Section 4 7 the device file names dev vout which never caught on were replaced by dev video With Linux 2 6 15 the possible range for VBI device minor numbers was extended from 224 239 to 224 255 Accordingly device file names dev vbi0 to dev vbi31 are possible now 6 2 23 V4L2 in Linux 2 6 18 1 New ioctls VIDIOC G EXT CTRLS VIDIOC S EXT CTRLS and VIDIOC TRY EXT CTRLS were added a flag to skip unsupported controls with vIDIOC QUERYCTRL new control types V4L2 CTRL TYPE INTEGER64 and VAL2 CTRL TYPE CTRI CLASS Table 3 and new control flags vAL2 CTRL FLAG READ ONLY VAL2 CTRL FLAG UPDATE V4L2 CTRL FLAG INACTIVE and VAL2 CTRL FLAG SLIDER Table 4 See Section 1 9 for details 6 2 24 V4L2 in Linux 2 6 19 1 In struct v412 sliced vbi cap a buffer type field was added replacing a reserved field Note on architectures where the size of enum types differs from int types the size of the structure changed The viDiOC G SLICED VBI CAP ioctl was redefined from being read only to write read Applications must initialize the type field and clear the reserved fields now These changes may break the compatibility with older drivers and applications
254. n 1 1 2 drivers must make related device functions available under all minor device numbers 2 The open function requires access mode O_RDWR regardless of the device type All VAL2 drivers exchanging data with applications must support the O_NONBLOCK flag The o Noro flag a V4L2 symbol which aliased the meaningless O TRUNC to indicate accesses without data exchange panel applications was dropped Drivers must stay in panel mode until the application attempts to initiate a data exchange see Section 1 1 3 The struct v412 capability changed dramatically Note that also the size of the structure changed which is encoded in the ioctl request code thus older V4L2 devices will respond with an EINVAL error code to the new VIDIOC_QUERYCAP ioctl There are new fields to identify the driver a new as of yet unspecified device function V4L2_CAP_RDS_CAPTURE the V4L2 CAP AUDIO flag indicates if the device has any audio connectors another I O capability vAL2 CAP ASYNCIO can be flagged In response to these changes the type field became a bit set and was merged into the flags field VAL2 FLAG TUNER was renamed to VAL2 CAP TUNER VAL2 CAP VIDEO OVERLAY replaced VAL2 FLAG PREVIEW and V4L2 CAP VBI CAPTURE and V4L2 CAP VBI OUTPUT replaced V4AL2 FLAG DATA SERVICE V4AL2 FLAG READ and V4L2 FLAG WRITE were merged into V4L2 CAP READWRITE The redundant fields inputs
255. n EINVAL error code To change the current format parameters applications initialize the t ype field and all fields of the respective mt union member For details see the documentation of the various devices types in Chapter 4 Good practice is to query the current parameters first and to modify only those parameters not suitable for the application When the application calls the VIDIOC_S_FMT ioctl with a pointer to a v412 format structure the driver checks and adjusts the parameters against hardware abilities Drivers should not return an error code unless the input is ambiguous this is a mechanism to fathom device capabilities and to approach parameters acceptable for both the application and driver On success the driver may program the hardware allocate resources and generally prepare for data exchange Finally the VIDIOC_S_FMT ioctl returns the current format parameters as VIDIOC G FMT does Very simple inflexible devices may even ignore all input and always return 140 ioctl VIDIOC G FMT VIDIOC S FMT VIDIOC TRY FMT the default parameters However all VAL2 devices exchanging data with the application must implement the VIDIOC_G_FMT and VIDIOC_S_FMT ioctl When the requested buffer type is not supported drivers return an EINVAL error code on a VIDIOC S rFMT attempt When I O is already in progress or the resource is not available for other reasons drivers return the EBUSY error code The VIDIOC_TRY_FMT ioctl is equiv
256. n extension of the X Window system 222 Chapter 6 Changes implemented for example by the XFree86 project Its scope is similar to V4L2 an API to video capture and output devices for X clients Xv allows applications to display live video in a window send window contents to a TV output and capture or output still images in XPixmaps With their implementation XFree86 makes the extension available across many operating systems and architectures Because the driver is embedded into the X server Xv has a number of advantages over the VAL2 video overlay interface The driver can easily determine the overlay target i e visible graphics memory or off screen buffers for a destructive overlay It can program the RAMDAC for a non destructive overlay scaling or color keying or the clipping functions of the video capture hardware always in sync with drawing operations or windows moving or changing their stacking order To combine the advantages of Xv and V4L a special Xv driver exists in XFree86 and XOrg just programming any overlay capable Video4Linux device it finds To enable it etc X11 XF86Config must contain these lines Section Module Load v41 EndSection As of XFree86 4 2 this driver still supports only VAL ioctls however it should work just fine with all V4L2 devices through the V4L2 backward compatibility layer Since V4L2 permits multiple opens it is possible if supported by the V4L2 driver to capture video while an X cli
257. n the sense of freedom to assure everyone the effective freedom to copy and redistribute it with or without modifying it either commercially or noncommercially Secondarily this License preserves for the author and publisher a way to get credit for their work while not being considered responsible for modifications made by others This License is a kind of copyleft which means that derivative works of the document must themselves be free in the same sense It complements the GNU General Public License which is a copyleft license designed for free software We have designed this License in order to use it for manuals for free software because free software needs free documentation a free program should come with manuals providing the same freedoms that the software does But this License is not limited to software manuals it can be used for any textual work regardless of subject matter or whether it is published as a printed book We recommend this License principally for works whose purpose is instruction or reference C 2 1 APPLICABILITY AND DEFINITIONS This License applies to any manual or other work that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License The Document below refers to any such manual or work Any member of the public is a licensee and is addressed as you A Modified Version of the Document means any work containing the Document or a port
258. nChromaticities WhiteGamma Lumi Point Correc inance Red Green Blue Y Cb Cr tion Evy IV4L2_COLORSPACM NITS Cx S10 47K 0 21 x 0 14 accord y 0 33 y 0 71 y 0 08 x 0 310 0 299 E x219 E v 224 Part 128 ing to y 20 316 H 0 587 H c ITU BT 470 Illumi 0 114 H5 ITU BT 601 nant C V4L2 cQaLoR PAQG25 line Sx eid R 0 29 x 0 15 PAL and y 0 33 y 0 60 y 0 06 x 20 313 0 299 E3219 E v 224 Part 128 SECAM y 0 329 0 587 Ba systems Humi 0 114 B s accord Inant Des ing to ITU BT 470 ITU BT 601 l V4L2_CQLOR6PAGHPEGEG y 0 330y 0 600y 0 060y 0 32960 099 Io 44 0 099 for 0 018 lt I Illumi nant Des Y CbCr 0 299 E 3256 E v 42b Per 128 see JFIF 0 587 B c ITU BT 601 0 114 H s V4L2 CQLORSPAQ SRGB E x 0 640x 0 300x 0 150x 0 3124 5 I for I 0 018 Notes a The coordinates of the color primaries are given in the CIE system 1931 b The ubiquitous Bt878 video 2 3 Indexed Format In this format each pixel is represented by an 8 bit index into a 256 entry ARGB palette It is intended for Video Output Overlays only There are no ioctls to access the palette this must be done with ioctls of the Linux framebuffer API Table 2 3 Indexed Image Format Identifier Code Byte 0 76543210 Bit V4L2_PiKi WA IPA 42 li io PALS 33 2 4 RGB Formats Packed RG
259. nce and recycle the most recently used buffers first Of course the pages of empty buffers in the incoming queue need not be saved to disk Output buffers must be saved on the incoming and outgoing queue because an application may share them with other processes At the driver level select and po11 are the same and select is too important to be optional The rest should be evident Since no other Linux multimedia API supports unadjusted time it would be foolish to introduce here We must use a universally supported clock to synchronize different media hence time of day 65 Chapter 4 Interfaces 4 1 Video Capture Interface Video capture devices sample an analog video signal and store the digitized images in memory Today nearly all devices can capture at full 25 or 30 frames second With this interface applications can control the capture process and move images from the driver into user space Conventionally V4L2 video capture devices are accessed through character device special files named dev video and dev videoO to dev video63 with major number 81 and minor numbers 0 to 63 dev video is typically a symbolic link to the preferred video device Note the same device files are used for video output devices 4 1 1 Querying Capabilities Devices supporting the video capture interface set the VAL2 CAP VIDEO CAPTURE flag in the capabilities field of struct v412 capability returned by the VIDIOC_QUERYCAP ioctl As second
260. nd exclusive V4L2_CID_BASE_LASTP1 Drivers may return EINVAL if a control in this range is not supported Further applications can enumerate private controls which are not defined in this specification by starting at V4L2_CID_PRIVATE_BASE and incrementing id until the driver returns EINVAL In both cases when the driver sets the V4L2_CTRL_FLAG_DISABLED flag in the flags field this control is permanently disabled and should be ignored by the application When the application ORs id with V4L2_CTRL_FLAG_NEXT_CTRL the driver returns the next supported control or EINVAL if there is none Drivers which do not support this flag yet always return EINVAL Additional information is required for menu controls the name of menu items To query them applications set the id and index fields of struct v412_querymenu and call the VIDIOC_QUERYMENU ioctl with a pointer to this structure The driver fills the rest of the structure or 177 ioctl VIDIOC QUERYCTRL VIDIOC QUERYMENU returns an EINVAL error code when the id or index is invalid Menu items are enumerated by calling VIDIOC QUERYMENU with successive index values from struct v412_queryctrl minimum 0 to maximum inclusive See also the examples in Section 1 8 Table 1 struct v4I2 queryctrl u32 id Identifies the control set by the application See Table 1 1 for predefined IDs When the ID is ORed with VAL2 CTRL FLAG NEXT CTRL the d
261. nd overlay simultaneously multiple opens allow concurrent use of the device by forked processes or specialized applications Multiple opens are optional although drivers should permit at least concurrent accesses without data exchange i e panel applications This implies open can return an EBUSY error code when the device is already in use as well as ioct 1 functions initiating data exchange namely the VIDIOC_S_FMT ioctl and the read and write functions Mere opening a VAL2 device does not grant exclusive access Initiating data exchange however assigns the right to read or write the requested type of data and to change related properties to this file descriptor Applications can request additional access privileges using the priority mechanism described in Section 1 3 1 1 4 Shared Data Streams VAL2 drivers should not support multiple applications reading or writing the same data stream on a device by copying buffers time multiplexing or similar means This is better handled by a proxy application in user space When the driver supports stream sharing anyway it must be implemented transparently The VAL2 API does not specify how conflicts are solved 1 1 5 Functions To open and close V4L2 devices applications use the open and c1ose function respectively Devices are programmed using the ioct1 function as explained in the following sections 1 2 Querying Capabilities Because V4L2 covers a wide variety of de
262. ndow The x y width and height fields of struct video window moved into struct v412_rect substructure w Of struct v412 window The chromakey clips and clipcount fields remained unchanged Struct video clip was renamed to struct v412 clip also containing a struct v412 rect but the semantics are still the same The VIDEO WINDOW INTERLACE flag was dropped Instead applications must set the field field to V4L2 FIELD ANY or V4L2 FIELD INTERLACED The VIDEO WINDOW CHROMAKEY flag moved into struct v412 framebuffer under the new name V4L2 FBUF FLAG CHROMAKEY In VAL storing a bitmap pointer in clips and setting clipcount to VIDEO CLIP BITMAP 1 requests bitmap clipping using a fixed size bitmap of 1024 x 625 bits Struct v4I2 window has a separate bitmap pointer field for this purpose and the bitmap size is determined by w width and w height The VIDIOCCAPTURE ioctl to enable or disable overlay was renamed to VIDIOC OVERLAY 207 Chapter 6 Changes 6 1 8 Cropping To capture only a subsection of the full picture VAL defines the VIDIOCGCAPTURE and VIDIOCSCAPTURE ioctls using struct video capture The equivalent V4L2 ioctls are VIDIOC G CROP and VIDIOC S CROP using struct v412 crop and the related VIDIOC_CROPCAP ioctl This is a rather complex matter see Section 1 11 for details The x y width and height fields moved into struct v412 rect substructure c of struct v41
263. not be switched 120 ioctl VIDIOC G AUDOUT VIDIOC S AUDOUT Name VIDIOC G AUDOUT VIDIOC S AUDOUT Query or select the current audio output Synopsis int ioctl int fd int request struct v412 audioout xargp int ioctl int fd int request const struct v412 audioout argp Arguments fd File descriptor returned by open request VIDIOC G AUDOUT VIDIOC 5 AUDOUT argp Description To query the current audio output applications zero out the reserved array of a struct v412_audioout and call the VIDIOC_G_AUDOUT ioctl with a pointer to this structure Drivers fill the rest of the structure or return an EINVAL error code when the device has no audio inputs or none which combine with the current video output Audio outputs have no writable properties Nevertheless to select the current audio output applications can initialize the index field and reserved array which in the future may contain writable properties of a v412_audioout structure and call the vIDIOC_S_AUDOUT ioctl Drivers switch to the requested output or return the EINVAL error code when the index is out of bounds This is a write only ioctl it does not return the current audio output attributes as VIDIOC G AUDOUT does Note connectors on a TV card to loop back the received audio signal to a sound card are not audio outputs in this sense Table 1 struct v412_audioout u32 index Identifies the audio output set by the driver or application 1
264. ns see the section discussing the read function To get and set the streaming parameters applications call the vIDIOC G PARM and VIDIOC S PARM ioctl respectively They take a pointer to a struct v412_streamparm which contains a union holding separate parameters for input and output devices These ioctls are optional drivers need not implement them If so they return the EINVAL error code 27 Notes 10 11 Chapter 1 Common API Elements Access permissions are associated with character device special files hence we must ensure device numbers cannot change with the module load order To this end minor numbers are no longer automatically assigned by the videodev module as in VAL but requested by the driver The defaults will suffice for most people unless two drivers compete for the same minor numbers In earlier versions of the V4L2 API the module options where named after the device special file prefix expressing the minor number itself not an offset Rationale for this change is unknown Lastly the naming and semantics are just a convention among driver writers the point to note is that minor numbers are not supposed to be hardcoded into drivers with a unit Given a device file name one cannot reliable find related devices For once names are arbitrary and in a system with multiple devices where only some support VBI capturing a dev video2 is not necessarily related to dev vbi2 The VAL vIDIOCGUNIT ioctl would r
265. nst hardware limits i e the bounds given by the capture output window and it rounds to the closest possible values of horizontal and vertical offset width and height In particular the driver must round the vertical offset of the cropping rectangle to frame lines modulo two such that the field order cannot be confused Second the driver adjusts the image size the opposite rectangle of the scaling process source or target depending on the data direction to the closest size possible while maintaining the current horizontal and vertical scaling factor Finally the driver programs the hardware with the actual cropping and image parameters VIDIOC S CROP is a write only ioctl it does not return the actual parameters To query them applications must call vIDIOC G CROP and VIDIOC G FMT When the parameters are unsuitable 126 ioctl VIDIOC G CROP VIDIOC S CROP the application may modify the cropping or image parameters and repeat the cycle until satisfactory parameters have been negotiated When cropping is not supported then no parameters are changed and VIDIOC S CROP returns the EINVAL error code Table 1 struct v4l2 crop enum v412 buf type type Type of the data stream set by the application Only these types are valid here V4L2 BUF TYPE VIDEO CAPTURE V4L2 BUF TYPE VIDEO OUTPUT V4L2 BUF TYPE VIDEO OVERLAY and custom driver defined types with code VAL2 BUF struct
266. nteraction from the application itself This means that the enumeration data is consistent if the application does not perform any other ioctl calls while it runs the frame size enumeration Structs In the structs below IN denotes a value that has to be filled in by the application OUT denotes values that the driver fills in The application should zero out all members except for the JN fields Table 1 struct v4l2 frmsize discrete u32 u32 width height Table 2 struct v412 frmsize stepwise u32 u32 u32 u32 u32 u32 min width max width step width min height max height step height Table 3 struct v412_frmsizeenum u32 u32 u32 union index pixel format type Width of the frame pixel Height of the frame pixel Minimum frame width pixel Maximum frame width pixel Frame width step size pixel Minimum frame height pixel Maximum frame height pixel Frame height step size pixel IN Index of the given frame size in the enumeration IN Pixel format for which the frame sizes are enumerated OUT Frame size type the device supports OUT Frame size with the given index struct v412 frmsize discretescrete struct v412_frmsize_stepweisepwise 104 u32 reserved 2 Enums Table 4 enum v4l2 frmsizetypes VA4L2 FRMSIZE TYPE DISCRETE 1 V4L2 FRMSIZE TYPE CONTINUOUS2 V4L2 FRMSIZE TYPE STEPWISE 3
267. ny audio inputs or outputs the driver must set the V4L2 CAP AUDIO flag in the struct v412 capability returned by the VIDIOC_QUERYCAP ioctl Example 1 3 Information about the current audio input struct v412 audio audio memset amp audio 0 sizeof audio if 1 ioctl fd VIDIOC G AUDIO amp audio perror VIDIOC G AUDIO exit EXIT_FAILURE Chapter 1 Common API Elements printf Current input s n audio name Example 1 4 Switching to the first audio input struct v412 audio audio memset amp audio 0 sizeof audio clear audio mode audio reserved audio index 0 if 1 ioctl fd VIDIOC S AUDIO amp audio perror VIDIOC S AUDIO exit EXIT FAILURE 1 6 Tuners and Modulators 1 6 1 Tuners Video input devices can have one or more tuners demodulating a RF signal Each tuner is associated with one or more video inputs depending on the number of RF connectors on the tuner The t ype field of the respective struct v412 input returned by the VIDIOC_ENUMINPUT ioctl is set to V4L2 INPUT TYPE TUNER and its tuner field contains the index number of the tuner Radio devices have exactly one tuner with index zero no video inputs To query and change tuner properties applications use the VIDIOC G TUNER and VIDIOC S TUNER ioctl respectively The struct v412 tuner returned by VIDIOC_G_TUNER also contains signal status information applicable when t
268. o start 23 Cr3o Color Sample Location W N e O KKK KO KKK KR A OAA KKK RS 48 KKK K V4L2 PIX FMT NV12 NV12 V4AL2 PIX FMT NV21 NV21 Name V4L2_PIX_FMT_NV12 V4L2_PIX_FMT_NV21 Formats with horizontal and vertical chroma resolution also known as YUV 4 2 0 One luminance and one chrominance plane with alternating chroma samples as opposed to V4L2_PIX_FMT_YVvu420 Description These are two plane versions of the YUV 4 2 0 format The three components are separated into two sub images or planes The Y plane is first The Y plane has one byte per pixel For V4L2_P1X_FMT_NV12 a combined CbCr plane immediately follows the Y plane in memory The CbCr plane is the same width in bytes as the Y plane and of the image but is half as tall in pixels Each CbCr pair belongs to four pixels For example Cb Cr belongs to Y Yor Y 19 Y V4L2_P1X_FMT_NV21 is the same except the Cb and Cr bytes are swapped the CrCb plane starts with a Cr byte If the Y plane has pad bytes after each row then the CbCr plane has as many pad bytes after its rows Example 2 1 v4L2_PIX_FMT_NV12 4 x 4 pixel image Byte Order Each cell is one byte start 0 Y 00 Y oi Y o Y os start 4 Y io Yu Yr Y 13 start 8 Y o Y Y 2 Y start 12 Y 30 Y s Y Y ss start 4 16 Cboo Croo Cbo Croi start 4 20 Cbio Crio Cbi Cri Color Sample Location 0 1 2 0 Y C C 1 Y Y Y 2 Y Y Y C C 3 Y Y Y 49 2
269. o audio signal The tuner receives a stereo audio signal The tuner receives the primary language of a bilingual audio signal Drivers must clear this flag when the current video standard is VAL2 STD NTSC M The tuner receives the secondary language of a bilingual audio signal or a second audio program The tuner receives a Second Audio Program Note the VAL2 TUNER SUB LANG2 and V4L2 TUNER SUB SAP flags are synonyms The V4L2 TUNER SUB SAP flag applies when the current video standard is VAL2 STD NTSC M Play mono audio When the tuner receives a stereo signal this a down mix of the left and right channel When the tuner receives a bilingual or SAP signal this mode selects the primary language 165 V4L2 TUNER MODE STERE VAL2 TUNER MODE LANGI VA4L2 TUNER MODE LANG2 V4L2 TUNER MODE SAP V4L2 TUNER MODE LANG1_LANG2 4 Table 6 Tuner Audio Matrix ioctl VIDIOC G TUNER VIDIOC S TUNER Play stereo audio When the tuner receives bilingual audio it may play different languages on the left and right channel or the primary language on both channels behave as in mono mode Playing different languages in this mode is deprecated New drivers should do this only in MODE LANG1 LANG2 When the tuner receives no stereo signal or does not support stereo reception the driver shall fall back to MODE MONO Play the primary languag
270. octl fd VIDIOC S FMT amp fmt errno exit VIDIOC S FMT Note VIDIOC S FMT may change width and height x Buggy driver paranoia min fmt fmt pix width 2 if fmt fmt pix bytesperline min fmt fmt pix bytesperline min min fmt fmt pix bytesperline fmt fmt pix height if fmt fmt pix sizeimage min fmt fmt pix sizeimage min switch io case IO METHOD READ init read fmt fmt pix sizeimage break case IO METHOD MMAP init mmap break case IO METHOD USERPTR init userp fmt fmt pix sizeimage break static void close_device void if 1 close fd errno_exit close fd 1 static void open_device void struct stat st if 1 stat dev_name amp st fprintf stderr Cannot identify s d S dev name errno strerror errno 260 exit EXIT_FAILURE Appendix B Video Capture Example if S ISCHR st st mode fprintf stderr s is no device n dev name exit EXIT FAILURE fd open dev name O_RDWR required O_NONBLOCK 0 if 1 fd fprintf stderr Cannot open s d s n dev name errno strerror errno exit EXIT FAILURE static void usage FILE fp int argc char xx argv fprintf fp Usage s options n n Options n iq device nam Video device name dev video n h
271. of the buffer same as struct v412_format type or struct v412_requestbuffers type set by the application u32 bytesused The number of bytes occupied by the data in the buffer It depends on the negotiated data format and may change with each buffer for compressed variable size data like JPEG images Drivers must set this field when type refers to an input stream applications when an output stream u32 flags Flags set by the application or driver see Table 3 3 enum v412_ field field Indicates the field order of the image in the buffer see Table 3 8 This field is not used when the buffer contains VBI data Drivers must set it when type refers to an input stream applications when an output stream 56 struct timeval timestamp struct v412 timecod amp imecode u32 sequence Chapter 3 Input Output For input streams this is the system time as returned by the gett imeofday function when the first data byte was captured For output streams the data will not be displayed before this time secondary to the nominal frame rate determined by the current video standard in enqueued order Applications can for example zero this field to display frames as soon as possible The driver stores the time at which the first data byte was actually sent out in the timestamp field This permits applications to monitor the drift between the video and system clock When type is VAL2 BUF TYPE VIDEO CAPTURE and the V4AL2 BUF F
272. ols x define V4L2 CID PRIVATE BASFE 0x08000000 define V4L2 CID USER CLASS VAL2 CTRL CLASS USER 1 define V4L2 CID BRIGHTNESS V4L2_CID_BASE 0 define V4L2_CID_CONTRAST V4L2_CID_BASE 1 define V4L2_CID_SATURATION V4L2_CID_BASE 2 define V4L2_CID_HUE V4L2_CID_BASE 3 define V4L2_CID_AUDIO_VOLUME V4L2_CID_BASE 5 define V4L2_CID_AUDIO_BALANCE V4L2_CID_BASE 6 define V4L2_CID_AUDIO_BASS V4L2_CID_BASE 7 define V4L2_CID_AUDIO_TREBLE V4L2_CID_BASE 8 239 Appendix A Video For Linux Two Header File define V4L2 CID AUDIO MUTE V4L2_CID_BASE 9 define V4L2_CID_AUDIO_LOUDNESS V4L2_CID_BASE 10 define V4L2_CID_BLACK_LEVEL V4L2_CID_BASE 11 Deprecated x define V4L2_CID_AUTO_WHITE_BALANCE V4L2_CID_BASE 12 define V4L2_CID_DO_WHITE_BALANCE V4L2_CID_BASE 13 define V4L2_CID_RED_BALANCE V4L2_CID_BASE 14 define V4L2_CID_BLUE_BALANCE V4L2_CID_BASE 15 define V4L2_CID_
273. on Any attempt to change the control will result in an EINVAL error code This control is temporarily unchangeable for example because another application took over control of the respective resource Such controls may be displayed specially in a user interface Attempts to change the control may result in an EBUSY error code This control is permanently readable only Any attempt to change the control will result in an EINVAL error code A hint that changing this control may affect the value of other controls within the same control class Applications should update their user interface accordingly This control is not applicable to the current configuration and should be displayed accordingly in a user interface For example the flag may be set on a MPEG audio level 2 bitrate control when MPEG audio encoding level 1 was selected with another control 180 ioctl VIDIOC QUERYCTRL VIDIOC QUERYMENU VA4L2 CTRL FLAG SLIDER 0x0020 A hint that this control is best represented as a slider like element in a user interface Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The struct v412_queryctrl id is invalid The struct v412_querymenu id or index is invalid 181 Notes 1 V4L2 CTRL FLAG DISABLED was intended for two purposes Drivers can skip predefined controls not supported by the hardware although returning EINVAL would do as well or disable predefined
274. on count 0 gt 0 and count 1 gt 0 has been relaxed to count 0 count 1 gt 0 Rationale Drivers may allocate resources at scan line granularity and some data services are transmitted only on the first field The comment that both count values will usually be equal is misleading and pointless and has been removed This change breaks compatibility with earlier versions Drivers may return EINVAL applications may not function correctly W Drivers are again permitted to return negative unknown start values as proposed earlier Why this feature was dropped is unclear This change may break compatibility with applications 213 Chapter 6 Changes depending on the start values being positive The use of EBUSY and EINVAL error codes with the VIDIOC_S_FMT ioctl was clarified The EBUSY error code was finally documented and the reserved2 field which was previously mentioned only in the videodev n header file 4 New buffer types VAL2 TYPE VBI INPUT and V4L2 TYPE VBI OUTPUT were added The former is an alias for the old vaL2 TYPE VBI the latter was missing in the videodev h file 6 2 8 V4L2 Version 0 20 2002 07 25 Added sliced VBI interface proposal 6 2 9 V4L2 in Linux 2 5 46 2002 10 Around October November 2002 prior to an announced feature freeze of Linux 2 5 the API was revised drawing from experience with V4L2 0 20 This unnamed version was finally merged into Linux 2 5 46 1 As specified in Sectio
275. on may be lower than 16 bits for example 10 bits per pixel with values in range 0 to 1023 Example 2 1 v4L2_PIX_FMT_Y16 4 x 4 pixel image Byte Order Each cell is one byte start 4 0 start 8 start 4 16 start 4 24 Y ootow Y tolow Y 201ow Y s0low Y oohigh Y 10high Y 20high Y 30high Y ollow Y iow Y 2110w Y 31low Y othigh Y tthigh Y 2ihign Y sihign Y ootow Y itow Y zatow Y 321ow Y o2high Y ionigh Y 2high Y 32high Y o3tow Y i3tow Y 2310w Y 3310w Y o3high Y 13high Y 23high Y 33high 41 V4L2 PIX FMT YUYV YUYV Name VAL2 PIX FMT YUYV Packed format with 2 horizontal chroma resolution also known as YUV 4 2 2 Description In this format each four bytes is two pixels Each four bytes is two Y s a Cb and a Cr Each Y goes to one of the pixels and the Cb and Cr belong to both pixels As you can see the Cr and Cb components have half the horizontal resolution of the Y component v4AL2 PIX FMT YUYV is known in the Windows environment as YUY2 Example 2 1 vAL2 PIX FMT YUYV 4 x 4 pixel image Byte Order Each cell is one byte start 4 0 Y oo start 8 Y 10 start 16 Y o start 4 24 Y 30 Color Sample Location Ww N Cc i em Cboo Cbio Cboo Cb30 Q0000 Y oi Y u Yazi Y 31 KAM Croo Crio Cro Cro Y o Yn Y 2 Y Cbo Cbi Cboi Cbs KAN Y o3 Y 13 Y
276. onal information about formats When not used drivers and applications must set this field to zero 2 1 Standard Image Formats In order to exchange images between drivers and applications it is necessary to have standard image data formats which both sides will interpret the same way V4L2 includes several such formats and this section is intended to be an unambiguous specification of the standard image data formats in V4L2 VAL2 drivers are not limited to these formats however Driver specific formats are possible In that case the application may depend on a codec to convert images to one of the standard formats when needed But the data can still be stored and retrieved in the proprietary format For example a device may support a proprietary compressed format Applications can still capture and save the data in the 29 Chapter 2 Image Formats compressed format saving much disk space and later use a codec to convert the images to the X Windows screen format when the video is to be displayed Even so ultimately some standard formats are needed so the V4L2 specification would not be complete without well defined standard formats The V4L2 standard formats are mainly uncompressed formats The pixels are always arranged in memory from left to right and from top to bottom The first byte of data in the image buffer is always for the leftmost pixel of the topmost row Following that is the pixel immediately to its right and so on
277. op capturing or output applications call the VIDIOC_STREAMON and VIDIOC STREAMOFF ioctl Note VIDIOC STREAMOFF removes all buffers from both queues and unlocks all buffers as a side effect Since there is no notion of doing anything now on a multitasking system if an application needs to synchronize with another event it should examine the struct v4I2 buffer timestamp of captured buffers or set the field before enqueuing buffers for output Drivers implementing user pointer I O must support the VIDIOC REOBUFS VIDIOC OBUF VIDIOC_DQBUF VIDIOC_STREAMON and VIDIOC STREAMOFF ioctl the select and poll function 3 4 Asynchronous I O This method is not defined yet 3 5 Buffers A buffer contains data exchanged by application and driver using one of the Streaming I O methods Only pointers to buffers are exchanged the data itself is not copied These pointers together with meta information like timestamps or field parity are stored in a struct v412 buffer argument to the VIDIOC_QUERYBUF VIDIOC_QBUF and VIDIOC DOBUF ioctl Nominally timestamps refer to the first data byte transmitted In practice however the wide range of hardware covered by the V4L2 API limits timestamp accuracy Often an interrupt routine will sample the system clock shortly after the field or frame was stored completely in memory So applications must expect a constant difference up to one field or frame period plus a small few scan lines
278. ory mapped or user pointer I O Memory mapped buffers are located in device memory and must be allocated with this ioctl before they can be mapped into the application s address space User buffers are allocated by applications themselves and this ioctl is merely used to switch the driver into user pointer I O mode To allocate device buffers applications initialize three fields of a v412 requestbuffers structure They set the type field to the respective stream or buffer type the count field to the desired number of buffers and memory must be set to vAL2 MEMORY MMAP When the ioctl is called with a pointer to this structure the driver attempts to allocate the requested number of buffers and stores the actual number allocated in the count field It can be smaller than the number requested even zero when the driver runs out of free memory A larger number is possible when the driver requires more buffers to function correctly When memory mapping I O is not supported the ioctl returns an EINVAL error code Applications can call VIDIOC_REQBUFS again to change the number of buffers however this cannot succeed when any buffers are still mapped A count value of zero frees all buffers after aborting or finishing any DMA in progress an implicit VIDIOC STREAMOFF To negotiate user pointer I O applications initialize only the type field and set memory to VAL2 MEMORY USERPTR When the ioctl is called with a pointer to this structure the driver
279. ot use it When you found a chip specific bug please contact the Video4Linux mailing list https listman redhat com mailman listinfo video4linux list so it can be fixed To query the driver applications must initialize the match type and match chip fields of a struct v4I2 chip ident and call vibIOC G CHIP IDENT with a pointer to this structure On success the driver stores information about the selected chip in the ident and revision fields On failure the structure remains unchanged When match typeis VAL2 CHIP MATCH HOST match chip selects the nth non PC chip on the TV card You can enumerate all chips by starting at zero and incrementing match chip by one until VIDIOC G CHIP IDENT fails with an EINVAL error code Drivers may also interpret match chip as a random ID but we recommend against that The number zero always selects the host chip e g the chip connected to the PCI bus When match typeis VAL2 CHIP MATCH I2C DRIVER match chip contains a driver ID as defined in the 1inux i2c id h header file For instance 12C DRIVERID SAA7127 will match any chip supported by the saa7127 driver regardless of its PC bus address When multiple chips 123 ioctl VIDIOC G CHIP IDENT supported by the same driver are present the ioctl will return v4AL2 IDENT AMBIGUOUS in the ident field When match typeis V4L2 CHIP MATCH I2C ADDR match chip selects a chip by its 7 bit PC bus address On success the ident
280. pdate their code 6 1 Differences between VAL and V4L2 The Video For Linux API was first introduced in Linux 2 1 to unify and replace various TV and radio device related interfaces developed independently by driver writers in prior years Starting with Linux 2 5 the much improved V4L2 API replaces the VAL API although existing drivers will continue to support V4L applications in the future either directly or through the V4L2 compatibility layer in the videodev kernel module translating ioctls on the fly For a transition period not all drivers will support the VAL2 API 6 1 1 Opening and Closing Devices For compatibility reasons the character device file names recommended for V4L2 video capture overlay radio teletext and raw vbi capture devices did not change from those used by VAL They are listed in Chapter 4 and below in Table 6 1 The V4L videodev module automatically assigns minor numbers to drivers in load order depending on the registered device type We recommend that V4L2 drivers by default register devices with the same numbers but the system administrator can assign arbitrary minor numbers using driver module options The major device number remains 81 Table 6 1 V4L Device Types Names and Numbers Device Type File Name Minor Numbers Video capture and overlay dev video and dev bttv0a 0 63 dev videoO to dev video63 Radio receiver dev radioe dev radioO to 64 127 dev radio63 Teletext
281. pe V4L2_BUF_TYPE_VIDEO_OUTPUT if 1 ioctl fd VIDIOC_CROPCAP amp cropcap perror VIDIOC CROPCAP exit EXIT_FAILURE memset amp crop 0 sizeof crop crop type V4L2_BUF_TYPE_VIDEO_OUTPUT crop c cropcap defrect Scale the width and height to 50 of their original size and center the output x width 2 height 2 left crop c width 2 top crop c height 2 crop crop crop crop Ignore if cropping is not supported EINVAL x if 1 ioctl fd VIDIOC S CROP amp crop amp amp errno EINVAL perror VIDIOC S CROP exit EXIT FAILURE Example 1 13 Current scaling factor and pixel aspect A video capture device is assumed struct v412 cropcap cropcap struct v412 crop crop struct v412 format format double hscale vscale double aspect int dwidth dheight memset amp cropcap 0 sizeof cropcap cropcap type V4L2_BUF_TYPE_VIDEO_CAPTURE Em if 1 ioctl fd VIDIOC CROPCAP amp cropcap perror VIDIOC CROPCAP exit EXIT_FAILURE memset amp crop 0 sizeof crop 26 Chapter 1 Common API Elements crop type VA4L2 BUF TYPE VIDEO CAPTURE if 1 ioctl fd VIDIOC_G_CROP amp crop if errno EINVAL perror VIDIOC G CROP exit EXIT FAILURE Cropping not supported
282. pplications see Section 1 1 and drivers permitting simultaneous video capturing and overlay using the same file descriptor for compatibility with V4L and earlier versions of V4L2 VIDIOC_S_FMT and VIDIOC_REQBUFS would permit this to some degree but for simplicity drivers need not support switching the I O method after first switching away from read write other than by closing and reopening the device The following sections describe the various I O methods in more detail 3 1 Read Write Input and output devices support the read and write function respectively when the V4L2_CAP_READWRITE flag in the capabilities field of struct v412_capability returned by the VIDIOC_QUERYCAP ioctl is set Drivers may need the CPU to copy the data but they may also support DMA to or from user memory so this I O method is not necessarily less efficient than other methods merely exchanging buffer pointers It is considered inferior though because no meta information like frame counters or timestamps are passed This information is necessary to recognize frame dropping and to synchronize with other data streams However this is also the simplest I O method requiring little or no setup to exchange data It permits command line stunts like this the vidctrl tool is fictitious gt vidctrl dev video input 0 format YUYV size 352x288 gt dd if dev video of myimage 422 bs 202752 count 1 To read from the device applica
283. provides the flags VIDEO_AUDIO_VOLUME VIDEO_AUDIO_BASS VIDEO_AUDIO_TREBLE and VIDEO_AUDIO_BALANCE In the V4L2 API the VIDIOC_QUERYCTRL ioctl reports if the respective control is supported Accordingly the VIDEO_AUDIO_MUTABLE and VIDEO_AUDIO_MUTE flags where replaced by the boolean v4L2_CID_AUDIO_MUTE control All V4L2 controls have a step attribute replacing the struct video_audio step field The V4L audio controls are assumed to range from 0 to 65535 with no particular reset value The V4L2 API permits arbitrary limits and defaults which can be queried with the VIDIOC_QUERYCTRL ioctl For general information about controls see Section 1 8 6 1 7 Frame Buffer Overlay The V4L2 ioctls equivalent to VIDIOCGFBUF and VIDIOCSFBUF are VIDIOC G FBUF and VIDIOC S FBUF The base field of struct video buffer remained unchanged except V4L2 defines a flag to indicate non destructive overlays instead of a NULL pointer All other fields moved into the struct v4I2 pix format fmt substructure of struct v412 framebuffer The depth field was replaced by pixelformat See Section 2 4 for a list of RGB formats and their respective color depths Instead of the special ioctls VIDIOCGWIN and VIDIOCSWIN V4L2 uses the general purpose data format negotiation ioctls vVIDIOC G FMT and VIDIOC S FMT They take a pointer to a struct v412 format as argument Here the win member of the fmt union is used a struct v412_ wi
284. r 2032 capability 3 2 flags FIXME in theory we s region offset inst void struct v412 pix Flags for the capab hould pass something like PCI device memory ad of some physical address x base format fmt ility field Read only struct v412 rect struct v412 clip struct v412 window struct v412 rect enum v412 field u32 struct v412 clip u32 void u8 CAPTURE define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001 define V4L2_FBUF_CAP_CHROMAKEY 0x0002 define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004 define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008 define V4L2_FBUF_CAP_LOCAL_ALPHA 0x0010 define V4L2_FBUF_CAP_GLOBAL_ALPHA 0x0020 define V4L2_FBUF_CAP_LOCAL_INV_ALPHA 0x0040 Flags for the flags field x define V4L2 FBUF FLAG PRIMARY 0x0001 define V4L2 FBUF FLAG OVERLAY 0x0002 define V4L2 FBUF FLAG CHROMAKEY 0x0004 define V4L2 FBUF FLAG LOCAL ALPHA 0x0008 define V4L2 FBUF FLAG GLOBAL ALPHA 0x0010 define V4L2 FBUF FLAG LOCAL INV ALPHA 0x0020 struct v412 clip Cr user next wW field chromakey user clips clipcount user xbitmap global alpha PARAMETERS 234 Appendix A Video For Linux Two Header File struct v412 captureparm u32 capability Supported modes 2 132 capturemode Current mode x struct v412 fract timepe
285. r 255 224 0 Cr 128 r 1 0 yl 0 pb 1 402 pr g 1 0 yl 0 344 x pb 0 714 pr b 1 0 yl 1 772 pb 0 pr ER clamp r 255 x EG clamp g 255 EB clamp b 255 Table 2 2 enum v4l2 colorspace Chapter 2 Image Formats imit yl pb pr Identifier Value DescriptionChromaticities WhiteGamma Lumi Point Correc inance Red Green Blue Y Cb Cr tion Ev l V4L2_CQLORISPACNTSIG PAL 0M E accord xk 0 630 0 310 0 155 0 3124 5 I for IG 290158 2 19 E v 224 Par 128 ingto y 0 340y 0 595y 0 070y 0 32900 099 Io 45 0 587 E G SMPTE 170M Illumi 0 099 for 0 0 18 B s ITU BT 601 nant Des V4L2 CQLORSPAGEI2SMP TE240M EF Line x 0 630x 0 310x 0 155x 0 3124 I for I MDZE 4219 E v 224 Part 128 US y20 340y 0 595y 0 070 0 32910 1115 I0450 701 E IHDTV Humi 0 1115 for OORRRsI See Inant Des SMPTE 240M V4L2 COLOKEPAQHDHEX 7 0 9 FE Bt878 lextentsp ITU BT 601 and x 0 640x 0 300x 0 150x 0 3124 5 I for IGZDIQ 8 219 E v 224 Part 128 modern y 0 330y 0 600y 0 060y 0 3290 099 Io44 0 7154 E G devices Illumi 0 099 for 0 0 08 XE s see nant Des ITU BT 709 V4L2_COLORSPACBrokea7 0 299 E R237 E v 204 Psr 128 H 0 587 B c 0 114 B s proba bly 32 Chapter 2 Image Formats Identifier Value Descriptio
286. r ro Byte 2 76543210 I7 fo rs r4 r3 r2 r ro b be bs ba bs b bi bo I7 r6 rs r4 r3 I2 r ro 87 ge 85 84 83 82 81 go Packed RGB formats Byte 3 76543210 a7 a6 a5 a4 a3 a2 al ao b7 be bs b4 bs b2 bi bo A test utility to determine which RGB formats a driver actually supports is available from the LinuxTV v4l dvb repository See http linuxtv org repo for access instructions 36 V4AL2 PIX FMT SBGGRS BA81 Name V4L2 PIX FMT SBGGRS8 Bayer RGB format Description This is commonly the native format of digital cameras reflecting the arrangement of sensors on the CCD device Only one red green or blue value is given for each pixel Missing components must be interpolated from neighbouring pixels From left to right the first row consists of a blue and green value the second row of a green and red value This scheme repeats to the right and down for every two columns and rows Example 2 1 VAL2 PIX FMT SBGGRS 4 x 4 pixel image Byte Order Each cell is one byte start 0 Boo Goi Bo Gos start 4 Gio Ru Gu Ris start 8 B2 Gai Bo G3 start 12 G30 R31 G32 R33 37 VAL2 PIX FMT SBGGR16 BA82 Name V4L2 PIX FMT SBGGR16 Bayer RGB format Description This format is similar to VAL2 PIX FMT SBGGRS except each pixel has a depth of 16 bits The least significant byte is stored at lower memory addresses little endian Note the actual sampling precision may be lower than
287. r changes Most symbols have been renamed Some material changes to struct v412_capability 1998 11 12 The read write directon of some ioctls was misdefined 210 Chapter 6 Changes 1998 11 14 vVAL2 PIX FMT RGB24 changed to VAL2 PIX FMT BGR24 and V4L2 PIX FMT RGB32 changed to V4L2 PIX FMT BGR32 Audio controls are now accessible with the VIDIOC G CTRL and VIDIOC S CTRL ioctls under names starting with V4L2 CID AUDIO The V4L2 MAJOR define was removed from videodev h since it was only used once in the videodev kernel module The vuv422 and yuv411 planar image formats were added 1998 11 28 A few ioctl symbols changed Interfaces for codecs and video output devices were added 1999 01 14 A raw VBI capture interface was added 1999 01 19 The VIDIOC NEXTBUF ioctl was removed 6 2 2 VAL2 Version 0 16 1999 01 31 1999 01 27 There is now one QBUF ioctl VIDIOC QWBUF and VIDIOC QRBUF are gone VIDIOC QBUF takes a v412 buffer as a parameter Added digital zoom cropping controls 6 2 3 VAL2 Version 0 18 1999 03 16 Added a v4l to VAL2 ioctl compatibility layer to videodev c Driver writers this changes how you implement your ioctl handler See the Driver Writer s Guide Added some more control id codes 6 2 4 V4L2 Version 0 19 1999 06 05 1999 03 18 Fill in the category and catname fields of v412 queryctrl objects before passing them to the driver Required a minor change to the VIDIOC QUERYCTRL handlers in the sample dr
288. r tie a e EE er ioe 68 42 5 Enabling Overlay eee Ree RE Uqu aU qune 70 4 3 Video Output Interface eon oemhe tee nte e Chee ret rette pe 70 4 3 T Querying Capabilities 1 uero it iet he re eb eee inen 71 4 3 2 Supplemental Functions eesesssseeeeseeeeeen eren entren enne nnne 71 4 3 3 Image Format Negotiation ener ethernet nennen ene 71 4 3 4 Writing Images cere eeepc dteteen per ire EERE 71 4 4 Video Output Overlay Interface 00 ienaa E E R N E EEEE REESS 72 4 4 1 Querying Capabilities nennen eene enne enne nene 72 AAD Frame DULL MR DE 72 4 4 3 Overlay Window and Scaling essere nennen 73 44A Bnabhing Overlay tese eee Ue e Re ete te RO UE tet 74 4 5 Codec Interface ie esis ee a RN RE ns ee 74 4 6 Effect Devices Interface Aree bt eS eei e des 74 4 7 Raw VBI Data Interface teet cmt iet E RR 74 473 Querying Capabilities eite teo emet Cete p etre 75 4 7 2 Supplemental Functions essere enne nennen nennen 75 4 7 3 Raw VBI Format Negotiation oseese rines nekes enne 75 4 7 4 Reading and writing VBI images eese 81 4 8zShced V BI Data Interface ete pee He ei Utere o e Ut SU oer its 81 4 8 1 Querying Capabilities eene enne nnne 81 4 8 2 Supplemental FunctiOnS x iere ete t edet ei d ete e 82 4 8 3 Sliced VBI Format Negotiation sess eene 82 4 8 4 Reading and writing sliced VBI data
289. random error The delay and error can be much larger due to compression or transmission over an external bus when the frames are not properly stamped by the sender This is frequently the case 55 Chapter 3 Input Output with USB cameras Here timestamps refer to the instant the field or frame was received by the driver not the capture time These devices identify by not enumerating any video standards see Section 1 7 Similar limitations apply to output timestamps Typically the video hardware locks to a clock controlling the video timing the horizontal and vertical synchronization pulses At some point in the line sequence possibly the vertical blanking an interrupt routine samples the system clock compares against the timestamp and programs the hardware to repeat the previous field or frame or to display the buffer contents Apart of limitations of the video device and natural inaccuracies of all clocks it should be noted system time itself is not perfectly stable It can be affected by power saving cycles warped to insert leap seconds or even turned back or forth by the system administrator affecting long term measurements Table 3 1 struct v412 buffer u32 index Number of the buffer set by the application This field is only used for memory mapping I O and can range from zero to the number of buffers allocated with the VIDIOC_REQBUFS ioctl struct v412_requestbuffers count minus one enum v412_buf_typet ype Type
290. red or preferred or Mono L R IL R or IL R L R LANG1 Language 1 Langl Lang2 Language 1 Language 2 Lang 1 Lang2 LANG2 deprecatedb or preferred or Lang 1 Lang1 Lang 1 Lang1 Notes a This mode has been added in Linux 2 6 17 and may not be supported by older drivers b Playback of both Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The struct v412 tuner index is out of bounds 167 ioctl VIDIOC LOG STATUS Name VIDIOC LOG STATUS Log driver status information Synopsis int ioctl int fd int request Description As the video audio devices become more complicated it becomes harder to debug problems When this ioctl is called the driver will output the current device status to the kernel log This is particular useful when dealing with problems like no sound no video and incorrectly tuned channels Also many modern devices autodetect video and audio standards and this ioctl will report what the device thinks what the standard is Mismatches may give an indication where the problem is This ioctl is optional and not all drivers support it It was introduced in Linux 2 6 15 Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The driver does not support this ioctl 168 ioctl VIDIOC OVERLAY Name VIDIOC OVERLAY Start or stop Synopsis int ioctl int fd Arguments fd int reque
291. rent input or output applications call the VIDIOC_S_INPUT and VIDIOC S OUTPUT ioctl Drivers must implement all the input ioctls when the device has one or more inputs all the output ioctls when the device has one or more outputs Example 1 1 Information about the current video input struct v412 input input int index if 1 ioctl fd VIDIOC G INPUT amp index perror VIDIOC G INPUT exit EXIT FAILURE memset amp input 0 sizeof input input index index if 1 ioctl fd VIDIOC ENUMINPUT amp input perror VIDIOC ENUMINPUT exit EXIT_FAILURE printf Current input s n input name Chapter 1 Common API Elements Example 1 2 Switching to the first video input int index index 0 if 1 ioctl fd VIDIOC S INPUT amp index perror VIDIOC S INPUT exit EXIT_FAILURE 1 5 Audio Inputs and Outputs Audio inputs and outputs are physical connectors of a device Video capture devices have inputs output devices have outputs zero or more each Radio devices have no audio inputs or outputs They have exactly one tuner which in fact is an audio source but this API associates tuners with video inputs or outputs only and radio devices have none of these A connector on a TV card to loop back the received audio signal to a sound card is not considered an audio output Audio and video inputs and outputs are associated Selecting a video source al
292. rframe Time per frame in lus units x u32 extendedmode Driver specific extensions u32 readbuffers of buffers for read x 32 reserved 4 Flags for capability and capturemode fields define V4L2 MODE HIGHQUALITY 0x0001 High quality imaging mode define V4L2 CAP TIMEPERFRAME 0x1000 x timeperframe field is supported struct v412 outputparm u32 capability Supported modes x u32 outputmode Current mode struct v412 fract timeperframe Time per frame in seconds x u32 extendedmode Driver specific extensions u32 writebuffers of buffers for write x u32 reserved 4 E IN PUP E IMAGE CROPPING struct v412 cropcap enum v412 buf type type struct v412 rect bounds struct v412 rect defrect struct v412 fract pixelaspect H struct v412 crop enum v412 buf type type struct v412 rect 3 i ANALOG VIDEO STANDARD x typedef u64 v412 std ig one bit for each define V4L2 STD PAL B v412 std id 0x00000001 define V4L2 STD PAL B1 v412 std id 0x00000002 define V4L2 STD PAL G v412 std id 0x00000004 define V4L2 STD PAL H v412 std id 0x00000008 define V4L2 STD PAL I v412 std id 0x00000010 define V4L2 STD PAL D v412 std id 0x00000020 define V4L2 STD PAL D1 v412 std id 0x00000040 define V4L2 STD PAL K v412 std id 0x00000080 define V4L2 STD PAL M
293. river clears the flag and returns the first control with a higher ID Drivers which do not support this flag yet always return an EINVAL error code enum v412 ctrl type type Type of control see Table 3 u8 name 32 Name of the control a NUL terminated ASCII string This information is intended for the user 32 minimum Minimum value inclusive This field gives a lower bound for VAL2 CTRL TYPE INTEGER controls It may not be valid for any other type of control including V4L2_CTRL_TYPE_INTEGER64 controls Note this is a signed value 32 maximum Maximum value inclusive This field gives an upper bound for vVAL2 CTRL TYPE INTEGER controls and the highest valid index for V4L2 CTRL TYPE MENU controls It may not be valid for any other type of control including V4L2 CTRL TYPE INTEGER64A controls Note this is a signed value 178 32 832 u32 u32 step default value flags reserved 2 Table 2 struct v4l2 querymenu u32 u32 u8 u32 id index name 32 reserved Table 3 enum v4l2 ctrl type ioctl VIDIOC QUERYCTRL VIDIOC QUERYMENU This field gives a step size for V4L2 CTRL TYPE INTEGER controls It may not be valid for any other type of control including V4L2 CTRL TYPE INTEGER64 controls Generally drivers should not scale hardware control values It may be necessary for
294. river fills the v412 window substructure named win It is not possible to retrieve a previously programmed clipping list or bitmap To program the source rectangle applications set the t ype field of a struct v412 format to V4L2 BUF TYPE VIDEO OUTPUT OVERLAY initialize the win substructure and call the VIDIOC S FMT ioctl The driver adjusts the parameters against hardware limits and returns the actual parameters as VIDIOC G FMT does Like VIDIOC S FMT the VIDIOC TRY FMT ioctl can be used to learn about driver capabilities without actually changing driver state Unlike VIDIOC S FMT this also works after the overlay has been enabled 73 Chapter 4 Interfaces A struct v412_crop defines the size and position of the target rectangle The scaling factor of the overlay is implied by the width and height given in struct v412 window and struct v412 crop The cropping API applies to Video Output and Video Output Overlay devices in the same way as to Video Capture and Video Overlay devices merely reversing the direction of the data flow For more information see Section 1 11 4 4 4 Enabling Overlay There is no V4L2 ioctl to enable or disable the overlay however the framebuffer interface of the driver may support the FBIOBLANK ioctl 4 5 Codec Interface Suspended This interface has been be suspended from the V4L2 API implemented in Linux 2 6 until we have more experience with codec device interfaces
295. rn Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL Streaming I O is not supported the buffer t ype is not supported or no buffers have been allocated memory mapping or enqueued output yet 187 V4L2 mmap Name v412 mmap Map device memory into application address space Synopsis include lt unistd h gt include lt sys mman h gt void mmap void start size_t length int prot int flags int fd off t offset Arguments start Map the buffer to this address in the application s address space When the MAP FIXED flag is specified start must be a multiple of the pagesize and mmap will fail when the specified address cannot be used Use of this option is discouraged applications should just specify a NULL pointer here length Length of the memory area to map This must be the same value as returned by the driver in the struct v412 buffer length field prot The prot argument describes the desired memory protection Regardless of the device type and the direction of data exchange it should be set to PROT READ PROT WRITE permitting read and write access to image buffers Drivers should support at least this combination of flags Note the Linux video buf kernel module which is used by the bttv saa7134 saa7146 cx88 and vivi driver supports only PROT READ PROT WRITE When the driver does not support the desired protection the mmap function fai
296. rn an EINVAL error code when the index is out of bounds To enumerate all standards applications shall begin at index zero incrementing by one until the driver returns EINVAL Drivers may enumerate a different set of standards after switching the video input or output Table 1 struct v4l2 standard u32 index Number of the video standard set by the application v4l2 std id id The bits in this field identify the standard as one of the common standards listed in Table 3 or if bits 32 to 63 are set as custom standards Multiple bits can be set if the hardware does not distinguish between these standards however separate indices do not indicate the opposite The id must be unique No other enumerated v412 standard structure for this input or output anyway can contain the same set of bits 114 ioctl VIDIOC ENUMSTD u8 name 24 Name of the standard a NUL terminated ASCII string for example PAL B G NTSC Japan This information is intended for the user struct v412_fract frameperiod The frame period not field period is numerator denominator For example M NTSC has a frame period of 1001 30000 seconds u32 framelines Total lines per frame including blanking e g 625 for B PAL u32 reserved 4 Reserved for future extensions Drivers must set the array to zero Table 2 struct v412_fract u32 numerator u32 denominator Table 3 typedef v4I2 std id u64 v412 std id This type is a set each
297. rol This is needed since it is often required to atomically change several controls at once Each of the new ioctls expects a pointer to a struct v412 ext controls This structure contains a pointer to the control array a count of the number of controls in that array and a control class Control classes are used to group similar controls into a single class For example control class V4L2 CTRL CLASS USER contains all user controls i e all controls that can also be set using the old VIDIOC_S_CTRL ioctl Control class vV4L2 CTRL CLASS MPEG contains all controls relating to MPEG encoding etc All controls in the control array must belong to the specified control class An error is returned if this is not the case It is also possible to use an empty control array count 0 to check whether the specified control class is supported The control array is a struct v412 ext control array The v412 ext control structure is very similar to struct v412 control except for the fact that it also allows for 64 bit values and pointers to be passed although the latter is not yet used anywhere It is important to realize that due to the flexibility of controls it is necessary to check whether the control you want to set actually is supported in the driver and what the valid range of values is So use the VIDIOC_QUERYCTRL and VIDIOC_QUERYMENU ioctls to check this Also note that it is possible that some of the menu indices in
298. rs 1 6 3 Radio Frequency To get and set the tuner or modulator radio frequency applications use the VIDIOC G FREQUENCY and VIDIOC S FREQUENCY ioctl which both take a pointer to a struct v4I2 frequency These ioctls are used for TV and radio devices alike Drivers must support both ioctls when the tuner or modulator ioctls are supported or when the device is a radio device 1 6 4 Satellite Receivers To be discussed See also proposals by Peter Schlaf video4linux list 9 redhat com on 23 Oct 2002 subject Re VAL Re v412 api 1 7 Video Standards Video devices typically support one or more different video standards or variations of standards Each video input and output may support another set of standards This set is reported by the std field of struct v412_input and struct v412 output returned by the VIDIOC_ENUMINPUT and VIDIOC_ENUMOUTPUT ioctl respectively VAL2 defines one bit for each analog video standard currently in use worldwide and sets aside bits for driver defined standards e g hybrid standards to watch NTSC video tapes on PAL TVs and vice versa Applications can use the predefined bits to select a particular standard although presenting the user a menu of supported standards is preferred To enumerate and query the attributes of the supported standards applications use the VIDIOC_ENUMSTD ioctl Many of the defined standards are actually just variations of a few major standards
299. rsement of any Modified Version C 6 5 COMBINING DOCUMENTS You may combine the Document with other documents released under this License under the terms defined in section 4 above for modified versions provided that you include in the combination all of the Invariant Sections of all of the original documents unmodified and list them all as Invariant Sections of your combined work in its license notice The combined work need only contain one copy of this License and multiple identical Invariant Sections may be replaced with a single copy If there are multiple Invariant Sections with the same name but different contents make the title of each such section unique by adding at the end of it in parentheses the name of the original author or publisher of that section if known or else a unique number Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work In the combination you must combine any sections entitled History in the various original documents forming one section entitled History likewise combine any sections entitled Acknowledgements and any sections entitled Dedications You must delete all sections entitled Endorsements C 7 6 COLLECTIONS OF DOCUMENTS You may make a collection consisting of the Document and other documents released under this License and replace the individual copies of this License in the various documents w
300. s are hosted at http vAI2spec bytesex org and http linuxtv org downloads video4linux API V4L2_API Chapter 1 Common API Elements Programming a V4L2 device consists of these steps Opening the device Changing device properties selecting a video and audio input video standard picture brightness a o Negotiating a data format Negotiating an input output method The actual input output loop Closing the device In practice most steps are optional and can be executed out of order It depends on the V4L2 device type you can read about the details in Chapter 4 In this chapter we will discuss the basic concepts applicable to all devices 1 1 Opening and Closing Devices 1 1 1 Device Naming VAL2 drivers are implemented as kernel modules loaded manually by the system administrator or automatically when a device is first opened The driver modules plug into the videodev kernel module It provides helper functions and a common application interface specified in this document Each driver thus loaded registers one or more device nodes with major number 81 and a minor number between 0 and 255 Assigning minor numbers to V4L2 devices is entirely up to the system administrator this is primarily intended to solve conflicts between devices The module options to select minor numbers are named after the device special file with a nr suffix For example video nr for dev video video capture devices The number is an off
301. s stopped the driver resets the offset to zero The 33 bit Presentation Time Stamp of this picture as defined in ISO 13818 1 The length of this picture in bytes Flags containing the coding type of this picture see Table 3 Reserved for future extensions Drivers must set the array to zero This is an Intra coded picture This is a Predictive coded picture This is a Bidirectionally predictive coded picture AND the flags field with this mask to obtain the picture coding type On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The driver does not support this ioctl 131 ioctl VIDIOC G EXT CTRLS VIDIOC S EXT CTRLS VIDIOC TRY EXT CTRLS Name VIDIOC G EXT CTRLS VIDIOC S EXT CTRLS VIDIOC TRY EXT CTRLS Get or set the value of several controls try control values Synopsis int ioctl int fd int request struct v412 ext controls xargp Arguments fd File descriptor returned by open request VIDIOC_G_EXT_CTRLS VIDIOC_S_EXT_CTRLS VIDIOC_TRY_EXT_CTRLS argp Description These ioctls allow the caller to get or set multiple controls atomically Control IDs are grouped into control classes see Table 3 and all controls in the control array must belong to the same control class Applications must always fill in the count ctrl_class controls and reserved fields of struct v412_ext_controls and initialize the struct v412_ext_control array pointed
302. s three devices with minor number 0 64 and 224 this numbering scheme is inherited from the VAL API Regardless if dev video 81 0 or dev vbi 81 224 is opened the application can select any one of the video capturing overlay or VBI capturing functions Without programming e g reading from the device with dd or cat dev video captures video images while dev vbi captures raw VBI data dev radio 81 64 is invariable a radio device unrelated to the video functions Being unrelated does not imply the devices can be used at the same time however The open function may very well return an EBUSY error code Besides video input or output the hardware may also support audio sampling or playback If so these functions are implemented as OSS or ALSA PCM devices and eventually OSS or ALSA audio mixer The VAL2 API makes no provisions yet to find these related devices If you have an idea please write to the Video4Linux mailing list https listman redhat com mailman listinfo video4linux list 1 1 3 Multiple Opens In general VAL2 devices can be opened more than once When this is supported by the driver users can for example start a panel application to change controls like brightness or audio volume while Chapter 1 Common API Elements another application captures video and audio In other words panel applications are comparable to an OSS or ALSA audio mixer application When a device supports multiple functions like capturing a
303. se the encoder When the encoder has not been started yet the driver will return an EPERM error code When the encoder is already paused this command does nothing No flags are defined for this command Resume encoding after a PAUSE command When the encoder has not been started yet the driver will return an EPERM error code When the encoder is already running this command does nothing No flags are defined for this command Stop encoding at the end of the current Group Of Pictures rather than immediately On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The driver does not support this ioctl or the cmd field is invalid EPERM The application sent a PAUSE or RESUME command when the encoder was not running 98 ioctl VIDIOC ENUMAUDIO Name VIDIOC ENUMAUDIO Enumerate audio inputs Synopsis int ioctl int fd int request struct v412 audio xargp Arguments fd File descriptor returned by open request VIDIOC ENUMAUDIO argp Description To query the attributes of an audio input applications initialize the index field and zero out the reserved array of a struct v412 audio and call the VIDIOC_ENUMAUDIO ioctl with a pointer to this structure Drivers fill the rest of the structure or return an EINVAL error code when the index is out of bounds To enumerate all audio inputs applications shall begin at index zero incrementing by one until the driver returns E
304. set to the base minor number associated with the device type When the driver supports multiple devices of the same type more than one minor number can be assigned separated by commas gt insmod mydriver o video nr 0 1 radio nr 20 1 In etc modules conf this may be written as alias char major 81 0 mydriver alias char major 81 1 mydriver alias char major 81 64 mydriver o options mydriver video nr 0 1 radio nr 20 1 e9 Q When an application attempts to open a device special file with major number 81 and minor number 0 1 or 64 load mydriver and the videodev module it depends upon O Register the first two video capture devices with minor number 0 and 1 base number is 0 the first two radio device with minor number 64 and 65 base 64 Chapter 1 Common API Elements When no minor number is given as module option the driver supplies a default Chapter 4 recommends the base minor numbers to be used for the various device types Obviously minor numbers must be unique When the number is already in use the offending device will not be registered By convention system administrators create various character device special files with these major and minor numbers in the dev directory The names recomended for the different V4L2 device types are listed in Chapter 4 The creation of character special files with mknod is a privileged operation and devices cannot be opened by major and minor number That means applications cannot r
305. so selects an audio source This is most evident when the video and audio source is a tuner Further audio connectors can combine with more than one video input or output Assumed two composite video inputs and two audio inputs exist there may be up to four valid combinations The relation of video and audio connectors is defined in the audioset field of the respective struct v412_input or struct v412_output where each bit represents the index number starting at zero of one audio input or output To learn about the number and attributes of the available inputs and outputs applications can enumerate them with the VIDIOC_ENUMAUDIO and VIDIOC_ENUMAUDOUT ioctl respectively The struct v412_audio returned by the VIDIOC_ENUMAUDIO ioctl also contains signal status information applicable when the current audio input is queried The VIDIOC_G_AUDIO and VIDIOC_G_AUDOUT ioctl report the current audio input and output respectively Note that unlike VIDIOC_G_INPUT and VIDIOC_G_OUTPUT these ioctls return a structure as VIDIOC_ENUMAUDIO and VIDIOC ENUMAUDOUT do not just an index To select an audio input and change its properties applications call the vIDIOC S AUDIO ioctl To select an audio output which presently has no changeable properties applications call the VIDIOC S AUDOUT ioctl Drivers must implement all input ioctls when the device has one or more inputs all output ioctls when the device has one or more outputs When the device has a
306. space V4L2 defines the VIDIOC G PRIORITY and VIDIOC S PRIORITY ioctls to request and query the access priority associate with a file descriptor Opening a device assigns a medium priority compatible with earlier versions of V4L2 and drivers not supporting these ioctls Applications requiring a different priority will usually call VIDIOC_S_PRIORITY after verifying the device with the VIDIOC QUERYCAP ioctl Ioctls changing driver properties such as VIDIOC S INPUT return an EBUSY error code after another application obtained higher priority An event mechanism to notify applications about asynchronous property changes has been proposed but not added yet 1 4 Video Inputs and Outputs Video inputs and outputs are physical connectors of a device These can be for example RF connectors antenna cable CVBS a k a Composite Video S Video or RGB connectors Only video and VBI capture devices have inputs output devices have outputs at least one each Radio devices have no video inputs or outputs To learn about the number and attributes of the available inputs and outputs applications can enumerate them with the VIDIOC_ENUMINPUT and VIDIOC ENUMOUTPUT ioctl respectively The struct v4I2 input returned by the VIDIOC_ENUMINPUT ioctl also contains signal status information applicable when the current video input is queried The VIDIOC_G_INPUT and VIDIOC G OUTPUT ioctl return the index of the current video input or output To select a diffe
307. sscccsosgasuasuscescoceasasestesveass 184 ioctl VIDIOC STREAMON VIDIOC_STREAMOEF sscssssssssssssscesssscsssssscsessesssessocceeees 186 VAL2 MMAP E S 188 VAL2 MUNMAP siess ss ssss 190 VAL2 OPEN m 191 VAL 22 POll mE 193 V4L2 close Name v412 close Close a V4L2 device Synopsis include lt unistd h gt int close int fd Arguments fd File descriptor returned by open Description Closes the device Any I O in progress is terminated and resources associated with the file descriptor are freed However data format parameters current input or output control values or other properties remain unchanged Return Value The function returns 0 on success 1 on failure and the errno is set appropriately Possible error codes EBADF dis not a valid open file descriptor 89 V4L2 ioctl Name v412 ioctl Program a V4L2 device Synopsis include sys ioctl h int ioctl int fd int request void xargp Arguments fd File descriptor returned by open request VAL2 ioctl request code as defined in the videodev h header file for example VIDIOC QUERYCAP argp Pointer to a function parameter usually a structure Description The ioct1 function is used to program V4L2 devices The argument d must be an open file descriptor
308. st video overlay File descriptor returned by open request VIDIOC OVERLAY argp Description This ioctl is part of the video overlay I O method Applications call VIDIOC_OV const int xargp ERLAY to start or stop the overlay It takes a pointer to an integer which must be set to zero by the application to stop overlay to one to start Drivers do not support VIDIOC STRI VAL2 BUF TYPE VIDEO OVERLAY Return Value EAMON Or VIDIOC STR EAMOFF with On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL Video overlay is not supported or the parameters have not been set up See Section 4 2 for the necessary steps 169 ioctl VIDIOC QBUF VIDIOC DQBUF Name VIDIOC QBUF VIDIOC DOBUF Exchange a buffer with the driver Synopsis int ioctl int fd int request struct v412 buffer xargp Arguments fd File descriptor returned by open request VIDIOC_QBUF VIDIOC_DQBUF argp Description Applications call the vIDIOC OBUF ioctl to enqueue an empty capturing or filled output buffer in the driver s incoming queue The semantics depend on the selected I O method To enqueue a memory mapped buffer applications set the t ype field of a struct v412_buffer to the same buffer type as previously struct v412_format t ype and struct v412_requestbuffers type the memory field to V4L2_MEMORY_MMAP and the index field Valid inde
309. stating at least the title year new authors and publisher of the Modified Version as given on the Title Page If there is no section entitled History in the Document create one stating the title year authors and publisher of the Document as given on its Title Page then add an item describing the Modified Version as stated in the previous sentence e J Preserve the network location if any given in the Document for public access to a Transparent copy of the Document and likewise the network locations given in the Document for previous versions it was based on These may be placed in the History section You may omit a network location for a work that was published at least four years before the Document itself or if the original publisher of the version it refers to gives permission e K In any section entitled Acknowledgements or Dedications preserve the section s title and preserve in the section all the substance and tone of each of the contributor acknowledgements and or dedications given therein 265 Appendix C GNU Free Documentation License L Preserve all the Invariant Sections of the Document unaltered in their text and in their titles Section numbers or the equivalent are not considered part of the section titles M Delete any section entitled Endorsements Such a section may not be included in the Modified Version N Do not retitle any existing section as Endorsements or to confl
310. success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The struct v412_cropcap type is invalid or the ioctl is not supported This is not permitted for video capture output and overlay devices which must support VIDIOC_CROPCAP 93 ioctl VIDIOC DBG G REGISTER VIDIOC DBG S REGISTER Name VIDIOC DBG G REGISTER VIDIOC DBG S REGISTER Read or write hardware registers Synopsis int ioctl int fd int request struct v412 register argp int ioctl int fd int request const struct v412 register x argp Arguments fd File descriptor returned by open request VIDIOC_DBG_G_REGISTER VIDIOC_DBG_S_REGISTER argp Description Experimental This is an experimental interface and may change in the future For driver debugging purposes these ioctls allow test applications to access hardware registers directly Regular applications should not use them Since writing or even reading registers can jeopardize the system security its stability and damage the hardware both ioctls require superuser privileges Additionally the Linux kernel must be compiled with the CONFIG_VIDEO_ADV_DEBUG option to enable these ioctls To write a register applications must initialize all fields of a struct v412_register and call VIDIOC_DBG_S_REGISTER With a pointer to this structure The match type and match chip fields select a chip on the TV card the reg field specifies a regist
311. t four bytes a machine endianess integer contain a frame counter start 10 273 NTSC 22 335 PAL and SECAM count 16 16a flags 0 Notes a Old driver versions used different values eventually the custom BTTV VBISIZE ioctl was added to query th Undocumented in the VAL specification in Linux 2 3 the VIDIOCGVBIFMT and VIDIOCSVBIFMT ioctls using struct vbi format were added to determine the VBI image parameters These ioctls are 209 Chapter 6 Changes only partially compatible with the V4L2 VBI interface specified in Section 4 7 An offset field does not exist sample formatis supposed to be VIDEO PALETTE RAW equivalent to vVAL2 PIX FMT GREY The remaining fields are probably equivalent to struct v4I2 vbi format Apparently only the Zoran ZR 36120 driver implements these ioctls The semantics differ from those specified for VAL2 in two ways The parameters are reset on open and VIDIOCSVBIFMT always returns an EINVAL error code if the parameters are invalid 6 1 11 Miscellaneous V4L2 has no equivalent of the VIDIOCGUNIT ioctl Applications can find the VBI device associated with a video capture device or vice versa by reopening the device and requesting VBI data For details see Section 1 1 No replacement exists for VIDIOCKEY and the V4L functions for microcode programming A new interface for MPEG compression and playback devices is documented in Section 1 9 6
312. ter To catch the most likely failure we recommend a VIDIOC_G_CHIP_IDENT Call confirming the presence of the selected C chip These ioctls are optional not all drivers may support them However when a driver supports these ioctls it must also support VIDIOC G CHIP IDENT Conversely it may support VIDIOC G CHIP IDENT but not these ioctls VIDIOC DBG G REGISTER and VIDIOC DBG S REGISTER were introduced in Linux 2 6 21 We recommended the v412 dbg utility over calling these ioctls directly It is available from the LinuxTV v4l dvb repository see http linuxtv org repo for access instructions Table 1 struct v4l2 register u32 match type See Table 2 for a list of possible types u32 match chip Match a chip by this number interpreted according to the match type field u64 reg A register number u64 val The value read from or to be written into the register Table 2 Chip Match Types V4L2 CHIP MATCH HOST 0 Match the nth chip on the card zero for the host chip Does not match DC chips V4L2 CHIP MATCH I2C DRIVER 1 Match an LC chip by its driver ID from the linux i2c id h header file V4L2 CHIP MATCH I2C ADDR 2 Match a chip by its 7 bit bC bus address 95 ioctl VIDIOC DBG G REGISTER VIDIOC DBG S REGISTER Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The driver does not support this ioctl or the
313. ter calling VIDIOC S FMT are undefined When clip lists are supported but no clipping is desired this field must be set to zero When chroma keying has not been negotiated and VIDIOC G FBUF indicated this capability applications can set this field to point to a clipping bit mask 69 Chapter 4 Interfaces It must be of the same size as the window w width and w height Each bit corresponds to a pixel in the overlaid im u8 global alpha Notes Table 4 2 struct v412 clip struct v4I2 rect c struct v412_clip next Table 4 3 struct v412_rect 32 left 832 top 832 width 832 height 4 2 5 Enabling Overlay The global alpha value used to blend the framebuffer with video images if global alpha blending has been negotiated V4L2 FBUF FLAG GLOBAL ALPHA see VIDIOC S FBUF Table 3 Note this field was added in Linux 2 6 23 extending the structure However the VIDIOC G S TRY FMT ioctls which take a pointer to a v412 format parent structure with padding bytes at the end are not affected Coordinates of the clipping rectangle relative to the top left corner of the frame buffer Only window pixels outside all clipping rectangles are displayed Pointer to the next clipping rectangle NULL when this is the last rectangle Drivers ignore this field it cannot be used to pass a linked list of clipping rectangles Horizontal offset of the top left corner of the rectangle in pixels Vertical offset
314. than the category In other words there may be multiple groups within a category Controls within a group would typically be drawn within a group box Controls in different categories might have a greater separation or may even appear in separate windows The struct v4I2 buffer timestamp was changed to a 64 bit integer containing the sampling or output time of the frame in nanoseconds Additionally timestamps will be in absolute system time not starting from zero at the beginning of a stream The data type name for timestamps is stamp t defined as a signed 64 bit integer Output devices should not send a buffer out until the time in the timestamp field has arrived I would like to follow SGI s lead and adopt a multimedia timestamping system like their UST Unadjusted System Time See http reality sgi com cpirazzi_engr lg time intro html This link is no longer valid UST uses timestamps that are 64 bit signed integers not struct timeval s and given in nanosecond units The UST clock starts at zero when the system is booted and runs continuously and uniformly It takes a little over 292 years for UST to overflow There is no way to set the UST clock The regular Linux time of day clock can be changed periodically which would cause errors if it were being used for timestamping a multimedia stream A real UST style clock will require some support in the kernel that is not there yet But in anticipation I will change the timestamp fie
315. the driver not the captured frames Here the driver shall set the std field of struct v412 input and struct v412 output to zero the VIDIOC G STD VIDIOC S STD VIDIOC_QUERYSTD and VIDIOC_ENUMSTD ioctls shall return the EINVAL error code Example 1 5 Information about the current video standard v412 std id std id struct v412 standard standard if 1 ioctl fd VIDIOC G STD amp std id Note when VIDIOC ENUMSTD always returns EINVAL this is no video device or it falls under the USB exception and VIDIOC G STD returning EINVAL is no error x perror VIDIOC G STD exit EXIT FAILURE memset amp standard 0 sizeof standargad standard index 0 while 0 ioctl fd VIDIOC ENUMSTD amp standard if standard id amp std_id printf Current video standard s n standard name exit EXIT_SUCCESS standard indext EINVAL indicates the end of the enumeration which cannot be empty unless this device falls under the USB exception x if errno EINVAL standard index 0 perror VIDIOC_ENUMSTD exit EXIT_FAILURE Example 1 6 Listing the video standards supported by the current input struct v412 input input struct v412 standard standard memset amp input 0 sizeof input if 1 ioctl fd VIDIOC G INPUT amp input index perror VIDIOC G INPUT exit EXIT FAILURE if 1
316. the nearest integer and clamping to the range 0 255 finally yields the digital color components Y CbCr stored in YUV images Example 2 1 ITU R Rec BT 601 Forward Transformation int ER EG EB int Yi Cb Cr double r g b double yl pb pr int clamp double x int r x x if r lt 0 else if r gt 255 else r ER 255 0 g EG 255 0 b EB 255 0 yl 0 299 x r 0 587 pb 0 169 x r 0 331 pr 0 5 x r 0 419 Yl clamp 219 yl 16 Cb clamp 224 x pb 128 Cr clamp 224 x pr 128 or shorter x yl 0 299 x ER 0 587 x Yl clamp 219 255 0 Cb clamp 224 255 0 Cr clamp 224 255 0 Inverse Transformation int th Cbr Crs int ER EG EB double r g b double yl pb pr int clamp double x color conversion 0 255 x gamma corrected RGB input output 0 255 gt temporaries round to nearest x return 0 return 255 return r g 0 114 xg 305 g 0 081 i 0 114 x EB yl EB yl ER yl 2 2 x 0 114 2 2 0 299 0 255 x gamma pre corrected input output 0 255 gt temporaries 31 round to nearest ok one should prob 1 int r 2 x du t xu return 0 else if r 255 return 255 else return r yl 255 219 0 Y1 16 pb 255 224 0 Cb 128 p
317. the reserved array of a struct v412 tuner and call the VIDIOC_G_TUNER ioctl with a pointer to this structure Drivers fill the rest of the structure or return an EINVAL error code when the index is out of bounds To enumerate all tuners applications shall begin at index zero incrementing by one until the driver returns EINVAL Tuners have two writable properties the audio mode and the radio frequency To change the audio mode applications initialize the index audmode and reserved fields and call the VIDIOC S TUNER ioctl This will not change the current tuner which is determined by the current video input Drivers may choose a different audio mode if the requested mode is invalid or unsupported Since this is a write only ioctl it does not return the actually selected audio mode To change the radio frequency the vib1OC S FREQUENCY ioctl is available Table 1 struct v412_tuner u32 index Identifies the tuner set by the application u8 name 32 Name of the tuner a NUL terminated ASCII string enum v4l2 tuner type type Type of the tuner see Table 2 163 u32 capability u32 rangelow u32 rangehigh u32 rxsubchans u32 audmode u32 signal 832 afc u32 reserved 4 Table 2 enum v4l2 tuner type V4L2 TUNER RADIO V4L2 TUNER ANALOG TV 2 Table 3 Tuner and Modulator Capability Flags ioctl VIDIOC G TUNER VIDIOC S TUNER Tuner capability flags see Table 3
318. the sense of other bounds another default and current value step size or other menu items A control with a certain custom ID can also change name and type Control values are stored globally they do not change when switching except to stay within the reported bounds They also do not change e g when the device is opened or closed when the tuner radio frequency is changed or generally never without application request Since VAL2 specifies no event mechanism panel applications intended to cooperate with other panel applications be they built into a larger application as a TV viewer may need to regularly poll control values to update their user interface Table 1 1 Control IDs ID Type Description V4L2 CID BASE First predefined ID equal to V4L2 CID BRIGHTNESS V4L2 CID USER BASE Synonym of V4L2 CID BASE V4L2 CID BRIGHTNESS integer Picture brightness or more precisely the black level V4L2 CID CONTRAST integer Picture contrast or luma gain V4L2 CID SATURATION integer Picture color saturation or chroma gain V4L2 CID HUE integer Hue or color balance V4L2 CID AUDIO VOLUME integer Overall audio volume Note some drivers also provide an OSS or ALSA mixer interface V4L2 CID AUDIO BALANCE integer Audio stereo balance Minimum corresponds to all the way left maximum to right V4L2 CID AUDIO BASS integer Audio bass adjustment V4L2 CID AUDIO TREBLE integer Audio treble adjustment
319. the struct v412_buffer length field Description Unmaps a previously with the mmap function mapped buffer and frees it if possible Return Value On success munmap returns 0 on failure 1 and the errno variable is set appropriately EINVAL The start or length is incorrect or no buffers have been mapped yet 190 V4L2 open Name v412 open Open a V4L2 device Synopsis include fcntl h int open const char device name int flags Arguments device name Device to be opened flags Open flags Access mode must be O_RDWR This is just a technicality input devices still support only reading and output devices only writing When the o NONBLOCK flag is given the read function and the VIDIOC_DQBUF ioctl will return the EAGAIN error code when no data is available or no buffer is in the driver outgoing queue otherwise these functions block until data becomes available All V4L2 drivers exchanging data with applications must support the O NONBLOCK flag Other flags have no effect Description To open a V4L2 device applications call open with the desired device name This function has no side effects all data format parameters current input or output control values or other properties remain unchanged At the first open call after loading the driver they will be reset to default values drivers are never in an undefined state Return Value On success open returns the new file descriptor
320. tion for in an AVI or so COM is the same but it s comments like encoded by me or so jpeg markers describes whether the huffman tables quantization tables and the restart interval information all JPEG specific stuff should be stored in the JPEG encoded fields These define how the JPEG field is encoded If you omit them applications assume you ve used standard encoding You usually do want to add them Table 1 struct v412_jpegcompression int quality int APPn int APP len char APP data 60 147 int char u32 Table 2 JPEG Markers Flags COM len ioctl VIDIOC G JPEGCOMP VIDIOC S JPEGCOMP COM data 60 jpeg markers VAL2 JP VAL2 JP EG MARK ER DH EG MARK ER DQ VAL2 JP EG MARK ER DRI VAL2 JP EG MARK ER COM VAL2 JP EG MARK ER APP Return Value 1 3 1 4 1 5 1 lt lt 6 1 7 See Table 2 Define Huffman Tables Define Quantization Tables Define Restart Interval Comment segment App segment driver will always use APPO On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL This ioctl is not supported 148 ioctl VIDIOC G MODULATOR VIDIOC S MODULATOR Name VIDIOC G MODULATOR VIDIOC S MODULATOR Get or set modulator attributes Synopsis int ioctl int fd int request struct v412 modulator xargp int ioctl int fd int request const struct v412 modulator x
321. tions use the read function to write the write function Drivers must implement one I O method if they exchange data with applications but it need not be this When reading or writing is supported the driver must also support the select and poll function 3 2 Streaming I O Memory Mapping Input and output devices support this I O method when the v4L2_CAP_STREAMING flag in the capabilities field of struct v412 capability returned by the VIDIOC_QUERYCAP ioctl is set There 51 Chapter 3 Input Output are two streaming methods to determine if the memory mapping flavor is supported applications must call the VIDIOC_REQBUFS ioctl Streaming is an I O method where only pointers to buffers are exchanged between application and driver the data itself is not copied Memory mapping is primarily intended to map buffers in device memory into the application s address space Device memory can be for example the video memory on a graphics card with a video capture add on However being the most efficient I O method available for a long time many other drivers support streaming as well allocating buffers in DMA able main memory A driver can support many sets of buffers Each set is identified by a unique buffer type value The sets are independent and each set can hold a different type of data To access different sets at the same time different file descriptors must be used To allocate device buffers applications call th
322. tl VIDIOC_G_AUDIO VIDIOC_S_AUDIO sese ener 119 ioctl VIDIOC_G_AUDOUT VIDIOC_S_AUDOUT ccc eccccccessecesseeeeseesenenteecnseeeees 121 ioctl VIDIOC G CHIP IDENT eseseeeeeeeeeeen enne enne eene enne nnne erret rnnt nennen 123 ioctl VIDIOC G CROP VIDIOC S CROP sese 126 ioctl VIDIOC_G_CTRL VIDIOC S CTRL eaa E ennemi 128 ioctl VIDIOC G ENC INDEX sese entere eren ernst a a nen rns anaiai 130 ioctl VIDIOC G EXT CTRLS VIDIOC EXT CTRLS VIDIOC TRY EXT CTRLS132 ioctl VIDIOC_G_FBUF VIDIOC S FBUPF eese nennen enne 135 ioctl VIDIOC G FMT VIDIOC S FMT VIDIOC TRY FMT een 140 ioctl VIDIOC G FREQUENCY VIDIOC S FREQUENCY eene 143 ioctl VIDIOC_G_INPUT VIDIOC S INPUT essere nennen nennen 145 ioctl VIDIOC_G_JPEGCOMP VIDIOC S JPEGCOMP sse eene 147 ioctl VIDIOC G MODULATOR VIDIOC S MODULATOR eee 149 ioctl VIDIOC G OUTPUT VIDIOC S OUTPUT enne 152 ioctl VIDIOC_G_PARM VIDIOC S PARM sees enne nennen enne nnn 154 ioctl VIDIOC G PRIORITY VIDIOC S PRIORITY eese 158 ioctl VIDIOC G SLICED VBI CAP 4 ES EERE enn nene nnn 160 ioctl VIDIOC G STD VIDIOC S STD esses enne nennen enne nnne 162 ioctl VIDIOC G TUNER VIDIOC S TUNER esee ene 163 ioctl VIDIOC
323. trols However the same applies to AVL which is still there Again for consistency the struct v412 audioout field audio was renamed to index The struct v4I2 tuner input field was replaced by an index field permitting devices with multiple tuners The link between video inputs and tuners is now reversed inputs point to their tuner The std substructure became a simple set more about this below and moved into struct v412 input A type field was added Accordingly in struct v412 modulator the output was replaced by an index field In struct v412 frequency the port field was replaced by a tuner field containing the respective tuner or modulator index number A tuner t ype field was added and the reserved field became larger for future extensions satellite tuners in particular The idea of completely transparent video standards was dropped Experience showed that applications must be able to work with video standards beyond presenting the user a menu Instead of enumerating supported standards with an ioctl applications can now refer to standards by v412 std id and symbols defined in the videodev2 h header file For details see Section 1 7 The VIDIOC_G_STD and VIDIOC S STD now take a pointer to this type as argument VIDIOC_QUERYSTD was added to autodetect the received standard if the hardware has this capability In struct v412 standard an index field was added for VIDIOC_ENUMSTD A v412_std_id field name
324. ts If your document contains nontrivial examples of program code we recommend releasing these examples in parallel under your choice of free software license such as the GNU General Public License http www gnu org copyleft gpl html to permit their use in free software 268 L i st of Ty pes struct v4I2 standard struct v412_streamparm struct v412_ timecode v412 std id enum v412 buf type struct v412_tuner struct v412 vbi format enum v412_colorspace struct v4I2 window enum v4lI2 ctrl type enum v4D2 field enum v412_frmivaltypes enum v412_frmsizetypes enum v4l2 memory enum v4l2 priority enum v4l2 tuner type struct v412_ audio struct v412_audioout struct v412 buffer struct v412 capability struct v412_captureparm struct v412 chip ident struct v412 clip struct v412 control struct v412_crop struct v412_cropcap struct v412 enc idx struct v4I2 enc idx entry struct v4l2 encoder cmd struct v412 ext control struct v412 ext controls struct v412_fmtdesc struct v412 format struct v412 fract struct v412 framebuffer struct v412 frequency struct v412_frmival_stepwise struct v412 frmivalenum struct v412 frmsize discrete struct v412_frmsize_stepwise struct v412 frmsizeenum struct v412 input struct v412_jpegcompression struct v412 modulator struct v4I2 output struct v412_outputparm struct v4I2 pix format struct v412_queryctrl struct v412_querymenu struct v412 rect struct
325. tted order The driver can insert empty packets with id set to zero anywhere in the packet array To assure synchronization and to distinguish from frame dropping when a captured frame does not carry any of the requested data services drivers must pass one or more empty packets When an application fails to pass VBI data in time for output the driver must output the last VPS and WSS packet again and disable the output of Closed Caption and Teletext data or output data which is ignored by Closed Caption and Teletext decoders A sliced VBI device may support read write and or streaming memory mapping and or user pointer I O The latter bears the possibility of synchronizing video and VBI data by using buffer timestamps 4 9 Teletext Interface This interface aims at devices receiving and demodulating Teletext data ETS 300 706 ITU BT 653 evaluating the Teletext packages and storing formatted pages in cache memory Such devices are 84 Chapter 4 Interfaces usually implemented as microcontrollers with serial interface C and can be found on older TV cards dedicated Teletext decoding cards and home brew devices connected to the PC parallel port The Teletext API was designed by Martin Buck It is defined in the kernel header file linux videotext h the specification is available from http home pages de videotext Videotext is the name of the German public television Teletext service Conventional character device file names are
326. ture example x This program can be used and distributed without restrictions include lt stdio h gt include lt stdlib h gt include lt string h gt include lt assert h gt include lt getopt h gt getopt long include fcntl h low level i o x include lt unistd h gt include lt errno h gt include lt malloc h gt include lt sys stat h gt include lt sys types h gt include lt sys time h gt include lt sys mman h gt include lt sys ioctl h gt include lt asm types h gt for videodev2 h include lt linux videodev2 h gt define CLEAR x memset amp x 0 sizeof x typedef enum IO_METHOD_READ IO_METHOD_MMAP IO_METHOD_USERPTR io method I struct buffer void x start size t length un static char x dev name NULL static io method io IO METHOD MMAP static int fd 1 struct buffer x buffers NULL static unsigned int n buffers 0 static void errno_exit const char x S fprintf stderr s error d s n S errno strerror errno 251 Appendix B Video Capture Example exit EXIT FAILURE static int xioctl int fd int request void arg int qi do r ioctl fd request arg while 1 r amp amp EINTR errno return r static void process image const void x p fputc stdout fflush stdout static int read frame void struct v412
327. tureparm and struct v412_outputparm the t imeperframe field gives the time in seconds not microseconds 6 2 20 V4L2 spec erratum 2006 02 04 1 The clips field in struct v412_window must point to an array of struct v412_clip not a linked list because drivers ignore the struct v412_clip next pointer 6 2 21 V4L2 in Linux 2 6 17 1 New video standard macros were added V4L2_STD_NTSC_M_KR NTSC M South Korea and the sets VAL2 STD MN V4L2 STD B V4L2 STD GH and VA4L2 STD DK The VA4L2 STD NTSC and V4L2 STD SECAM sets now include V4 2 STD NTSC M KR and VAL2 STD SECAM LC respectively 2 A new V4AL2 TUNER MODE LANG1 LANG2 was defined to record both languages of a bilingual program The use of vVAL2 TUNER MODE STEREO for this purpose is deprecated now See the VIDIOC G TUNER section for details 6 2 22 VAL2 spec erratum 2006 09 23 Draft 0 15 1 In various places V4AL2 BUF TYPE SLICED VBI CAPTURE and VAL2 BUF TYPE SLICED VBI OUTPUT of the sliced VBI interface were not mentioned along with other buffer types 220 Chapter 6 Changes N In ioctl VIDIOC_G_AUDIO VIDIOC_S_AUDIO 2 it was clarified that the struct v412_audio mode field is a flags field W ioctl VIDIOC_QUERYCAP 2 did not mention the sliced VBI and radio capability flags 4 In ioctl VIDIOC_G_FREQUENCY VIDIOC_S_FREQUENCY 2 it was clarified that applications
328. uct v412 pix format pix member of the fmt union To request different parameters applications set the type field of a struct v412 format as above and initialize all fields of the struct v412 pix format vbi member of the fmt union or better just modify the results of VIDIOC_G_FMT and call the VIDIOC_S_FMT ioctl with a pointer to this structure Drivers may adjust the parameters and finally return the actual parameters as VIDIOC G FMT does 66 Chapter 4 Interfaces Like VIDIOC S rFMT the VIDIOC TRY FMT ioctl can be used to learn about hardware limitations without disabling I O or possibly time consuming hardware preparations The contents of struct v412 pix format are discussed in Chapter 2 See also the specification of the VIDIOC G FMT VIDIOC S FMT and VIDIOC TRY FWT ioctls for details Video capture devices must implement both the VIDIOC_G_FMT and VIDIOC S FMT ioctl even if VIDIOC S FMT ignores all requests and always returns default parameters as VIDIOC G FMT does VIDIOC TRY FMT is optional 4 1 4 Reading Images A video capture device may support the read function and or streaming memory mapping or user pointer I O See Chapter 3 for details 4 2 Video Overlay Interface Video overlay devices have the ability to genlock TV video into the VGA video signal of a graphics card or to store captured images directly in video memory of a graphics card typically with clipping This can be considerable more
329. ue New value or current value Return Value On success 0 is returned on error 1 and the errno variable is set appropriately 128 ioctl VIDIOC G CTRL VIDIOC S CTRL EINVAL The struct v412 control id is invalid ERANGE The struct v412 control value is out of bounds EBUSY The control is temporarily not changeable possibly because another applications took over control of the device function this control belongs to 129 ioctl VIDIOC G ENC INDEX Name VIDIOC G ENC INDEX Get meta data about a compressed video stream Synopsis int ioctl int fd int request struct v412 enc idx xargp Arguments fd File descriptor returned by open request VIDIOC_G_ENC_INDEX argp Description Experimental This is an experimental interface and may change in the future The VIDIOC_G_ENC_INDEx ioctl provides meta data about a compressed video stream the same or another application currently reads from the driver which is useful for random access into the stream without decoding it To read the data applications must call VIDIOC_G_ENC_INDEX with a pointer to a struct v412_enc_idx On success the driver fills the ent ry array stores the number of elements written in the ent ries field and initializes the entries_cap field Each element of the ent ry array contains meta data about one picture A VIDIOC_G_ENC_INDEX call reads up to V4L2_ENC_IDX_ENTRIES entries from a driver buffer which can
330. until the end of the top row of pixels Following the rightmost pixel of the row there may be zero or more bytes of padding to guarantee that each row of pixel data has a certain alignment Following the pad bytes if any is data for the leftmost pixel of the second row from the top and so on The last row has just as many pad bytes after it as the other rows In V4L2 each format has an identifier which looks like PIX FMT XXX defined in the videodev h header file These identifiers represent four character codes which are also listed below however they are not the same as those used in the Windows world 2 2 Colorspaces intro Gamma Correction to do E KR E 2 f G E f B Construction of luminance and color difference signals to do E Coeff E p Coeff E Coeff E E E E Coeff E Coeff E Coeff E E E E Coeff FE Coeff E Coeff E Re normalized color difference signals The color difference signals are scaled back to unity range 0 5 0 5 K 0 5 1 Coeff K 0 5 1 Coeff P K E E 2 0 5 Coeff Coeff E p 0 5 Coeff Coeff E 0 5 E P K E Ey 20 5 E 0 5 Coeff Coeff E 0 5 Coeff Coeff E Quantization to do Y Lum Levels 1 E Lum Offset C Chrom Levels 1 Pa Chrom Offset 30 C Chrom Levels 1 P Chapter 2 Image Formats Chrom Offset Rounding to
331. upper limit in this example of 640 x 400 pixels at offset 0 0 An application requests an image size of 300 x 225 pixels assuming video will be scaled down from the full picture accordingly The driver sets the image size to the closest possible values 304 x 224 then chooses the cropping rectangle closest to the requested size that is 608 x 224 224 x 2 1 would exceed the limit 400 The offset 0 0 is still valid thus unmodified Given the default cropping rectangle reported by VIDIOC_CROPCAP the application can easily propose another offset to center the cropping rectangle Now the application may insist on covering an area using a picture aspect ratio closer to the original request so it asks for a cropping rectangle of 608 x 456 pixels The present scaling factors limit cropping to 640 x 384 so the driver returns the cropping size 608 x 384 and adjusts the image size to closest possible 304 x 192 1 11 3 Examples Source and target rectangles shall remain unchanged across closing and reopening a device such 24 Chapter 1 Common API Elements that piping data into or out of a device will work without special preparations More advanced applications should ensure the parameters are suitable before starting I O Example 1 10 Resetting the cropping parameters A video capture device is assumed change VAL2 BUF TYPE VIDEO CAPTURE for other devices struct v412 cropcap cropcap struct v412 crop crop memset
332. ur blocks when no buffer is in the outgoing queue When the o NONBLOCK flag was given to the open function VIDIOC DOBUF returns immediately with an EAGAIN error code when no buffer is available The select or poll function are always available To start and stop capturing or output applications call the VIDIOC_STREAMON and VIDIOC STREAMOFF ioctl Note VIDIOC STREAMOFF removes all buffers from both queues as a side effect Since there is no notion of doing anything now on a multitasking system if an application needs to synchronize with another event it should examine the struct v412 buffer timestamp of captured buffers or set the field before enqueuing buffers for output Drivers implementing memory mapping I O must support the VIDIOC_REQBUFS VIDIOC QUERYBUF VIDIOC OBUF VIDIOC DOBUF VIDIOC_STREAMON and VIDIOC_STREAMOFF ioctl the mmap munmap select and poll function capture example 3 3 Streaming I O User Pointers Input and output devices support this I O method when the v4L2_CAP_STREAMING flag in the capabilities field of struct v412_capability returned by the VIDIOC_QUERYCAP ioctl is set If the particular user pointer method not only memory mapping is supported must be determined by calling the VIDIOC_REQBUFS ioctl This I O method combines advantages of the read write and memory mapping methods Buffers are allocated by the application itself and can reside for exampl
333. ut in an integer and call the VIDIOC S OUTPUT ioctl with a pointer to this integer Side effects are possible For example outputs may support different video standards so the driver may implicitly switch the current standard It is good practice to select an output before querying or negotiating any other parameters Information about video outputs is available using the VIDIOC_ENUMOUTPUT ioctl Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The number of the video output is out of bounds or there are no video outputs at all and this ioctl is not supported 152 ioctl VIDIOC G OUTPUT VIDIOC S OUTPUT EBUSY I O is in progress the output cannot be switched 153 ioctl VIDIOC G PARM VIDIOC S PARM Name VIDIOC G PARM VIDIOC S PARM Get or set streaming parameters Synopsis int ioctl int fd int request v412 streamparm argp Arguments fd File descriptor returned by open request VIDIOC G PARM VIDIOC S8 PARM argp Description The current video standard determines a nominal number of frames per second If less than this number of frames is to be captured or output applications can request frame skipping or duplicating on the driver side This is especially useful when using the read or write which are not augmented by timestamps or sequence counters and to avoid unneccessary data copying Further these ioctls can be used to
334. ut index field This ioctl will fail only when there are no video inputs returning EINVAL To select a video input applications store the number of the desired input in an integer and call the VIDIOC S INPUT ioctl with a pointer to this integer Side effects are possible For example inputs may support different video standards so the driver may implicitly switch the current standard It is good practice to select an input before querying or negotiating any other parameters Information about video inputs is available using the VIDIOC_ENUMINPUT ioctl Return Value On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The number of the video input is out of bounds or there are no video inputs at all and this ioctl is not supported 145 ioctl VIDIOC G INPUT VIDIOC S INPUT EBUSY I O is in progress the input cannot be switched 146 ioctl VIDIOC G JPEGCOMP VIDIOC S JPEGCOMP Name VIDIOC G JPEGCOMP VIDIOC S JPEGCOMP Synopsis int ioctl int fd int request v412 jpegcompression argp int ioctl int fd int request const v412 jpegcompression xargp Arguments fd File descriptor returned by open request VIDIOC G JPEGCOMP VIDIOC 5 JPEGCOMP argp Description to do Ronald Bultje elaborates APP is some application specific information The application can set it itself and it ll be stored in the JPEG encoded fields eg interlacing informa
335. utomatically select audio outputs without enumerating them For details on audio outputs and how to select the current output see Section 1 5 Output devices can have zero or more RF modulators When the type is V4L2 OUTPUT TYPE MODULATOR this is an RF connector and this field identifies the modulator It corresponds to struct v412 modulator field index For details on modulators see Section 1 6 Every video output supports one or more different video standards This field is a set of all supported standards For details on video standards and how to switch see Section 1 7 Reserved for future extensions Drivers must set the array to zero This output is an analog TV modulator Analog baseband output for example Composite CVBS S Video RGB On success 0 is returned on error 1 and the errno variable is set appropriately EINVAL The struct v412 output index is out of bounds 113 ioctl VIDIOC ENUMSTD Name VIDIOC_ENUMSTD Enumerate supported video standards Synopsis int ioctl int fd int request struct v412 standard xargp Arguments fd File descriptor returned by open request VIDIOC ENUMSTD argp Description To query the attributes of a video standard especially a custom driver defined one applications initialize the index field of struct v412 standard and call the VIDIOC_ENUMSTD ioctl with a pointer to this structure Drivers fill the rest of the structure or retu
336. utput Overlay interface set the V4L2_CAP_VIDEO_OUTPUT_OVERLAY flag in the capabilities field of struct v412_capability returned by the VIDIOC_QUERYCAP ioctl 4 4 2 Framebuffer Contrary to the Video Overlay interface the framebuffer is normally implemented on the TV card and not the graphics card On Linux it is accessible as a framebuffer device dev fbN Given a V4L2 device applications can find the corresponding framebuffer device by calling the VIDIOC_G_FBUF ioctl It returns amongst other information the physical address of the framebuffer in the base field of struct v412_framebuffer The framebuffer device ioctl FRIOGET_FSCREENINFO returns the same address in the smem start field of struct fb fix screeninfo The FBIOGET FSCREENINFO ioctl and struct fb fix screeninfo are defined in the 1inux fb h header file The width and height of the framebuffer depends on the current video standard A V4L2 driver may reject attempts to change the video standard or any other ioctl which would imply a framebuffer size change with an EBUSY error code until all applications closed the framebuffer device Example 4 1 Finding a framebuffer device for OSD finclude lt linux fb h gt struct v412 framebuffer fbuf unsigned int i int fb fd if 1 ioctl fd VIDIOC G FBUF amp fbuf perror VIDIOC G FBUF exit EXIT_FAILURE 72 Chapter 4 Interfaces for i 0 i lt 30 i
337. v412 register struct v412_requestbuffers struct v412 sliced vbi cap struct v412 sliced vbi data struct v412 sliced vbi format 269 References EIA 608 B Electronic Industries Alliance http www eia org EIA 608 B Recommended Practice for Line 21 Data Service EN 300 294 European Telecommunication Standards Institute http www etsi org EN 300 294 625 line television Wide Screen Signalling WSS ETS 300 231 European Telecommunication Standards Institute http www etsi org ETS 300 231 Specification of the domestic video Programme Delivery Control system PDC ETS 300 706 European Telecommunication Standards Institute http www etsi org ETS 300 706 Enhanced Teletext specification ISO 13818 1 International Telecommunication Union http www itu ch International Organisation for Standardisation http www iso ch ITU T Rec H 222 0 ISO IEC 13818 1 Information technology Generic coding of moving pictures and associated audio information Systems ISO 13818 2 International Telecommunication Union http www itu ch International Organisation for Standardisation http www iso ch ITU T Rec H 262 ISO IEC 13818 2 Information technology Generic coding of moving pictures and associated audio information Video ITU BT 470 International Telecommunication Union http www itu ch ITU R Recommendation BT 470 6 Conventional Television Systems ITU BT 601 International
338. v412 std id 0x00000100 define V4L2 STD PAL N v412 std id 0x00000200 235 v4 v4 define define v4 v4 v4 v4 define define define define v4 v4 v4 v4 v4 v4 v4 v4 define define define define define define define define ATSC HD define VAI L2 S L2 S L2 S L2 S L2 S L2 S L2 S L2 S L2 S L2 S L2 S L2 S L2 S L2 S D PAL D PAL 60 Nc SC M SC M JP SC 443 SC M KR Wn onu0tu TV x UU UV VV OU Uu QU uututut t L2 S define VAI FIXME Although std id is 64 bits there is an issue on makes switch u64 to break SC 8 VSB L2 S this value to 32 bits As currently the max value is for V4L2 STD ATSC 16 VSB it should work fine SC 16 VSB However v4 v4 v4l2 common c should be fixed So 12 5 12 s 12 s l2 8 l2 8 LAs 8 12 8 Lats I2 ow 12 s 12 s 12 s 12 s 12 s 12 s q 2 5 Appendix A Video For Linux Two Header File td_id 0x00 td_id 0x00 id id id id 0x0010 0x0020 0x0040 0x0080 td id 0x0100 td id 0x0200 000400 000800 001000 002000 004000 008000 01 02 04 08 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 PPC32 architecture that there s a hack on v4l2 common
339. vices not all aspects of the API are equally applicable to all types of devices Furthermore devices of the same type have different capabilities and this specification permits the omission of a few complicated and less important parts of the API The VIDIOC_QUERYCAP ioctl is available to check if the kernel device is compatible with this specification and to query the functions and I O methods supported by the device Other features can be queried by calling the respective ioctl for example VIDIOC_ENUMINPUT to learn about the number types and names of video connectors on the device Although abstraction is a major objective of this API the ioctl also allows driver specific applications to reliable identify the driver All V4L2 drivers must support VIDIOC QUERYCAP Applications should always call this ioctl after opening the device 1 3 Application Priority When multiple applications share a device it may be desirable to assign them different priorities Contrary to the traditional rm rf school of thought a video recording application could for example block other applications from changing video controls or switching the current TV channel Another objective is to permit low priority applications working in background which can be Chapter 1 Common API Elements preempted by user controlled applications and automatically regain control of the device at a later time Since these features cannot be implemented entirely in user
340. x numbers range from zero to the number of buffers allocated with VIDIOC_REQBUFS struct v412 requestbuffers count minus one The contents of the struct v412_buffer returned by a VIDIOC_QUERYBUF ioctl will do as well When the buffer is intended for output t ype is V4L2_BUF_TYPE_VIDEO_OUTPUT or V4L2_BUF_TYPE_VBI_OUTPUT applications must also initialize the bytesused field and timestamp fields See Section 3 5 for details When VIDIOC_QBUF is called with a pointer to this structure the driver sets the V4L2_BUF_FLAG_MAPPED and V4L2_BUF_FLAG_QUEUED flags and clears the V4L2_BUF_FLAG_DONE flag in the flags field or it returns an EINVAL error code To enqueue a user pointer buffer applications set the type field of a struct v412_buffer to the same buffer type as previously struct v412_format t ype and struct v412_requestbuffers t ype the memory field to V4L2_MEMORY_USERPTR and the m userpt r field to the address of the buffer and length to its size When the buffer is intended for output additional fields must be set as above When VIDIOC_QBUF is called with a pointer to this structure the driver sets the V4L2_BUF_FLAG_QUEUED flag and clears the V4L2_BUF_FLAG_MAPPED and V4L2_BUF_FLAG_DONE flags in the flags field or it returns an error code This ioctl locks the memory pages of the buffer in physical memory they 170 ioctl VIDIOC QBUF VIDIOC DQBUF cannot be swapped out to dis
341. xel of a video image is implied by the selected image format V4L2 does not explicitely provide such information assuming applications recognizing the format are aware of the image depth and others need not know The palette field moved into the struct v412_pix_format struct video picture palette struct v4l2 pix format pixfmt VIDEO PALETTE GREY V4L2 PIX FMT GREY VIDEO PALETTE HI240 V4L2 PIX FMT HI240a VIDEO PALETTE RGB565 V4L2 PIX FMT RGB565 VIDEO PALETTE RGB555 VA4L2 PIX FMT RGB555 VIDEO PALETTE RGB24 VA4L2 PIX FMT BGR24 VIDEO PALETTE RGB32 V4L2 PIX FMT BGR32 VIDEO PALETTE YUV422 VA4L2 PIX FMT YUYV VIDEO PALETTE YUYV VAL2 PIX FMT YUYV VIDEO PALETTE UYVY VA4L2 PIX FMT UYVY VIDEO PALETTE YUV420 None VIDEO_PALETTE_YUV411 V4L2 PIX FMT Y41Pa VIDEO PALETTE RAW INone e VIDEO PALETTE YUV422P VA4L2 PIX FMT YUV422P VIDEO PALETTE YUV411P VA4L2 PIX FMT YUV411Pr VIDEO PALETTE YUV420P VA4L2 PIX FMT YVU420 VIDEO PALETTE YUV410P VA4L2 PIX FMT YVU410 Notes a This is a custom format used by the BTTV driver not one of the V4L2 standard formats b Presumably al V4L2 image formats are defined in Chapter 2 The image format can be selected with the VIDIOC S FMT ioctl 6 1 6 Audio The VIDIOCGAUDIO and VIDIOCSAUDI
342. y on the actual cover and continue the rest onto adjacent pages If you publish or distribute Opaque copies of the Document numbering more than 100 you must either include a machine readable Transparent copy along with each Opaque copy or state in or with each Opaque copy a publicly accessible computer network location containing a complete Transparent copy of the Document free of added material which the general network using public has access to download anonymously at no charge using public standard network protocols If you use the latter option you must take reasonably prudent steps when you begin distribution of Opaque copies in quantity to ensure that this Transparent copy will remain thus accessible at the stated 264 Appendix C GNU Free Documentation License location until at least one year after the last time you distribute an Opaque copy directly or through your agents or retailers of that edition to the public It is requested but not required that you contact the authors of the Document well before redistributing any large number of copies to give them a chance to provide you with an updated version of the Document C 5 4 MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above provided that you release the Modified Version under precisely this License with the Modified Version filling the role of the Document thus licensing distribution and modif
Download Pdf Manuals
Related Search
Related Contents
PDF Format User Manual - Squarespace (MagLev) Student Handout Samsung SM-T116 Наръчник за потребителя Optimus 27 User's Manual KW Suspension Systems Installation Instructions スマート・リンク・プラス 取扱説明書 User Guide A Subgraph Operator for Graph Transformation Languages Copyright © All rights reserved.
Failed to retrieve file