00001 /* 00002 # (C) 2008 Hans de Goede <hdegoede@redhat.com> 00003 00004 # This program is free software; you can redistribute it and/or modify 00005 # it under the terms of the GNU Lesser General Public License as published by 00006 # the Free Software Foundation; either version 2.1 of the License, or 00007 # (at your option) any later version. 00008 # 00009 # This program is distributed in the hope that it will be useful, 00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 # GNU Lesser General Public License for more details. 00013 # 00014 # You should have received a copy of the GNU Lesser General Public License 00015 # along with this program; if not, write to the Free Software 00016 # Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 00017 */ 00018 00019 #ifndef __LIBV4L2_H 00020 #define __LIBV4L2_H 00021 00022 #include <stdio.h> 00023 #include <unistd.h> 00024 #include <stdint.h> 00025 00026 #ifdef __cplusplus 00027 extern "C" { 00028 #endif /* __cplusplus */ 00029 00030 #if HAVE_VISIBILITY 00031 #define LIBV4L_PUBLIC __attribute__ ((visibility("default"))) 00032 #else 00033 #define LIBV4L_PUBLIC 00034 #endif 00035 00036 /* Point this to a FILE opened for writing when you want to log error and 00037 status messages to a file, when NULL errors will get send to stderr */ 00038 LIBV4L_PUBLIC extern FILE *v4l2_log_file; 00039 00040 /* Just like your regular open/close/etc, except that format conversion is 00041 done if necessary when capturing. That is if you (try to) set a capture 00042 format which is not supported by the cam, but is supported by libv4lconvert, 00043 then the try_fmt / set_fmt will succeed as if the cam supports the format 00044 and on dqbuf / read the data will be converted for you and returned in 00045 the request format. enum_fmt will also report support for the formats to 00046 which conversion is possible. 00047 00048 Another difference is that you can make v4l2_read() calls even on devices 00049 which do not support the regular read() method. 00050 00051 Note the device name passed to v4l2_open must be of a video4linux2 device, 00052 if it is anything else (including a video4linux1 device), v4l2_open will 00053 fail. 00054 00055 Note that the argument to v4l2_ioctl after the request must be a valid 00056 memory address of structure of the appropriate type for the request (for 00057 v4l2 requests which expect a structure address). Passing in NULL or an 00058 invalid memory address will not lead to failure with errno being EFAULT, 00059 as it would with a real ioctl, but will cause libv4l2 to break, and you 00060 get to keep both pieces. 00061 */ 00062 00063 LIBV4L_PUBLIC int v4l2_open(const char *file, int oflag, ...); 00064 LIBV4L_PUBLIC int v4l2_close(int fd); 00065 LIBV4L_PUBLIC int v4l2_dup(int fd); 00066 LIBV4L_PUBLIC int v4l2_ioctl(int fd, unsigned long int request, ...); 00067 LIBV4L_PUBLIC ssize_t v4l2_read(int fd, void *buffer, size_t n); 00068 LIBV4L_PUBLIC ssize_t v4l2_write(int fd, const void *buffer, size_t n); 00069 LIBV4L_PUBLIC void *v4l2_mmap(void *start, size_t length, int prot, int flags, 00070 int fd, int64_t offset); 00071 LIBV4L_PUBLIC int v4l2_munmap(void *_start, size_t length); 00072 00073 00074 /* Misc utility functions */ 00075 00076 /* This function takes a value of 0 - 65535, and then scales that range to 00077 the actual range of the given v4l control id, and then if the cid exists 00078 and is not locked sets the cid to the scaled value. 00079 00080 Normally returns 0, even if the cid did not exist or was locked, returns 00081 non 0 when an other error occured. */ 00082 LIBV4L_PUBLIC int v4l2_set_control(int fd, int cid, int value); 00083 00084 /* This function returns a value of 0 - 65535, scaled to from the actual range 00085 of the given v4l control id. When the cid does not exist, or could not be 00086 accessed -1 is returned. */ 00087 LIBV4L_PUBLIC int v4l2_get_control(int fd, int cid); 00088 00089 00090 /* "low level" access functions, these functions allow somewhat lower level 00091 access to libv4l2 (currently there only is v4l2_fd_open here) */ 00092 00093 /* Flags for v4l2_fd_open's v4l2_flags argument */ 00094 00095 /* Disable all format conversion done by libv4l2, this includes the software 00096 whitebalance, gamma correction, flipping, etc. libv4lconvert does. Use this 00097 if you want raw frame data, but still want the additional error checks and 00098 the read() emulation libv4l2 offers. */ 00099 #define V4L2_DISABLE_CONVERSION 0x01 00100 /* This flag is *OBSOLETE*, since version 0.5.98 libv4l *always* reports 00101 emulated formats to ENUM_FMT, except when conversion is disabled. */ 00102 #define V4L2_ENABLE_ENUM_FMT_EMULATION 0x02 00103 00104 /* v4l2_fd_open: open an already opened fd for further use through 00105 v4l2lib and possibly modify libv4l2's default behavior through the 00106 v4l2_flags argument. 00107 00108 Returns fd on success, -1 if the fd is not suitable for use through libv4l2 00109 (note the fd is left open in this case). */ 00110 LIBV4L_PUBLIC int v4l2_fd_open(int fd, int v4l2_flags); 00111 00112 #ifdef __cplusplus 00113 } 00114 #endif /* __cplusplus */ 00115 00116 #endif