summaryrefslogtreecommitdiff
path: root/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h
diff options
context:
space:
mode:
authorThierry MERLE <thierry.merle@free.fr>2008-07-01 21:11:29 +0200
committerThierry MERLE <thierry.merle@free.fr>2008-07-01 21:11:29 +0200
commit0d3f75db47da8e0a51eab041eb401bfb6f309174 (patch)
tree26c040de64f866bf61c13e6a4cd53f65a2147051 /v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h
parent096cff3723440c08b1e706007cfdfda445409476 (diff)
downloadmediapointer-dvb-s2-0d3f75db47da8e0a51eab041eb401bfb6f309174.tar.gz
mediapointer-dvb-s2-0d3f75db47da8e0a51eab041eb401bfb6f309174.tar.bz2
v4l2-library: libv4l2 and v4l2convert
From: Hans de Goede <j.w.r.degoede at hhs.nl> libv4l2 offers v4l2_ prefixed versions of open/close/etc. The API is 100% the same as directly opening /dev/videoX using regular open/close/etc, the big difference is that format conversion is done if necessary when capturing. That is if you (try to) set a capture format which is not supported by the cam, but is supported by libv4lconvert, then the try_fmt / set_fmt will succeed as if the cam supports the format and on dqbuf / read the data will be converted for you and returned in the request format. v4l2convert: open/close/ioctl/mmap/munmap library call wrapper doing format conversion for v4l2 applications which want to be able to simply capture bgr24 / yuv420 from v4l2 devices with more exotic frame formats. Signed-off-by: Hans de Goede <j.w.r.degoede at hhs.nl> Signed-off-by: Thierry MERLE <thierry.merle@free.fr>
Diffstat (limited to 'v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h')
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h b/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h
new file mode 100644
index 000000000..bdbd45e5c
--- /dev/null
+++ b/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h
@@ -0,0 +1,94 @@
+/*
+# (C) 2008 Hans de Goede <j.w.r.degoede@hhs.nl>
+
+# 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef __LIBV4L2_PRIV_H
+#define __LIBV4L2_PRIV_H
+
+#include <stdio.h>
+#include <pthread.h>
+#include <libv4lconvert.h> /* includes videodev2.h for us */
+
+#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 32u
+#define V4L2_DEFAULT_NREADBUFFERS 4
+#define V4L2_FRAME_BUF_SIZE (4096 * 4096)
+
+#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_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))
+
+enum v4l2_io { v4l2_io_none, v4l2_io_read, v4l2_io_mmap };
+
+struct v4l2_dev_info {
+ int fd;
+ int flags;
+ int open_count;
+ /* actually 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;
+ enum v4l2_io io;
+ struct v4lconvert_data *convert;
+ unsigned char *convert_mmap_buf;
+ /* 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 */
+ /* mapping tracking of our fake (converting mmap) frame buffers, todo this
+ perfect we should use a map counter per frame, this is a good
+ approximation but there are scenarios thinkable where this doesn't work.
+ However no normal application not even a buggy one is likely to exhibit
+ the patterns needed to fail this somewhat simplified tracking */
+ int frame_mapped; /* 1 status bit per frame */
+ int frame_map_count; /* total number of maps of (fake) buffers combined */
+};
+
+/* From log.c */
+void v4l2_log_ioctl(unsigned long int request, void *arg, int result);
+
+#endif