summaryrefslogtreecommitdiff
path: root/v4l2-apps/lib/libv4l
diff options
context:
space:
mode:
Diffstat (limited to 'v4l2-apps/lib/libv4l')
-rw-r--r--v4l2-apps/lib/libv4l/ChangeLog58
-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/include/libv4l1.h22
-rw-r--r--v4l2-apps/lib/libv4l/include/libv4l2.h28
-rw-r--r--v4l2-apps/lib/libv4l/include/libv4lconvert.h23
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/Makefile51
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/libv4l1-priv.h2
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/libv4l1.c17
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/log.c9
-rw-r--r--v4l2-apps/lib/libv4l/libv4l1/v4l1compat.c30
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/Makefile51
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h16
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/libv4l2.c422
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/log.c16
-rw-r--r--v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c33
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/Makefile44
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/bayer.c30
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/flip.c107
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/jidctflt.c4
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h48
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c272
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/pac207.c4
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c66
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/sn9c10x.c4
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/spca501.c75
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/spca561-decompress.c3
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.c348
-rw-r--r--v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.h1
33 files changed, 1409 insertions, 835 deletions
diff --git a/v4l2-apps/lib/libv4l/ChangeLog b/v4l2-apps/lib/libv4l/ChangeLog
index 286963543..eefe0028b 100644
--- a/v4l2-apps/lib/libv4l/ChangeLog
+++ b/v4l2-apps/lib/libv4l/ChangeLog
@@ -1,3 +1,61 @@
+libv4l-0.4.2
+------------
+* The bayer pixel order in gspca's sonixb driver was different from that in
+ the sn9c102 driver from the mainline kernel, a recent gspca patch fixes
+ this, adjust libv4l to match (and make it work properly with the sn9c102
+ driver).
+
+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
+* Fix errors and warnings when compiling with ICC (Gregor Jasny)
+* Add support to libv4lconvert for rotating images 90 (for Pixart 7302 cams)
+ or 180 (Philips SPC200NC / Philips SPC300NC) degrees
+* Add support for Pixart custom JPEG format
+* Hide non public symbols (Gregor Jasny)
+* Fix and enable x86_64 asm jpeg decompress helper functions (Gregor Jasny)
+
+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..92928271a 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.2
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/include/libv4l1.h b/v4l2-apps/lib/libv4l/include/libv4l1.h
index 9036ae869..c878cc198 100644
--- a/v4l2-apps/lib/libv4l/include/libv4l1.h
+++ b/v4l2-apps/lib/libv4l/include/libv4l1.h
@@ -26,9 +26,15 @@ extern "C" {
#include <stdio.h>
#include <unistd.h>
+#if __GNUC__ >= 4
+#define LIBV4L_PUBLIC __attribute__ ((visibility("default")))
+#else
+#define LIBV4L_PUBLIC
+#endif
+
/* Point this to a FILE opened for writing when you want to log error and
status messages to a file, when NULL errors will get send to stderr */
-extern FILE *v4l1_log_file;
+LIBV4L_PUBLIC extern FILE *v4l1_log_file;
/* Just like your regular open/close/etc, except that when opening a v4l2
capture only device, full v4l1 emulation is done including emulating the
@@ -51,14 +57,14 @@ extern FILE *v4l1_log_file;
capture formats, like hw specific bayer compression methods).
*/
-int v4l1_open (const char *file, int oflag, ...);
-int v4l1_close(int fd);
-int v4l1_dup(int fd);
-int v4l1_ioctl (int fd, unsigned long int request, ...);
-ssize_t v4l1_read (int fd, void* buffer, size_t n);
-void *v4l1_mmap(void *start, size_t length, int prot, int flags, int fd,
+LIBV4L_PUBLIC int v4l1_open (const char *file, int oflag, ...);
+LIBV4L_PUBLIC int v4l1_close(int fd);
+LIBV4L_PUBLIC int v4l1_dup(int fd);
+LIBV4L_PUBLIC int v4l1_ioctl (int fd, unsigned long int request, ...);
+LIBV4L_PUBLIC ssize_t v4l1_read (int fd, void* buffer, size_t n);
+LIBV4L_PUBLIC void *v4l1_mmap(void *start, size_t length, int prot, int flags, int fd,
__off64_t offset);
-int v4l1_munmap(void *_start, size_t length);
+LIBV4L_PUBLIC int v4l1_munmap(void *_start, size_t length);
#ifdef __cplusplus
}
diff --git a/v4l2-apps/lib/libv4l/include/libv4l2.h b/v4l2-apps/lib/libv4l/include/libv4l2.h
index 63529cf4b..b05b57cb6 100644
--- a/v4l2-apps/lib/libv4l/include/libv4l2.h
+++ b/v4l2-apps/lib/libv4l/include/libv4l2.h
@@ -26,9 +26,15 @@
extern "C" {
#endif /* __cplusplus */
+#if __GNUC__ >= 4
+#define LIBV4L_PUBLIC __attribute__ ((visibility("default")))
+#else
+#define LIBV4L_PUBLIC
+#endif
+
/* Point this to a FILE opened for writing when you want to log error and
status messages to a file, when NULL errors will get send to stderr */
-extern FILE *v4l2_log_file;
+LIBV4L_PUBLIC extern FILE *v4l2_log_file;
/* Just like your regular open/close/etc, except that format conversion is
done if necessary when capturing. That is if you (try to) set a capture
@@ -52,14 +58,14 @@ extern FILE *v4l2_log_file;
fail.
*/
-int v4l2_open (const char *file, int oflag, ...);
-int v4l2_close(int fd);
-int v4l2_dup(int fd);
-int v4l2_ioctl (int fd, unsigned long int request, ...);
-ssize_t v4l2_read (int fd, void* buffer, size_t n);
-void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd,
+LIBV4L_PUBLIC int v4l2_open (const char *file, int oflag, ...);
+LIBV4L_PUBLIC int v4l2_close(int fd);
+LIBV4L_PUBLIC int v4l2_dup(int fd);
+LIBV4L_PUBLIC int v4l2_ioctl (int fd, unsigned long int request, ...);
+LIBV4L_PUBLIC ssize_t v4l2_read (int fd, void* buffer, size_t n);
+LIBV4L_PUBLIC void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd,
__off64_t offset);
-int v4l2_munmap(void *_start, size_t length);
+LIBV4L_PUBLIC int v4l2_munmap(void *_start, size_t length);
/* Misc utility functions */
@@ -70,12 +76,12 @@ int v4l2_munmap(void *_start, size_t length);
Normally returns 0, even if the cid did not exist or was locked, returns
non 0 when an other error occured. */
-int v4l2_set_control(int fd, int cid, int value);
+LIBV4L_PUBLIC int v4l2_set_control(int fd, int cid, int value);
/* This function returns a value of 0 - 65535, scaled to from the actual range
of the given v4l control id. when the cid does not exist, could not be
accessed for some reason, or some error occured 0 is returned. */
-int v4l2_get_control(int fd, int cid);
+LIBV4L_PUBLIC int v4l2_get_control(int fd, int cid);
/* "low level" access functions, these functions allow somewhat lower level
@@ -95,7 +101,7 @@ int v4l2_get_control(int fd, int cid);
Returns fd on success, -1 if the fd is not suitable for use through libv4l2
(note the fd is left open in this case). */
-int v4l2_fd_open(int fd, int v4l2_flags);
+LIBV4L_PUBLIC int v4l2_fd_open(int fd, int v4l2_flags);
#ifdef __cplusplus
}
diff --git a/v4l2-apps/lib/libv4l/include/libv4lconvert.h b/v4l2-apps/lib/libv4l/include/libv4lconvert.h
index d8446dac8..87e41ceaa 100644
--- a/v4l2-apps/lib/libv4l/include/libv4lconvert.h
+++ b/v4l2-apps/lib/libv4l/include/libv4lconvert.h
@@ -31,34 +31,45 @@
extern "C" {
#endif /* __cplusplus */
+#if __GNUC__ >= 4
+#define LIBV4L_PUBLIC __attribute__ ((visibility("default")))
+#else
+#define LIBV4L_PUBLIC
+#endif
+
struct v4lconvert_data;
-struct v4lconvert_data *v4lconvert_create(int fd);
-void v4lconvert_destroy(struct v4lconvert_data *data);
+LIBV4L_PUBLIC struct v4lconvert_data *v4lconvert_create(int fd);
+LIBV4L_PUBLIC void v4lconvert_destroy(struct v4lconvert_data *data);
/* With regards to dest_fmt just like VIDIOC_TRY_FMT, except that the try
format will succeed and return the requested V4L2_PIX_FMT_foo in dest_fmt if
the cam has a format from which v4lconvert can convert to dest_fmt.
The real format to which the cam should be set is returned through src_fmt
when not NULL. */
-int v4lconvert_try_format(struct v4lconvert_data *data,
+LIBV4L_PUBLIC int v4lconvert_try_format(struct v4lconvert_data *data,
struct v4l2_format *dest_fmt, /* in / out */
struct v4l2_format *src_fmt /* out */
);
/* Just like VIDIOC_ENUM_FMT, except that the emulated formats are added at
the end of the list */
-int v4lconvert_enum_fmt(struct v4lconvert_data *data, struct v4l2_fmtdesc *fmt);
+LIBV4L_PUBLIC int v4lconvert_enum_fmt(struct v4lconvert_data *data, struct v4l2_fmtdesc *fmt);
+
+/* Is conversion necessary or can the app use the data directly? */
+LIBV4L_PUBLIC int v4lconvert_needs_conversion(struct v4lconvert_data *data,
+ const struct v4l2_format *src_fmt, /* in */
+ const struct v4l2_format *dest_fmt); /* in */
/* return value of -1 on error, otherwise the amount of bytes written to
dest */
-int v4lconvert_convert(struct v4lconvert_data *data,
+LIBV4L_PUBLIC int v4lconvert_convert(struct v4lconvert_data *data,
const struct v4l2_format *src_fmt, /* in */
const struct v4l2_format *dest_fmt, /* in */
unsigned char *src, int src_size, unsigned char *dest, int dest_size);
/* get a string describing the last error*/
-const char *v4lconvert_get_error_message(struct v4lconvert_data *data);
+LIBV4L_PUBLIC const char *v4lconvert_get_error_message(struct v4lconvert_data *data);
#ifdef __cplusplus
}
diff --git a/v4l2-apps/lib/libv4l/libv4l1/Makefile b/v4l2-apps/lib/libv4l/libv4l1/Makefile
index 8cb064cd4..27848477e 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
+override CPPFLAGS += -I../include -I../../../include -fvisibility=hidden
CFLAGS := -g -O1
-CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes
+CFLAGS += -Wall -Wno-unused -Wpointer-arith -Wstrict-prototypes -Wmissing-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)
+override 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..39f2d29e0 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
@@ -59,6 +59,7 @@
#include <linux/videodev.h>
#include <linux/videodev2.h>
#include <libv4l2.h>
+#include "libv4l1.h"
#include "libv4l1-priv.h"
#define V4L1_SUPPORTS_ENUMINPUT 0x01
@@ -279,7 +280,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
@@ -582,7 +583,7 @@ int v4l1_ioctl (int fd, unsigned long int request, ...)
input2.index = chan->channel;
result = v4l2_ioctl(fd, VIDIOC_ENUMINPUT, &input2);
if (result == 0) {
- snprintf(chan->name, sizeof(chan->name), "%s", input2.name);
+ snprintf(chan->name, sizeof(chan->name), "%s", (char*)input2.name);
if (input2.type == V4L2_INPUT_TYPE_TUNER) {
chan->tuners = 1;
chan->type = VIDEO_TYPE_TV;
diff --git a/v4l2-apps/lib/libv4l/libv4l1/log.c b/v4l2-apps/lib/libv4l/libv4l1/log.c
index 178c6d23c..74ce0f20b 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
@@ -25,6 +25,7 @@
#include <asm/types.h>
/* end broken header workaround includes */
#include <linux/videodev.h>
+#include "libv4l1-priv.h"
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
@@ -92,9 +93,9 @@ void v4l1_log_ioctl(unsigned long int request, void *arg, int result)
break;
case VIDIOCGWIN:
case VIDIOCSWIN:
- fprintf(v4l1_log_file,"width\t%d\n",
+ fprintf(v4l1_log_file,"width\t%u\n",
((struct video_window *)arg)->width);
- fprintf(v4l1_log_file,"height\t%d\n",
+ fprintf(v4l1_log_file,"height\t%u\n",
((struct video_window *)arg)->height);
break;
@@ -115,7 +116,7 @@ void v4l1_log_ioctl(unsigned long int request, void *arg, int result)
fprintf(v4l1_log_file,"palette %d\n",( (int)((struct video_picture*)arg)->palette) );
break;
- case VIDIOCCAPTURE: fprintf(v4l1_log_file,"on/of? %d\n", *((int *)arg) );
+ case VIDIOCCAPTURE: fprintf(v4l1_log_file,"on/off? %d\n", *((int *)arg) );
break;
case VIDIOCSYNC: fprintf(v4l1_log_file,"sync %d\n", *((int *)arg) );
diff --git a/v4l2-apps/lib/libv4l/libv4l1/v4l1compat.c b/v4l2-apps/lib/libv4l/libv4l1/v4l1compat.c
index db3a0027b..e4293d2f9 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
@@ -26,12 +26,21 @@
#include <fcntl.h>
#include <libv4l1.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+
/* Check that open/read/mmap is not a define */
#if defined open || defined read || defined mmap
#error open/read/mmap is a prepocessor macro !!
#endif
-int open (const char *file, int oflag, ...)
+#if __GNUC__ >= 4
+#define LIBV4L_PUBLIC __attribute__ ((visibility("default")))
+#else
+#define LIBV4L_PUBLIC
+#endif
+
+LIBV4L_PUBLIC int open (const char *file, int oflag, ...)
{
int fd;
@@ -52,7 +61,7 @@ int open (const char *file, int oflag, ...)
return fd;
}
-int open64 (const char *file, int oflag, ...)
+LIBV4L_PUBLIC int open64 (const char *file, int oflag, ...)
{
int fd;
@@ -73,16 +82,16 @@ int open64 (const char *file, int oflag, ...)
return fd;
}
-int close(int fd) {
+LIBV4L_PUBLIC int close(int fd) {
return v4l1_close(fd);
}
-int dup(int fd)
+LIBV4L_PUBLIC int dup(int fd)
{
return v4l1_dup(fd);
}
-int ioctl (int fd, unsigned long int request, ...)
+LIBV4L_PUBLIC int ioctl (int fd, unsigned long int request, ...)
{
void *arg;
va_list ap;
@@ -94,24 +103,25 @@ int ioctl (int fd, unsigned long int request, ...)
return v4l1_ioctl (fd, request, arg);
}
-ssize_t read(int fd, void* buffer, size_t n)
+LIBV4L_PUBLIC 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,
+LIBV4L_PUBLIC 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,
+LIBV4L_PUBLIC 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);
}
-int munmap(void *start, size_t length)
+LIBV4L_PUBLIC int munmap(void *start, size_t length)
{
return v4l1_munmap(start, length);
}
+
diff --git a/v4l2-apps/lib/libv4l/libv4l2/Makefile b/v4l2-apps/lib/libv4l/libv4l2/Makefile
index 1258e379b..648d27c0c 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
+override CPPFLAGS += -I../include -I../../../include -fvisibility=hidden
CFLAGS := -g -O1
-CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes
+CFLAGS += -Wall -Wno-unused -Wpointer-arith -Wstrict-prototypes -Wmissing-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)
+override 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..7029f69c3 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;
@@ -255,23 +252,54 @@ static int v4l2_queue_read_buffer(int index, int buffer_index)
return 0;
}
-static int v4l2_dequeue_read_buffer(int index, int *bytesused)
+static int v4l2_dequeue_and_convert(int index, struct v4l2_buffer *buf,
+ unsigned char *dest, int dest_size)
{
- int result;
- struct v4l2_buffer buf;
+ const int max_tries = 10;
+ int result, tries = max_tries;
- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- buf.memory = V4L2_MEMORY_MMAP;
- if ((result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_DQBUF, &buf))) {
- int saved_err = errno;
- V4L2_LOG_ERR("dequeuing buf: %s\n", strerror(errno));
- errno = saved_err;
+ /* Make sure we have the real v4l2 buffers mapped */
+ if ((result = v4l2_map_buffers(index)))
return result;
+
+ do {
+ if ((result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_DQBUF, buf))) {
+ int saved_err = errno;
+ V4L2_LOG_ERR("dequeuing buf: %s\n", strerror(errno));
+ errno = saved_err;
+ return result;
+ }
+
+ devices[index].frame_queued &= ~(1 << buf->index);
+
+ result = v4lconvert_convert(devices[index].convert,
+ &devices[index].src_fmt, &devices[index].dest_fmt,
+ devices[index].frame_pointers[buf->index],
+ buf->bytesused, dest ? dest : (devices[index].convert_mmap_buf +
+ buf->index * V4L2_FRAME_BUF_SIZE), dest_size);
+
+ if (result < 0) {
+ int saved_err = errno;
+
+ if(errno == EAGAIN)
+ V4L2_LOG("warning error while converting frame data: %s\n",
+ v4lconvert_get_error_message(devices[index].convert));
+ else
+ V4L2_LOG_ERR("converting / decoding frame data: %s\n",
+ v4lconvert_get_error_message(devices[index].convert));
+
+ v4l2_queue_read_buffer(index, buf->index);
+ errno = saved_err;
+ }
+ tries--;
+ } while (result < 0 && errno == EAGAIN && tries);
+
+ if (result < 0 && errno == EAGAIN) {
+ V4L2_LOG_ERR("got %d consecutive frame decode errors, last error: %s\n",
+ max_tries, v4lconvert_get_error_message(devices[index].convert));
}
- devices[index].frame_queued &= ~(1 << buf.index);
- *bytesused = buf.bytesused;
- return buf.index;
+ return result;
}
static int v4l2_queue_read_buffers(int index)
@@ -310,6 +338,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 +354,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 +452,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 +488,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 +498,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 +555,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 +591,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,8 +641,12 @@ 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)
+ if (((struct v4l2_fmtdesc *)arg)->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
+ (devices[index].flags & V4L2_ENABLE_ENUM_FMT_EMULATION))
is_capture_request = 1;
break;
case VIDIOC_TRY_FMT:
@@ -598,11 +695,21 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
if (stream_needs_locking)
pthread_mutex_lock(&devices[index].stream_lock);
- converting = devices[index].src_fmt.fmt.pix.pixelformat !=
- devices[index].dest_fmt.fmt.pix.pixelformat;
-
+ converting = v4lconvert_needs_conversion(devices[index].convert,
+ &devices[index].src_fmt, &devices[index].dest_fmt);
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 +727,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 +747,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 +778,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 +785,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 +806,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 +818,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,14 +842,19 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
{
struct v4l2_buffer *buf = arg;
- result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_DQBUF, buf);
- if (result) {
- V4L2_LOG_ERR("dequeing buffer: %s\n", strerror(errno));
- break;
- }
+ if (devices[index].flags & V4L2_STREAM_CONTROLLED_BY_READ)
+ if ((result = v4l2_deactivate_read_stream(index)))
+ break;
- if (!converting)
+ if (!converting) {
+ result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_DQBUF, buf);
+ if (result) {
+ int saved_err = errno;
+ V4L2_LOG_ERR("dequeuing buf: %s\n", strerror(errno));
+ errno = saved_err;
+ }
break;
+ }
/* An application can do a DQBUF before mmap-ing in the buffer,
but we need the buffer _now_ to write our converted data
@@ -791,26 +876,17 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
}
}
- /* Make sure we have the real v4l2 buffers mapped before trying to
- read from them */
- if ((result = v4l2_map_buffers(index)))
- break;
-
- result = v4lconvert_convert(devices[index].convert,
- &devices[index].src_fmt, &devices[index].dest_fmt,
- devices[index].frame_pointers[buf->index],
- buf->bytesused,
- devices[index].convert_mmap_buf +
- buf->index * V4L2_FRAME_BUF_SIZE,
- V4L2_FRAME_BUF_SIZE);
- if (result < 0) {
- V4L2_LOG_ERR("converting / decoding frame data: %s\n",
- v4lconvert_get_error_message(devices[index].convert));
+ result = v4l2_dequeue_and_convert(index, buf, 0, V4L2_FRAME_BUF_SIZE);
+ if (result < 0)
break;
- }
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 +894,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);
@@ -845,42 +919,43 @@ int v4l2_ioctl (int fd, unsigned long int request, ...)
}
-ssize_t v4l2_read (int fd, void* buffer, size_t n)
+ssize_t v4l2_read (int fd, void* dest, size_t n)
{
ssize_t result;
- int index, bytesused = 0, frame_index;
+ int index;
+ struct v4l2_buffer buf;
if ((index = v4l2_get_index(fd)) == -1)
- return syscall(SYS_read, fd, buffer, n);
+ return syscall(SYS_read, fd, dest, 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) &&
+ !v4lconvert_needs_conversion(devices[index].convert,
+ &devices[index].src_fmt, &devices[index].dest_fmt)) {
+ result = syscall(SYS_read, fd, dest, n);
goto leave;
}
- devices[index].io = v4l2_io_read;
-
- if ((result = v4l2_activate_read_stream(index)))
- goto leave;
- if ((frame_index = v4l2_dequeue_read_buffer(index, &bytesused)) < 0) {
- result = -1;
- 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;
}
- result = v4lconvert_convert(devices[index].convert,
- &devices[index].src_fmt, &devices[index].dest_fmt,
- devices[index].frame_pointers[frame_index], bytesused,
- buffer, n);
-
- v4l2_queue_read_buffer(index, frame_index);
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ result = v4l2_dequeue_and_convert(index, &buf, dest, n);
- if (result < 0)
- V4L2_LOG_ERR("converting / decoding frame data: %s\n",
- v4lconvert_get_error_message(devices[index].convert));
+ if (result >= 0)
+ v4l2_queue_read_buffer(index, buf.index);
leave:
pthread_mutex_unlock(&devices[index].stream_lock);
@@ -917,10 +992,9 @@ 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) {
+ !v4lconvert_needs_conversion(devices[index].convert,
+ &devices[index].src_fmt, &devices[index].dest_fmt)) {
errno = EINVAL;
result = MAP_FAILED;
goto leave;
@@ -943,8 +1017,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 +1058,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..6237d55ec 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
@@ -25,6 +25,8 @@
#include <asm/types.h>
/* end broken header workaround includes */
#include <linux/videodev2.h>
+#include "libv4l2.h"
+#include "libv4l2-priv.h"
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
@@ -116,7 +118,7 @@ void v4l2_log_ioctl(unsigned long int request, void *arg, int result)
int pixfmt = fmt->fmt.pix.pixelformat;
if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
- fprintf(v4l2_log_file, " pixelformat: %c%c%c%c %dx%d\n",
+ fprintf(v4l2_log_file, " pixelformat: %c%c%c%c %ux%u\n",
pixfmt & 0xff,
(pixfmt >> 8) & 0xff,
(pixfmt >> 16) & 0xff,
@@ -131,6 +133,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, (int)req->type, (int)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..e8756f338 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
@@ -27,6 +27,8 @@
#include <syscall.h>
#include <fcntl.h>
#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
/* These headers are not needed by us, but by linux/videodev2.h,
which is broken on some systems and doesn't include them itself :( */
#include <sys/time.h>
@@ -41,7 +43,13 @@
#error open/read/mmap is a prepocessor macro !!
#endif
-int open (const char *file, int oflag, ...)
+#if __GNUC__ >= 4
+#define LIBV4L_PUBLIC __attribute__ ((visibility("default")))
+#else
+#define LIBV4L_PUBLIC
+#endif
+
+LIBV4L_PUBLIC int open (const char *file, int oflag, ...)
{
int fd;
struct v4l2_capability cap;
@@ -66,7 +74,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 */
@@ -84,7 +92,7 @@ int open (const char *file, int oflag, ...)
return fd;
}
-int open64(const char *file, int oflag, ...)
+LIBV4L_PUBLIC int open64(const char *file, int oflag, ...)
{
int fd;
@@ -107,17 +115,17 @@ int open64(const char *file, int oflag, ...)
return fd;
}
-int close(int fd)
+LIBV4L_PUBLIC int close(int fd)
{
return v4l2_close(fd);
}
-int dup(int fd)
+LIBV4L_PUBLIC int dup(int fd)
{
return v4l2_dup(fd);
}
-int ioctl (int fd, unsigned long int request, ...)
+LIBV4L_PUBLIC int ioctl (int fd, unsigned long int request, ...)
{
void *arg;
va_list ap;
@@ -129,24 +137,25 @@ int ioctl (int fd, unsigned long int request, ...)
return v4l2_ioctl (fd, request, arg);
}
-ssize_t read (int fd, void* buffer, size_t n)
+LIBV4L_PUBLIC 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,
+LIBV4L_PUBLIC 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,
+LIBV4L_PUBLIC 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);
}
-int munmap(void *start, size_t length)
+LIBV4L_PUBLIC int munmap(void *start, size_t length)
{
return v4l2_munmap(start, length);
}
+
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/Makefile b/v4l2-apps/lib/libv4l/libv4lconvert/Makefile
index 38071de94..641d19d6e 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
+override CPPFLAGS += -I../include -I../../../include -fvisibility=hidden
CFLAGS := -g -O1
-CFLAGS += -Wall -W -Wno-unused -Wpointer-arith -Wstrict-prototypes
-
-LDFLAGS = -shared
+CFLAGS += -Wall -Wno-unused -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes
+ifeq ($(LINKTYPE),static)
+CONVERT_LIB = libv4lconvert.a
+else
CONVERT_LIB = libv4lconvert.so
-CONVERT_OBJS = libv4lconvert.o tinyjpeg.o sn9c10x.o pac207.o \
+override CPPFLAGS += -fPIC
+endif
+
+CONVERT_OBJS = libv4lconvert.o tinyjpeg.o sn9c10x.o pac207.o flip.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/flip.c b/v4l2-apps/lib/libv4l/libv4lconvert/flip.c
new file mode 100644
index 000000000..cd3468a89
--- /dev/null
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/flip.c
@@ -0,0 +1,107 @@
+/*
+
+# RGB / YUV flip/rotate routines
+
+# (C) 2008 Hans de Goede <j.w.r.degoede@hhs.nl>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+*/
+
+#include "libv4lconvert-priv.h"
+
+void v4lconvert_rotate180_rgbbgr24(const unsigned char *src, unsigned char *dst,
+ int width, int height)
+{
+ int i;
+
+ src += 3 * width * height - 3;
+
+ for (i = 0; i < width * height; i++) {
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ dst += 3;
+ src -= 3;
+ }
+}
+
+void v4lconvert_rotate180_yuv420(const unsigned char *src, unsigned char *dst,
+ int width, int height)
+{
+ int i;
+
+ /* First flip x and y of the Y plane */
+ src += width * height - 1;
+ for (i = 0; i < width * height; i++)
+ *dst++ = *src--;
+
+ /* Now flip the U plane */
+ src += width * height * 5 / 4;
+ for (i = 0; i < width * height / 4; i++)
+ *dst++ = *src--;
+
+ /* Last flip the V plane */
+ src += width * height / 2;
+ for (i = 0; i < width * height / 4; i++)
+ *dst++ = *src--;
+}
+
+void v4lconvert_rotate90_rgbbgr24(const unsigned char *src, unsigned char *dst,
+ int destwidth, int destheight)
+{
+ int x, y;
+#define srcwidth destheight
+#define srcheight destwidth
+
+ for (y = 0; y < destheight; y++)
+ for (x = 0; x < destwidth; x++) {
+ int offset = ((srcheight - x - 1) * srcwidth + y) * 3;
+ *dst++ = src[offset++];
+ *dst++ = src[offset++];
+ *dst++ = src[offset];
+ }
+}
+
+void v4lconvert_rotate90_yuv420(const unsigned char *src, unsigned char *dst,
+ int destwidth, int destheight)
+{
+ int x, y;
+
+ /* Y-plane */
+ for (y = 0; y < destheight; y++)
+ for (x = 0; x < destwidth; x++) {
+ int offset = (srcheight - x - 1) * srcwidth + y;
+ *dst++ = src[offset];
+ }
+
+ /* U-plane */
+ src += srcwidth * srcheight;
+ destwidth /= 2;
+ destheight /= 2;
+ for (y = 0; y < destheight; y++)
+ for (x = 0; x < destwidth; x++) {
+ int offset = (srcheight - x - 1) * srcwidth + y;
+ *dst++ = src[offset];
+ }
+
+ /* V-plane */
+ src += srcwidth * srcheight;
+ for (y = 0; y < destheight; y++)
+ for (x = 0; x < destwidth; x++) {
+ int offset = (srcheight - x - 1) * srcwidth + y;
+ *dst++ = src[offset];
+ }
+}
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/jidctflt.c b/v4l2-apps/lib/libv4l/libv4lconvert/jidctflt.c
index ba70309c9..532abc7ea 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/jidctflt.c
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/jidctflt.c
@@ -80,7 +80,7 @@
#define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
-#if defined(__GNUC__) && (defined(__i686__)) // || defined(__x86_64__))
+#if defined(__GNUC__) && (defined(__i686__) || defined(__x86_64__))
static inline unsigned char descale_and_clamp(int x, int shift)
{
@@ -92,7 +92,7 @@ static inline unsigned char descale_and_clamp(int x, int shift)
"\tcmpl %4,%1\n"
"\tcmovg %4,%1\n"
: "=r"(x)
- : "0"(x), "Ic"((unsigned char)shift), "ir"(1UL<<(shift-1)), "r" (0xff), "r" (0)
+ : "0"(x), "Ic"((unsigned char)shift), "ir"(1U<<(shift-1)), "r" (0xff), "r" (0)
);
return x;
}
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h b/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h
index badb89d62..915c33283 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
@@ -35,6 +43,10 @@
#define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P','2','0','7')
#endif
+#ifndef V4L2_PIX_FMT_PJPG
+#define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G')
+#endif
+
#ifndef V4L2_PIX_FMT_SGBRG8
#define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G','B','R','G')
#endif
@@ -53,23 +65,38 @@
snprintf(data->error_msg, V4LCONVERT_ERROR_MSG_SIZE, \
"v4l-convert: error " __VA_ARGS__)
+#define V4LCONVERT_UPSIDE_DOWN 0x01
struct v4lconvert_data {
int fd;
+ int flags; /* bitfield */
int supported_src_formats; /* bitfield */
unsigned int no_formats;
char error_msg[V4LCONVERT_ERROR_MSG_SIZE];
struct jdec_private *jdec;
};
+struct v4lconvert_flags_info {
+ const char *card;
+ int flags;
+};
+
+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,10 +108,25 @@ 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);
void v4lconvert_bayer_to_yuv420(const unsigned char *bayer,
unsigned char *yuv, int width, int height, unsigned int pixfmt);
+void v4lconvert_rotate90_rgbbgr24(const unsigned char *src, unsigned char *dst,
+ int destwidth, int destheight);
+
+void v4lconvert_rotate90_yuv420(const unsigned char *src, unsigned char *dst,
+ int destwidth, int destheight);
+
+void v4lconvert_rotate180_rgbbgr24(const unsigned char *src, unsigned char *dst,
+ int width, int height);
+
+void v4lconvert_rotate180_yuv420(const unsigned char *src, unsigned char *dst,
+ int width, int height);
+
#endif
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c b/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c
index 6c6cb693d..4b48bfac4 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,20 +43,31 @@ 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,
+ V4L2_PIX_FMT_PJPG,
};
static const unsigned int supported_dst_pixfmts[] = {
SUPPORTED_DST_PIXFMTS
};
+/* List of cams which need special flags */
+static const struct v4lconvert_flags_info v4lconvert_flags[] = {
+ { "USB Camera (0471:0325)", V4LCONVERT_UPSIDE_DOWN }, /* SPC200NC */
+ { "USB Camera (0471:0326)", V4LCONVERT_UPSIDE_DOWN }, /* SPC300NC */
+ { "SPC 200NC ", V4LCONVERT_UPSIDE_DOWN },
+ { "SPC 300NC ", V4LCONVERT_UPSIDE_DOWN },
+};
struct v4lconvert_data *v4lconvert_create(int fd)
{
int i, j;
struct v4lconvert_data *data = calloc(1, sizeof(struct v4lconvert_data));
+ struct v4l2_capability cap;
if (!data)
return NULL;
@@ -81,6 +93,15 @@ struct v4lconvert_data *v4lconvert_create(int fd)
data->no_formats = i;
+ /* Check if this cam has any special flags */
+ if (syscall(SYS_ioctl, fd, VIDIOC_QUERYCAP, &cap) == 0) {
+ for (i = 0; i < ARRAY_SIZE(v4lconvert_flags); i++)
+ if (!strcmp((const char *)v4lconvert_flags[i].card, (char *)cap.card)) {
+ data->flags = v4lconvert_flags[i].flags;
+ break;
+ }
+ }
+
return data;
}
@@ -168,7 +189,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 +212,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 *
@@ -208,17 +232,42 @@ int v4lconvert_try_format(struct v4lconvert_data *data,
return 0;
}
+/* Is conversion necessary ? */
+int v4lconvert_needs_conversion(struct v4lconvert_data *data,
+ const struct v4l2_format *src_fmt, /* in */
+ const struct v4l2_format *dest_fmt) /* in */
+{
+ int i;
+
+ if(memcmp(src_fmt, dest_fmt, sizeof(*src_fmt)))
+ return 1; /* Formats differ */
+
+ if (!(data->flags & V4LCONVERT_UPSIDE_DOWN))
+ return 0; /* Formats identical and we don't need flip */
+
+ /* Formats are identical, but we need flip, do we support the dest_fmt? */
+ for (i = 0; i < ARRAY_SIZE(supported_dst_pixfmts); i++)
+ if (supported_dst_pixfmts[i] == dest_fmt->fmt.pix.pixelformat)
+ break;
+
+ if (i == ARRAY_SIZE(supported_dst_pixfmts))
+ return 0; /* Needs flip but we cannot do it :( */
+ else
+ return 1; /* Needs flip and thus conversion */
+}
+
int v4lconvert_convert(struct v4lconvert_data *data,
const struct v4l2_format *src_fmt, /* in */
const struct v4l2_format *dest_fmt, /* in */
- unsigned char *src, int src_size, unsigned char *dest, int dest_size)
+ unsigned char *src, int src_size, unsigned char *_dest, int dest_size)
{
unsigned int header_width, header_height;
- int result, needed;
+ int result, needed, rotate = 0, jpeg_flags = TINYJPEG_FLAGS_MJPEG_TABLE;
unsigned char *components[3];
+ unsigned char *dest = _dest;
/* Special case when no conversion is needed */
- if(!memcmp(src_fmt, dest_fmt, sizeof(*src_fmt))) {
+ if (!v4lconvert_needs_conversion(data, src_fmt, dest_fmt)) {
int to_copy = MIN(dest_size, src_size);
memcpy(dest, src, to_copy);
return to_copy;
@@ -226,6 +275,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;
@@ -244,7 +294,15 @@ int v4lconvert_convert(struct v4lconvert_data *data,
return -1;
}
+ if (data->flags & V4LCONVERT_UPSIDE_DOWN) {
+ rotate = 180;
+ dest = alloca(needed);
+ }
+
switch (src_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_PJPG:
+ jpeg_flags |= TINYJPEG_FLAGS_PIXART_JPEG;
+ /* Fall through */
case V4L2_PIX_FMT_MJPEG:
case V4L2_PIX_FMT_JPEG:
if (!data->jdec) {
@@ -255,9 +313,7 @@ int v4lconvert_convert(struct v4lconvert_data *data,
return -1;
}
}
- tinyjpeg_set_flags(data->jdec,
- (src_fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG)?
- TINYJPEG_FLAGS_MJPEG_TABLE : 0);
+ tinyjpeg_set_flags(data->jdec, jpeg_flags);
if (tinyjpeg_parse_header(data->jdec, src, src_size)) {
V4LCONVERT_ERR("parsing JPEG header: %s\n",
tinyjpeg_get_errorstring(data->jdec));
@@ -266,13 +322,22 @@ int v4lconvert_convert(struct v4lconvert_data *data,
}
tinyjpeg_get_size(data->jdec, &header_width, &header_height);
- if (header_width != dest_fmt->fmt.pix.width || header_height != dest_fmt->fmt.pix.height) {
- V4LCONVERT_ERR("unexpected width / height in JPEG header\n");
- V4LCONVERT_ERR("expected: %dx%d, header: %ux%u\n",
- dest_fmt->fmt.pix.width, dest_fmt->fmt.pix.height,
- header_width, header_height);
- errno = EIO;
- return -1;
+ if (header_width != dest_fmt->fmt.pix.width ||
+ header_height != dest_fmt->fmt.pix.height) {
+ /* Check for (pixart) rotated JPEG */
+ if (header_width == dest_fmt->fmt.pix.height ||
+ header_height == dest_fmt->fmt.pix.width) {
+ if (!rotate)
+ dest = alloca(needed);
+ rotate += 90;
+ } else {
+ V4LCONVERT_ERR("unexpected width / height in JPEG header"
+ "expected: %ux%u, header: %ux%u\n",
+ dest_fmt->fmt.pix.width, dest_fmt->fmt.pix.height,
+ header_width, header_height);
+ errno = EIO;
+ return -1;
+ }
}
components[0] = dest;
@@ -281,43 +346,98 @@ 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
- decompression, log the error, but don't return an errorcode to the
- application, so that the user gets what we managed to decompress */
- if (result)
- fprintf(stderr, "libv4lconvert: Error decompressing JPEG: %s",
- tinyjpeg_get_errorstring(data->jdec));
-
+ if (result) {
+ /* Pixart webcam's seem to regulary generate corrupt frames, which
+ are best thrown away to avoid flashes in the video stream. Tell
+ the upper layer this is an intermediate fault and it should try
+ again with a new buffer by setting errno to EAGAIN */
+ if (src_fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_PJPG) {
+ V4LCONVERT_ERR("Error decompressing JPEG: %s",
+ tinyjpeg_get_errorstring(data->jdec));
+ errno = EAGAIN;
+ return -1;
+ } else {
+ /* If the JPEG header checked out ok and we get an error during actual
+ decompression, log the error, but don't return an errorcode to the
+ application, so that the user gets what we managed to decompress */
+ fprintf(stderr, "libv4lconvert: Error decompressing JPEG: %s",
+ tinyjpeg_get_errorstring(data->jdec));
+ }
+ }
break;
case V4L2_PIX_FMT_SBGGR8:
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:
@@ -336,7 +456,7 @@ int v4lconvert_convert(struct v4lconvert_data *data,
case V4L2_PIX_FMT_SN9C10X:
v4lconvert_decode_sn9c10x(src, tmpbuf, dest_fmt->fmt.pix.width,
dest_fmt->fmt.pix.height);
- bayer_fmt = V4L2_PIX_FMT_SGBRG8;
+ bayer_fmt = V4L2_PIX_FMT_SBGGR8;
break;
case V4L2_PIX_FMT_PAC207:
v4lconvert_decode_pac207(src, tmpbuf, dest_fmt->fmt.pix.width,
@@ -345,24 +465,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:
@@ -371,6 +524,45 @@ int v4lconvert_convert(struct v4lconvert_data *data,
return -1;
}
+ /* Note when rotating dest is our temporary buffer to which our conversion
+ was done and _dest is the real dest! If the formats are identical no
+ conversion has been done! */
+ if (rotate && dest_fmt->fmt.pix.pixelformat == src_fmt->fmt.pix.pixelformat)
+ dest = src;
+
+ switch (rotate) {
+ case 0:
+ break;
+ case 90:
+ switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
+ case V4L2_PIX_FMT_BGR24:
+ v4lconvert_rotate90_rgbbgr24(dest, _dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ case V4L2_PIX_FMT_YUV420:
+ v4lconvert_rotate90_yuv420(dest, _dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ }
+ break;
+ case 180:
+ switch (dest_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_RGB24:
+ case V4L2_PIX_FMT_BGR24:
+ v4lconvert_rotate180_rgbbgr24(dest, _dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ case V4L2_PIX_FMT_YUV420:
+ v4lconvert_rotate180_yuv420(dest, _dest, dest_fmt->fmt.pix.width,
+ dest_fmt->fmt.pix.height);
+ break;
+ }
+ break;
+ default:
+ printf("FIXME add %d degrees rotation\n", rotate);
+ }
+
return needed;
}
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/pac207.c b/v4l2-apps/lib/libv4l/libv4lconvert/pac207.c
index 085d7a772..97ef4ebc0 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
@@ -38,7 +38,7 @@ static struct {
signed char val;
} table[256];
-void init_pixart_decoder(void)
+static void init_pixart_decoder(void)
{
int i;
int is_abs, val, len;
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c b/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c
index 79c8ecb35..883d62330 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
@@ -20,6 +20,8 @@
*/
+#include "libv4lconvert-priv.h"
+
#define RGB2YUV(r,g,b,y,u,v) \
(y) = (( 8453*(r) + 16594*(g) + 3223*(b) + 524288) >> 15); \
(u) = (( -4878*(r) - 9578*(g) + 14456*(b) + 4210688) >> 15); \
@@ -80,3 +82,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..4ea526d49 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
@@ -50,7 +50,7 @@ static int sonix_unknown = 0;
present at the MSB of byte x.
*/
-void sonix_decompress_init(void)
+static void sonix_decompress_init(void)
{
int i;
int is_abs, val, len, unk;
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..01eed4ec5 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
@@ -28,6 +28,7 @@
* but it might work with other spca561 cameras
*/
#include <string.h>
+#include "libv4lconvert-priv.h"
/*fixme: not reentrant */
static unsigned int bit_bucket;
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.c b/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.c
index 5c3b4e26d..fc9efbeb2 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.c
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.c
@@ -214,6 +214,28 @@ static const unsigned char val_ac_chrominance[] =
0xf9, 0xfa
};
+const unsigned char pixart_quantization[][64] = {
+ {
+ 0x07, 0x07, 0x08, 0x0a, 0x09, 0x07, 0x0d, 0x0b,
+ 0x0c, 0x0d, 0x11, 0x10, 0x0f, 0x12, 0x17, 0x27,
+ 0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25,
+ 0x1d, 0x28, 0x3a, 0x33, 0x3d, 0x3c, 0x39, 0x33,
+ 0x38, 0x37, 0x40, 0x48, 0x5c, 0x4e, 0x40, 0x44,
+ 0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51, 0x57,
+ 0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71,
+ 0x79, 0x70, 0x64, 0x78, 0x5c, 0x65, 0x67, 0x63,
+ },
+ {
+ 0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a,
+ 0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63,
+ 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+ 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+ 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+ 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+ 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+ 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+ },
+};
/*
* 4 functions to manage the stream
@@ -246,7 +268,7 @@ static const unsigned char val_ac_chrominance[] =
unsigned char c; \
if (stream >= priv->stream_end) { \
snprintf(priv->error_string, sizeof(priv->error_string), \
- "fill_nbits error: need %d more bits\n", \
+ "fill_nbits error: need %u more bits\n", \
nbits_wanted - nbits_in_reservoir); \
longjmp(priv->jump_state, -EIO); \
} \
@@ -288,6 +310,74 @@ static const unsigned char val_ac_chrominance[] =
} while(0);
+/* Special Pixart versions of the *_nbits functions, these remove the special
+ ff ff ff xx sequences pixart cams insert from the bitstream */
+#define pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,nbits_wanted) \
+do { \
+ while (nbits_in_reservoir<nbits_wanted) \
+ { \
+ unsigned char c; \
+ if (stream >= priv->stream_end) { \
+ snprintf(priv->error_string, sizeof(priv->error_string), \
+ "fill_nbits error: need %u more bits\n", \
+ nbits_wanted - nbits_in_reservoir); \
+ longjmp(priv->jump_state, -EIO); \
+ } \
+ c = *stream++; \
+ reservoir <<= 8; \
+ if (c == 0xff) { \
+ switch (stream[0]) { \
+ case 0x00: \
+ stream++; \
+ break; \
+ case 0xd9: /* EOF marker */ \
+ stream++; \
+ if (stream != priv->stream_end) { \
+ snprintf(priv->error_string, sizeof(priv->error_string), \
+ "Pixart JPEG error: premature EOF\n"); \
+ longjmp(priv->jump_state, -EIO); \
+ } \
+ break; \
+ case 0xff: \
+ if (stream[1] == 0xff && (stream[2] < 7 || stream[2] == 0xff)) { \
+ stream += 3; \
+ c = *stream++; \
+ break; \
+ } \
+ /* Error fall through */ \
+ default: \
+ snprintf(priv->error_string, sizeof(priv->error_string), \
+ "Pixart JPEG error: invalid JPEG marker: 0xff 0x%02x 0x%02x 0x%02x\n", \
+ (unsigned int)stream[0], (unsigned int)stream[1], \
+ (unsigned int)stream[2]); \
+ longjmp(priv->jump_state, -EIO); \
+ } \
+ } \
+ reservoir |= c; \
+ nbits_in_reservoir+=8; \
+ } \
+} while(0);
+
+/* Signed version !!!! */
+#define pixart_get_nbits(reservoir,nbits_in_reservoir,stream,nbits_wanted,result) \
+do { \
+ pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,(nbits_wanted)); \
+ result = ((reservoir)>>(nbits_in_reservoir-(nbits_wanted))); \
+ nbits_in_reservoir -= (nbits_wanted); \
+ reservoir &= ((1U<<nbits_in_reservoir)-1); \
+ if ((unsigned int)result < (1UL<<((nbits_wanted)-1))) \
+ result += (0xFFFFFFFFUL<<(nbits_wanted))+1; \
+} while(0);
+
+#define pixart_look_nbits(reservoir,nbits_in_reservoir,stream,nbits_wanted,result) \
+do { \
+ pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,(nbits_wanted)); \
+ result = ((reservoir)>>(nbits_in_reservoir-(nbits_wanted))); \
+} while(0);
+
+/* Note skip_nbits is identical for both */
+
+
#define be16_to_cpu(x) (((x)[0]<<8)|(x)[1])
static void resync(struct jdec_private *priv);
@@ -334,9 +424,50 @@ static int get_next_huffman_code(struct jdec_private *priv, struct huffman_table
slowtable+=2;
}
}
+ snprintf(priv->error_string, sizeof(priv->error_string),
+ "unknown huffman code: %08x\n", (unsigned int)hcode);
+ longjmp(priv->jump_state, -EIO);
return 0;
}
+/* identical as above but with *_nbits replaced with pixart_*_nbits */
+static int pixart_get_next_huffman_code(struct jdec_private *priv,
+ struct huffman_table *huffman_table)
+{
+ int value, hcode;
+ unsigned int extra_nbits, nbits;
+ uint16_t *slowtable;
+
+ pixart_look_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, HUFFMAN_HASH_NBITS, hcode);
+ value = huffman_table->lookup[hcode];
+ if (value >= 0)
+ {
+ unsigned int code_size = huffman_table->code_size[value];
+ skip_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, code_size);
+ return value;
+ }
+
+ /* Decode more bits each time ... */
+ for (extra_nbits=0; extra_nbits<16-HUFFMAN_HASH_NBITS; extra_nbits++)
+ {
+ nbits = HUFFMAN_HASH_NBITS + 1 + extra_nbits;
+
+ pixart_look_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, nbits, hcode);
+ slowtable = huffman_table->slowtable[extra_nbits];
+ /* Search if the code is in this array */
+ while (slowtable[0]) {
+ if (slowtable[0] == hcode) {
+ skip_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, nbits);
+ return slowtable[1];
+ }
+ slowtable+=2;
+ }
+ }
+ snprintf(priv->error_string, sizeof(priv->error_string),
+ "unknown huffman code: %08x\n", (unsigned int)hcode);
+ longjmp(priv->jump_state, -EIO);
+ return 0;
+}
@@ -388,15 +519,84 @@ static void process_Huffman_data_unit(struct jdec_private *priv, int component)
else
{
j += count_0; /* skip count_0 zeroes */
- get_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, size_val, DCT[j]);
- j++;
+ if (j < 64) {
+ get_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, size_val, DCT[j]);
+ j++;
+ }
}
}
+ if (j > 64) {
+ snprintf(priv->error_string, sizeof(priv->error_string),
+ "error: more then 63 AC components (%d) in huffman unit\n", (int)j);
+ longjmp(priv->jump_state, -EIO);
+ }
+
for (j = 0; j < 64; j++)
c->DCT[j] = DCT[zigzag[j]];
}
+/* identical as above both with *_nbits replaced with pixart_*_nbits */
+static void pixart_process_Huffman_data_unit(struct jdec_private *priv, int component)
+{
+ unsigned char j;
+ unsigned int huff_code;
+ unsigned char size_val, count_0;
+
+ struct component *c = &priv->component_infos[component];
+ short int DCT[64];
+
+ /* Initialize the DCT coef table */
+ memset(DCT, 0, sizeof(DCT));
+
+ /* DC coefficient decoding */
+ huff_code = pixart_get_next_huffman_code(priv, c->DC_table);
+ if (huff_code) {
+ pixart_get_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, huff_code, DCT[0]);
+ DCT[0] += c->previous_DC;
+ c->previous_DC = DCT[0];
+ } else {
+ DCT[0] = c->previous_DC;
+ }
+
+
+ /* AC coefficient decoding */
+ j = 1;
+ while (j<64)
+ {
+ huff_code = pixart_get_next_huffman_code(priv, c->AC_table);
+
+ size_val = huff_code & 0xF;
+ count_0 = huff_code >> 4;
+
+ if (size_val == 0)
+ { /* RLE */
+ if (count_0 == 0)
+ break; /* EOB found, go out */
+ else if (count_0 == 0xF)
+ j += 16; /* skip 16 zeros */
+ }
+ else
+ {
+ j += count_0; /* skip count_0 zeroes */
+ if (j < 64 ) {
+ pixart_get_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, size_val, DCT[j]);
+ j++;
+ }
+ }
+ }
+
+ if (j > 64) {
+ snprintf(priv->error_string, sizeof(priv->error_string),
+ "error: more then 63 AC components (%d) in huffman unit\n", (int)j);
+ longjmp(priv->jump_state, -EIO);
+ }
+
+ for (j = 0; j < 64; j++)
+ c->DCT[j] = DCT[zigzag[j]];
+}
+
+
/*
* Takes two array of bits, and build the huffman table for size, and code
*
@@ -404,12 +604,13 @@ static void process_Huffman_data_unit(struct jdec_private *priv, int component)
* code_size will be used to known how many bits this symbol is encoded.
* slowtable will be used when the first lookup didn't give the result.
*/
-static void build_huffman_table(const unsigned char *bits, const unsigned char *vals, struct huffman_table *table)
+static int build_huffman_table(struct jdec_private *priv, const unsigned char *bits, const unsigned char *vals, struct huffman_table *table)
{
unsigned int i, j, code, code_size, val, nbits;
unsigned char huffsize[257], *hz;
unsigned int huffcode[257], *hc;
int next_free_entry;
+ int slowtable_used[16-HUFFMAN_HASH_NBITS];
/*
* Build a temp array
@@ -425,7 +626,7 @@ static void build_huffman_table(const unsigned char *bits, const unsigned char *
memset(table->lookup, 0xff, sizeof(table->lookup));
for (i=0; i<(16-HUFFMAN_HASH_NBITS); i++)
- table->slowtable[i][0] = 0;
+ slowtable_used[i] = 0;
/* Build a temp array
* huffcode[X] => code used to write vals[X]
@@ -472,32 +673,43 @@ static void build_huffman_table(const unsigned char *bits, const unsigned char *
else
{
/* Perhaps sorting the array will be an optimization */
- uint16_t *slowtable = table->slowtable[code_size-HUFFMAN_HASH_NBITS-1];
- while(slowtable[0])
- slowtable+=2;
- slowtable[0] = code;
- slowtable[1] = val;
- slowtable[2] = 0;
- /* TODO: NEED TO CHECK FOR AN OVERFLOW OF THE TABLE */
- }
+ int slowtable_index = code_size-HUFFMAN_HASH_NBITS-1;
+
+ if (slowtable_used[slowtable_index] == 254)
+ error("slow Huffman table overflow\n");
+ table->slowtable[slowtable_index][slowtable_used[slowtable_index]]
+ = code;
+ table->slowtable[slowtable_index][slowtable_used[slowtable_index] + 1]
+ = val;
+ slowtable_used[slowtable_index] += 2;
+ }
}
+ for (i=0; i<(16-HUFFMAN_HASH_NBITS); i++)
+ table->slowtable[i][slowtable_used[i]] = 0;
+
+ return 0;
}
-static void build_default_huffman_tables(struct jdec_private *priv)
+static int build_default_huffman_tables(struct jdec_private *priv)
{
if ( (priv->flags & TINYJPEG_FLAGS_MJPEG_TABLE)
&& priv->default_huffman_table_initialized)
- return;
+ return 0;
- build_huffman_table(bits_dc_luminance, val_dc_luminance, &priv->HTDC[0]);
- build_huffman_table(bits_ac_luminance, val_ac_luminance, &priv->HTAC[0]);
+ if (build_huffman_table(priv, bits_dc_luminance, val_dc_luminance, &priv->HTDC[0]))
+ return -1;
+ if (build_huffman_table(priv, bits_ac_luminance, val_ac_luminance, &priv->HTAC[0]))
+ return -1;
- build_huffman_table(bits_dc_chrominance, val_dc_chrominance, &priv->HTDC[1]);
- build_huffman_table(bits_ac_chrominance, val_ac_chrominance, &priv->HTAC[1]);
+ if (build_huffman_table(priv, bits_dc_chrominance, val_dc_chrominance, &priv->HTDC[1]))
+ return -1;
+ if (build_huffman_table(priv, bits_ac_chrominance, val_ac_chrominance, &priv->HTAC[1]))
+ return -1;
priv->default_huffman_table_initialized = 1;
+ return 0;
}
@@ -1390,6 +1602,44 @@ static void decode_MCU_2x1_3planes(struct jdec_private *priv)
IDCT(&priv->component_infos[cCr], priv->Cr, 8);
}
+static void pixart_decode_MCU_2x1_3planes(struct jdec_private *priv)
+{
+ unsigned char marker;
+
+ pixart_look_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream,
+ 8, marker);
+ /* I think the marker indicates which quantization table to use, iow
+ a Pixart JPEG may have a different quantization table per MCU, most
+ MCU's have 0x44 as marker for which our special Pixart quantization
+ tables are correct. Unfortunately with a 7302 some blocks also have 0x48,
+ and sometimes even other values. As 0x48 is quite common too, we really
+ need to find out the correct table for that, as currently the blocks
+ with a 0x48 marker look wrong. During normal operation the marker stays
+ within the range below, if it gets out of this range we're most likely
+ decoding garbage */
+ if (marker < 0x20 || marker > 0x7f) {
+ snprintf(priv->error_string, sizeof(priv->error_string),
+ "Pixart JPEG error: invalid MCU marker: 0x%02x\n",
+ (unsigned int)marker);
+ longjmp(priv->jump_state, -EIO);
+ }
+ skip_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, 8);
+
+ // Y
+ pixart_process_Huffman_data_unit(priv, cY);
+ IDCT(&priv->component_infos[cY], priv->Y, 16);
+ pixart_process_Huffman_data_unit(priv, cY);
+ IDCT(&priv->component_infos[cY], priv->Y+8, 16);
+
+ // Cb
+ pixart_process_Huffman_data_unit(priv, cCb);
+ IDCT(&priv->component_infos[cCb], priv->Cb, 8);
+
+ // Cr
+ pixart_process_Huffman_data_unit(priv, cCr);
+ IDCT(&priv->component_infos[cCr], priv->Cr, 8);
+}
+
/*
* Decode a 2x1
* .-------.
@@ -1676,9 +1926,9 @@ static int parse_SOS(struct jdec_private *priv, const unsigned char *stream)
error("We do not support more than %d DC Huffman table\n",
HUFFMAN_TABLES);
if (cid != priv->component_infos[i].cid)
- error("SOS cid order (%d:%d) isn't compatible with the SOF marker (%d:%d)\n",
+ error("SOS cid order (%u:%u) isn't compatible with the SOF marker (%u:%u)\n",
i, cid, i, priv->component_infos[i].cid);
- trace("ComponentId:%d tableAC:%d tableDC:%d\n", cid, table&0xf, table>>4);
+ trace("ComponentId:%u tableAC:%d tableDC:%d\n", cid, table&0xf, table>>4);
#endif
priv->component_infos[i].AC_table = &priv->HTAC[table&0xf];
priv->component_infos[i].DC_table = &priv->HTDC[table>>4];
@@ -1723,10 +1973,13 @@ static int parse_DHT(struct jdec_private *priv, const unsigned char *stream)
trace("Length of the table: %d\n", count);
#endif
- if (index & 0xf0 )
- build_huffman_table(huff_bits, stream, &priv->HTAC[index&0xf]);
- else
- build_huffman_table(huff_bits, stream, &priv->HTDC[index&0xf]);
+ if (index & 0xf0 ) {
+ if (build_huffman_table(priv, huff_bits, stream, &priv->HTAC[index&0xf]))
+ return -1;
+ } else {
+ if (build_huffman_table(priv, huff_bits, stream, &priv->HTDC[index&0xf]))
+ return -1;
+ }
length -= 1;
length -= 16;
@@ -1817,6 +2070,8 @@ static int parse_JFIF(struct jdec_private *priv, const unsigned char *stream)
{
int chuck_len;
int marker;
+ int sof_marker_found = 0;
+ int dqt_marker_found = 0;
int sos_marker_found = 0;
int dht_marker_found = 0;
const unsigned char *next_chunck;
@@ -1838,10 +2093,12 @@ static int parse_JFIF(struct jdec_private *priv, const unsigned char *stream)
case SOF:
if (parse_SOF(priv, stream) < 0)
return -1;
+ sof_marker_found = 1;
break;
case DQT:
if (parse_DQT(priv, stream) < 0)
return -1;
+ dqt_marker_found = 1;
break;
case SOS:
if (parse_SOS(priv, stream) < 0)
@@ -1865,9 +2122,24 @@ static int parse_JFIF(struct jdec_private *priv, const unsigned char *stream)
stream = next_chunck;
}
+ if ( !sof_marker_found ||
+ (!dqt_marker_found && !(priv->flags & TINYJPEG_FLAGS_PIXART_JPEG)))
+ goto bogus_jpeg_format;
+
+ if (priv->flags & TINYJPEG_FLAGS_PIXART_JPEG) {
+ if (!priv->default_huffman_table_initialized) {
+ build_quantization_table(priv->Q_tables[0], pixart_quantization[0]);
+ build_quantization_table(priv->Q_tables[1], pixart_quantization[1]);
+ }
+
+ /* Pixart JPEG data starts with one unknown / unused byte */
+ priv->stream++;
+ }
+
if (!dht_marker_found) {
trace("No Huffman table loaded, using the default one\n");
- build_default_huffman_tables(priv);
+ if (build_default_huffman_tables(priv))
+ return -1;
}
#ifdef SANITY_CHECK
@@ -1962,6 +2234,13 @@ static const decode_MCU_fct decode_mcu_3comp_table[4] = {
decode_MCU_2x2_3planes,
};
+static const decode_MCU_fct pixart_decode_mcu_3comp_table[4] = {
+ NULL,
+ NULL,
+ pixart_decode_MCU_2x1_3planes,
+ NULL,
+};
+
static const decode_MCU_fct decode_mcu_1comp_table[4] = {
decode_MCU_1x1_1plane,
decode_MCU_1x2_1plane,
@@ -2021,6 +2300,9 @@ int tinyjpeg_decode(struct jdec_private *priv, int pixfmt)
bytes_per_blocklines[2] = 0;
decode_mcu_table = decode_mcu_3comp_table;
+ if (priv->flags & TINYJPEG_FLAGS_PIXART_JPEG)
+ decode_mcu_table = pixart_decode_mcu_3comp_table;
+
switch (pixfmt) {
case TINYJPEG_FMT_YUV420P:
colorspace_array_conv = convert_colorspace_yuv420p;
@@ -2056,6 +2338,8 @@ int tinyjpeg_decode(struct jdec_private *priv, int pixfmt)
case TINYJPEG_FMT_GREY:
decode_mcu_table = decode_mcu_1comp_table;
+ if (priv->flags & TINYJPEG_FLAGS_PIXART_JPEG)
+ error("Greyscale output not support for PIXART JPEG's\n");
colorspace_array_conv = convert_colorspace_grey;
if (priv->components[0] == NULL)
priv->components[0] = (uint8_t *)malloc(priv->width * priv->height);
@@ -2064,8 +2348,7 @@ int tinyjpeg_decode(struct jdec_private *priv, int pixfmt)
break;
default:
- trace("Bad pixel format\n");
- return -1;
+ error("Bad pixel format\n");
}
xstride_by_mcu = ystride_by_mcu = 8;
@@ -2091,6 +2374,9 @@ int tinyjpeg_decode(struct jdec_private *priv, int pixfmt)
trace("Use decode 2x1 sampling\n");
}
+ if (decode_MCU == NULL)
+ error("no decode MCU function for this JPEG format (PIXART?)\n");
+
resync(priv);
/* Don't forget to that block can be either 8 or 16 lines */
@@ -2130,6 +2416,12 @@ int tinyjpeg_decode(struct jdec_private *priv, int pixfmt)
}
}
+ if (priv->flags & TINYJPEG_FLAGS_PIXART_JPEG) {
+ /* Additional sanity check for funky Pixart format */
+ if ((priv->stream_end - priv->stream) > 5)
+ error("Pixart JPEG error, stream does not end with EOF marker\n");
+ }
+
return 0;
}
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.h b/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.h
index 42b60c1ee..b0096f0de 100644
--- a/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.h
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.h
@@ -43,6 +43,7 @@ struct jdec_private;
/* Flags that can be set by any applications */
#define TINYJPEG_FLAGS_MJPEG_TABLE (1<<1)
+#define TINYJPEG_FLAGS_PIXART_JPEG (1<<2)
/* Format accepted in outout */
enum tinyjpeg_fmt {