libv4l2.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 __LIBV4L2_H
  18. #define __LIBV4L2_H
  19. #include <stdio.h>
  20. #include <unistd.h>
  21. #include <stdint.h>
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif /* __cplusplus */
  25. #if HAVE_VISIBILITY
  26. #define LIBV4L_PUBLIC __attribute__ ((visibility("default")))
  27. #else
  28. #define LIBV4L_PUBLIC
  29. #endif
  30. /* Point this to a FILE opened for writing when you want to log error and
  31. status messages to a file, when NULL errors will get send to stderr */
  32. LIBV4L_PUBLIC extern FILE *v4l2_log_file;
  33. /* Just like your regular open/close/etc, except that format conversion is
  34. done if necessary when capturing. That is if you (try to) set a capture
  35. format which is not supported by the cam, but is supported by libv4lconvert,
  36. then the try_fmt / set_fmt will succeed as if the cam supports the format
  37. and on dqbuf / read the data will be converted for you and returned in
  38. the request format. enum_fmt will also report support for the formats to
  39. which conversion is possible.
  40. Another difference is that you can make v4l2_read() calls even on devices
  41. which do not support the regular read() method.
  42. Note the device name passed to v4l2_open must be of a video4linux2 device,
  43. if it is anything else (including a video4linux1 device), v4l2_open will
  44. fail.
  45. Note that the argument to v4l2_ioctl after the request must be a valid
  46. memory address of structure of the appropriate type for the request (for
  47. v4l2 requests which expect a structure address). Passing in NULL or an
  48. invalid memory address will not lead to failure with errno being EFAULT,
  49. as it would with a real ioctl, but will cause libv4l2 to break, and you
  50. get to keep both pieces.
  51. */
  52. LIBV4L_PUBLIC int v4l2_open(const char *file, int oflag, ...);
  53. LIBV4L_PUBLIC int v4l2_close(int fd);
  54. LIBV4L_PUBLIC int v4l2_dup(int fd);
  55. LIBV4L_PUBLIC int v4l2_ioctl(int fd, unsigned long int request, ...);
  56. LIBV4L_PUBLIC ssize_t v4l2_read(int fd, void *buffer, size_t n);
  57. LIBV4L_PUBLIC ssize_t v4l2_write(int fd, const void *buffer, size_t n);
  58. LIBV4L_PUBLIC void *v4l2_mmap(void *start, size_t length, int prot, int flags,
  59. int fd, int64_t offset);
  60. LIBV4L_PUBLIC int v4l2_munmap(void *_start, size_t length);
  61. /* Misc utility functions */
  62. /* This function takes a value of 0 - 65535, and then scales that range to
  63. the actual range of the given v4l control id, and then if the cid exists
  64. and is not locked sets the cid to the scaled value.
  65. Normally returns 0, even if the cid did not exist or was locked, returns
  66. non 0 when an other error occurred. */
  67. LIBV4L_PUBLIC int v4l2_set_control(int fd, int cid, int value);
  68. /* This function returns a value of 0 - 65535, scaled to from the actual range
  69. of the given v4l control id. When the cid does not exist, or could not be
  70. accessed -1 is returned. */
  71. LIBV4L_PUBLIC int v4l2_get_control(int fd, int cid);
  72. /* "low level" access functions, these functions allow somewhat lower level
  73. access to libv4l2 (currently there only is v4l2_fd_open here) */
  74. /* Flags for v4l2_fd_open's v4l2_flags argument */
  75. /* Disable all format conversion done by libv4l2, this includes the software
  76. whitebalance, gamma correction, flipping, etc. libv4lconvert does. Use this
  77. if you want raw frame data, but still want the additional error checks and
  78. the read() emulation libv4l2 offers. */
  79. #define V4L2_DISABLE_CONVERSION 0x01
  80. /* This flag is *OBSOLETE*, since version 0.5.98 libv4l *always* reports
  81. emulated formats to ENUM_FMT, except when conversion is disabled. */
  82. #define V4L2_ENABLE_ENUM_FMT_EMULATION 0x02
  83. /* v4l2_fd_open: open an already opened fd for further use through
  84. v4l2lib and possibly modify libv4l2's default behavior through the
  85. v4l2_flags argument.
  86. Returns fd on success, -1 if the fd is not suitable for use through libv4l2
  87. (note the fd is left open in this case). */
  88. LIBV4L_PUBLIC int v4l2_fd_open(int fd, int v4l2_flags);
  89. #ifdef __cplusplus
  90. }
  91. #endif /* __cplusplus */
  92. #endif