File: libv4l2-priv.h

package info (click to toggle)
v4l-utils 1.32.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,276 kB
  • sloc: ansic: 85,528; cpp: 69,473; perl: 11,915; sh: 1,333; python: 883; php: 119; makefile: 39
file content (133 lines) | stat: -rw-r--r-- 4,208 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
#             (C) 2008 Hans de Goede <hdegoede@redhat.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335  USA
 */

#ifndef __LIBV4L2_PRIV_H
#define __LIBV4L2_PRIV_H

#include <stdio.h>
#include <pthread.h>
#include <libv4lconvert.h> /* includes videodev2.h for us */

#include "../libv4lconvert/libv4lsyscall-priv.h"

#define V4L2_MAX_DEVICES 16
/* Warning when making this larger the frame_queued and frame_mapped members of
   the v4l2_dev_info struct can no longer be a bitfield, so the code needs to
   be adjusted! */
#define V4L2_MAX_NO_FRAMES 32
#define V4L2_DEFAULT_NREADBUFFERS 4
#define V4L2_IGNORE_FIRST_FRAME_ERRORS 3
#define V4L2_DEFAULT_FPS 30

#define V4L2_LOG_ERR(...) 			\
	do { 					\
		if (v4l2_log_file) { 		\
			fprintf(v4l2_log_file, "libv4l2: error " __VA_ARGS__); \
			fflush(v4l2_log_file); 	\
		} else 				\
		fprintf(stderr, "libv4l2: error " __VA_ARGS__); \
	} while (0)

#define V4L2_PERROR(format, ...)		\
	do { 					\
		if (errno == ENODEV) {		\
			devices[index].gone = 1;\
			break;			\
		}				\
		V4L2_LOG_ERR(format ": %s\n", ##__VA_ARGS__, strerror(errno)); \
	} while (0)

#define V4L2_LOG_WARN(...) 			\
	do { 					\
		if (v4l2_log_file) { 		\
			fprintf(v4l2_log_file, "libv4l2: warning " __VA_ARGS__); \
			fflush(v4l2_log_file); 	\
		} else 				\
		fprintf(stderr, "libv4l2: warning " __VA_ARGS__); \
	} while (0)

#define V4L2_LOG(...) 				\
	do { 					\
		if (v4l2_log_file) { 		\
			fprintf(v4l2_log_file, "libv4l2: " __VA_ARGS__); \
			fflush(v4l2_log_file); 	\
		} 				\
	} while (0)

#define MIN(a, b) (((a) < (b)) ? (a) : (b))

struct v4l2_dev_info {
	int fd;
	int flags;
	int open_count;
	int gone; /* Set to 1 when a device is detached (ENODEV encountered) */
	long page_size;
	/* actual format of the cam */
	struct v4l2_format src_fmt;
	/* fmt as seen by the application (iow after conversion) */
	struct v4l2_format dest_fmt;
	pthread_mutex_t stream_lock;
	unsigned int no_frames;
	unsigned int nreadbuffers;
	int fps;
	int first_frame;
	struct v4lconvert_data *convert;
	unsigned char *convert_mmap_buf;
	size_t convert_mmap_buf_size;
	size_t convert_mmap_frame_size;
	/* Frame bookkeeping is only done when in read or mmap-conversion mode */
	unsigned char *frame_pointers[V4L2_MAX_NO_FRAMES];
	int frame_sizes[V4L2_MAX_NO_FRAMES];
	int frame_queued; /* 1 status bit per frame */
	int frame_info_generation;
	/* mapping tracking of our fake (converting mmap) frame buffers */
	unsigned char frame_map_count[V4L2_MAX_NO_FRAMES];
	/* buffer when doing conversion and using read() for read() */
	int readbuf_size;
	unsigned char *readbuf;
	/* plugin info */
	void *plugin_library;
	void *dev_ops_priv;
	const struct libv4l_dev_ops *dev_ops;
};

/* From v4l2-plugin.c */
#if defined(HAVE_V4L_PLUGINS)
void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret,
		      const struct libv4l_dev_ops **dev_ops_ret);
void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv,
			 const struct libv4l_dev_ops *dev_ops);
#else
static inline void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret,
				    const struct libv4l_dev_ops **dev_ops_ret)
{
	*dev_ops_ret = v4lconvert_get_default_dev_ops();
	*plugin_lib_ret = NULL;
	*plugin_priv_ret = NULL;
}
static inline void v4l2_plugin_cleanup(void *plugin_lib, void *plugin_priv,
				       const struct libv4l_dev_ops *dev_ops)
{
}
#endif /* WITH_V4L_PLUGINS */

/* From log.c */
extern const char *v4l2_ioctls[];
void v4l2_log_ioctl(unsigned long int request, void *arg, int result);

#endif