summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/indi/webcam
diff options
context:
space:
mode:
Diffstat (limited to 'kstars/kstars/indi/webcam')
-rw-r--r--kstars/kstars/indi/webcam/Makefile.am16
-rw-r--r--kstars/kstars/indi/webcam/PPort.cpp107
-rw-r--r--kstars/kstars/indi/webcam/PPort.h75
-rw-r--r--kstars/kstars/indi/webcam/ccvt.h164
-rw-r--r--kstars/kstars/indi/webcam/ccvt_c2.c118
-rw-r--r--kstars/kstars/indi/webcam/ccvt_misc.c435
-rw-r--r--kstars/kstars/indi/webcam/ccvt_types.h60
-rw-r--r--kstars/kstars/indi/webcam/port.cpp199
-rw-r--r--kstars/kstars/indi/webcam/port.h122
-rw-r--r--kstars/kstars/indi/webcam/pwc-ioctl.h176
-rw-r--r--kstars/kstars/indi/webcam/v4l1_base.cpp564
-rw-r--r--kstars/kstars/indi/webcam/v4l1_base.h110
-rw-r--r--kstars/kstars/indi/webcam/v4l1_pwc.cpp563
-rw-r--r--kstars/kstars/indi/webcam/v4l1_pwc.h89
-rw-r--r--kstars/kstars/indi/webcam/v4l2_base.cpp1189
-rw-r--r--kstars/kstars/indi/webcam/v4l2_base.h141
-rw-r--r--kstars/kstars/indi/webcam/vcvt.h73
-rw-r--r--kstars/kstars/indi/webcam/videodev.h346
-rw-r--r--kstars/kstars/indi/webcam/videodev2.h903
19 files changed, 5450 insertions, 0 deletions
diff --git a/kstars/kstars/indi/webcam/Makefile.am b/kstars/kstars/indi/webcam/Makefile.am
new file mode 100644
index 00000000..565859da
--- /dev/null
+++ b/kstars/kstars/indi/webcam/Makefile.am
@@ -0,0 +1,16 @@
+if HAVE_V4L2
+ libwebcam_linux = libwebcam_v4l2_linux.la
+else
+ libwebcam_linux = libwebcam_v4l1_linux.la
+endif
+
+noinst_LTLIBRARIES = libwebcam.la $(libwebcam_linux)
+
+libwebcam_v4l1_linux_la_SOURCES = PPort.cpp port.cpp v4l1_base.cpp v4l1_pwc.cpp ccvt_c2.c ccvt_misc.c
+libwebcam_v4l2_linux_la_SOURCES = PPort.cpp port.cpp v4l2_base.cpp ccvt_c2.c ccvt_misc.c
+
+libwebcam_la_SOURCES = empty_file.cpp
+libwebcam_la_LIBADD = $(libwebcam_linux)
+
+empty_file.cpp:
+ echo > empty_file.cpp
diff --git a/kstars/kstars/indi/webcam/PPort.cpp b/kstars/kstars/indi/webcam/PPort.cpp
new file mode 100644
index 00000000..b222a6f6
--- /dev/null
+++ b/kstars/kstars/indi/webcam/PPort.cpp
@@ -0,0 +1,107 @@
+/*
+ Copyright (C) 2004 by Jasem Mutlaq
+
+ This library 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 library 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 library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#include "PPort.h"
+#include "port.h"
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <iostream>
+
+using namespace std;
+
+#define TEST_VALIDITY {if (this==NULL) return false;}
+
+PPort::PPort() {
+ reset();
+}
+
+PPort::PPort(int ioPort) {
+ reset();
+ setPort(ioPort);
+}
+
+void PPort::reset() {
+ bitArray=0;
+ for (int i=0;i<8;++i) {
+ assignedBit[i]=NULL;
+ }
+ currentPort=NULL;
+}
+
+bool PPort::setPort(int ioPort) {
+ TEST_VALIDITY;
+ if (geteuid() != 0) {
+ cerr << "must be setuid root control parallel port"<<endl;
+ return false;
+ }
+ if (currentPort) {
+ delete currentPort;
+ }
+ reset();
+ currentPort=new port_t(ioPort);
+ return commit();
+}
+
+bool PPort::commit() {
+ TEST_VALIDITY;
+ if (currentPort) {
+ currentPort->write_data(bitArray);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool PPort::setBit(const void * ID,int bit,bool stat) {
+ TEST_VALIDITY;
+ if (ID != assignedBit[bit]) {
+ return false;
+ }
+
+ if (stat) {
+ bitArray |= (1<<bit);
+ } else {
+ bitArray &= ~(1<<bit);
+ }
+ return true;
+}
+
+bool PPort::registerBit(const void * ID,int bit) {
+ TEST_VALIDITY;
+ if (assignedBit[bit] || currentPort==NULL) {
+ return false;
+ }
+ assignedBit[bit]=ID;
+ return true;
+}
+
+bool PPort::unregisterBit(const void * ID,int bit) {
+ TEST_VALIDITY;
+ if (assignedBit[bit] != ID) {
+ return false;
+ }
+ assignedBit[bit]=NULL;
+ return true;
+}
+
+bool PPort::isRegisterBit(const void * ID,int bit) const {
+ TEST_VALIDITY;
+ return (assignedBit[bit] == ID);
+}
diff --git a/kstars/kstars/indi/webcam/PPort.h b/kstars/kstars/indi/webcam/PPort.h
new file mode 100644
index 00000000..c095a6e7
--- /dev/null
+++ b/kstars/kstars/indi/webcam/PPort.h
@@ -0,0 +1,75 @@
+/*
+ Copyright (C) 2004 by Jasem Mutlaq
+
+ This library 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 library 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 library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#ifndef _PPort_hpp_
+#define _PPort_hpp_
+
+class port_t;
+
+/** To access and share the parallel port
+ between severa objects. */
+class PPort {
+public:
+ PPort();
+ PPort(int ioPort);
+ /** set the ioport associated to the // port.
+ \return true if the binding was possible
+ */
+ bool setPort(int ioPort);
+ /** set a data bit of the // port.
+ \return false if IO port not set, or bit not registered by ID.
+ \param ID the identifier used to register the bit
+ \param stat the stat wanted for the given bit
+ \param bit the bit to set. They are numbered from 0 to 7.
+
+ */
+ bool setBit(const void * ID,int bit,bool stat);
+ /** register a bit for object ID.
+ \param ID the identifier used to register the bit it should be the 'this' pointer.
+ \param bit the bit of the // port to register
+ \return false if the bit is allready register with an
+ other ID, or if the // port is not initialised.
+ */
+ bool registerBit(const void * ID,int bit);
+ /** release a bit.
+ \param ID the identifier used to register the bit
+ \param bit the bit to register.
+ \return false if the bit was not registered by ID or
+ if the if the // port is not initialised.
+ */
+ bool unregisterBit(const void * ID,int bit);
+
+ /** test if a bit is registerd.
+ \param ID the identifier used to register the bit
+ \param bit the bit to test.
+ \return false if the bit was not registered by ID or
+ if the if the // port is not initialised.
+ */
+ bool isRegisterBit(const void * ID,int bit) const;
+
+ /** set the bits off the // port according to previous call to setBit().
+ */
+ bool commit();
+private:
+ void reset();
+ unsigned char bitArray;
+ const void * assignedBit[8];
+ port_t * currentPort;
+};
+#endif
diff --git a/kstars/kstars/indi/webcam/ccvt.h b/kstars/kstars/indi/webcam/ccvt.h
new file mode 100644
index 00000000..c78f88a6
--- /dev/null
+++ b/kstars/kstars/indi/webcam/ccvt.h
@@ -0,0 +1,164 @@
+/* CCVT: ColourConVerT: simple library for converting colourspaces
+ Copyright (C) 2002 Nemosoft Unv.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ For questions, remarks, patches, etc. for this program, the author can be
+ reached at nemosoft@smcc.demon.nl.
+*/
+
+/*
+ $Log$
+ Revision 1.4 2005/04/29 16:51:20 mutlaqja
+ Adding initial support for Video 4 Linux 2 drivers. This mean that KStars can probably control Meade Lunar Planetary Imager (LPI). V4L2 requires a fairly recent kernel (> 2.6.9) and many drivers don't fully support it yet. It will take sometime. KStars still supports V4L1 and will continue so until V4L1 is obselete. Please test KStars video drivers if you can. Any comments welcomed.
+
+ CCMAIL: kstars-devel@kde.org
+
+ Revision 1.3 2004/06/26 23:12:03 mutlaqja
+ Hopefully this will fix compile issues on 64bit archs, and FreeBSD, among others. The assembly code is replaced with a more portable, albeit slower C implementation. I imported the videodev.h header after cleaning it for user space.
+
+ Anyone who has problems compiling this, please report the problem to kstars-devel@kde.org
+
+ I noticed one odd thing after updating my kdelibs, the LEDs don't change color when state is changed. Try that by starting any INDI device, and hit connect, if the LED turns to yellow and back to grey then it works fine, otherwise, we've got a problem.
+
+ CCMAIL: kstars-devel@kde.org
+
+ Revision 1.10 2003/10/24 16:55:18 nemosoft
+ removed erronous log messages
+
+ Revision 1.9 2002/11/03 22:46:25 nemosoft
+ Adding various RGB to RGB functions.
+ Adding proper copyright header too.
+
+ Revision 1.8 2002/04/14 01:00:27 nemosoft
+ Finishing touches: adding const, adding libs for 'show'
+*/
+
+
+#ifndef CCVT_H
+#define CCVT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Colour ConVerT: going from one colour space to another.
+ ** NOTE: the set of available functions is far from complete! **
+
+ Format descriptions:
+ 420i = "4:2:0 interlaced"
+ YYYY UU YYYY UU even lines
+ YYYY VV YYYY VV odd lines
+ U/V data is subsampled by 2 both in horizontal
+ and vertical directions, and intermixed with the Y values.
+
+ 420p = "4:2:0 planar"
+ YYYYYYYY N lines
+ UUUU N/2 lines
+ VVVV N/2 lines
+ U/V is again subsampled, but all the Ys, Us and Vs are placed
+ together in separate buffers. The buffers may be placed in
+ one piece of contiguous memory though, with Y buffer first,
+ followed by U, followed by V.
+
+ yuyv = "4:2:2 interlaced"
+ YUYV YUYV YUYV ... N lines
+ The U/V data is subsampled by 2 in horizontal direction only.
+
+ bgr24 = 3 bytes per pixel, in the order Blue Green Red (whoever came up
+ with that idea...)
+ rgb24 = 3 bytes per pixel, in the order Red Green Blue (which is sensible)
+ rgb32 = 4 bytes per pixel, in the order Red Green Blue Alpha, with
+ Alpha really being a filler byte (0)
+ bgr32 = last but not least, 4 bytes per pixel, in the order Blue Green Red
+ Alpha, Alpha again a filler byte (0)
+ */
+
+/* 4:2:0 YUV planar to RGB/BGR */
+void ccvt_420p_bgr24(int width, int height, const void *src, void *dst);
+void ccvt_420p_rgb24(int width, int height, const void *src, void *dst);
+void ccvt_420p_bgr32(int width, int height, const void *src, void *dst);
+void ccvt_420p_rgb32(int width, int height, const void *src, void *dst);
+
+/* 4:2:2 YUYV interlaced to RGB/BGR */
+void ccvt_yuyv_rgb32(int width, int height, const void *src, void *dst);
+void ccvt_yuyv_bgr32(int width, int height, const void *src, void *dst);
+
+/* 4:2:2 YUYV interlaced to 4:2:0 YUV planar */
+void ccvt_yuyv_420p(int width, int height, const void *src, void *dsty, void *dstu, void *dstv);
+
+/* RGB/BGR to 4:2:0 YUV interlaced */
+
+/* RGB/BGR to 4:2:0 YUV planar */
+void ccvt_rgb24_420p(int width, int height, const void *src, void *dsty, void *dstu, void *dstv);
+void ccvt_bgr24_420p(int width, int height, const void *src, void *dsty, void *dstu, void *dstv);
+
+/* RGB/BGR to RGB/BGR */
+void ccvt_bgr24_bgr32(int width, int height, const void *const src, void *const dst);
+void ccvt_bgr24_rgb32(int width, int height, const void *const src, void *const dst);
+void ccvt_bgr32_bgr24(int width, int height, const void *const src, void *const dst);
+void ccvt_bgr32_rgb24(int width, int height, const void *const src, void *const dst);
+void ccvt_rgb24_bgr32(int width, int height, const void *const src, void *const dst);
+void ccvt_rgb24_rgb32(int width, int height, const void *const src, void *const dst);
+void ccvt_rgb32_bgr24(int width, int height, const void *const src, void *const dst);
+void ccvt_rgb32_rgb24(int width, int height, const void *const src, void *const dst);
+
+int RGB2YUV (int x_dim, int y_dim, void *bmp, void *y_out, void *u_out, void *v_out, int flip);
+
+/*
+ * BAYER2RGB24 ROUTINE TAKEN FROM:
+ *
+ * Sonix SN9C101 based webcam basic I/F routines
+ * Copyright (C) 2004 Takafumi Mizuno <taka-qce@ls-a.jp>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+void bayer2rgb24(unsigned char *dst, unsigned char *src, long int WIDTH, long int HEIGHT);
+
+#ifdef __cplusplus
+}
+#endif
+
+enum Options {
+ ioNoBlock=(1<<0),
+ ioUseSelect=(1<<1),
+ haveBrightness=(1<<2),
+ haveContrast=(1<<3),
+ haveHue=(1<<4),
+ haveColor=(1<<5),
+ haveWhiteness=(1<<6) };
+
+
+#endif
diff --git a/kstars/kstars/indi/webcam/ccvt_c2.c b/kstars/kstars/indi/webcam/ccvt_c2.c
new file mode 100644
index 00000000..52ed276d
--- /dev/null
+++ b/kstars/kstars/indi/webcam/ccvt_c2.c
@@ -0,0 +1,118 @@
+/*
+ * Convert an image from yuv colourspace to rgb
+ *
+ * Code by Tony Hague (C) 2001.
+ */
+
+#include "ccvt.h"
+#include "ccvt_types.h"
+
+/* by suitable definition of PIXTYPE, can do yuv to rgb or bgr, with or
+without word alignment */
+
+/* This doesn't exactly earn a prize in a programming beauty contest. */
+
+#define WHOLE_FUNC2RGB(type) \
+ const unsigned char *y1, *y2, *u, *v; \
+ PIXTYPE_##type *l1, *l2; \
+ int r, g, b, cr, cg, cb, yp, j, i; \
+ \
+ if ((width & 1) || (height & 1)) \
+ return; \
+ \
+ l1 = (PIXTYPE_##type *)dst; \
+ l2 = l1 + width; \
+ y1 = (unsigned char *)src; \
+ y2 = y1 + width; \
+ u = (unsigned char *)src + width * height; \
+ v = u + (width * height) / 4; \
+ j = height / 2; \
+ while (j--) { \
+ i = width / 2; \
+ while (i--) { \
+ /* Since U & V are valid for 4 pixels, repeat code 4 \
+ times for different Y */ \
+ cb = ((*u-128) * 454)>>8; \
+ cr = ((*v-128) * 359)>>8; \
+ cg = ((*v-128) * 183 + (*u-128) * 88)>>8; \
+ \
+ yp = *(y1++); \
+ r = yp + cr; \
+ b = yp + cb; \
+ g = yp - cg; \
+ SAT(r); \
+ SAT(g); \
+ SAT(b); \
+ l1->b = b; \
+ l1->g = g; \
+ l1->r = r; \
+ l1++; \
+ \
+ yp = *(y1++); \
+ r = yp + cr; \
+ b = yp + cb; \
+ g = yp - cg; \
+ SAT(r); \
+ SAT(g); \
+ SAT(b); \
+ l1->b = b; \
+ l1->g = g; \
+ l1->r = r; \
+ l1++; \
+ \
+ yp = *(y2++); \
+ r = yp + cr; \
+ b = yp + cb; \
+ g = yp - cg; \
+ SAT(r); \
+ SAT(g); \
+ SAT(b); \
+ l2->b = b; \
+ l2->g = g; \
+ l2->r = r; \
+ l2++; \
+ \
+ yp = *(y2++); \
+ r = yp + cr; \
+ b = yp + cb; \
+ g = yp - cg; \
+ SAT(r); \
+ SAT(g); \
+ SAT(b); \
+ l2->b = b; \
+ l2->g = g; \
+ l2->r = r; \
+ l2++; \
+ \
+ u++; \
+ v++; \
+ } \
+ y1 = y2; \
+ y2 += width; \
+ l1 = l2; \
+ l2 += width; \
+ }
+
+
+
+
+void ccvt_420p_bgr32(int width, int height, const void *src, void *dst)
+{
+ WHOLE_FUNC2RGB(bgr32)
+}
+
+void ccvt_420p_bgr24(int width, int height, const void *src, void *dst)
+{
+ WHOLE_FUNC2RGB(bgr24)
+}
+
+void ccvt_420p_rgb32(int width, int height, const void *src, void *dst)
+{
+ WHOLE_FUNC2RGB(rgb32)
+}
+
+void ccvt_420p_rgb24(int width, int height, const void *src, void *dst)
+{
+ WHOLE_FUNC2RGB(rgb24)
+}
+
diff --git a/kstars/kstars/indi/webcam/ccvt_misc.c b/kstars/kstars/indi/webcam/ccvt_misc.c
new file mode 100644
index 00000000..e774ca6d
--- /dev/null
+++ b/kstars/kstars/indi/webcam/ccvt_misc.c
@@ -0,0 +1,435 @@
+/* CCVT: ColourConVerT: simple library for converting colourspaces
+ Copyright (C) 2002 Nemosoft Unv.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ For questions, remarks, patches, etc. for this program, the author can be
+ reached at nemosoft@smcc.demon.nl.
+*/
+
+/* This file contains CCVT functions that aren't available in assembly yet
+ (or are not worth programming)
+ */
+
+/*
+ * $Log$
+ * Revision 1.2 2005/04/29 16:51:20 mutlaqja
+ * Adding initial support for Video 4 Linux 2 drivers. This mean that KStars can probably control Meade Lunar Planetary Imager (LPI). V4L2 requires a fairly recent kernel (> 2.6.9) and many drivers don't fully support it yet. It will take sometime. KStars still supports V4L1 and will continue so until V4L1 is obselete. Please test KStars video drivers if you can. Any comments welcomed.
+ *
+ * CCMAIL: kstars-devel@kde.org
+ *
+ * Revision 1.1 2004/06/26 23:12:03 mutlaqja
+ * Hopefully this will fix compile issues on 64bit archs, and FreeBSD, among others. The assembly code is replaced with a more portable, albeit slower C implementation. I imported the videodev.h header after cleaning it for user space.
+ *
+ * Anyone who has problems compiling this, please report the problem to kstars-devel@kde.org
+ *
+ * I noticed one odd thing after updating my kdelibs, the LEDs don't change color when state is changed. Try that by starting any INDI device, and hit connect, if the LED turns to yellow and back to grey then it works fine, otherwise, we've got a problem.
+ *
+ * CCMAIL: kstars-devel@kde.org
+ *
+ * Revision 1.7 2003/01/02 04:10:19 nemosoft
+ * Adding ''upside down" conversion to rgb/bgr routines
+ *
+ * Revision 1.6 2002/12/03 23:29:11 nemosoft
+ * *** empty log message ***
+ *
+ * Revision 1.5 2002/12/03 23:27:41 nemosoft
+ * fixing log messages (gcc 3.2 complaining)
+ *
+ Revision 1.4 2002/12/03 22:29:07 nemosoft
+ Fixing up FTP stuff and some video
+
+ Revision 1.3 2002/11/03 22:46:25 nemosoft
+ Adding various RGB to RGB functions.
+ Adding proper copyright header too.
+ */
+
+
+#include "ccvt.h"
+#include "ccvt_types.h"
+#include <stdlib.h>
+
+static float RGBYUV02990[256], RGBYUV05870[256], RGBYUV01140[256];
+static float RGBYUV01684[256], RGBYUV03316[256];
+static float RGBYUV04187[256], RGBYUV00813[256];
+
+void InitLookupTable(void);
+
+
+/* YUYV: two Y's and one U/V */
+void ccvt_yuyv_rgb32(int width, int height, const void *src, void *dst)
+{
+ width=width; height=height; src=src; dst=dst;
+
+}
+
+
+void ccvt_yuyv_bgr32(int width, int height, const void *src, void *dst)
+{
+ const unsigned char *s;
+ PIXTYPE_bgr32 *d;
+ int l, c;
+ int r, g, b, cr, cg, cb, y1, y2;
+
+ l = height;
+ s = src;
+ d = dst;
+ while (l--) {
+ c = width >> 2;
+ while (c--) {
+ y1 = *s++;
+ cb = ((*s - 128) * 454) >> 8;
+ cg = (*s++ - 128) * 88;
+ y2 = *s++;
+ cr = ((*s - 128) * 359) >> 8;
+ cg = (cg + (*s++ - 128) * 183) >> 8;
+
+ r = y1 + cr;
+ b = y1 + cb;
+ g = y1 - cg;
+ SAT(r);
+ SAT(g);
+ SAT(b);
+ d->b = b;
+ d->g = g;
+ d->r = r;
+ d++;
+ r = y2 + cr;
+ b = y2 + cb;
+ g = y2 - cg;
+ SAT(r);
+ SAT(g);
+ SAT(b);
+ d->b = b;
+ d->g = g;
+ d->r = r;
+ d++;
+ }
+ }
+
+}
+
+void ccvt_yuyv_420p(int width, int height, const void *src, void *dsty, void *dstu, void *dstv)
+{
+ int n, l, j;
+ const unsigned char *s1, *s2;
+ unsigned char *dy, *du, *dv;
+
+ dy = (unsigned char *)dsty;
+ du = (unsigned char *)dstu;
+ dv = (unsigned char *)dstv;
+ s1 = (unsigned char *)src;
+ s2 = s1; /* keep pointer */
+ n = width * height;
+ for (; n > 0; n--) {
+ *dy = *s1;
+ dy++;
+ s1 += 2;
+ }
+
+ /* Two options here: average U/V values, or skip every second row */
+ s1 = s2; /* restore pointer */
+ s1++; /* point to U */
+ for (l = 0; l < height; l += 2) {
+ s2 = s1 + width * 2; /* odd line */
+ for (j = 0; j < width; j += 2) {
+ *du = (*s1 + *s2) / 2;
+ du++;
+ s1 += 2;
+ s2 += 2;
+ *dv = (*s1 + *s2) / 2;
+ dv++;
+ s1 += 2;
+ s2 += 2;
+ }
+ s1 = s2;
+ }
+}
+
+void bayer2rgb24(unsigned char *dst, unsigned char *src, long int WIDTH, long int HEIGHT)
+{
+ long int i;
+ unsigned char *rawpt, *scanpt;
+ long int size;
+
+ rawpt = src;
+ scanpt = dst;
+ size = WIDTH*HEIGHT;
+
+ for ( i = 0; i < size; i++ ) {
+ if ( (i/WIDTH) % 2 == 0 ) {
+ if ( (i % 2) == 0 ) {
+ /* B */
+ if ( (i > WIDTH) && ((i % WIDTH) > 0) ) {
+ *scanpt++ = (*(rawpt-WIDTH-1)+*(rawpt-WIDTH+1)+
+ *(rawpt+WIDTH-1)+*(rawpt+WIDTH+1))/4; /* R */
+ *scanpt++ = (*(rawpt-1)+*(rawpt+1)+
+ *(rawpt+WIDTH)+*(rawpt-WIDTH))/4; /* G */
+ *scanpt++ = *rawpt; /* B */
+ } else {
+ /* first line or left column */
+ *scanpt++ = *(rawpt+WIDTH+1); /* R */
+ *scanpt++ = (*(rawpt+1)+*(rawpt+WIDTH))/2; /* G */
+ *scanpt++ = *rawpt; /* B */
+ }
+ } else {
+ /* (B)G */
+ if ( (i > WIDTH) && ((i % WIDTH) < (WIDTH-1)) ) {
+ *scanpt++ = (*(rawpt+WIDTH)+*(rawpt-WIDTH))/2; /* R */
+ *scanpt++ = *rawpt; /* G */
+ *scanpt++ = (*(rawpt-1)+*(rawpt+1))/2; /* B */
+ } else {
+ /* first line or right column */
+ *scanpt++ = *(rawpt+WIDTH); /* R */
+ *scanpt++ = *rawpt; /* G */
+ *scanpt++ = *(rawpt-1); /* B */
+ }
+ }
+ } else {
+ if ( (i % 2) == 0 ) {
+ /* G(R) */
+ if ( (i < (WIDTH*(HEIGHT-1))) && ((i % WIDTH) > 0) ) {
+ *scanpt++ = (*(rawpt-1)+*(rawpt+1))/2; /* R */
+ *scanpt++ = *rawpt; /* G */
+ *scanpt++ = (*(rawpt+WIDTH)+*(rawpt-WIDTH))/2; /* B */
+ } else {
+ /* bottom line or left column */
+ *scanpt++ = *(rawpt+1); /* R */
+ *scanpt++ = *rawpt; /* G */
+ *scanpt++ = *(rawpt-WIDTH); /* B */
+ }
+ } else {
+ /* R */
+ if ( i < (WIDTH*(HEIGHT-1)) && ((i % WIDTH) < (WIDTH-1)) ) {
+ *scanpt++ = *rawpt; /* R */
+ *scanpt++ = (*(rawpt-1)+*(rawpt+1)+
+ *(rawpt-WIDTH)+*(rawpt+WIDTH))/4; /* G */
+ *scanpt++ = (*(rawpt-WIDTH-1)+*(rawpt-WIDTH+1)+
+ *(rawpt+WIDTH-1)+*(rawpt+WIDTH+1))/4; /* B */
+ } else {
+ /* bottom line or right column */
+ *scanpt++ = *rawpt; /* R */
+ *scanpt++ = (*(rawpt-1)+*(rawpt-WIDTH))/2; /* G */
+ *scanpt++ = *(rawpt-WIDTH-1); /* B */
+ }
+ }
+ }
+ rawpt++;
+ }
+
+}
+
+/************************************************************************
+ *
+ * int RGB2YUV (int x_dim, int y_dim, void *bmp, YUV *yuv)
+ *
+ * Purpose : It takes a 24-bit RGB bitmap and convert it into
+ * YUV (4:2:0) format
+ *
+ * Input : x_dim the x dimension of the bitmap
+ * y_dim the y dimension of the bitmap
+ * bmp pointer to the buffer of the bitmap
+ * yuv pointer to the YUV structure
+ *
+ * Output : 0 OK
+ * 1 wrong dimension
+ * 2 memory allocation error
+ *
+ * Side Effect :
+ * None
+ *
+ * Date : 09/28/2000
+ *
+ * Contacts:
+ *
+ * Adam Li
+ *
+ * DivX Advance Research Center <darc@projectmayo.com>
+ *
+ ************************************************************************/
+
+int RGB2YUV (int x_dim, int y_dim, void *bmp, void *y_out, void *u_out, void *v_out, int flip)
+{
+ static int init_done = 0;
+
+ long i, j, size;
+ unsigned char *r, *g, *b;
+ unsigned char *y, *u, *v;
+ unsigned char *pu1, *pu2, *pv1, *pv2, *psu, *psv;
+ unsigned char *y_buffer, *u_buffer, *v_buffer;
+ unsigned char *sub_u_buf, *sub_v_buf;
+
+ if (init_done == 0)
+ {
+ InitLookupTable();
+ init_done = 1;
+ }
+
+ /* check to see if x_dim and y_dim are divisible by 2*/
+ if ((x_dim % 2) || (y_dim % 2)) return 1;
+ size = x_dim * y_dim;
+
+ /* allocate memory*/
+ y_buffer = (unsigned char *)y_out;
+ sub_u_buf = (unsigned char *)u_out;
+ sub_v_buf = (unsigned char *)v_out;
+ u_buffer = (unsigned char *)malloc(size * sizeof(unsigned char));
+ v_buffer = (unsigned char *)malloc(size * sizeof(unsigned char));
+ if (!(u_buffer && v_buffer))
+ {
+ if (u_buffer) free(u_buffer);
+ if (v_buffer) free(v_buffer);
+ return 2;
+ }
+
+ b = (unsigned char *)bmp;
+ y = y_buffer;
+ u = u_buffer;
+ v = v_buffer;
+
+ /* convert RGB to YUV*/
+ if (!flip) {
+ for (j = 0; j < y_dim; j ++)
+ {
+ y = y_buffer + (y_dim - j - 1) * x_dim;
+ u = u_buffer + (y_dim - j - 1) * x_dim;
+ v = v_buffer + (y_dim - j - 1) * x_dim;
+
+ for (i = 0; i < x_dim; i ++) {
+ g = b + 1;
+ r = b + 2;
+ *y = (unsigned char)( RGBYUV02990[*r] + RGBYUV05870[*g] + RGBYUV01140[*b]);
+ *u = (unsigned char)(- RGBYUV01684[*r] - RGBYUV03316[*g] + (*b)/2 + 128);
+ *v = (unsigned char)( (*r)/2 - RGBYUV04187[*g] - RGBYUV00813[*b] + 128);
+ b += 3;
+ y ++;
+ u ++;
+ v ++;
+ }
+ }
+ } else {
+ for (i = 0; i < size; i++)
+ {
+ g = b + 1;
+ r = b + 2;
+ *y = (unsigned char)( RGBYUV02990[*r] + RGBYUV05870[*g] + RGBYUV01140[*b]);
+ *u = (unsigned char)(- RGBYUV01684[*r] - RGBYUV03316[*g] + (*b)/2 + 128);
+ *v = (unsigned char)( (*r)/2 - RGBYUV04187[*g] - RGBYUV00813[*b] + 128);
+ b += 3;
+ y ++;
+ u ++;
+ v ++;
+ }
+ }
+
+ /* subsample UV*/
+ for (j = 0; j < y_dim/2; j ++)
+ {
+ psu = sub_u_buf + j * x_dim / 2;
+ psv = sub_v_buf + j * x_dim / 2;
+ pu1 = u_buffer + 2 * j * x_dim;
+ pu2 = u_buffer + (2 * j + 1) * x_dim;
+ pv1 = v_buffer + 2 * j * x_dim;
+ pv2 = v_buffer + (2 * j + 1) * x_dim;
+ for (i = 0; i < x_dim/2; i ++)
+ {
+ *psu = (*pu1 + *(pu1+1) + *pu2 + *(pu2+1)) / 4;
+ *psv = (*pv1 + *(pv1+1) + *pv2 + *(pv2+1)) / 4;
+ psu ++;
+ psv ++;
+ pu1 += 2;
+ pu2 += 2;
+ pv1 += 2;
+ pv2 += 2;
+ }
+ }
+
+ free(u_buffer);
+ free(v_buffer);
+
+ return 0;
+}
+
+
+void InitLookupTable()
+{
+ int i;
+
+ for (i = 0; i < 256; i++) RGBYUV02990[i] = (float)0.2990 * i;
+ for (i = 0; i < 256; i++) RGBYUV05870[i] = (float)0.5870 * i;
+ for (i = 0; i < 256; i++) RGBYUV01140[i] = (float)0.1140 * i;
+ for (i = 0; i < 256; i++) RGBYUV01684[i] = (float)0.1684 * i;
+ for (i = 0; i < 256; i++) RGBYUV03316[i] = (float)0.3316 * i;
+ for (i = 0; i < 256; i++) RGBYUV04187[i] = (float)0.4187 * i;
+ for (i = 0; i < 256; i++) RGBYUV00813[i] = (float)0.0813 * i;
+}
+
+
+/* RGB/BGR to RGB/BGR */
+
+#define RGBBGR_BODY24(TIN, TOUT) \
+void ccvt_ ## TIN ## _ ## TOUT (int width, int height, const void *const src, void *dst) \
+{ \
+ const PIXTYPE_ ## TIN *in = src; \
+ PIXTYPE_ ## TOUT *out = dst; \
+ int l, c, stride = 0; \
+ \
+ stride = width; \
+ out += ((height - 1) * width); \
+ stride *= 2; \
+ for (l = 0; l < height; l++) { \
+ for (c = 0; c < width; c++) { \
+ out->r = in->r; \
+ out->g = in->g; \
+ out->b = in->b; \
+ in++; \
+ out++; \
+ } \
+ out -= stride; \
+ } \
+}
+
+#define RGBBGR_BODY32(TIN, TOUT) \
+void ccvt_ ## TIN ## _ ## TOUT (int width, int height, const void *const src, void *dst) \
+{ \
+ const PIXTYPE_ ## TIN *in = src; \
+ PIXTYPE_ ## TOUT *out = dst; \
+ int l, c, stride = 0; \
+ \
+ stride = width;\
+ out += ((height - 1) * width); \
+ stride *= 2; \
+ for (l = 0; l < height; l++) { \
+ for (c = 0; c < width; c++) { \
+ out->r = in->r; \
+ out->g = in->g; \
+ out->b = in->b; \
+ out->z = 0; \
+ in++; \
+ out++; \
+ } \
+ out -= stride; \
+ } \
+}
+
+RGBBGR_BODY32(bgr24, bgr32)
+RGBBGR_BODY32(bgr24, rgb32)
+RGBBGR_BODY32(rgb24, bgr32)
+RGBBGR_BODY32(rgb24, rgb32)
+
+RGBBGR_BODY24(bgr32, bgr24)
+RGBBGR_BODY24(bgr32, rgb24)
+RGBBGR_BODY24(rgb32, bgr24)
+RGBBGR_BODY24(rgb32, rgb24)
diff --git a/kstars/kstars/indi/webcam/ccvt_types.h b/kstars/kstars/indi/webcam/ccvt_types.h
new file mode 100644
index 00000000..8e40f9fc
--- /dev/null
+++ b/kstars/kstars/indi/webcam/ccvt_types.h
@@ -0,0 +1,60 @@
+/* CCVT: ColourConVerT: simple library for converting colourspaces
+ Copyright (C) 2002 Nemosoft Unv.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ For questions, remarks, patches, etc. for this program, the author can be
+ reached at nemosoft@smcc.demon.nl.
+*/
+
+#ifndef CCVT_TYPES_H
+#define CCVT_TYPES_H
+
+typedef struct
+{
+ unsigned char b;
+ unsigned char g;
+ unsigned char r;
+ unsigned char z;
+} PIXTYPE_bgr32;
+
+typedef struct
+{
+ unsigned char b;
+ unsigned char g;
+ unsigned char r;
+} PIXTYPE_bgr24;
+
+typedef struct
+{
+ unsigned char r;
+ unsigned char g;
+ unsigned char b;
+ unsigned char z;
+} PIXTYPE_rgb32;
+
+typedef struct
+{
+ unsigned char r;
+ unsigned char g;
+ unsigned char b;
+} PIXTYPE_rgb24;
+
+#define SAT(c) \
+ if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
+
+
+
+#endif
diff --git a/kstars/kstars/indi/webcam/port.cpp b/kstars/kstars/indi/webcam/port.cpp
new file mode 100644
index 00000000..fce53a18
--- /dev/null
+++ b/kstars/kstars/indi/webcam/port.cpp
@@ -0,0 +1,199 @@
+/* libcqcam - shared Color Quickcam routines
+ * Copyright (C) 1996-1998 by Patrick Reynolds
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// I/O ports wrapper code
+// This file might need tweaking if you're trying to port my code to other
+// x86 Unix platforms. Code is already available for Linux, FreeBSD, and
+// QNX; see the Makefile.
+//
+// QNX code by: Anders Arpteg <aa11ac@hik.se>
+// FreeBSD code by: Patrick Reynolds <reynolds@cs.duke.edu> and Charles
+// Henrich <henrich@msu.edu>
+
+
+//#include "config.h"
+
+#include <stdio.h>
+#include <errno.h>
+
+#ifdef LOCKING
+#include <fcntl.h>
+#include <sys/stat.h>
+#endif /* LOCKING */
+
+#ifdef __linux__
+ #if defined(arm) || defined(__hppa__) || defined(__sparc__) || defined(__ppc__) || defined(__powerpc__) || defined(__s390__) || defined(__s390x__) || defined(__mips__) || defined(__mc68000__)
+ #include <fcntl.h>
+ #else
+ #include <sys/io.h>
+ #endif /* arm */
+#elif defined(QNX)
+#include <conio.h>
+#elif defined(__FreeBSD__)
+#include <sys/types.h>
+#include <machine/cpufunc.h>
+#elif defined(BSDI)
+#include <machine/inline.h>
+#elif defined(OPENBSD)
+#include <machine/pio.h>
+#elif defined(LYNX)
+#include "lynx-io.h"
+#elif defined(SOLARIS)
+#include "solaris-io.h"
+#else
+#error Please define a platform in the Makefile
+#endif /* which OS */
+
+#include "port.h"
+
+port_t::port_t(int iport) {
+ port = -1;
+
+#ifdef LOCKING
+ if (lock(iport) == -1) {
+#ifdef DEBUG
+ fprintf(stderr, "port 0x%x already locked\n", iport);
+#endif /* DEBUG */
+ return;
+ }
+#endif /* LOCKING */
+
+#ifdef LINUX
+#if defined(arm) || defined(__hppa__) || defined(__sparc__) || defined(__ppc__) || defined(__powerpc__) || defined(__s390__) || defined(__s390x__) || defined(__mips__) || defined(__mc68000__)
+ if ((devport = open("/dev/port", O_RDWR)) < 0) {
+ perror("open /dev/port");
+ return;
+ }
+#else
+ if (ioperm(iport, 3, 1) == -1) {
+ perror("ioperm()");
+ return;
+ }
+#endif /* arm */
+#elif defined(FREEBSD)
+ if ((devio = fopen("/dev/io", "r+")) == NULL) {
+ perror("fopen /dev/io");
+ return;
+ }
+#elif defined(OPENBSD)
+ if (i386_iopl(1) == -1) {
+ perror("i386_iopl");
+ return;
+ }
+#elif defined(LYNX)
+ if (io_access() < 0) {
+ perror("io_access");
+ return;
+ }
+#elif defined(SOLARIS)
+ if (openiop()) {
+ perror("openiop");
+ return;
+ }
+#endif /* which OS */
+
+ port = iport;
+ port1 = port + 1;
+ port2 = port + 2;
+ control_reg = read_control();
+}
+
+port_t::~port_t(void) {
+#ifdef LOCKING
+ unlock(port);
+#endif /* LOCKING */
+#ifdef LINUX
+#if defined(arm) || defined(__hppa__) || defined(__sparc__) || defined(__ppc__) || defined(__powerpc__) || defined(__s390__) || defined(__s390x__) || defined(__mips__) || defined(__mc68000__)
+ if (devport >= 0)
+ close(devport);
+#else
+ if (port > 0 && geteuid() == 0)
+ if (ioperm(port, 3, 0) != 0) // drop port permissions -- still must
+ // be root
+ perror("ioperm()");
+#endif /* arm */
+#elif defined(FREEBSD)
+ if (devio != NULL)
+ fclose(devio);
+#elif defined(SOLARIS)
+ close(iopfd);
+#endif /* which OS */
+}
+
+#ifdef LOCKING
+int port_t::lock(int portnum) {
+ char lockfile[80];
+ sprintf(lockfile, "/tmp/LOCK.qcam.0x%x", portnum);
+ while ((lock_fd = open(lockfile, O_WRONLY | O_CREAT | O_EXCL, 0600)) == -1) {
+ if (errno != EEXIST) {
+ perror(lockfile);
+ return -1;
+ }
+ struct stat stat_buf;
+ if (lstat(lockfile, &stat_buf) < 0) continue;
+ if (S_ISLNK(stat_buf.st_mode) || stat_buf.st_uid != 0) {
+ if (unlink(lockfile)) {
+ if (errno == ENOENT) continue;
+ if (errno != EISDIR || (rmdir(lockfile) && errno != ENOENT)) {
+ /* known problem: if lockfile exists and is a non-empty
+ directory, we give up instead of doing an rm-r of it */
+ perror(lockfile);
+ return -1;
+ }
+ }
+ continue;
+ }
+ lock_fd = open(lockfile, O_WRONLY, 0600);
+ if (lock_fd == -1) {
+ perror(lockfile);
+ return -1;
+ }
+ break;
+ }
+
+ static struct flock lock_info;
+ lock_info.l_type = F_WRLCK;
+#ifdef LOCK_FAIL
+ if (fcntl(lock_fd, F_SETLK, &lock_info) != 0) {
+#else
+ if (fcntl(lock_fd, F_SETLKW, &lock_info) != 0) {
+#endif /* LOCK_FAIL */
+ if (errno != EAGAIN)
+ perror("fcntl");
+ return -1;
+ }
+ chown(lockfile, getuid(), getgid());
+#ifdef DEBUG
+ fprintf(stderr, "Locked port 0x%x\n", portnum);
+#endif /* DEBUG */
+ return 0;
+}
+
+void port_t::unlock(int portnum) {
+ if (portnum == -1)
+ return;
+ close(lock_fd); // this clears the lock
+ char lockfile[80];
+ sprintf(lockfile, "/tmp/LOCK.qcam.0x%x", portnum);
+ if (unlink(lockfile)) perror(lockfile);
+#ifdef DEBUG
+ fprintf(stderr, "Unlocked port 0x%x\n", portnum);
+#endif /* DEBUG */
+}
+#endif /* LOCKING */
diff --git a/kstars/kstars/indi/webcam/port.h b/kstars/kstars/indi/webcam/port.h
new file mode 100644
index 00000000..c5896858
--- /dev/null
+++ b/kstars/kstars/indi/webcam/port.h
@@ -0,0 +1,122 @@
+/* libcqcam - shared Color Quickcam routines
+ * Copyright (C) 1996-1998 by Patrick Reynolds
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// I/O ports wrapper definitions and prototypes
+// This file might need tweaking if you're trying to port my code to other
+// x86 Unix platforms. Code is already available for Linux, FreeBSD, and
+// QNX; see the Makefile.
+//
+// QNX code by: Anders Arpteg <aa11ac@hik.se>
+// FreeBSD code by: Patrick Reynolds <reynolds@cs.duke.edu> and Charles
+// Henrich <henrich@msu.edu>
+// Inlining implemented by: Philip Blundell <philip.blundell@pobox.com>
+
+#ifndef PORT_H
+#define PORT_H
+
+//#include "config.h"
+
+#include <unistd.h>
+
+#ifdef __linux__
+ #if !defined(arm) && !defined(__hppa__) && !defined(__sparc__) && !defined(__ppc__) && !defined(__powerpc__) && !defined(__s390__) && !defined(__s390x__) && !defined(__mips__) && !defined(__mc68000__)
+ #include <sys/io.h>
+ #endif /* !arm */
+#elif defined(QNX)
+#include <conio.h>
+#elif defined(__FreeBSD__)
+#include <machine/cpufunc.h>
+#include <stdio.h>
+#elif defined(BSDI)
+#include <machine/inline.h>
+#elif defined(OPENBSD)
+#include <machine/pio.h>
+#elif defined(LYNX)
+#include "lynx-io.h"
+#elif defined(SOLARIS)
+#include "solaris-io.h"
+#else
+#error Please define a platform in the Makefile
+#endif
+
+#if defined(arm) || defined(__hppa__) || defined(__sparc__) || defined(__ppc__) || defined(__powerpc__) || defined(__s390__) || defined(__s390x__) || defined(__mips__) || defined(__mc68000__)
+static char ports_temp;
+
+#ifdef inb
+#undef inb
+#endif /* inb */
+#define inb(port) \
+ lseek(devport, port, SEEK_SET), \
+ read(devport, &ports_temp, 1), \
+ ports_temp
+
+#ifdef outb
+#undef outb
+#endif /* inb */
+#define outb(data, port) \
+ lseek(devport, port, SEEK_SET); \
+ ports_temp = data; \
+ write(devport, &ports_temp, 1);
+
+#endif /* arm, hppa */
+
+class port_t {
+public:
+ port_t(int iport);
+ ~port_t(void);
+
+ inline int read_data(void) { return inb(port); }
+ inline int read_status(void) { return inb(port1); }
+ inline int read_control(void) { return inb(port2); }
+
+#if defined(LINUX) || defined(LYNX)
+ inline void write_data(int data) { outb(data, port); }
+ inline void write_control(int data) { outb(control_reg = data, port2); }
+ inline void setbit_control(int data) { outb(control_reg |= data, port2); }
+ inline void clearbit_control(int data) { outb(control_reg &= ~data, port2); }
+#else // Solaris, QNX, and *BSD use (port, data) instead
+ inline void write_data(int data) { outb(port, data); }
+ inline void write_control(int data) { outb(port2, control_reg = data); }
+ inline void setbit_control(int data) { outb(port2, control_reg |= data); }
+ inline void clearbit_control(int data) { outb(port2, control_reg &= ~data); }
+#endif
+
+ inline int get_port() { return port; }
+ inline operator bool () const { return port != -1; }
+
+private:
+ int port; // number of the base port
+ int port1; // port+1, precalculated for speed
+ int port2; // port+2, precalculated for speed
+ int control_reg; // current contents of the control register
+#ifdef LOCKING
+ int lock_fd;
+ int lock(int portnum);
+ void unlock(int portnum);
+#endif
+
+#ifdef FREEBSD
+ FILE *devio;
+#endif
+#if defined(__linux__) && (defined(arm) || defined(__hppa__) || defined(__sparc__) || defined(__ppc__) || defined(__powerpc__) || defined(__s390__) || defined(__s390x__) || defined(__mips__) || defined(__mc68000__))
+ int devport;
+#endif
+};
+
+#endif
diff --git a/kstars/kstars/indi/webcam/pwc-ioctl.h b/kstars/kstars/indi/webcam/pwc-ioctl.h
new file mode 100644
index 00000000..9b650298
--- /dev/null
+++ b/kstars/kstars/indi/webcam/pwc-ioctl.h
@@ -0,0 +1,176 @@
+#ifndef PWC_IOCTL_H
+#define PWC_IOCTL_H
+
+/* (C) 2001-2002 Nemosoft Unv. webcam@smcc.demon.nl
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/* This is pwc-ioctl.h belonging to PWC 8.6 */
+
+/*
+ Changes
+ 2001/08/03 Alvarado Added ioctl constants to access methods for
+ changing white balance and red/blue gains
+ */
+
+/* These are private ioctl() commands, specific for the Philips webcams.
+ They contain functions not found in other webcams, and settings not
+ specified in the Video4Linux API.
+
+ The #define names are built up like follows:
+ VIDIOC VIDeo IOCtl prefix
+ PWC Philps WebCam
+ G optional: Get
+ S optional: Set
+ ... the function
+ */
+
+
+
+
+/* The frame rate is encoded in the video_window.flags parameter using
+ the upper 16 bits, since some flags are defined nowadays. The following
+ defines provide a mask and shift to filter out this value.
+
+ In 'Snapshot' mode the camera freezes its automatic exposure and colour
+ balance controls.
+ */
+#define PWC_FPS_SHIFT 16
+#define PWC_FPS_MASK 0x00FF0000
+#define PWC_FPS_FRMASK 0x003F0000
+#define PWC_FPS_SNAPSHOT 0x00400000
+
+
+
+struct pwc_probe
+{
+ char name[32];
+ int type;
+};
+
+
+/* pwc_whitebalance.mode values */
+#define PWC_WB_INDOOR 0
+#define PWC_WB_OUTDOOR 1
+#define PWC_WB_FL 2
+#define PWC_WB_MANUAL 3
+#define PWC_WB_AUTO 4
+
+/* Used with VIDIOCPWC[SG]AWB (Auto White Balance).
+ Set mode to one of the PWC_WB_* values above.
+ *red and *blue are the respective gains of these colour components inside
+ the camera; range 0..65535
+ When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read;
+ otherwise undefined.
+ 'read_red' and 'read_blue' are read-only.
+*/
+
+struct pwc_whitebalance
+{
+ int mode;
+ int manual_red, manual_blue; /* R/W */
+ int read_red, read_blue; /* R/O */
+};
+
+/*
+ 'control_speed' and 'control_delay' are used in automatic whitebalance mode,
+ and tell the camera how fast it should react to changes in lighting, and
+ with how much delay. Valid values are 0..65535.
+*/
+struct pwc_wb_speed
+{
+ int control_speed;
+ int control_delay;
+
+};
+
+/* Used with VIDIOCPWC[SG]LED */
+struct pwc_leds
+{
+ int led_on; /* Led on-time; range = 0..25000 */
+ int led_off; /* Led off-time; range = 0..25000 */
+};
+
+
+
+ /* Restore user settings */
+#define VIDIOCPWCRUSER _IO('v', 192)
+ /* Save user settings */
+#define VIDIOCPWCSUSER _IO('v', 193)
+ /* Restore factory settings */
+#define VIDIOCPWCFACTORY _IO('v', 194)
+
+ /* You can manipulate the compression factor. A compression preference of 0
+ means use uncompressed modes when available; 1 is low compression, 2 is
+ medium and 3 is high compression preferred. Of course, the higher the
+ compression, the lower the bandwidth used but more chance of artefacts
+ in the image. The driver automatically chooses a higher compression when
+ the preferred mode is not available.
+ */
+ /* Set preferred compression quality (0 = uncompressed, 3 = highest compression) */
+#define VIDIOCPWCSCQUAL _IOW('v', 195, int)
+ /* Get preferred compression quality */
+#define VIDIOCPWCGCQUAL _IOR('v', 195, int)
+
+
+ /* This is a probe function; since so many devices are supported, it
+ becomes difficult to include all the names in programs that want to
+ check for the enhanced Philips stuff. So in stead, try this PROBE;
+ it returns a structure with the original name, and the corresponding
+ Philips type.
+ To use, fill the structure with zeroes, call PROBE and if that succeeds,
+ compare the name with that returned from VIDIOCGCAP; they should be the
+ same. If so, you can be assured it is a Philips (OEM) cam and the type
+ is valid.
+ */
+#define VIDIOCPWCPROBE _IOR('v', 199, struct pwc_probe)
+
+ /* Set AGC (Automatic Gain Control); int < 0 = auto, 0..65535 = fixed */
+#define VIDIOCPWCSAGC _IOW('v', 200, int)
+ /* Get AGC; int < 0 = auto; >= 0 = fixed, range 0..65535 */
+#define VIDIOCPWCGAGC _IOR('v', 200, int)
+ /* Set shutter speed; int < 0 = auto; >= 0 = fixed, range 0..65535 */
+#define VIDIOCPWCSSHUTTER _IOW('v', 201, int)
+
+ /* Color compensation (Auto White Balance) */
+#define VIDIOCPWCSAWB _IOW('v', 202, struct pwc_whitebalance)
+#define VIDIOCPWCGAWB _IOR('v', 202, struct pwc_whitebalance)
+
+ /* Auto WB speed */
+#define VIDIOCPWCSAWBSPEED _IOW('v', 203, struct pwc_wb_speed)
+#define VIDIOCPWCGAWBSPEED _IOR('v', 203, struct pwc_wb_speed)
+
+ /* LEDs on/off/blink; int range 0..65535 */
+#define VIDIOCPWCSLED _IOW('v', 205, struct pwc_leds)
+#define VIDIOCPWCGLED _IOR('v', 205, struct pwc_leds)
+
+ /* Contour (sharpness); int < 0 = auto, 0..65536 = fixed */
+#define VIDIOCPWCSCONTOUR _IOW('v', 206, int)
+#define VIDIOCPWCGCONTOUR _IOR('v', 206, int)
+
+ /* Backlight compensation; 0 = off, otherwise on */
+#define VIDIOCPWCSBACKLIGHT _IOW('v', 207, int)
+#define VIDIOCPWCGBACKLIGHT _IOR('v', 207, int)
+
+ /* Flickerless mode; = 0 off, otherwise on */
+#define VIDIOCPWCSFLICKER _IOW('v', 208, int)
+#define VIDIOCPWCGFLICKER _IOR('v', 208, int)
+
+ /* Dynamic noise reduction; 0 off, 3 = high noise reduction */
+#define VIDIOCPWCSDYNNOISE _IOW('v', 209, int)
+#define VIDIOCPWCGDYNNOISE _IOR('v', 209, int)
+
+#endif
diff --git a/kstars/kstars/indi/webcam/v4l1_base.cpp b/kstars/kstars/indi/webcam/v4l1_base.cpp
new file mode 100644
index 00000000..12007870
--- /dev/null
+++ b/kstars/kstars/indi/webcam/v4l1_base.cpp
@@ -0,0 +1,564 @@
+/*
+ Copyright (C) 2005 by Jasem Mutlaq
+
+ Some code based on qastrocam
+
+ This library 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 library 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 library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#include <iostream>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <string.h>
+
+#include "ccvt.h"
+#include "v4l1_base.h"
+#include "../eventloop.h"
+#include "../indidevapi.h"
+
+#define ERRMSGSIZ 1024
+
+using namespace std;
+
+V4L1_Base::V4L1_Base()
+{
+ frameRate=10;
+ fd=-1;
+ //usingTimer = false;
+
+ //frameUpdate = true;
+ //selectCallBackID = -1;
+ //timerCallBackID = -1;
+
+ YBuf = NULL;
+ UBuf = NULL;
+ VBuf = NULL;
+ colorBuffer= NULL;
+ buffer_start=NULL;
+
+}
+
+V4L1_Base::~V4L1_Base()
+{
+
+ delete (YBuf);
+ delete (UBuf);
+ delete (VBuf);
+ delete (colorBuffer);
+
+}
+
+int V4L1_Base::connectCam(const char * devpath, char *errmsg)
+{
+ options= (haveBrightness|haveContrast|haveHue|haveColor|haveWhiteness);
+
+ buffer_start=NULL;
+ frameRate=10;
+ fd=-1;
+ //usingTimer = false;
+
+ //frameUpdate = true;
+ //selectCallBackID = -1;
+ //timerCallBackID = -1;
+
+ cerr << "In connect Cam with device " << devpath << endl;
+ if (-1 == (fd=open(devpath, O_RDONLY | O_NONBLOCK, 0)))
+ {
+ strncpy(errmsg, strerror(errno), ERRMSGSIZ);
+ cerr << strerror(errno);
+ return -1;
+ }
+
+ cerr << "Device opened" << endl;
+
+ if (fd != -1)
+ {
+ if (-1 == ioctl(fd,VIDIOCGCAP,&capability))
+ {
+ cerr << "Error: ioctl (VIDIOCGCAP)" << endl;
+ strncpy(errmsg, "ioctl (VIDIOCGCAP)", ERRMSGSIZ);
+ return -1;
+ }
+ if (-1 == ioctl (fd, VIDIOCGWIN, &window))
+ {
+ cerr << "Error ioctl (VIDIOCGWIN)" << endl;
+ strncpy(errmsg, "ioctl (VIDIOCGWIN)", ERRMSGSIZ);
+ return -1;
+ }
+ if (-1 == ioctl (fd, VIDIOCGPICT, &picture_format))
+ {
+ cerr << "Error: ioctl (VIDIOCGPICT)" << endl;
+ strncpy(errmsg, "ioctl (VIDIOCGPICT)", ERRMSGSIZ);
+ return -1;
+ }
+
+ init(0);
+ }
+
+ cerr << "initial size w:" << window.width << " -- h: " << window.height << endl;
+
+ /*if (options & ioUseSelect)
+ {
+ selectCallBackID = addCallback(fd, V4L1_Base::staticUpdateFrame, this);
+ cerr << "Using select to wait new frames." << endl;
+ } else
+ {
+ usingTimer = true;
+ timerCallBackID = addTimer(1000/frameRate, V4L1_Base::staticCallFrame, this);
+ cerr << "Using timer to wait new frames.\n";
+ }
+ */
+
+ mmapInit();
+ //mmapCapture();
+
+ cerr << "All successful, returning\n";
+ return fd;
+}
+
+void V4L1_Base::disconnectCam()
+{
+
+
+ delete YBuf;
+ delete UBuf;
+ delete VBuf;
+ YBuf = UBuf = VBuf = NULL;
+
+ if (selectCallBackID != -1)
+ rmCallback(selectCallBackID);
+
+ //if (usingTimer && timerCallBackID != -1)
+ //rmTimer(timerCallBackID);
+
+ if (munmap (buffer_start, mmap_buffer.size) < 0)
+ fprintf(stderr, "munmap: %s\n", strerror(errno));
+
+ if (close(fd) < 0)
+ fprintf(stderr, "close(fd): %s\n", strerror(errno));
+
+ fprintf(stderr, "Disconnect cam\n");
+}
+
+//void V4L1_Base::staticCallFrame(void *p)
+//{
+// ((V4L1_Base *) p)->updateFrame(0, NULL);
+//}
+
+//void V4L1_Base::staticUpdateFrame(int /*d*/, void *p)
+//{
+// ((V4L1_Base *) p)->updateFrame(0, NULL);
+//}
+
+void V4L1_Base::newFrame()
+{
+ switch (picture_format.palette)
+ {
+ case VIDEO_PALETTE_GREY:
+ memcpy(YBuf,mmapFrame(),window.width * window.height);
+ break;
+ case VIDEO_PALETTE_YUV420P:
+ memcpy(YBuf,mmapFrame(), window.width * window.height);
+ memcpy(UBuf,
+ mmapFrame()+ window.width * window.height,
+ (window.width/2) * (window.height/2));
+ memcpy(VBuf,
+ mmapFrame()+ window.width * window.height+(window.width/2) * (window.height/2),
+ (window.width/2) * (window.height/2));
+ break;
+ case VIDEO_PALETTE_YUYV:
+ ccvt_yuyv_420p(window.width,window.height,
+ mmapFrame(),
+ YBuf,
+ UBuf,
+ VBuf);
+ break;
+
+ case VIDEO_PALETTE_RGB24:
+ RGB2YUV(window.width, window.height, mmapFrame(), YBuf, UBuf, VBuf, 0);
+ break;
+
+ default:
+ cerr << "invalid palette " <<picture_format.palette << endl;
+ exit(1);
+ }
+
+
+ if (callback)
+ (*callback)(uptr);
+
+}
+
+void V4L1_Base::updateFrame(int /*d*/, void * p)
+{
+
+ ( (V4L1_Base *) (p))->newFrame();
+
+}
+
+int V4L1_Base::start_capturing(char * /*errmsg*/)
+{
+
+ mmapCapture();
+ mmapSync();
+
+ selectCallBackID = IEAddCallback(fd, updateFrame, this);
+ //newFrame();
+ return 0;
+}
+
+int V4L1_Base::stop_capturing(char * /*errmsg*/)
+{
+
+ IERmCallback(selectCallBackID);
+ selectCallBackID = -1;
+ return 0;
+}
+
+int V4L1_Base::getWidth()
+{
+ return window.width;
+}
+
+int V4L1_Base::getHeight()
+{
+ return window.height;
+}
+
+void V4L1_Base::setFPS(int fps)
+{
+ frameRate = fps;
+}
+
+int V4L1_Base::getFPS()
+{
+ return frameRate;
+}
+
+char * V4L1_Base::getDeviceName()
+{
+ return capability.name;
+}
+
+void V4L1_Base::init(int preferedPalette)
+ {
+
+ if (preferedPalette)
+ {
+ picture_format.palette=preferedPalette;
+ if (0 == ioctl(fd, VIDIOCSPICT, &picture_format))
+ cerr << "found preferedPalette " << preferedPalette << endl;
+ else
+ {
+ preferedPalette=0;
+ cerr << "preferedPalette " << preferedPalette << " invalid, trying to find one." << endl;
+ }
+ }
+
+ if (preferedPalette == 0)
+ {
+ do {
+ /* trying VIDEO_PALETTE_YUV420P (Planar) */
+ picture_format.palette=VIDEO_PALETTE_YUV420P;
+ if (0 == ioctl(fd, VIDIOCSPICT, &picture_format)) {
+ cerr << "found palette VIDEO_PALETTE_YUV420P" << endl;
+ break;
+ }
+ cerr << "VIDEO_PALETTE_YUV420P not supported." << endl;
+ /* trying VIDEO_PALETTE_YUV420 (interlaced) */
+ picture_format.palette=VIDEO_PALETTE_YUV420;
+ if ( 0== ioctl(fd, VIDIOCSPICT, &picture_format)) {
+ cerr << "found palette VIDEO_PALETTE_YUV420" << endl;
+ break;
+ }
+ cerr << "VIDEO_PALETTE_YUV420 not supported." << endl;
+ /* trying VIDEO_PALETTE_RGB24 */
+ picture_format.palette=VIDEO_PALETTE_RGB24;
+ if ( 0== ioctl(fd, VIDIOCSPICT, &picture_format)) {
+ cerr << "found palette VIDEO_PALETTE_RGB24" << endl;
+ break;
+ }
+ cerr << "VIDEO_PALETTE_RGB24 not supported." << endl;
+ /* trying VIDEO_PALETTE_GREY */
+ picture_format.palette=VIDEO_PALETTE_GREY;
+ if ( 0== ioctl(fd, VIDIOCSPICT, &picture_format)) {
+ cerr << "found palette VIDEO_PALETTE_GREY" << endl;
+ break;
+ }
+ cerr << "VIDEO_PALETTE_GREY not supported." << endl;
+ cerr << "could not find a supported palette." << endl;
+ exit(1);
+ } while (false);
+ }
+
+ allocBuffers();
+
+}
+
+void V4L1_Base::allocBuffers()
+{
+ delete YBuf;
+ delete UBuf;
+ delete VBuf;
+ delete colorBuffer;
+
+ YBuf= new unsigned char[window.width * window.height];
+ UBuf= new unsigned char[window.width * window.height];
+ VBuf= new unsigned char[window.width * window.height];
+ colorBuffer = new unsigned char[window.width * window.height * 4];
+}
+
+void V4L1_Base::checkSize(int & x, int & y)
+{
+ if (x >= capability.maxwidth && y >= capability.maxheight)
+ {
+ x=capability.maxwidth;
+ y=capability.maxheight;
+ }
+ else if (x>=352 && y >=288) {
+ x=352;y=288;
+ } else if (x>=320 && y >= 240) {
+ x=320;y=240;
+ } else if (x>=176 && y >=144) {
+ x=176;y=144;
+ } else if (x>=160 && y >=120 ) {
+ x=160;y=120;
+ } else
+ {
+ x=capability.minwidth;
+ y=capability.minheight;
+ }
+}
+
+void V4L1_Base::getMaxMinSize(int & xmax, int & ymax, int & xmin, int & ymin)
+{
+ xmax = capability.maxwidth;
+ ymax = capability.maxheight;
+ xmin = capability.minwidth;
+ ymin = capability.minheight;
+}
+
+bool V4L1_Base::setSize(int x, int y)
+{
+ int oldX, oldY;
+ checkSize(x,y);
+
+ oldX = window.width;
+ oldY = window.height;
+
+ window.width=x;
+ window.height=y;
+
+ cerr << "New size is x=" << window.width << " " << "y=" << window.height <<endl;
+
+ if (ioctl (fd, VIDIOCSWIN, &window))
+ {
+ cerr << "ioctl(VIDIOCSWIN)" << endl;
+ window.width=oldX;
+ window.height=oldY;
+ return false;
+ }
+ ioctl (fd, VIDIOCGWIN, &window);
+
+ allocBuffers();
+
+ return true;
+}
+
+void V4L1_Base::setContrast(int val)
+{
+ picture_format.contrast=val;
+ setPictureSettings();
+}
+
+int V4L1_Base::getContrast()
+{
+ return picture_format.contrast;
+}
+
+void V4L1_Base::setBrightness(int val)
+{
+ picture_format.brightness=val;
+ setPictureSettings();
+}
+
+int V4L1_Base::getBrightness()
+{
+ return picture_format.brightness;
+}
+
+void V4L1_Base::setColor(int val)
+{
+ picture_format.colour=val;
+ setPictureSettings();
+}
+
+int V4L1_Base::getColor()
+{
+ return picture_format.colour;
+}
+
+void V4L1_Base::setHue(int val)
+{
+ picture_format.hue=val;
+ setPictureSettings();
+}
+
+int V4L1_Base::getHue()
+{
+ return picture_format.hue;
+}
+
+void V4L1_Base::setWhiteness(int val)
+{
+ picture_format.whiteness=val;
+ setPictureSettings();
+}
+
+int V4L1_Base::getWhiteness()
+{
+ return picture_format.whiteness;
+}
+
+void V4L1_Base::setPictureSettings()
+{
+ if (ioctl(fd, VIDIOCSPICT, &picture_format) ) {
+ cerr << "setPictureSettings" << endl;
+ }
+ ioctl(fd, VIDIOCGPICT, &picture_format);
+}
+
+void V4L1_Base::getPictureSettings()
+{
+ if (ioctl(fd, VIDIOCGPICT, &picture_format) )
+ {
+ cerr << "getPictureSettings" << endl;
+ }
+}
+
+int V4L1_Base::mmapInit()
+{
+ mmap_buffer.size = 0;
+ mmap_buffer.frames = 0;
+
+ mmap_sync_buffer=-1;
+ mmap_capture_buffer=-1;
+ buffer_start=NULL;
+
+ if (ioctl(fd, VIDIOCGMBUF, &mmap_buffer)) {
+ // mmap not supported
+ return -1;
+ }
+
+ buffer_start = (unsigned char *) mmap (NULL, mmap_buffer.size, PROT_READ, MAP_SHARED, fd, 0);
+
+ if (buffer_start == MAP_FAILED)
+ {
+ cerr << "mmap" << endl;
+ mmap_buffer.size = 0;
+ mmap_buffer.frames = 0;
+ buffer_start=NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+void V4L1_Base::mmapCapture()
+{
+
+ struct video_mmap vm;
+ mmap_capture_buffer = (mmap_capture_buffer + 1) % mmap_buffer.frames;
+
+ vm.frame = mmap_capture_buffer;
+ vm.format = picture_format.palette;
+ vm.width = window.width;
+ vm.height = window.height;
+
+ if (ioctl(fd, VIDIOCMCAPTURE, &vm) < 0)
+ cerr << "Error V4L1_Base::mmapCapture" << endl;
+}
+
+void V4L1_Base::mmapSync()
+{
+ mmap_sync_buffer= (mmap_sync_buffer + 1) % mmap_buffer.frames;
+
+ if (ioctl(fd, VIDIOCSYNC, &mmap_sync_buffer) < 0)
+ cerr << "Error V4L1_Base::mmapSync()" << endl;
+}
+
+unsigned char * V4L1_Base::mmapFrame()
+{
+ return (buffer_start + mmap_buffer.offsets[mmap_sync_buffer]);
+}
+
+unsigned char * V4L1_Base::getY()
+{
+ return YBuf;
+}
+
+unsigned char * V4L1_Base::getU()
+{
+ return UBuf;
+}
+
+unsigned char * V4L1_Base::getV()
+{
+ return VBuf;
+}
+
+unsigned char * V4L1_Base::getColorBuffer()
+{
+ //cerr << "in get color buffer " << endl;
+
+ switch (picture_format.palette)
+ {
+ case VIDEO_PALETTE_YUV420P:
+ ccvt_420p_bgr32(window.width, window.height,
+ mmapFrame(), (void*)colorBuffer);
+ break;
+
+ case VIDEO_PALETTE_YUYV:
+ ccvt_yuyv_bgr32(window.width, window.height,
+ mmapFrame(), (void*)colorBuffer);
+ break;
+
+ case VIDEO_PALETTE_RGB24:
+ ccvt_rgb24_bgr32(window.width, window.height,
+ mmapFrame(), (void*)colorBuffer);
+ break;
+
+ default:
+ break;
+ }
+
+
+ return colorBuffer;
+
+}
+
+void V4L1_Base::registerCallback(WPF *fp, void *ud)
+{
+ callback = fp;
+ uptr = ud;
+}
diff --git a/kstars/kstars/indi/webcam/v4l1_base.h b/kstars/kstars/indi/webcam/v4l1_base.h
new file mode 100644
index 00000000..7a7c93f9
--- /dev/null
+++ b/kstars/kstars/indi/webcam/v4l1_base.h
@@ -0,0 +1,110 @@
+/*
+ Copyright (C) 2005 by Jasem Mutlaq
+
+ Some code based on qastrocam
+
+ This library 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 library 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 library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#ifndef V4L1_BASE_H
+#define V4L1_BASE_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "videodev.h"
+#include "../eventloop.h"
+
+class V4L1_Base
+{
+ public:
+ V4L1_Base();
+ virtual ~V4L1_Base();
+
+ /* Connection */
+ virtual int connectCam(const char * devpath, char *errmsg);
+ virtual void disconnectCam();
+ char * getDeviceName();
+
+ /* Image settings */
+ int getBrightness();
+ int getContrast();
+ int getColor();
+ int getHue();
+ int getWhiteness();
+ void setContrast(int val);
+ void setBrightness(int val);
+ void setColor(int val);
+ void setHue(int val);
+ void setWhiteness(int val);
+
+ /* Updates */
+ static void updateFrame(int d, void * p);
+ void newFrame();
+ void setPictureSettings();
+ void getPictureSettings();
+
+ /* Image Size */
+ int getWidth();
+ int getHeight();
+ void checkSize(int & x, int & y);
+ virtual bool setSize(int x, int y);
+ virtual void getMaxMinSize(int & xmax, int & ymax, int & xmin, int & ymin);
+
+ /* Frame rate */
+ void setFPS(int fps);
+ int getFPS();
+
+ void init(int preferedPalette);
+ void allocBuffers();
+ int mmapInit();
+ void mmapCapture();
+ void mmapSync();
+
+ unsigned char * mmapFrame();
+ unsigned char * getY();
+ unsigned char * getU();
+ unsigned char * getV();
+ unsigned char * getColorBuffer();
+
+ int start_capturing(char *errmsg);
+ int stop_capturing(char *errmsg);
+ void registerCallback(WPF *fp, void *ud);
+
+ protected:
+
+ int fd;
+ WPF *callback;
+ void *uptr;
+ unsigned long options;
+
+ struct video_capability capability;
+ struct video_window window;
+ struct video_picture picture_format;
+ struct video_mbuf mmap_buffer;
+
+ unsigned char * buffer_start;
+
+ long mmap_sync_buffer;
+ long mmap_capture_buffer;
+
+ int frameRate;
+ bool streamActive;
+ int selectCallBackID;
+ unsigned char * YBuf,*UBuf,*VBuf, *colorBuffer;
+
+};
+
+#endif
diff --git a/kstars/kstars/indi/webcam/v4l1_pwc.cpp b/kstars/kstars/indi/webcam/v4l1_pwc.cpp
new file mode 100644
index 00000000..9f644885
--- /dev/null
+++ b/kstars/kstars/indi/webcam/v4l1_pwc.cpp
@@ -0,0 +1,563 @@
+/*
+ Phlips webcam driver for V4L 1
+ Copyright (C) 2005 by Jasem Mutlaq
+
+ This library 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 library 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 library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#include <iostream>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <string.h>
+
+#include "ccvt.h"
+#include "pwc-ioctl.h"
+#include "v4l1_pwc.h"
+#include "../eventloop.h"
+
+#define ERRMSG_SIZ 1024
+
+extern int errno;
+using namespace std;
+
+V4L1_PWC::V4L1_PWC()
+{
+ frameRate=15;
+ fd=-1;
+ streamActive = true;
+
+ YBuf = NULL;
+ UBuf = NULL;
+ VBuf = NULL;
+ colorBuffer= NULL;
+ buffer_start=NULL;
+}
+
+V4L1_PWC::~V4L1_PWC()
+{
+
+}
+
+int V4L1_PWC::connectCam(const char * devpath, char *errmsg)
+{
+ options= (ioNoBlock|ioUseSelect|haveBrightness|haveContrast|haveColor);
+ struct pwc_probe probe;
+ bool IsPhilips = false;
+ frameRate=15;
+ fd=-1;
+ streamActive = true;
+ buffer_start=NULL;
+
+ if (-1 == (fd=open(devpath,
+ O_RDONLY | ((options & ioNoBlock) ? O_NONBLOCK : 0)))) {
+
+ strncpy(errmsg, strerror(errno), 1024);
+ cerr << strerror(errno);
+ return -1;
+ }
+
+ cerr << "Device opened" << endl;
+
+ if (fd != -1) {
+ if (-1 == ioctl(fd,VIDIOCGCAP,&capability)) {
+ cerr << "Error: ioctl (VIDIOCGCAP)" << endl;
+ strncpy(errmsg, "ioctl (VIDIOCGCAP)", 1024);
+ return -1;
+ }
+ if (-1 == ioctl (fd, VIDIOCGWIN, &window)) {
+ cerr << "Error: ioctl (VIDIOCGWIN)" << endl;
+ strncpy(errmsg, "ioctl (VIDIOCGWIN)", 1024);
+ return -1;
+ }
+ if (-1 == ioctl (fd, VIDIOCGPICT, &picture_format)) {
+ cerr << "Error: ioctl (VIDIOCGPICT)" << endl;
+ strncpy(errmsg, "ioctl (VIDIOCGPICT)", 1024);
+ return -1;
+ }
+ init(0);
+ }
+
+ // Check to see if it's really a philips webcam
+ if (ioctl(fd, VIDIOCPWCPROBE, &probe) == 0)
+ {
+ if (!strcmp(capability.name,probe.name))
+ {
+ IsPhilips = true;
+ type_=probe.type;
+ }
+ }
+
+ if (IsPhilips)
+ cerr << "Philips webcam type " << type_ << " detected" << endl;
+ else
+ {
+ strncpy(errmsg, "No Philips webcam detected.", 1024);
+ return -1;
+ }
+
+ cerr << "initial size w:" << window.width << " -- h: " << window.height << endl;
+
+
+ mmapInit();
+
+ setWhiteBalanceMode(PWC_WB_AUTO, errmsg);
+ multiplicateur_=1;
+ skippedFrame_=0;
+ lastGain_=getGain();
+
+ cerr << "All successful, returning\n";
+ return fd;
+}
+
+void V4L1_PWC::checkSize(int & x, int & y)
+{
+ if (x>=capability.maxwidth && y >= capability.maxheight)
+ {
+ x=capability.maxwidth;
+ y=capability.maxheight;
+ } else if (x>=352 && y >=288 && type_<700) {
+ x=352;y=288;
+ } else if (x>=320 && y >= 240) {
+ x=320;y=240;
+ } else if (x>=176 && y >=144 && type_<700 ) {
+ x=176;y=144;
+ } else if (x>=160 && y >=120 ) {
+ x=160;y=120;
+ } else {
+ x=capability.minwidth;
+ y=capability.minheight;
+ }
+}
+
+bool V4L1_PWC::setSize(int x, int y)
+{
+
+ int oldX, oldY;
+ char msg[ERRMSG_SIZ];
+ checkSize(x,y);
+
+ oldX = window.width;
+ oldY = window.height;
+
+ window.width=x;
+ window.height=y;
+
+ if (ioctl (fd, VIDIOCSWIN, &window))
+ {
+ snprintf(msg, ERRMSG_SIZ, "ioctl(VIDIOCSWIN) %s", strerror(errno));
+ cerr << msg << endl;
+ window.width=oldX;
+ window.height=oldY;
+ return false;
+ }
+ ioctl (fd, VIDIOCGWIN, &window);
+
+ cerr << "New size is x=" << window.width << " " << "y=" << window.height <<endl;
+
+ allocBuffers();
+
+ return true;
+}
+
+int V4L1_PWC::saveSettings(char *errmsg)
+{
+ if (ioctl(fd, VIDIOCPWCSUSER)==-1)
+ {
+ snprintf(errmsg, ERRMSG_SIZ, "VIDIOCPWCSUSER %s", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+void V4L1_PWC::restoreSettings()
+ {
+ ioctl(fd, VIDIOCPWCRUSER);
+ getPictureSettings();
+}
+
+void V4L1_PWC::restoreFactorySettings()
+{
+ ioctl(fd, VIDIOCPWCFACTORY);
+ getPictureSettings();
+}
+
+int V4L1_PWC::setGain(int val, char *errmsg)
+ {
+ if(-1==ioctl(fd, VIDIOCPWCSAGC, &val))
+ {
+ snprintf(errmsg, ERRMSG_SIZ, "VIDIOCPWCSAGC %s", strerror(errno));
+ return -1;
+ }
+ else lastGain_=val;
+
+ cerr << "setGain "<<val<<endl;
+
+ return lastGain_;
+}
+
+int V4L1_PWC::getGain()
+{
+ int gain;
+ char msg[ERRMSG_SIZ];
+ static int cpt=0;
+ if ((cpt%4)==0)
+ {
+ if (-1==ioctl(fd, VIDIOCPWCGAGC, &gain))
+ {
+ //perror("VIDIOCPWCGAGC");
+ snprintf(msg, ERRMSG_SIZ, "VIDIOCPWCGAGC %s", strerror(errno));
+ cerr << msg << endl;
+ gain=lastGain_;
+ } else
+ {
+ ++cpt;
+ lastGain_=gain;
+ }
+ } else
+ {
+ ++cpt;
+ gain=lastGain_;
+ }
+ //cerr << "get gain "<<gain<<endl;
+ if (gain < 0) gain*=-1;
+ return gain;
+}
+
+int V4L1_PWC::setExposure(int val, char *errmsg)
+ {
+ //cout << "set exposure "<<val<<"\n";
+
+ if (-1==ioctl(fd, VIDIOCPWCSSHUTTER, &val))
+ {
+ snprintf(errmsg, ERRMSG_SIZ, "VIDIOCPWCSSHUTTER %s", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+void V4L1_PWC::setCompression(int val)
+{
+ ioctl(fd, VIDIOCPWCSCQUAL, &val);
+}
+
+int V4L1_PWC::getCompression()
+{
+ int gain;
+ ioctl(fd, VIDIOCPWCGCQUAL , &gain);
+ if (gain < 0) gain*=-1;
+ return gain;
+}
+
+int V4L1_PWC::setNoiseRemoval(int val, char *errmsg)
+{
+ if (-1 == ioctl(fd, VIDIOCPWCSDYNNOISE, &val))
+ {
+ snprintf(errmsg, ERRMSG_SIZ, "VIDIOCPWCGDYNNOISE %s", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+int V4L1_PWC::getNoiseRemoval()
+{
+ int gain;
+ char msg[ERRMSG_SIZ];
+
+ if (-1 == ioctl(fd, VIDIOCPWCGDYNNOISE , &gain))
+ {
+ snprintf(msg, ERRMSG_SIZ, "VIDIOCPWCGDYNNOISE %s", strerror(errno));
+ cerr << msg << endl;
+ }
+
+ cout <<"get noise = "<<gain<<endl;
+ return gain;
+}
+
+int V4L1_PWC::setSharpness(int val, char *errmsg)
+ {
+ if (-1 == ioctl(fd, VIDIOCPWCSCONTOUR, &val))
+ {
+ snprintf(errmsg, ERRMSG_SIZ, "VIDIOCPWCSCONTOUR %s", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+int V4L1_PWC::getSharpness()
+{
+ int gain;
+ char msg[ERRMSG_SIZ];
+
+ if (-1 == ioctl(fd, VIDIOCPWCGCONTOUR, &gain))
+ {
+ snprintf(msg, ERRMSG_SIZ, "VIDIOCPWCGCONTOUR %s", strerror(errno));
+ cerr << msg << endl;
+ }
+
+ cout <<"get sharpness = "<<gain<<endl;
+ return gain;
+}
+
+int V4L1_PWC::setBackLight(bool val, char *errmsg)
+{
+ static int on=1;
+ static int off=0;
+ if (-1 == ioctl(fd,VIDIOCPWCSBACKLIGHT, & val?&on:&off))
+ {
+ snprintf(errmsg, ERRMSG_SIZ, "VIDIOCPWCSBACKLIGHT %s", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+bool V4L1_PWC::getBackLight()
+{
+ int val;
+ char msg[ERRMSG_SIZ];
+
+ if (-1 == ioctl(fd,VIDIOCPWCGBACKLIGHT, & val))
+ {
+ snprintf(msg, ERRMSG_SIZ, "VIDIOCPWCSBACKLIGHT %s", strerror(errno));
+ cerr << msg << endl;
+ }
+
+ return val !=0;
+}
+
+int V4L1_PWC::setFlicker(bool val, char *errmsg)
+{
+ static int on=1;
+ static int off=0;
+ if (-1 == ioctl(fd,VIDIOCPWCSFLICKER, val?&on:&off))
+ {
+ snprintf(errmsg, ERRMSG_SIZ, "VIDIOCPWCSFLICKER %s", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+
+}
+
+bool V4L1_PWC::getFlicker()
+{
+ int val;
+ char msg[ERRMSG_SIZ];
+
+ if (-1 == ioctl(fd,VIDIOCPWCGFLICKER, & val))
+ {
+ snprintf(msg, ERRMSG_SIZ, "VIDIOCPWCGFLICKER %s", strerror(errno));
+ cerr << msg << endl;
+ }
+
+ return val !=0;
+}
+
+void V4L1_PWC::setGama(int val)
+{
+ picture_format.whiteness=val;
+ setPictureSettings();
+}
+
+int V4L1_PWC::getGama()
+{
+ return picture_format.whiteness;
+}
+
+int V4L1_PWC::setFrameRate(int value, char *errmsg)
+ {
+ window.flags = (window.flags & ~PWC_FPS_MASK) | ((value << PWC_FPS_SHIFT) & PWC_FPS_MASK);
+ if (ioctl(fd, VIDIOCSWIN, &window))
+ {
+ snprintf(errmsg, ERRMSG_SIZ, "setFrameRate %s", strerror(errno));
+ return -1;
+ }
+
+ ioctl(fd, VIDIOCGWIN, &window);
+ frameRate = value;
+
+ return 0;
+ //emit exposureTime(multiplicateur_/(double)getFrameRate());
+}
+
+int V4L1_PWC::getFrameRate()
+{
+ return ((window.flags&PWC_FPS_FRMASK)>>PWC_FPS_SHIFT);
+}
+
+int V4L1_PWC::getWhiteBalance()
+{
+ char msg[ERRMSG_SIZ];
+ struct pwc_whitebalance tmp_whitebalance;
+ tmp_whitebalance.mode = tmp_whitebalance.manual_red = tmp_whitebalance.manual_blue = tmp_whitebalance.read_red = tmp_whitebalance.read_blue = PWC_WB_AUTO;
+
+ if (ioctl(fd, VIDIOCPWCGAWB, &tmp_whitebalance))
+ {
+ snprintf(msg, ERRMSG_SIZ, "getWhiteBalance %s", strerror(errno));
+ cerr << msg << endl;
+ }
+ else
+ {
+#if 0
+ cout << "mode="<<tmp_whitebalance.mode
+ <<" mr="<<tmp_whitebalance.manual_red
+ <<" mb="<<tmp_whitebalance.manual_blue
+ <<" ar="<<tmp_whitebalance.read_red
+ <<" ab="<<tmp_whitebalance.read_blue
+ <<endl;
+#endif
+ /* manual_red and manual_blue are garbage :-( */
+ whiteBalanceMode_=tmp_whitebalance.mode;
+ }
+
+ return whiteBalanceMode_;
+
+ /*switch(whiteBalanceMode_) {
+ case PWC_WB_INDOOR:
+ setProperty("WhiteBalanceMode","Indor");
+ break;
+ case PWC_WB_OUTDOOR:
+ setProperty("WhiteBalanceMode","Outdoor");
+ break;
+ case PWC_WB_FL:
+ setProperty("WhiteBalanceMode","Neon");
+ break;
+ case PWC_WB_MANUAL:
+ setProperty("WhiteBalanceMode","Manual");
+ whiteBalanceRed_=tmp_whitebalance.manual_red;
+ whiteBalanceBlue_=tmp_whitebalance.manual_blue;
+
+ break;
+ case PWC_WB_AUTO:
+ setProperty("WhiteBalanceMode","Auto");
+ whiteBalanceRed_=tmp_whitebalance.read_red;
+ whiteBalanceBlue_=tmp_whitebalance.read_blue;
+ break;
+ default:
+ setProperty("WhiteBalanceMode","???");
+ }
+
+ emit whiteBalanceModeChange(whiteBalanceMode_);
+
+ if (((whiteBalanceMode_ == PWC_WB_AUTO) && liveWhiteBalance_)
+ || whiteBalanceMode_ != PWC_WB_AUTO) {
+ setProperty("WhiteBalanceRed",whiteBalanceRed_);
+ emit whiteBalanceRedChange(whiteBalanceRed_);
+ setProperty("WhiteBalanceBlue",whiteBalanceBlue_);
+ emit whiteBalanceBlueChange(whiteBalanceBlue_);
+ if (guiBuild()) {
+ remoteCTRLWBred_->show();
+ remoteCTRLWBblue_->show();
+ }
+ } else {
+ if (guiBuild()) {
+ remoteCTRLWBred_->hide();
+ remoteCTRLWBblue_->hide();
+ }
+ }
+ }*/
+}
+
+int V4L1_PWC::setWhiteBalance(char *errmsg)
+{
+ struct pwc_whitebalance wb;
+ wb.mode=whiteBalanceMode_;
+ if (wb.mode == PWC_WB_MANUAL)
+ {
+ wb.manual_red=whiteBalanceRed_;
+ wb.manual_blue=whiteBalanceBlue_;
+ }
+
+ if (ioctl(fd, VIDIOCPWCSAWB, &wb))
+ {
+ snprintf(errmsg, ERRMSG_SIZ, "setWhiteBalance %s", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+int V4L1_PWC::setWhiteBalanceMode(int val, char *errmsg)
+ {
+ if (val == whiteBalanceMode_)
+ return whiteBalanceMode_;
+
+ if (val != PWC_WB_AUTO)
+ {
+ if ( val != PWC_WB_MANUAL)
+ {
+ whiteBalanceMode_=val;
+ if (setWhiteBalance(errmsg) < 0)
+ return -1;
+ }
+
+ //whiteBalanceMode_=PWC_WB_AUTO;
+ whiteBalanceMode_= val;
+ if (setWhiteBalance(errmsg) < 0)
+ return -1;
+ getWhiteBalance();
+ }
+
+ /*if (guiBuild()) {
+ if (val != PWC_WB_AUTO
+ || ( liveWhiteBalance_ && (val ==PWC_WB_AUTO))) {
+ remoteCTRLWBred_->show();
+ remoteCTRLWBblue_->show();
+ } else {
+ remoteCTRLWBred_->hide();
+ remoteCTRLWBblue_->hide();
+ }
+ }*/
+
+ whiteBalanceMode_=val;
+ if (setWhiteBalance(errmsg) < 0)
+ return -1;
+ getWhiteBalance();
+
+ return 0;
+}
+
+int V4L1_PWC::setWhiteBalanceRed(int val, char *errmsg)
+{
+ whiteBalanceMode_ = PWC_WB_MANUAL;
+ whiteBalanceRed_=val;
+ if (setWhiteBalance(errmsg) < 0)
+ return -1;
+
+ return 0;
+}
+
+int V4L1_PWC::setWhiteBalanceBlue(int val, char *errmsg)
+{
+ whiteBalanceMode_ = PWC_WB_MANUAL;
+ whiteBalanceBlue_=val;
+ if (setWhiteBalance(errmsg) < 0)
+ return -1;
+
+ return 0;
+}
+
diff --git a/kstars/kstars/indi/webcam/v4l1_pwc.h b/kstars/kstars/indi/webcam/v4l1_pwc.h
new file mode 100644
index 00000000..ad0fab1f
--- /dev/null
+++ b/kstars/kstars/indi/webcam/v4l1_pwc.h
@@ -0,0 +1,89 @@
+/*
+ Phlips webcam driver for V4L 1
+ Copyright (C) 2005 by Jasem Mutlaq
+
+ This library 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 library 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 library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#ifndef V4L1_PWC_H
+#define V4L1_PWC_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "videodev.h"
+#include "v4l1_base.h"
+
+class V4L1_PWC : public V4L1_Base
+{
+ public:
+ V4L1_PWC();
+ ~V4L1_PWC();
+
+ int connectCam(const char * devpath, char *errmsg);
+
+ /* Philips related, from QAstrocam */
+ int saveSettings(char *errmsg);
+ void restoreSettings();
+ void restoreFactorySettings();
+ int setGain(int value, char *errmsg);
+ int getGain();
+ int setExposure(int val, char *errmsg);
+ void setCompression(int value);
+ int getCompression();
+ int setNoiseRemoval(int value, char *errmsg);
+ int getNoiseRemoval();
+ int setSharpness(int value, char *errmsg);
+ int getSharpness();
+ int setBackLight(bool val, char *errmsg);
+ bool getBackLight();
+ int setFlicker(bool val, char *errmsg);
+ bool getFlicker();
+ void setGama(int value);
+ int getGama();
+ int setFrameRate(int value, char *errmsg);
+ int getFrameRate();
+ int setWhiteBalance(char *errmsg);
+ int getWhiteBalance();
+ int setWhiteBalanceMode(int val, char *errmsg);
+ int setWhiteBalanceRed(int val, char *errmsg);
+ int setWhiteBalanceBlue(int val, char *errmsg);
+
+ /* TODO consider the SC modded cam after this
+ void setLongExposureTime(const QString& str);
+ void setFrameRateMultiplicateur(int value);*/
+
+
+ /* Updates */
+ //void updateFrame(int d, void *p);
+
+ /* Image Size */
+ void checkSize(int & x, int & y);
+ bool setSize(int x, int y);
+
+
+ private:
+ int whiteBalanceMode_;
+ int whiteBalanceRed_;
+ int whiteBalanceBlue_;
+ int lastGain_;
+ int multiplicateur_;
+ int skippedFrame_;
+ int type_;
+
+
+};
+
+#endif
diff --git a/kstars/kstars/indi/webcam/v4l2_base.cpp b/kstars/kstars/indi/webcam/v4l2_base.cpp
new file mode 100644
index 00000000..26ec3d51
--- /dev/null
+++ b/kstars/kstars/indi/webcam/v4l2_base.cpp
@@ -0,0 +1,1189 @@
+/*
+ Copyright (C) 2005 by Jasem Mutlaq
+
+ Based on V4L 2 Example
+ http://v4l2spec.bytesex.org/spec-single/v4l2.html#CAPTURE-EXAMPLE
+
+ This library 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 library 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 library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#include <iostream>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <string.h>
+#include <asm/types.h> /* for videodev2.h */
+
+#include "ccvt.h"
+#include "v4l2_base.h"
+#include "../eventloop.h"
+#include "../indidevapi.h"
+
+#define ERRMSGSIZ 1024
+
+#define CLEAR(x) memset (&(x), 0, sizeof (x))
+
+using namespace std;
+
+V4L2_Base::V4L2_Base()
+{
+ frameRate=10;
+ selectCallBackID = -1;
+ dropFrame = false;
+
+ xmax = xmin = 160;
+ ymax = ymin = 120;
+
+ io = IO_METHOD_MMAP;
+ fd = -1;
+ buffers = NULL;
+ n_buffers = 0;
+
+ YBuf = NULL;
+ UBuf = NULL;
+ VBuf = NULL;
+ colorBuffer = NULL;
+ rgb24_buffer = NULL;
+ callback = NULL;
+
+}
+
+V4L2_Base::~V4L2_Base()
+{
+
+ delete (YBuf);
+ delete (UBuf);
+ delete (VBuf);
+ delete (colorBuffer);
+ delete (rgb24_buffer);
+
+}
+
+int V4L2_Base::xioctl(int fd, int request, void *arg)
+{
+ int r;
+
+ do r = ioctl (fd, request, arg);
+ while (-1 == r && EINTR == errno);
+
+ return r;
+}
+
+int V4L2_Base::errno_exit(const char *s, char *errmsg)
+{
+ fprintf (stderr, "%s error %d, %s\n",
+ s, errno, strerror (errno));
+
+ snprintf(errmsg, ERRMSGSIZ, "%s error %d, %s\n", s, errno, strerror (errno));
+
+ return -1;
+}
+
+int V4L2_Base::connectCam(const char * devpath, char *errmsg , int pixelFormat , int width , int height )
+{
+ frameRate=10;
+ selectCallBackID = -1;
+ dropFrame = false;
+
+ if (open_device (devpath, errmsg) < 0)
+ return -1;
+
+ if (init_device(errmsg, pixelFormat, width, height) < 0)
+ return -1;
+
+ cerr << "V4L 2 - All successful, returning\n";
+ return fd;
+}
+
+void V4L2_Base::disconnectCam()
+{
+ char errmsg[ERRMSGSIZ];
+ delete YBuf;
+ delete UBuf;
+ delete VBuf;
+ YBuf = UBuf = VBuf = NULL;
+
+ if (selectCallBackID != -1)
+ rmCallback(selectCallBackID);
+
+ stop_capturing (errmsg);
+
+ uninit_device (errmsg);
+
+ close_device ();
+
+ fprintf(stderr, "Disconnect cam\n");
+}
+
+int V4L2_Base::read_frame(char *errmsg)
+{
+ struct v4l2_buffer buf;
+ unsigned int i;
+ //cerr << "in read Frame" << endl;
+
+ switch (io) {
+ case IO_METHOD_READ:
+ if (-1 == read (fd, buffers[0].start, buffers[0].length)) {
+ switch (errno) {
+ case EAGAIN:
+ return 0;
+
+ case EIO:
+ /* Could ignore EIO, see spec. */
+
+ /* fall through */
+
+ default:
+ return errno_exit ("read", errmsg);
+ }
+ }
+
+ //process_image (buffers[0].start);
+
+ break;
+
+ case IO_METHOD_MMAP:
+ CLEAR (buf);
+
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+
+ if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) {
+ switch (errno) {
+ case EAGAIN:
+ return 0;
+
+ case EIO:
+ /* Could ignore EIO, see spec. */
+
+ /* fall through */
+
+ default:
+ return errno_exit ("VIDIOC_DQBUF", errmsg);
+ }
+ }
+
+ assert (buf.index < n_buffers);
+
+ switch (fmt.fmt.pix.pixelformat)
+ {
+ case V4L2_PIX_FMT_YUV420:
+ memcpy(YBuf,((unsigned char *) buffers[buf.index].start), fmt.fmt.pix.width * fmt.fmt.pix.height);
+ memcpy(UBuf,((unsigned char *) buffers[buf.index].start) + fmt.fmt.pix.width * fmt.fmt.pix.height, (fmt.fmt.pix.width/2) * (fmt.fmt.pix.height/2));
+ memcpy(VBuf,((unsigned char *) buffers[buf.index].start) + fmt.fmt.pix.width * fmt.fmt.pix.height + (fmt.fmt.pix.width/2) * (fmt.fmt.pix.height/2), (fmt.fmt.pix.width/2) * (fmt.fmt.pix.width/2));
+ break;
+
+ case V4L2_PIX_FMT_YUYV:
+ ccvt_yuyv_420p( fmt.fmt.pix.width , fmt.fmt.pix.height, buffers[buf.index].start, YBuf, UBuf, VBuf);
+ break;
+
+ case V4L2_PIX_FMT_RGB24:
+ RGB2YUV(fmt.fmt.pix.width, fmt.fmt.pix.height, buffers[buf.index].start, YBuf, UBuf, VBuf, 0);
+ break;
+
+ case V4L2_PIX_FMT_SBGGR8:
+ bayer2rgb24(rgb24_buffer, ((unsigned char *) buffers[buf.index].start), fmt.fmt.pix.width, fmt.fmt.pix.height);
+ break;
+ }
+
+ if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))
+ return errno_exit ("VIDIOC_QBUF", errmsg);
+
+ if (dropFrame)
+ {
+ dropFrame = false;
+ return 0;
+ }
+
+ /* Call provided callback function if any */
+ if (callback)
+ (*callback)(uptr);
+
+ break;
+
+ case IO_METHOD_USERPTR:
+ CLEAR (buf);
+
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_USERPTR;
+
+ if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) {
+ switch (errno) {
+ case EAGAIN:
+ return 0;
+
+ case EIO:
+ /* Could ignore EIO, see spec. */
+
+ /* fall through */
+
+ default:
+ errno_exit ("VIDIOC_DQBUF", errmsg);
+ }
+ }
+
+ for (i = 0; i < n_buffers; ++i)
+ if (buf.m.userptr == (unsigned long) buffers[i].start
+ && buf.length == buffers[i].length)
+ break;
+
+ assert (i < n_buffers);
+
+ //process_image ((void *) buf.m.userptr);
+
+ if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))
+ errno_exit ("VIDIOC_QBUF", errmsg);
+
+ break;
+ }
+
+ return 0;
+}
+
+int V4L2_Base::stop_capturing(char *errmsg)
+{
+ enum v4l2_buf_type type;
+
+ switch (io) {
+ case IO_METHOD_READ:
+ /* Nothing to do. */
+ break;
+
+ case IO_METHOD_MMAP:
+ case IO_METHOD_USERPTR:
+ type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ IERmCallback(selectCallBackID);
+ selectCallBackID = -1;
+
+ dropFrame = true;
+
+ if (-1 == xioctl (fd, VIDIOC_STREAMOFF, &type))
+ return errno_exit ("VIDIOC_STREAMOFF", errmsg);
+
+
+
+ break;
+ }
+
+ return 0;
+}
+
+int V4L2_Base::start_capturing(char * errmsg)
+{
+ unsigned int i;
+ enum v4l2_buf_type type;
+
+ switch (io) {
+ case IO_METHOD_READ:
+ /* Nothing to do. */
+ break;
+
+ case IO_METHOD_MMAP:
+ for (i = 0; i < n_buffers; ++i) {
+ struct v4l2_buffer buf;
+
+ CLEAR (buf);
+
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = i;
+
+ if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))
+ return errno_exit ("VIDIOC_QBUF", errmsg);
+
+ }
+
+ type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ if (-1 == xioctl (fd, VIDIOC_STREAMON, &type))
+ return errno_exit ("VIDIOC_STREAMON", errmsg);
+
+
+
+ selectCallBackID = IEAddCallback(fd, newFrame, this);
+
+ break;
+
+ case IO_METHOD_USERPTR:
+ for (i = 0; i < n_buffers; ++i) {
+ struct v4l2_buffer buf;
+
+ CLEAR (buf);
+
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_USERPTR;
+ buf.m.userptr = (unsigned long) buffers[i].start;
+ buf.length = buffers[i].length;
+
+ if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))
+ return errno_exit ("VIDIOC_QBUF", errmsg);
+ }
+
+
+ type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ if (-1 == xioctl (fd, VIDIOC_STREAMON, &type))
+ return errno_exit ("VIDIOC_STREAMON", errmsg);
+
+ break;
+ }
+
+ return 0;
+
+}
+
+void V4L2_Base::newFrame(int /*fd*/, void *p)
+{
+ char errmsg[ERRMSGSIZ];
+
+ ( (V4L2_Base *) (p))->read_frame(errmsg);
+
+}
+
+int V4L2_Base::uninit_device(char *errmsg)
+{
+
+ switch (io) {
+ case IO_METHOD_READ:
+ free (buffers[0].start);
+ break;
+
+ case IO_METHOD_MMAP:
+ for (unsigned int i = 0; i < n_buffers; ++i)
+ if (-1 == munmap (buffers[i].start, buffers[i].length))
+ return errno_exit ("munmap", errmsg);
+ break;
+
+ case IO_METHOD_USERPTR:
+ for (unsigned int i = 0; i < n_buffers; ++i)
+ free (buffers[i].start);
+ break;
+ }
+
+ free (buffers);
+
+ return 0;
+}
+
+void V4L2_Base::init_read(unsigned int buffer_size)
+{
+ buffers = (buffer *) calloc (1, sizeof (*buffers));
+
+ if (!buffers) {
+ fprintf (stderr, "Out of memory\n");
+ exit (EXIT_FAILURE);
+ }
+
+ buffers[0].length = buffer_size;
+ buffers[0].start = malloc (buffer_size);
+
+ if (!buffers[0].start) {
+ fprintf (stderr, "Out of memory\n");
+ exit (EXIT_FAILURE);
+ }
+}
+
+int V4L2_Base::init_mmap(char *errmsg)
+{
+ struct v4l2_requestbuffers req;
+
+ CLEAR (req);
+
+ req.count = 4;
+ req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ req.memory = V4L2_MEMORY_MMAP;
+
+ if (-1 == xioctl (fd, VIDIOC_REQBUFS, &req)) {
+ if (EINVAL == errno) {
+ fprintf (stderr, "%s does not support "
+ "memory mapping\n", dev_name);
+ snprintf(errmsg, ERRMSGSIZ, "%s does not support "
+ "memory mapping\n", dev_name);
+ return -1;
+ } else {
+ return errno_exit ("VIDIOC_REQBUFS", errmsg);
+ }
+ }
+
+ if (req.count < 2) {
+ fprintf (stderr, "Insufficient buffer memory on %s\n",
+ dev_name);
+ snprintf(errmsg, ERRMSGSIZ, "Insufficient buffer memory on %s\n",
+ dev_name);
+ return -1;
+ }
+
+ buffers = (buffer *) calloc (req.count, sizeof (*buffers));
+
+ if (!buffers)
+ {
+ fprintf (stderr, "buffers. Out of memory\n");
+ strncpy(errmsg, "buffers. Out of memory\n", ERRMSGSIZ);
+ return -1;
+ }
+
+ for (n_buffers = 0; n_buffers < req.count; ++n_buffers)
+ {
+ struct v4l2_buffer buf;
+
+ CLEAR (buf);
+
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = n_buffers;
+
+ if (-1 == xioctl (fd, VIDIOC_QUERYBUF, &buf))
+ return errno_exit ("VIDIOC_QUERYBUF", errmsg);
+
+ buffers[n_buffers].length = buf.length;
+ buffers[n_buffers].start =
+ mmap (NULL /* start anywhere */,
+ buf.length,
+ PROT_READ | PROT_WRITE /* required */,
+ MAP_SHARED /* recommended */,
+ fd, buf.m.offset);
+
+ if (MAP_FAILED == buffers[n_buffers].start)
+ return errno_exit ("mmap", errmsg);
+ }
+
+ return 0;
+}
+
+void V4L2_Base::init_userp(unsigned int buffer_size)
+{
+ struct v4l2_requestbuffers req;
+ char errmsg[ERRMSGSIZ];
+
+ CLEAR (req);
+
+ req.count = 4;
+ req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ req.memory = V4L2_MEMORY_USERPTR;
+
+ if (-1 == xioctl (fd, VIDIOC_REQBUFS, &req)) {
+ if (EINVAL == errno) {
+ fprintf (stderr, "%s does not support "
+ "user pointer i/o\n", dev_name);
+ exit (EXIT_FAILURE);
+ } else {
+ errno_exit ("VIDIOC_REQBUFS", errmsg);
+ }
+ }
+
+ buffers = (buffer *) calloc (4, sizeof (*buffers));
+
+ if (!buffers) {
+ fprintf (stderr, "Out of memory\n");
+ exit (EXIT_FAILURE);
+ }
+
+ for (n_buffers = 0; n_buffers < 4; ++n_buffers) {
+ buffers[n_buffers].length = buffer_size;
+ buffers[n_buffers].start = malloc (buffer_size);
+
+ if (!buffers[n_buffers].start) {
+ fprintf (stderr, "Out of memory\n");
+ exit (EXIT_FAILURE);
+ }
+ }
+}
+
+int V4L2_Base::init_device(char *errmsg, int pixelFormat , int width, int height)
+{
+ unsigned int min;
+
+ if (-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap))
+ {
+ if (EINVAL == errno) {
+ fprintf (stderr, "%s is no V4L2 device\n",
+ dev_name);
+ snprintf(errmsg, ERRMSGSIZ, "%s is no V4L2 device\n", dev_name);
+ return -1;
+ } else {
+ return errno_exit ("VIDIOC_QUERYCAP", errmsg);
+ }
+ }
+
+ if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
+ {
+ fprintf (stderr, "%s is no video capture device\n",
+ dev_name);
+ snprintf(errmsg, ERRMSGSIZ, "%s is no video capture device\n", dev_name);
+ return -1;
+ }
+
+ switch (io)
+ {
+ case IO_METHOD_READ:
+ if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
+ fprintf (stderr, "%s does not support read i/o\n",
+ dev_name);
+ snprintf(errmsg, ERRMSGSIZ, "%s does not support read i/o\n",
+ dev_name);
+ return -1;
+ }
+
+ break;
+
+ case IO_METHOD_MMAP:
+ case IO_METHOD_USERPTR:
+ if (!(cap.capabilities & V4L2_CAP_STREAMING))
+ {
+ fprintf (stderr, "%s does not support streaming i/o\n",
+ dev_name);
+ snprintf(errmsg, ERRMSGSIZ, "%s does not support streaming i/o\n",
+ dev_name);
+ return -1;
+ }
+
+ break;
+ }
+
+ /* Select video input, video standard and tune here. */
+
+ cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ if (-1 == xioctl (fd, VIDIOC_CROPCAP, &cropcap)) {
+ /* Errors ignored. */
+ }
+
+ crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ crop.c = cropcap.defrect; /* reset to default */
+
+ if (-1 == xioctl (fd, VIDIOC_S_CROP, &crop)) {
+ switch (errno) {
+ case EINVAL:
+ /* Cropping not supported. */
+ break;
+ default:
+ /* Errors ignored. */
+ break;
+ }
+ }
+
+ CLEAR (fmt);
+
+ fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ fmt.fmt.pix.width = width;
+ fmt.fmt.pix.height = height;
+ fmt.fmt.pix.pixelformat = pixelFormat;
+ //fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
+
+ if (-1 == xioctl (fd, VIDIOC_S_FMT, &fmt))
+ return errno_exit ("VIDIOC_S_FMT", errmsg);
+
+ /* Note VIDIOC_S_FMT may change width and height. */
+
+ /* Buggy driver paranoia. */
+ min = fmt.fmt.pix.width * 2;
+ if (fmt.fmt.pix.bytesperline < min)
+ fmt.fmt.pix.bytesperline = min;
+ min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
+ if (fmt.fmt.pix.sizeimage < min)
+ fmt.fmt.pix.sizeimage = min;
+
+ /* Let's get the actual size */
+ CLEAR(fmt);
+
+ fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ if (-1 == xioctl (fd, VIDIOC_G_FMT, &fmt))
+ return errno_exit ("VIDIOC_G_FMT", errmsg);
+
+ cerr << "width: " << fmt.fmt.pix.width << " - height: " << fmt.fmt.pix.height << endl;
+
+ switch (pixelFormat)
+ {
+ case V4L2_PIX_FMT_YUV420:
+ cerr << "pixel format: V4L2_PIX_FMT_YUV420" << endl;
+ break;
+
+ case V4L2_PIX_FMT_YUYV:
+ cerr << "pixel format: V4L2_PIX_FMT_YUYV" << endl;
+ break;
+
+ case V4L2_PIX_FMT_RGB24:
+ cerr << "pixel format: V4L2_PIX_FMT_RGB24" << endl;
+ break;
+
+ case V4L2_PIX_FMT_SBGGR8:
+ cerr << "pixel format: V4L2_PIX_FMT_SBGGR8" << endl;
+ break;
+
+ }
+
+ findMinMax();
+
+ allocBuffers();
+
+ switch (io)
+ {
+ case IO_METHOD_READ:
+ init_read (fmt.fmt.pix.sizeimage);
+ break;
+
+ case IO_METHOD_MMAP:
+ return init_mmap(errmsg);
+ break;
+
+ case IO_METHOD_USERPTR:
+ init_userp (fmt.fmt.pix.sizeimage);
+ break;
+ }
+
+ return 0;
+}
+
+void V4L2_Base::close_device(void)
+{
+ char errmsg[ERRMSGSIZ];
+
+ if (-1 == close (fd))
+ errno_exit ("close", errmsg);
+
+ fd = -1;
+}
+
+int V4L2_Base::open_device(const char *devpath, char *errmsg)
+{
+ struct stat st;
+
+ strncpy(dev_name, devpath, 64);
+
+ if (-1 == stat (dev_name, &st)) {
+ fprintf (stderr, "Cannot identify '%s': %d, %s\n",
+ dev_name, errno, strerror (errno));
+ snprintf(errmsg, ERRMSGSIZ, "Cannot identify '%s': %d, %s\n",
+ dev_name, errno, strerror (errno));
+ return -1;
+ }
+
+ if (!S_ISCHR (st.st_mode))
+ {
+ fprintf (stderr, "%s is no device\n", dev_name);
+ snprintf(errmsg, ERRMSGSIZ, "%s is no device\n", dev_name);
+ return -1;
+ }
+
+ fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
+
+ if (-1 == fd)
+ {
+ fprintf (stderr, "Cannot open '%s': %d, %s\n",
+ dev_name, errno, strerror (errno));
+ snprintf(errmsg, ERRMSGSIZ, "Cannot open '%s': %d, %s\n",
+ dev_name, errno, strerror (errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
+int V4L2_Base::getWidth()
+{
+ return fmt.fmt.pix.width;
+}
+
+int V4L2_Base::getHeight()
+{
+ return fmt.fmt.pix.height;
+}
+
+void V4L2_Base::setFPS(int fps)
+{
+ frameRate = 15;//fps;
+}
+
+int V4L2_Base::getFPS()
+{
+ return 15;
+}
+
+char * V4L2_Base::getDeviceName()
+{
+ return ((char *) cap.card);
+}
+
+void V4L2_Base::allocBuffers()
+{
+ delete (YBuf); YBuf = NULL;
+ delete (UBuf); UBuf = NULL;
+ delete (VBuf); VBuf = NULL;
+ delete (colorBuffer); colorBuffer = NULL;
+ delete (rgb24_buffer); rgb24_buffer = NULL;
+
+ YBuf= new unsigned char[ fmt.fmt.pix.width * fmt.fmt.pix.height];
+ UBuf= new unsigned char[ fmt.fmt.pix.width * fmt.fmt.pix.height];
+ VBuf= new unsigned char[ fmt.fmt.pix.width * fmt.fmt.pix.height];
+ colorBuffer = new unsigned char[fmt.fmt.pix.width * fmt.fmt.pix.height * 4];
+
+ if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_SBGGR8)
+ rgb24_buffer = new unsigned char[fmt.fmt.pix.width * fmt.fmt.pix.height * 3];
+}
+
+void V4L2_Base::getMaxMinSize(int & x_max, int & y_max, int & x_min, int & y_min)
+{
+ x_max = xmax; y_max = ymax; x_min = xmin; y_min = ymin;
+}
+
+int V4L2_Base::setSize(int x, int y)
+{
+ char errmsg[ERRMSGSIZ];
+ int oldW, oldH;
+
+ oldW = fmt.fmt.pix.width;
+ oldH = fmt.fmt.pix.height;
+
+ fmt.fmt.pix.width = x;
+ fmt.fmt.pix.height = y;
+
+ if (-1 == xioctl (fd, VIDIOC_S_FMT, &fmt))
+ {
+ fmt.fmt.pix.width = oldW;
+ fmt.fmt.pix.height = oldH;
+ return errno_exit ("VIDIOC_S_FMT", errmsg);
+ }
+
+ /* PWC bug? It seems that setting the "wrong" width and height will mess something in the driver.
+ Only 160x120, 320x280, and 640x480 are accepted. If I try to set it for example to 300x200, it wii
+ get set to 320x280, which is fine, but then the video information is messed up for some reason. */
+ xioctl (fd, VIDIOC_S_FMT, &fmt);
+
+
+ allocBuffers();
+
+ return 0;
+}
+
+void V4L2_Base::setContrast(int val)
+{
+ /*picture_.contrast=val;
+ updatePictureSettings();*/
+}
+
+int V4L2_Base::getContrast()
+{
+ return 255;//picture_.contrast;
+}
+
+void V4L2_Base::setBrightness(int val)
+{
+ /*picture_.brightness=val;
+ updatePictureSettings();*/
+}
+
+int V4L2_Base::getBrightness()
+{
+ return 255;//picture_.brightness;
+}
+
+void V4L2_Base::setColor(int val)
+{
+ /*picture_.colour=val;
+ updatePictureSettings();*/
+}
+
+int V4L2_Base::getColor()
+{
+ return 255; //picture_.colour;
+}
+
+void V4L2_Base::setHue(int val)
+{
+ /*picture_.hue=val;
+ updatePictureSettings();*/
+}
+
+int V4L2_Base::getHue()
+{
+ return 255;//picture_.hue;
+}
+
+void V4L2_Base::setWhiteness(int val)
+{
+ /*picture_.whiteness=val;
+ updatePictureSettings();*/
+}
+
+int V4L2_Base::getWhiteness()
+{
+ return 255;//picture_.whiteness;
+}
+
+void V4L2_Base::setPictureSettings()
+{
+ /*if (ioctl(device_, VIDIOCSPICT, &picture_) ) {
+ cerr << "updatePictureSettings" << endl;
+ }
+ ioctl(device_, VIDIOCGPICT, &picture_);*/
+}
+
+void V4L2_Base::getPictureSettings()
+{
+ /*if (ioctl(device_, VIDIOCGPICT, &picture_) )
+ {
+ cerr << "refreshPictureSettings" << endl;
+ }*/
+}
+
+unsigned char * V4L2_Base::getY()
+{
+ if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_SBGGR8)
+ RGB2YUV(fmt.fmt.pix.width, fmt.fmt.pix.height, rgb24_buffer, YBuf, UBuf, VBuf, 0);
+
+ return YBuf;
+}
+
+unsigned char * V4L2_Base::getU()
+{
+ return UBuf;
+}
+
+unsigned char * V4L2_Base::getV()
+{
+ return VBuf;
+}
+
+unsigned char * V4L2_Base::getColorBuffer()
+{
+ //cerr << "in get color buffer " << endl;
+
+ switch (fmt.fmt.pix.pixelformat)
+ {
+ case V4L2_PIX_FMT_YUV420:
+ ccvt_420p_bgr32(fmt.fmt.pix.width, fmt.fmt.pix.height,
+ buffers[0].start, (void*)colorBuffer);
+ break;
+
+ case V4L2_PIX_FMT_YUYV:
+ ccvt_yuyv_bgr32(fmt.fmt.pix.width, fmt.fmt.pix.height,
+ buffers[0].start, (void*)colorBuffer);
+ break;
+
+ case V4L2_PIX_FMT_RGB24:
+ ccvt_rgb24_bgr32(fmt.fmt.pix.width, fmt.fmt.pix.height,
+ buffers[0].start, (void*)colorBuffer);
+ break;
+
+ case V4L2_PIX_FMT_SBGGR8:
+ ccvt_rgb24_bgr32(fmt.fmt.pix.width, fmt.fmt.pix.height,
+ rgb24_buffer, (void*)colorBuffer);
+ break;
+
+ default:
+ break;
+ }
+
+ return colorBuffer;
+}
+
+void V4L2_Base::registerCallback(WPF *fp, void *ud)
+{
+ callback = fp;
+ uptr = ud;
+}
+
+void V4L2_Base::findMinMax()
+{
+ char errmsg[ERRMSGSIZ];
+ struct v4l2_format tryfmt;
+ CLEAR(tryfmt);
+
+ xmin = xmax = fmt.fmt.pix.width;
+ ymin = ymax = fmt.fmt.pix.height;
+
+ tryfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ tryfmt.fmt.pix.width = 10;
+ tryfmt.fmt.pix.height = 10;
+ tryfmt.fmt.pix.pixelformat = fmt.fmt.pix.pixelformat;
+ tryfmt.fmt.pix.field = fmt.fmt.pix.field;
+
+ if (-1 == xioctl (fd, VIDIOC_TRY_FMT, &tryfmt))
+ {
+ errno_exit ("VIDIOC_TRY_FMT 1", errmsg);
+ return;
+ }
+
+ xmin = tryfmt.fmt.pix.width;
+ ymin = tryfmt.fmt.pix.height;
+
+ tryfmt.fmt.pix.width = 1600;
+ tryfmt.fmt.pix.height = 1200;
+
+ if (-1 == xioctl (fd, VIDIOC_TRY_FMT, &tryfmt))
+ {
+ errno_exit ("VIDIOC_TRY_FMT 2", errmsg);
+ return;
+ }
+
+ xmax = tryfmt.fmt.pix.width;
+ ymax = tryfmt.fmt.pix.height;
+
+ cerr << "Min X: " << xmin << " - Max X: " << xmax << " - Min Y: " << ymin << " - Max Y: " << ymax << endl;
+}
+
+void V4L2_Base::enumerate_ctrl (void)
+{
+ char errmsg[ERRMSGSIZ];
+ CLEAR(queryctrl);
+
+ for (queryctrl.id = V4L2_CID_BASE; queryctrl.id < V4L2_CID_LASTP1; queryctrl.id++)
+ {
+ if (0 == xioctl (fd, VIDIOC_QUERYCTRL, &queryctrl))
+ {
+ cerr << "Control " << queryctrl.name << endl;
+
+ if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
+ continue;
+
+ cerr << "Control " << queryctrl.name << endl;
+
+ if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
+ enumerate_menu ();
+ } else
+ {
+ if (errno == EINVAL)
+ continue;
+
+ errno_exit("VIDIOC_QUERYCTRL", errmsg);
+ return;
+ }
+ }
+
+ for (queryctrl.id = V4L2_CID_PRIVATE_BASE; ; queryctrl.id++)
+ {
+ if (0 == xioctl (fd, VIDIOC_QUERYCTRL, &queryctrl))
+ {
+ cerr << "Private Control " << queryctrl.name << endl;
+
+ if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
+ continue;
+
+ if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
+ enumerate_menu ();
+ } else {
+ if (errno == EINVAL)
+ break;
+
+ errno_exit ("VIDIOC_QUERYCTRL", errmsg);
+ return;
+ }
+
+ }
+
+}
+
+void V4L2_Base::enumerate_menu (void)
+{
+ char errmsg[ERRMSGSIZ];
+ cerr << " Menu items:" << endl;
+
+ CLEAR(querymenu);
+ querymenu.id = queryctrl.id;
+
+ for (querymenu.index = queryctrl.minimum; querymenu.index <= queryctrl.maximum; querymenu.index++)
+ {
+ if (0 == xioctl (fd, VIDIOC_QUERYMENU, &querymenu))
+ {
+ cerr << " " << querymenu.name << endl;
+ } else
+ {
+ errno_exit("VIDIOC_QUERYMENU", errmsg);
+ return;
+ }
+ }
+}
+
+int V4L2_Base::query_ctrl(unsigned int ctrl_id, double & ctrl_min, double & ctrl_max, double & ctrl_step, double & ctrl_value, char *errmsg)
+{
+
+ struct v4l2_control control;
+
+ CLEAR(queryctrl);
+
+ queryctrl.id = ctrl_id;
+
+ if (-1 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl))
+ {
+ if (errno != EINVAL)
+ return errno_exit ("VIDIOC_QUERYCTRL", errmsg);
+
+ else
+ {
+ cerr << "#" << ctrl_id << " is not supported" << endl;
+ snprintf(errmsg, ERRMSGSIZ, "# %d is not supported", ctrl_id);
+ return -1;
+ }
+ } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
+ {
+ cerr << "#" << ctrl_id << " is disabled" << endl;
+ snprintf(errmsg, ERRMSGSIZ, "# %d is disabled", ctrl_id);
+ return -1;
+ }
+
+ ctrl_min = queryctrl.minimum;
+ ctrl_max = queryctrl.maximum;
+ ctrl_step = queryctrl.step;
+ ctrl_value = queryctrl.default_value;
+
+ /* Get current value */
+ CLEAR(control);
+ control.id = ctrl_id;
+
+ if (0 == xioctl(fd, VIDIOC_G_CTRL, &control))
+ ctrl_value = control.value;
+
+ cerr << queryctrl.name << " -- min: " << ctrl_min << " max: " << ctrl_max << " step: " << ctrl_step << " value: " << ctrl_value << endl;
+
+ return 0;
+
+}
+
+int V4L2_Base::queryINTControls(INumberVectorProperty *nvp)
+{
+ struct v4l2_control control;
+ char errmsg[ERRMSGSIZ];
+ CLEAR(queryctrl);
+ INumber *numbers = NULL;
+ unsigned int *num_ctrls = NULL;
+ int nnum=0;
+
+ for (queryctrl.id = V4L2_CID_BASE; queryctrl.id < V4L2_CID_LASTP1; queryctrl.id++)
+ {
+ if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl))
+ {
+ if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
+ {
+ cerr << queryctrl.name << " is disabled." << endl;
+ continue;
+ }
+
+ if (queryctrl.type == V4L2_CTRL_TYPE_INTEGER)
+ {
+ numbers = (numbers == NULL) ? (INumber *) malloc (sizeof(INumber)) :
+ (INumber *) realloc (numbers, (nnum+1) * sizeof (INumber));
+
+ num_ctrls = (num_ctrls == NULL) ? (unsigned int *) malloc (sizeof (unsigned int)) :
+ (unsigned int *) realloc (num_ctrls, (nnum+1) * sizeof (unsigned int));
+
+ strncpy(numbers[nnum].name, ((char *) queryctrl.name) , MAXINDINAME);
+ strncpy(numbers[nnum].label, ((char *) queryctrl.name), MAXINDILABEL);
+ strncpy(numbers[nnum].format, "%0.f", MAXINDIFORMAT);
+ numbers[nnum].min = queryctrl.minimum;
+ numbers[nnum].max = queryctrl.maximum;
+ numbers[nnum].step = queryctrl.step;
+ numbers[nnum].value = queryctrl.default_value;
+
+ /* Get current value if possible */
+ CLEAR(control);
+ control.id = queryctrl.id;
+ if (0 == xioctl(fd, VIDIOC_G_CTRL, &control))
+ numbers[nnum].value = control.value;
+
+ /* Store ID info in INumber. This is the first time ever I make use of aux0!! */
+ num_ctrls[nnum] = queryctrl.id;
+
+ cerr << queryctrl.name << " -- min: " << queryctrl.minimum << " max: " << queryctrl.maximum << " step: " << queryctrl.step << " value: " << numbers[nnum].value << endl;
+
+ nnum++;
+
+ }
+ } else if (errno != EINVAL)
+ return errno_exit ("VIDIOC_QUERYCTRL", errmsg);
+
+ }
+
+ for (queryctrl.id = V4L2_CID_PRIVATE_BASE; ; queryctrl.id++)
+ {
+ if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl))
+ {
+ if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
+ {
+ cerr << queryctrl.name << " is disabled." << endl;
+ continue;
+ }
+
+ if (queryctrl.type == V4L2_CTRL_TYPE_INTEGER)
+ {
+ numbers = (numbers == NULL) ? (INumber *) malloc (sizeof(INumber)) :
+ (INumber *) realloc (numbers, (nnum+1) * sizeof (INumber));
+
+ num_ctrls = (num_ctrls == NULL) ? (unsigned int *) malloc (sizeof (unsigned int)) :
+ (unsigned int *) realloc (num_ctrls, (nnum+1) * sizeof (unsigned int));
+
+ strncpy(numbers[nnum].name, ((char *) queryctrl.name) , MAXINDINAME);
+ strncpy(numbers[nnum].label, ((char *) queryctrl.name), MAXINDILABEL);
+ strncpy(numbers[nnum].format, "%0.f", MAXINDIFORMAT);
+ numbers[nnum].min = queryctrl.minimum;
+ numbers[nnum].max = queryctrl.maximum;
+ numbers[nnum].step = queryctrl.step;
+ numbers[nnum].value = queryctrl.default_value;
+
+ /* Get current value if possible */
+ CLEAR(control);
+ control.id = queryctrl.id;
+ if (0 == xioctl(fd, VIDIOC_G_CTRL, &control))
+ numbers[nnum].value = control.value;
+
+ /* Store ID info in INumber. This is the first time ever I make use of aux0!! */
+ num_ctrls[nnum] = queryctrl.id;
+
+ nnum++;
+
+ }
+ }
+ else break;
+ }
+
+ /* Store numbers in aux0 */
+ for (int i=0; i < nnum; i++)
+ numbers[i].aux0 = &num_ctrls[i];
+
+ nvp->np = numbers;
+ nvp->nnp = nnum;
+
+ return nnum;
+
+}
+
+int V4L2_Base::setINTControl(unsigned int ctrl_id, double new_value, char *errmsg)
+{
+ struct v4l2_control control;
+
+ CLEAR(control);
+
+ cerr << "The id is " << ctrl_id << " new value is " << new_value << endl;
+
+ control.id = ctrl_id;
+ control.value = (int) new_value;
+
+ if (-1 == xioctl(fd, VIDIOC_S_CTRL, &control))
+ return errno_exit ("VIDIOC_S_CTRL", errmsg);
+
+ return 0;
+}
+
diff --git a/kstars/kstars/indi/webcam/v4l2_base.h b/kstars/kstars/indi/webcam/v4l2_base.h
new file mode 100644
index 00000000..668c77c9
--- /dev/null
+++ b/kstars/kstars/indi/webcam/v4l2_base.h
@@ -0,0 +1,141 @@
+/*
+ Copyright (C) 2005 by Jasem Mutlaq
+
+ Based on V4L 2 Example
+ http://v4l2spec.bytesex.org/spec-single/v4l2.html#CAPTURE-EXAMPLE
+
+ This library 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 library 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 library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#ifndef V4L2_BASE_H
+#define V4L2_BASE_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "videodev2.h"
+#include "../eventloop.h"
+#include "../indidevapi.h"
+
+#define VIDEO_COMPRESSION_LEVEL 4
+
+class V4L2_Base
+{
+ public:
+ V4L2_Base();
+ virtual ~V4L2_Base();
+
+ typedef enum { IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR } io_method;
+
+ struct buffer
+ {
+ void * start;
+ size_t length;
+ };
+
+ /* Connection */
+ virtual int connectCam(const char * devpath, char *errmsg, int pixelFormat = V4L2_PIX_FMT_YUYV , int width = 160, int height = 120);
+ virtual void disconnectCam();
+ char * getDeviceName();
+
+ /* Image settings */
+ int getBrightness();
+ int getContrast();
+ int getColor();
+ int getHue();
+ int getWhiteness();
+ void setContrast(int val);
+ void setBrightness(int val);
+ void setColor(int val);
+ void setHue(int val);
+ void setWhiteness(int val);
+
+ /* Updates */
+ void callFrame(void *p);
+ void setPictureSettings();
+ void getPictureSettings();
+
+ /* Image Size */
+ int getWidth();
+ int getHeight();
+ virtual int setSize(int x, int y);
+ virtual void getMaxMinSize(int & x_max, int & y_max, int & x_min, int & y_min);
+
+ /* Frame rate */
+ void setFPS(int fps);
+ int getFPS();
+
+ void allocBuffers();
+ unsigned char * getY();
+ unsigned char * getU();
+ unsigned char * getV();
+ unsigned char * getColorBuffer();
+
+ void registerCallback(WPF *fp, void *ud);
+
+ int start_capturing(char *errmsg);
+ int stop_capturing(char *errmsg);
+ static void newFrame(int fd, void *p);
+
+ void enumerate_ctrl (void);
+ void enumerate_menu (void);
+ int queryINTControls(INumberVectorProperty *nvp);
+ int setINTControl(unsigned int ctrl_id, double new_value, char *errmsg);
+
+ int query_ctrl(unsigned int ctrl_id, double & ctrl_min, double & ctrl_max, double & ctrl_step, double & ctrl_value, char *errmsg);
+
+ protected:
+
+ int xioctl(int fd, int request, void *arg);
+ int read_frame(char *errsg);
+ int uninit_device(char *errmsg);
+ int open_device(const char *devpath, char *errmsg);
+ int init_device(char *errmsg, int pixelFormat , int width, int height);
+ int init_mmap(char *errmsg);
+ int errno_exit(const char *s, char *errmsg);
+
+ void close_device(void);
+ void init_userp(unsigned int buffer_size);
+ void init_read(unsigned int buffer_size);
+
+ void findMinMax();
+
+ struct v4l2_capability cap;
+ struct v4l2_cropcap cropcap;
+ struct v4l2_crop crop;
+ struct v4l2_format fmt;
+
+ struct v4l2_queryctrl queryctrl;
+ struct v4l2_querymenu querymenu;
+
+ WPF *callback;
+ void *uptr;
+ char dev_name[64];
+ io_method io;
+ int fd;
+ struct buffer *buffers;
+ unsigned int n_buffers;
+
+ bool dropFrame;
+
+
+ int frameRate;
+ int xmax, xmin, ymax, ymin;
+ int selectCallBackID;
+ unsigned char * YBuf,*UBuf,*VBuf, *colorBuffer, *rgb24_buffer;
+
+};
+
+#endif
diff --git a/kstars/kstars/indi/webcam/vcvt.h b/kstars/kstars/indi/webcam/vcvt.h
new file mode 100644
index 00000000..9b765b41
--- /dev/null
+++ b/kstars/kstars/indi/webcam/vcvt.h
@@ -0,0 +1,73 @@
+/*
+ (C) 2001 Nemosoft Unv. nemosoft@smcc.demon.nl
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+
+/* 'Viewport' conversion routines. These functions convert from one colour
+ space to another, taking into account that the source image has a smaller
+ size than the view, and is placed inside the view:
+
+ +-------view.x------------+
+ | |
+ | +---image.x---+ |
+ | | | |
+ | | | |
+ | +-------------+ |
+ | |
+ +-------------------------+
+
+ The image should always be smaller than the view. The offset (top-left
+ corner of the image) should be precomputed, so you can place the image
+ anywhere in the view.
+
+ The functions take these parameters:
+ - width image width (in pixels)
+ - height image height (in pixels)
+ - plus view width (in pixels)
+ *src pointer at start of image
+ *dst pointer at offset (!) in view
+*/
+
+
+#ifndef VCVT_H
+#define VCVT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Functions in vcvt_i386.S/vcvt_c.c */
+/* 4:2:0 YUV interlaced to RGB/BGR */
+void vcvt_420i_bgr24(int width, int height, int plus, void *src, void *dst);
+void vcvt_420i_rgb24(int width, int height, int plus, void *src, void *dst);
+void vcvt_420i_bgr32(int width, int height, int plus, void *src, void *dst);
+void vcvt_420i_rgb32(int width, int height, int plus, void *src, void *dst);
+
+
+/* Go from 420i to other yuv formats */
+void vcvt_420i_420p(int width, int height, int plus, void *src, void *dsty, void *dstu, void *dstv);
+void vcvt_420i_yuyv(int width, int height, int plus, void *src, void *dst);
+
+#if 0
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/kstars/kstars/indi/webcam/videodev.h b/kstars/kstars/indi/webcam/videodev.h
new file mode 100644
index 00000000..a5b0aec7
--- /dev/null
+++ b/kstars/kstars/indi/webcam/videodev.h
@@ -0,0 +1,346 @@
+#ifndef __LINUX_VIDEODEV_H
+#define __LINUX_VIDEODEV_H
+
+#define VID_TYPE_CAPTURE 1 /* Can capture */
+#define VID_TYPE_TUNER 2 /* Can tune */
+#define VID_TYPE_TELETEXT 4 /* Does teletext */
+#define VID_TYPE_OVERLAY 8 /* Overlay onto frame buffer */
+#define VID_TYPE_CHROMAKEY 16 /* Overlay by chromakey */
+#define VID_TYPE_CLIPPING 32 /* Can clip */
+#define VID_TYPE_FRAMERAM 64 /* Uses the frame buffer memory */
+#define VID_TYPE_SCALES 128 /* Scalable */
+#define VID_TYPE_MONOCHROME 256 /* Monochrome only */
+#define VID_TYPE_SUBCAPTURE 512 /* Can capture subareas of the image */
+#define VID_TYPE_MPEG_DECODER 1024 /* Can decode MPEG streams */
+#define VID_TYPE_MPEG_ENCODER 2048 /* Can encode MPEG streams */
+#define VID_TYPE_MJPEG_DECODER 4096 /* Can decode MJPEG streams */
+#define VID_TYPE_MJPEG_ENCODER 8192 /* Can encode MJPEG streams */
+
+struct video_capability
+{
+ char name[32];
+ int type;
+ int channels; /* Num channels */
+ int audios; /* Num audio devices */
+ int maxwidth; /* Supported width */
+ int maxheight; /* And height */
+ int minwidth; /* Supported width */
+ int minheight; /* And height */
+};
+
+
+struct video_channel
+{
+ int channel;
+ char name[32];
+ int tuners;
+ unsigned int flags;
+#define VIDEO_VC_TUNER 1 /* Channel has a tuner */
+#define VIDEO_VC_AUDIO 2 /* Channel has audio */
+ unsigned short type;
+#define VIDEO_TYPE_TV 1
+#define VIDEO_TYPE_CAMERA 2
+ unsigned short norm; /* Norm set by channel */
+};
+
+struct video_tuner
+{
+ int tuner;
+ char name[32];
+ unsigned long rangelow, rangehigh; /* Tuner range */
+ unsigned int flags;
+#define VIDEO_TUNER_PAL 1
+#define VIDEO_TUNER_NTSC 2
+#define VIDEO_TUNER_SECAM 4
+#define VIDEO_TUNER_LOW 8 /* Uses KHz not MHz */
+#define VIDEO_TUNER_NORM 16 /* Tuner can set norm */
+#define VIDEO_TUNER_STEREO_ON 128 /* Tuner is seeing stereo */
+#define VIDEO_TUNER_RDS_ON 256 /* Tuner is seeing an RDS datastream */
+#define VIDEO_TUNER_MBS_ON 512 /* Tuner is seeing an MBS datastream */
+ unsigned short mode; /* PAL/NTSC/SECAM/OTHER */
+#define VIDEO_MODE_PAL 0
+#define VIDEO_MODE_NTSC 1
+#define VIDEO_MODE_SECAM 2
+#define VIDEO_MODE_AUTO 3
+ unsigned short signal; /* Signal strength 16bit scale */
+};
+
+struct video_picture
+{
+ unsigned short brightness;
+ unsigned short hue;
+ unsigned short colour;
+ unsigned short contrast;
+ unsigned short whiteness; /* Black and white only */
+ unsigned short depth; /* Capture depth */
+ unsigned short palette; /* Palette in use */
+#define VIDEO_PALETTE_GREY 1 /* Linear greyscale */
+#define VIDEO_PALETTE_HI240 2 /* High 240 cube (BT848) */
+#define VIDEO_PALETTE_RGB565 3 /* 565 16 bit RGB */
+#define VIDEO_PALETTE_RGB24 4 /* 24bit RGB */
+#define VIDEO_PALETTE_RGB32 5 /* 32bit RGB */
+#define VIDEO_PALETTE_RGB555 6 /* 555 15bit RGB */
+#define VIDEO_PALETTE_YUV422 7 /* YUV422 capture */
+#define VIDEO_PALETTE_YUYV 8
+#define VIDEO_PALETTE_UYVY 9 /* The great thing about standards is ... */
+#define VIDEO_PALETTE_YUV420 10
+#define VIDEO_PALETTE_YUV411 11 /* YUV411 capture */
+#define VIDEO_PALETTE_RAW 12 /* RAW capture (BT848) */
+#define VIDEO_PALETTE_YUV422P 13 /* YUV 4:2:2 Planar */
+#define VIDEO_PALETTE_YUV411P 14 /* YUV 4:1:1 Planar */
+#define VIDEO_PALETTE_YUV420P 15 /* YUV 4:2:0 Planar */
+#define VIDEO_PALETTE_YUV410P 16 /* YUV 4:1:0 Planar */
+#define VIDEO_PALETTE_PLANAR 13 /* start of planar entries */
+#define VIDEO_PALETTE_COMPONENT 7 /* start of component entries */
+};
+
+struct video_audio
+{
+ int audio; /* Audio channel */
+ unsigned short volume; /* If settable */
+ unsigned short bass, treble;
+ unsigned int flags;
+#define VIDEO_AUDIO_MUTE 1
+#define VIDEO_AUDIO_MUTABLE 2
+#define VIDEO_AUDIO_VOLUME 4
+#define VIDEO_AUDIO_BASS 8
+#define VIDEO_AUDIO_TREBLE 16
+#define VIDEO_AUDIO_BALANCE 32
+ char name[16];
+#define VIDEO_SOUND_MONO 1
+#define VIDEO_SOUND_STEREO 2
+#define VIDEO_SOUND_LANG1 4
+#define VIDEO_SOUND_LANG2 8
+ unsigned short mode;
+ unsigned short balance; /* Stereo balance */
+ unsigned short step; /* Step actual volume uses */
+};
+
+struct video_clip
+{
+ int x,y;
+ int width, height;
+ struct video_clip *next; /* For user use/driver use only */
+};
+
+struct video_window
+{
+ unsigned int x,y; /* Position of window */
+ unsigned int width,height; /* Its size */
+ unsigned int chromakey;
+ unsigned int flags;
+ struct video_clip *clips; /* Set only */
+ int clipcount;
+#define VIDEO_WINDOW_INTERLACE 1
+#define VIDEO_WINDOW_CHROMAKEY 16 /* Overlay by chromakey */
+#define VIDEO_CLIP_BITMAP -1
+/* bitmap is 1024x625, a '1' bit represents a clipped pixel */
+#define VIDEO_CLIPMAP_SIZE (128 * 625)
+};
+
+struct video_capture
+{
+ unsigned int x,y; /* Offsets into image */
+ unsigned int width, height; /* Area to capture */
+ unsigned short decimation; /* Decimation divider */
+ unsigned short flags; /* Flags for capture */
+#define VIDEO_CAPTURE_ODD 0 /* Temporal */
+#define VIDEO_CAPTURE_EVEN 1
+};
+
+struct video_buffer
+{
+ void *base;
+ int height,width;
+ int depth;
+ int bytesperline;
+};
+
+struct video_mmap
+{
+ unsigned int frame; /* Frame (0 - n) for double buffer */
+ int height,width;
+ unsigned int format; /* should be VIDEO_PALETTE_* */
+};
+
+struct video_key
+{
+ unsigned char key[8];
+ unsigned int flags;
+};
+
+
+#define VIDEO_MAX_FRAME 32
+
+struct video_mbuf
+{
+ int size; /* Total memory to map */
+ int frames; /* Frames */
+ int offsets[VIDEO_MAX_FRAME];
+};
+
+
+#define VIDEO_NO_UNIT (-1)
+
+
+struct video_unit
+{
+ int video; /* Video minor */
+ int vbi; /* VBI minor */
+ int radio; /* Radio minor */
+ int audio; /* Audio minor */
+ int teletext; /* Teletext minor */
+};
+
+struct vbi_format {
+ unsigned int sampling_rate; /* in Hz */
+ unsigned int samples_per_line;
+ unsigned int sample_format; /* VIDEO_PALETTE_RAW only (1 byte) */
+ int start[2]; /* starting line for each frame */
+ unsigned int count[2]; /* count of lines for each frame */
+ unsigned int flags;
+#define VBI_UNSYNC 1 /* can distingues between top/bottom field */
+#define VBI_INTERLACED 2 /* lines are interlaced */
+};
+
+/* video_info is biased towards hardware mpeg encode/decode */
+/* but it could apply generically to any hardware compressor/decompressor */
+struct video_info
+{
+ unsigned int frame_count; /* frames output since decode/encode began */
+ unsigned int h_size; /* current unscaled horizontal size */
+ unsigned int v_size; /* current unscaled veritcal size */
+ unsigned int smpte_timecode; /* current SMPTE timecode (for current GOP) */
+ unsigned int picture_type; /* current picture type */
+ unsigned int temporal_reference; /* current temporal reference */
+ unsigned char user_data[256]; /* user data last found in compressed stream */
+ /* user_data[0] contains user data flags, user_data[1] has count */
+};
+
+/* generic structure for setting playback modes */
+struct video_play_mode
+{
+ int mode;
+ int p1;
+ int p2;
+};
+
+/* for loading microcode / fpga programming */
+struct video_code
+{
+ char loadwhat[16]; /* name or tag of file being passed */
+ int datasize;
+ unsigned char *data;
+};
+
+#define VIDIOCGCAP _IOR('v',1,struct video_capability) /* Get capabilities */
+#define VIDIOCGCHAN _IOWR('v',2,struct video_channel) /* Get channel info (sources) */
+#define VIDIOCSCHAN _IOW('v',3,struct video_channel) /* Set channel */
+#define VIDIOCGTUNER _IOWR('v',4,struct video_tuner) /* Get tuner abilities */
+#define VIDIOCSTUNER _IOW('v',5,struct video_tuner) /* Tune the tuner for the current channel */
+#define VIDIOCGPICT _IOR('v',6,struct video_picture) /* Get picture properties */
+#define VIDIOCSPICT _IOW('v',7,struct video_picture) /* Set picture properties */
+#define VIDIOCCAPTURE _IOW('v',8,int) /* Start, end capture */
+#define VIDIOCGWIN _IOR('v',9, struct video_window) /* Get the video overlay window */
+#define VIDIOCSWIN _IOW('v',10, struct video_window) /* Set the video overlay window - passes clip list for hardware smarts , chromakey etc */
+#define VIDIOCGFBUF _IOR('v',11, struct video_buffer) /* Get frame buffer */
+#define VIDIOCSFBUF _IOW('v',12, struct video_buffer) /* Set frame buffer - root only */
+#define VIDIOCKEY _IOR('v',13, struct video_key) /* Video key event - to dev 255 is to all - cuts capture on all DMA windows with this key (0xFFFFFFFF == all) */
+#define VIDIOCGFREQ _IOR('v',14, unsigned long) /* Set tuner */
+#define VIDIOCSFREQ _IOW('v',15, unsigned long) /* Set tuner */
+#define VIDIOCGAUDIO _IOR('v',16, struct video_audio) /* Get audio info */
+#define VIDIOCSAUDIO _IOW('v',17, struct video_audio) /* Audio source, mute etc */
+#define VIDIOCSYNC _IOW('v',18, int) /* Sync with mmap grabbing */
+#define VIDIOCMCAPTURE _IOW('v',19, struct video_mmap) /* Grab frames */
+#define VIDIOCGMBUF _IOR('v',20, struct video_mbuf) /* Memory map buffer info */
+#define VIDIOCGUNIT _IOR('v',21, struct video_unit) /* Get attached units */
+#define VIDIOCGCAPTURE _IOR('v',22, struct video_capture) /* Get subcapture */
+#define VIDIOCSCAPTURE _IOW('v',23, struct video_capture) /* Set subcapture */
+#define VIDIOCSPLAYMODE _IOW('v',24, struct video_play_mode) /* Set output video mode/feature */
+#define VIDIOCSWRITEMODE _IOW('v',25, int) /* Set write mode */
+#define VIDIOCGPLAYINFO _IOR('v',26, struct video_info) /* Get current playback info from hardware */
+#define VIDIOCSMICROCODE _IOW('v',27, struct video_code) /* Load microcode into hardware */
+#define VIDIOCGVBIFMT _IOR('v',28, struct vbi_format) /* Get VBI information */
+#define VIDIOCSVBIFMT _IOW('v',29, struct vbi_format) /* Set VBI information */
+
+
+#define BASE_VIDIOCPRIVATE 192 /* 192-255 are private */
+
+/* VIDIOCSWRITEMODE */
+#define VID_WRITE_MPEG_AUD 0
+#define VID_WRITE_MPEG_VID 1
+#define VID_WRITE_OSD 2
+#define VID_WRITE_TTX 3
+#define VID_WRITE_CC 4
+#define VID_WRITE_MJPEG 5
+
+/* VIDIOCSPLAYMODE */
+#define VID_PLAY_VID_OUT_MODE 0
+ /* p1: = VIDEO_MODE_PAL, VIDEO_MODE_NTSC, etc ... */
+#define VID_PLAY_GENLOCK 1
+ /* p1: 0 = OFF, 1 = ON */
+ /* p2: GENLOCK FINE DELAY value */
+#define VID_PLAY_NORMAL 2
+#define VID_PLAY_PAUSE 3
+#define VID_PLAY_SINGLE_FRAME 4
+#define VID_PLAY_FAST_FORWARD 5
+#define VID_PLAY_SLOW_MOTION 6
+#define VID_PLAY_IMMEDIATE_NORMAL 7
+#define VID_PLAY_SWITCH_CHANNELS 8
+#define VID_PLAY_FREEZE_FRAME 9
+#define VID_PLAY_STILL_MODE 10
+#define VID_PLAY_MASTER_MODE 11
+ /* p1: see below */
+#define VID_PLAY_MASTER_NONE 1
+#define VID_PLAY_MASTER_VIDEO 2
+#define VID_PLAY_MASTER_AUDIO 3
+#define VID_PLAY_ACTIVE_SCANLINES 12
+ /* p1 = first active; p2 = last active */
+#define VID_PLAY_RESET 13
+#define VID_PLAY_END_MARK 14
+
+
+
+#define VID_HARDWARE_BT848 1
+#define VID_HARDWARE_QCAM_BW 2
+#define VID_HARDWARE_PMS 3
+#define VID_HARDWARE_QCAM_C 4
+#define VID_HARDWARE_PSEUDO 5
+#define VID_HARDWARE_SAA5249 6
+#define VID_HARDWARE_AZTECH 7
+#define VID_HARDWARE_SF16MI 8
+#define VID_HARDWARE_RTRACK 9
+#define VID_HARDWARE_ZOLTRIX 10
+#define VID_HARDWARE_SAA7146 11
+#define VID_HARDWARE_VIDEUM 12 /* Reserved for Winnov videum */
+#define VID_HARDWARE_RTRACK2 13
+#define VID_HARDWARE_PERMEDIA2 14 /* Reserved for Permedia2 */
+#define VID_HARDWARE_RIVA128 15 /* Reserved for RIVA 128 */
+#define VID_HARDWARE_PLANB 16 /* PowerMac motherboard video-in */
+#define VID_HARDWARE_BROADWAY 17 /* Broadway project */
+#define VID_HARDWARE_GEMTEK 18
+#define VID_HARDWARE_TYPHOON 19
+#define VID_HARDWARE_VINO 20 /* SGI Indy Vino */
+#define VID_HARDWARE_CADET 21 /* Cadet radio */
+#define VID_HARDWARE_TRUST 22 /* Trust FM Radio */
+#define VID_HARDWARE_TERRATEC 23 /* TerraTec ActiveRadio */
+#define VID_HARDWARE_CPIA 24
+#define VID_HARDWARE_ZR36120 25 /* Zoran ZR36120/ZR36125 */
+#define VID_HARDWARE_ZR36067 26 /* Zoran ZR36067/36060 */
+#define VID_HARDWARE_OV511 27
+#define VID_HARDWARE_ZR356700 28 /* Zoran 36700 series */
+#define VID_HARDWARE_W9966 29
+#define VID_HARDWARE_SE401 30 /* SE401 USB webcams */
+#define VID_HARDWARE_PWC 31 /* Philips webcams */
+#define VID_HARDWARE_MEYE 32 /* Sony Vaio MotionEye cameras */
+#define VID_HARDWARE_CPIA2 33
+#define VID_HARDWARE_VICAM 34
+#define VID_HARDWARE_SF16FMR2 35
+#define VID_HARDWARE_W9968CF 36
+#endif /* __LINUX_VIDEODEV_H */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/kstars/kstars/indi/webcam/videodev2.h b/kstars/kstars/indi/webcam/videodev2.h
new file mode 100644
index 00000000..e3dab3a6
--- /dev/null
+++ b/kstars/kstars/indi/webcam/videodev2.h
@@ -0,0 +1,903 @@
+#ifndef __LINUX_VIDEODEV2_H
+#define __LINUX_VIDEODEV2_H
+/*
+ * Video for Linux Two
+ *
+ * Header file for v4l or V4L2 drivers and applications, for
+ * Linux kernels 2.2.x or 2.4.x.
+ *
+ * See http://bytesex.org/v4l/ for API specs and other
+ * v4l2 documentation.
+ *
+ * Author: Bill Dirks <bdirks@pacbell.net>
+ * Justin Schoeman
+ * et al.
+ */
+/*
+ * M I S C E L L A N E O U S
+ */
+
+/* Four-character-code (FOURCC) */
+#define v4l2_fourcc(a,b,c,d)\
+ (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))
+
+/*
+ * E N U M S
+ */
+enum v4l2_field {
+ V4L2_FIELD_ANY = 0, /* driver can choose from none,
+ top, bottom, interlaced
+ depending on whatever it thinks
+ is approximate ... */
+ V4L2_FIELD_NONE = 1, /* this device has no fields ... */
+ V4L2_FIELD_TOP = 2, /* top field only */
+ V4L2_FIELD_BOTTOM = 3, /* bottom field only */
+ V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */
+ V4L2_FIELD_SEQ_TB = 5, /* both fields sequential into one
+ buffer, top-bottom order */
+ V4L2_FIELD_SEQ_BT = 6, /* same as above + bottom-top order */
+ V4L2_FIELD_ALTERNATE = 7 /* both fields alternating into
+ separate buffers */
+};
+#define V4L2_FIELD_HAS_TOP(field) \
+ ((field) == V4L2_FIELD_TOP ||\
+ (field) == V4L2_FIELD_INTERLACED ||\
+ (field) == V4L2_FIELD_SEQ_TB ||\
+ (field) == V4L2_FIELD_SEQ_BT)
+#define V4L2_FIELD_HAS_BOTTOM(field) \
+ ((field) == V4L2_FIELD_BOTTOM ||\
+ (field) == V4L2_FIELD_INTERLACED ||\
+ (field) == V4L2_FIELD_SEQ_TB ||\
+ (field) == V4L2_FIELD_SEQ_BT)
+#define V4L2_FIELD_HAS_BOTH(field) \
+ ((field) == V4L2_FIELD_INTERLACED ||\
+ (field) == V4L2_FIELD_SEQ_TB ||\
+ (field) == V4L2_FIELD_SEQ_BT)
+
+enum v4l2_buf_type {
+ V4L2_BUF_TYPE_VIDEO_CAPTURE = 1,
+ V4L2_BUF_TYPE_VIDEO_OUTPUT = 2,
+ V4L2_BUF_TYPE_VIDEO_OVERLAY = 3,
+ V4L2_BUF_TYPE_VBI_CAPTURE = 4,
+ V4L2_BUF_TYPE_VBI_OUTPUT = 5,
+ V4L2_BUF_TYPE_PRIVATE = 0x80
+};
+
+enum v4l2_ctrl_type {
+ V4L2_CTRL_TYPE_INTEGER = 1,
+ V4L2_CTRL_TYPE_BOOLEAN = 2,
+ V4L2_CTRL_TYPE_MENU = 3,
+ V4L2_CTRL_TYPE_BUTTON = 4
+};
+
+enum v4l2_tuner_type {
+ V4L2_TUNER_RADIO = 1,
+ V4L2_TUNER_ANALOG_TV = 2
+};
+
+enum v4l2_memory {
+ V4L2_MEMORY_MMAP = 1,
+ V4L2_MEMORY_USERPTR = 2,
+ V4L2_MEMORY_OVERLAY = 3
+};
+
+/* see also http://vektor.theorem.ca/graphics/ycbcr/ */
+enum v4l2_colorspace {
+ /* ITU-R 601 -- broadcast NTSC/PAL */
+ V4L2_COLORSPACE_SMPTE170M = 1,
+
+ /* 1125-Line (US) HDTV */
+ V4L2_COLORSPACE_SMPTE240M = 2,
+
+ /* HD and modern captures. */
+ V4L2_COLORSPACE_REC709 = 3,
+
+ /* broken BT878 extents (601, luma range 16-253 instead of 16-235) */
+ V4L2_COLORSPACE_BT878 = 4,
+
+ /* These should be useful. Assume 601 extents. */
+ V4L2_COLORSPACE_470_SYSTEM_M = 5,
+ V4L2_COLORSPACE_470_SYSTEM_BG = 6,
+
+ /* I know there will be cameras that send this. So, this is
+ * unspecified chromaticities and full 0-255 on each of the
+ * Y'CbCr components
+ */
+ V4L2_COLORSPACE_JPEG = 7,
+
+ /* For RGB colourspaces, this is probably a good start. */
+ V4L2_COLORSPACE_SRGB = 8
+};
+
+enum v4l2_priority {
+ V4L2_PRIORITY_UNSET = 0, /* not initialized */
+ V4L2_PRIORITY_BACKGROUND = 1,
+ V4L2_PRIORITY_INTERACTIVE = 2,
+ V4L2_PRIORITY_RECORD = 3,
+ V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE
+};
+
+struct v4l2_rect {
+ __s32 left;
+ __s32 top;
+ __s32 width;
+ __s32 height;
+};
+
+struct v4l2_fract {
+ __u32 numerator;
+ __u32 denominator;
+};
+
+/*
+ * D R I V E R C A P A B I L I T I E S
+ */
+struct v4l2_capability
+{
+ __u8 driver[16]; /* i.e. "bttv" */
+ __u8 card[32]; /* i.e. "Hauppauge WinTV" */
+ __u8 bus_info[32]; /* "PCI:" + pci_name(pci_dev) */
+ __u32 version; /* should use KERNEL_VERSION() */
+ __u32 capabilities; /* Device capabilities */
+ __u32 reserved[4];
+};
+
+/* Values for 'capabilities' field */
+#define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */
+#define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */
+#define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */
+#define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a VBI capture device */
+#define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a VBI output device */
+#define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */
+
+#define V4L2_CAP_TUNER 0x00010000 /* has a tuner */
+#define V4L2_CAP_AUDIO 0x00020000 /* has audio support */
+#define V4L2_CAP_RADIO 0x00040000 /* is a radio device */
+
+#define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */
+#define V4L2_CAP_ASYNCIO 0x02000000 /* async I/O */
+#define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls */
+
+/*
+ * V I D E O I M A G E F O R M A T
+ */
+
+struct v4l2_pix_format
+{
+ __u32 width;
+ __u32 height;
+ __u32 pixelformat;
+ enum v4l2_field field;
+ __u32 bytesperline; /* for padding, zero if unused */
+ __u32 sizeimage;
+ enum v4l2_colorspace colorspace;
+ __u32 priv; /* private data, depends on pixelformat */
+};
+
+/* Pixel format FOURCC depth Description */
+#define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R','G','B','1') /* 8 RGB-3-3-2 */
+#define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R','G','B','O') /* 16 RGB-5-5-5 */
+#define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R','G','B','P') /* 16 RGB-5-6-5 */
+#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R','G','B','Q') /* 16 RGB-5-5-5 BE */
+#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R','G','B','R') /* 16 RGB-5-6-5 BE */
+#define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B','G','R','3') /* 24 BGR-8-8-8 */
+#define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R','G','B','3') /* 24 RGB-8-8-8 */
+#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B','G','R','4') /* 32 BGR-8-8-8-8 */
+#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R','G','B','4') /* 32 RGB-8-8-8-8 */
+#define V4L2_PIX_FMT_GREY v4l2_fourcc('G','R','E','Y') /* 8 Greyscale */
+#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y','V','U','9') /* 9 YVU 4:1:0 */
+#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y','V','1','2') /* 12 YVU 4:2:0 */
+#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y','U','Y','V') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_UYVY v4l2_fourcc('U','Y','V','Y') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4','2','2','P') /* 16 YVU422 planar */
+#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4','1','1','P') /* 16 YVU411 planar */
+#define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y','4','1','P') /* 12 YUV 4:1:1 */
+
+/* two planes -- one Y, one Cr + Cb interleaved */
+#define V4L2_PIX_FMT_NV12 v4l2_fourcc('N','V','1','2') /* 12 Y/CbCr 4:2:0 */
+#define V4L2_PIX_FMT_NV21 v4l2_fourcc('N','V','2','1') /* 12 Y/CrCb 4:2:0 */
+
+/* The following formats are not defined in the V4L2 specification */
+#define V4L2_PIX_FMT_YUV410 v4l2_fourcc('Y','U','V','9') /* 9 YUV 4:1:0 */
+#define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y','U','1','2') /* 12 YUV 4:2:0 */
+#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y','Y','U','V') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H','I','2','4') /* 8 8-bit color */
+
+/* see http://www.siliconimaging.com/RGB%20Bayer.htm */
+#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */
+
+/* compressed formats */
+#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M','J','P','G') /* Motion-JPEG */
+#define V4L2_PIX_FMT_JPEG v4l2_fourcc('J','P','E','G') /* JFIF JPEG */
+#define V4L2_PIX_FMT_DV v4l2_fourcc('d','v','s','d') /* 1394 */
+#define V4L2_PIX_FMT_MPEG v4l2_fourcc('M','P','E','G') /* MPEG */
+
+/* Vendor-specific formats */
+#define V4L2_PIX_FMT_WNVA v4l2_fourcc('W','N','V','A') /* Winnov hw compress */
+
+/*
+ * F O R M A T E N U M E R A T I O N
+ */
+struct v4l2_fmtdesc
+{
+ __u32 index; /* Format number */
+ enum v4l2_buf_type type; /* buffer type */
+ __u32 flags;
+ __u8 description[32]; /* Description string */
+ __u32 pixelformat; /* Format fourcc */
+ __u32 reserved[4];
+};
+
+#define V4L2_FMT_FLAG_COMPRESSED 0x0001
+
+
+/*
+ * T I M E C O D E
+ */
+struct v4l2_timecode
+{
+ __u32 type;
+ __u32 flags;
+ __u8 frames;
+ __u8 seconds;
+ __u8 minutes;
+ __u8 hours;
+ __u8 userbits[4];
+};
+
+/* Type */
+#define V4L2_TC_TYPE_24FPS 1
+#define V4L2_TC_TYPE_25FPS 2
+#define V4L2_TC_TYPE_30FPS 3
+#define V4L2_TC_TYPE_50FPS 4
+#define V4L2_TC_TYPE_60FPS 5
+
+/* Flags */
+#define V4L2_TC_FLAG_DROPFRAME 0x0001 /* "drop-frame" mode */
+#define V4L2_TC_FLAG_COLORFRAME 0x0002
+#define V4L2_TC_USERBITS_field 0x000C
+#define V4L2_TC_USERBITS_USERDEFINED 0x0000
+#define V4L2_TC_USERBITS_8BITCHARS 0x0008
+/* The above is based on SMPTE timecodes */
+
+
+/*
+ * C O M P R E S S I O N P A R A M E T E R S
+ */
+#if 0
+/* ### generic compression settings don't work, there is too much
+ * ### codec-specific stuff. Maybe reuse that for MPEG codec settings
+ * ### later ... */
+struct v4l2_compression
+{
+ __u32 quality;
+ __u32 keyframerate;
+ __u32 pframerate;
+ __u32 reserved[5];
+
+/* what we'll need for MPEG, extracted from some postings on
+ the v4l list (Gert Vervoort, PlasmaJohn).
+
+system stream:
+ - type: elementary stream(ES), packatised elementary stream(s) (PES)
+ program stream(PS), transport stream(TS)
+ - system bitrate
+ - PS packet size (DVD: 2048 bytes, VCD: 2324 bytes)
+ - TS video PID
+ - TS audio PID
+ - TS PCR PID
+ - TS system information tables (PAT, PMT, CAT, NIT and SIT)
+ - (MPEG-1 systems stream vs. MPEG-2 program stream (TS not supported
+ by MPEG-1 systems)
+
+audio:
+ - type: MPEG (+Layer I,II,III), AC-3, LPCM
+ - bitrate
+ - sampling frequency (DVD: 48 Khz, VCD: 44.1 KHz, 32 kHz)
+ - Trick Modes? (ff, rew)
+ - Copyright
+ - Inverse Telecine
+
+video:
+ - picturesize (SIF, 1/2 D1, 2/3 D1, D1) and PAL/NTSC norm can be set
+ through excisting V4L2 controls
+ - noise reduction, parameters encoder specific?
+ - MPEG video version: MPEG-1, MPEG-2
+ - GOP (Group Of Pictures) definition:
+ - N: number of frames per GOP
+ - M: distance between reference (I,P) frames
+ - open/closed GOP
+ - quantiser matrix: inter Q matrix (64 bytes) and intra Q matrix (64 bytes)
+ - quantiser scale: linear or logarithmic
+ - scanning: alternate or zigzag
+ - bitrate mode: CBR (constant bitrate) or VBR (variable bitrate).
+ - target video bitrate for CBR
+ - target video bitrate for VBR
+ - maximum video bitrate for VBR - min. quantiser value for VBR
+ - max. quantiser value for VBR
+ - adaptive quantisation value
+ - return the number of bytes per GOP or bitrate for bitrate monitoring
+
+*/
+};
+#endif
+
+struct v4l2_jpegcompression
+{
+ int quality;
+
+ int APPn; /* Number of APP segment to be written,
+ * must be 0..15 */
+ int APP_len; /* Length of data in JPEG APPn segment */
+ char APP_data[60]; /* Data in the JPEG APPn segment. */
+
+ int COM_len; /* Length of data in JPEG COM segment */
+ char COM_data[60]; /* Data in JPEG COM segment */
+
+ __u32 jpeg_markers; /* Which markers should go into the JPEG
+ * output. Unless you exactly know what
+ * you do, leave them untouched.
+ * Inluding less markers will make the
+ * resulting code smaller, but there will
+ * be fewer aplications which can read it.
+ * The presence of the APP and COM marker
+ * is influenced by APP_len and COM_len
+ * ONLY, not by this property! */
+
+#define V4L2_JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
+#define V4L2_JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
+#define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
+#define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */
+#define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will
+ * allways use APP0 */
+};
+
+
+/*
+ * M E M O R Y - M A P P I N G B U F F E R S
+ */
+struct v4l2_requestbuffers
+{
+ __u32 count;
+ enum v4l2_buf_type type;
+ enum v4l2_memory memory;
+ __u32 reserved[2];
+};
+
+struct v4l2_buffer
+{
+ __u32 index;
+ enum v4l2_buf_type type;
+ __u32 bytesused;
+ __u32 flags;
+ enum v4l2_field field;
+ struct timeval timestamp;
+ struct v4l2_timecode timecode;
+ __u32 sequence;
+
+ /* memory location */
+ enum v4l2_memory memory;
+ union {
+ __u32 offset;
+ unsigned long userptr;
+ } m;
+ __u32 length;
+ __u32 input;
+ __u32 reserved;
+};
+
+/* Flags for 'flags' field */
+#define V4L2_BUF_FLAG_MAPPED 0x0001 /* Buffer is mapped (flag) */
+#define V4L2_BUF_FLAG_QUEUED 0x0002 /* Buffer is queued for processing */
+#define V4L2_BUF_FLAG_DONE 0x0004 /* Buffer is ready */
+#define V4L2_BUF_FLAG_KEYFRAME 0x0008 /* Image is a keyframe (I-frame) */
+#define V4L2_BUF_FLAG_PFRAME 0x0010 /* Image is a P-frame */
+#define V4L2_BUF_FLAG_BFRAME 0x0020 /* Image is a B-frame */
+#define V4L2_BUF_FLAG_TIMECODE 0x0100 /* timecode field is valid */
+#define V4L2_BUF_FLAG_INPUT 0x0200 /* input field is valid */
+
+/*
+ * O V E R L A Y P R E V I E W
+ */
+struct v4l2_framebuffer
+{
+ __u32 capability;
+ __u32 flags;
+/* FIXME: in theory we should pass something like PCI device + memory
+ * region + offset instead of some physical address */
+ void* base;
+ struct v4l2_pix_format fmt;
+};
+/* Flags for the 'capability' field. Read only */
+#define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001
+#define V4L2_FBUF_CAP_CHROMAKEY 0x0002
+#define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004
+#define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008
+/* Flags for the 'flags' field. */
+#define V4L2_FBUF_FLAG_PRIMARY 0x0001
+#define V4L2_FBUF_FLAG_OVERLAY 0x0002
+#define V4L2_FBUF_FLAG_CHROMAKEY 0x0004
+
+struct v4l2_clip
+{
+ struct v4l2_rect c;
+ struct v4l2_clip *next;
+};
+
+struct v4l2_window
+{
+ struct v4l2_rect w;
+ enum v4l2_field field;
+ __u32 chromakey;
+ struct v4l2_clip *clips;
+ __u32 clipcount;
+ void *bitmap;
+};
+
+
+/*
+ * C A P T U R E P A R A M E T E R S
+ */
+struct v4l2_captureparm
+{
+ __u32 capability; /* Supported modes */
+ __u32 capturemode; /* Current mode */
+ struct v4l2_fract timeperframe; /* Time per frame in .1us units */
+ __u32 extendedmode; /* Driver-specific extensions */
+ __u32 readbuffers; /* # of buffers for read */
+ __u32 reserved[4];
+};
+/* Flags for 'capability' and 'capturemode' fields */
+#define V4L2_MODE_HIGHQUALITY 0x0001 /* High quality imaging mode */
+#define V4L2_CAP_TIMEPERFRAME 0x1000 /* timeperframe field is supported */
+
+struct v4l2_outputparm
+{
+ __u32 capability; /* Supported modes */
+ __u32 outputmode; /* Current mode */
+ struct v4l2_fract timeperframe; /* Time per frame in seconds */
+ __u32 extendedmode; /* Driver-specific extensions */
+ __u32 writebuffers; /* # of buffers for write */
+ __u32 reserved[4];
+};
+
+/*
+ * I N P U T I M A G E C R O P P I N G
+ */
+
+struct v4l2_cropcap {
+ enum v4l2_buf_type type;
+ struct v4l2_rect bounds;
+ struct v4l2_rect defrect;
+ struct v4l2_fract pixelaspect;
+};
+
+struct v4l2_crop {
+ enum v4l2_buf_type type;
+ struct v4l2_rect c;
+};
+
+/*
+ * A N A L O G V I D E O S T A N D A R D
+ */
+
+typedef __u64 v4l2_std_id;
+
+/* one bit for each */
+#define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001)
+#define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002)
+#define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004)
+#define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008)
+#define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010)
+#define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020)
+#define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040)
+#define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080)
+
+#define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100)
+#define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200)
+#define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400)
+#define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800)
+
+#define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000)
+#define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000)
+
+#define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000)
+#define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000)
+#define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000)
+#define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000)
+#define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000)
+#define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000)
+#define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000)
+
+/* ATSC/HDTV */
+#define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000)
+#define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000)
+
+/* some common needed stuff */
+#define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\
+ V4L2_STD_PAL_B1 |\
+ V4L2_STD_PAL_G)
+#define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\
+ V4L2_STD_PAL_D1 |\
+ V4L2_STD_PAL_K)
+#define V4L2_STD_PAL (V4L2_STD_PAL_BG |\
+ V4L2_STD_PAL_DK |\
+ V4L2_STD_PAL_H |\
+ V4L2_STD_PAL_I)
+#define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\
+ V4L2_STD_NTSC_M_JP)
+#define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D |\
+ V4L2_STD_SECAM_K |\
+ V4L2_STD_SECAM_K1)
+#define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\
+ V4L2_STD_SECAM_G |\
+ V4L2_STD_SECAM_H |\
+ V4L2_STD_SECAM_DK |\
+ V4L2_STD_SECAM_L)
+
+#define V4L2_STD_525_60 (V4L2_STD_PAL_M |\
+ V4L2_STD_PAL_60 |\
+ V4L2_STD_NTSC)
+#define V4L2_STD_625_50 (V4L2_STD_PAL |\
+ V4L2_STD_PAL_N |\
+ V4L2_STD_PAL_Nc |\
+ V4L2_STD_SECAM)
+#define V4L2_STD_ATSC (V4L2_STD_ATSC_8_VSB |\
+ V4L2_STD_ATSC_16_VSB)
+
+#define V4L2_STD_UNKNOWN 0
+#define V4L2_STD_ALL (V4L2_STD_525_60 |\
+ V4L2_STD_625_50)
+
+struct v4l2_standard
+{
+ __u32 index;
+ v4l2_std_id id;
+ __u8 name[24];
+ struct v4l2_fract frameperiod; /* Frames, not fields */
+ __u32 framelines;
+ __u32 reserved[4];
+};
+
+
+/*
+ * V I D E O I N P U T S
+ */
+struct v4l2_input
+{
+ __u32 index; /* Which input */
+ __u8 name[32]; /* Label */
+ __u32 type; /* Type of input */
+ __u32 audioset; /* Associated audios (bitfield) */
+ __u32 tuner; /* Associated tuner */
+ v4l2_std_id std;
+ __u32 status;
+ __u32 reserved[4];
+};
+/* Values for the 'type' field */
+#define V4L2_INPUT_TYPE_TUNER 1
+#define V4L2_INPUT_TYPE_CAMERA 2
+
+/* field 'status' - general */
+#define V4L2_IN_ST_NO_POWER 0x00000001 /* Attached device is off */
+#define V4L2_IN_ST_NO_SIGNAL 0x00000002
+#define V4L2_IN_ST_NO_COLOR 0x00000004
+
+/* field 'status' - analog */
+#define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */
+#define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */
+
+/* field 'status' - digital */
+#define V4L2_IN_ST_NO_SYNC 0x00010000 /* No synchronization lock */
+#define V4L2_IN_ST_NO_EQU 0x00020000 /* No equalizer lock */
+#define V4L2_IN_ST_NO_CARRIER 0x00040000 /* Carrier recovery failed */
+
+/* field 'status' - VCR and set-top box */
+#define V4L2_IN_ST_MACROVISION 0x01000000 /* Macrovision detected */
+#define V4L2_IN_ST_NO_ACCESS 0x02000000 /* Conditional access denied */
+#define V4L2_IN_ST_VTR 0x04000000 /* VTR time constant */
+
+/*
+ * V I D E O O U T P U T S
+ */
+struct v4l2_output
+{
+ __u32 index; /* Which output */
+ __u8 name[32]; /* Label */
+ __u32 type; /* Type of output */
+ __u32 audioset; /* Associated audios (bitfield) */
+ __u32 modulator; /* Associated modulator */
+ v4l2_std_id std;
+ __u32 reserved[4];
+};
+/* Values for the 'type' field */
+#define V4L2_OUTPUT_TYPE_MODULATOR 1
+#define V4L2_OUTPUT_TYPE_ANALOG 2
+#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3
+
+/*
+ * C O N T R O L S
+ */
+struct v4l2_control
+{
+ __u32 id;
+ __s32 value;
+};
+
+/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
+struct v4l2_queryctrl
+{
+ __u32 id;
+ enum v4l2_ctrl_type type;
+ __u8 name[32]; /* Whatever */
+ __s32 minimum; /* Note signedness */
+ __s32 maximum;
+ __s32 step;
+ __s32 default_value;
+ __u32 flags;
+ __u32 reserved[2];
+};
+
+/* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */
+struct v4l2_querymenu
+{
+ __u32 id;
+ __u32 index;
+ __u8 name[32]; /* Whatever */
+ __u32 reserved;
+};
+
+/* Control flags */
+#define V4L2_CTRL_FLAG_DISABLED 0x0001
+#define V4L2_CTRL_FLAG_GRABBED 0x0002
+
+/* Control IDs defined by V4L2 */
+#define V4L2_CID_BASE 0x00980900
+/* IDs reserved for driver specific controls */
+#define V4L2_CID_PRIVATE_BASE 0x08000000
+
+#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0)
+#define V4L2_CID_CONTRAST (V4L2_CID_BASE+1)
+#define V4L2_CID_SATURATION (V4L2_CID_BASE+2)
+#define V4L2_CID_HUE (V4L2_CID_BASE+3)
+#define V4L2_CID_AUDIO_VOLUME (V4L2_CID_BASE+5)
+#define V4L2_CID_AUDIO_BALANCE (V4L2_CID_BASE+6)
+#define V4L2_CID_AUDIO_BASS (V4L2_CID_BASE+7)
+#define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8)
+#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9)
+#define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10)
+#define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11)
+#define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12)
+#define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13)
+#define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14)
+#define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15)
+#define V4L2_CID_GAMMA (V4L2_CID_BASE+16)
+#define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* ? Not sure */
+#define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17)
+#define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18)
+#define V4L2_CID_GAIN (V4L2_CID_BASE+19)
+#define V4L2_CID_HFLIP (V4L2_CID_BASE+20)
+#define V4L2_CID_VFLIP (V4L2_CID_BASE+21)
+#define V4L2_CID_HCENTER (V4L2_CID_BASE+22)
+#define V4L2_CID_VCENTER (V4L2_CID_BASE+23)
+#define V4L2_CID_LASTP1 (V4L2_CID_BASE+24) /* last CID + 1 */
+
+/*
+ * T U N I N G
+ */
+struct v4l2_tuner
+{
+ __u32 index;
+ __u8 name[32];
+ enum v4l2_tuner_type type;
+ __u32 capability;
+ __u32 rangelow;
+ __u32 rangehigh;
+ __u32 rxsubchans;
+ __u32 audmode;
+ __s32 signal;
+ __s32 afc;
+ __u32 reserved[4];
+};
+
+struct v4l2_modulator
+{
+ __u32 index;
+ __u8 name[32];
+ __u32 capability;
+ __u32 rangelow;
+ __u32 rangehigh;
+ __u32 txsubchans;
+ __u32 reserved[4];
+};
+
+/* Flags for the 'capability' field */
+#define V4L2_TUNER_CAP_LOW 0x0001
+#define V4L2_TUNER_CAP_NORM 0x0002
+#define V4L2_TUNER_CAP_STEREO 0x0010
+#define V4L2_TUNER_CAP_LANG2 0x0020
+#define V4L2_TUNER_CAP_SAP 0x0020
+#define V4L2_TUNER_CAP_LANG1 0x0040
+
+/* Flags for the 'rxsubchans' field */
+#define V4L2_TUNER_SUB_MONO 0x0001
+#define V4L2_TUNER_SUB_STEREO 0x0002
+#define V4L2_TUNER_SUB_LANG2 0x0004
+#define V4L2_TUNER_SUB_SAP 0x0004
+#define V4L2_TUNER_SUB_LANG1 0x0008
+
+/* Values for the 'audmode' field */
+#define V4L2_TUNER_MODE_MONO 0x0000
+#define V4L2_TUNER_MODE_STEREO 0x0001
+#define V4L2_TUNER_MODE_LANG2 0x0002
+#define V4L2_TUNER_MODE_SAP 0x0002
+#define V4L2_TUNER_MODE_LANG1 0x0003
+
+struct v4l2_frequency
+{
+ __u32 tuner;
+ enum v4l2_tuner_type type;
+ __u32 frequency;
+ __u32 reserved[8];
+};
+
+/*
+ * A U D I O
+ */
+struct v4l2_audio
+{
+ __u32 index;
+ __u8 name[32];
+ __u32 capability;
+ __u32 mode;
+ __u32 reserved[2];
+};
+/* Flags for the 'capability' field */
+#define V4L2_AUDCAP_STEREO 0x00001
+#define V4L2_AUDCAP_AVL 0x00002
+
+/* Flags for the 'mode' field */
+#define V4L2_AUDMODE_AVL 0x00001
+
+struct v4l2_audioout
+{
+ __u32 index;
+ __u8 name[32];
+ __u32 capability;
+ __u32 mode;
+ __u32 reserved[2];
+};
+
+/*
+ * D A T A S E R V I C E S ( V B I )
+ *
+ * Data services API by Michael Schimek
+ */
+
+struct v4l2_vbi_format
+{
+ __u32 sampling_rate; /* in 1 Hz */
+ __u32 offset;
+ __u32 samples_per_line;
+ __u32 sample_format; /* V4L2_PIX_FMT_* */
+ __s32 start[2];
+ __u32 count[2];
+ __u32 flags; /* V4L2_VBI_* */
+ __u32 reserved[2]; /* must be zero */
+};
+
+/* VBI flags */
+#define V4L2_VBI_UNSYNC (1<< 0)
+#define V4L2_VBI_INTERLACED (1<< 1)
+
+
+/*
+ * A G G R E G A T E S T R U C T U R E S
+ */
+
+/* Stream data format
+ */
+struct v4l2_format
+{
+ enum v4l2_buf_type type;
+ union
+ {
+ struct v4l2_pix_format pix; // V4L2_BUF_TYPE_VIDEO_CAPTURE
+ struct v4l2_window win; // V4L2_BUF_TYPE_VIDEO_OVERLAY
+ struct v4l2_vbi_format vbi; // V4L2_BUF_TYPE_VBI_CAPTURE
+ __u8 raw_data[200]; // user-defined
+ } fmt;
+};
+
+
+/* Stream type-dependent parameters
+ */
+struct v4l2_streamparm
+{
+ enum v4l2_buf_type type;
+ union
+ {
+ struct v4l2_captureparm capture;
+ struct v4l2_outputparm output;
+ __u8 raw_data[200]; /* user-defined */
+ } parm;
+};
+
+
+
+/*
+ * I O C T L C O D E S F O R V I D E O D E V I C E S
+ *
+ */
+#define VIDIOC_QUERYCAP _IOR ('V', 0, struct v4l2_capability)
+#define VIDIOC_RESERVED _IO ('V', 1)
+#define VIDIOC_ENUM_FMT _IOWR ('V', 2, struct v4l2_fmtdesc)
+#define VIDIOC_G_FMT _IOWR ('V', 4, struct v4l2_format)
+#define VIDIOC_S_FMT _IOWR ('V', 5, struct v4l2_format)
+#if 0
+#define VIDIOC_G_COMP _IOR ('V', 6, struct v4l2_compression)
+#define VIDIOC_S_COMP _IOW ('V', 7, struct v4l2_compression)
+#endif
+#define VIDIOC_REQBUFS _IOWR ('V', 8, struct v4l2_requestbuffers)
+#define VIDIOC_QUERYBUF _IOWR ('V', 9, struct v4l2_buffer)
+#define VIDIOC_G_FBUF _IOR ('V', 10, struct v4l2_framebuffer)
+#define VIDIOC_S_FBUF _IOW ('V', 11, struct v4l2_framebuffer)
+#define VIDIOC_OVERLAY _IOW ('V', 14, int)
+#define VIDIOC_QBUF _IOWR ('V', 15, struct v4l2_buffer)
+#define VIDIOC_DQBUF _IOWR ('V', 17, struct v4l2_buffer)
+#define VIDIOC_STREAMON _IOW ('V', 18, int)
+#define VIDIOC_STREAMOFF _IOW ('V', 19, int)
+#define VIDIOC_G_PARM _IOWR ('V', 21, struct v4l2_streamparm)
+#define VIDIOC_S_PARM _IOWR ('V', 22, struct v4l2_streamparm)
+#define VIDIOC_G_STD _IOR ('V', 23, v4l2_std_id)
+#define VIDIOC_S_STD _IOW ('V', 24, v4l2_std_id)
+#define VIDIOC_ENUMSTD _IOWR ('V', 25, struct v4l2_standard)
+#define VIDIOC_ENUMINPUT _IOWR ('V', 26, struct v4l2_input)
+#define VIDIOC_G_CTRL _IOWR ('V', 27, struct v4l2_control)
+#define VIDIOC_S_CTRL _IOWR ('V', 28, struct v4l2_control)
+#define VIDIOC_G_TUNER _IOWR ('V', 29, struct v4l2_tuner)
+#define VIDIOC_S_TUNER _IOW ('V', 30, struct v4l2_tuner)
+#define VIDIOC_G_AUDIO _IOR ('V', 33, struct v4l2_audio)
+#define VIDIOC_S_AUDIO _IOW ('V', 34, struct v4l2_audio)
+#define VIDIOC_QUERYCTRL _IOWR ('V', 36, struct v4l2_queryctrl)
+#define VIDIOC_QUERYMENU _IOWR ('V', 37, struct v4l2_querymenu)
+#define VIDIOC_G_INPUT _IOR ('V', 38, int)
+#define VIDIOC_S_INPUT _IOWR ('V', 39, int)
+#define VIDIOC_G_OUTPUT _IOR ('V', 46, int)
+#define VIDIOC_S_OUTPUT _IOWR ('V', 47, int)
+#define VIDIOC_ENUMOUTPUT _IOWR ('V', 48, struct v4l2_output)
+#define VIDIOC_G_AUDOUT _IOR ('V', 49, struct v4l2_audioout)
+#define VIDIOC_S_AUDOUT _IOW ('V', 50, struct v4l2_audioout)
+#define VIDIOC_G_MODULATOR _IOWR ('V', 54, struct v4l2_modulator)
+#define VIDIOC_S_MODULATOR _IOW ('V', 55, struct v4l2_modulator)
+#define VIDIOC_G_FREQUENCY _IOWR ('V', 56, struct v4l2_frequency)
+#define VIDIOC_S_FREQUENCY _IOW ('V', 57, struct v4l2_frequency)
+#define VIDIOC_CROPCAP _IOWR ('V', 58, struct v4l2_cropcap)
+#define VIDIOC_G_CROP _IOWR ('V', 59, struct v4l2_crop)
+#define VIDIOC_S_CROP _IOW ('V', 60, struct v4l2_crop)
+#define VIDIOC_G_JPEGCOMP _IOR ('V', 61, struct v4l2_jpegcompression)
+#define VIDIOC_S_JPEGCOMP _IOW ('V', 62, struct v4l2_jpegcompression)
+#define VIDIOC_QUERYSTD _IOR ('V', 63, v4l2_std_id)
+#define VIDIOC_TRY_FMT _IOWR ('V', 64, struct v4l2_format)
+#define VIDIOC_ENUMAUDIO _IOWR ('V', 65, struct v4l2_audio)
+#define VIDIOC_ENUMAUDOUT _IOWR ('V', 66, struct v4l2_audioout)
+#define VIDIOC_G_PRIORITY _IOR ('V', 67, enum v4l2_priority)
+#define VIDIOC_S_PRIORITY _IOW ('V', 68, enum v4l2_priority)
+
+/* for compatibility, will go away some day */
+#define VIDIOC_OVERLAY_OLD _IOWR ('V', 14, int)
+#define VIDIOC_S_PARM_OLD _IOW ('V', 22, struct v4l2_streamparm)
+#define VIDIOC_S_CTRL_OLD _IOW ('V', 28, struct v4l2_control)
+#define VIDIOC_G_AUDIO_OLD _IOWR ('V', 33, struct v4l2_audio)
+#define VIDIOC_G_AUDOUT_OLD _IOWR ('V', 49, struct v4l2_audioout)
+#define VIDIOC_CROPCAP_OLD _IOR ('V', 58, struct v4l2_cropcap)
+
+#define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */
+
+#endif /* __LINUX_VIDEODEV2_H */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */