vidioc-g-selection.rst 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. .. -*- coding: utf-8; mode: rst -*-
  2. .. _VIDIOC_G_SELECTION:
  3. ********************************************
  4. ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
  5. ********************************************
  6. Name
  7. ====
  8. VIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles
  9. Synopsis
  10. ========
  11. .. c:function:: int ioctl( int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp )
  12. :name: VIDIOC_G_SELECTION
  13. .. c:function:: int ioctl( int fd, VIDIOC_S_SELECTION, struct v4l2_selection *argp )
  14. :name: VIDIOC_S_SELECTION
  15. Arguments
  16. =========
  17. ``fd``
  18. File descriptor returned by :ref:`open() <func-open>`.
  19. ``request``
  20. VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
  21. ``argp``
  22. Description
  23. ===========
  24. The ioctls are used to query and configure selection rectangles.
  25. To query the cropping (composing) rectangle set struct
  26. :c:type:`v4l2_selection` ``type`` field to the
  27. respective buffer type. Do not use the multiplanar buffer types. Use
  28. ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` instead of
  29. ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and use
  30. ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` instead of
  31. ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``. The next step is setting the
  32. value of struct :c:type:`v4l2_selection` ``target``
  33. field to ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer
  34. to table :ref:`v4l2-selections-common` or :ref:`selection-api` for
  35. additional targets. The ``flags`` and ``reserved`` fields of struct
  36. :c:type:`v4l2_selection` are ignored and they must be
  37. filled with zeros. The driver fills the rest of the structure or returns
  38. EINVAL error code if incorrect buffer type or target was used. If
  39. cropping (composing) is not supported then the active rectangle is not
  40. mutable and it is always equal to the bounds rectangle. Finally, the
  41. struct :c:type:`v4l2_rect` ``r`` rectangle is filled with
  42. the current cropping (composing) coordinates. The coordinates are
  43. expressed in driver-dependent units. The only exception are rectangles
  44. for images in raw formats, whose coordinates are always expressed in
  45. pixels.
  46. To change the cropping (composing) rectangle set the struct
  47. :c:type:`v4l2_selection` ``type`` field to the
  48. respective buffer type. Do not use multiplanar buffers. Use
  49. ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` instead of
  50. ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``. Use
  51. ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` instead of
  52. ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``. The next step is setting the
  53. value of struct :c:type:`v4l2_selection` ``target`` to
  54. ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer to table
  55. :ref:`v4l2-selections-common` or :ref:`selection-api` for additional
  56. targets. The struct :c:type:`v4l2_rect` ``r`` rectangle need
  57. to be set to the desired active area. Field struct
  58. :c:type:`v4l2_selection` ``reserved`` is ignored and
  59. must be filled with zeros. The driver may adjust coordinates of the
  60. requested rectangle. An application may introduce constraints to control
  61. rounding behaviour. The struct :c:type:`v4l2_selection`
  62. ``flags`` field must be set to one of the following:
  63. - ``0`` - The driver can adjust the rectangle size freely and shall
  64. choose a crop/compose rectangle as close as possible to the requested
  65. one.
  66. - ``V4L2_SEL_FLAG_GE`` - The driver is not allowed to shrink the
  67. rectangle. The original rectangle must lay inside the adjusted one.
  68. - ``V4L2_SEL_FLAG_LE`` - The driver is not allowed to enlarge the
  69. rectangle. The adjusted rectangle must lay inside the original one.
  70. - ``V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE`` - The driver must choose the
  71. size exactly the same as in the requested rectangle.
  72. Please refer to :ref:`sel-const-adjust`.
  73. The driver may have to adjusts the requested dimensions against hardware
  74. limits and other parts as the pipeline, i.e. the bounds given by the
  75. capture/output window or TV display. The closest possible values of
  76. horizontal and vertical offset and sizes are chosen according to
  77. following priority:
  78. 1. Satisfy constraints from struct
  79. :c:type:`v4l2_selection` ``flags``.
  80. 2. Adjust width, height, left, and top to hardware limits and
  81. alignments.
  82. 3. Keep center of adjusted rectangle as close as possible to the
  83. original one.
  84. 4. Keep width and height as close as possible to original ones.
  85. 5. Keep horizontal and vertical offset as close as possible to original
  86. ones.
  87. On success the struct :c:type:`v4l2_rect` ``r`` field
  88. contains the adjusted rectangle. When the parameters are unsuitable the
  89. application may modify the cropping (composing) or image parameters and
  90. repeat the cycle until satisfactory parameters have been negotiated. If
  91. constraints flags have to be violated at then ``ERANGE`` is returned. The
  92. error indicates that *there exist no rectangle* that satisfies the
  93. constraints.
  94. Selection targets and flags are documented in
  95. :ref:`v4l2-selections-common`.
  96. .. _sel-const-adjust:
  97. .. figure:: vidioc-g-selection_files/constraints.*
  98. :alt: constraints.png
  99. :align: center
  100. Size adjustments with constraint flags.
  101. Behaviour of rectangle adjustment for different constraint flags.
  102. .. c:type:: v4l2_selection
  103. .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
  104. .. flat-table:: struct v4l2_selection
  105. :header-rows: 0
  106. :stub-columns: 0
  107. :widths: 1 1 2
  108. * - __u32
  109. - ``type``
  110. - Type of the buffer (from enum
  111. :c:type:`v4l2_buf_type`).
  112. * - __u32
  113. - ``target``
  114. - Used to select between
  115. :ref:`cropping and composing rectangles <v4l2-selections-common>`.
  116. * - __u32
  117. - ``flags``
  118. - Flags controlling the selection rectangle adjustments, refer to
  119. :ref:`selection flags <v4l2-selection-flags>`.
  120. * - struct :c:type:`v4l2_rect`
  121. - ``r``
  122. - The selection rectangle.
  123. * - __u32
  124. - ``reserved[9]``
  125. - Reserved fields for future use. Drivers and applications must zero
  126. this array.
  127. Return Value
  128. ============
  129. On success 0 is returned, on error -1 and the ``errno`` variable is set
  130. appropriately. The generic error codes are described at the
  131. :ref:`Generic Error Codes <gen-errors>` chapter.
  132. EINVAL
  133. Given buffer type ``type`` or the selection target ``target`` is not
  134. supported, or the ``flags`` argument is not valid.
  135. ERANGE
  136. It is not possible to adjust struct :c:type:`v4l2_rect`
  137. ``r`` rectangle to satisfy all constraints given in the ``flags``
  138. argument.
  139. ENODATA
  140. Selection is not supported for this input or output.
  141. EBUSY
  142. It is not possible to apply change of the selection rectangle at the
  143. moment. Usually because streaming is in progress.