| 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 GNU |
| 12 |
# 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_PRIV_H |
| 20 |
#define __LIBV4L2_PRIV_H |
| 21 |
|
| 22 |
#include <stdio.h> |
| 23 |
#include <pthread.h> |
| 24 |
#include <libv4lconvert.h> /* includes videodev2.h for us */ |
| 25 |
|
| 26 |
#include "../libv4lconvert/libv4lsyscall-priv.h" |
| 27 |
|
| 28 |
#define V4L2_MAX_DEVICES 16 |
| 29 |
/* Warning when making this larger the frame_queued and frame_mapped members of |
| 30 |
the v4l2_dev_info struct can no longer be a bitfield, so the code needs to |
| 31 |
be adjusted! */ |
| 32 |
#define V4L2_MAX_NO_FRAMES 32 |
| 33 |
#define V4L2_DEFAULT_NREADBUFFERS 4 |
| 34 |
#define V4L2_IGNORE_FIRST_FRAME_ERRORS 3 |
| 35 |
#define V4L2_DEFAULT_FPS 30 |
| 36 |
|
| 37 |
#define V4L2_LOG_ERR(...) \ |
| 38 |
do { \ |
| 39 |
if (v4l2_log_file) { \ |
| 40 |
fprintf(v4l2_log_file, "libv4l2: error " __VA_ARGS__); \ |
| 41 |
fflush(v4l2_log_file); \ |
| 42 |
} else \ |
| 43 |
fprintf(stderr, "libv4l2: error " __VA_ARGS__); \ |
| 44 |
} while (0) |
| 45 |
|
| 46 |
#define V4L2_PERROR(format, ...) \ |
| 47 |
do { \ |
| 48 |
if (errno == ENODEV) { \ |
| 49 |
devices[index].gone = 1;\ |
| 50 |
break; \ |
| 51 |
} \ |
| 52 |
V4L2_LOG_ERR(format ": %s\n", ##__VA_ARGS__, strerror(errno)); \ |
| 53 |
} while (0) |
| 54 |
|
| 55 |
#define V4L2_LOG_WARN(...) \ |
| 56 |
do { \ |
| 57 |
if (v4l2_log_file) { \ |
| 58 |
fprintf(v4l2_log_file, "libv4l2: warning " __VA_ARGS__); \ |
| 59 |
fflush(v4l2_log_file); \ |
| 60 |
} else \ |
| 61 |
fprintf(stderr, "libv4l2: warning " __VA_ARGS__); \ |
| 62 |
} while (0) |
| 63 |
|
| 64 |
#define V4L2_LOG(...) \ |
| 65 |
do { \ |
| 66 |
if (v4l2_log_file) { \ |
| 67 |
fprintf(v4l2_log_file, "libv4l2: " __VA_ARGS__); \ |
| 68 |
fflush(v4l2_log_file); \ |
| 69 |
} \ |
| 70 |
} while (0) |
| 71 |
|
| 72 |
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
| 73 |
|
| 74 |
struct v4l2_dev_info { |
| 75 |
int fd; |
| 76 |
int flags; |
| 77 |
int open_count; |
| 78 |
int gone; /* Set to 1 when a device is detached (ENODEV encountered) */ |
| 79 |
long page_size; |
| 80 |
/* actual format of the cam */ |
| 81 |
struct v4l2_format src_fmt; |
| 82 |
/* fmt as seen by the application (iow after conversion) */ |
| 83 |
struct v4l2_format dest_fmt; |
| 84 |
pthread_mutex_t stream_lock; |
| 85 |
unsigned int no_frames; |
| 86 |
unsigned int nreadbuffers; |
| 87 |
int fps; |
| 88 |
int first_frame; |
| 89 |
struct v4lconvert_data *convert; |
| 90 |
unsigned char *convert_mmap_buf; |
| 91 |
size_t convert_mmap_buf_size; |
| 92 |
size_t convert_mmap_frame_size; |
| 93 |
/* Frame bookkeeping is only done when in read or mmap-conversion mode */ |
| 94 |
unsigned char *frame_pointers[V4L2_MAX_NO_FRAMES]; |
| 95 |
int frame_sizes[V4L2_MAX_NO_FRAMES]; |
| 96 |
int frame_queued; /* 1 status bit per frame */ |
| 97 |
int frame_info_generation; |
| 98 |
/* mapping tracking of our fake (converting mmap) frame buffers */ |
| 99 |
unsigned char frame_map_count[V4L2_MAX_NO_FRAMES]; |
| 100 |
/* buffer when doing conversion and using read() for read() */ |
| 101 |
int readbuf_size; |
| 102 |
unsigned char *readbuf; |
| 103 |
/* plugin info */ |
| 104 |
void *plugin_library; |
| 105 |
void *dev_ops_priv; |
| 106 |
const struct libv4l_dev_ops *dev_ops; |
| 107 |
}; |
| 108 |
|
| 109 |
/* From v4l2-plugin.c */ |
| 110 |
#if defined(HAVE_V4L_PLUGINS) |
| 111 |
void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret, |
| 112 |
const struct libv4l_dev_ops **dev_ops_ret); |
| 113 |
void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv, |
| 114 |
const struct libv4l_dev_ops *dev_ops); |
| 115 |
#else |
| 116 |
static inline void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret, |
| 117 |
const struct libv4l_dev_ops **dev_ops_ret) |
| 118 |
{ |
| 119 |
*dev_ops_ret = v4lconvert_get_default_dev_ops(); |
| 120 |
*plugin_lib_ret = NULL; |
| 121 |
*plugin_priv_ret = NULL; |
| 122 |
} |
| 123 |
static inline void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv, |
| 124 |
const struct libv4l_dev_ops *dev_ops) |
| 125 |
{ |
| 126 |
} |
| 127 |
#endif /* WITH_V4L_PLUGINS */ |
| 128 |
|
| 129 |
/* From log.c */ |
| 130 |
extern const char *v4l2_ioctls[]; |
| 131 |
void v4l2_log_ioctl(unsigned long int request, void *arg, int result); |
| 132 |
|
| 133 |
#endif |