Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 1 | .. -*- coding: utf-8; mode: rst -*- |
| 2 | |
| 3 | .. _output: |
| 4 | |
| 5 | ********************** |
| 6 | Video Output Interface |
| 7 | ********************** |
| 8 | |
| 9 | Video output devices encode stills or image sequences as analog video |
| 10 | signal. With this interface applications can control the encoding |
| 11 | process and move images from user space to the driver. |
| 12 | |
| 13 | Conventionally V4L2 video output devices are accessed through character |
| 14 | device special files named ``/dev/video`` and ``/dev/video0`` to |
| 15 | ``/dev/video63`` with major number 81 and minor numbers 0 to 63. |
| 16 | ``/dev/video`` is typically a symbolic link to the preferred video |
| 17 | device. Note the same device files are used for video capture devices. |
| 18 | |
| 19 | |
| 20 | Querying Capabilities |
| 21 | ===================== |
| 22 | |
| 23 | Devices supporting the video output interface set the |
| 24 | ``V4L2_CAP_VIDEO_OUTPUT`` or ``V4L2_CAP_VIDEO_OUTPUT_MPLANE`` flag in |
| 25 | the ``capabilities`` field of struct |
| 26 | :ref:`v4l2_capability <v4l2-capability>` returned by the |
Mauro Carvalho Chehab | 7347081 | 2016-07-01 13:58:44 -0300 | [diff] [blame] | 27 | :ref:`VIDIOC_QUERYCAP` ioctl. As secondary device |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 28 | functions they may also support the :ref:`raw VBI output <raw-vbi>` |
| 29 | (``V4L2_CAP_VBI_OUTPUT``) interface. At least one of the read/write or |
| 30 | streaming I/O methods must be supported. Modulators and audio outputs |
| 31 | are optional. |
| 32 | |
| 33 | |
| 34 | Supplemental Functions |
| 35 | ====================== |
| 36 | |
| 37 | Video output devices shall support :ref:`audio output <audio>`, |
| 38 | :ref:`modulator <tuner>`, :ref:`controls <control>`, |
| 39 | :ref:`cropping and scaling <crop>` and |
| 40 | :ref:`streaming parameter <streaming-par>` ioctls as needed. The |
| 41 | :ref:`video output <video>` and :ref:`video standard <standard>` |
| 42 | ioctls must be supported by all video output devices. |
| 43 | |
| 44 | |
| 45 | Image Format Negotiation |
| 46 | ======================== |
| 47 | |
| 48 | The output is determined by cropping and image format parameters. The |
| 49 | former select an area of the video picture where the image will appear, |
| 50 | the latter how images are stored in memory, i. e. in RGB or YUV format, |
| 51 | the number of bits per pixel or width and height. Together they also |
| 52 | define how images are scaled in the process. |
| 53 | |
| 54 | As usual these parameters are *not* reset at :ref:`open() <func-open>` |
| 55 | time to permit Unix tool chains, programming a device and then writing |
| 56 | to it as if it was a plain file. Well written V4L2 applications ensure |
| 57 | they really get what they want, including cropping and scaling. |
| 58 | |
| 59 | Cropping initialization at minimum requires to reset the parameters to |
| 60 | defaults. An example is given in :ref:`crop`. |
| 61 | |
| 62 | To query the current image format applications set the ``type`` field of |
| 63 | a struct :ref:`v4l2_format <v4l2-format>` to |
| 64 | ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` or ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`` |
Mauro Carvalho Chehab | 4e03cb7 | 2016-07-03 10:02:29 -0300 | [diff] [blame] | 65 | and call the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 66 | to this structure. Drivers fill the struct |
| 67 | :ref:`v4l2_pix_format <v4l2-pix-format>` ``pix`` or the struct |
| 68 | :ref:`v4l2_pix_format_mplane <v4l2-pix-format-mplane>` ``pix_mp`` |
| 69 | member of the ``fmt`` union. |
| 70 | |
| 71 | To request different parameters applications set the ``type`` field of a |
| 72 | struct :ref:`v4l2_format <v4l2-format>` as above and initialize all |
| 73 | fields of the struct :ref:`v4l2_pix_format <v4l2-pix-format>` |
| 74 | ``vbi`` member of the ``fmt`` union, or better just modify the results |
Mauro Carvalho Chehab | 4e03cb7 | 2016-07-03 10:02:29 -0300 | [diff] [blame] | 75 | of :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 76 | ioctl with a pointer to this structure. Drivers may adjust the |
Mauro Carvalho Chehab | 4e03cb7 | 2016-07-03 10:02:29 -0300 | [diff] [blame] | 77 | parameters and finally return the actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 78 | does. |
| 79 | |
Mauro Carvalho Chehab | 2212ff2 | 2016-07-01 14:33:56 -0300 | [diff] [blame] | 80 | Like :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` the :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 81 | can be used to learn about hardware limitations without disabling I/O or |
| 82 | possibly time consuming hardware preparations. |
| 83 | |
| 84 | The contents of struct :ref:`v4l2_pix_format <v4l2-pix-format>` and |
| 85 | struct :ref:`v4l2_pix_format_mplane <v4l2-pix-format-mplane>` are |
| 86 | discussed in :ref:`pixfmt`. See also the specification of the |
Mauro Carvalho Chehab | 4e03cb7 | 2016-07-03 10:02:29 -0300 | [diff] [blame] | 87 | :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctls for |
| 88 | details. Video output devices must implement both the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` |
Mauro Carvalho Chehab | 2212ff2 | 2016-07-01 14:33:56 -0300 | [diff] [blame] | 89 | and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, even if :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ignores all |
Mauro Carvalho Chehab | 4e03cb7 | 2016-07-03 10:02:29 -0300 | [diff] [blame] | 90 | requests and always returns default parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. |
Mauro Carvalho Chehab | 2212ff2 | 2016-07-01 14:33:56 -0300 | [diff] [blame] | 91 | :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` is optional. |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 92 | |
| 93 | |
| 94 | Writing Images |
| 95 | ============== |
| 96 | |
| 97 | A video output device may support the :ref:`write() function <rw>` |
| 98 | and/or streaming (:ref:`memory mapping <mmap>` or |
| 99 | :ref:`user pointer <userp>`) I/O. See :ref:`io` for details. |