summaryrefslogtreecommitdiff
path: root/v4l2-apps
diff options
context:
space:
mode:
Diffstat (limited to 'v4l2-apps')
-rw-r--r--v4l2-apps/Make.rules2
-rw-r--r--v4l2-apps/lib/libv4l/ChangeLog46
-rw-r--r--v4l2-apps/lib/libv4l/Makefile8
-rw-r--r--v4l2-apps/lib/libv4l/README2
-rw-r--r--v4l2-apps/lib/libv4l/appl-patches/camorama-0.19-fixes.patch90
-rw-r--r--v4l2-apps/lib/libv4l/appl-patches/kdenetwork-4.0.85-kopete.patch12
-rw-r--r--v4l2-apps/lib/libv4l/appl-patches/vlc-0.8.6-libv4l1.patch319
-rw-r--r--v4l2-apps/lib/libv4l/appl-patches/xawtv-3.95-fixes.patch29
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/Makefile49
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/libv4l1-priv.h2
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/libv4l1.c14
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/log.c2
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/v4l1compat.c6
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/Makefile49
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h16
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/libv4l2.c305
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/log.c12
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c10
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/Makefile40
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/bayer.c30
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h26
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c122
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/pac207.c2
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c64
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/sn9c10x.c2
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/spca501.c75
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/spca561-decompress.c2
-rw-r--r--v4l2-apps/test/capture_example.c436
-rw-r--r--v4l2-apps/util/Makefile6
-rw-r--r--v4l2-apps/util/cx18-ctl.c9
-rw-r--r--v4l2-apps/util/em28xx-dbg.h2
-rw-r--r--v4l2-apps/util/ivtv-ctl.c9
-rw-r--r--v4l2-apps/util/qv4l2/general-tab.cpp8
-rw-r--r--v4l2-apps/util/v4l-board-dbg.h2
-rw-r--r--v4l2-apps/util/v4l2-ctl.cpp311
-rw-r--r--v4l2-apps/util/v4l2-dbg.cpp19
-rwxr-xr-xv4l2-apps/util/v4l_rec.pl4
37 files changed, 1061 insertions, 1081 deletions
diff --git a/v4l2-apps/Make.rules b/v4l2-apps/Make.rules
index d1b013317..5e471abcd 100644
--- a/v4l2-apps/Make.rules
+++ b/v4l2-apps/Make.rules
@@ -35,7 +35,7 @@ else
@$(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(filter %.o %.c,$^) $(LOADLIBES) $(LDLIBS) -o $@
%.so:
@echo LD $@
- @$(LD) -shared -o $@ $^
+ @$(CC) -shared -o $@ $^
%.a:
@echo AR $@
@$(AR) rcs $@ $^
diff --git a/v4l2-apps/lib/libv4l/ChangeLog b/v4l2-apps/lib/libv4l/ChangeLog
index 286963543..3d4e40ad2 100644
--- a/v4l2-apps/lib/libv4l/ChangeLog
+++ b/v4l2-apps/lib/libv4l/ChangeLog
@@ -1,3 +1,49 @@
+libv4l-0.4.1
+------------
+* When the driver supports read() and we are not converting let the driver
+ handle read() instead of emulating it with mmap mode
+
+
+libv4l-0.4.0
+------------
+* Be more relaxed in our checks for mixing read and mmap access, we were
+ being more strict in this then certain kernel drivers (bttv) making xawtv
+ unhappy
+* With some drivers the buffers must be mapped before queuing, so when
+ converting map the (real) buffers before calling the qbuf ioctl
+* Add support for conversion to RGB24 (before we only supported BGR24) based
+ on a patch by Jean-Francois Moine
+* When the hardware supports a format natively prefer using the native
+ version over converting from another supported format
+* Various Makefile and pkgconfig file improvements by Gregor Jasny (Debian)
+* Drop the appl-patches dir, all application patches are now available and
+ tracked here: http://linuxtv.org/v4lwiki/index.php/Libv4l_Progress
+
+
+libv4l-0.3.9
+------------
+* Not only see /dev/video* but also /dev/v4l/* as video devices
+ (only affects libv4l1 and the wrappers) patch from Brandon Philips
+* Silence the creation of the .pc files in the Makefiles (Brandon Philips)
+* Part of the copyright headers refered GPL instead of LGPL due to a copy
+ and paste error (Brandon Philips)
+
+
+libv4l-0.3.8
+------------
+* work around wrong REQUEST_BUFFERS ioctl return code from certain drivers
+* add pkg-config (.pc) files for easier detection if libv4l is available
+* check capabilities for streaming, if the driver cannot do streaming don't
+ insert ourselves between the application and the driver
+* intercept get capabilites and report read capability (which we always offer)
+* query buffer: indicate the mapping state of our (fake) buffer in the flags
+
+
+libv4l-0.3.7
+------------
+* Add spca505/6 and spca508 cam specific formats (YUYV per line variations)
+
+
libv4l-0.3.6
------------
* Add missing COPYING.LIB file
diff --git a/v4l2-apps/lib/libv4l/Makefile b/v4l2-apps/lib/libv4l/Makefile
index 0f4428eba..31254a09e 100644
--- a/v4l2-apps/lib/libv4l/Makefile
+++ b/v4l2-apps/lib/libv4l/Makefile
@@ -1,10 +1,10 @@
LIB_RELEASE=0
-V4L2_LIB_VERSION=$(LIB_RELEASE).3.6
+V4L2_LIB_VERSION=$(LIB_RELEASE).4.1
all clean install:
- $(MAKE) -C libv4lconvert $@
- $(MAKE) -C libv4l2 $@
- $(MAKE) -C libv4l1 $@
+ $(MAKE) -C libv4lconvert V4L2_LIB_VERSION=$(V4L2_LIB_VERSION) $@
+ $(MAKE) -C libv4l2 V4L2_LIB_VERSION=$(V4L2_LIB_VERSION) $@
+ $(MAKE) -C libv4l1 V4L2_LIB_VERSION=$(V4L2_LIB_VERSION) $@
export: clean
mkdir /tmp/libv4l-$(V4L2_LIB_VERSION)
diff --git a/v4l2-apps/lib/libv4l/README b/v4l2-apps/lib/libv4l/README
index b9b056f66..3a2059224 100644
--- a/v4l2-apps/lib/libv4l/README
+++ b/v4l2-apps/lib/libv4l/README
@@ -6,7 +6,7 @@ top of video4linux2 devices. The purpose of this (thin) layer is to make it
easy for application writers to support a wide variety of devices without
having to write seperate code for different devices in the same class.
-All libv4l components are licensed under the GNU Library General Publishing
+All libv4l components are licensed under the GNU Lesser General Public
License version 2 or (at your option) any later version.
libv4l consists of 3 different libraries:
diff --git a/v4l2-apps/lib/libv4l/appl-patches/camorama-0.19-fixes.patch b/v4l2-apps/lib/libv4l/appl-patches/camorama-0.19-fixes.patch
deleted file mode 100644
index 1e1333575..000000000
--- a/v4l2-apps/lib/libv4l/appl-patches/camorama-0.19-fixes.patch
+++ /dev/null
@@ -1,90 +0,0 @@
---- camorama-0.19/src/callbacks.c 2007-09-16 15:36:55.000000000 +0200
-+++ camorama-0.19.new/src/callbacks.c 2008-06-29 22:22:44.000000000 +0200
-@@ -387,9 +387,6 @@
- }
- }
-
-- cam->pixmap = gdk_pixmap_new (NULL, cam->x, cam->y, cam->desk_depth);
-- gtk_widget_set_size_request (glade_xml_get_widget (cam->xml, "da"),
-- cam->x, cam->y);
-
- /*
- * if(cam->read == FALSE) {
-@@ -441,6 +438,11 @@
- * * }
- */
- get_win_info (cam);
-+
-+ cam->pixmap = gdk_pixmap_new (NULL, cam->x, cam->y, cam->desk_depth);
-+ gtk_widget_set_size_request (glade_xml_get_widget (cam->xml, "da"),
-+ cam->x, cam->y);
-+
- frame = 0;
- gtk_window_resize (GTK_WINDOW
- (glade_xml_get_widget (cam->xml, "main_window")), 320,
-@@ -520,8 +522,14 @@
- gtk_widget_show (about);
- }
-
-+void
-+camorama_filter_color_filter(void* filter, guchar *image, int x, int y, int depth);
-+
- static void
- apply_filters(cam* cam) {
-+ /* v4l has reverse rgb order from what camora expect so call the color
-+ filter to fix things up before running the user selected filters */
-+ camorama_filter_color_filter(NULL, cam->pic_buf, cam->x, cam->y, cam->depth);
- camorama_filter_chain_apply(cam->filter_chain, cam->pic_buf, cam->x, cam->y, cam->depth);
- #warning "FIXME: enable the threshold channel filter"
- // if((effect_mask & CAMORAMA_FILTER_THRESHOLD_CHANNEL) != 0)
---- camorama-0.19/src/filter.c 2007-09-16 14:48:50.000000000 +0200
-+++ camorama-0.19.new/src/filter.c 2008-06-29 22:11:42.000000000 +0200
-@@ -151,12 +151,12 @@
- static void
- camorama_filter_color_init(CamoramaFilterColor* self) {}
-
--static void
-+void
- camorama_filter_color_filter(CamoramaFilterColor* filter, guchar *image, int x, int y, int depth) {
- int i;
- char tmp;
- i = x * y;
-- while (--i) {
-+ while (i--) {
- tmp = image[0];
- image[0] = image[2];
- image[2] = tmp;
---- camorama-0.19/src/main.c 2007-09-16 15:36:55.000000000 +0200
-+++ camorama-0.19.new/src/main.c 2008-06-29 22:20:04.000000000 +0200
-@@ -224,8 +224,7 @@
-
- /* get picture attributes */
- get_pic_info (cam);
--// set_pic_info(cam);
-- /* set_pic_info(cam); */
-+ set_pic_info (cam);
- cam->contrast = cam->vid_pic.contrast;
- cam->brightness = cam->vid_pic.brightness;
- cam->colour = cam->vid_pic.colour;
---- camorama-0.19/src/v4l.c 2007-09-16 14:48:05.000000000 +0200
-+++ camorama-0.19.new/src/v4l.c 2008-06-29 22:20:23.000000000 +0200
-@@ -158,8 +158,8 @@
- if(cam->debug) {
- g_message("SET PIC");
- }
-- //cam->vid_pic.palette = VIDEO_PALETTE_RGB24;
-- //cam->vid_pic.depth = 24;
-+ cam->vid_pic.palette = VIDEO_PALETTE_RGB24;
-+ cam->vid_pic.depth = 24;
- //cam->vid_pic.palette = VIDEO_PALETTE_YUV420P;
- if(ioctl(cam->dev, VIDIOCSPICT, &cam->vid_pic) == -1) {
- if(cam->debug) {
-@@ -232,6 +232,8 @@
- exit(0);
- }
-
-+ cam->x = cam->vid_win.width;
-+ cam->y = cam->vid_win.height;
- }
-
- void set_buffer(cam * cam)
diff --git a/v4l2-apps/lib/libv4l/appl-patches/kdenetwork-4.0.85-kopete.patch b/v4l2-apps/lib/libv4l/appl-patches/kdenetwork-4.0.85-kopete.patch
deleted file mode 100644
index b187f05e4..000000000
--- a/v4l2-apps/lib/libv4l/appl-patches/kdenetwork-4.0.85-kopete.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff -up kdenetwork-4.0.85/kopete/libkopete/avdevice/videodevice.cpp~ kdenetwork-4.0.85/kopete/libkopete/avdevice/videodevice.cpp
---- kdenetwork-4.0.85/kopete/libkopete/avdevice/videodevice.cpp~ 2008-07-07 22:40:56.000000000 +0200
-+++ kdenetwork-4.0.85/kopete/libkopete/avdevice/videodevice.cpp 2008-07-07 22:40:56.000000000 +0200
-@@ -679,6 +679,8 @@ kDebug() << "VIDIOC_S_FMT worked (" << e
- if (fmt.fmt.pix.sizeimage < min)
- fmt.fmt.pix.sizeimage = min;
- m_buffer_size=fmt.fmt.pix.sizeimage ;
-+ currentwidth = fmt.fmt.pix.width;
-+ currentheight = fmt.fmt.pix.height;
- }
- break;
- #endif
diff --git a/v4l2-apps/lib/libv4l/appl-patches/vlc-0.8.6-libv4l1.patch b/v4l2-apps/lib/libv4l/appl-patches/vlc-0.8.6-libv4l1.patch
deleted file mode 100644
index 132549b55..000000000
--- a/v4l2-apps/lib/libv4l/appl-patches/vlc-0.8.6-libv4l1.patch
+++ /dev/null
@@ -1,319 +0,0 @@
-diff -up vlc-0.8.6f/modules/access/v4l/Makefile.am~ vlc-0.8.6f/modules/access/v4l/Makefile.am
---- vlc-0.8.6f/modules/access/v4l/Makefile.am~ 2008-06-29 17:14:11.000000000 +0200
-+++ vlc-0.8.6f/modules/access/v4l/Makefile.am 2008-06-29 17:16:39.000000000 +0200
-@@ -100,7 +100,7 @@ libv4l_plugin_la_CXXFLAGS = `$(VLC_CONFI
- libv4l_plugin_la_OBJCFLAGS = `$(VLC_CONFIG) --objcflags plugin v4l`
- libv4l_plugin_la_LDFLAGS = `$(VLC_CONFIG) --libs plugin v4l` \
- -rpath '$(libvlcdir)' -avoid-version -module -shrext $(LIBEXT)
--libv4l_plugin_la_LIBADD = $(LTLIBVLC)
-+libv4l_plugin_la_LIBADD = $(LTLIBVLC) -lv4l1
-
- libv4l_a_SOURCES = $(SOURCES_v4l)
- libv4l_builtin_la_SOURCES = $(SOURCES_v4l)
-diff -up vlc-0.8.6f/modules/access/v4l/Makefile.in~ vlc-0.8.6f/modules/access/v4l/Makefile.in
---- vlc-0.8.6f/modules/access/v4l/Makefile.in~ 2008-06-29 17:16:22.000000000 +0200
-+++ vlc-0.8.6f/modules/access/v4l/Makefile.in 2008-06-29 17:16:42.000000000 +0200
-@@ -390,7 +390,7 @@ libv4l_plugin_la_OBJCFLAGS = `$(VLC_CONF
- libv4l_plugin_la_LDFLAGS = `$(VLC_CONFIG) --libs plugin v4l` \
- -rpath '$(libvlcdir)' -avoid-version -module -shrext $(LIBEXT)
-
--libv4l_plugin_la_LIBADD = $(LTLIBVLC)
-+libv4l_plugin_la_LIBADD = $(LTLIBVLC) -lv4l1
- libv4l_a_SOURCES = $(SOURCES_v4l)
- libv4l_builtin_la_SOURCES = $(SOURCES_v4l)
- libv4l_a_CFLAGS = `$(VLC_CONFIG) --cflags builtin pic v4l`
-diff -up vlc-0.8.6f/modules/access/v4l/v4l.c~ vlc-0.8.6f/modules/access/v4l/v4l.c
---- vlc-0.8.6f/modules/access/v4l/v4l.c~ 2008-06-29 17:13:30.000000000 +0200
-+++ vlc-0.8.6f/modules/access/v4l/v4l.c 2008-06-29 17:13:30.000000000 +0200
-@@ -64,6 +64,9 @@
-
- #include <sys/soundcard.h>
-
-+#include <libv4l1.h>
-+
-+
- /*****************************************************************************
- * Module descriptior
- *****************************************************************************/
-@@ -546,23 +549,23 @@ static void Close( vlc_object_t *p_this
- if( p_sys->psz_device ) free( p_sys->psz_device );
- if( p_sys->psz_vdev ) free( p_sys->psz_vdev );
- if( p_sys->psz_adev ) free( p_sys->psz_adev );
-- if( p_sys->fd_video >= 0 ) close( p_sys->fd_video );
-+ if( p_sys->fd_video >= 0 ) v4l1_close( p_sys->fd_video );
- if( p_sys->fd_audio >= 0 ) close( p_sys->fd_audio );
- if( p_sys->p_block_audio ) block_Release( p_sys->p_block_audio );
-
- if( p_sys->b_mjpeg )
- {
- int i_noframe = -1;
-- ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT, &i_noframe );
-+ v4l1_ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT, &i_noframe );
- }
-
- if( p_sys->p_video_mmap && p_sys->p_video_mmap != MAP_FAILED )
- {
- if( p_sys->b_mjpeg )
-- munmap( p_sys->p_video_mmap, p_sys->mjpeg_buffers.size *
-+ v4l1_munmap( p_sys->p_video_mmap, p_sys->mjpeg_buffers.size *
- p_sys->mjpeg_buffers.count );
- else
-- munmap( p_sys->p_video_mmap, p_sys->vid_mbuf.size );
-+ v4l1_munmap( p_sys->p_video_mmap, p_sys->vid_mbuf.size );
- }
-
- free( p_sys );
-@@ -875,13 +878,13 @@ static int OpenVideoDev( demux_t *p_demu
- struct mjpeg_params mjpeg;
- int i;
-
-- if( ( i_fd = open( psz_device, O_RDWR ) ) < 0 )
-+ if( ( i_fd = v4l1_open( psz_device, O_RDWR ) ) < 0 )
- {
- msg_Err( p_demux, "cannot open device (%s)", strerror( errno ) );
- goto vdev_failed;
- }
-
-- if( ioctl( i_fd, VIDIOCGCAP, &p_sys->vid_cap ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCGCAP, &p_sys->vid_cap ) < 0 )
- {
- msg_Err( p_demux, "cannot get capabilities (%s)", strerror( errno ) );
- goto vdev_failed;
-@@ -926,7 +929,7 @@ static int OpenVideoDev( demux_t *p_demu
- }
-
- vid_channel.channel = p_sys->i_channel;
-- if( ioctl( i_fd, VIDIOCGCHAN, &vid_channel ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCGCHAN, &vid_channel ) < 0 )
- {
- msg_Err( p_demux, "cannot get channel infos (%s)",
- strerror( errno ) );
-@@ -944,7 +947,7 @@ static int OpenVideoDev( demux_t *p_demu
- }
-
- vid_channel.norm = p_sys->i_norm;
-- if( ioctl( i_fd, VIDIOCSCHAN, &vid_channel ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCSCHAN, &vid_channel ) < 0 )
- {
- msg_Err( p_demux, "cannot set channel (%s)", strerror( errno ) );
- goto vdev_failed;
-@@ -959,7 +962,7 @@ static int OpenVideoDev( demux_t *p_demu
- if( p_sys->i_tuner >= 0 )
- {
- vid_tuner.tuner = p_sys->i_tuner;
-- if( ioctl( i_fd, VIDIOCGTUNER, &vid_tuner ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCGTUNER, &vid_tuner ) < 0 )
- {
- msg_Err( p_demux, "cannot get tuner (%s)", strerror( errno ) );
- goto vdev_failed;
-@@ -974,7 +977,7 @@ static int OpenVideoDev( demux_t *p_demu
-
- /* FIXME FIXME to be checked FIXME FIXME */
- //vid_tuner.mode = p_sys->i_norm;
-- if( ioctl( i_fd, VIDIOCSTUNER, &vid_tuner ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCSTUNER, &vid_tuner ) < 0 )
- {
- msg_Err( p_demux, "cannot set tuner (%s)", strerror( errno ) );
- goto vdev_failed;
-@@ -990,7 +993,7 @@ static int OpenVideoDev( demux_t *p_demu
- if( p_sys->i_frequency >= 0 )
- {
- int driver_frequency = p_sys->i_frequency * 16 /1000;
-- if( ioctl( i_fd, VIDIOCSFREQ, &driver_frequency ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCSFREQ, &driver_frequency ) < 0 )
- {
- msg_Err( p_demux, "cannot set frequency (%s)",
- strerror( errno ) );
-@@ -1010,7 +1013,7 @@ static int OpenVideoDev( demux_t *p_demu
- if( p_sys->i_audio >= 0 )
- {
- vid_audio.audio = p_sys->i_audio;
-- if( ioctl( i_fd, VIDIOCGAUDIO, &vid_audio ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCGAUDIO, &vid_audio ) < 0 )
- {
- msg_Err( p_demux, "cannot get audio (%s)", strerror( errno ) );
- goto vdev_failed;
-@@ -1019,7 +1022,7 @@ static int OpenVideoDev( demux_t *p_demu
- /* unmute audio */
- vid_audio.flags &= ~VIDEO_AUDIO_MUTE;
-
-- if( ioctl( i_fd, VIDIOCSAUDIO, &vid_audio ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCSAUDIO, &vid_audio ) < 0 )
- {
- msg_Err( p_demux, "cannot set audio (%s)", strerror( errno ) );
- goto vdev_failed;
-@@ -1035,7 +1038,7 @@ static int OpenVideoDev( demux_t *p_demu
- struct quicktime_mjpeg_app1 *p_app1;
- int32_t i_offset;
-
-- if( ioctl( i_fd, MJPIOC_G_PARAMS, &mjpeg ) < 0 )
-+ if( v4l1_ioctl( i_fd, MJPIOC_G_PARAMS, &mjpeg ) < 0 )
- {
- msg_Err( p_demux, "cannot get mjpeg params (%s)",
- strerror( errno ) );
-@@ -1086,7 +1089,7 @@ static int OpenVideoDev( demux_t *p_demu
- * optional. They will be present in the output. */
- mjpeg.jpeg_markers = JPEG_MARKER_DHT | JPEG_MARKER_DQT;
-
-- if( ioctl( i_fd, MJPIOC_S_PARAMS, &mjpeg ) < 0 )
-+ if( v4l1_ioctl( i_fd, MJPIOC_S_PARAMS, &mjpeg ) < 0 )
- {
- msg_Err( p_demux, "cannot set mjpeg params (%s)",
- strerror( errno ) );
-@@ -1103,7 +1106,7 @@ static int OpenVideoDev( demux_t *p_demu
- {
- struct video_window vid_win;
-
-- if( ioctl( i_fd, VIDIOCGWIN, &vid_win ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCGWIN, &vid_win ) < 0 )
- {
- msg_Err( p_demux, "cannot get win (%s)", strerror( errno ) );
- goto vdev_failed;
-@@ -1130,7 +1133,7 @@ static int OpenVideoDev( demux_t *p_demu
- if( !p_sys->b_mjpeg )
- {
- /* set hue/color/.. */
-- if( ioctl( i_fd, VIDIOCGPICT, &p_sys->vid_picture ) == 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCGPICT, &p_sys->vid_picture ) == 0 )
- {
- struct video_picture vid_picture = p_sys->vid_picture;
-
-@@ -1150,7 +1153,7 @@ static int OpenVideoDev( demux_t *p_demu
- {
- vid_picture.contrast = p_sys->i_contrast;
- }
-- if( ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
- {
- msg_Dbg( p_demux, "v4l device uses brightness: %d",
- vid_picture.brightness );
-@@ -1164,7 +1167,7 @@ static int OpenVideoDev( demux_t *p_demu
- }
-
- /* Find out video format used by device */
-- if( ioctl( i_fd, VIDIOCGPICT, &p_sys->vid_picture ) == 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCGPICT, &p_sys->vid_picture ) == 0 )
- {
- struct video_picture vid_picture = p_sys->vid_picture;
- char *psz;
-@@ -1191,7 +1194,7 @@ static int OpenVideoDev( demux_t *p_demu
- free( psz );
-
- if( vid_picture.palette &&
-- !ioctl( i_fd, VIDIOCSPICT, &vid_picture ) )
-+ !v4l1_ioctl( i_fd, VIDIOCSPICT, &vid_picture ) )
- {
- p_sys->vid_picture = vid_picture;
- }
-@@ -1199,14 +1202,14 @@ static int OpenVideoDev( demux_t *p_demu
- {
- /* Try to set the format to something easy to encode */
- vid_picture.palette = VIDEO_PALETTE_YUV420P;
-- if( ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
- {
- p_sys->vid_picture = vid_picture;
- }
- else
- {
- vid_picture.palette = VIDEO_PALETTE_YUV422P;
-- if( ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
- {
- p_sys->vid_picture = vid_picture;
- }
-@@ -1237,13 +1240,13 @@ static int OpenVideoDev( demux_t *p_demu
- p_sys->mjpeg_buffers.count = 8;
- p_sys->mjpeg_buffers.size = MJPEG_BUFFER_SIZE;
-
-- if( ioctl( i_fd, MJPIOC_REQBUFS, &p_sys->mjpeg_buffers ) < 0 )
-+ if( v4l1_ioctl( i_fd, MJPIOC_REQBUFS, &p_sys->mjpeg_buffers ) < 0 )
- {
- msg_Err( p_demux, "mmap unsupported" );
- goto vdev_failed;
- }
-
-- p_sys->p_video_mmap = mmap( 0,
-+ p_sys->p_video_mmap = v4l1_mmap( 0,
- p_sys->mjpeg_buffers.size * p_sys->mjpeg_buffers.count,
- PROT_READ | PROT_WRITE, MAP_SHARED, i_fd, 0 );
- if( p_sys->p_video_mmap == MAP_FAILED )
-@@ -1258,7 +1261,7 @@ static int OpenVideoDev( demux_t *p_demu
- /* queue up all the frames */
- for( i = 0; i < (int)p_sys->mjpeg_buffers.count; i++ )
- {
-- if( ioctl( i_fd, MJPIOC_QBUF_CAPT, &i ) < 0 )
-+ if( v4l1_ioctl( i_fd, MJPIOC_QBUF_CAPT, &i ) < 0 )
- {
- msg_Err( p_demux, "unable to queue frame" );
- goto vdev_failed;
-@@ -1289,13 +1292,13 @@ static int OpenVideoDev( demux_t *p_demu
- (char*)&p_sys->i_fourcc );
-
- /* Allocate mmap buffer */
-- if( ioctl( i_fd, VIDIOCGMBUF, &p_sys->vid_mbuf ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCGMBUF, &p_sys->vid_mbuf ) < 0 )
- {
- msg_Err( p_demux, "mmap unsupported" );
- goto vdev_failed;
- }
-
-- p_sys->p_video_mmap = mmap( 0, p_sys->vid_mbuf.size,
-+ p_sys->p_video_mmap = v4l1_mmap( 0, p_sys->vid_mbuf.size,
- PROT_READ|PROT_WRITE, MAP_SHARED,
- i_fd, 0 );
- if( p_sys->p_video_mmap == MAP_FAILED )
-@@ -1310,7 +1313,7 @@ static int OpenVideoDev( demux_t *p_demu
- p_sys->vid_mmap.width = p_sys->i_width;
- p_sys->vid_mmap.height = p_sys->i_height;
- p_sys->vid_mmap.format = p_sys->vid_picture.palette;
-- if( ioctl( i_fd, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
-+ if( v4l1_ioctl( i_fd, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
- {
- msg_Warn( p_demux, "%4.4s refused", (char*)&p_sys->i_fourcc );
- msg_Err( p_demux, "chroma selection failed" );
-@@ -1321,7 +1324,7 @@ static int OpenVideoDev( demux_t *p_demu
-
- vdev_failed:
-
-- if( i_fd >= 0 ) close( i_fd );
-+ if( i_fd >= 0 ) v4l1_close( i_fd );
- return -1;
- }
-
-@@ -1431,7 +1434,7 @@ static uint8_t *GrabCapture( demux_t *p_
-
- p_sys->vid_mmap.frame = (p_sys->i_frame_pos + 1) % p_sys->vid_mbuf.frames;
-
-- while( ioctl( p_sys->fd_video, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
-+ while( v4l1_ioctl( p_sys->fd_video, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
- {
- if( errno != EAGAIN )
- {
-@@ -1447,7 +1450,7 @@ static uint8_t *GrabCapture( demux_t *p_
- msg_Dbg( p_demux, "grab failed, trying again" );
- }
-
-- while( ioctl(p_sys->fd_video, VIDIOCSYNC, &p_sys->i_frame_pos) < 0 )
-+ while( v4l1_ioctl(p_sys->fd_video, VIDIOCSYNC, &p_sys->i_frame_pos) < 0 )
- {
- if( errno != EAGAIN && errno != EINTR )
- {
-@@ -1473,7 +1476,7 @@ static uint8_t *GrabMJPEG( demux_t *p_de
- /* re-queue the last frame we sync'd */
- if( p_sys->i_frame_pos != -1 )
- {
-- while( ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT,
-+ while( v4l1_ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT,
- &p_sys->i_frame_pos ) < 0 )
- {
- if( errno != EAGAIN && errno != EINTR )
-@@ -1485,7 +1488,7 @@ static uint8_t *GrabMJPEG( demux_t *p_de
- }
-
- /* sync on the next frame */
-- while( ioctl( p_sys->fd_video, MJPIOC_SYNC, &sync ) < 0 )
-+ while( v4l1_ioctl( p_sys->fd_video, MJPIOC_SYNC, &sync ) < 0 )
- {
- if( errno != EAGAIN && errno != EINTR )
- {
diff --git a/v4l2-apps/lib/libv4l/appl-patches/xawtv-3.95-fixes.patch b/v4l2-apps/lib/libv4l/appl-patches/xawtv-3.95-fixes.patch
deleted file mode 100644
index ccb077be0..000000000
--- a/v4l2-apps/lib/libv4l/appl-patches/xawtv-3.95-fixes.patch
+++ /dev/null
@@ -1,29 +0,0 @@
---- xawtv-3.95/libng/plugins/drv0-v4l2.c 2005-02-11 18:56:24.000000000 +0100
-+++ xawtv-3.95.new/libng/plugins/drv0-v4l2.c 2008-07-05 21:12:37.000000000 +0200
-@@ -161,7 +161,7 @@
- #define PREFIX "ioctl: "
-
- static int
--xioctl(int fd, int cmd, void *arg, int mayfail)
-+xioctl(int fd, unsigned long int cmd, void *arg, int mayfail)
- {
- int rc;
-
-@@ -768,6 +768,7 @@
- /* get it */
- memset(&buf,0,sizeof(buf));
- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-+ buf.memory = V4L2_MEMORY_MMAP;
- if (-1 == xioctl(h->fd,VIDIOC_DQBUF,&buf, 0))
- return -1;
- h->waiton++;
-@@ -813,8 +814,7 @@
- if (-1 == xioctl(h->fd, VIDIOC_QUERYBUF, &h->buf_v4l2[i], 0))
- return -1;
- h->buf_me[i].fmt = h->fmt_me;
-- h->buf_me[i].size = h->buf_me[i].fmt.bytesperline *
-- h->buf_me[i].fmt.height;
-+ h->buf_me[i].size = h->buf_v4l2[i].length;
- h->buf_me[i].data = mmap(NULL, h->buf_v4l2[i].length,
- PROT_READ | PROT_WRITE, MAP_SHARED,
- h->fd, h->buf_v4l2[i].m.offset);
diff --git a/v4l2-apps/lib/libv4l/libv4l1/Makefile b/v4l2-apps/lib/libv4l/libv4l1/Makefile
index 8cb064cd4..c92731daa 100644
--- a/v4l2-apps/lib/libv4l/libv4l1/Makefile
+++ b/v4l2-apps/lib/libv4l/libv4l1/Makefile
@@ -1,20 +1,25 @@
-CC = gcc
-LD = gcc
-
-CPPFLAGS = -fPIC -I../include -I../../../../linux/include
+CPPFLAGS = -I../include -I../../../../linux/include
CFLAGS := -g -O1
CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes
-LDFLAGS = -shared
+LIBS = -lpthread
-V4L1_OBJS = libv4l1.o log.o ../libv4l2/libv4l2.so
-V4L1_LIB = libv4l1.so
+V4L1_OBJS = libv4l1.o log.o
V4L1COMPAT = v4l1compat.so
V4L1COMPAT_O = v4l1compat.o libv4l1.so
-TARGETS = $(V4L1_LIB) $(V4L1COMPAT)
+TARGETS = $(V4L1_LIB) libv4l1.pc
INCLUDES = ../include/libv4l1.h
+ifeq ($(LINKTYPE),static)
+V4L1_LIB = libv4l1.a
+else
+V4L1_LIB = libv4l1.so
+V4L1_OBJS += ../libv4l2/libv4l2.so
+TARGETS += $(V4L1COMPAT)
+CPPFLAGS += -fPIC
+endif
+
ifeq ($(LIB_RELEASE),)
LIB_RELEASE = 0
endif
@@ -34,23 +39,45 @@ $(V4L1_LIB): $(V4L1_OBJS)
$(V4L1COMPAT): $(V4L1COMPAT_O) $(V4L1_LIB)
+libv4l1.pc:
+ @echo prefix=$(PREFIX) > libv4l1.pc
+ @echo libdir=$(LIBDIR) >> libv4l1.pc
+ @echo >> libv4l1.pc
+ @echo 'Name: libv4l1' >> libv4l1.pc
+ @echo 'Description: v4l1 compatibility library' >> libv4l1.pc
+ @echo 'Version: '$(V4L2_LIB_VERSION) >> libv4l1.pc
+ @echo 'Requires: libv4l2' >> libv4l1.pc
+ @echo 'Libs: -L$${libdir} -lv4l1' >> libv4l1.pc
+ @echo 'Libs.private: -lpthread' >> libv4l1.pc
+ @echo 'Cflags: -I$${prefix}/include' >> libv4l1.pc
+
install: all
mkdir -p $(DESTDIR)$(PREFIX)/include
install -p -m 644 $(INCLUDES) $(DESTDIR)$(PREFIX)/include
+ifeq ($(LINKTYPE),static)
+ mkdir -p $(DESTDIR)$(LIBDIR)
+ install -m 644 $(V4L1_LIB) $(DESTDIR)$(LIBDIR)
+else
mkdir -p $(DESTDIR)$(LIBDIR)/libv4l
install -m 755 $(V4L1_LIB).$(LIB_RELEASE) $(DESTDIR)$(LIBDIR)
cd $(DESTDIR)$(LIBDIR) && \
ln -f -s $(V4L1_LIB).$(LIB_RELEASE) $(V4L1_LIB)
install -m 755 $(V4L1COMPAT).$(LIB_RELEASE) \
$(DESTDIR)$(LIBDIR)/libv4l/$(V4L1COMPAT)
+endif
+ mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig
+ install -m 644 libv4l1.pc $(DESTDIR)$(LIBDIR)/pkgconfig
clean::
- rm -f *.so* *.o log *~
- rm -f *.d
+ rm -f *.a *.so* *.o *.d libv4l1.pc log *~
%.o: %.c
$(CC) -c -MMD $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.so:
- $(CC) $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^
+ $(CC) -shared $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^ $(LIBS)
ln -f -s $@.$(LIB_RELEASE) $@
+
+%.a:
+ $(AR) cqs $@ $^
+
diff --git a/v4l2-apps/lib/libv4l/libv4l1/libv4l1-priv.h b/v4l2-apps/lib/libv4l/libv4l1/libv4l1-priv.h
index e09041256..651599255 100644
--- a/v4l2-apps/lib/libv4l/libv4l1/libv4l1-priv.h
+++ b/v4l2-apps/lib/libv4l/libv4l1/libv4l1-priv.h
@@ -9,7 +9,7 @@
# 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.
+# 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
diff --git a/v4l2-apps/lib/libv4l/libv4l1/libv4l1.c b/v4l2-apps/lib/libv4l/libv4l1/libv4l1.c
index b80fcb56d..80d2fa09b 100644
--- a/v4l2-apps/lib/libv4l/libv4l1/libv4l1.c
+++ b/v4l2-apps/lib/libv4l/libv4l1/libv4l1.c
@@ -28,12 +28,12 @@
capture only devices, or non v4l2 devices.
2) libv4l1 is the base of the v4l1compat.so wrapper lib, which is a .so
which can be LD_PRELOAD-ed and the overrules the libc's open/close/etc,
- and when opening /dev/videoX calls v4l1_open. Because we behave as the
- regular counterpart when the fd is not known (instead of say throwing
- an error), v4l1compat.so can simply call the v4l1_ prefixed function
- for all wrapped functions. This way the wrapper does not have to keep
- track of which fd's are being handled by libv4l1, as libv4l1 already
- keeps track of this itself.
+ and when opening /dev/videoX or /dev/v4l/ calls v4l1_open. Because we
+ behave as the regular counterpart when the fd is not known (instead of
+ say throwing an error), v4l1compat.so can simply call the v4l1_ prefixed
+ function for all wrapped functions. This way the wrapper does not have
+ to keep track of which fd's are being handled by libv4l1, as libv4l1
+ already keeps track of this itself.
This also means that libv4l1 may not use any of the regular functions
it mimics, as for example open could be a symbol in v4l1compat.so, which
@@ -279,7 +279,7 @@ int v4l1_open (const char *file, int oflag, ...)
return fd;
/* check if we're opening a video4linux2 device */
- if (strncmp(file, "/dev/video", 10))
+ if (strncmp(file, "/dev/video", 10) && strncmp(file, "/dev/v4l/", 9))
return fd;
/* check that this is an v4l2 device, no need to emulate v4l1 on
diff --git a/v4l2-apps/lib/libv4l/libv4l1/log.c b/v4l2-apps/lib/libv4l/libv4l1/log.c
index 178c6d23c..cccc3e6d0 100644
--- a/v4l2-apps/lib/libv4l/libv4l1/log.c
+++ b/v4l2-apps/lib/libv4l/libv4l1/log.c
@@ -9,7 +9,7 @@
# 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.
+# 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
diff --git a/v4l2-apps/lib/libv4l/libv4l1/v4l1compat.c b/v4l2-apps/lib/libv4l/libv4l1/v4l1compat.c
index db3a0027b..f1134fe3b 100644
--- a/v4l2-apps/lib/libv4l/libv4l1/v4l1compat.c
+++ b/v4l2-apps/lib/libv4l/libv4l1/v4l1compat.c
@@ -12,7 +12,7 @@
# 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.
+# 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
@@ -99,13 +99,13 @@ ssize_t read(int fd, void* buffer, size_t n)
return v4l1_read (fd, buffer, n);
}
-void mmap(void *start, size_t length, int prot, int flags, int fd,
+void *mmap(void *start, size_t length, int prot, int flags, int fd,
__off_t offset)
{
return v4l1_mmap(start, length, prot, flags, fd, offset);
}
-void mmap64(void *start, size_t length, int prot, int flags, int fd,
+void *mmap64(void *start, size_t length, int prot, int flags, int fd,
__off64_t offset)
{
return v4l1_mmap(start, length, prot, flags, fd, offset);
diff --git a/v4l2-apps/lib/libv4l/libv4l2/Makefile b/v4l2-apps/lib/libv4l/libv4l2/Makefile
index 1258e379b..d8ac01c34 100644
--- a/v4l2-apps/lib/libv4l/libv4l2/Makefile
+++ b/v4l2-apps/lib/libv4l/libv4l2/Makefile
@@ -1,20 +1,25 @@
-CC = gcc
-LD = gcc
-
-CPPFLAGS = -fPIC -I../include -I../../../../linux/include
+CPPFLAGS = -I../include -I../../../../linux/include
CFLAGS := -g -O1
CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes
-LDFLAGS = -shared
+LIBS = -lpthread
-V4L2_OBJS = libv4l2.o log.o ../libv4lconvert/libv4lconvert.so
-V4L2_LIB = libv4l2.so
+V4L2_OBJS = libv4l2.o log.o
V4L2CONVERT = v4l2convert.so
V4L2CONVERT_O = v4l2convert.o libv4l2.so
-TARGETS = $(V4L2_LIB) $(V4L2CONVERT)
+TARGETS = $(V4L2_LIB) libv4l2.pc
INCLUDES = ../include/libv4l2.h
+ifeq ($(LINKTYPE),static)
+V4L2_LIB = libv4l2.a
+else
+V4L2_LIB = libv4l2.so
+V4L2_OBJS += ../libv4lconvert/libv4lconvert.so
+TARGETS += $(V4L2CONVERT)
+CPPFLAGS += -fPIC
+endif
+
ifeq ($(LIB_RELEASE),)
LIB_RELEASE = 0
endif
@@ -33,23 +38,45 @@ $(V4L2_LIB): $(V4L2_OBJS)
$(V4L2CONVERT): $(V4L2CONVERT_O) $(V4L2_LIB)
+libv4l2.pc:
+ @echo prefix=$(PREFIX) > libv4l2.pc
+ @echo libdir=$(LIBDIR) >> libv4l2.pc
+ @echo >> libv4l2.pc
+ @echo 'Name: libv4l2' >> libv4l2.pc
+ @echo 'Description: v4l2 device access library' >> libv4l2.pc
+ @echo 'Version: '$(V4L2_LIB_VERSION) >> libv4l2.pc
+ @echo 'Requires: libv4lconvert' >> libv4l2.pc
+ @echo 'Libs: -L$${libdir} -lv4l2' >> libv4l2.pc
+ @echo 'Libs.private: -lpthread' >> libv4l2.pc
+ @echo 'Cflags: -I$${prefix}/include' >> libv4l2.pc
+
install: all
mkdir -p $(DESTDIR)$(PREFIX)/include
install -p -m 644 $(INCLUDES) $(DESTDIR)$(PREFIX)/include
+ifeq ($(LINKTYPE),static)
+ mkdir -p $(DESTDIR)$(LIBDIR)
+ install -m 644 $(V4L2_LIB) $(DESTDIR)$(LIBDIR)
+else
mkdir -p $(DESTDIR)$(LIBDIR)/libv4l
install -m 755 $(V4L2_LIB).$(LIB_RELEASE) $(DESTDIR)$(LIBDIR)
cd $(DESTDIR)$(LIBDIR) && \
ln -f -s $(V4L2_LIB).$(LIB_RELEASE) $(V4L2_LIB)
install -m 755 $(V4L2CONVERT).$(LIB_RELEASE) \
$(DESTDIR)$(LIBDIR)/libv4l/$(V4L2CONVERT)
+endif
+ mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig
+ install -m 644 libv4l2.pc $(DESTDIR)$(LIBDIR)/pkgconfig
clean::
- rm -f *.so* *.o log *~
- rm -f *.d
+ rm -f *.a *.so* *.o *.d libv4l2.pc log *~
%.o: %.c
$(CC) -c -MMD $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.so:
- $(CC) $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^
+ $(CC) -shared $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^ $(LIBS)
ln -f -s $@.$(LIB_RELEASE) $@
+
+%.a:
+ $(AR) cqs $@ $^
+
diff --git a/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h b/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h
index 203dcffaf..8724832e1 100644
--- a/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h
+++ b/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h
@@ -8,8 +8,8 @@
#
# 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.
+# 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
@@ -68,8 +68,6 @@
#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;
@@ -81,20 +79,14 @@ struct v4l2_dev_info {
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 */
+ /* mapping tracking of our fake (converting mmap) frame buffers */
+ unsigned char frame_map_count[V4L2_MAX_NO_FRAMES];
};
/* From log.c */
diff --git a/v4l2-apps/lib/libv4l/libv4l2/libv4l2.c b/v4l2-apps/lib/libv4l/libv4l2/libv4l2.c
index 8dfcf9b71..a40ab4ffe 100644
--- a/v4l2-apps/lib/libv4l/libv4l2/libv4l2.c
+++ b/v4l2-apps/lib/libv4l/libv4l2/libv4l2.c
@@ -8,8 +8,8 @@
#
# 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.
+# 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
@@ -35,12 +35,12 @@
capture devices.
2) libv4l2 is the base of the v4l2convert.so wrapper lib, which is a .so
which can be LD_PRELOAD-ed and the overrules the libc's open/close/etc,
- and when opening /dev/videoX calls v4l2_open. Because we behave as the
- regular counterpart when the fd is not known (instead of say throwing
- an error), v4l2convert.so can simply call the v4l2_ prefixed function
- for all wrapped functions (except for v4l2_open which will fail when not
- called on a v4l2 device). This way the wrapper does not have to keep
- track of which fd's are being handled by libv4l2, as libv4l2 already
+ and when opening /dev/videoX or /dev/v4l/ calls v4l2_open. Because we
+ behave as the regular counterpart when the fd is not known (instead of say
+ throwing an error), v4l2convert.so can simply call the v4l2_ prefixed
+ function for all wrapped functions (except for v4l2_open which will fail
+ when not called on a v4l2 device). This way the wrapper does not have to
+ keep track of which fd's are being handled by libv4l2, as libv4l2 already
keeps track of this itself.
This also means that libv4l2 may not use any of the regular functions
@@ -72,7 +72,10 @@
/* Note these flags are stored together with the flags passed to v4l2_fd_open()
in v4l2_dev_info's flags member, so care should be taken that the do not
use the same bits! */
-#define V4L2_STREAMON 0x0100
+#define V4L2_STREAMON 0x0100
+#define V4L2_BUFFERS_REQUESTED_BY_READ 0x0200
+#define V4L2_STREAM_CONTROLLED_BY_READ 0x0400
+#define V4L2_SUPPORTS_READ 0x0800
#define V4L2_MMAP_OFFSET_MAGIC 0xABCDEF00u
@@ -89,52 +92,45 @@ static int v4l2_request_read_buffers(int index)
int result;
struct v4l2_requestbuffers req;
- /* No-op if already done */
- if (devices[index].no_frames)
- return 0;
-
- /* Request buffers */
- req.count = devices[index].nreadbuffers;
+ /* Note we re-request the buffers if they are already requested as the format
+ and thus the needed buffersize may have changed. */
+ req.count = (devices[index].no_frames)? devices[index].no_frames:
+ devices[index].nreadbuffers;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
- if ((result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_REQBUFS, &req))){
+ if ((result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_REQBUFS, &req)) < 0){
int saved_err = errno;
- V4L2_LOG_ERR("requesting buffers: %s\n", strerror(errno));
+ V4L2_LOG_ERR("requesting %u buffers: %s\n", req.count, strerror(errno));
errno = saved_err;
return result;
}
+ if (!devices[index].no_frames && req.count)
+ devices[index].flags |= V4L2_BUFFERS_REQUESTED_BY_READ;
+
devices[index].no_frames = MIN(req.count, V4L2_MAX_NO_FRAMES);
return 0;
}
-static int v4l2_unrequest_read_buffers(int index)
+static void v4l2_unrequest_read_buffers(int index)
{
- int result;
struct v4l2_requestbuffers req;
- /* No-op of already done */
- if (devices[index].no_frames == 0)
- return 0;
+ if (!(devices[index].flags & V4L2_BUFFERS_REQUESTED_BY_READ) ||
+ devices[index].no_frames == 0)
+ return;
- /* (Un)Request buffers */
+ /* (Un)Request buffers, note not all driver support this, and those
+ who do not support it don't need it. */
req.count = 0;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
- if ((result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_REQBUFS, &req))) {
- int saved_err = errno;
- V4L2_LOG_ERR("unrequesting buffers: %s\n", strerror(errno));
- errno = saved_err;
- return result;
- }
+ if(syscall(SYS_ioctl, devices[index].fd, VIDIOC_REQBUFS, &req) < 0)
+ return;
devices[index].no_frames = MIN(req.count, V4L2_MAX_NO_FRAMES);
- if (devices[index].no_frames) {
- V4L2_LOG_ERR("number of buffers > 0 after requesting 0 buffers\n");
- errno = EBUSY;
- return -1;
- }
- return 0;
+ if (devices[index].no_frames == 0)
+ devices[index].flags &= ~V4L2_BUFFERS_REQUESTED_BY_READ;
}
static int v4l2_map_buffers(int index)
@@ -159,7 +155,7 @@ static int v4l2_map_buffers(int index)
}
devices[index].frame_pointers[i] = (void *)syscall(SYS_mmap2, NULL,
- (size_t)buf.length, PROT_READ, MAP_SHARED, devices[index].fd,
+ (size_t)buf.length, PROT_READ|PROT_WRITE, MAP_SHARED, devices[index].fd,
(__off_t)(buf.m.offset >> MMAP2_PAGE_SHIFT));
if (devices[index].frame_pointers[i] == MAP_FAILED) {
int saved_err = errno;
@@ -241,6 +237,7 @@ static int v4l2_queue_read_buffer(int index, int buffer_index)
if (devices[index].frame_queued & (1 << buffer_index))
return 0;
+ memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = buffer_index;
@@ -310,6 +307,8 @@ static int v4l2_activate_read_stream(int index)
if ((result = v4l2_queue_read_buffers(index)))
return result;
+ devices[index].flags |= V4L2_STREAM_CONTROLLED_BY_READ;
+
return result = v4l2_streamon(index);
}
@@ -324,12 +323,48 @@ static int v4l2_deactivate_read_stream(int index)
v4l2_unmap_buffers(index);
- if ((result = v4l2_unrequest_read_buffers(index)))
- return result;
+ v4l2_unrequest_read_buffers(index);
+
+ devices[index].flags &= ~V4L2_STREAM_CONTROLLED_BY_READ;
return 0;
}
+static int v4l2_buffers_mapped(int index)
+{
+ unsigned int i;
+
+ if (devices[index].src_fmt.fmt.pix.pixelformat ==
+ devices[index].dest_fmt.fmt.pix.pixelformat) {
+ /* Normal (no conversion) mode */
+ struct v4l2_buffer buf;
+
+ for (i = 0; i < devices[index].no_frames; i++) {
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = i;
+ if (syscall(SYS_ioctl, devices[index].fd, VIDIOC_QUERYBUF, &buf)) {
+ int saved_err = errno;
+ V4L2_LOG_ERR("querying buffer %u: %s\n", i, strerror(errno));
+ errno = saved_err;
+ break;
+ }
+ if (buf.flags & V4L2_BUF_FLAG_MAPPED)
+ break;
+ }
+ } else {
+ /* Conversion mode */
+ for (i = 0; i < devices[index].no_frames; i++)
+ if (devices[index].frame_map_count[i])
+ break;
+ }
+
+ if (i != devices[index].no_frames)
+ V4L2_LOG("v4l2_buffers_mapped(): buffers still mapped\n");
+
+ return i != devices[index].no_frames;
+}
+
int v4l2_open (const char *file, int oflag, ...)
{
@@ -386,8 +421,10 @@ int v4l2_fd_open(int fd, int v4l2_flags)
return -1;
}
- /* we only add functionality for video capture devices */
- if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
+ /* we only add functionality for video capture devices, and we do not
+ handle devices which don't do mmap */
+ if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) ||
+ !(cap.capabilities & V4L2_CAP_STREAMING))
return fd;
/* Get current cam format */
@@ -420,6 +457,8 @@ int v4l2_fd_open(int fd, int v4l2_flags)
}
devices[index].flags = v4l2_flags;
+ if (cap.capabilities & V4L2_CAP_READWRITE)
+ devices[index].flags |= V4L2_SUPPORTS_READ;
devices[index].open_count = 1;
devices[index].src_fmt = fmt;
devices[index].dest_fmt = fmt;
@@ -428,15 +467,13 @@ int v4l2_fd_open(int fd, int v4l2_flags)
devices[index].no_frames = 0;
devices[index].nreadbuffers = V4L2_DEFAULT_NREADBUFFERS;
- devices[index].io = v4l2_io_none;
devices[index].convert = convert;
devices[index].convert_mmap_buf = MAP_FAILED;
for (i = 0; i < V4L2_MAX_NO_FRAMES; i++) {
devices[index].frame_pointers[i] = MAP_FAILED;
+ devices[index].frame_map_count[i] = 0;
}
devices[index].frame_queued = 0;
- devices[index].frame_mapped = 0;
- devices[index].frame_map_count = 0;
if (index >= devices_used)
devices_used = index + 1;
@@ -487,11 +524,8 @@ int v4l2_close(int fd)
v4l2_unmap_buffers(index);
v4lconvert_destroy(devices[index].convert);
if (devices[index].convert_mmap_buf != MAP_FAILED) {
- if (devices[index].frame_mapped || devices[index].frame_map_count)
- V4L2_LOG(
- "v4l2 mmap buffers still mapped on close(), mask: %08x, count: %d\n",
- (unsigned int)devices[index].frame_mapped,
- devices[index].frame_map_count);
+ if (v4l2_buffers_mapped(index))
+ V4L2_LOG_WARN("v4l2 mmap buffers still mapped on close()\n");
else
syscall(SYS_munmap, devices[index].convert_mmap_buf,
devices[index].no_frames * V4L2_FRAME_BUF_SIZE);
@@ -526,6 +560,34 @@ int v4l2_dup(int fd)
return fd;
}
+static int v4l2_check_buffer_change_ok(int index)
+{
+ v4l2_unmap_buffers(index);
+
+ /* Check if the app itself still is using the stream */
+ if (v4l2_buffers_mapped(index) ||
+ (!(devices[index].flags & V4L2_STREAM_CONTROLLED_BY_READ) &&
+ ((devices[index].flags & V4L2_STREAMON) ||
+ devices[index].frame_queued))) {
+ V4L2_LOG("v4l2_check_buffer_change_ok(): stream busy\n");
+ errno = EBUSY;
+ return -1;
+ }
+
+ /* We may change from convert to non conversion mode and
+ v4l2_unrequest_read_buffers may change the no_frames, so free the
+ convert mmap buffer */
+ syscall(SYS_munmap, devices[index].convert_mmap_buf,
+ devices[index].no_frames * V4L2_FRAME_BUF_SIZE);
+ devices[index].convert_mmap_buf = MAP_FAILED;
+
+ if (devices[index].flags & V4L2_STREAM_CONTROLLED_BY_READ) {
+ V4L2_LOG("deactivating read-stream for settings change\n");
+ return v4l2_deactivate_read_stream(index);
+ }
+
+ return 0;
+}
int v4l2_ioctl (int fd, unsigned long int request, ...)
{
@@ -548,6 +610,9 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
/* Is this a capture request and do we need to take the stream lock? */
switch (request) {
+ case VIDIOC_QUERYCAP:
+ is_capture_request = 1;
+ break;
case VIDIOC_ENUM_FMT:
if (((struct v4l2_fmtdesc *)arg)->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
is_capture_request = 1;
@@ -603,6 +668,17 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
switch (request) {
+ case VIDIOC_QUERYCAP:
+ {
+ struct v4l2_capability *cap = arg;
+
+ result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_QUERYCAP, cap);
+ if (result == 0)
+ /* We always support read() as we fake it using mmap mode */
+ cap->capabilities |= V4L2_CAP_READWRITE;
+ }
+ break;
+
case VIDIOC_ENUM_FMT:
result = v4lconvert_enum_fmt(devices[index].convert, arg);
break;
@@ -620,17 +696,6 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
break;
}
- /* Don't allow changing the format when mmap-ed IO is active, we could
- allow this to happen in certain special circumstances, but it is
- best to consistently deny this so that application developers do not
- go expect this to work, because in their test setup it happens to
- work. This also keeps the code much saner. */
- if (devices[index].io == v4l2_io_mmap) {
- errno = EBUSY;
- result = -1;
- break;
- }
-
if (devices[index].flags & V4L2_DISABLE_CONVERSION) {
result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_TRY_FMT,
dest_fmt);
@@ -651,16 +716,8 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
break;
}
- if (devices[index].io == v4l2_io_read) {
- V4L2_LOG("deactivating read-stream for format change\n");
- if ((result = v4l2_deactivate_read_stream(index))) {
- /* Undo what we've done to leave things in a consisten state */
- if (v4l2_activate_read_stream(index))
- V4L2_LOG_ERR(
- "reactivating stream after deactivate failure (AAIIEEEE)\n");
- break;
- }
- }
+ if ((result = v4l2_check_buffer_change_ok(index)))
+ break;
result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_S_FMT, &src_fmt);
if (result) {
@@ -690,22 +747,6 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
{
struct v4l2_requestbuffers *req = arg;
- /* Don't allow mixing read / mmap io, either we control the buffers
- (read based io), or the app does */
- if (devices[index].io == v4l2_io_read) {
- V4L2_LOG_ERR("to change from read io to mmap io open and close the device first!\n");
- errno = EBUSY;
- result = -1;
- break;
- }
-
- /* Are any of our fake (convert_mmap_buf) buffers still mapped ? */
- if (devices[index].frame_mapped || devices[index].frame_map_count) {
- errno = EBUSY;
- result = -1;
- break;
- }
-
/* IMPROVEME (maybe?) add support for userptr's? */
if (req->memory != V4L2_MEMORY_MMAP) {
errno = EINVAL;
@@ -713,29 +754,20 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
break;
}
+ if ((result = v4l2_check_buffer_change_ok(index)))
+ break;
+
/* No more buffers then we can manage please */
if (req->count > V4L2_MAX_NO_FRAMES)
req->count = V4L2_MAX_NO_FRAMES;
- /* Stop stream and unmap our real mapping of the buffers
- (only relevant when we're converting, otherwise a no-op) */
- v4l2_streamoff(index);
- v4l2_unmap_buffers(index);
-
result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_REQBUFS, req);
- if (result)
+ if (result < 0)
break;
+ result = 0; /* some drivers return the number of buffers on success */
- /* If we got more frames then we can handle lie to the app */
- if (req->count > V4L2_MAX_NO_FRAMES)
- req->count = V4L2_MAX_NO_FRAMES;
-
- /* Force reallocation of convert_mmap_buf to fit the new no_frames */
- syscall(SYS_munmap, devices[index].convert_mmap_buf,
- devices[index].no_frames * V4L2_FRAME_BUF_SIZE);
- devices[index].convert_mmap_buf = MAP_FAILED;
- devices[index].no_frames = req->count;
- devices[index].io = req->count? v4l2_io_mmap:v4l2_io_none;
+ devices[index].no_frames = MIN(req->count, V4L2_MAX_NO_FRAMES);
+ devices[index].flags &= ~V4L2_BUFFERS_REQUESTED_BY_READ;
}
break;
@@ -743,6 +775,10 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
{
struct v4l2_buffer *buf = arg;
+ if (devices[index].flags & V4L2_STREAM_CONTROLLED_BY_READ)
+ if ((result = v4l2_deactivate_read_stream(index)))
+ break;
+
/* Do a real query even when converting to let the driver fill in
things like buf->field */
result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_QUERYBUF, buf);
@@ -751,10 +787,23 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
buf->m.offset = V4L2_MMAP_OFFSET_MAGIC | buf->index;
buf->length = V4L2_FRAME_BUF_SIZE;
+ if (devices[index].frame_map_count[buf->index])
+ buf->flags |= V4L2_BUF_FLAG_MAPPED;
+ else
+ buf->flags &= ~V4L2_BUF_FLAG_MAPPED;
}
break;
case VIDIOC_QBUF:
+ if (devices[index].flags & V4L2_STREAM_CONTROLLED_BY_READ)
+ if ((result = v4l2_deactivate_read_stream(index)))
+ break;
+
+ /* With some drivers the buffers must be mapped before queuing */
+ if (converting)
+ if ((result = v4l2_map_buffers(index)))
+ break;
+
result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_QBUF, arg);
break;
@@ -762,6 +811,10 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
{
struct v4l2_buffer *buf = arg;
+ if (devices[index].flags & V4L2_STREAM_CONTROLLED_BY_READ)
+ if ((result = v4l2_deactivate_read_stream(index)))
+ break;
+
result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_DQBUF, buf);
if (result) {
V4L2_LOG_ERR("dequeing buffer: %s\n", strerror(errno));
@@ -810,7 +863,12 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
}
buf->bytesused = result;
+ buf->m.offset = V4L2_MMAP_OFFSET_MAGIC | buf->index;
buf->length = V4L2_FRAME_BUF_SIZE;
+ if (devices[index].frame_map_count[buf->index])
+ buf->flags |= V4L2_BUF_FLAG_MAPPED;
+ else
+ buf->flags &= ~V4L2_BUF_FLAG_MAPPED;
result = 0;
}
@@ -818,11 +876,9 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
case VIDIOC_STREAMON:
case VIDIOC_STREAMOFF:
- if (devices[index].io != v4l2_io_mmap) {
- errno = EINVAL;
- result = -1;
- break;
- }
+ if (devices[index].flags & V4L2_STREAM_CONTROLLED_BY_READ)
+ if ((result = v4l2_deactivate_read_stream(index)))
+ break;
if (request == VIDIOC_STREAMON)
result = v4l2_streamon(index);
@@ -855,22 +911,36 @@ ssize_t v4l2_read (int fd, void* buffer, size_t n)
pthread_mutex_lock(&devices[index].stream_lock);
- if (devices[index].io == v4l2_io_mmap) {
- V4L2_LOG_ERR("to change from mmap io to read io first do request_buffers with a count of 0\n");
- errno = EBUSY;
- result = -1;
+ /* When not converting and the device supports read let the kernel handle
+ it */
+ if ((devices[index].flags & V4L2_SUPPORTS_READ) &&
+ devices[index].src_fmt.fmt.pix.pixelformat ==
+ devices[index].dest_fmt.fmt.pix.pixelformat) {
+ result = syscall(SYS_read, fd, buffer, n);
goto leave;
}
- devices[index].io = v4l2_io_read;
- if ((result = v4l2_activate_read_stream(index)))
- goto leave;
+ if (!(devices[index].flags & V4L2_STREAM_CONTROLLED_BY_READ)) {
+ if ((devices[index].flags & V4L2_STREAMON) ||
+ devices[index].frame_queued) {
+ errno = EBUSY;
+ result = -1;
+ goto leave;
+ }
+ if ((result = v4l2_activate_read_stream(index)))
+ goto leave;
+ }
if ((frame_index = v4l2_dequeue_read_buffer(index, &bytesused)) < 0) {
result = -1;
goto leave;
}
+ /* ensure buffers are mapped before using them (they could have been
+ unmapped by a s_fmt ioctl) */
+ if ((result = v4l2_map_buffers(index)))
+ goto leave;
+
result = v4lconvert_convert(devices[index].convert,
&devices[index].src_fmt, &devices[index].dest_fmt,
devices[index].frame_pointers[frame_index], bytesused,
@@ -917,7 +987,6 @@ void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd,
buffer_index = offset & 0xff;
if (buffer_index >= devices[index].no_frames ||
- devices[index].io != v4l2_io_mmap ||
/* Got magic offset and not converting ?? */
devices[index].src_fmt.fmt.pix.pixelformat ==
devices[index].dest_fmt.fmt.pix.pixelformat) {
@@ -943,8 +1012,7 @@ void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd,
}
}
- devices[index].frame_mapped |= 1 << buffer_index;
- devices[index].frame_map_count++;
+ devices[index].frame_map_count[buffer_index]++;
result = devices[index].convert_mmap_buf +
buffer_index * V4L2_FRAME_BUF_SIZE;
@@ -985,9 +1053,8 @@ int v4l2_munmap(void *_start, size_t length)
start >= devices[index].convert_mmap_buf &&
(start - devices[index].convert_mmap_buf) % length == 0 &&
buffer_index < devices[index].no_frames) {
- devices[index].frame_mapped &= ~(1 << buffer_index);
- if (devices[index].frame_map_count > 0)
- devices[index].frame_map_count--;
+ if (devices[index].frame_map_count[buffer_index] > 0)
+ devices[index].frame_map_count[buffer_index]--;
unmapped = 1;
}
diff --git a/v4l2-apps/lib/libv4l/libv4l2/log.c b/v4l2-apps/lib/libv4l/libv4l2/log.c
index 982a185c6..05f6c46d7 100644
--- a/v4l2-apps/lib/libv4l/libv4l2/log.c
+++ b/v4l2-apps/lib/libv4l/libv4l2/log.c
@@ -8,8 +8,8 @@
#
# 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.
+# 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
@@ -131,6 +131,14 @@ void v4l2_log_ioctl(unsigned long int request, void *arg, int result)
}
}
break;
+ case VIDIOC_REQBUFS:
+ {
+ struct v4l2_requestbuffers *req = arg;
+
+ fprintf(v4l2_log_file, " count: %u type: %d memory: %d\n",
+ req->count, req->type, req->memory);
+ }
+ break;
}
fprintf(v4l2_log_file, "result == %d\n", result);
diff --git a/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c b/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c
index 7db1ca6d6..f312828c6 100644
--- a/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c
+++ b/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c
@@ -12,8 +12,8 @@
#
# 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.
+# 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
@@ -66,7 +66,7 @@ int open (const char *file, int oflag, ...)
return fd;
/* check if we're opening a video4linux2 device */
- if (strncmp(file, "/dev/video", 10))
+ if (strncmp(file, "/dev/video", 10) && strncmp(file, "/dev/v4l/", 9))
return fd;
/* check that this is an v4l2 device, libv4l2 only supports v4l2 devices */
@@ -134,13 +134,13 @@ ssize_t read (int fd, void* buffer, size_t n)
return v4l2_read (fd, buffer, n);
}
-void mmap(void *start, size_t length, int prot, int flags, int fd,
+void *mmap(void *start, size_t length, int prot, int flags, int fd,
__off_t offset)
{
return v4l2_mmap(start, length, prot, flags, fd, offset);
}
-void mmap64(void *start, size_t length, int prot, int flags, int fd,
+void *mmap64(void *start, size_t length, int prot, int flags, int fd,
__off64_t offset)
{
return v4l2_mmap(start, length, prot, flags, fd, offset);
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/Makefile b/v4l2-apps/lib/libv4l/libv4lconvert/Makefile
index 38071de94..c2a5be942 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/Makefile
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/Makefile
@@ -1,17 +1,18 @@
-CC = gcc
-LD = gcc
-
-CPPFLAGS = -fPIC -I../include -I../../../../linux/include
+CPPFLAGS = -I../include -I../../../../linux/include
CFLAGS := -g -O1
CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes
-LDFLAGS = -shared
-
+ifeq ($(LINKTYPE),static)
+CONVERT_LIB = libv4lconvert.a
+else
CONVERT_LIB = libv4lconvert.so
+CPPFLAGS += -fPIC
+endif
+
CONVERT_OBJS = libv4lconvert.o tinyjpeg.o sn9c10x.o pac207.o \
jidctflt.o spca561-decompress.o rgbyuv.o spca501.o bayer.o
-TARGETS = $(CONVERT_LIB)
+TARGETS = $(CONVERT_LIB) libv4lconvert.pc
INCLUDES = ../include/libv4lconvert.h
ifeq ($(LIB_RELEASE),)
@@ -30,21 +31,40 @@ all: $(TARGETS)
$(CONVERT_LIB): $(CONVERT_OBJS)
+libv4lconvert.pc:
+ @echo prefix=$(PREFIX) > libv4lconvert.pc
+ @echo libdir=$(LIBDIR) >> libv4lconvert.pc
+ @echo >> libv4lconvert.pc
+ @echo 'Name: libv4lconvert' >> libv4lconvert.pc
+ @echo 'Description: v4l format conversion library' >> libv4lconvert.pc
+ @echo 'Version: '$(V4L2_LIB_VERSION) >> libv4lconvert.pc
+ @echo 'Libs: -L$${libdir} -lv4lconvert' >> libv4lconvert.pc
+ @echo 'Cflags: -I$${prefix}/include' >> libv4lconvert.pc
+
install: all
mkdir -p $(DESTDIR)$(PREFIX)/include
install -p -m 644 $(INCLUDES) $(DESTDIR)$(PREFIX)/include
mkdir -p $(DESTDIR)$(LIBDIR)
+ifeq ($(LINKTYPE),static)
+ mkdir -p $(DESTDIR)$(LIBDIR)
+ install -m 644 $(CONVERT_LIB) $(DESTDIR)$(LIBDIR)
+else
install -m 755 $(CONVERT_LIB).$(LIB_RELEASE) $(DESTDIR)$(LIBDIR)
cd $(DESTDIR)$(LIBDIR) && \
ln -f -s $(CONVERT_LIB).$(LIB_RELEASE) $(CONVERT_LIB)
+endif
+ mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig
+ install -m 644 libv4lconvert.pc $(DESTDIR)$(LIBDIR)/pkgconfig
clean::
- rm -f *.so* *.o log *~
- rm -f *.d
+ rm -f *.a *.so* *.o *.d libv4lconvert.pc log *~
%.o: %.c
$(CC) -c -MMD $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.so:
- $(CC) $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^
+ $(CC) -shared $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^
ln -f -s $@.$(LIB_RELEASE) $@
+
+%.a:
+ $(AR) cqs $@ $^
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/bayer.c b/v4l2-apps/lib/libv4l/libv4lconvert/bayer.c
index 166c13011..ca7bb486f 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/bayer.c
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/bayer.c
@@ -163,14 +163,10 @@ static void v4lconvert_border_bayer_line_to_bgr24(
}
/* From libdc1394, which on turn was based on OpenCV's Bayer decoding */
-void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
- unsigned char *bgr, int width, int height, unsigned int pixfmt)
+static void bayer_to_rgbbgr24(const unsigned char *bayer,
+ unsigned char *bgr, int width, int height, unsigned int pixfmt,
+ int start_with_green, int blue_line)
{
- int blue_line = pixfmt == V4L2_PIX_FMT_SBGGR8
- || pixfmt == V4L2_PIX_FMT_SGBRG8;
- int start_with_green = pixfmt == V4L2_PIX_FMT_SGBRG8
- || pixfmt == V4L2_PIX_FMT_SGRBG8;
-
/* render the first line */
v4lconvert_border_bayer_line_to_bgr24(bayer, bayer + width, bgr, width,
start_with_green, blue_line);
@@ -317,6 +313,26 @@ void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
!start_with_green, !blue_line);
}
+void v4lconvert_bayer_to_rgb24(const unsigned char *bayer,
+ unsigned char *bgr, int width, int height, unsigned int pixfmt)
+{
+ bayer_to_rgbbgr24(bayer, bgr, width, height, pixfmt,
+ pixfmt == V4L2_PIX_FMT_SGBRG8 /* start with green */
+ || pixfmt == V4L2_PIX_FMT_SGRBG8,
+ pixfmt != V4L2_PIX_FMT_SBGGR8 /* blue line */
+ && pixfmt != V4L2_PIX_FMT_SGBRG8);
+}
+
+void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
+ unsigned char *bgr, int width, int height, unsigned int pixfmt)
+{
+ bayer_to_rgbbgr24(bayer, bgr, width, height, pixfmt,
+ pixfmt == V4L2_PIX_FMT_SGBRG8 /* start with green */
+ || pixfmt == V4L2_PIX_FMT_SGRBG8,
+ pixfmt == V4L2_PIX_FMT_SBGGR8 /* blue line */
+ || pixfmt == V4L2_PIX_FMT_SGBRG8);
+}
+
static void v4lconvert_border_bayer_line_to_y(
const unsigned char* bayer, const unsigned char* adjacent_bayer,
unsigned char *y, int width, int start_with_green, int blue_line)
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h b/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h
index badb89d62..bdf847186 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h
@@ -9,7 +9,7 @@
# 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.
+# 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
@@ -24,7 +24,15 @@
#include "tinyjpeg.h"
#ifndef V4L2_PIX_FMT_SPCA501
-#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S','5','0','1')
+#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S','5','0','1') /* YUYV per line */
+#endif
+
+#ifndef V4L2_PIX_FMT_SPCA505
+#define V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S','5','0','5') /* YYUV per line */
+#endif
+
+#ifndef V4L2_PIX_FMT_SPCA508
+#define V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S','5','0','8') /* YUVY per line */
#endif
#ifndef V4L2_PIX_FMT_SPCA561
@@ -63,13 +71,22 @@ struct v4lconvert_data {
};
+void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dst,
+ int width, int height);
+
void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dst,
int width, int height);
+void v4lconvert_swap_rgb(const unsigned char *src, unsigned char *dst,
+ int width, int height);
+
void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height);
-void v4lconvert_spca501_to_bgr24(const unsigned char *src, unsigned char *dst,
+void v4lconvert_spca505_to_yuv420(const unsigned char *src, unsigned char *dst,
+ int width, int height);
+
+void v4lconvert_spca508_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_decode_spca561(const unsigned char *src, unsigned char *dst,
@@ -81,6 +98,9 @@ void v4lconvert_decode_sn9c10x(const unsigned char *src, unsigned char *dst,
void v4lconvert_decode_pac207(const unsigned char *src, unsigned char *dst,
int width, int height);
+void v4lconvert_bayer_to_rgb24(const unsigned char *bayer,
+ unsigned char *rgb, int width, int height, unsigned int pixfmt);
+
void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
unsigned char *rgb, int width, int height, unsigned int pixfmt);
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c b/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c
index 6c6cb693d..4c9e67d52 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c
@@ -9,7 +9,7 @@
# 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.
+# 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
@@ -30,6 +30,7 @@
/* Note for proper functioning of v4lconvert_enum_fmt the first entries in
supported_src_pixfmts must match with the entries in supported_dst_pixfmts */
#define SUPPORTED_DST_PIXFMTS \
+ V4L2_PIX_FMT_RGB24, \
V4L2_PIX_FMT_BGR24, \
V4L2_PIX_FMT_YUV420
@@ -42,6 +43,8 @@ static const unsigned int supported_src_pixfmts[] = {
V4L2_PIX_FMT_SGRBG8,
V4L2_PIX_FMT_SRGGB8,
V4L2_PIX_FMT_SPCA501,
+ V4L2_PIX_FMT_SPCA505,
+ V4L2_PIX_FMT_SPCA508,
V4L2_PIX_FMT_SPCA561,
V4L2_PIX_FMT_SN9C10X,
V4L2_PIX_FMT_PAC207,
@@ -168,7 +171,9 @@ int v4lconvert_try_format(struct v4lconvert_data *data,
(int)dest_fmt->fmt.pix.height);
unsigned int size_diff = size_x_diff * size_x_diff +
size_y_diff * size_y_diff;
- if (size_diff < closest_fmt_size_diff) {
+ if (size_diff < closest_fmt_size_diff ||
+ (size_diff == closest_fmt_size_diff &&
+ try_fmt.fmt.pix.pixelformat == desired_pixfmt)) {
closest_fmt_size_diff = size_diff;
closest_fmt = try_fmt;
}
@@ -189,6 +194,7 @@ int v4lconvert_try_format(struct v4lconvert_data *data,
if (closest_fmt.fmt.pix.pixelformat != desired_pixfmt) {
dest_fmt->fmt.pix.pixelformat = desired_pixfmt;
switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
dest_fmt->fmt.pix.bytesperline = dest_fmt->fmt.pix.width * 3;
dest_fmt->fmt.pix.sizeimage = dest_fmt->fmt.pix.width *
@@ -226,6 +232,7 @@ int v4lconvert_convert(struct v4lconvert_data *data,
/* sanity check, is the dest buffer large enough? */
switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
needed = dest_fmt->fmt.pix.width * dest_fmt->fmt.pix.height * 3;
break;
@@ -281,12 +288,19 @@ int v4lconvert_convert(struct v4lconvert_data *data,
components[2] = components[1] + (dest_fmt->fmt.pix.width *
dest_fmt->fmt.pix.height) / 4;
- if (dest_fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_BGR24) {
+ switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
+ tinyjpeg_set_components(data->jdec, components, 1);
+ result = tinyjpeg_decode(data->jdec, TINYJPEG_FMT_RGB24);
+ break;
+ case V4L2_PIX_FMT_BGR24:
tinyjpeg_set_components(data->jdec, components, 1);
result = tinyjpeg_decode(data->jdec, TINYJPEG_FMT_BGR24);
- } else {
+ break;
+ default:
tinyjpeg_set_components(data->jdec, components, 3);
result = tinyjpeg_decode(data->jdec, TINYJPEG_FMT_YUV420P);
+ break;
}
/* If the JPEG header checked out ok and we get an error during actual
@@ -302,22 +316,59 @@ int v4lconvert_convert(struct v4lconvert_data *data,
case V4L2_PIX_FMT_SGBRG8:
case V4L2_PIX_FMT_SGRBG8:
case V4L2_PIX_FMT_SRGGB8:
- if (dest_fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_BGR24)
+ switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
+ v4lconvert_bayer_to_rgb24(src, dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height, src_fmt->fmt.pix.pixelformat);
+ break;
+ case V4L2_PIX_FMT_BGR24:
v4lconvert_bayer_to_bgr24(src, dest, dest_fmt->fmt.pix.width,
dest_fmt->fmt.pix.height, src_fmt->fmt.pix.pixelformat);
- else
+ break;
+ default:
v4lconvert_bayer_to_yuv420(src, dest, dest_fmt->fmt.pix.width,
dest_fmt->fmt.pix.height, src_fmt->fmt.pix.pixelformat);
+ break;
+ }
break;
+ /* YUYV line by line formats */
case V4L2_PIX_FMT_SPCA501:
- if (dest_fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_BGR24)
- v4lconvert_spca501_to_bgr24(src, dest, dest_fmt->fmt.pix.width,
- dest_fmt->fmt.pix.height);
- else
- v4lconvert_spca501_to_yuv420(src, dest, dest_fmt->fmt.pix.width,
- dest_fmt->fmt.pix.height);
+ case V4L2_PIX_FMT_SPCA505:
+ case V4L2_PIX_FMT_SPCA508:
+ {
+ unsigned char tmpbuf[dest_fmt->fmt.pix.width * dest_fmt->fmt.pix.height *
+ 3 / 2];
+ unsigned char *my_dst = (dest_fmt->fmt.pix.pixelformat !=
+ V4L2_PIX_FMT_YUV420) ? tmpbuf : dest;
+
+ switch (src_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_SPCA501:
+ v4lconvert_spca501_to_yuv420(src, my_dst, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ case V4L2_PIX_FMT_SPCA505:
+ v4lconvert_spca505_to_yuv420(src, my_dst, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ case V4L2_PIX_FMT_SPCA508:
+ v4lconvert_spca508_to_yuv420(src, my_dst, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ }
+
+ switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
+ v4lconvert_yuv420_to_rgb24(tmpbuf, dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ case V4L2_PIX_FMT_BGR24:
+ v4lconvert_yuv420_to_bgr24(tmpbuf, dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ }
break;
+ }
/* compressed bayer formats */
case V4L2_PIX_FMT_SPCA561:
@@ -345,24 +396,57 @@ int v4lconvert_convert(struct v4lconvert_data *data,
break;
}
- if (dest_fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_BGR24)
+ switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
+ v4lconvert_bayer_to_rgb24(tmpbuf, dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height, bayer_fmt);
+ break;
+ case V4L2_PIX_FMT_BGR24:
v4lconvert_bayer_to_bgr24(tmpbuf, dest, dest_fmt->fmt.pix.width,
dest_fmt->fmt.pix.height, bayer_fmt);
- else
+ break;
+ default:
v4lconvert_bayer_to_yuv420(tmpbuf, dest, dest_fmt->fmt.pix.width,
dest_fmt->fmt.pix.height, bayer_fmt);
+ break;
+ }
break;
}
+ case V4L2_PIX_FMT_RGB24:
+ switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_BGR24:
+ v4lconvert_swap_rgb(src, dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ case V4L2_PIX_FMT_YUV420:
+ printf("FIXME add rgb24 -> yuv420 conversion\n");
+ break;
+ }
+ break;
case V4L2_PIX_FMT_BGR24:
- /* dest must be V4L2_PIX_FMT_YUV420 then */
- printf("FIXME add bgr24 -> yuv420 conversion\n");
+ switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
+ v4lconvert_swap_rgb(src, dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ case V4L2_PIX_FMT_YUV420:
+ printf("FIXME add bgr24 -> yuv420 conversion\n");
+ break;
+ }
break;
case V4L2_PIX_FMT_YUV420:
- /* dest must be V4L2_PIX_FMT_BGR24 then */
- v4lconvert_yuv420_to_bgr24(src, dest, dest_fmt->fmt.pix.width,
- dest_fmt->fmt.pix.height);
+ switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
+ v4lconvert_yuv420_to_rgb24(src, dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ case V4L2_PIX_FMT_BGR24:
+ v4lconvert_yuv420_to_bgr24(src, dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ }
break;
default:
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/pac207.c b/v4l2-apps/lib/libv4l/libv4lconvert/pac207.c
index 085d7a772..4887c25ee 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/pac207.c
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/pac207.c
@@ -12,7 +12,7 @@
# 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.
+# 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
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c b/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c
index 79c8ecb35..742dd06ce 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c
@@ -12,7 +12,7 @@
# 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.
+# 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
@@ -80,3 +80,65 @@ void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dest,
}
}
}
+
+void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dest,
+ int width, int height)
+{
+ int i,j;
+
+ const unsigned char *ysrc = src;
+ const unsigned char *usrc = src + width * height;
+ const unsigned char *vsrc = usrc + (width * height) / 4;
+
+ for (i = 0; i < height; i++) {
+ for (j = 0; j < width; j += 2) {
+#if 1 /* fast slightly less accurate multiplication free code */
+ int u1 = (((*usrc - 128) << 7) + (*usrc - 128)) >> 6;
+ int rg = (((*usrc - 128) << 1) + (*usrc - 128) +
+ ((*vsrc - 128) << 2) + ((*vsrc - 128) << 1)) >> 3;
+ int v1 = (((*vsrc - 128) << 1) + (*vsrc - 128)) >> 1;
+
+ *dest++ = CLIP(*ysrc + v1);
+ *dest++ = CLIP(*ysrc - rg);
+ *dest++ = CLIP(*ysrc + u1);
+ ysrc++;
+
+ *dest++ = CLIP(*ysrc + v1);
+ *dest++ = CLIP(*ysrc - rg);
+ *dest++ = CLIP(*ysrc + u1);
+#else
+ *dest++ = YUV2R(*ysrc, *usrc, *vsrc);
+ *dest++ = YUV2G(*ysrc, *usrc, *vsrc);
+ *dest++ = YUV2B(*ysrc, *usrc, *vsrc);
+ ysrc++;
+
+ *dest++ = YUV2R(*ysrc, *usrc, *vsrc);
+ *dest++ = YUV2G(*ysrc, *usrc, *vsrc);
+ *dest++ = YUV2B(*ysrc, *usrc, *vsrc);
+#endif
+ ysrc++;
+ usrc++;
+ vsrc++;
+ }
+ /* Rewind u and v for next line */
+ if (i&1) {
+ usrc -= width / 2;
+ vsrc -= width / 2;
+ }
+ }
+}
+
+void v4lconvert_swap_rgb(const unsigned char *src, unsigned char *dst,
+ int width, int height)
+{
+ int i;
+
+ for (i = 0; i < (width * height); i++) {
+ unsigned char tmp0, tmp1;
+ tmp0 = *src++;
+ tmp1 = *src++;
+ *dst++ = *src++;
+ *dst++ = tmp1;
+ *dst++ = tmp0;
+ }
+}
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/sn9c10x.c b/v4l2-apps/lib/libv4l/libv4lconvert/sn9c10x.c
index b23ad4630..98a513378 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/sn9c10x.c
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/sn9c10x.c
@@ -10,7 +10,7 @@
# 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.
+# 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
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/spca501.c b/v4l2-apps/lib/libv4l/libv4lconvert/spca501.c
index b0170e7cb..9157629e3 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/spca501.c
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/spca501.c
@@ -9,7 +9,7 @@
# 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.
+# 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
@@ -18,14 +18,14 @@
#include "libv4lconvert-priv.h"
+/* YUYV per line */
void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height)
{
int i,j;
+ unsigned long *lsrc = (unsigned long *)src;
for (i = 0; i < height; i += 2) {
- unsigned long *lsrc = (unsigned long *)(src + (i / 2) * 3 * width);
-
/* -128 - 127 --> 0 - 255 and copy first line Y */
unsigned long *ldst = (unsigned long *)(dst + i * width);
for (j = 0; j < width; j += sizeof(long)) {
@@ -56,12 +56,71 @@ void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst,
}
}
-/* IMPROVEME (maybe?) make this convert in one go?? */
-void v4lconvert_spca501_to_bgr24(const unsigned char *src, unsigned char *dst,
+/* YYUV per line */
+void v4lconvert_spca505_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height)
{
- unsigned char buf[(width * height * 6) / 4];
+ int i,j;
+ unsigned long *lsrc = (unsigned long *)src;
+
+ for (i = 0; i < height; i += 2) {
+ /* -128 - 127 --> 0 - 255 and copy 2 lines of Y */
+ unsigned long *ldst = (unsigned long *)(dst + i * width);
+ for (j = 0; j < width*2; j += sizeof(long)) {
+ *ldst = *lsrc++;
+ *ldst++ ^= 0x8080808080808080ULL;
+ }
+
+ /* -128 - 127 --> 0 - 255 and copy 1 line U */
+ ldst = (unsigned long *)(dst + width * height + i * width / 4);
+ for (j = 0; j < width/2; j += sizeof(long)) {
+ *ldst = *lsrc++;
+ *ldst++ ^= 0x8080808080808080ULL;
+ }
- v4lconvert_spca501_to_yuv420(src, buf, width, height);
- v4lconvert_yuv420_to_bgr24(buf, dst, width, height);
+ /* -128 - 127 --> 0 - 255 and copy 1 line V */
+ ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4);
+ for (j = 0; j < width/2; j += sizeof(long)) {
+ *ldst = *lsrc++;
+ *ldst++ ^= 0x8080808080808080ULL;
+ }
+ }
+}
+
+/* YUVY per line */
+void v4lconvert_spca508_to_yuv420(const unsigned char *src, unsigned char *dst,
+ int width, int height)
+{
+ int i,j;
+ unsigned long *lsrc = (unsigned long *)src;
+
+ for (i = 0; i < height; i += 2) {
+ /* -128 - 127 --> 0 - 255 and copy first line Y */
+ unsigned long *ldst = (unsigned long *)(dst + i * width);
+ for (j = 0; j < width; j += sizeof(long)) {
+ *ldst = *lsrc++;
+ *ldst++ ^= 0x8080808080808080ULL;
+ }
+
+ /* -128 - 127 --> 0 - 255 and copy 1 line U */
+ ldst = (unsigned long *)(dst + width * height + i * width / 4);
+ for (j = 0; j < width/2; j += sizeof(long)) {
+ *ldst = *lsrc++;
+ *ldst++ ^= 0x8080808080808080ULL;
+ }
+
+ /* -128 - 127 --> 0 - 255 and copy 1 line V */
+ ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4);
+ for (j = 0; j < width/2; j += sizeof(long)) {
+ *ldst = *lsrc++;
+ *ldst++ ^= 0x8080808080808080ULL;
+ }
+
+ /* -128 - 127 --> 0 - 255 and copy second line Y */
+ ldst = (unsigned long *)(dst + i * width + width);
+ for (j = 0; j < width; j += sizeof(long)) {
+ *ldst = *lsrc++;
+ *ldst++ ^= 0x8080808080808080ULL;
+ }
+ }
}
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/spca561-decompress.c b/v4l2-apps/lib/libv4l/libv4lconvert/spca561-decompress.c
index 40b0f90db..802345af0 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/spca561-decompress.c
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/spca561-decompress.c
@@ -10,7 +10,7 @@
# 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.
+# 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
diff --git a/v4l2-apps/test/capture_example.c b/v4l2-apps/test/capture_example.c
index bbb0c4e57..a15ef3c09 100644
--- a/v4l2-apps/test/capture_example.c
+++ b/v4l2-apps/test/capture_example.c
@@ -27,7 +27,7 @@
#include <linux/videodev2.h>
-#define CLEAR(x) memset (&(x), 0, sizeof (x))
+#define CLEAR(x) memset(&(x), 0, sizeof(x))
typedef enum {
IO_METHOD_READ,
@@ -36,60 +36,53 @@ typedef enum {
} io_method;
struct buffer {
- void * start;
- size_t length;
+ void *start;
+ size_t length;
};
-static char * dev_name = NULL;
-static io_method io = IO_METHOD_MMAP;
-static int fd = -1;
-struct buffer * buffers = NULL;
-static unsigned int n_buffers = 0;
-static int out_buf = 0;
+static char *dev_name;
+static io_method io = IO_METHOD_MMAP;
+static int fd = -1;
+struct buffer *buffers;
+static unsigned int n_buffers;
+static int out_buf;
+static int force_format;
-static void
-errno_exit (const char * s)
+static void errno_exit(const char *s)
{
- fprintf (stderr, "%s error %d, %s\n",
- s, errno, strerror (errno));
-
- exit (EXIT_FAILURE);
+ fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno));
+ exit(EXIT_FAILURE);
}
-static int
-xioctl (int fd,
- int request,
- void * arg)
+static int xioctl(int fh, int request, void *arg)
{
int r;
- do r = ioctl (fd, request, arg);
- while (-1 == r && EINTR == errno);
+ do {
+ r = ioctl(fh, request, arg);
+ } while (-1 == r && EINTR == errno);
return r;
}
-static void
-process_image (const void * p,
- int size)
+static void process_image(const void *p, int size)
{
- if (!out_buf)
- fputc ('.', stdout);
- else
- fwrite (p, size, 1, stdout);
+ if (out_buf)
+ fwrite(p, size, 1, stdout);
- fflush (stdout);
+ fflush(stderr);
+ fprintf(stderr, ".");
+ fflush(stdout);
}
-static int
-read_frame (void)
+static int read_frame(void)
{
struct v4l2_buffer buf;
unsigned int i;
switch (io) {
case IO_METHOD_READ:
- if (-1 == read (fd, buffers[0].start, buffers[0].length)) {
+ if (-1 == read(fd, buffers[0].start, buffers[0].length)) {
switch (errno) {
case EAGAIN:
return 0;
@@ -100,21 +93,20 @@ read_frame (void)
/* fall through */
default:
- errno_exit ("read");
+ errno_exit("read");
}
}
- process_image (buffers[0].start, buffers[0].length);
-
+ process_image(buffers[0].start, buffers[0].length);
break;
case IO_METHOD_MMAP:
- CLEAR (buf);
+ CLEAR(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
- if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) {
+ if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {
switch (errno) {
case EAGAIN:
return 0;
@@ -125,26 +117,25 @@ read_frame (void)
/* fall through */
default:
- errno_exit ("VIDIOC_DQBUF");
+ errno_exit("VIDIOC_DQBUF");
}
}
- assert (buf.index < n_buffers);
+ assert(buf.index < n_buffers);
- process_image (buffers[buf.index].start, buffers[buf.index].length);
-
- if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))
- errno_exit ("VIDIOC_QBUF");
+ process_image(buffers[buf.index].start, buf.bytesused);
+ if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
+ errno_exit("VIDIOC_QBUF");
break;
case IO_METHOD_USERPTR:
- CLEAR (buf);
+ CLEAR(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_USERPTR;
- if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) {
+ if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {
switch (errno) {
case EAGAIN:
return 0;
@@ -155,30 +146,28 @@ read_frame (void)
/* fall through */
default:
- errno_exit ("VIDIOC_DQBUF");
+ errno_exit("VIDIOC_DQBUF");
}
}
for (i = 0; i < n_buffers; ++i)
- if (buf.m.userptr == (unsigned long) buffers[i].start
+ if (buf.m.userptr == (unsigned long)buffers[i].start
&& buf.length == buffers[i].length)
break;
- assert (i < n_buffers);
-
- process_image ((void *) buf.m.userptr, buf.length);
+ assert(i < n_buffers);
- if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))
- errno_exit ("VIDIOC_QBUF");
+ process_image((void *)buf.m.userptr, buf.bytesused);
+ if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
+ errno_exit("VIDIOC_QBUF");
break;
}
return 1;
}
-static void
-mainloop (void)
+static void mainloop(void)
{
unsigned int count;
@@ -190,37 +179,34 @@ mainloop (void)
struct timeval tv;
int r;
- FD_ZERO (&fds);
- FD_SET (fd, &fds);
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
/* Timeout. */
tv.tv_sec = 2;
tv.tv_usec = 0;
- r = select (fd + 1, &fds, NULL, NULL, &tv);
+ r = select(fd + 1, &fds, NULL, NULL, &tv);
if (-1 == r) {
if (EINTR == errno)
continue;
-
- errno_exit ("select");
+ errno_exit("select");
}
if (0 == r) {
- fprintf (stderr, "select timeout\n");
- exit (EXIT_FAILURE);
+ fprintf(stderr, "select timeout\n");
+ exit(EXIT_FAILURE);
}
- if (read_frame ())
+ if (read_frame())
break;
-
/* EAGAIN - continue select loop. */
}
}
}
-static void
-stop_capturing (void)
+static void stop_capturing(void)
{
enum v4l2_buf_type type;
@@ -232,16 +218,13 @@ stop_capturing (void)
case IO_METHOD_MMAP:
case IO_METHOD_USERPTR:
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
- if (-1 == xioctl (fd, VIDIOC_STREAMOFF, &type))
- errno_exit ("VIDIOC_STREAMOFF");
-
+ if (-1 == xioctl(fd, VIDIOC_STREAMOFF, &type))
+ errno_exit("VIDIOC_STREAMOFF");
break;
}
}
-static void
-start_capturing (void)
+static void start_capturing(void)
{
unsigned int i;
enum v4l2_buf_type type;
@@ -255,192 +238,179 @@ start_capturing (void)
for (i = 0; i < n_buffers; ++i) {
struct v4l2_buffer buf;
- CLEAR (buf);
+ CLEAR(buf);
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = i;
- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- buf.memory = V4L2_MEMORY_MMAP;
- buf.index = i;
-
- if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))
- errno_exit ("VIDIOC_QBUF");
+ if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
+ errno_exit("VIDIOC_QBUF");
}
-
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
- if (-1 == xioctl (fd, VIDIOC_STREAMON, &type))
- errno_exit ("VIDIOC_STREAMON");
-
+ if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))
+ errno_exit("VIDIOC_STREAMON");
break;
case IO_METHOD_USERPTR:
for (i = 0; i < n_buffers; ++i) {
struct v4l2_buffer buf;
- CLEAR (buf);
+ CLEAR(buf);
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_USERPTR;
+ buf.index = i;
+ buf.m.userptr = (unsigned long)buffers[i].start;
+ buf.length = buffers[i].length;
- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- buf.memory = V4L2_MEMORY_USERPTR;
- buf.index = i;
- buf.m.userptr = (unsigned long) buffers[i].start;
- buf.length = buffers[i].length;
-
- if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))
- errno_exit ("VIDIOC_QBUF");
+ if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
+ errno_exit("VIDIOC_QBUF");
}
-
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
- if (-1 == xioctl (fd, VIDIOC_STREAMON, &type))
- errno_exit ("VIDIOC_STREAMON");
-
+ if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))
+ errno_exit("VIDIOC_STREAMON");
break;
}
}
-static void
-uninit_device (void)
+static void uninit_device(void)
{
unsigned int i;
switch (io) {
case IO_METHOD_READ:
- free (buffers[0].start);
+ free(buffers[0].start);
break;
case IO_METHOD_MMAP:
for (i = 0; i < n_buffers; ++i)
- if (-1 == munmap (buffers[i].start, buffers[i].length))
- errno_exit ("munmap");
+ if (-1 == munmap(buffers[i].start, buffers[i].length))
+ errno_exit("munmap");
break;
case IO_METHOD_USERPTR:
for (i = 0; i < n_buffers; ++i)
- free (buffers[i].start);
+ free(buffers[i].start);
break;
}
- free (buffers);
+ free(buffers);
}
-static void
-init_read (unsigned int buffer_size)
+static void init_read(unsigned int buffer_size)
{
- buffers = calloc (1, sizeof (*buffers));
+ buffers = calloc(1, sizeof(*buffers));
if (!buffers) {
- fprintf (stderr, "Out of memory\n");
- exit (EXIT_FAILURE);
+ fprintf(stderr, "Out of memory\n");
+ exit(EXIT_FAILURE);
}
buffers[0].length = buffer_size;
- buffers[0].start = malloc (buffer_size);
+ buffers[0].start = malloc(buffer_size);
if (!buffers[0].start) {
- fprintf (stderr, "Out of memory\n");
- exit (EXIT_FAILURE);
+ fprintf(stderr, "Out of memory\n");
+ exit(EXIT_FAILURE);
}
}
-static void
-init_mmap (void)
+static void init_mmap(void)
{
struct v4l2_requestbuffers req;
- CLEAR (req);
+ CLEAR(req);
- req.count = 4;
- req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- req.memory = V4L2_MEMORY_MMAP;
+ req.count = 4;
+ req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ req.memory = V4L2_MEMORY_MMAP;
- if (-1 == xioctl (fd, VIDIOC_REQBUFS, &req)) {
+ if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
if (EINVAL == errno) {
- fprintf (stderr, "%s does not support "
+ fprintf(stderr, "%s does not support "
"memory mapping\n", dev_name);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
} else {
- errno_exit ("VIDIOC_REQBUFS");
+ errno_exit("VIDIOC_REQBUFS");
}
}
if (req.count < 2) {
- fprintf (stderr, "Insufficient buffer memory on %s\n",
+ fprintf(stderr, "Insufficient buffer memory on %s\n",
dev_name);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
- buffers = calloc (req.count, sizeof (*buffers));
+ buffers = calloc(req.count, sizeof(*buffers));
if (!buffers) {
- fprintf (stderr, "Out of memory\n");
- exit (EXIT_FAILURE);
+ fprintf(stderr, "Out of memory\n");
+ exit(EXIT_FAILURE);
}
for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {
struct v4l2_buffer buf;
- CLEAR (buf);
+ CLEAR(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = n_buffers;
- if (-1 == xioctl (fd, VIDIOC_QUERYBUF, &buf))
- errno_exit ("VIDIOC_QUERYBUF");
+ if (-1 == xioctl(fd, VIDIOC_QUERYBUF, &buf))
+ errno_exit("VIDIOC_QUERYBUF");
buffers[n_buffers].length = buf.length;
buffers[n_buffers].start =
- mmap (NULL /* start anywhere */,
+ mmap(NULL /* start anywhere */,
buf.length,
PROT_READ | PROT_WRITE /* required */,
MAP_SHARED /* recommended */,
fd, buf.m.offset);
if (MAP_FAILED == buffers[n_buffers].start)
- errno_exit ("mmap");
+ errno_exit("mmap");
}
}
-static void
-init_userp (unsigned int buffer_size)
+static void init_userp(unsigned int buffer_size)
{
struct v4l2_requestbuffers req;
- CLEAR (req);
+ CLEAR(req);
- req.count = 4;
- req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- req.memory = V4L2_MEMORY_USERPTR;
+ req.count = 4;
+ req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ req.memory = V4L2_MEMORY_USERPTR;
- if (-1 == xioctl (fd, VIDIOC_REQBUFS, &req)) {
+ if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
if (EINVAL == errno) {
- fprintf (stderr, "%s does not support "
+ fprintf(stderr, "%s does not support "
"user pointer i/o\n", dev_name);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
} else {
- errno_exit ("VIDIOC_REQBUFS");
+ errno_exit("VIDIOC_REQBUFS");
}
}
- buffers = calloc (4, sizeof (*buffers));
+ buffers = calloc(4, sizeof(*buffers));
if (!buffers) {
- fprintf (stderr, "Out of memory\n");
- exit (EXIT_FAILURE);
+ fprintf(stderr, "Out of memory\n");
+ exit(EXIT_FAILURE);
}
for (n_buffers = 0; n_buffers < 4; ++n_buffers) {
buffers[n_buffers].length = buffer_size;
- buffers[n_buffers].start = malloc (buffer_size);
+ buffers[n_buffers].start = malloc(buffer_size);
if (!buffers[n_buffers].start) {
- fprintf (stderr, "Out of memory\n");
- exit (EXIT_FAILURE);
+ fprintf(stderr, "Out of memory\n");
+ exit(EXIT_FAILURE);
}
}
}
-static void
-init_device (void)
+static void init_device(void)
{
struct v4l2_capability cap;
struct v4l2_cropcap cropcap;
@@ -448,40 +418,38 @@ init_device (void)
struct v4l2_format fmt;
unsigned int min;
- if (-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap)) {
+ if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
if (EINVAL == errno) {
- fprintf (stderr, "%s is no V4L2 device\n",
+ fprintf(stderr, "%s is no V4L2 device\n",
dev_name);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
} else {
- errno_exit ("VIDIOC_QUERYCAP");
+ errno_exit("VIDIOC_QUERYCAP");
}
}
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
- fprintf (stderr, "%s is no video capture device\n",
+ fprintf(stderr, "%s is no video capture device\n",
dev_name);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
switch (io) {
case IO_METHOD_READ:
if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
- fprintf (stderr, "%s does not support read i/o\n",
+ fprintf(stderr, "%s does not support read i/o\n",
dev_name);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
-
break;
case IO_METHOD_MMAP:
case IO_METHOD_USERPTR:
if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
- fprintf (stderr, "%s does not support streaming i/o\n",
+ fprintf(stderr, "%s does not support streaming i/o\n",
dev_name);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
-
break;
}
@@ -489,15 +457,15 @@ init_device (void)
/* Select video input, video standard and tune here. */
- CLEAR (cropcap);
+ CLEAR(cropcap);
cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (0 == xioctl (fd, VIDIOC_CROPCAP, &cropcap)) {
+ if (0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)) {
crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
crop.c = cropcap.defrect; /* reset to default */
- if (-1 == xioctl (fd, VIDIOC_S_CROP, &crop)) {
+ if (-1 == xioctl(fd, VIDIOC_S_CROP, &crop)) {
switch (errno) {
case EINVAL:
/* Cropping not supported. */
@@ -512,18 +480,24 @@ init_device (void)
}
- CLEAR (fmt);
+ CLEAR(fmt);
- fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- fmt.fmt.pix.width = 640;
- fmt.fmt.pix.height = 480;
- fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
- fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
+ fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ if (force_format) {
+ fmt.fmt.pix.width = 640;
+ fmt.fmt.pix.height = 480;
+ fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
+ fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
- if (-1 == xioctl (fd, VIDIOC_S_FMT, &fmt))
- errno_exit ("VIDIOC_S_FMT");
+ if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
+ errno_exit("VIDIOC_S_FMT");
- /* Note VIDIOC_S_FMT may change width and height. */
+ /* Note VIDIOC_S_FMT may change width and height. */
+ } else {
+ /* Preserve original settings as set by v4l2-ctl for example */
+ if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt))
+ errno_exit("VIDIOC_G_FMT");
+ }
/* Buggy driver paranoia. */
min = fmt.fmt.pix.width * 2;
@@ -535,97 +509,91 @@ init_device (void)
switch (io) {
case IO_METHOD_READ:
- init_read (fmt.fmt.pix.sizeimage);
+ init_read(fmt.fmt.pix.sizeimage);
break;
case IO_METHOD_MMAP:
- init_mmap ();
+ init_mmap();
break;
case IO_METHOD_USERPTR:
- init_userp (fmt.fmt.pix.sizeimage);
+ init_userp(fmt.fmt.pix.sizeimage);
break;
}
}
-static void
-close_device (void)
+static void close_device(void)
{
- if (-1 == close (fd))
- errno_exit ("close");
+ if (-1 == close(fd))
+ errno_exit("close");
fd = -1;
}
-static void
-open_device (void)
+static void open_device(void)
{
struct stat st;
- if (-1 == stat (dev_name, &st)) {
- fprintf (stderr, "Cannot identify '%s': %d, %s\n",
- dev_name, errno, strerror (errno));
- exit (EXIT_FAILURE);
+ if (-1 == stat(dev_name, &st)) {
+ fprintf(stderr, "Cannot identify '%s': %d, %s\n",
+ dev_name, errno, strerror(errno));
+ exit(EXIT_FAILURE);
}
- if (!S_ISCHR (st.st_mode)) {
- fprintf (stderr, "%s is no device\n", dev_name);
- exit (EXIT_FAILURE);
+ if (!S_ISCHR(st.st_mode)) {
+ fprintf(stderr, "%s is no device\n", dev_name);
+ exit(EXIT_FAILURE);
}
- fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
+ fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
if (-1 == fd) {
- fprintf (stderr, "Cannot open '%s': %d, %s\n",
- dev_name, errno, strerror (errno));
- exit (EXIT_FAILURE);
+ fprintf(stderr, "Cannot open '%s': %d, %s\n",
+ dev_name, errno, strerror(errno));
+ exit(EXIT_FAILURE);
}
}
-static void
-usage (FILE * fp,
- int argc,
- char ** argv)
+static void usage(FILE *fp, int argc, char **argv)
{
- fprintf (fp,
+ fprintf(fp,
"Usage: %s [options]\n\n"
"Options:\n"
- "-d | --device name Video device name [/dev/video]\n"
+ "-d | --device name Video device name [/dev/video0]\n"
"-h | --help Print this message\n"
"-m | --mmap Use memory mapped buffers\n"
"-r | --read Use read() calls\n"
"-u | --userp Use application allocated buffers\n"
"-o | --output Outputs stream to stdout\n"
+ "-f | --format Force format to 640x480 YUYV\n"
"",
argv[0]);
}
-static const char short_options [] = "d:hmruo";
+static const char short_options[] = "d:hmruof";
static const struct option
-long_options [] = {
- { "device", required_argument, NULL, 'd' },
- { "help", no_argument, NULL, 'h' },
- { "mmap", no_argument, NULL, 'm' },
- { "read", no_argument, NULL, 'r' },
- { "userp", no_argument, NULL, 'u' },
- { "output", no_argument, NULL, 'o' },
+long_options[] = {
+ { "device", required_argument, NULL, 'd' },
+ { "help", no_argument, NULL, 'h' },
+ { "mmap", no_argument, NULL, 'm' },
+ { "read", no_argument, NULL, 'r' },
+ { "userp", no_argument, NULL, 'u' },
+ { "output", no_argument, NULL, 'o' },
+ { "format", no_argument, NULL, 'f' },
{ 0, 0, 0, 0 }
};
-int
-main (int argc,
- char ** argv)
+int main(int argc, char **argv)
{
- dev_name = "/dev/video";
+ dev_name = "/dev/video0";
for (;;) {
- int index;
+ int idx;
int c;
- c = getopt_long (argc, argv,
- short_options, long_options,
- &index);
+ c = getopt_long(argc, argv,
+ short_options, long_options, &idx);
if (-1 == c)
break;
@@ -639,8 +607,8 @@ main (int argc,
break;
case 'h':
- usage (stdout, argc, argv);
- exit (EXIT_SUCCESS);
+ usage(stdout, argc, argv);
+ exit(EXIT_SUCCESS);
case 'm':
io = IO_METHOD_MMAP;
@@ -658,27 +626,23 @@ main (int argc,
out_buf++;
break;
+ case 'f':
+ force_format++;
+ break;
+
default:
- usage (stderr, argc, argv);
- exit (EXIT_FAILURE);
+ usage(stderr, argc, argv);
+ exit(EXIT_FAILURE);
}
}
- open_device ();
-
- init_device ();
-
- start_capturing ();
-
- mainloop ();
-
- stop_capturing ();
-
- uninit_device ();
-
- close_device ();
-
- exit (EXIT_SUCCESS);
-
+ open_device();
+ init_device();
+ start_capturing();
+ mainloop();
+ stop_capturing();
+ uninit_device();
+ close_device();
+ fprintf(stderr, "\n");
return 0;
}
diff --git a/v4l2-apps/util/Makefile b/v4l2-apps/util/Makefile
index 873553a95..41d4712e1 100644
--- a/v4l2-apps/util/Makefile
+++ b/v4l2-apps/util/Makefile
@@ -22,6 +22,8 @@ clean::
-if [ -f qv4l2/Makefile ]; then make -C qv4l2 $@; fi
-rm -f qv4l2/qv4l2 qv4l2/Makefile
make -C xc3028-firmware $@
+ rm -f v4l2-driverids.cpp v4l2-chipids.cpp
+ rm -rf keycodes parse.h keytable
qv4l2:
if [ ! -f qv4l2/Makefile ]; then (cd qv4l2; qmake); fi
@@ -41,7 +43,7 @@ parse.h: $(KERNEL_DIR)/include/linux/input.h
@echo -en "struct parse_key {\n\tchar *name;\n\tunsigned int value;\n} " >parse.h
@echo -en "keynames[] = {\n" >>parse.h
- @more $(KERNEL_DIR)/linux/input.h |perl -n \
+ @more $(KERNEL_DIR)/include/linux/input.h |perl -n \
-e 'if (m/^\#define\s+(KEY_[^\s]+)\s+(0x[\d\w]+|[\d]+)/) ' \
-e '{ printf "\t{\"%s\", %s},\n",$$1,$$2; }' \
-e 'if (m/^\#define\s+(BTN_[^\s]+)\s+(0x[\d\w]+|[\d]+)/) ' \
@@ -50,7 +52,7 @@ parse.h: $(KERNEL_DIR)/include/linux/input.h
@echo -en "\t{ NULL, 0}\n};\n" >>parse.h
keytables:
- -mkdir keycodes
+ -mkdir -p keycodes
./gen_keytables.pl ../../linux/drivers/media/common/ir-keymaps.c
keytable: keytable.c parse.h keytables
diff --git a/v4l2-apps/util/cx18-ctl.c b/v4l2-apps/util/cx18-ctl.c
index 755b9437f..4081f3aef 100644
--- a/v4l2-apps/util/cx18-ctl.c
+++ b/v4l2-apps/util/cx18-ctl.c
@@ -267,7 +267,7 @@ int main(int argc, char **argv)
/* bitfield for OptSetCodec */
/* command args */
- char *device = strdup("/dev/video0"); /* -d device */
+ const char *device = "/dev/video0"; /* -d device */
int ch;
int yuv_mode = 0;
struct v4l2_routing route; /* audio_route */
@@ -312,11 +312,13 @@ int main(int argc, char **argv)
break;
}
case OptSetDevice:
- device = strdup(optarg);
+ device = optarg;
if (device[0] >= '0' && device[0] <= '9' && device[1] == 0) {
+ static char newdev[20];
char dev = device[0];
- sprintf(device, "/dev/video%c", dev);
+ sprintf(newdev, "/dev/video%c", dev);
+ device = newdev;
}
break;
case OptSetAudioRoute:
@@ -410,7 +412,6 @@ int main(int argc, char **argv)
strerror(errno));
exit(1);
}
- free(device);
/* Setting Opts */
diff --git a/v4l2-apps/util/em28xx-dbg.h b/v4l2-apps/util/em28xx-dbg.h
index d2edc60bc..3d3600c44 100644
--- a/v4l2-apps/util/em28xx-dbg.h
+++ b/v4l2-apps/util/em28xx-dbg.h
@@ -81,4 +81,4 @@ static struct board_regs em28xx_regs[] = {
{0x02, EM28XX_PREFIX "MASTER_AC97", 1},
{0x10, EM28XX_PREFIX "LINE_IN_AC97", 1},
{0x14, EM28XX_PREFIX "VIDEO_AC97", 1},
-}; \ No newline at end of file
+};
diff --git a/v4l2-apps/util/ivtv-ctl.c b/v4l2-apps/util/ivtv-ctl.c
index 9d3170785..ab836e240 100644
--- a/v4l2-apps/util/ivtv-ctl.c
+++ b/v4l2-apps/util/ivtv-ctl.c
@@ -343,7 +343,7 @@ int main(int argc, char **argv)
/* bitfield for OptSetCodec */
/* command args */
- char *device = strdup("/dev/video0"); /* -d device */
+ const char *device = "/dev/video0"; /* -d device */
int ch;
int yuv_mode = 0;
struct v4l2_routing route; /* audio_route */
@@ -415,11 +415,13 @@ int main(int argc, char **argv)
break;
}
case OptSetDevice:
- device = strdup(optarg);
+ device = optarg;
if (device[0] >= '0' && device[0] <= '9' && device[1] == 0) {
+ static char newdev[20];
char dev = device[0];
- sprintf(device, "/dev/video%c", dev);
+ sprintf(newdev, "/dev/video%c", dev);
+ device = newdev;
}
break;
case OptSetAudioRoute:
@@ -524,7 +526,6 @@ int main(int argc, char **argv)
strerror(errno));
exit(1);
}
- free(device);
/* Setting Opts */
diff --git a/v4l2-apps/util/qv4l2/general-tab.cpp b/v4l2-apps/util/qv4l2/general-tab.cpp
index d7f5a98d2..3b9ad2e5b 100644
--- a/v4l2-apps/util/qv4l2/general-tab.cpp
+++ b/v4l2-apps/util/qv4l2/general-tab.cpp
@@ -42,23 +42,23 @@ GeneralTab::GeneralTab(const char *device, int _fd, int n, QWidget *parent) :
memset(&querycap, 0, sizeof(querycap));
if (ioctl(fd, VIDIOC_QUERYCAP, &querycap) >=0) {
QLabel *l1 = new QLabel("Device:", this);
- QLabel *l1t = new QLabel(device, this);
+ new QLabel(device, this);
l1->setAlignment(Qt::AlignRight);
QLabel *l2 = new QLabel("Driver:", this);
l2->setAlignment(Qt::AlignRight);
- QLabel *l2t = new QLabel((char *)querycap.driver, this);
+ new QLabel((char *)querycap.driver, this);
QLabel *l3 = new QLabel("Card:", this);
l3->setAlignment(Qt::AlignRight);
- QLabel *l3t = new QLabel((char *)querycap.card, this);
+ new QLabel((char *)querycap.card, this);
QLabel *l4 = new QLabel("Bus:", this);
l4->setAlignment(Qt::AlignRight);
- QLabel *l4t = new QLabel((char *)querycap.bus_info, this);
+ new QLabel((char *)querycap.bus_info, this);
}
memset(&tuner, 0, sizeof(tuner));
diff --git a/v4l2-apps/util/v4l-board-dbg.h b/v4l2-apps/util/v4l-board-dbg.h
index 5d040812d..d7e7a9ef3 100644
--- a/v4l2-apps/util/v4l-board-dbg.h
+++ b/v4l2-apps/util/v4l-board-dbg.h
@@ -21,4 +21,4 @@ struct board_regs {
char *name;
int size;
};
-#endif \ No newline at end of file
+#endif
diff --git a/v4l2-apps/util/v4l2-ctl.cpp b/v4l2-apps/util/v4l2-ctl.cpp
index 57d98fc13..ae9293414 100644
--- a/v4l2-apps/util/v4l2-ctl.cpp
+++ b/v4l2-apps/util/v4l2-ctl.cpp
@@ -160,6 +160,7 @@ static const flag_def service_def[] = {
#define FmtHeight (1L<<1)
#define FmtChromaKey (1L<<2)
#define FmtGlobalAlpha (1L<<3)
+#define FmtPixelFormat (1L<<4)
/* crop specified */
#define CropWidth (1L<<0)
@@ -236,126 +237,128 @@ static struct option long_options[] = {
static void usage(void)
{
printf("Usage:\n");
- printf("Common options:\n");
- printf(" --all display all information available\n");
- printf(" -B, --get-fmt-sliced-vbi\n");
- printf(" query the sliced VBI capture format [VIDIOC_G_FMT]\n");
- printf(" -b, --set-fmt-sliced-vbi=<mode>\n");
- printf(" set the sliced VBI capture format to <mode> [VIDIOC_S_FMT]\n");
- printf(" <mode> is a comma separated list of:\n");
- printf(" off: turn off sliced VBI (cannot be combined with other modes)\n");
- printf(" teletext: teletext (PAL/SECAM)\n");
- printf(" cc: closed caption (NTSC)\n");
- printf(" wss: widescreen signal (PAL/SECAM)\n");
- printf(" vps: VPS (PAL/SECAM)\n");
- printf(" -C, --get-ctrl=<ctrl>[,<ctrl>...]\n");
- printf(" get the value of the controls [VIDIOC_G_EXT_CTRLS]\n");
- printf(" -c, --set-ctrl=<ctrl>=<val>[,<ctrl>=<val>...]\n");
- printf(" set the controls to the values specified [VIDIOC_S_EXT_CTRLS]\n");
- printf(" -D, --info show driver info [VIDIOC_QUERYCAP]\n");
- printf(" -d, --device=<dev> use device <dev> instead of /dev/video0\n");
- printf(" if <dev> is a single digit, then /dev/video<dev> is used\n");
- printf(" -F, --get-freq query the frequency [VIDIOC_G_FREQUENCY]\n");
- printf(" -f, --set-freq=<freq>\n");
- printf(" set the frequency to <freq> MHz [VIDIOC_S_FREQUENCY]\n");
- printf(" -h, --help display this help message\n");
- printf(" -I, --get-input query the video input [VIDIOC_G_INPUT]\n");
- printf(" -i, --set-input=<num>\n");
- printf(" set the video input to <num> [VIDIOC_S_INPUT]\n");
- printf(" -l, --list-ctrls display all controls and their values [VIDIOC_QUERYCTRL]\n");
- printf(" -L, --list-ctrls-menus\n");
- printf(" display all controls, their values and the menus [VIDIOC_QUERYMENU]\n");
- printf(" -N, --list-outputs display video outputs [VIDIOC_ENUMOUTPUT]\n");
- printf(" -n, --list-inputs display video inputs [VIDIOC_ENUMINPUT]\n");
- printf(" -O, --get-output query the video output [VIDIOC_G_OUTPUT]\n");
- printf(" -o, --set-output=<num>\n");
- printf(" set the video output to <num> [VIDIOC_S_OUTPUT]\n");
- printf(" -S, --get-standard\n");
- printf(" query the video standard [VIDIOC_G_STD]\n");
- printf(" -s, --set-standard=<num>\n");
- printf(" set the video standard to <num> [VIDIOC_S_STD]\n");
- printf(" <num> can be a numerical v4l2_std value, or it can be one of:\n");
- printf(" pal-X (X = B/G/H/N/Nc/I/D/K/M/60) or just 'pal' (V4L2_STD_PAL)\n");
- printf(" ntsc-X (X = M/J/K) or just 'ntsc' (V4L2_STD_NTSC)\n");
- printf(" secam-X (X = B/G/H/D/K/L/Lc) or just 'secam' (V4L2_STD_SECAM)\n");
- printf(" --list-standards display supported video standards [VIDIOC_ENUMSTD]\n");
- printf(" -T, --get-tuner query the tuner settings [VIDIOC_G_TUNER]\n");
- printf(" -t, --set-tuner=<mode>\n");
- printf(" set the audio mode of the tuner [VIDIOC_S_TUNER]\n");
- printf(" Possible values: mono, stereo, lang2, lang1, bilingual\n");
- printf(" --list-formats display supported video formats [VIDIOC_ENUM_FMT]\n");
- printf(" -V, --get-fmt-video\n");
- printf(" query the video capture format [VIDIOC_G_FMT]\n");
- printf(" -v, --set-fmt-video=width=<w>,height=<h>\n");
- printf(" set the video capture format [VIDIOC_S_FMT]\n");
- printf(" --verbose turn on verbose ioctl error reporting.\n");
- printf("\n");
- printf("Uncommon options:\n");
- printf(" --get-fmt-video-out\n");
- printf(" query the video output format [VIDIOC_G_FMT]\n");
- printf(" --set-fmt-video-out=width=<w>,height=<h>\n");
- printf(" set the video output format [VIDIOC_S_FMT]\n");
- printf(" --get-fmt-overlay\n");
- printf(" query the video overlay format [VIDIOC_G_FMT]\n");
- printf(" --get-fmt-output-overlay\n");
- printf(" query the video output overlay format [VIDIOC_G_FMT]\n");
- printf(" --set-fmt-output-overlay=chromakey=<key>,global_alpha=<alpha>\n");
- printf(" set the video output overlay format [VIDIOC_S_FMT]\n");
- printf(" --get-sliced-vbi-cap\n");
- printf(" query the sliced VBI capture capabilities [VIDIOC_G_SLICED_VBI_CAP]\n");
- printf(" --get-sliced-vbi-out-cap\n");
- printf(" query the sliced VBI output capabilities [VIDIOC_G_SLICED_VBI_CAP]\n");
- printf(" --get-fmt-sliced-vbi-out\n");
- printf(" query the sliced VBI output format [VIDIOC_G_FMT]\n");
- printf(" --set-fmt-sliced-vbi-out=<mode>\n");
- printf(" set the sliced VBI output format to <mode> [VIDIOC_S_FMT]\n");
- printf(" <mode> is a comma separated list of:\n");
- printf(" off: turn off sliced VBI (cannot be combined with other modes)\n");
- printf(" teletext: teletext (PAL/SECAM)\n");
- printf(" cc: closed caption (NTSC)\n");
- printf(" wss: widescreen signal (PAL/SECAM)\n");
- printf(" vps: VPS (PAL/SECAM)\n");
- printf(" --get-fmt-vbi query the VBI capture format [VIDIOC_G_FMT]\n");
- printf(" --get-fmt-vbi-out query the VBI output format [VIDIOC_G_FMT]\n");
- printf(" --overlay=<on> turn overlay on (1) or off (0) (VIDIOC_OVERLAY)\n");
- printf(" --get-fbuf query the overlay framebuffer data [VIDIOC_G_FBUF]\n");
- printf(" --set-fbuf=chromakey=<0/1>,global_alpha=<0/1>,local_alpha=<0/1>,local_inv_alpha=<0/1>\n");
- printf(" set the overlay framebuffer [VIDIOC_S_FBUF]\n");
- printf(" --get-cropcap query the crop capabilities [VIDIOC_CROPCAP]\n");
- printf(" --get-crop query the video capture crop window [VIDIOC_G_CROP]\n");
- printf(" --set-crop=top=<x>,left=<y>,width=<w>,height=<h>\n");
- printf(" set the video capture crop window [VIDIOC_S_CROP]\n");
- printf(" --get-cropcap-output\n");
- printf(" query the crop capabilities for video output [VIDIOC_CROPCAP]\n");
- printf(" --get-crop-output query the video output crop window [VIDIOC_G_CROP]\n");
- printf(" --set-crop-output=top=<x>,left=<y>,width=<w>,height=<h>\n");
- printf(" set the video output crop window [VIDIOC_S_CROP]\n");
- printf(" --get-cropcap-overlay\n");
- printf(" query the crop capabilities for video overlay [VIDIOC_CROPCAP]\n");
- printf(" --get-crop-overlay query the video overlay crop window [VIDIOC_G_CROP]\n");
- printf(" --set-crop-overlay=top=<x>,left=<y>,width=<w>,height=<h>\n");
- printf(" set the video overlay crop window [VIDIOC_S_CROP]\n");
- printf(" --get-cropcap-output-overlay\n");
- printf(" query the crop capabilities for video output overlays [VIDIOC_CROPCAP]\n");
- printf(" --get-crop-output-overlay\n");
- printf(" query the video output overlay crop window [VIDIOC_G_CROP]\n");
- printf(" --set-crop-output-overlay=top=<x>,left=<y>,width=<w>,height=<h>\n");
- printf(" set the video output overlay crop window [VIDIOC_S_CROP]\n");
- printf(" --get-audio-input query the audio input [VIDIOC_G_AUDIO]\n");
- printf(" --set-audio-input=<num>\n");
- printf(" set the audio input to <num> [VIDIOC_S_AUDIO]\n");
- printf(" --get-audio-output query the audio output [VIDIOC_G_AUDOUT]\n");
- printf(" --set-audio-output=<num>\n");
- printf(" set the audio output to <num> [VIDIOC_S_AUDOUT]\n");
- printf(" --list-audio-outputs\n");
- printf(" display audio outputs [VIDIOC_ENUMAUDOUT]\n");
- printf(" --list-audio-inputs\n");
- printf(" display audio inputs [VIDIOC_ENUMAUDIO]\n");
- printf("\n");
- printf("Expert options:\n");
- printf(" --streamoff turn the stream off [VIDIOC_STREAMOFF]\n");
- printf(" --streamon turn the stream on [VIDIOC_STREAMOFF]\n");
- printf(" --log-status log the board status in the kernel log [VIDIOC_LOG_STATUS]\n");
+ printf("Common options:\n"
+ " --all display all information available\n"
+ " -B, --get-fmt-sliced-vbi\n"
+ " query the sliced VBI capture format [VIDIOC_G_FMT]\n"
+ " -b, --set-fmt-sliced-vbi=<mode>\n"
+ " set the sliced VBI capture format to <mode> [VIDIOC_S_FMT]\n"
+ " <mode> is a comma separated list of:\n"
+ " off: turn off sliced VBI (cannot be combined with other modes)\n"
+ " teletext: teletext (PAL/SECAM)\n"
+ " cc: closed caption (NTSC)\n"
+ " wss: widescreen signal (PAL/SECAM)\n"
+ " vps: VPS (PAL/SECAM)\n"
+ " -C, --get-ctrl=<ctrl>[,<ctrl>...]\n"
+ " get the value of the controls [VIDIOC_G_EXT_CTRLS]\n"
+ " -c, --set-ctrl=<ctrl>=<val>[,<ctrl>=<val>...]\n"
+ " set the controls to the values specified [VIDIOC_S_EXT_CTRLS]\n"
+ " -D, --info show driver info [VIDIOC_QUERYCAP]\n"
+ " -d, --device=<dev> use device <dev> instead of /dev/video0\n"
+ " if <dev> is a single digit, then /dev/video<dev> is used\n"
+ " -F, --get-freq query the frequency [VIDIOC_G_FREQUENCY]\n"
+ " -f, --set-freq=<freq>\n"
+ " set the frequency to <freq> MHz [VIDIOC_S_FREQUENCY]\n"
+ " -h, --help display this help message\n"
+ " -I, --get-input query the video input [VIDIOC_G_INPUT]\n"
+ " -i, --set-input=<num>\n"
+ " set the video input to <num> [VIDIOC_S_INPUT]\n"
+ " -l, --list-ctrls display all controls and their values [VIDIOC_QUERYCTRL]\n"
+ " -L, --list-ctrls-menus\n"
+ " display all controls, their values and the menus [VIDIOC_QUERYMENU]\n"
+ " -N, --list-outputs display video outputs [VIDIOC_ENUMOUTPUT]\n"
+ " -n, --list-inputs display video inputs [VIDIOC_ENUMINPUT]\n"
+ " -O, --get-output query the video output [VIDIOC_G_OUTPUT]\n"
+ " -o, --set-output=<num>\n"
+ " set the video output to <num> [VIDIOC_S_OUTPUT]\n"
+ " -S, --get-standard\n"
+ " query the video standard [VIDIOC_G_STD]\n"
+ " -s, --set-standard=<num>\n"
+ " set the video standard to <num> [VIDIOC_S_STD]\n"
+ " <num> can be a numerical v4l2_std value, or it can be one of:\n"
+ " pal-X (X = B/G/H/N/Nc/I/D/K/M/60) or just 'pal' (V4L2_STD_PAL)\n"
+ " ntsc-X (X = M/J/K) or just 'ntsc' (V4L2_STD_NTSC)\n"
+ " secam-X (X = B/G/H/D/K/L/Lc) or just 'secam' (V4L2_STD_SECAM)\n"
+ " --list-standards display supported video standards [VIDIOC_ENUMSTD]\n"
+ " -T, --get-tuner query the tuner settings [VIDIOC_G_TUNER]\n"
+ " -t, --set-tuner=<mode>\n"
+ " set the audio mode of the tuner [VIDIOC_S_TUNER]\n"
+ " Possible values: mono, stereo, lang2, lang1, bilingual\n"
+ " --list-formats display supported video formats [VIDIOC_ENUM_FMT]\n"
+ " -V, --get-fmt-video\n"
+ " query the video capture format [VIDIOC_G_FMT]\n"
+ " -v, --set-fmt-video=width=<w>,height=<h>,pixelformat=<f>\n"
+ " set the video capture format [VIDIOC_S_FMT]\n"
+ " pixelformat is either the format index as reported by\n"
+ " --list-formats, or the fourcc value as a string\n"
+ " --verbose turn on verbose ioctl error reporting.\n"
+ "\n");
+ printf("Uncommon options:\n"
+ " --get-fmt-video-out\n"
+ " query the video output format [VIDIOC_G_FMT]\n"
+ " --set-fmt-video-out=width=<w>,height=<h>\n"
+ " set the video output format [VIDIOC_S_FMT]\n"
+ " --get-fmt-overlay\n"
+ " query the video overlay format [VIDIOC_G_FMT]\n"
+ " --get-fmt-output-overlay\n"
+ " query the video output overlay format [VIDIOC_G_FMT]\n"
+ " --set-fmt-output-overlay=chromakey=<key>,global_alpha=<alpha>\n"
+ " set the video output overlay format [VIDIOC_S_FMT]\n"
+ " --get-sliced-vbi-cap\n"
+ " query the sliced VBI capture capabilities [VIDIOC_G_SLICED_VBI_CAP]\n"
+ " --get-sliced-vbi-out-cap\n"
+ " query the sliced VBI output capabilities [VIDIOC_G_SLICED_VBI_CAP]\n"
+ " --get-fmt-sliced-vbi-out\n"
+ " query the sliced VBI output format [VIDIOC_G_FMT]\n"
+ " --set-fmt-sliced-vbi-out=<mode>\n"
+ " set the sliced VBI output format to <mode> [VIDIOC_S_FMT]\n"
+ " <mode> is a comma separated list of:\n"
+ " off: turn off sliced VBI (cannot be combined with other modes)\n"
+ " teletext: teletext (PAL/SECAM)\n"
+ " cc: closed caption (NTSC)\n"
+ " wss: widescreen signal (PAL/SECAM)\n"
+ " vps: VPS (PAL/SECAM)\n"
+ " --get-fmt-vbi query the VBI capture format [VIDIOC_G_FMT]\n"
+ " --get-fmt-vbi-out query the VBI output format [VIDIOC_G_FMT]\n"
+ " --overlay=<on> turn overlay on (1) or off (0) (VIDIOC_OVERLAY)\n"
+ " --get-fbuf query the overlay framebuffer data [VIDIOC_G_FBUF]\n"
+ " --set-fbuf=chromakey=<0/1>,global_alpha=<0/1>,local_alpha=<0/1>,local_inv_alpha=<0/1>\n"
+ " set the overlay framebuffer [VIDIOC_S_FBUF]\n"
+ " --get-cropcap query the crop capabilities [VIDIOC_CROPCAP]\n"
+ " --get-crop query the video capture crop window [VIDIOC_G_CROP]\n"
+ " --set-crop=top=<x>,left=<y>,width=<w>,height=<h>\n"
+ " set the video capture crop window [VIDIOC_S_CROP]\n"
+ " --get-cropcap-output\n"
+ " query the crop capabilities for video output [VIDIOC_CROPCAP]\n"
+ " --get-crop-output query the video output crop window [VIDIOC_G_CROP]\n"
+ " --set-crop-output=top=<x>,left=<y>,width=<w>,height=<h>\n"
+ " set the video output crop window [VIDIOC_S_CROP]\n"
+ " --get-cropcap-overlay\n"
+ " query the crop capabilities for video overlay [VIDIOC_CROPCAP]\n"
+ " --get-crop-overlay query the video overlay crop window [VIDIOC_G_CROP]\n"
+ " --set-crop-overlay=top=<x>,left=<y>,width=<w>,height=<h>\n"
+ " set the video overlay crop window [VIDIOC_S_CROP]\n"
+ " --get-cropcap-output-overlay\n"
+ " query the crop capabilities for video output overlays [VIDIOC_CROPCAP]\n"
+ " --get-crop-output-overlay\n"
+ " query the video output overlay crop window [VIDIOC_G_CROP]\n"
+ " --set-crop-output-overlay=top=<x>,left=<y>,width=<w>,height=<h>\n"
+ " set the video output overlay crop window [VIDIOC_S_CROP]\n"
+ " --get-audio-input query the audio input [VIDIOC_G_AUDIO]\n"
+ " --set-audio-input=<num>\n"
+ " set the audio input to <num> [VIDIOC_S_AUDIO]\n"
+ " --get-audio-output query the audio output [VIDIOC_G_AUDOUT]\n"
+ " --set-audio-output=<num>\n"
+ " set the audio output to <num> [VIDIOC_S_AUDOUT]\n"
+ " --list-audio-outputs\n"
+ " display audio outputs [VIDIOC_ENUMAUDOUT]\n"
+ " --list-audio-inputs\n"
+ " display audio inputs [VIDIOC_ENUMAUDIO]\n"
+ "\n");
+ printf("Expert options:\n"
+ " --streamoff turn the stream off [VIDIOC_STREAMOFF]\n"
+ " --streamon turn the stream on [VIDIOC_STREAMOFF]\n"
+ " --log-status log the board status in the kernel log [VIDIOC_LOG_STATUS]\n");
exit(0);
}
@@ -634,13 +637,17 @@ static void find_controls(int fd)
for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) {
qctrl.id = id;
if (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0 &&
- !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED))
+ !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) {
ctrl_str2id[name2var(qctrl.name)] = qctrl.id;
+ ctrl_id2str[qctrl.id] = name2var(qctrl.name);
+ }
}
for (qctrl.id = V4L2_CID_PRIVATE_BASE;
ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) {
- if (!(qctrl.flags & V4L2_CTRL_FLAG_DISABLED))
+ if (!(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) {
ctrl_str2id[name2var(qctrl.name)] = qctrl.id;
+ ctrl_id2str[qctrl.id] = name2var(qctrl.name);
+ }
}
}
@@ -697,7 +704,7 @@ static void printfbuf(const struct v4l2_framebuffer &fb)
printf("\tBase : 0x%p\n", fb.base);
printf("\tWidth : %d\n", fb.fmt.width);
printf("\tHeight : %d\n", fb.fmt.height);
- printf("\tPixel Format : %s\n", fcc2s(fb.fmt.pixelformat).c_str());
+ printf("\tPixel Format : '%s'\n", fcc2s(fb.fmt.pixelformat).c_str());
if (!is_ext) {
printf("\tBytes per Line: %d\n", fb.fmt.bytesperline);
printf("\tSize image : %d\n", fb.fmt.sizeimage);
@@ -736,7 +743,7 @@ static void printfmt(struct v4l2_format vfmt)
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
printf("\tWidth/Height : %u/%u\n", vfmt.fmt.pix.width, vfmt.fmt.pix.height);
- printf("\tPixel Format : %s\n", fcc2s(vfmt.fmt.pix.pixelformat).c_str());
+ printf("\tPixel Format : '%s'\n", fcc2s(vfmt.fmt.pix.pixelformat).c_str());
printf("\tField : %s\n", field2s(vfmt.fmt.pix.field).c_str());
printf("\tBytes per Line: %u\n", vfmt.fmt.pix.bytesperline);
printf("\tSize Image : %u\n", vfmt.fmt.pix.sizeimage);
@@ -794,8 +801,9 @@ static void print_video_formats(int fd, enum v4l2_buf_type type)
fmt.index = 0;
fmt.type = type;
while (ioctl(fd, VIDIOC_ENUM_FMT, &fmt) >= 0) {
+ printf("\tIndex : %d\n", fmt.index);
printf("\tType : %s\n", buftype2s(type).c_str());
- printf("\tPixelformat : %s", fcc2s(fmt.pixelformat).c_str());
+ printf("\tPixel Format: '%s'", fcc2s(fmt.pixelformat).c_str());
if (fmt.flags)
printf(" (compressed)");
printf("\n");
@@ -1019,9 +1027,9 @@ static int doioctl(int fd, int request, void *parm, const char *name)
return retVal;
}
-static int parse_subopt(char **subs, char * const *subopts, char **value)
+static int parse_subopt(char **subs, const char * const *subopts, char **value)
{
- int opt = getsubopt(subs, subopts, value);
+ int opt = getsubopt(subs, (char * const *)subopts, value);
if (opt == -1) {
fprintf(stderr, "Invalid suboptions specified\n");
@@ -1094,7 +1102,7 @@ static void parse_crop(char *optarg, unsigned int &set_crop, v4l2_rect &vcrop)
char *subs = optarg;
while (*subs != '\0') {
- static char *const subopts[] = {
+ static const char *const subopts[] = {
"left",
"top",
"width",
@@ -1144,7 +1152,7 @@ int main(int argc, char **argv)
/* command args */
int ch;
- char *device = strdup("/dev/video0"); /* -d device */
+ const char *device = "/dev/video0"; /* -d device */
struct v4l2_format vfmt; /* set_format/get_format for video */
struct v4l2_format vfmt_out; /* set_format/get_format video output */
struct v4l2_format vbi_fmt; /* set_format/get_format for sliced VBI */
@@ -1220,19 +1228,22 @@ int main(int argc, char **argv)
usage();
return 0;
case OptSetDevice:
- device = strdup(optarg);
+ device = optarg;
if (device[0] >= '0' && device[0] <= '9' && device[1] == 0) {
+ static char newdev[20];
char dev = device[0];
- sprintf(device, "/dev/video%c", dev);
+ sprintf(newdev, "/dev/video%c", dev);
+ device = newdev;
}
break;
case OptSetVideoFormat:
subs = optarg;
while (*subs != '\0') {
- static char *const subopts[] = {
+ static const char *const subopts[] = {
"width",
"height",
+ "pixelformat",
NULL
};
@@ -1245,13 +1256,22 @@ int main(int argc, char **argv)
vfmt.fmt.pix.height = strtol(value, 0L, 0);
set_fmts |= FmtHeight;
break;
+ case 2:
+ if (strlen(value) == 4)
+ vfmt.fmt.pix.pixelformat =
+ v4l2_fourcc(value[0], value[1],
+ value[2], value[3]);
+ else
+ vfmt.fmt.pix.pixelformat = strtol(value, 0L, 0);
+ set_fmts |= FmtPixelFormat;
+ break;
}
}
break;
case OptSetVideoOutFormat:
subs = optarg;
while (*subs != '\0') {
- static char *const subopts[] = {
+ static const char *const subopts[] = {
"width",
"height",
NULL
@@ -1272,7 +1292,7 @@ int main(int argc, char **argv)
case OptSetOutputOverlayFormat:
subs = optarg;
while (*subs != '\0') {
- static char *const subopts[] = {
+ static const char *const subopts[] = {
"chromakey",
"global_alpha",
NULL
@@ -1293,7 +1313,7 @@ int main(int argc, char **argv)
case OptSetFBuf:
subs = optarg;
while (*subs != '\0') {
- static char *const subopts[] = {
+ static const char *const subopts[] = {
"chromakey",
"global_alpha",
"local_alpha",
@@ -1428,7 +1448,7 @@ int main(int argc, char **argv)
fmt->fmt.sliced.service_set = 0;
subs = optarg;
while (*subs != '\0') {
- static char *const subopts[] = {
+ static const char *const subopts[] = {
"off",
"teletext",
"cc",
@@ -1492,7 +1512,6 @@ int main(int argc, char **argv)
strerror(errno));
exit(1);
}
- free(device);
doioctl(fd, VIDIOC_QUERYCAP, &vcap, "VIDIOC_QUERYCAP");
capabilities = vcap.capabilities;
@@ -1622,9 +1641,22 @@ int main(int argc, char **argv)
in_vfmt.fmt.pix.width = vfmt.fmt.pix.width;
if (set_fmts & FmtHeight)
in_vfmt.fmt.pix.height = vfmt.fmt.pix.height;
+ if (set_fmts & FmtPixelFormat) {
+ in_vfmt.fmt.pix.pixelformat = vfmt.fmt.pix.pixelformat;
+ if (in_vfmt.fmt.pix.pixelformat < 256) {
+ struct v4l2_fmtdesc fmt;
+
+ fmt.index = in_vfmt.fmt.pix.pixelformat;
+ fmt.type = in_vfmt.type;
+ if (doioctl(fd, VIDIOC_ENUM_FMT, &fmt, "VIDIOC_ENUM_FMT"))
+ goto set_vid_fmt_error;
+ in_vfmt.fmt.pix.pixelformat = fmt.pixelformat;
+ }
+ }
doioctl(fd, VIDIOC_S_FMT, &in_vfmt, "VIDIOC_S_FMT");
}
}
+set_vid_fmt_error:
if (options[OptSetVideoOutFormat]) {
struct v4l2_format in_vfmt;
@@ -1992,6 +2024,7 @@ int main(int argc, char **argv)
memset(&vt, 0, sizeof(struct v4l2_tuner));
if (doioctl(fd, VIDIOC_G_TUNER, &vt, "VIDIOC_G_TUNER") == 0) {
printf("Tuner:\n");
+ printf("\tName : %s\n", vt.name);
printf("\tCapabilities : %s\n", tcap2s(vt.capability).c_str());
if (vt.capability & V4L2_TUNER_CAP_LOW)
printf("\tFrequency range : %.1f MHz - %.1f MHz\n",
@@ -1999,7 +2032,7 @@ int main(int argc, char **argv)
else
printf("\tFrequency range : %.1f MHz - %.1f MHz\n",
vt.rangelow / 16.0, vt.rangehigh / 16.0);
- printf("\tSignal strength : %d%%\n", (int)(vt.signal / 655.35));
+ printf("\tSignal strength/AFC : %d%%/%d\n", (int)(vt.signal / 655.35), vt.afc);
printf("\tCurrent audio mode : %s\n", audmode2s(vt.audmode));
printf("\tAvailable subchannels: %s\n",
rxsubchans2s(vt.rxsubchans).c_str());
@@ -2113,7 +2146,7 @@ int main(int argc, char **argv)
while (ioctl(fd, VIDIOC_ENUMSTD, &vs) >= 0) {
if (vs.index)
printf("\n");
- printf("\tindex : %d\n", vs.index);
+ printf("\tIndex : %d\n", vs.index);
printf("\tID : 0x%016llX\n", (unsigned long long)vs.id);
printf("\tName : %s\n", vs.name);
printf("\tFrame period: %d/%d\n",
diff --git a/v4l2-apps/util/v4l2-dbg.cpp b/v4l2-apps/util/v4l2-dbg.cpp
index 8323f2120..2561f42b2 100644
--- a/v4l2-apps/util/v4l2-dbg.cpp
+++ b/v4l2-apps/util/v4l2-dbg.cpp
@@ -245,9 +245,9 @@ static int doioctl(int fd, int request, void *parm, const char *name)
return retVal;
}
-static int parse_subopt(char **subs, char * const *subopts, char **value)
+static int parse_subopt(char **subs, const char * const *subopts, char **value)
{
- int opt = getsubopt(subs, subopts, value);
+ int opt = getsubopt(subs, (char * const *)subopts, value);
if (opt == -1) {
fprintf(stderr, "Invalid suboptions specified\n");
@@ -272,7 +272,7 @@ int main(int argc, char **argv)
/* command args */
int ch;
- char *device = strdup("/dev/video0"); /* -d device */
+ const char *device = "/dev/video0"; /* -d device */
struct v4l2_capability vcap; /* list_cap */
struct v4l2_register set_reg;
struct v4l2_register get_reg;
@@ -311,18 +311,20 @@ int main(int argc, char **argv)
usage();
return 0;
case OptSetDevice:
- device = strdup(optarg);
+ device = optarg;
if (device[0] >= '0' && device[0] <= '9' && device[1] == 0) {
+ static char newdev[20];
char dev = device[0];
- sprintf(device, "/dev/video%c", dev);
+ sprintf(newdev, "/dev/video%c", dev);
+ device = newdev;
}
break;
case OptSetRegister:
subs = optarg;
set_reg.match_type = V4L2_CHIP_MATCH_I2C_DRIVER;
while (*subs != '\0') {
- static char *const subopts[] = {
+ static const char * const subopts[] = {
"type",
"chip",
"reg",
@@ -352,7 +354,7 @@ int main(int argc, char **argv)
subs = optarg;
get_reg.match_type = V4L2_CHIP_MATCH_I2C_DRIVER;
while (*subs != '\0') {
- static char *const subopts[] = {
+ static const char * const subopts[] = {
"type",
"chip",
"min",
@@ -382,7 +384,7 @@ int main(int argc, char **argv)
subs = optarg;
set_reg.match_type = V4L2_CHIP_MATCH_I2C_DRIVER;
while (*subs != '\0') {
- static char *const subopts[] = {
+ static const char *const subopts[] = {
"type",
"chip",
NULL
@@ -424,7 +426,6 @@ int main(int argc, char **argv)
strerror(errno));
exit(1);
}
- free(device);
doioctl(fd, VIDIOC_QUERYCAP, &vcap, "VIDIOC_QUERYCAP");
capabilities = vcap.capabilities;
diff --git a/v4l2-apps/util/v4l_rec.pl b/v4l2-apps/util/v4l_rec.pl
index b533af097..941c03634 100755
--- a/v4l2-apps/util/v4l_rec.pl
+++ b/v4l2-apps/util/v4l_rec.pl
@@ -16,7 +16,7 @@ $std=shift or $std='PAL-M';
$dev=shift or $dev="/dev/video1";
##############################################
-# Those stuff bellow are currently "hardcoded"
+# Those stuff below are currently "hardcoded"
my $acard=0;
my $rec_ctrl="Aux,0";
@@ -25,7 +25,7 @@ my $vbitrate=1500;
my $abitrate=224;
##############################################
-# Those stuff bellow are NTSC / PAL-M specific
+# Those stuff below are NTSC / PAL-M specific
my $list="/usr/share/xawtv/ntsc-cable.list";
my $fps=30000/1001;