libv4lconvert.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. # (C) 2008 Hans de Goede <hdegoede@redhat.com>
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU Lesser General Public License as published by
  5. # the Free Software Foundation; either version 2.1 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU Lesser General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU Lesser General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  16. */
  17. #ifndef __LIBV4LCONVERT_H
  18. #define __LIBV4LCONVERT_H
  19. /* These headers are not needed by us, but by linux/videodev2.h,
  20. which is broken on some systems and doesn't include them itself :( */
  21. #ifdef linux
  22. #include <sys/time.h>
  23. #include <linux/types.h>
  24. #include <linux/ioctl.h>
  25. #endif
  26. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
  27. #include <sys/time.h>
  28. #include <sys/types.h>
  29. #include <sys/ioctl.h>
  30. #endif
  31. /* end broken header workaround includes */
  32. #include <linux/videodev2.h>
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif /* __cplusplus */
  36. #if HAVE_VISIBILITY
  37. #define LIBV4L_PUBLIC __attribute__ ((visibility("default")))
  38. #else
  39. #define LIBV4L_PUBLIC
  40. #endif
  41. struct libv4l_dev_ops;
  42. struct v4lconvert_data;
  43. LIBV4L_PUBLIC const struct libv4l_dev_ops *v4lconvert_get_default_dev_ops();
  44. LIBV4L_PUBLIC struct v4lconvert_data *v4lconvert_create(int fd);
  45. LIBV4L_PUBLIC struct v4lconvert_data *v4lconvert_create_with_dev_ops(int fd,
  46. void *dev_ops_priv, const struct libv4l_dev_ops *dev_ops);
  47. LIBV4L_PUBLIC void v4lconvert_destroy(struct v4lconvert_data *data);
  48. /* When doing flipping / rotating / video-processing, only supported
  49. destination formats can be used (as flipping / rotating / video-processing
  50. is not supported on other formats). This function can be used to query
  51. if that is the case. */
  52. LIBV4L_PUBLIC int v4lconvert_supported_dst_fmt_only(
  53. struct v4lconvert_data *data);
  54. /* With regards to dest_fmt just like VIDIOC_TRY_FMT, except that the try
  55. format will succeed and return the requested V4L2_PIX_FMT_foo in dest_fmt if
  56. the cam has a format from which v4lconvert can convert to dest_fmt.
  57. The real format to which the cam should be set is returned through src_fmt
  58. when not NULL.
  59. Note that just like the real VIDIOC_TRY_FMT this function will change the
  60. dest_fmt when not supported. This includes changing it to a supported
  61. destination format when trying a native format of the camera and
  62. v4lconvert_supported_dst_fmt_only() returns true. */
  63. LIBV4L_PUBLIC int v4lconvert_try_format(struct v4lconvert_data *data,
  64. struct v4l2_format *dest_fmt, /* in / out */
  65. struct v4l2_format *src_fmt); /* out */
  66. /* Like VIDIOC_ENUM_FMT, but the emulated formats are added at the end of the
  67. list, except if flipping / processing is active for the device, then only
  68. supported destination formats are listed */
  69. LIBV4L_PUBLIC int v4lconvert_enum_fmt(struct v4lconvert_data *data,
  70. struct v4l2_fmtdesc *fmt);
  71. /* Is conversion necessary or can the app use the data directly? */
  72. LIBV4L_PUBLIC int v4lconvert_needs_conversion(struct v4lconvert_data *data,
  73. const struct v4l2_format *src_fmt, /* in */
  74. const struct v4l2_format *dest_fmt); /* in */
  75. /* This function does the following conversions:
  76. - format conversion
  77. - cropping
  78. if enabled:
  79. - processing (auto whitebalance, auto gain, gamma correction)
  80. - horizontal/vertical flipping
  81. - 90 degree (clockwise) rotation
  82. NOTE: the last 3 steps are enabled/disabled depending on
  83. - the internal device list
  84. - the state of the (software emulated) image controls
  85. Therefore this function should
  86. - not be used when getting the frames from libv4l
  87. - be called only once per frame
  88. Otherwise this may result in unintended double conversions !
  89. Returns the amount of bytes written to dest and -1 on error */
  90. LIBV4L_PUBLIC int v4lconvert_convert(struct v4lconvert_data *data,
  91. const struct v4l2_format *src_fmt, /* in */
  92. const struct v4l2_format *dest_fmt, /* in */
  93. unsigned char *src, int src_size, unsigned char *dest, int dest_size);
  94. /* get a string describing the last error */
  95. LIBV4L_PUBLIC const char *v4lconvert_get_error_message(struct v4lconvert_data *data);
  96. /* Just like VIDIOC_ENUM_FRAMESIZE, except that the framesizes of emulated
  97. formats can be enumerated as well. */
  98. LIBV4L_PUBLIC int v4lconvert_enum_framesizes(struct v4lconvert_data *data,
  99. struct v4l2_frmsizeenum *frmsize);
  100. /* Just like VIDIOC_ENUM_FRAMEINTERVALS, except that the intervals of emulated
  101. formats can be enumerated as well. */
  102. LIBV4L_PUBLIC int v4lconvert_enum_frameintervals(struct v4lconvert_data *data,
  103. struct v4l2_frmivalenum *frmival);
  104. /* Pass calls to query, get and set video controls to the libv4lcontrol class */
  105. LIBV4L_PUBLIC int v4lconvert_vidioc_queryctrl(struct v4lconvert_data *data,
  106. void *arg);
  107. LIBV4L_PUBLIC int v4lconvert_vidioc_g_ctrl(struct v4lconvert_data *data,
  108. void *arg);
  109. LIBV4L_PUBLIC int v4lconvert_vidioc_s_ctrl(struct v4lconvert_data *data,
  110. void *arg);
  111. LIBV4L_PUBLIC int v4lconvert_vidioc_g_ext_ctrls(struct v4lconvert_data *data,
  112. void *arg);
  113. LIBV4L_PUBLIC int v4lconvert_vidioc_try_ext_ctrls(struct v4lconvert_data *data,
  114. void *arg);
  115. LIBV4L_PUBLIC int v4lconvert_vidioc_s_ext_ctrls(struct v4lconvert_data *data,
  116. void *arg);
  117. /* Is the passed in pixelformat supported as destination format? */
  118. LIBV4L_PUBLIC int v4lconvert_supported_dst_format(unsigned int pixelformat);
  119. /* Get/set the no fps libv4lconvert uses to decide if a compressed format
  120. must be used as src fmt to stay within the bus bandwidth */
  121. LIBV4L_PUBLIC int v4lconvert_get_fps(struct v4lconvert_data *data);
  122. LIBV4L_PUBLIC void v4lconvert_set_fps(struct v4lconvert_data *data, int fps);
  123. /* Fixup bytesperline and sizeimage for supported destination formats */
  124. LIBV4L_PUBLIC void v4lconvert_fixup_fmt(struct v4l2_format *fmt);
  125. #ifdef __cplusplus
  126. }
  127. #endif /* __cplusplus */
  128. #endif