| 1 |
/* |
| 2 |
# (C) 2008 Hans de Goede <[email protected]> |
| 3 |
|
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU Lesser General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2.1 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU Lesser General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU Lesser General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef __LIBV4L2_H |
| 20 |
#define __LIBV4L2_H |
| 21 |
|
| 22 |
#include <stdio.h> |
| 23 |
#include <unistd.h> |
| 24 |
#include <stdint.h> |
| 25 |
|
| 26 |
#ifdef __cplusplus |
| 27 |
extern "C" { |
| 28 |
#endif /* __cplusplus */ |
| 29 |
|
| 30 |
#if HAVE_VISIBILITY |
| 31 |
#define LIBV4L_PUBLIC __attribute__ ((visibility("default"))) |
| 32 |
#else |
| 33 |
#define LIBV4L_PUBLIC |
| 34 |
#endif |
| 35 |
|
| 36 |
/* Point this to a FILE opened for writing when you want to log error and |
| 37 |
status messages to a file, when NULL errors will get send to stderr */ |
| 38 |
LIBV4L_PUBLIC extern FILE *v4l2_log_file; |
| 39 |
|
| 40 |
/* Just like your regular open/close/etc, except that format conversion is |
| 41 |
done if necessary when capturing. That is if you (try to) set a capture |
| 42 |
format which is not supported by the cam, but is supported by libv4lconvert, |
| 43 |
then the try_fmt / set_fmt will succeed as if the cam supports the format |
| 44 |
and on dqbuf / read the data will be converted for you and returned in |
| 45 |
the request format. enum_fmt will also report support for the formats to |
| 46 |
which conversion is possible. |
| 47 |
|
| 48 |
Another difference is that you can make v4l2_read() calls even on devices |
| 49 |
which do not support the regular read() method. |
| 50 |
|
| 51 |
Note the device name passed to v4l2_open must be of a video4linux2 device, |
| 52 |
if it is anything else (including a video4linux1 device), v4l2_open will |
| 53 |
fail. |
| 54 |
|
| 55 |
Note that the argument to v4l2_ioctl after the request must be a valid |
| 56 |
memory address of structure of the appropriate type for the request (for |
| 57 |
v4l2 requests which expect a structure address). Passing in NULL or an |
| 58 |
invalid memory address will not lead to failure with errno being EFAULT, |
| 59 |
as it would with a real ioctl, but will cause libv4l2 to break, and you |
| 60 |
get to keep both pieces. |
| 61 |
*/ |
| 62 |
|
| 63 |
LIBV4L_PUBLIC int v4l2_open(const char *file, int oflag, ...); |
| 64 |
LIBV4L_PUBLIC int v4l2_close(int fd); |
| 65 |
LIBV4L_PUBLIC int v4l2_dup(int fd); |
| 66 |
#ifdef LIBV4L_HAVE_POSIX_IOCTL |
| 67 |
LIBV4L_PUBLIC int v4l2_ioctl(int fd, int request, ...); |
| 68 |
#else |
| 69 |
LIBV4L_PUBLIC int v4l2_ioctl(int fd, unsigned long int request, ...); |
| 70 |
#endif |
| 71 |
LIBV4L_PUBLIC ssize_t v4l2_read(int fd, void *buffer, size_t n); |
| 72 |
LIBV4L_PUBLIC ssize_t v4l2_write(int fd, const void *buffer, size_t n); |
| 73 |
LIBV4L_PUBLIC void *v4l2_mmap(void *start, size_t length, int prot, int flags, |
| 74 |
int fd, int64_t offset); |
| 75 |
LIBV4L_PUBLIC int v4l2_munmap(void *_start, size_t length); |
| 76 |
|
| 77 |
|
| 78 |
/* Misc utility functions */ |
| 79 |
|
| 80 |
/* This function takes a value of 0 - 65535, and then scales that range to |
| 81 |
the actual range of the given v4l control id, and then if the cid exists |
| 82 |
and is not locked sets the cid to the scaled value. |
| 83 |
|
| 84 |
Normally returns 0, even if the cid did not exist or was locked, returns |
| 85 |
non 0 when an other error occurred. */ |
| 86 |
LIBV4L_PUBLIC int v4l2_set_control(int fd, int cid, int value); |
| 87 |
|
| 88 |
/* This function returns a value of 0 - 65535, scaled to from the actual range |
| 89 |
of the given v4l control id. When the cid does not exist, or could not be |
| 90 |
accessed -1 is returned. */ |
| 91 |
LIBV4L_PUBLIC int v4l2_get_control(int fd, int cid); |
| 92 |
|
| 93 |
|
| 94 |
/* "low level" access functions, these functions allow somewhat lower level |
| 95 |
access to libv4l2 (currently there only is v4l2_fd_open here) */ |
| 96 |
|
| 97 |
/* Flags for v4l2_fd_open's v4l2_flags argument */ |
| 98 |
|
| 99 |
/* Disable all format conversion done by libv4l2, this includes the software |
| 100 |
whitebalance, gamma correction, flipping, etc. libv4lconvert does. Use this |
| 101 |
if you want raw frame data, but still want the additional error checks and |
| 102 |
the read() emulation libv4l2 offers. */ |
| 103 |
#define V4L2_DISABLE_CONVERSION 0x01 |
| 104 |
/* This flag is *OBSOLETE*, since version 0.5.98 libv4l *always* reports |
| 105 |
emulated formats to ENUM_FMT, except when conversion is disabled. */ |
| 106 |
#define V4L2_ENABLE_ENUM_FMT_EMULATION 0x02 |
| 107 |
|
| 108 |
/* v4l2_fd_open: open an already opened fd for further use through |
| 109 |
v4l2lib and possibly modify libv4l2's default behavior through the |
| 110 |
v4l2_flags argument. |
| 111 |
|
| 112 |
Returns fd on success, -1 if the fd is not suitable for use through libv4l2 |
| 113 |
(note the fd is left open in this case). */ |
| 114 |
LIBV4L_PUBLIC int v4l2_fd_open(int fd, int v4l2_flags); |
| 115 |
|
| 116 |
#ifdef __cplusplus |
| 117 |
} |
| 118 |
#endif /* __cplusplus */ |
| 119 |
|
| 120 |
#endif |