diff options
| author | 2012-12-25 20:31:51 +0000 | |
|---|---|---|
| committer | 2012-12-25 20:31:51 +0000 | |
| commit | f261961598ae818cc72bb09a9aa104d21743b580 (patch) | |
| tree | 60a1473b085bb532778c195c959e15ba26b68d47 /src | |
| parent | added a set of monochrome icons to be used on kde and osx (diff) | |
| download | KVIrc-f261961598ae818cc72bb09a9aa104d21743b580.tar.gz KVIrc-f261961598ae818cc72bb09a9aa104d21743b580.tar.bz2 KVIrc-f261961598ae818cc72bb09a9aa104d21743b580.zip | |
dcc video: removed linux-only, v4l implementation; use qt5's cross-platform implementation instead.
Note: this is still so dirty that is disabled by default
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@6307 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvilib/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/bayer.cpp | 144 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/bayer.h | 56 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/sonix_compress.cpp | 206 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/sonix_compress.h | 34 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/videodevice.cpp | 3127 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/videodevice.h | 440 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/videodevicepool.cpp | 886 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/videodevicepool.h | 153 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/videoinput.cpp | 70 | ||||
| -rw-r--r-- | src/kvilib/ext/avdevice/videoinput.h | 81 | ||||
| -rw-r--r-- | src/modules/dcc/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/modules/dcc/DccVideoWindow.cpp | 164 | ||||
| -rw-r--r-- | src/modules/dcc/DccVideoWindow.h | 14 |
14 files changed, 65 insertions, 5322 deletions
diff --git a/src/kvilib/CMakeLists.txt b/src/kvilib/CMakeLists.txt index 0b75f0458..a7e7f8812 100644 --- a/src/kvilib/CMakeLists.txt +++ b/src/kvilib/CMakeLists.txt @@ -100,16 +100,6 @@ set(kvilib_SRCS tal/KviTalWizard.cpp ) -if(NOT DEFINED COMPILE_DISABLE_AVDEVICE) - list(APPEND kvilib_SRCS - ext/avdevice/videodevice.cpp - ext/avdevice/videoinput.cpp - ext/avdevice/videodevicepool.cpp - ext/avdevice/bayer.cpp - ext/avdevice/sonix_compress.cpp - ) -endif() - if(NOT DEFINED COMPILE_DISABLE_OGG_THEORA) list(APPEND kvilib_SRCS ext/KviOggTheoraDecoder.cpp diff --git a/src/kvilib/ext/avdevice/bayer.cpp b/src/kvilib/ext/avdevice/bayer.cpp deleted file mode 100644 index 48780f01a..000000000 --- a/src/kvilib/ext/avdevice/bayer.cpp +++ /dev/null @@ -1,144 +0,0 @@ -//============================================================================= -// -// File : bayer.cpp -// Creation date : Tue Nov 10 18:08:09 2009 GMT by Fabio Bas -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 file has been taken from the "Kopete, The KDE Instant Messenger" -// sourcecode. Original copyright of the file follows: -//============================================================================= - -/* - * 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) -{ - 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++; - } -} - diff --git a/src/kvilib/ext/avdevice/bayer.h b/src/kvilib/ext/avdevice/bayer.h deleted file mode 100644 index 7eceb23b5..000000000 --- a/src/kvilib/ext/avdevice/bayer.h +++ /dev/null @@ -1,56 +0,0 @@ -//============================================================================= -// -// File : bayer.h -// Creation date : Tue Nov 10 18:08:09 2009 GMT by Fabio Bas -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 file has been taken from the "Kopete, The KDE Instant Messenger" -// sourcecode. Original copyright of the file follows: -//============================================================================= - -/* - * 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); diff --git a/src/kvilib/ext/avdevice/sonix_compress.cpp b/src/kvilib/ext/avdevice/sonix_compress.cpp deleted file mode 100644 index 0eeddcbee..000000000 --- a/src/kvilib/ext/avdevice/sonix_compress.cpp +++ /dev/null @@ -1,206 +0,0 @@ -//============================================================================= -// -// File : sonix_compress.cpp -// Creation date : Tue Nov 10 18:08:09 2009 GMT by Fabio Bas -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 file has been taken from the "Kopete, The KDE Instant Messenger" -// sourcecode. Original file had no copyright header. -//============================================================================= - -#include "sonix_compress.h" - -#define CLAMP(x) ((x)<0?0:((x)>255)?255:(x)) - -typedef struct { - int is_abs; - int len; - int val; - int unk; -} code_table_t; - - -/* local storage */ -static code_table_t table[256]; -static int init_done = 0; - -/* global variable */ -int sonix_unknown = 0; - -/* - sonix_decompress_init - ===================== - pre-calculates a locally stored table for efficient huffman-decoding. - - Each entry at index x in the table represents the codeword - present at the MSB of byte x. - -*/ -void sonix_decompress_init(void) -{ - int i; - int is_abs, val, len, unk; - - for (i = 0; i < 256; i++) { - is_abs = 0; - val = 0; - len = 0; - unk = 0; - if ((i & 0x80) == 0) { - /* code 0 */ - val = 0; - len = 1; - } - else if ((i & 0xE0) == 0x80) { - /* code 100 */ - val = +4; - len = 3; - } - else if ((i & 0xE0) == 0xA0) { - /* code 101 */ - val = -4; - len = 3; - } - else if ((i & 0xF0) == 0xD0) { - /* code 1101 */ - val = +11; - len = 4; - } - else if ((i & 0xF0) == 0xF0) { - /* code 1111 */ - val = -11; - len = 4; - } - else if ((i & 0xF8) == 0xC8) { - /* code 11001 */ - val = +20; - len = 5; - } - else if ((i & 0xFC) == 0xC0) { - /* code 110000 */ - val = -20; - len = 6; - } - else if ((i & 0xFC) == 0xC4) { - /* code 110001xx: unknown */ - val = 0; - len = 8; - unk = 1; - } - else if ((i & 0xF0) == 0xE0) { - /* code 1110xxxx */ - is_abs = 1; - val = (i & 0x0F) << 4; - len = 8; - } - table[i].is_abs = is_abs; - table[i].val = val; - table[i].len = len; - table[i].unk = unk; - } - - sonix_unknown = 0; - init_done = 1; -} - - -/* - sonix_decompress - ================ - decompresses an image encoded by a SN9C101 camera controller chip. - - IN width - height - inp pointer to compressed frame (with header already stripped) - OUT outp pointer to decompressed frame - - Returns 0 if the operation was successful. - Returns <0 if operation failed. - -*/ -int sonix_decompress(int width, int height, unsigned char *inp, unsigned char *outp) -{ - int row, col; - int val; - int bitpos; - unsigned char code; - unsigned char *addr; - - if (!init_done) { - /* do sonix_decompress_init first! */ - return -1; - } - - bitpos = 0; - for (row = 0; row < height; row++) { - - col = 0; - - /* first two pixels in first two rows are stored as raw 8-bit */ - if (row < 2) { - addr = inp + (bitpos >> 3); - code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7))); - bitpos += 8; - *outp++ = code; - - addr = inp + (bitpos >> 3); - code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7))); - bitpos += 8; - *outp++ = code; - - col += 2; - } - - while (col < width) { - /* get bitcode from bitstream */ - addr = inp + (bitpos >> 3); - code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7))); - - /* update bit position */ - bitpos += table[code].len; - - /* update code statistics */ - sonix_unknown += table[code].unk; - - /* calculate pixel value */ - val = table[code].val; - if (!table[code].is_abs) { - /* value is relative to top and left pixel */ - if (col < 2) { - /* left column: relative to top pixel */ - val += outp[-2*width]; - } - else if (row < 2) { - /* top row: relative to left pixel */ - val += outp[-2]; - } - else { - /* main area: average of left pixel and top pixel */ - val += (outp[-2] + outp[-2*width]) / 2; - } - } - - /* store pixel */ - *outp++ = CLAMP(val); - col++; - } - } - - return 0; -} diff --git a/src/kvilib/ext/avdevice/sonix_compress.h b/src/kvilib/ext/avdevice/sonix_compress.h deleted file mode 100644 index d2d5bbef7..000000000 --- a/src/kvilib/ext/avdevice/sonix_compress.h +++ /dev/null @@ -1,34 +0,0 @@ -//============================================================================= -// -// File : sonix_compress.h -// Creation date : Tue Nov 10 18:08:09 2009 GMT by Fabio Bas -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 file has been taken from the "Kopete, The KDE Instant Messenger" -// sourcecode. Original file had no copyright header. -//============================================================================= - -// Call this function first (just once is needed), before calling sonix_decompress -void sonix_decompress_init(void); - -// decompresses data at inp until a full image of widthxheight has been written to outp -int sonix_decompress(int width, int height, unsigned char *inp, unsigned char *outp); - -// counter to detect presence of currently unknown huffman codes -extern int sonix_unknown; diff --git a/src/kvilib/ext/avdevice/videodevice.cpp b/src/kvilib/ext/avdevice/videodevice.cpp deleted file mode 100644 index 7c53f791b..000000000 --- a/src/kvilib/ext/avdevice/videodevice.cpp +++ /dev/null @@ -1,3127 +0,0 @@ -//============================================================================= -// -// File : videodevice.cpp -// Creation date : Tue Nov 10 18:08:09 2009 GMT by Fabio Bas -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 file has been taken from the "Kopete, The KDE Instant Messenger" -// sourcecode. Original copyright of the file follows: -//============================================================================= - -/* - videodevice.cpp - Kopete Video Device Low-level Support - - Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com> - Copyright (c) 2010 by Frank Schaefer <fschaefer.oss@googlemail.com> - - Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> - - ************************************************************************* - * * - * 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 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#include <cstdlib> -#include <cerrno> -#include <cstring> - -#include <QDebug> - -#include "videoinput.h" -#include "videodevice.h" - -#include "bayer.h" -#include "sonix_compress.h" - -#include "KviLocale.h" - -#define CLEAR(x) memset (&(x), 0, sizeof (x)) - -namespace Kopete { - -namespace AV { - -VideoDevice::VideoDevice() -{ - descriptor = -1; - m_streambuffers = 0; - m_current_input = 0; -} - - -VideoDevice::~VideoDevice() -{ - close(); -} - -/*! - \fn void VideoDevice::setupControls() - \brief Sets up the supported video-controls for the current input - - Determines which video-controls are supported for the current input, - reads all needed informations about them and stores the data to the local members - */ -void VideoDevice::setupControls() -{ -#ifndef COMPILE_DISABLE_AVDEVICE - bool driver_vflip = false; - bool driver_hflip = false; -#endif - m_numericCtrls.clear(); - m_booleanCtrls.clear(); - m_menuCtrls.clear(); - m_actionCtrls.clear(); - - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - struct v4l2_queryctrl qctrl; - CLEAR (qctrl); - // Get standard controls: - for (quint32 k = V4L2_CID_BASE; k < V4L2_CID_LASTP1; k++) // NOTE: DO NOT USE qctrl.id DIRECTLY ! - { - qctrl.id = k; - if (0 == xioctl(VIDIOC_QUERYCTRL, &qctrl)) - { - if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) - continue; - if (qctrl.id == V4L2_CID_VFLIP) - driver_vflip = true; - if (qctrl.id == V4L2_CID_HFLIP) - driver_hflip = true; - const char *name_uni = getUnifiedV4L2StdCtrlName(qctrl.id); - if (name_uni && strlen(name_uni)) - strncpy((char*)qctrl.name, name_uni, 32); // NOTE: v4l2_queryctrl.name is _u8[32] - saveV4L2ControlData(qctrl); - } - else - { - if (errno == EINVAL) - continue; - qDebug() << "VIDIOC_QUERYCTRL failed (" << errno << ")."; - } - } - // Get custom controls: - for (quint32 k = V4L2_CID_PRIVATE_BASE; ; k++) - { - qctrl.id = k; - if (0 == xioctl(VIDIOC_QUERYCTRL, &qctrl)) - { - if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) - continue; - saveV4L2ControlData(qctrl); - } - else - { - if (errno == EINVAL) - break; - qDebug() << "VIDIOC_QUERYCTRL failed (" << errno << ")."; - } - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - - case VIDEODEV_DRIVER_V4L: - { - NumericVideoControl numCtrl; - numCtrl.value_min = 0; - numCtrl.value_max = 65535; - numCtrl.value_step = 1; - numCtrl.value_default = 32767; - numCtrl.id = IMGCTRL_ID_V4L1_BRIGHTNESS; - numCtrl.name = __tr("Brightness"); - m_numericCtrls.push_back( numCtrl ); - numCtrl.id = IMGCTRL_ID_V4L1_HUE; - numCtrl.name = __tr("Hue"); - m_numericCtrls.push_back( numCtrl ); - numCtrl.id = IMGCTRL_ID_V4L1_COLOR; - numCtrl.name = __tr("Color"); - m_numericCtrls.push_back( numCtrl ); - numCtrl.id = IMGCTRL_ID_V4L1_CONTRAST; - numCtrl.name = __tr("Contrast"); - m_numericCtrls.push_back( numCtrl ); - numCtrl.id = IMGCTRL_ID_V4L1_WHITENESS; - numCtrl.name = __tr("Whiteness"); - m_numericCtrls.push_back( numCtrl ); - } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - break; - } - -#ifndef COMPILE_DISABLE_AVDEVICE - // Software controls: - BooleanVideoControl boolCtrl; - boolCtrl.value_default = 0; - boolCtrl.id = IMGCTRL_ID_SOFT_AUTOBRIGHTNESSCONTRASTCORR; - boolCtrl.name = __tr("Automatic Brightness/Contrast Correction"); - m_booleanCtrls.push_back( boolCtrl ); - boolCtrl.id = IMGCTRL_ID_SOFT_AUTOCOLORCORR; - boolCtrl.name = __tr("Automatic Color Correction"); - m_booleanCtrls.push_back( boolCtrl ); - if (!driver_vflip) - { - boolCtrl.id = IMGCTRL_ID_SOFT_VFLIP; - boolCtrl.name = __tr("Vertical Flip"); - m_booleanCtrls.push_back( boolCtrl ); - } - if (!driver_hflip) - { - boolCtrl.id = IMGCTRL_ID_SOFT_HFLIP; - boolCtrl.name = __tr("Horizontal Flip"); - m_booleanCtrls.push_back( boolCtrl ); - } -#endif -} - -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE -/*! - \fn bool VideoDevice::getMenuCtrlOptions(quint32 id, quint32 maxindex, QStringList * options) - \param id ID of the video-control - \param maxindex Highest menu index - \param options Pointer to the QStringList which will recieve the option-strings of the video-control - \return The success of the operation - \brief Reads the available options provided by a menu-video-control - */ -bool VideoDevice::getMenuCtrlOptions(quint32 id, quint32 maxindex, QStringList * options) -{ - QStringList opt; - struct v4l2_querymenu ctrlmenu; - CLEAR (ctrlmenu); - options->clear(); - ctrlmenu.id = id; - for (quint32 k = 0; k <= maxindex; k++) // DO NOT USE ctrlmenu.index DIRECTLY ! - { - ctrlmenu.index = k; - if (0 == xioctl(VIDIOC_QUERYMENU, &ctrlmenu)) - { - opt.push_back( __tr( (char*)(ctrlmenu.name) ) ); - qDebug() << "option" << k << ":" << (char*)(ctrlmenu.name); - } - else - { - qDebug() << "VIDIOC_QUERYMENU failed (" << errno << ")."; - return false; - } - } - *options = opt; - return true; - /* NOTE: According to V4L2-spec v0.24: - v4l2_querymenu.minimum = start-index = 0, v4l2_querymenu.maximum = last index - => DO DRIVERS REALLY SET THESE VALUES CORRECTLY ??? - */ -} - - -/*! - \fn void VideoDevice::saveV4L2ControlData(struct v4l2_queryctrl qctrl) - \param qctrl The struct v4l2_queryctrl of the V4L2-control that should be saved - \brief Saves the data of a V4L2-video-control - */ -void VideoDevice::saveV4L2ControlData(struct v4l2_queryctrl qctrl) -{ - NumericVideoControl numericCtrl; - BooleanVideoControl booleanCtrl; - MenuVideoControl menuCtrl; - ActionVideoControl actionCtrl; - QStringList options; - switch (qctrl.type) - { - case V4L2_CTRL_TYPE_INTEGER: - numericCtrl.id = qctrl.id; - numericCtrl.name = __tr((char*)qctrl.name); - numericCtrl.value_min = qctrl.minimum; - numericCtrl.value_max = qctrl.maximum; - numericCtrl.value_default = qctrl.default_value; - numericCtrl.value_step = qctrl.step; - m_numericCtrls.push_back( numericCtrl ); - break; - case V4L2_CTRL_TYPE_BOOLEAN: - booleanCtrl.id = qctrl.id; - booleanCtrl.name = __tr((char*)qctrl.name); - booleanCtrl.value_default = qctrl.default_value; - m_booleanCtrls.push_back( booleanCtrl ); - break; - case V4L2_CTRL_TYPE_MENU: - if (getMenuCtrlOptions( qctrl.id, qctrl.maximum, &options )) - { - menuCtrl.id = qctrl.id; - menuCtrl.name = __tr((char*)qctrl.name); - menuCtrl.index_default = qctrl.default_value; - menuCtrl.options = options; - m_menuCtrls.push_back( menuCtrl ); - } - break; - case V4L2_CTRL_TYPE_BUTTON: - actionCtrl.id = qctrl.id; - actionCtrl.name = __tr((char*)qctrl.name); - m_actionCtrls.push_back( actionCtrl ); - break; - // Since kernel 2.6.18: -#ifdef V4L2_CTRL_TYPE_INTEGER64 - case V4L2_CTRL_TYPE_INTEGER64: -#endif -#ifdef V4L2_CTRL_TYPE_CTRL_CLASS - case V4L2_CTRL_TYPE_CTRL_CLASS: -#endif - default: - break; - } -// TODO V4L2_CTRL_TYPE_INTEGER64, V4L2_CTRL_TYPE_CTRL_CLASS -} -#endif -#endif - -/*! - \fn VideoDevice::xioctl(int fd, int request, void *arg) - */ -int VideoDevice::xioctl(int request, void *arg) -{ - int r; - -#ifdef HAVE_LIBV4L2 - do r = v4l2_ioctl (descriptor, request, arg); -#else - do r = ioctl (descriptor, request, arg); -#endif - while (-1 == r && EINTR == errno); - return r; -} - -/*! - \fn VideoDevice::errnoReturn(const char* s) - */ -int VideoDevice::errnoReturn(const char* s) -{ - /// @todo implement me - fprintf (stderr, "%s error %d, %s\n",s, errno, strerror (errno)); - return EXIT_FAILURE; -} - -/*! - \fn VideoDevice::setFileName(QString name) - */ -int VideoDevice::setFileName(QString filename) -{ - /// @todo implement me - full_filename=filename; - return EXIT_SUCCESS; -} - -/*! - \fn QString VideoDevice::fileName() - */ -QString VideoDevice::fileName() -{ - return full_filename; -} - -/*! - \fn VideoDevice::open() - */ -int VideoDevice::open() -{ - /// @todo implement me - - qDebug() << "called"; - if(-1 != descriptor) - { - qDebug() << "Device is already open"; - return EXIT_SUCCESS; - } -#ifdef HAVE_LIBV4L2 - descriptor = ::v4l2_open (QFile::encodeName(full_filename), O_RDWR | O_NONBLOCK, 0); -#else - descriptor = ::open (QFile::encodeName(full_filename), O_RDWR | O_NONBLOCK, 0); -#endif - if(isOpen()) - { - qDebug() << "File " << full_filename << " was opened successfuly"; - if(EXIT_FAILURE==checkDevice()) - { - qDebug() << "File " << full_filename << " could not be opened"; - close(); - return EXIT_FAILURE; - } - } - else - { - qDebug() << "Unable to open file " << full_filename << "Err: "<< errno; - return EXIT_FAILURE; - } - - initDevice(); - selectInput(m_current_input); - qDebug() << "exited successfuly"; - return EXIT_SUCCESS; -} - -bool VideoDevice::isOpen() -{ - if(-1 == descriptor) - { -// qDebug() << "VideoDevice::isOpen() File is not open"; - return false; - } -// qDebug() << "VideoDevice::isOpen() File is open"; - return true; -} - -int VideoDevice::checkDevice() -{ - qDebug() << "checkDevice() called."; - if(isOpen()) - { - m_videocapture=false; - m_videochromakey=false; - m_videoscale=false; - m_videooverlay=false; - m_videoread=false; - m_videoasyncio=false; - m_videostream=false; - - m_driver=VIDEODEV_DRIVER_NONE; -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - - CLEAR(V4L2_capabilities); - - if (-1 != xioctl (VIDIOC_QUERYCAP, &V4L2_capabilities)) - { - if (!(V4L2_capabilities.capabilities & V4L2_CAP_VIDEO_CAPTURE)) - { - qDebug() << "checkDevice(): " << full_filename << " is not a video capture device."; - m_driver = VIDEODEV_DRIVER_NONE; - return EXIT_FAILURE; - } - m_videocapture=true; - qDebug() << "checkDevice(): " << full_filename << " is a V4L2 device."; - m_driver = VIDEODEV_DRIVER_V4L2; - m_model=QString::fromLocal8Bit((const char*)V4L2_capabilities.card); - - -// Detect maximum and minimum resolution supported by the V4L2 device. VIDIOC_ENUM_FRAMESIZES is still experimental. - CLEAR (fmt); - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (-1 == xioctl (VIDIOC_G_FMT, &fmt)) - { - qDebug() << "VIDIOC_G_FMT failed (" << errno << ")."; - } - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = 32767; - fmt.fmt.pix.height = 32767; - fmt.fmt.pix.field = V4L2_FIELD_ANY; - if (-1 == xioctl (VIDIOC_S_FMT, &fmt)) - { - qDebug() << "Detecting maximum size with VIDIOC_S_FMT failed (" << errno << ").Returned maxwidth: " << pixelFormatName(fmt.fmt.pix.pixelformat) << " " << fmt.fmt.pix.width << "x" << fmt.fmt.pix.height; - // Note VIDIOC_S_FMT may change width and height. - } - else - { - maxwidth = fmt.fmt.pix.width; - maxheight = fmt.fmt.pix.height; - } - if (-1 == xioctl (VIDIOC_G_FMT, &fmt)) - { - qDebug() << "VIDIOC_G_FMT failed (" << errno << ")."; - } - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = 1; - fmt.fmt.pix.height = 1; - fmt.fmt.pix.field = V4L2_FIELD_ANY; - if (-1 == xioctl (VIDIOC_S_FMT, &fmt)) - { - qDebug() << "Detecting minimum size with VIDIOC_S_FMT failed (" << errno << ").Returned maxwidth: " << fmt.fmt.pix.width << "x" << fmt.fmt.pix.height; - // Note VIDIOC_S_FMT may change width and height. - } - else - { - minwidth = fmt.fmt.pix.width; - minheight = fmt.fmt.pix.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; - m_buffer_size=fmt.fmt.pix.sizeimage ;*/ - - int inputisok=EXIT_SUCCESS; - m_input.clear(); - for(unsigned int loop=0; inputisok==EXIT_SUCCESS; loop++) - { - struct v4l2_input videoinput; - CLEAR(videoinput); - videoinput.index = loop; - inputisok=xioctl(VIDIOC_ENUMINPUT, &videoinput); - if(inputisok==EXIT_SUCCESS) - { - VideoInput tempinput; - tempinput.name = QString::fromLocal8Bit((const char*)videoinput.name); - tempinput.hastuner = videoinput.type & V4L2_INPUT_TYPE_TUNER; -detectSignalStandards(); - tempinput.m_standards = videoinput.std; - m_input.push_back(tempinput); - qDebug() << "Input " << loop << ": " << tempinput.name << " (tuner: " << ((videoinput.type & V4L2_INPUT_TYPE_TUNER) != 0) << ")"; - if((videoinput.type & V4L2_INPUT_TYPE_TUNER) != 0) - { -// _tunerForInput[name] = desc.tuner; -// _isTuner = true; - } - else - { -// _tunerForInput[name] = -1; - } - } - } - } - else - { -// V4L-only drivers should return an EINVAL in errno to indicate they cannot handle V4L2 calls. Not every driver is compliant, so -// it will try the V4L api even if the error code is different than expected. - qDebug() << "checkDevice(): " << full_filename << " is not a V4L2 device."; - } - -#endif - -#ifdef COMPILE_V4L1_CODE - CLEAR(V4L_capabilities); - - if(m_driver==VIDEODEV_DRIVER_NONE) - { - qDebug() << "checkDevice(): " << full_filename << " Trying V4L API."; - if (-1 == xioctl (VIDIOCGCAP, &V4L_capabilities)) - { - perror ("ioctl (VIDIOCGCAP)"); - m_driver = VIDEODEV_DRIVER_NONE; - return EXIT_FAILURE; - } - else - { - qDebug() << full_filename << " is a V4L device."; - m_driver = VIDEODEV_DRIVER_V4L; - m_model=QString::fromLocal8Bit((const char*)V4L_capabilities.name); - if(V4L_capabilities.type & VID_TYPE_CAPTURE) - m_videocapture=true; - if(V4L_capabilities.type & VID_TYPE_CHROMAKEY) - m_videochromakey=true; - if(V4L_capabilities.type & VID_TYPE_SCALES) - m_videoscale=true; - if(V4L_capabilities.type & VID_TYPE_OVERLAY) - m_videooverlay=true; -// qDebug() << "libkopete (avdevice): Inputs : " << V4L_capabilities.channels; -// qDebug() << "libkopete (avdevice): Audios : " << V4L_capabilities.audios; - minwidth = V4L_capabilities.minwidth; - maxwidth = V4L_capabilities.maxwidth; - minheight = V4L_capabilities.minheight; - maxheight = V4L_capabilities.maxheight; - - - int inputisok=EXIT_SUCCESS; - m_input.clear(); - for(int loop=0; loop < V4L_capabilities.channels; loop++) - { - struct video_channel videoinput; - CLEAR(videoinput); - videoinput.channel = loop; - videoinput.norm = 1; - inputisok=xioctl(VIDIOCGCHAN, &videoinput); - if(inputisok==EXIT_SUCCESS) - { - VideoInput tempinput; - tempinput.name = QString::fromLocal8Bit((const char*)videoinput.name); - tempinput.hastuner=videoinput.flags & VIDEO_VC_TUNER; -// TODO: The routine to detect the appropriate video standards for V4L must be placed here - m_input.push_back(tempinput); -// qDebug() << "libkopete (avdevice): Input " << loop << ": " << tempinput.name << " (tuner: " << ((videoinput.flags & VIDEO_VC_TUNER) != 0) << ")"; -/* if((input.type & V4L2_INPUT_TYPE_TUNER) != 0) - { -// _tunerForInput[name] = desc.tuner; -// _isTuner = true; - } - else - { -// _tunerForInput[name] = -1; - } -*/ } - } - - } - } -#endif //COMPILE_V4L1_CODE -#endif - m_name=m_model; // Take care about changing the name to be different from the model itself... - - detectPixelFormats(); -// TODO: Now we must execute the proper initialization according to the type of the driver. - qDebug() << "checkDevice() exited successfuly."; - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - - -/*! - \fn VideoDevice::showDeviceCapabilities() - */ -int VideoDevice::showDeviceCapabilities() -{ - qDebug() << "showDeviceCapabilities() called."; - if(isOpen()) - { -/* qDebug() << "libkopete (avdevice): Driver: " << (const char*)V4L2_capabilities.driver << " " - << ((V4L2_capabilities.version>>16) & 0xFF) << "." - << ((V4L2_capabilities.version>> 8) & 0xFF) << "." - << ((V4L2_capabilities.version ) & 0xFF) << endl; - qDebug() << "libkopete (avdevice): Device: " << name; - qDebug() << "libkopete (avdevice): Capabilities:"; - if(V4L2_capabilities.capabilities & V4L2_CAP_VIDEO_CAPTURE) - qDebug() << "libkopete (avdevice): Video capture"; - if(V4L2_capabilities.capabilities & V4L2_CAP_VIDEO_OUTPUT) - qDebug() << "libkopete (avdevice): Video output"; - if(V4L2_capabilities.capabilities & V4L2_CAP_VIDEO_OVERLAY) - qDebug() << "libkopete (avdevice): Video overlay"; - if(V4L2_capabilities.capabilities & V4L2_CAP_VBI_CAPTURE) - qDebug() << "libkopete (avdevice): VBI capture"; - if(V4L2_capabilities.capabilities & V4L2_CAP_VBI_OUTPUT) - qDebug() << "libkopete (avdevice): VBI output"; - if(V4L2_capabilities.capabilities & V4L2_CAP_RDS_CAPTURE) - qDebug() << "libkopete (avdevice): RDS capture"; - if(V4L2_capabilities.capabilities & V4L2_CAP_TUNER) - qDebug() << "libkopete (avdevice): Tuner IO"; - if(V4L2_capabilities.capabilities & V4L2_CAP_AUDIO) - qDebug() << "libkopete (avdevice): Audio IO"; -;*/ - qDebug() << "Device model: " << m_model; - qDebug() << "Device name : " << m_name; - qDebug() << "Capabilities:"; - if(canCapture()) - { - qDebug() << " Video capture"; - } - if(canRead()) - { - qDebug() << " Read"; - } - if(canAsyncIO()) - { - qDebug() << " Asynchronous input/output"; - } - if(canStream()) - { - qDebug() << " Streaming"; - } - if(canChromakey()) - { - qDebug() << " Video chromakey"; - } - if(canScale()) - { - qDebug() << " Video scales"; - } - if(canOverlay()) - { - qDebug() << " Video overlay"; - } -// qDebug() << "libkopete (avdevice): Audios : " << V4L_capabilities.audios; - qDebug() << " Max res: " << maxWidth() << " x " << maxHeight(); - qDebug() << " Min res: " << minWidth() << " x " << minHeight(); - qDebug() << " Inputs : " << inputs(); - for (int loop=0; loop < inputs(); loop++) - qDebug() << "Input " << loop << ": " << m_input[loop].name << " (tuner: " << m_input[loop].hastuner << ")"; - qDebug() << "showDeviceCapabilities() exited successfuly."; - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - -/*! - \fn VideoDevicePool::initDevice() - */ -int VideoDevice::initDevice() -{ - /// @todo implement me - qDebug() << "initDevice() started"; - if(-1 == descriptor) - { - qDebug() << "initDevice() Device is not open"; - return EXIT_FAILURE; - } - m_io_method = IO_METHOD_NONE; - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - if(V4L2_capabilities.capabilities & V4L2_CAP_READWRITE) - { - m_videoread=true; - m_io_method = IO_METHOD_READ; - qDebug() << " Read/Write interface"; - } - if(V4L2_capabilities.capabilities & V4L2_CAP_ASYNCIO) - { - m_videoasyncio=true; - qDebug() << " Async IO interface"; - } - if(V4L2_capabilities.capabilities & V4L2_CAP_STREAMING) - { - m_videostream=true; - m_io_method = IO_METHOD_MMAP; -// m_io_method = IO_METHOD_USERPTR; - qDebug() << " Streaming interface"; - } - if(m_io_method==IO_METHOD_NONE) - { - qDebug() << "initDevice() Found no suitable input/output method for " << full_filename; - return EXIT_FAILURE; - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - m_videoread=true; - m_io_method=IO_METHOD_READ; - if(-1 != xioctl(VIDIOCGFBUF,&V4L_videobuffer)) - { -// m_videostream=true; -// m_io_method = IO_METHOD_MMAP; - qDebug() << " Streaming interface"; - } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - - break; - } - -// Select video input, video standard and tune here. -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - struct v4l2_cropcap cropcap; - struct v4l2_crop crop; - CLEAR (cropcap); - CLEAR (crop); - - cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (-1 == xioctl (VIDIOC_CROPCAP, &cropcap)) - { // Errors ignored. - } - crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - crop.c = cropcap.defrect; // reset to default - if (-1 == xioctl (VIDIOC_S_CROP, &crop)) - { - switch (errno) - { - case EINVAL: break; // Cropping not supported. - default: break; // Errors ignored. - } - } -#endif -#endif - - showDeviceCapabilities(); - qDebug() << "initDevice() exited successfuly"; - return EXIT_SUCCESS; -} - -int VideoDevice::inputs() -{ - return m_input.size(); -} - - -int VideoDevice::width() -{ - return currentwidth; -} - -int VideoDevice::minWidth() -{ - return minwidth; -} - -int VideoDevice::maxWidth() -{ - return maxwidth; -} - -int VideoDevice::height() -{ - return currentheight; -} - -int VideoDevice::minHeight() -{ - return minheight; -} - -int VideoDevice::maxHeight() -{ - return maxheight; -} - -int VideoDevice::setSize( int newwidth, int newheight) -{ -qDebug() << "setSize(" << newwidth << ", " << newheight << ") called."; - if(isOpen()) - { -// It should not be there. It must remain in a completely distict place, cause this method should not change the pixelformat. -// It shouldn't try to find a suitable pixel format this way. It should use values discovered by - detectPixelFormats() - to choose a valid one. - qDebug() << "Trying YUY422P"; - errno = 0; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_YUV422P) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support YUV422P format. Trying YUYV."; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_YUYV) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support YUYV format. Trying UYVY."; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_UYVY) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support UYVY format. Trying YUV420P."; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_YUV420P) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support YUV420P format. Trying RGB24."; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_RGB24) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support RGB24 format. Trying BGR24."; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_BGR24) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support RGB24 format. Trying RGB32."; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_RGB32) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support RGB32 format. Trying BGR32."; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_BGR32) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support BGR32 format. Trying SBGGR8."; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_SBGGR8) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support SBGGR8 format. Trying SN9C10X."; - if(PIXELFORMAT_NONE == setPixelFormat(PIXELFORMAT_SN9C10X) && errno != EBUSY) - { - qDebug() << "Device doesn't seem to support BGR32 format. Fallback to it is not yet implemented."; - } - } - } - } - } - } - } - } - } - } - if (errno == EBUSY) { - qDebug() << "Can't change the video size: device in use"; - return EXIT_FAILURE; - } - - if(newwidth > maxwidth ) newwidth = maxwidth; - if(newheight > maxheight) newheight = maxheight; - if(newwidth < minwidth ) newwidth = minwidth; - if(newheight < minheight) newheight = minheight; - - currentwidth = newwidth; - currentheight = newheight; - -//qDebug() << "width: " << pixelFormatName(fmt.fmt.pix.pixelformat) << " " << width() << "x" << height(); -// Change resolution for the video device - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: -// CLEAR (fmt); - if (-1 == xioctl (VIDIOC_G_FMT, &fmt)) - { - qDebug() << "VIDIOC_G_FMT failed (" << errno << ").Returned width: " << pixelFormatName(fmt.fmt.pix.pixelformat) << " " << fmt.fmt.pix.width << "x" << fmt.fmt.pix.height; - } - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = width(); - fmt.fmt.pix.height = height(); - fmt.fmt.pix.field = V4L2_FIELD_ANY; - if (-1 == xioctl (VIDIOC_S_FMT, &fmt)) - { - qDebug() << "VIDIOC_S_FMT failed (" << errno << ").Returned width: " << pixelFormatName(fmt.fmt.pix.pixelformat) << " " << fmt.fmt.pix.width << "x" << fmt.fmt.pix.height; - // Note VIDIOC_S_FMT may change width and height. - } - else - { -// Buggy driver paranoia. -qDebug() << "VIDIOC_S_FMT worked (" << errno << ").Returned width: " << pixelFormatName(fmt.fmt.pix.pixelformat) << " " << fmt.fmt.pix.width << "x" << fmt.fmt.pix.height; - unsigned int 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; - } - m_buffer_size=fmt.fmt.pix.sizeimage ; - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - { - struct video_window V4L_videowindow; - - if (xioctl (VIDIOCGWIN, &V4L_videowindow)== -1) - { - perror ("ioctl VIDIOCGWIN"); -// return (NULL); - } - V4L_videowindow.width = width(); - V4L_videowindow.height = height(); - V4L_videowindow.clipcount=0; - if (xioctl (VIDIOCSWIN, &V4L_videowindow)== -1) - { - perror ("ioctl VIDIOCSWIN"); -// return (NULL); - } -qDebug() << "------------- width: " << V4L_videowindow.width << " Height: " << V4L_videowindow.height << " Clipcount: " << V4L_videowindow.clipcount << " -----------------"; - -// qDebug() << "libkopete (avdevice): V4L_picture.palette: " << V4L_picture.palette << " Depth: " << V4L_picture.depth; - -/* if(-1 == xioctl(VIDIOCGFBUF,&V4L_videobuffer)) - qDebug() << "libkopete (avdevice): VIDIOCGFBUF failed (" << errno << "): Device cannot stream";*/ - - } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - break; - } - m_buffer_size = width() * height() * pixelFormatDepth(m_pixelformat) / 8; -qDebug() << "------------------------- ------- -- m_buffer_size: " << m_buffer_size << " !!! -- ------- -----------------------------------------"; - - m_currentbuffer.pixelformat=m_pixelformat; - m_currentbuffer.data.resize(m_buffer_size); - - switch (m_io_method) - { - case IO_METHOD_NONE: break; - case IO_METHOD_READ: initRead (); break; - case IO_METHOD_MMAP: initMmap (); break; - case IO_METHOD_USERPTR: initUserptr (); break; - } - -qDebug() << "setSize(" << newwidth << ", " << newheight << ") exited successfuly."; - return EXIT_SUCCESS; - } -qDebug() << "setSize(" << newwidth << ", " << newheight << ") Device is not open."; - return EXIT_FAILURE; -} - - - - - - - - - - - - - -pixel_format VideoDevice::setPixelFormat(pixel_format newformat) -{ - pixel_format ret = PIXELFORMAT_NONE; -//qDebug() << "called."; -// Change the pixel format for the video device - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: -// CLEAR (fmt); - if (-1 == xioctl (VIDIOC_G_FMT, &fmt)) - { -// return errnoReturn ("VIDIOC_S_FMT"); -// qDebug() << "VIDIOC_G_FMT failed (" << errno << ").Returned width: " << pixelFormatName(fmt.fmt.pix.pixelformat) << " " << fmt.fmt.pix.width << "x" << fmt.fmt.pix.height; - } - else - m_pixelformat = pixelFormatForPalette(fmt.fmt.pix.pixelformat); - - fmt.fmt.pix.pixelformat = pixelFormatCode(newformat); - if (-1 == xioctl (VIDIOC_S_FMT, &fmt)) - { -// qDebug() << "VIDIOC_S_FMT failed (" << errno << ").Returned width: " << pixelFormatName(fmt.fmt.pix.pixelformat) << " " << fmt.fmt.pix.width << "x" << fmt.fmt.pix.height; - } - else - { - if (fmt.fmt.pix.pixelformat == (unsigned int) pixelFormatCode(newformat)) // Thih "if" (not what is contained within) is a fix for a bug in sn9c102 driver. - { - m_pixelformat = newformat; - ret = m_pixelformat; - } - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - { - struct video_picture V4L_picture; - if(-1 == xioctl(VIDIOCGPICT, &V4L_picture)) - { - qDebug() << "VIDIOCGPICT failed (" << errno << ")."; - } -// qDebug() << "V4L_picture.palette: " << V4L_picture.palette << " Depth: " << V4L_picture.depth; - V4L_picture.palette = pixelFormatCode(newformat); - V4L_picture.depth = pixelFormatDepth(newformat); - if(-1 == xioctl(VIDIOCSPICT,&V4L_picture)) - { -// qDebug() << "Device seems to not support " << pixelFormatName(newformat) << " format. Fallback to it is not yet implemented."; - } - - if(-1 == xioctl(VIDIOCGPICT, &V4L_picture)) - { - qDebug() << "VIDIOCGPICT failed (" << errno << ")."; - } - -// qDebug() << "V4L_picture.palette: " << V4L_picture.palette << " Depth: " << V4L_picture.depth; - m_pixelformat=pixelFormatForPalette(V4L_picture.palette); - if (m_pixelformat == newformat) - ret = newformat; - - } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - break; - } - return ret; -} - - - - - - -/*! - \fn Kopete::AV::VideoDevice::currentInput() - */ -int VideoDevice::currentInput() -{ - /// @todo implement me - if(isOpen()) - { - return m_current_input; - } - return 0; -} - -/*! - \fn Kopete::AV::VideoDevice::selectInput(int input) - */ -int VideoDevice::selectInput(int newinput) -{ - /// @todo implement me - if(m_current_input >= inputs()) - return EXIT_FAILURE; - - if(isOpen()) - { - switch (m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - if (-1 == ioctl (descriptor, VIDIOC_S_INPUT, &newinput)) - { - perror ("VIDIOC_S_INPUT"); - return EXIT_FAILURE; - } - setupControls(); - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - struct video_channel V4L_input; - V4L_input.channel=newinput; - V4L_input.norm=4; // Hey, it's plain wrong! It should be input's signal standard! - if (-1 == ioctl (descriptor, VIDIOCSCHAN, &V4L_input)) - { - perror ("ioctl (VIDIOCSCHAN)"); - return EXIT_FAILURE; - } - setupControls(); - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - break; - } - qDebug() << "Selected input " << newinput << " (" << m_input[newinput].name << ")"; - m_current_input = newinput; - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - -/*! - \fn VideoDevice::startCapturing() - */ -int VideoDevice::startCapturing() -{ - - qDebug() << "called."; - if(isOpen()) - { - switch (m_io_method) - { - case IO_METHOD_NONE: // Device cannot capture frames - return EXIT_FAILURE; - break; - case IO_METHOD_READ: // Nothing to do - break; - case IO_METHOD_MMAP: -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - { - unsigned int loop; - for (loop = 0; loop < m_streambuffers; ++loop) - { - struct v4l2_buffer buf; - CLEAR (buf); - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - buf.index = loop; - if (-1 == xioctl (VIDIOC_QBUF, &buf)) - return errnoReturn ("VIDIOC_QBUF"); - } - enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (-1 == xioctl (VIDIOC_STREAMON, &type)) - return errnoReturn ("VIDIOC_STREAMON"); - } -#endif -#endif - break; - case IO_METHOD_USERPTR: -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - { - unsigned int loop; - for (loop = 0; loop < m_streambuffers; ++loop) - { - struct v4l2_buffer buf; - CLEAR (buf); - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_USERPTR; - buf.m.userptr = (unsigned long) m_rawbuffers[loop].start; - buf.length = m_rawbuffers[loop].length; - if (-1 == xioctl (VIDIOC_QBUF, &buf)) - return errnoReturn ("VIDIOC_QBUF"); - } - enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (-1 == xioctl (VIDIOC_STREAMON, &type)) - return errnoReturn ("VIDIOC_STREAMON"); - } -#endif -#endif - break; - } - - qDebug() << "exited successfuly."; - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - -/*! - \fn VideoDevice::getFrame() - */ -int VideoDevice::getFrame() -{ - /// @todo implement me - ssize_t bytesread; - -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - struct v4l2_buffer v4l2buffer; -#endif -#endif -// qDebug() << "getFrame() called."; - if(isOpen()) - { - switch (m_io_method) - { - case IO_METHOD_NONE: // Device cannot capture frames - return EXIT_FAILURE; - break; - case IO_METHOD_READ: -// qDebug() << "Using IO_METHOD_READ.File descriptor: " << descriptor << " Buffer address: " << &m_currentbuffer.data[0] << " Size: " << m_currentbuffer.data.size(); - if (m_currentbuffer.data.isEmpty()) - return EXIT_FAILURE; - -#ifdef HAVE_LIBV4L2 - bytesread = v4l2_read (descriptor, &m_currentbuffer.data[0], m_currentbuffer.data.size()); -#else - bytesread = read (descriptor, &m_currentbuffer.data[0], m_currentbuffer.data.size()); -#endif - if (-1 == bytesread) // must verify this point with ov511 driver. - { - if (errno == EAGAIN) - { -// qDebug() << "No new frame available."; - return EXIT_FAILURE; - } - else - return errnoReturn ("read"); - } - if((int)m_currentbuffer.data.size() < bytesread) - { - qDebug() << "IO_METHOD_READ returned less bytes (" << bytesread << ") than it was asked for (" << m_currentbuffer.data.size() <<")."; - } - break; - case IO_METHOD_MMAP: -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - CLEAR (v4l2buffer); - v4l2buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - v4l2buffer.memory = V4L2_MEMORY_MMAP; - if (-1 == xioctl (VIDIOC_DQBUF, &v4l2buffer)) - { - if (errno == EAGAIN) - { -// qDebug() << "No new frame available."; - return EXIT_FAILURE; - } - else - return errnoReturn ("VIDIOC_DQBUF"); - } -/* if (v4l2buffer.index < m_streambuffers) - return EXIT_FAILURE;*/ //it was an assert() -// qDebug() << "m_rawbuffers[" << v4l2buffer.index << "].start: " << (void *)m_rawbuffers[v4l2buffer.index].start << " Size: " << m_currentbuffer.data.size(); - if (m_currentbuffer.data.isEmpty() || -// v4l2buffer.index < 0 || // is always false: v4l2buffer.index is unsigned - (uint) m_rawbuffers.size() <= v4l2buffer.index) - return EXIT_FAILURE; - - if (m_rawbuffers[v4l2buffer.index].length < (uint)m_currentbuffer.data.size()) - { - qDebug() << "Buffer size mismatch: expecting raw buffer length to be" << m_currentbuffer.data.size() << "but it was" << m_rawbuffers[v4l2buffer.index].length; - return EXIT_FAILURE; - } - - memcpy(&m_currentbuffer.data[0], m_rawbuffers[v4l2buffer.index].start, m_currentbuffer.data.size()); - if (-1 == xioctl (VIDIOC_QBUF, &v4l2buffer)) - return errnoReturn ("VIDIOC_QBUF"); -#endif -#endif - break; - case IO_METHOD_USERPTR: -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - { - unsigned int i; - CLEAR (v4l2buffer); - v4l2buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - v4l2buffer.memory = V4L2_MEMORY_USERPTR; - if (-1 == xioctl (VIDIOC_DQBUF, &v4l2buffer)) - { - if (errno == EAGAIN) - { -// qDebug() << "No new frame available."; - return EXIT_FAILURE; - } - else - return errnoReturn ("VIDIOC_DQBUF"); - } - if ((unsigned int) m_rawbuffers.size() < m_streambuffers) - return EXIT_FAILURE; - - for (i = 0; i < m_streambuffers; ++i) - if (v4l2buffer.m.userptr == (unsigned long) m_rawbuffers[i].start && v4l2buffer.length == m_rawbuffers[i].length) - break; - if (i < m_streambuffers) - return EXIT_FAILURE; - if (-1 == xioctl (VIDIOC_QBUF, &v4l2buffer)) - return errnoReturn ("VIDIOC_QBUF"); - } -#endif -#endif - break; - } -// qDebug() << "exited successfuly."; - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - -/*! - \fn VideoDevice::getFrame(imagebuffer *imgbuffer) - */ -int VideoDevice::getFrame(imagebuffer *imgbuffer) -{ - if(imgbuffer) - { - getFrame(); - imgbuffer->height = m_currentbuffer.height; - imgbuffer->width = m_currentbuffer.width; - imgbuffer->pixelformat = m_currentbuffer.pixelformat; - imgbuffer->data = m_currentbuffer.data; - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - -/*! - \fn Kopete::AV::VideoDevice::getImage(const QImage *qimage) - */ -int VideoDevice::getImage(QImage *qimage) -{ - /// @todo implement me - - // do NOT delete qimage here, as it is received as a parameter - if (qimage->width() != width() || qimage->height() != height()) - *qimage = QImage(width(), height(), QImage::Format_RGB32); - - if (!m_currentbuffer.data.size()) - { - //there is no data so if we continue something will try access it (as in bug 161536) and crash kopete - //perhaps we should look at having the interface reflect when the camera isn't available? as it thinks - //it is for some reason, though the data size seems to be an ok check - return EXIT_FAILURE; - } - - uchar *bits=qimage->bits(); -//qDebug() << "Capturing in " << pixelFormatName(m_currentbuffer.pixelformat); - switch(m_currentbuffer.pixelformat) - { - case PIXELFORMAT_NONE : break; - -// Packed RGB formats - case PIXELFORMAT_RGB332 : - { - int step=0; - for(int loop=0;loop < qimage->numBytes();loop+=4) - { - bits[loop] = (m_currentbuffer.data[step]>>5<<5)+(m_currentbuffer.data[step]>>5<<2)+(m_currentbuffer.data[step]>>6); - bits[loop+1] = (m_currentbuffer.data[step]>>2<<5)+(m_currentbuffer.data[step]<<3>>5<<2)+(m_currentbuffer.data[step]<<3>>6); - bits[loop+2] = (m_currentbuffer.data[step]<<6)+(m_currentbuffer.data[step]<<6>>2)+(m_currentbuffer.data[step]<<6>>4)+(m_currentbuffer.data[step]<<6>>6); - bits[loop+3] = 255; - step++; - } - } - break; - case PIXELFORMAT_RGB444 : break; - case PIXELFORMAT_RGB555 : break; - case PIXELFORMAT_RGB565 : - { - int step=0; - for(int loop=0;loop < qimage->numBytes();loop+=4) - { - bits[loop] = (m_currentbuffer.data[step]<<3)+(m_currentbuffer.data[step]<<3>>5); - bits[loop+1] = ((m_currentbuffer.data[step+1])<<5)|m_currentbuffer.data[step]>>5; - bits[loop+2] = ((m_currentbuffer.data[step+1])&248)+((m_currentbuffer.data[step+1])>>5); - bits[loop+3] = 255; - step+=2; - } - } - break; - case PIXELFORMAT_RGB555X: break; - case PIXELFORMAT_RGB565X: break; - case PIXELFORMAT_BGR24 : - { - int step=0; - for(int loop=0;loop < qimage->numBytes();loop+=4) - { - bits[loop] = m_currentbuffer.data[step+2]; - bits[loop+1] = m_currentbuffer.data[step+1]; - bits[loop+2] = m_currentbuffer.data[step]; - bits[loop+3] = 255; - step+=3; - } - } - break; - case PIXELFORMAT_RGB24 : - { - int step=0; - for(int loop=0;loop < qimage->numBytes();loop+=4) - { - bits[loop] = m_currentbuffer.data[step]; - bits[loop+1] = m_currentbuffer.data[step+1]; - bits[loop+2] = m_currentbuffer.data[step+2]; - bits[loop+3] = 255; - step+=3; - } - } - break; - case PIXELFORMAT_BGR32 : - { - int step=0; - for(int loop=0;loop < qimage->numBytes();loop+=4) - { - bits[loop] = m_currentbuffer.data[step+2]; - bits[loop+1] = m_currentbuffer.data[step+1]; - bits[loop+2] = m_currentbuffer.data[step]; - bits[loop+3] = m_currentbuffer.data[step+3]; - step+=4; - } - } - break; - case PIXELFORMAT_RGB32 : memcpy(bits,&m_currentbuffer.data[0], m_currentbuffer.data.size()); - break; - -// Bayer RGB format - case PIXELFORMAT_SBGGR8 : - { - unsigned char *d = (unsigned char *) malloc (width() * height() * 3); - bayer2rgb24(d, &m_currentbuffer.data.first(), width(), height()); - int step=0; - for(int loop=0;loop < qimage->numBytes();loop+=4) - { - bits[loop] = d[step+2]; - bits[loop+1] = d[step+1]; - bits[loop+2] = d[step]; - bits[loop+3] = 255; - step+=3; - } - free(d); - } - break; - -// YUV formats - case PIXELFORMAT_GREY : - { - int step=0; - for(int loop=0;loop < qimage->numBytes();loop+=4) - { - bits[loop] = m_currentbuffer.data[step]; - bits[loop+1] = m_currentbuffer.data[step]; - bits[loop+2] = m_currentbuffer.data[step]; - bits[loop+3] = 255; - step++; - } - } - break; - case PIXELFORMAT_YUYV: - case PIXELFORMAT_UYVY: - case PIXELFORMAT_YUV420P: - case PIXELFORMAT_YUV422P: - { - uchar *yptr, *cbptr, *crptr; - bool halfheight=false; - bool packed=false; -// Adjust algorythm to specific YUV data arrangements. - if (m_currentbuffer.pixelformat == PIXELFORMAT_YUV420P) - halfheight=true; - if (m_currentbuffer.pixelformat == PIXELFORMAT_YUYV) - { - yptr = &m_currentbuffer.data[0]; - cbptr = yptr + 1; - crptr = yptr + 3; - packed=true; - } - else if (m_currentbuffer.pixelformat == PIXELFORMAT_UYVY) - { - cbptr = &m_currentbuffer.data[0]; - yptr = cbptr + 1; - crptr = cbptr + 2; - packed=true; - } - else - { - yptr = &m_currentbuffer.data[0]; - cbptr = yptr + (width()*height()); - crptr = cbptr + (width()*height()/(halfheight ? 4:2)); - } - - for(int y=0; y<height(); y++) - { -// Decode scanline - for(int x=0; x<width(); x++) - { - int c,d,e; - - if (packed) - { - c = (yptr[x<<1])-16; - d = (cbptr[x>>1<<2])-128; - e = (crptr[x>>1<<2])-128; - } - else - { - c = (yptr[x])-16; - d = (cbptr[x>>1])-128; - e = (crptr[x>>1])-128; - } - - int r = (298 * c + 409 * e + 128)>>8; - int g = (298 * c - 100 * d - 208 * e + 128)>>8; - int b = (298 * c + 516 * d + 128)>>8; - - if (r<0) r=0; if (r>255) r=255; - if (g<0) g=0; if (g>255) g=255; - if (b<0) b=0; if (b>255) b=255; - - uint *p = (uint*)qimage->scanLine(y)+x; - *p = qRgba(r,g,b,255); - - } -// Jump to next line - if (packed) - { - yptr+=width()*2; - cbptr+=width()*2; - crptr+=width()*2; - } - else - { - yptr+=width(); - if (!halfheight || y&1) - { - cbptr+=width()/2; - crptr+=width()/2; - } - } - } - } - break; - -// Compressed formats - case PIXELFORMAT_JPEG : break; - case PIXELFORMAT_MPEG : break; - -// Reserved formats - case PIXELFORMAT_DV : break; - case PIXELFORMAT_ET61X251:break; - case PIXELFORMAT_HI240 : break; - case PIXELFORMAT_HM12 : break; - case PIXELFORMAT_MJPEG : break; - case PIXELFORMAT_PWC1 : break; - case PIXELFORMAT_PWC2 : break; - case PIXELFORMAT_SN9C10X: - { - unsigned char *s = new unsigned char [width() * height()]; - unsigned char *d = new unsigned char [width() * height() * 3]; - sonix_decompress_init(); - sonix_decompress(width(), height(), &m_currentbuffer.data.first(), s); - bayer2rgb24(d, s, width(), height()); - int step=0; - for(int loop=0;loop < qimage->numBytes();loop+=4) - { - bits[loop] = d[step+2]; - bits[loop+1] = d[step+1]; - bits[loop+2] = d[step]; - bits[loop+3] = 255; - step+=3; - } - delete[] s; - delete[] d; - } - case PIXELFORMAT_WNVA : break; - case PIXELFORMAT_YYUV : break; - } - - if (m_current_input >= m_input.size() ) - return EXIT_SUCCESS; - -// Proccesses image for automatic Brightness/Contrast/Color correction - if (m_input[m_current_input].img_softcorr_autobrightnesscontrast || m_input[m_current_input].img_softcorr_autocolor) - { - unsigned long long R=0, G=0, B=0, A=0, global=0; - int Rmax=0, Gmax=0, Bmax=0, Amax=0, globalmax=0; - int Rmin=255, Gmin=255, Bmin=255, Amin=255, globalmin=255; - int Rrange=255, Grange=255, Brange=255; - -// Finds minimum and maximum intensity for each color component - for(unsigned int loop=0;loop < (unsigned int) qimage->numBytes();loop+=4) - { - R+=bits[loop]; - G+=bits[loop+1]; - B+=bits[loop+2]; -// A+=bits[loop+3]; - if (bits[loop] < Rmin) Rmin = bits[loop]; - if (bits[loop+1] < Gmin) Gmin = bits[loop+1]; - if (bits[loop+2] < Bmin) Bmin = bits[loop+2]; -// if (bits[loop+3] < Amin) Amin = bits[loop+3]; - if (bits[loop] > Rmax) Rmax = bits[loop]; - if (bits[loop+1] > Gmax) Gmax = bits[loop+1]; - if (bits[loop+2] > Bmax) Bmax = bits[loop+2]; -// if (bits[loop+3] > Amax) Amax = bits[loop+3]; - } - global = R + G + B; -// Finds overall minimum and maximum intensity - if (Rmin > Gmin) globalmin = Gmin; else globalmin = Rmin; if (Bmin < globalmin) globalmin = Bmin; - if (Rmax > Gmax) globalmax = Rmax; else globalmax = Gmax; if (Bmax > globalmax) globalmax = Bmax; -// If no color correction should be performed, simply level all the intensities so they're just the same. -// In fact color correction should use the R, G and B variables to detect color deviation and "bump up" the saturation, -// but it's computationally more expensive and the current way returns better results to the user. - if(!m_input[m_current_input].img_softcorr_autocolor) - { - Rmin = globalmin ; Rmax = globalmax; - Gmin = globalmin ; Gmax = globalmax; - Bmin = globalmin ; Bmax = globalmax; -// Amin = globalmin ; Amax = globalmax; - } -// Calculates ranges and prevent a division by zero later on. - Rrange = Rmax - Rmin; if (Rrange == 0) Rrange = 255; - Grange = Gmax - Gmin; if (Grange == 0) Grange = 255; - Brange = Bmax - Bmin; if (Brange == 0) Brange = 255; -// Arange = Amax - Amin; if (Arange == 0) Arange = 255; - - qDebug() << " R: " << R << " G: " << G << " B: " << B << " A: " << A << " global: " << global << - " Rmin: " << Rmin << " Gmin: " << Gmin << " Bmin: " << Bmin << " Amin: " << Amin << " globalmin: " << globalmin << - " Rmax: " << Rmax << " Gmax: " << Gmax << " Bmax: " << Bmax << " Amax: " << Amax << " globalmax: " << globalmax ; - - for(unsigned int loop=0;loop < (unsigned int) qimage->numBytes();loop+=4) - { - bits[loop] = (bits[loop] - Rmin) * 255 / (Rrange); - bits[loop+1] = (bits[loop+1] - Gmin) * 255 / (Grange); - bits[loop+2] = (bits[loop+2] - Bmin) * 255 / (Brange); -// bits[loop+3] = (bits[loop+3] - Amin) * 255 / (Arange); - } - } - - if (m_input[m_current_input].img_softcorr_vflip || m_input[m_current_input].img_softcorr_hflip) - *qimage = qimage->mirrored(m_input[m_current_input].img_softcorr_vflip, m_input[m_current_input].img_softcorr_hflip); - - return EXIT_SUCCESS; -} - -/*! - \fn VideoDevice::stopCapturing() - */ -int VideoDevice::stopCapturing() -{ - /// @todo implement me - qDebug() << "called."; - if(isOpen()) - { - switch (m_io_method) - { - case IO_METHOD_NONE: // Device cannot capture frames - return EXIT_FAILURE; - break; - case IO_METHOD_READ: // Nothing to do - break; - case IO_METHOD_MMAP: - case IO_METHOD_USERPTR: -#ifdef V4L2_CAP_VIDEO_CAPTURE - { - enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (-1 == xioctl (VIDIOC_STREAMOFF, &type)) - return errnoReturn ("VIDIOC_STREAMOFF"); - - if (m_io_method == IO_METHOD_MMAP) - { - unsigned int loop; - for (loop = 0; loop < m_streambuffers; ++loop) - { -#ifdef HAVE_LIBV4L2 - if (v4l2_munmap(m_rawbuffers[loop].start,m_rawbuffers[loop].length) != 0) -#else - if (munmap(m_rawbuffers[loop].start,m_rawbuffers[loop].length) != 0) -#endif - { - qDebug() << "unable to munmap."; - } - } - } - } -#endif - break; - } - qDebug() << "exited successfuly."; - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - - -/*! - \fn int VideoDevice::close() - \return The success of the operation: EXIT_SUCCESS or EXIT_FAILURE - \brief Closes the device - - Stops capturing, resets internal data and closes the device. - */ -int VideoDevice::close() -{ - qDebug() << "called."; - if (isOpen()) - { - qDebug() << "Device is open. Trying to properly shutdown the device."; - stopCapturing(); -#ifdef HAVE_LIBV4L2 - int ret = ::v4l2_close(descriptor); -#else - int ret = ::close(descriptor); -#endif - if (ret == -1) - { - qDebug() << "::close() failed with errno" << errno << strerror(errno); - return EXIT_FAILURE; - } - else - qDebug() << "Device successfully closed."; - } - descriptor = -1; - m_numericCtrls.clear(); - m_booleanCtrls.clear(); - m_menuCtrls.clear(); - m_actionCtrls.clear(); - m_driver=VIDEODEV_DRIVER_NONE; - return EXIT_SUCCESS; -} - - -/*! - \fn QList<NumericVideoControl> VideoDevice::getSupportedNumericControls() - \return A list of all supported numeric controls for the current input - \brief Returns the supported numeric controls for the current input - */ -QList<NumericVideoControl> VideoDevice::getSupportedNumericControls() -{ - return m_numericCtrls; -} - -/*! - \fn QList<BooleanVideoControl> VideoDevice::getSupportedBooleanControls() - \return A list of all supported boolean controls for the current input - \brief Returns the supported boolean controls for the current input - */ -QList<BooleanVideoControl> VideoDevice::getSupportedBooleanControls() -{ - return m_booleanCtrls; -} - -/*! - \fn QList<MenuVideoControl> VideoDevice::getSupportedMenuControls() - \return A list of all supported menu-controls for the current input - \brief Returns the supported menu-controls for the current input - */ -QList<MenuVideoControl> VideoDevice::getSupportedMenuControls() -{ - return m_menuCtrls; -} - -/*! - \fn QList<ActionVideoControl> VideoDevice::getSupportedActionControls() - \return A list of all supported action-controls for the current input - \brief Returns the supported action-controls for the current input - */ -QList<ActionVideoControl> VideoDevice::getSupportedActionControls() -{ - return m_actionCtrls; -} - -/*! - \fn int VideoDevice::getControlValue(quint32 ctrl_id, qint32 * value) - \param ctrl_id ID of the video-control - \param value Pointer to the variable, which recieves the value of the querried video-control. - For boolean controls, the value is 0 or 1. - For menu-controls, the value is the index of the currently selected option. - \return The result-code, currently EXIT_SUCCESS or EXIT_FAILURE - \brief Reads the value of a video-control - */ -int VideoDevice::getControlValue(quint32 ctrl_id, qint32 * value) -{ - qDebug() << "Control-ID" << ctrl_id << ", Value" << &value; - - if (!isOpen()) - return EXIT_FAILURE; - -#ifndef COMPILE_DISABLE_AVDEVICE - if (ctrl_id == IMGCTRL_ID_SOFT_AUTOBRIGHTNESSCONTRASTCORR) - { - if (m_current_input < m_input.size() ) - { - *value = m_input[m_current_input].img_softcorr_autobrightnesscontrast; - qDebug() << "Reported current value is" << *value << "."; - return EXIT_SUCCESS; - } - else - return EXIT_FAILURE; - } - else if (ctrl_id == IMGCTRL_ID_SOFT_AUTOCOLORCORR) - { - if (m_current_input < m_input.size() ) - { - *value = m_input[m_current_input].img_softcorr_autocolor; - qDebug() << "Reported current value is" << *value << "."; - return EXIT_SUCCESS; - } - else - return EXIT_FAILURE; - } - else if (ctrl_id == IMGCTRL_ID_SOFT_VFLIP) - { - if (m_current_input < m_input.size() ) - { - *value = m_input[m_current_input].img_softcorr_vflip; - qDebug() << "Reported current value is" << *value << "."; - return EXIT_SUCCESS; - } - else - return EXIT_FAILURE; - } - else if (ctrl_id == IMGCTRL_ID_SOFT_HFLIP) - { - if (m_current_input < m_input.size() ) - { - *value = m_input[m_current_input].img_softcorr_hflip; - qDebug() << "Reported current value is" << *value << "."; - return EXIT_SUCCESS; - } - else - return EXIT_FAILURE; - } -#endif - - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - { - struct v4l2_queryctrl queryctrl; - struct v4l2_control control; - - CLEAR (queryctrl); - queryctrl.id = ctrl_id; - - if (-1 == xioctl(VIDIOC_QUERYCTRL, &queryctrl)) - { - if (errno != EINVAL) - qDebug() << "VIDIOC_QUERYCTRL failed (" << errno << ")."; - else - qDebug() << "Device doesn't support the control."; - } - else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) - { - qDebug() << "Control is disabled."; - } - else - { - CLEAR (control); - control.id = ctrl_id; - if (-1 == xioctl(VIDIOC_G_CTRL, &control)) - qDebug() << "VIDIOC_G_CTRL failed (" << errno << ")."; - else - { - *value = control.value; - qDebug() << "Reported current value is" << control.value << "."; - return EXIT_SUCCESS; - } - } - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - struct video_picture V4L_picture; - if(-1 == xioctl(VIDIOCGPICT, &V4L_picture)) - { - qDebug() << "VIDIOCGPICT failed (" << errno << ")."; - return EXIT_FAILURE; - } - switch (ctrl_id) - { - case IMGCTRL_ID_V4L1_BRIGHTNESS: - *value = V4L_picture.brightness; - break; - case IMGCTRL_ID_V4L1_HUE: - *value = V4L_picture.hue; - break; - case IMGCTRL_ID_V4L1_COLOR: - *value = V4L_picture.colour; - break; - case IMGCTRL_ID_V4L1_CONTRAST: - *value = V4L_picture.contrast; - break; - case IMGCTRL_ID_V4L1_WHITENESS: - *value = V4L_picture.whiteness; - break; - default: - return EXIT_FAILURE; - } - qDebug() << "Reported current value is" << *value << "."; - return EXIT_SUCCESS; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - break; - } - return EXIT_FAILURE; -} - -/*! - \fn int VideoDevice::setControlValue(quint32 ctrl_id, qint32 value) - \param ctrl_id ID of the video-control - \param value The value that should be set. - For boolean controls, the value must be 0 or 1. - For menu-controls, the value must be the index of the option. - For action-controls, the value is ignored. - \return The result-code, currently EXIT_SUCCESS or EXIT_FAILURE - \brief Sets the value of a video-control - */ -int VideoDevice::setControlValue(quint32 ctrl_id, qint32 value) -{ - qDebug() << "Control-ID" << ctrl_id << ", Value" << value; - - if (!isOpen()) - return EXIT_FAILURE; - -#ifndef COMPILE_DISABLE_AVDEVICE - if (ctrl_id == IMGCTRL_ID_SOFT_AUTOBRIGHTNESSCONTRASTCORR) - { - if (m_current_input < m_input.size() ) - { - m_input[m_current_input].img_softcorr_autobrightnesscontrast = value; - return EXIT_SUCCESS; - } - else - return EXIT_FAILURE; - } - else if (ctrl_id == IMGCTRL_ID_SOFT_AUTOCOLORCORR) - { - if (m_current_input < m_input.size() ) - { - m_input[m_current_input].img_softcorr_autocolor = value; - return EXIT_SUCCESS; - } - else - return EXIT_FAILURE; - } - else if (ctrl_id == IMGCTRL_ID_SOFT_VFLIP) - { - if (m_current_input < m_input.size() ) - { - m_input[m_current_input].img_softcorr_vflip = value; - return EXIT_SUCCESS; - } - else - return EXIT_FAILURE; - } - else if (ctrl_id == IMGCTRL_ID_SOFT_HFLIP) - { - if (m_current_input < m_input.size() ) - { - m_input[m_current_input].img_softcorr_hflip = value; - return EXIT_SUCCESS; - } - else - return EXIT_FAILURE; - } -#endif - - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - { - struct v4l2_queryctrl queryctrl; - struct v4l2_control control; - - CLEAR (queryctrl); - queryctrl.id = ctrl_id; - - if (-1 == xioctl(VIDIOC_QUERYCTRL, &queryctrl)) - { - if (errno != EINVAL) - qDebug() << "VIDIOC_QUERYCTRL failed (" << errno << ")."; - else - qDebug() << "Device doesn't support the control."; - } - else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) - { - qDebug() << "Control is disabled."; - } - else - { - CLEAR (control); - control.id = ctrl_id; - if (value < queryctrl.minimum) - { - control.value = queryctrl.minimum; - qDebug() << "Value exceeds lower limit ! Setting to minimum:" << control.value; - } - else if (value > queryctrl.maximum) - { - control.value = queryctrl.maximum; - qDebug() << "Value exceeds upper limit ! Setting to maximum:" << control.value; - } - else - { - control.value = value; - } - if (-1 == xioctl(VIDIOC_S_CTRL, &control)) - qDebug() << "VIDIOC_S_CTRL failed (" << errno << ")."; - else - return EXIT_SUCCESS; - } - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - struct video_picture V4L_picture; - if(-1 == xioctl(VIDIOCGPICT, &V4L_picture)) - { - qDebug() << "VIDIOCGPICT failed (" << errno << ")."; - return EXIT_FAILURE; - } - if (value < 0) - { - value = 0; - qDebug() << "Value exceeds lower limit ! Setting to minimum: 0"; - } - else if (value > 65535) - { - value = 65535; - qDebug() << "Value exceeds upper limit ! Setting to maximum: 65535"; - } - // TODO: consider step, too ? - switch (ctrl_id) - { - case IMGCTRL_ID_V4L1_BRIGHTNESS: - V4L_picture.brightness = value; - break; - case IMGCTRL_ID_V4L1_HUE: - V4L_picture.hue = value; - break; - case IMGCTRL_ID_V4L1_COLOR: - V4L_picture.colour = value; - break; - case IMGCTRL_ID_V4L1_CONTRAST: - V4L_picture.contrast = value; - break; - case IMGCTRL_ID_V4L1_WHITENESS: - V4L_picture.whiteness = value; - break; - default: - return EXIT_FAILURE; - } - if(-1 == xioctl(VIDIOCSPICT,&V4L_picture)) - { - qDebug() << "Device seems to not support adjusting image brightness. Fallback to it is not yet implemented."; - return EXIT_FAILURE; - } - return EXIT_SUCCESS; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - break; - } - return EXIT_FAILURE; -} - -pixel_format VideoDevice::pixelFormatForPalette( int palette ) -{ - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - switch(palette) - { - case 0 : return PIXELFORMAT_NONE; break; - -// Packed RGB formats - case V4L2_PIX_FMT_RGB332 : return PIXELFORMAT_RGB332; break; -#if defined( V4L2_PIX_FMT_RGB444 ) - case V4L2_PIX_FMT_RGB444 : return PIXELFORMAT_RGB444; break; -#endif - case V4L2_PIX_FMT_RGB555 : return PIXELFORMAT_RGB555; break; - case V4L2_PIX_FMT_RGB565 : return PIXELFORMAT_RGB565; break; - case V4L2_PIX_FMT_RGB555X : return PIXELFORMAT_RGB555X; break; - case V4L2_PIX_FMT_RGB565X : return PIXELFORMAT_RGB565X; break; - case V4L2_PIX_FMT_BGR24 : return PIXELFORMAT_BGR24; break; - case V4L2_PIX_FMT_RGB24 : return PIXELFORMAT_RGB24; break; - case V4L2_PIX_FMT_BGR32 : return PIXELFORMAT_BGR32; break; - case V4L2_PIX_FMT_RGB32 : return PIXELFORMAT_RGB32; break; - -// Bayer RGB format - case V4L2_PIX_FMT_SBGGR8 : return PIXELFORMAT_SBGGR8; break; - -// YUV formats - case V4L2_PIX_FMT_GREY : return PIXELFORMAT_GREY; break; - case V4L2_PIX_FMT_YUYV : return PIXELFORMAT_YUYV; break; - case V4L2_PIX_FMT_UYVY : return PIXELFORMAT_UYVY; break; - case V4L2_PIX_FMT_YUV420 : return PIXELFORMAT_YUV420P; break; - case V4L2_PIX_FMT_YUV422P : return PIXELFORMAT_YUV422P; break; - -// Compressed formats - case V4L2_PIX_FMT_JPEG : return PIXELFORMAT_JPEG; break; - case V4L2_PIX_FMT_MPEG : return PIXELFORMAT_MPEG; break; - -// Reserved formats - case V4L2_PIX_FMT_DV : return PIXELFORMAT_DV; break; - case V4L2_PIX_FMT_ET61X251 : return PIXELFORMAT_ET61X251; break; - case V4L2_PIX_FMT_HI240 : return PIXELFORMAT_HI240; break; -#if defined( V4L2_PIX_FMT_HM12 ) - case V4L2_PIX_FMT_HM12 : return PIXELFORMAT_HM12; break; -#endif - case V4L2_PIX_FMT_MJPEG : return PIXELFORMAT_MJPEG; break; - case V4L2_PIX_FMT_PWC1 : return PIXELFORMAT_PWC1; break; - case V4L2_PIX_FMT_PWC2 : return PIXELFORMAT_PWC2; break; - case V4L2_PIX_FMT_SN9C10X : return PIXELFORMAT_SN9C10X; break; - case V4L2_PIX_FMT_WNVA : return PIXELFORMAT_WNVA; break; - case V4L2_PIX_FMT_YYUV : return PIXELFORMAT_YYUV; break; - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - switch(palette) - { - case 0 : return PIXELFORMAT_NONE; break; - case VIDEO_PALETTE_GREY : return PIXELFORMAT_GREY; break; - case VIDEO_PALETTE_HI240 : return PIXELFORMAT_RGB332; break; - case VIDEO_PALETTE_RGB555 : return PIXELFORMAT_RGB555; break; - case VIDEO_PALETTE_RGB565 : return PIXELFORMAT_RGB565; break; - case VIDEO_PALETTE_RGB24 : return PIXELFORMAT_RGB24; break; - case VIDEO_PALETTE_RGB32 : return PIXELFORMAT_RGB32; break; - case VIDEO_PALETTE_YUYV : return PIXELFORMAT_YUYV; break; - case VIDEO_PALETTE_UYVY : return PIXELFORMAT_UYVY; break; - case VIDEO_PALETTE_YUV420 : - case VIDEO_PALETTE_YUV420P : return PIXELFORMAT_YUV420P; break; - case VIDEO_PALETTE_YUV422P : return PIXELFORMAT_YUV422P; break; - } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - return PIXELFORMAT_NONE; break; - } - return PIXELFORMAT_NONE; -} - -int VideoDevice::pixelFormatCode(pixel_format pixelformat) -{ - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - switch(pixelformat) - { - case PIXELFORMAT_NONE : return 0; break; - -// Packed RGB formats - case PIXELFORMAT_RGB332 : return V4L2_PIX_FMT_RGB332; break; -#if defined( V4L2_PIX_FMT_RGB444 ) - case PIXELFORMAT_RGB444 : return V4L2_PIX_FMT_RGB444; break; -#endif - case PIXELFORMAT_RGB555 : return V4L2_PIX_FMT_RGB555; break; - case PIXELFORMAT_RGB565 : return V4L2_PIX_FMT_RGB565; break; - case PIXELFORMAT_RGB555X: return V4L2_PIX_FMT_RGB555X; break; - case PIXELFORMAT_RGB565X: return V4L2_PIX_FMT_RGB565X; break; - case PIXELFORMAT_BGR24 : return V4L2_PIX_FMT_BGR24; break; - case PIXELFORMAT_RGB24 : return V4L2_PIX_FMT_RGB24; break; - case PIXELFORMAT_BGR32 : return V4L2_PIX_FMT_BGR32; break; - case PIXELFORMAT_RGB32 : return V4L2_PIX_FMT_RGB32; break; - -// Bayer RGB format - case PIXELFORMAT_SBGGR8 : return V4L2_PIX_FMT_SBGGR8; break; - -// YUV formats - case PIXELFORMAT_GREY : return V4L2_PIX_FMT_GREY; break; - case PIXELFORMAT_YUYV : return V4L2_PIX_FMT_YUYV; break; - case PIXELFORMAT_UYVY : return V4L2_PIX_FMT_UYVY; break; - case PIXELFORMAT_YUV420P: return V4L2_PIX_FMT_YUV420; break; - case PIXELFORMAT_YUV422P: return V4L2_PIX_FMT_YUV422P; break; - -// Compressed formats - case PIXELFORMAT_JPEG : return V4L2_PIX_FMT_JPEG; break; - case PIXELFORMAT_MPEG : return V4L2_PIX_FMT_MPEG; break; - -// Reserved formats - case PIXELFORMAT_DV : return V4L2_PIX_FMT_DV; break; - case PIXELFORMAT_ET61X251:return V4L2_PIX_FMT_ET61X251;break; - case PIXELFORMAT_HI240 : return V4L2_PIX_FMT_HI240; break; -#if defined( V4L2_PIX_FMT_HM12 ) - case PIXELFORMAT_HM12 : return V4L2_PIX_FMT_HM12; break; -#endif - case PIXELFORMAT_MJPEG : return V4L2_PIX_FMT_MJPEG; break; - case PIXELFORMAT_PWC1 : return V4L2_PIX_FMT_PWC1; break; - case PIXELFORMAT_PWC2 : return V4L2_PIX_FMT_PWC2; break; - case PIXELFORMAT_SN9C10X: return V4L2_PIX_FMT_SN9C10X; break; - case PIXELFORMAT_WNVA : return V4L2_PIX_FMT_WNVA; break; - case PIXELFORMAT_YYUV : return V4L2_PIX_FMT_YYUV; break; - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - switch(pixelformat) - { - case PIXELFORMAT_NONE : return 0; break; - -// Packed RGB formats - case PIXELFORMAT_RGB332 : return VIDEO_PALETTE_HI240; break; - case PIXELFORMAT_RGB444 : return 0; break; - case PIXELFORMAT_RGB555 : return VIDEO_PALETTE_RGB555; break; - case PIXELFORMAT_RGB565 : return VIDEO_PALETTE_RGB565; break; - case PIXELFORMAT_RGB555X: return 0; break; - case PIXELFORMAT_RGB565X: return 0; break; - case PIXELFORMAT_BGR24 : return 0; break; - case PIXELFORMAT_RGB24 : return VIDEO_PALETTE_RGB24; break; - case PIXELFORMAT_BGR32 : return 0; break; - case PIXELFORMAT_RGB32 : return VIDEO_PALETTE_RGB32; break; - -// Bayer RGB format - case PIXELFORMAT_SBGGR8 : return 0; break; - -// YUV formats - case PIXELFORMAT_GREY : return VIDEO_PALETTE_GREY; break; - case PIXELFORMAT_YUYV : return VIDEO_PALETTE_YUYV; break; - case PIXELFORMAT_UYVY : return VIDEO_PALETTE_UYVY; break; - case PIXELFORMAT_YUV420P: return VIDEO_PALETTE_YUV420; break; - case PIXELFORMAT_YUV422P: return VIDEO_PALETTE_YUV422P; break; - -// Compressed formats - case PIXELFORMAT_JPEG : return 0; break; - case PIXELFORMAT_MPEG : return 0; break; - -// Reserved formats - case PIXELFORMAT_DV : return 0; break; - case PIXELFORMAT_ET61X251:return 0; break; - case PIXELFORMAT_HI240 : return VIDEO_PALETTE_HI240; break; - case PIXELFORMAT_HM12 : return 0; break; - case PIXELFORMAT_MJPEG : return 0; break; - case PIXELFORMAT_PWC1 : return 0; break; - case PIXELFORMAT_PWC2 : return 0; break; - case PIXELFORMAT_SN9C10X: return 0; break; - case PIXELFORMAT_WNVA : return 0; break; - case PIXELFORMAT_YYUV : return 0; break; - } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - return PIXELFORMAT_NONE; break; - } - return PIXELFORMAT_NONE; -} - -int VideoDevice::pixelFormatDepth(pixel_format pixelformat) -{ - switch(pixelformat) - { - case PIXELFORMAT_NONE : return 0; break; - -// Packed RGB formats - case PIXELFORMAT_RGB332 : return 8; break; - case PIXELFORMAT_RGB444 : return 16; break; - case PIXELFORMAT_RGB555 : return 16; break; - case PIXELFORMAT_RGB565 : return 16; break; - case PIXELFORMAT_RGB555X: return 16; break; - case PIXELFORMAT_RGB565X: return 16; break; - case PIXELFORMAT_BGR24 : return 24; break; - case PIXELFORMAT_RGB24 : return 24; break; - case PIXELFORMAT_BGR32 : return 32; break; - case PIXELFORMAT_RGB32 : return 32; break; - -// Bayer RGB format - case PIXELFORMAT_SBGGR8 : return 0; break; - -// YUV formats - case PIXELFORMAT_GREY : return 8; break; - case PIXELFORMAT_YUYV : return 16; break; - case PIXELFORMAT_UYVY : return 16; break; - case PIXELFORMAT_YUV420P: return 16; break; - case PIXELFORMAT_YUV422P: return 16; break; - -// Compressed formats - case PIXELFORMAT_JPEG : return 0; break; - case PIXELFORMAT_MPEG : return 0; break; - -// Reserved formats - case PIXELFORMAT_DV : return 0; break; - case PIXELFORMAT_ET61X251:return 0; break; - case PIXELFORMAT_HI240 : return 8; break; - case PIXELFORMAT_HM12 : return 0; break; - case PIXELFORMAT_MJPEG : return 0; break; - case PIXELFORMAT_PWC1 : return 0; break; - case PIXELFORMAT_PWC2 : return 0; break; - case PIXELFORMAT_SN9C10X: return 0; break; - case PIXELFORMAT_WNVA : return 0; break; - case PIXELFORMAT_YYUV : return 0; break; - } - return 0; -} - -QString VideoDevice::pixelFormatName(pixel_format pixelformat) -{ - QString returnvalue; - returnvalue = "None"; - switch(pixelformat) - { - case PIXELFORMAT_NONE : returnvalue = "None"; break; - -// Packed RGB formats - case PIXELFORMAT_RGB332 : returnvalue = "8-bit RGB332"; break; - case PIXELFORMAT_RGB444 : returnvalue = "8-bit RGB444"; break; - case PIXELFORMAT_RGB555 : returnvalue = "16-bit RGB555"; break; - case PIXELFORMAT_RGB565 : returnvalue = "16-bit RGB565"; break; - case PIXELFORMAT_RGB555X: returnvalue = "16-bit RGB555X"; break; - case PIXELFORMAT_RGB565X: returnvalue = "16-bit RGB565X"; break; - case PIXELFORMAT_BGR24 : returnvalue = "24-bit BGR24"; break; - case PIXELFORMAT_RGB24 : returnvalue = "24-bit RGB24"; break; - case PIXELFORMAT_BGR32 : returnvalue = "32-bit BGR32"; break; - case PIXELFORMAT_RGB32 : returnvalue = "32-bit RGB32"; break; - -// Bayer RGB format - case PIXELFORMAT_SBGGR8 : returnvalue = "Bayer RGB format"; break; - -// YUV formats - case PIXELFORMAT_GREY : returnvalue = "8-bit Grayscale"; break; - case PIXELFORMAT_YUYV : returnvalue = "Packed YUV 4:2:2"; break; - case PIXELFORMAT_UYVY : returnvalue = "Packed YVU 4:2:2"; break; - case PIXELFORMAT_YUV420P: returnvalue = "Planar YUV 4:2:0"; break; - case PIXELFORMAT_YUV422P: returnvalue = "Planar YUV 4:2:2"; break; - - -// Compressed formats - case PIXELFORMAT_JPEG : returnvalue = "JPEG image"; break; - case PIXELFORMAT_MPEG : returnvalue = "MPEG stream"; break; - -// Reserved formats - case PIXELFORMAT_DV : returnvalue = "DV (unknown)"; break; - case PIXELFORMAT_ET61X251:returnvalue = "ET61X251"; break; - case PIXELFORMAT_HI240 : returnvalue = "8-bit HI240 (RGB332)"; break; - case PIXELFORMAT_HM12 : returnvalue = "Packed YUV 4:2:2"; break; - case PIXELFORMAT_MJPEG : returnvalue = "8-bit Grayscale"; break; - case PIXELFORMAT_PWC1 : returnvalue = "PWC1"; break; - case PIXELFORMAT_PWC2 : returnvalue = "PWC2"; break; - case PIXELFORMAT_SN9C10X: returnvalue = "SN9C102"; break; - case PIXELFORMAT_WNVA : returnvalue = "Winnov Videum"; break; - case PIXELFORMAT_YYUV : returnvalue = "YYUV (unknown)"; break; - } - return returnvalue; -} - -QString VideoDevice::pixelFormatName(int pixelformat) -{ - QString returnvalue; - returnvalue = "None"; - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - switch(pixelformat) - { - case 0 : returnvalue = pixelFormatName(PIXELFORMAT_NONE); break; - -// Packed RGB formats - case V4L2_PIX_FMT_RGB332 : returnvalue = pixelFormatName(PIXELFORMAT_RGB332); break; -#if defined( V4L2_PIX_FMT_RGB444 ) - case V4L2_PIX_FMT_RGB444 : returnvalue = pixelFormatName(PIXELFORMAT_RGB444); break; -#endif - case V4L2_PIX_FMT_RGB555 : returnvalue = pixelFormatName(PIXELFORMAT_RGB555); break; - case V4L2_PIX_FMT_RGB565 : returnvalue = pixelFormatName(PIXELFORMAT_RGB565); break; - case V4L2_PIX_FMT_RGB555X : returnvalue = pixelFormatName(PIXELFORMAT_RGB555X); break; - case V4L2_PIX_FMT_RGB565X : returnvalue = pixelFormatName(PIXELFORMAT_RGB565X); break; - case V4L2_PIX_FMT_BGR24 : returnvalue = pixelFormatName(PIXELFORMAT_BGR24); break; - case V4L2_PIX_FMT_RGB24 : returnvalue = pixelFormatName(PIXELFORMAT_RGB24); break; - case V4L2_PIX_FMT_BGR32 : returnvalue = pixelFormatName(PIXELFORMAT_BGR32); break; - case V4L2_PIX_FMT_RGB32 : returnvalue = pixelFormatName(PIXELFORMAT_RGB32); break; - -// Bayer RGB format - case V4L2_PIX_FMT_SBGGR8 : returnvalue = pixelFormatName(PIXELFORMAT_SBGGR8); break; - -// YUV formats - case V4L2_PIX_FMT_GREY : returnvalue = pixelFormatName(PIXELFORMAT_GREY); break; - case V4L2_PIX_FMT_YUYV : returnvalue = pixelFormatName(PIXELFORMAT_YUYV); break; - case V4L2_PIX_FMT_UYVY : returnvalue = pixelFormatName(PIXELFORMAT_UYVY); break; - case V4L2_PIX_FMT_YUV420 : returnvalue = pixelFormatName(PIXELFORMAT_YUV420P); break; - case V4L2_PIX_FMT_YUV422P : returnvalue = pixelFormatName(PIXELFORMAT_YUV422P); break; - -// Compressed formats - case V4L2_PIX_FMT_JPEG : returnvalue = pixelFormatName(PIXELFORMAT_JPEG); break; - case V4L2_PIX_FMT_MPEG : returnvalue = pixelFormatName(PIXELFORMAT_MPEG); break; - -// Reserved formats - case V4L2_PIX_FMT_DV : returnvalue = pixelFormatName(PIXELFORMAT_DV); break; - case V4L2_PIX_FMT_ET61X251 : returnvalue = pixelFormatName(PIXELFORMAT_ET61X251); break; - case V4L2_PIX_FMT_HI240 : returnvalue = pixelFormatName(PIXELFORMAT_HI240); break; -#if defined( V4L2_PIX_FMT_HM12 ) - case V4L2_PIX_FMT_HM12 : returnvalue = pixelFormatName(PIXELFORMAT_HM12); break; -#endif - case V4L2_PIX_FMT_MJPEG : returnvalue = pixelFormatName(PIXELFORMAT_MJPEG); break; - case V4L2_PIX_FMT_PWC1 : returnvalue = pixelFormatName(PIXELFORMAT_PWC1); break; - case V4L2_PIX_FMT_PWC2 : returnvalue = pixelFormatName(PIXELFORMAT_PWC2); break; - case V4L2_PIX_FMT_SN9C10X : returnvalue = pixelFormatName(PIXELFORMAT_SN9C10X); break; - case V4L2_PIX_FMT_WNVA : returnvalue = pixelFormatName(PIXELFORMAT_WNVA); break; - case V4L2_PIX_FMT_YYUV : returnvalue = pixelFormatName(PIXELFORMAT_YYUV); break; - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - switch(pixelformat) - { - case VIDEO_PALETTE_GREY : returnvalue = pixelFormatName(PIXELFORMAT_GREY); break; - case VIDEO_PALETTE_HI240 : returnvalue = pixelFormatName(PIXELFORMAT_RGB332); break; - case VIDEO_PALETTE_RGB555 : returnvalue = pixelFormatName(PIXELFORMAT_RGB555); break; - case VIDEO_PALETTE_RGB565 : returnvalue = pixelFormatName(PIXELFORMAT_RGB565); break; - case VIDEO_PALETTE_RGB24 : returnvalue = pixelFormatName(PIXELFORMAT_RGB24); break; - case VIDEO_PALETTE_RGB32 : returnvalue = pixelFormatName(PIXELFORMAT_RGB32); break; - case VIDEO_PALETTE_YUYV : returnvalue = pixelFormatName(PIXELFORMAT_YUYV); break; - case VIDEO_PALETTE_UYVY : returnvalue = pixelFormatName(PIXELFORMAT_UYVY); break; - case VIDEO_PALETTE_YUV420 : - case VIDEO_PALETTE_YUV420P : returnvalue = pixelFormatName(PIXELFORMAT_YUV420P); break; - case VIDEO_PALETTE_YUV422P : returnvalue = pixelFormatName(PIXELFORMAT_YUV422P); break; - } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - break; - } - return returnvalue; -} - -int VideoDevice::detectPixelFormats() -{ - int err = 0; - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - struct v4l2_fmtdesc fmtdesc; - fmtdesc.index = 0; - fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - while ( err == 0 ) - { - if (-1 == xioctl (VIDIOC_ENUM_FMT, &fmtdesc)) -// if (ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc) < 0 ) - { - perror("VIDIOC_ENUM_FMT"); - err = errno; - } - else - { - qDebug () << fmtdesc.pixelformat << " " << pixelFormatName(fmtdesc.pixelformat); // Need a cleanup. PixelFormatForPalette is a really bad name - fmtdesc.index++; - } - } -// break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: -// TODO: THis thing can be used to detec what pixel formats are supported in a API-independent way, but V4L2 has VIDIOC_ENUM_PIXFMT. -// The correct thing to do is to isolate these calls and do a proper implementation for V4L and another for V4L2 when this thing will be migrated to a plugin architecture. - -// Packed RGB formats - qDebug() << "Supported pixel formats:"; - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_RGB332)) { qDebug() << pixelFormatName(PIXELFORMAT_RGB332); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_RGB444)) { qDebug() << pixelFormatName(PIXELFORMAT_RGB444); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_RGB555)) { qDebug() << pixelFormatName(PIXELFORMAT_RGB555); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_RGB565)) { qDebug() << pixelFormatName(PIXELFORMAT_RGB565); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_RGB555X)) { qDebug() << pixelFormatName(PIXELFORMAT_RGB555X); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_RGB565X)) { qDebug() << pixelFormatName(PIXELFORMAT_RGB565X); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_BGR24)) { qDebug() << pixelFormatName(PIXELFORMAT_BGR24); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_RGB24)) { qDebug() << pixelFormatName(PIXELFORMAT_RGB24); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_BGR32)) { qDebug() << pixelFormatName(PIXELFORMAT_BGR32); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_RGB32)) { qDebug() << pixelFormatName(PIXELFORMAT_RGB32); } - -// Bayer RGB format - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_SBGGR8)) { qDebug() << pixelFormatName(PIXELFORMAT_SBGGR8); } - -// YUV formats - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_GREY)) { qDebug() << pixelFormatName(PIXELFORMAT_GREY); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_YUYV)) { qDebug() << pixelFormatName(PIXELFORMAT_YUYV); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_UYVY)) { qDebug() << pixelFormatName(PIXELFORMAT_UYVY); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_YUV420P)) { qDebug() << pixelFormatName(PIXELFORMAT_YUV420P); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_YUV422P)) { qDebug() << pixelFormatName(PIXELFORMAT_YUV422P); } - -// Compressed formats - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_JPEG)) { qDebug() << pixelFormatName(PIXELFORMAT_JPEG); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_MPEG)) { qDebug() << pixelFormatName(PIXELFORMAT_MPEG); } - -// Reserved formats - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_DV)) { qDebug() << pixelFormatName(PIXELFORMAT_DV); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_ET61X251)) { qDebug() << pixelFormatName(PIXELFORMAT_ET61X251); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_HI240)) { qDebug() << pixelFormatName(PIXELFORMAT_HI240); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_HM12)) { qDebug() << pixelFormatName(PIXELFORMAT_HM12); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_MJPEG)) { qDebug() << pixelFormatName(PIXELFORMAT_MJPEG); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_PWC1)) { qDebug() << pixelFormatName(PIXELFORMAT_PWC1); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_PWC2)) { qDebug() << pixelFormatName(PIXELFORMAT_PWC2); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_SN9C10X)) { qDebug() << pixelFormatName(PIXELFORMAT_SN9C10X); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_WNVA)) { qDebug() << pixelFormatName(PIXELFORMAT_WNVA); } - if(PIXELFORMAT_NONE != setPixelFormat(PIXELFORMAT_YYUV)) { qDebug() << pixelFormatName(PIXELFORMAT_YYUV); } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - return PIXELFORMAT_NONE; break; - } - return PIXELFORMAT_NONE; -} - -__u64 VideoDevice::signalStandardCode(signal_standard standard) -{ - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - switch(standard) - { - case STANDARD_PAL_B : return V4L2_STD_PAL_B; break; - case STANDARD_PAL_B1 : return V4L2_STD_PAL_B1; break; - case STANDARD_PAL_G : return V4L2_STD_PAL_G; break; - case STANDARD_PAL_H : return V4L2_STD_PAL_H; break; - case STANDARD_PAL_I : return V4L2_STD_PAL_I; break; - case STANDARD_PAL_D : return V4L2_STD_PAL_D; break; - case STANDARD_PAL_D1 : return V4L2_STD_PAL_D1; break; - case STANDARD_PAL_K : return V4L2_STD_PAL_K; break; - - case STANDARD_PAL_M : return V4L2_STD_PAL_M; break; - case STANDARD_PAL_N : return V4L2_STD_PAL_N; break; - case STANDARD_PAL_Nc : return V4L2_STD_PAL_Nc; break; - case STANDARD_PAL_60 : return V4L2_STD_PAL_60; break; - - case STANDARD_NTSC_M : return V4L2_STD_NTSC_M; break; - case STANDARD_NTSC_M_JP : return V4L2_STD_NTSC_M_JP; break; - case STANDARD_NTSC_443 : return V4L2_STD_NTSC_443; break; - case STANDARD_NTSC_M_KR : return V4L2_STD_NTSC_M_KR; break; - - case STANDARD_SECAM_B : return V4L2_STD_SECAM_B; break; - case STANDARD_SECAM_D : return V4L2_STD_SECAM_D; break; - case STANDARD_SECAM_G : return V4L2_STD_SECAM_G; break; - case STANDARD_SECAM_H : return V4L2_STD_SECAM_H; break; - case STANDARD_SECAM_K : return V4L2_STD_SECAM_K; break; - case STANDARD_SECAM_K1 : return V4L2_STD_SECAM_K1; break; - case STANDARD_SECAM_L : return V4L2_STD_SECAM_L; break; - case STANDARD_SECAM_LC : return V4L2_STD_SECAM_LC; break; - - case STANDARD_ATSC_8_VSB: return V4L2_STD_ATSC_8_VSB; break; - case STANDARD_ATSC_16_VSB:return V4L2_STD_ATSC_16_VSB; break; - - case STANDARD_PAL_BG : return V4L2_STD_PAL_BG; break; - case STANDARD_PAL_DK : return V4L2_STD_PAL_DK; break; - case STANDARD_PAL : return V4L2_STD_PAL; break; - case STANDARD_NTSC : return V4L2_STD_NTSC; break; - case STANDARD_SECAM_DK : return V4L2_STD_SECAM_DK; break; - case STANDARD_SECAM : return V4L2_STD_SECAM; break; - - case STANDARD_MN : return V4L2_STD_MN; break; - case STANDARD_B : return V4L2_STD_B; break; - case STANDARD_GH : return V4L2_STD_GH; break; - case STANDARD_DK : return V4L2_STD_DK; break; - - case STANDARD_525_60 : return V4L2_STD_525_60; break; - case STANDARD_625_50 : return V4L2_STD_625_50; break; - case STANDARD_ATSC : return V4L2_STD_ATSC; break; - - case STANDARD_UNKNOWN : return V4L2_STD_UNKNOWN; break; - case STANDARD_ALL : return V4L2_STD_ALL; break; - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - switch(standard) - { - case STANDARD_PAL_B : return VIDEO_MODE_PAL; break; - case STANDARD_PAL_B1 : return VIDEO_MODE_PAL; break; - case STANDARD_PAL_G : return VIDEO_MODE_PAL; break; - case STANDARD_PAL_H : return VIDEO_MODE_PAL; break; - case STANDARD_PAL_I : return VIDEO_MODE_PAL; break; - case STANDARD_PAL_D : return VIDEO_MODE_PAL; break; - case STANDARD_PAL_D1 : return VIDEO_MODE_PAL; break; - case STANDARD_PAL_K : return VIDEO_MODE_PAL; break; - - case STANDARD_PAL_M : return 5; break; // Undocumented value found to be compatible with V4L bttv driver - case STANDARD_PAL_N : return 6; break; // Undocumented value found to be compatible with V4L bttv driver - case STANDARD_PAL_Nc : return 4; break; // Undocumented value found to be compatible with V4L bttv driver - case STANDARD_PAL_60 : return VIDEO_MODE_PAL; break; - - case STANDARD_NTSC_M : return VIDEO_MODE_NTSC; break; - case STANDARD_NTSC_M_JP : return 7; break; // Undocumented value found to be compatible with V4L bttv driver - case STANDARD_NTSC_443 : return VIDEO_MODE_NTSC; break; - case STANDARD_NTSC_M_KR : return VIDEO_MODE_NTSC; break; - - case STANDARD_SECAM_B : return VIDEO_MODE_SECAM; break; - case STANDARD_SECAM_D : return VIDEO_MODE_SECAM; break; - case STANDARD_SECAM_G : return VIDEO_MODE_SECAM; break; - case STANDARD_SECAM_H : return VIDEO_MODE_SECAM; break; - case STANDARD_SECAM_K : return VIDEO_MODE_SECAM; break; - case STANDARD_SECAM_K1 : return VIDEO_MODE_SECAM; break; - case STANDARD_SECAM_L : return VIDEO_MODE_SECAM; break; - case STANDARD_SECAM_LC : return VIDEO_MODE_SECAM; break; - - case STANDARD_ATSC_8_VSB: return VIDEO_MODE_AUTO; break; - case STANDARD_ATSC_16_VSB:return VIDEO_MODE_AUTO; break; - - case STANDARD_PAL_BG : return VIDEO_MODE_PAL; break; - case STANDARD_PAL_DK : return VIDEO_MODE_PAL; break; - case STANDARD_PAL : return VIDEO_MODE_PAL; break; - case STANDARD_NTSC : return VIDEO_MODE_NTSC; break; - case STANDARD_SECAM_DK : return VIDEO_MODE_SECAM; break; - case STANDARD_SECAM : return VIDEO_MODE_SECAM; break; - - case STANDARD_MN : return VIDEO_MODE_AUTO; break; - case STANDARD_B : return VIDEO_MODE_AUTO; break; - case STANDARD_GH : return VIDEO_MODE_AUTO; break; - case STANDARD_DK : return VIDEO_MODE_AUTO; break; - - case STANDARD_525_60 : return VIDEO_MODE_PAL; break; - case STANDARD_625_50 : return VIDEO_MODE_SECAM; break; - case STANDARD_ATSC : return VIDEO_MODE_AUTO; break; - - case STANDARD_UNKNOWN : return VIDEO_MODE_AUTO; break; - case STANDARD_ALL : return VIDEO_MODE_AUTO; break; - } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - return STANDARD_UNKNOWN; break; - } - return STANDARD_UNKNOWN; -} - -QString VideoDevice::signalStandardName(signal_standard standard) -{ - QString returnvalue; - returnvalue = "None"; - switch(standard) - { - case STANDARD_PAL_B : returnvalue = "PAL-B"; break; - case STANDARD_PAL_B1 : returnvalue = "PAL-B1"; break; - case STANDARD_PAL_G : returnvalue = "PAL-G"; break; - case STANDARD_PAL_H : returnvalue = "PAL-H"; break; - case STANDARD_PAL_I : returnvalue = "PAL-I"; break; - case STANDARD_PAL_D : returnvalue = "PAL-D"; break; - case STANDARD_PAL_D1 : returnvalue = "PAL-D1"; break; - case STANDARD_PAL_K : returnvalue = "PAL-K"; break; - - case STANDARD_PAL_M : returnvalue = "PAL-M"; break; - case STANDARD_PAL_N : returnvalue = "PAL-N"; break; - case STANDARD_PAL_Nc : returnvalue = "PAL-Nc"; break; - case STANDARD_PAL_60 : returnvalue = "PAL-60"; break; - - case STANDARD_NTSC_M : returnvalue = "NTSC-M"; break; - case STANDARD_NTSC_M_JP : returnvalue = "NTSC-M(JP)"; break; - case STANDARD_NTSC_443 : returnvalue = "NTSC-443"; break; - case STANDARD_NTSC_M_KR : returnvalue = "NTSC-M(KR)"; break; - - case STANDARD_SECAM_B : returnvalue = "SECAM-B"; break; - case STANDARD_SECAM_D : returnvalue = "SECAM-D"; break; - case STANDARD_SECAM_G : returnvalue = "SECAM-G"; break; - case STANDARD_SECAM_H : returnvalue = "SECAM-H"; break; - case STANDARD_SECAM_K : returnvalue = "SECAM-K"; break; - case STANDARD_SECAM_K1 : returnvalue = "SECAM-K1"; break; - case STANDARD_SECAM_L : returnvalue = "SECAM-L"; break; - case STANDARD_SECAM_LC : returnvalue = "SECAM-LC"; break; - - case STANDARD_ATSC_8_VSB: returnvalue = "ATSC-8-VSB"; break; - case STANDARD_ATSC_16_VSB:returnvalue = "ATSC-16-VSB"; break; - - case STANDARD_PAL_BG : returnvalue = "PAL-BG"; break; - case STANDARD_PAL_DK : returnvalue = "PAL-DK"; break; - case STANDARD_PAL : returnvalue = "PAL"; break; - case STANDARD_NTSC : returnvalue = "NTSC"; break; - case STANDARD_SECAM_DK : returnvalue = "SECAM-DK"; break; - case STANDARD_SECAM : returnvalue = "SECAM"; break; - - case STANDARD_MN : returnvalue = "DK"; break; - case STANDARD_B : returnvalue = "B"; break; - case STANDARD_GH : returnvalue = "GH"; break; - case STANDARD_DK : returnvalue = "DK"; break; - - case STANDARD_525_60 : returnvalue = "525 lines 60Hz";break; - case STANDARD_625_50 : returnvalue = "625 lines 50Hz";break; - case STANDARD_ATSC : returnvalue = "ATSC"; break; - - case STANDARD_UNKNOWN : returnvalue = "Unknown"; break; - case STANDARD_ALL : returnvalue = "All"; break; - } - return returnvalue; -} - -QString VideoDevice::signalStandardName(int standard) -{ - QString returnvalue; - returnvalue = "None"; - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - switch(standard) - { - case V4L2_STD_PAL_B : returnvalue = signalStandardName(STANDARD_PAL_B); break; - case V4L2_STD_PAL_B1 : returnvalue = signalStandardName(STANDARD_PAL_B1); break; - case V4L2_STD_PAL_G : returnvalue = signalStandardName(STANDARD_PAL_G); break; - case V4L2_STD_PAL_H : returnvalue = signalStandardName(STANDARD_PAL_H); break; - case V4L2_STD_PAL_I : returnvalue = signalStandardName(STANDARD_PAL_I); break; - case V4L2_STD_PAL_D : returnvalue = signalStandardName(STANDARD_PAL_D); break; - case V4L2_STD_PAL_D1 : returnvalue = signalStandardName(STANDARD_PAL_D1); break; - case V4L2_STD_PAL_K : returnvalue = signalStandardName(STANDARD_PAL_K); break; - case V4L2_STD_PAL_M : returnvalue = signalStandardName(STANDARD_PAL_M); break; - case V4L2_STD_PAL_N : returnvalue = signalStandardName(STANDARD_PAL_N); break; - case V4L2_STD_PAL_Nc : returnvalue = signalStandardName(STANDARD_PAL_Nc); break; - case V4L2_STD_PAL_60 : returnvalue = signalStandardName(STANDARD_PAL_60); break; - case V4L2_STD_NTSC_M : returnvalue = signalStandardName(STANDARD_NTSC_M); break; - case V4L2_STD_NTSC_M_JP : returnvalue = signalStandardName(STANDARD_NTSC_M_JP); break; - case V4L2_STD_NTSC_443 : returnvalue = signalStandardName(STANDARD_NTSC_443); break; // Commented out because my videodev2.h header seems to not include this standard in struct __u64 v4l2_std_id - case V4L2_STD_NTSC_M_KR : returnvalue = signalStandardName(STANDARD_NTSC_M_KR); break; // Commented out because my videodev2.h header seems to not include this standard in struct __u64 v4l2_std_id - case V4L2_STD_SECAM_B : returnvalue = signalStandardName(STANDARD_SECAM_B); break; - case V4L2_STD_SECAM_D : returnvalue = signalStandardName(STANDARD_SECAM_D); break; - case V4L2_STD_SECAM_G : returnvalue = signalStandardName(STANDARD_SECAM_G); break; - case V4L2_STD_SECAM_H : returnvalue = signalStandardName(STANDARD_SECAM_H); break; - case V4L2_STD_SECAM_K : returnvalue = signalStandardName(STANDARD_SECAM_K); break; - case V4L2_STD_SECAM_K1 : returnvalue = signalStandardName(STANDARD_SECAM_K1); break; - case V4L2_STD_SECAM_L : returnvalue = signalStandardName(STANDARD_SECAM_L); break; - case V4L2_STD_SECAM_LC : returnvalue = signalStandardName(STANDARD_SECAM_LC); break; - - case V4L2_STD_ATSC_8_VSB: returnvalue = signalStandardName(STANDARD_ATSC_8_VSB);break; - case V4L2_STD_ATSC_16_VSB:returnvalue = signalStandardName(STANDARD_ATSC_16_VSB);break; - - case V4L2_STD_PAL_BG : returnvalue = signalStandardName(STANDARD_PAL_BG); break; - case V4L2_STD_PAL_DK : returnvalue = signalStandardName(STANDARD_PAL_DK); break; - case V4L2_STD_PAL : returnvalue = signalStandardName(STANDARD_PAL); break; - case V4L2_STD_NTSC : returnvalue = signalStandardName(STANDARD_NTSC); break; - case V4L2_STD_SECAM_DK : returnvalue = signalStandardName(STANDARD_SECAM_DK); break; - case V4L2_STD_SECAM : returnvalue = signalStandardName(STANDARD_SECAM); break; - - case V4L2_STD_MN : returnvalue = signalStandardName(STANDARD_MN); break; - case V4L2_STD_B : returnvalue = signalStandardName(STANDARD_B); break; - case V4L2_STD_GH : returnvalue = signalStandardName(STANDARD_GH); break; - case V4L2_STD_DK : returnvalue = signalStandardName(STANDARD_DK); break; - - case V4L2_STD_525_60 : returnvalue = signalStandardName(STANDARD_525_60); break; - case V4L2_STD_625_50 : returnvalue = signalStandardName(STANDARD_625_50); break; - case V4L2_STD_ATSC : returnvalue = signalStandardName(STANDARD_ATSC); break; - - case V4L2_STD_UNKNOWN : returnvalue = signalStandardName(STANDARD_UNKNOWN); break; - case V4L2_STD_ALL : returnvalue = signalStandardName(STANDARD_ALL); break; - } - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - switch(standard) - { - case VIDEO_MODE_PAL : returnvalue = signalStandardName(STANDARD_PAL); break; - case VIDEO_MODE_NTSC : returnvalue = signalStandardName(STANDARD_NTSC); break; - case VIDEO_MODE_SECAM : returnvalue = signalStandardName(STANDARD_SECAM); break; - case VIDEO_MODE_AUTO : returnvalue = signalStandardName(STANDARD_ALL); break; // It must be disabled until I find a correct way to handle those non-standard bttv modes -// case VIDEO_MODE_PAL_Nc : returnvalue = signalStandardName(STANDARD_PAL_Nc); break; // Undocumented value found to be compatible with V4L bttv driver - case VIDEO_MODE_PAL_M : returnvalue = signalStandardName(STANDARD_PAL_M); break; // Undocumented value found to be compatible with V4L bttv driver - case VIDEO_MODE_PAL_N : returnvalue = signalStandardName(STANDARD_PAL_N); break; // Undocumented value found to be compatible with V4L bttv driver - case VIDEO_MODE_NTSC_JP : returnvalue = signalStandardName(STANDARD_NTSC_M_JP); break; // Undocumented value found to be compatible with V4L bttv driver - } - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - break; - } - return returnvalue; -} - -/*! - \fn VideoDevice::detectSignalStandards() -// this must be done once for each _input_. - */ -int VideoDevice::detectSignalStandards() -{ - qDebug() << "called."; - if(isOpen()) - { - switch(m_driver) - { -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - case VIDEODEV_DRIVER_V4L2: - - - struct v4l2_input input; - struct v4l2_standard standard; - - memset (&input, 0, sizeof (input)); - - if (-1 == xioctl (VIDIOC_G_INPUT, &input.index)) { - perror ("VIDIOC_G_INPUT"); - return EXIT_FAILURE; - } - - if (-1 == xioctl (VIDIOC_ENUMINPUT, &input)) { - perror ("VIDIOC_ENUM_INPUT"); - return EXIT_FAILURE; - } - -// printf ("Current input %s supports:\n", input.name); - - memset (&standard, 0, sizeof (standard)); - standard.index = 0; - - while (0 == xioctl (VIDIOC_ENUMSTD, &standard)) { - if (standard.id & input.std) - { -// qDebug() << standard.name; - qDebug() << signalStandardName(standard.id) << " (" << standard.id << ")" << V4L2_STD_NTSC; - } - - standard.index++; - } - -/* EINVAL indicates the end of the enumeration, which cannot be - empty unless this device falls under the USB exception. */ - - if (errno != EINVAL || standard.index == 0) { - perror ("VIDIOC_ENUMSTD"); - return EXIT_FAILURE; - } - - - break; -#endif -#ifdef COMPILE_V4L1_CODE - case VIDEODEV_DRIVER_V4L: - break; -#endif //COMPILE_V4L1_CODE -#endif - case VIDEODEV_DRIVER_NONE: - default: - break; - } - //FIXME: return a real value - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - -/*! - \fn VideoDevice::initRead() - */ -int VideoDevice::initRead() -{ - /// @todo implement me - - qDebug() << "called."; - if(isOpen()) - { - m_rawbuffers.resize(1); - if (m_rawbuffers.size()==0) - { - fprintf (stderr, "Out of memory\n"); - return EXIT_FAILURE; - } - qDebug() << "m_buffer_size: " << m_buffer_size; - -// m_rawbuffers[0].pixelformat=m_pixelformat; - m_rawbuffers[0].length = m_buffer_size; - m_rawbuffers[0].start = (uchar *)malloc (m_buffer_size); - - if (!m_rawbuffers[0].start) - { - fprintf (stderr, "Out of memory\n"); - return EXIT_FAILURE; - } - qDebug() << "exited successfuly."; - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - - -/*! - \fn VideoDevice::initMmap() - */ -int VideoDevice::initMmap() -{ - /// @todo implement me -#define BUFFERS 2 - if(isOpen()) - { - qDebug() << full_filename << " Trying to MMAP"; -#ifdef V4L2_CAP_VIDEO_CAPTURE - struct v4l2_requestbuffers req; - - CLEAR (req); - - req.count = BUFFERS; - req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - req.memory = V4L2_MEMORY_MMAP; - - if (-1 == xioctl (VIDIOC_REQBUFS, &req)) - { - if (EINVAL == errno) - { - qDebug() << full_filename << " does not support memory mapping"; - return EXIT_FAILURE; - } - else - { - return errnoReturn ("VIDIOC_REQBUFS"); - } - } - - if (req.count < BUFFERS) - { - qDebug() << "Insufficient buffer memory on " << full_filename; - return EXIT_FAILURE; - } - - m_rawbuffers.resize(req.count); - - if (m_rawbuffers.size()==0) - { - qDebug() << "Out of memory"; - return EXIT_FAILURE; - } - - for (m_streambuffers = 0; m_streambuffers < req.count; ++m_streambuffers) - { - struct v4l2_buffer v4l2buffer; - - CLEAR (v4l2buffer); - - v4l2buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - v4l2buffer.memory = V4L2_MEMORY_MMAP; - v4l2buffer.index = m_streambuffers; - - if (-1 == xioctl (VIDIOC_QUERYBUF, &v4l2buffer)) - return errnoReturn ("VIDIOC_QUERYBUF"); - - m_rawbuffers[m_streambuffers].length = v4l2buffer.length; -#ifdef HAVE_LIBV4L2 - m_rawbuffers[m_streambuffers].start = (uchar *) v4l2_mmap (NULL /* start anywhere */, v4l2buffer.length, PROT_READ | PROT_WRITE /* required */, MAP_SHARED /* recommended */, descriptor, v4l2buffer.m.offset); -#else - m_rawbuffers[m_streambuffers].start = (uchar *) mmap (NULL /* start anywhere */, v4l2buffer.length, PROT_READ | PROT_WRITE /* required */, MAP_SHARED /* recommended */, descriptor, v4l2buffer.m.offset); -#endif - - if (MAP_FAILED == m_rawbuffers[m_streambuffers].start) - return errnoReturn ("mmap"); - } -#endif - m_currentbuffer.data.resize(m_rawbuffers[0].length); // Makes the imagesize.data buffer size equal to the rawbuffer size - qDebug() << full_filename << " m_currentbuffer.data.size(): " << m_currentbuffer.data.size(); - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - - -/*! - \fn VideoDevice::initUserptr() - */ -int VideoDevice::initUserptr() -{ - /// @todo implement me - if(isOpen()) - { -#ifdef V4L2_CAP_VIDEO_CAPTURE - struct v4l2_requestbuffers req; - - CLEAR (req); - - req.count = 2; - req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - req.memory = V4L2_MEMORY_USERPTR; - - if (-1 == xioctl (VIDIOC_REQBUFS, &req)) - { - if (EINVAL == errno) - { - qDebug() << full_filename << " does not support memory mapping"; - return EXIT_FAILURE; - } - else - { - return errnoReturn ("VIDIOC_REQBUFS"); - } - } - - m_rawbuffers.resize(4); - - if (m_rawbuffers.size()==0) - { - fprintf (stderr, "Out of memory\n"); - return EXIT_FAILURE; - } - - for (m_streambuffers = 0; m_streambuffers < 4; ++m_streambuffers) - { - m_rawbuffers[m_streambuffers].length = m_buffer_size; - m_rawbuffers[m_streambuffers].start = (uchar *) malloc (m_buffer_size); - - if (!m_rawbuffers[m_streambuffers].start) - { - qDebug() << "Out of memory"; - return EXIT_FAILURE; - } - } -#endif - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - -bool VideoDevice::canCapture() -{ - return m_videocapture; -} - -bool VideoDevice::canChromakey() -{ - return m_videochromakey; -} - -bool VideoDevice::canScale() -{ - return m_videoscale; -} - -bool VideoDevice::canOverlay() -{ - return m_videooverlay; -} - -bool VideoDevice::canRead() -{ - return m_videoread; -} - -bool VideoDevice::canAsyncIO() -{ - return m_videoasyncio; -} - -bool VideoDevice::canStream() -{ - return m_videostream; -} - -void VideoDevice::setUdi( const QString & udi ) -{ - m_udi = udi; -} - -QString VideoDevice::udi() const -{ - return m_udi; -} - - -#if !defined(COMPILE_DISABLE_AVDEVICE) && defined(V4L2_CAP_VIDEO_CAPTURE) -/*! - \fn const char * VideoDevice::getUnifiedV4L2StdCtrlName(quint32 std_ctrl_id) - \param std_ctrl_id ID of the V4L2 standard video control - \return The unified title of the V4L2 video control - \brief Returns a unified title of a V4L2-(standard-)video-control and makes it translatable - */ -const char *VideoDevice::getUnifiedV4L2StdCtrlName(quint32 std_ctrl_id) -{ - switch (std_ctrl_id) - { - /* USER controls */ - case V4L2_CID_BRIGHTNESS: return __tr("Brightness"); - case V4L2_CID_CONTRAST: return __tr("Contrast"); - case V4L2_CID_SATURATION: return __tr("Saturation"); - case V4L2_CID_HUE: return __tr("Hue"); - case V4L2_CID_AUDIO_VOLUME: return __tr("Volume"); - case V4L2_CID_AUDIO_BALANCE: return __tr("Balance"); - case V4L2_CID_AUDIO_BASS: return __tr("Bass"); - case V4L2_CID_AUDIO_TREBLE: return __tr("Treble"); - case V4L2_CID_AUDIO_MUTE: return __tr("Mute"); - case V4L2_CID_AUDIO_LOUDNESS: return __tr("Loudness"); - case V4L2_CID_BLACK_LEVEL: return __tr("Black Level"); - case V4L2_CID_AUTO_WHITE_BALANCE: return __tr("Automatic White Balance"); - case V4L2_CID_DO_WHITE_BALANCE: return __tr("Do White Balance"); - case V4L2_CID_RED_BALANCE: return __tr("Red Balance"); - case V4L2_CID_BLUE_BALANCE: return __tr("Blue Balance"); - case V4L2_CID_GAMMA: return __tr("Gamma"); - case V4L2_CID_EXPOSURE: return __tr("Exposure"); - case V4L2_CID_AUTOGAIN: return __tr("Automatic Gain"); - case V4L2_CID_GAIN: return __tr("Gain"); - case V4L2_CID_HFLIP: return __tr("Horizontal Flip"); - case V4L2_CID_VFLIP: return __tr("Vertical Flip"); - case V4L2_CID_HCENTER: return __tr("Horizontal Center"); - case V4L2_CID_VCENTER: return __tr("Vertical Center"); -#ifdef V4L2_CID_POWER_LINE_FREQUENCY // since kernel 2.6.25 - case V4L2_CID_POWER_LINE_FREQUENCY: return __tr("Power Line Frequency"); - case V4L2_CID_HUE_AUTO: return __tr("Automatic Hue"); - case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return __tr("White Balance Temperature"); - case V4L2_CID_SHARPNESS: return __tr("Sharpness"); - case V4L2_CID_BACKLIGHT_COMPENSATION: return __tr("Backlight Compensation"); -#endif -#ifdef V4L2_CID_CHROMA_AGC // since kernel 2.6.26 - case V4L2_CID_CHROMA_AGC: return __tr("Chroma AGC"); - case V4L2_CID_COLOR_KILLER: return __tr("Color Killer"); -#endif -#ifdef V4L2_CID_COLORFX // since kernel 2.6.30 - case V4L2_CID_COLORFX: return __tr("Color Effects"); -#endif -#ifdef V4L2_CID_ROTATE // since kernel 2.6.33 - case V4L2_CID_ROTATE: return __tr("Rotate"); - case V4L2_CID_BG_COLOR: return __tr("Background color"); -#endif - default: - return NULL; - } - /* NOTE: Unification is necessary for translation, because drivers use individual descriptions - (different uppercase/lowercase combinations but also some strange interpretations). - Otherwise we would end up with too many different (or even untranslated !)strings. - */ - /* NOTE: We only mark the strings for translation, the translation is done for ALL controls - (including custom controls) at a common place - */ -} -#endif - -} - -} diff --git a/src/kvilib/ext/avdevice/videodevice.h b/src/kvilib/ext/avdevice/videodevice.h deleted file mode 100644 index cc6f91122..000000000 --- a/src/kvilib/ext/avdevice/videodevice.h +++ /dev/null @@ -1,440 +0,0 @@ -//============================================================================= -// -// File : videodevice.h -// Creation date : Tue Nov 10 18:08:09 2009 GMT by Fabio Bas -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 file has been taken from the "Kopete, The KDE Instant Messenger" -// sourcecode. Original copyright of the file follows: -//============================================================================= - -/* - videodevice.h - Kopete Video Device Low-level Support - - Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com> - Copyright (c) 2010 by Frank Schaefer <fschaefer.oss@googlemail.com> - - Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> - - ************************************************************************* - * * - * 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 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef KOPETE_AVVIDEODEVICELISTITEM_H -#define KOPETE_AVVIDEODEVICELISTITEM_H - -#include <sys/time.h> -#include <sys/mman.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <signal.h> - -#include "kvi_settings.h" - -#ifndef COMPILE_DISABLE_AVDEVICE - -#include <asm/types.h> -#undef __STRICT_ANSI__ -#ifndef __u64 //required by videodev.h -#define __u64 unsigned long long -#endif // __u64 -#ifndef __s64 //required by videodev.h -#define __s64 signed long long -#endif // __s64 - - -#ifndef pgoff_t -#define pgoff_t unsigned long -#endif - -#include <linux/fs.h> -#include <linux/kernel.h> -#ifdef COMPILE_V4L1_CODE - #include <linux/videodev.h> -#else - #include <linux/videodev2.h> -#endif -#define VIDEO_MODE_PAL_Nc 3 -#define VIDEO_MODE_PAL_M 4 -#define VIDEO_MODE_PAL_N 5 -#define VIDEO_MODE_NTSC_JP 6 -#define __STRICT_ANSI__ - -#ifdef HAVE_LIBV4L2 -#include <libv4l2.h> -#endif // HAVE_V4L2 - -#endif // __linux__ - -#include <QString> -#include <QStringList> -#include <QFile> -#include <QImage> - -#include "videoinput.h" - -namespace Kopete { - -namespace AV { - -/** -@author Kopete Developers -*/ -typedef enum -{ - VIDEODEV_DRIVER_NONE -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef COMPILE_V4L1_CODE - , - VIDEODEV_DRIVER_V4L -#endif //COMPILE_V4L1_CODE -#ifdef V4L2_CAP_VIDEO_CAPTURE - , - VIDEODEV_DRIVER_V4L2 -#endif -#endif -} videodev_driver; - -typedef enum -{ -// Packed RGB formats - PIXELFORMAT_NONE = 0, - PIXELFORMAT_GREY = (1 << 0), - PIXELFORMAT_RGB332 = (1 << 1), - PIXELFORMAT_RGB444 = (1 << 2), - PIXELFORMAT_RGB555 = (1 << 3), - PIXELFORMAT_RGB565 = (1 << 4), - PIXELFORMAT_RGB555X = (1 << 5), - PIXELFORMAT_RGB565X = (1 << 6), - PIXELFORMAT_BGR24 = (1 << 7), - PIXELFORMAT_RGB24 = (1 << 8), - PIXELFORMAT_BGR32 = (1 << 9), - PIXELFORMAT_RGB32 = (1 << 10), - -// Bayer RGB format - PIXELFORMAT_SBGGR8 = (1 << 11), - -// YUV formats - PIXELFORMAT_YUYV = (1 << 12), - PIXELFORMAT_UYVY = (1 << 13), - PIXELFORMAT_YUV420P = (1 << 14), - PIXELFORMAT_YUV422P = (1 << 15), - -// Compressed formats - PIXELFORMAT_JPEG = (1 << 16), - PIXELFORMAT_MPEG = (1 << 17), - -// Reserved formats - PIXELFORMAT_DV = (1 << 18), - PIXELFORMAT_ET61X251 = (1 << 19), - PIXELFORMAT_HI240 = (1 << 20), - PIXELFORMAT_HM12 = (1 << 21), - PIXELFORMAT_MJPEG = (1 << 22), - PIXELFORMAT_PWC1 = (1 << 23), - PIXELFORMAT_PWC2 = (1 << 24), - PIXELFORMAT_SN9C10X = (1 << 25), - PIXELFORMAT_WNVA = (1 << 26), - PIXELFORMAT_YYUV = (1 << 27) - -// PIXELFORMAT_ALL = 0x00003FFF -} pixel_format; - -typedef enum -{ -// One bit for each - STANDARD_PAL_B = (1 << 0), - STANDARD_PAL_B1 = (1 << 1), - STANDARD_PAL_G = (1 << 2), - STANDARD_PAL_H = (1 << 3), - STANDARD_PAL_I = (1 << 4), - STANDARD_PAL_D = (1 << 5), - STANDARD_PAL_D1 = (1 << 6), - STANDARD_PAL_K = (1 << 7), - - STANDARD_PAL_M = (1 << 8), - STANDARD_PAL_N = (1 << 9), - STANDARD_PAL_Nc = (1 << 10), - STANDARD_PAL_60 = (1 << 11), -// STANDARD_PAL_60 is a hybrid standard with 525 lines, 60 Hz refresh rate, and PAL color modulation with a 4.43 MHz color subcarrier. Some PAL video recorders can play back NTSC tapes in this mode for display on a 50/60 Hz agnostic PAL TV. - - STANDARD_NTSC_M = (1 << 12), - STANDARD_NTSC_M_JP = (1 << 13), - STANDARD_NTSC_443 = (1 << 14), -// STANDARD_NTSC_443 is a hybrid standard with 525 lines, 60 Hz refresh rate, and NTSC color modulation with a 4.43 MHz color subcarrier. - STANDARD_NTSC_M_KR = (1 << 15), - - STANDARD_SECAM_B = (1 << 16), - STANDARD_SECAM_D = (1 << 17), - STANDARD_SECAM_G = (1 << 18), - STANDARD_SECAM_H = (1 << 19), - STANDARD_SECAM_K = (1 << 20), - STANDARD_SECAM_K1 = (1 << 21), - STANDARD_SECAM_L = (1 << 22), - STANDARD_SECAM_LC = (1 << 23), - -// ATSC/HDTV - STANDARD_ATSC_8_VSB = (1 << 24), - STANDARD_ATSC_16_VSB = (1 << 25), - -// Some common needed stuff - STANDARD_PAL_BG = ( STANDARD_PAL_B | STANDARD_PAL_B1 | STANDARD_PAL_G ), - STANDARD_PAL_DK = ( STANDARD_PAL_D | STANDARD_PAL_D1 | STANDARD_PAL_K ), - STANDARD_PAL = ( STANDARD_PAL_BG | STANDARD_PAL_DK | STANDARD_PAL_H | STANDARD_PAL_I ), - STANDARD_NTSC = ( STANDARD_NTSC_M | STANDARD_NTSC_M_JP| STANDARD_NTSC_M_KR ), - STANDARD_SECAM_DK = ( STANDARD_SECAM_D | STANDARD_SECAM_K | STANDARD_SECAM_K1 ), - STANDARD_SECAM = ( STANDARD_SECAM_B | STANDARD_SECAM_G | STANDARD_SECAM_H | STANDARD_SECAM_DK | STANDARD_SECAM_L | STANDARD_SECAM_LC ), - -// some merged standards */ - STANDARD_MN = ( STANDARD_PAL_M | STANDARD_PAL_N | STANDARD_PAL_Nc | STANDARD_NTSC ), - STANDARD_B = ( STANDARD_PAL_B | STANDARD_PAL_B1 | STANDARD_SECAM_B ), - STANDARD_GH = ( STANDARD_PAL_G | STANDARD_PAL_H | STANDARD_SECAM_G | STANDARD_SECAM_H ), - STANDARD_DK = ( STANDARD_PAL_DK | STANDARD_SECAM_DK ), - - STANDARD_525_60 = ( STANDARD_PAL_M | STANDARD_PAL_60 | STANDARD_NTSC | STANDARD_NTSC_443), - STANDARD_625_50 = ( STANDARD_PAL | STANDARD_PAL_N | STANDARD_PAL_Nc | STANDARD_SECAM), - STANDARD_ATSC = ( STANDARD_ATSC_8_VSB | STANDARD_ATSC_16_VSB ), - - STANDARD_UNKNOWN = 0, - STANDARD_ALL = ( STANDARD_525_60 | STANDARD_625_50) -} signal_standard; - -typedef enum -{ - IO_METHOD_NONE, - IO_METHOD_READ, - IO_METHOD_MMAP, - IO_METHOD_USERPTR -} io_method; - -struct imagebuffer -{ - int height; - int width; - pixel_format pixelformat; - QVector <uchar> data; // maybe it should be a rawbuffer instead of it? It could make us avoid a memory copy -}; - -struct rawbuffer // raw buffer -{ - uchar * start; - size_t length; -}; - - -/*! - \class ActionVideoControl - Data structure for action-video-controls -*/ -class ActionVideoControl -{ -public: - quint32 id; /*!< The ID of the control */ - QString name; /*!< The name/title of the control */ -}; - -/*! - \class BooleanVideoControl - Data structure for boolean video-controls -*/ -class BooleanVideoControl : public ActionVideoControl -{ -public: - qint32 value_default; /*!< The default value for the control */ -}; - -/*! - \class NumericVideoControl - Data structure for numeric video-controls -*/ -class NumericVideoControl : public BooleanVideoControl -{ -public: - qint32 value_min; /*!< The minimum value for the control */ - qint32 value_max; /*!< The maximum value allowed for the control */ - qint32 value_step; /*!< The step-size which has to be considered when changing the value of the control */ -}; - -/*! - \class MenuVideoControl - Data structure for menu-video-controls -*/ -class MenuVideoControl : public ActionVideoControl -{ -public: - qint32 index_default; /*!< The index of the default option for this control */ - QStringList options; /*!< The list of options provided by the control */ -}; - - - -class VideoDevice{ -public: - VideoDevice(); - virtual ~VideoDevice(); - int setFileName(QString filename); - QString fileName(); - void setUdi( const QString & ); - QString udi() const; - virtual int open(); - virtual bool isOpen(); - - int showDeviceCapabilities(); - - int width(); - int minWidth(); - int maxWidth(); - int height(); - int minHeight(); - int maxHeight(); - virtual int setSize( int newwidth, int newheight); - - virtual pixel_format setPixelFormat(pixel_format newformat); - int pixelFormatCode(pixel_format pixelformat); - pixel_format pixelFormatForPalette( int palette ); - int pixelFormatDepth(pixel_format pixelformat); - QString pixelFormatName(pixel_format pixelformat); - QString pixelFormatName(int pixelformat); - int detectPixelFormats(); - - __u64 signalStandardCode(signal_standard standard); - QString signalStandardName(signal_standard standard); - QString signalStandardName(int standard); - int detectSignalStandards(); - - int inputs(); - int currentInput(); - int selectInput(int input); - - virtual int startCapturing(); - virtual int getFrame(); - virtual int getFrame(imagebuffer *imgbuffer); - virtual int getImage(QImage *qimage); - virtual int stopCapturing(); - virtual int close(); - - QList<NumericVideoControl> getSupportedNumericControls(); - QList<BooleanVideoControl> getSupportedBooleanControls(); - QList<MenuVideoControl> getSupportedMenuControls(); - QList<ActionVideoControl> getSupportedActionControls(); - - int getControlValue(quint32 ctrl_id, qint32 * value); - int setControlValue(quint32 ctrl_id, qint32 value); - - bool canCapture(); - bool canChromakey(); - bool canScale(); - bool canOverlay(); - bool canRead(); - bool canAsyncIO(); - bool canStream(); - - QString m_name; - QVector<Kopete::AV::VideoInput> m_input; - -protected: -#ifndef COMPILE_DISABLE_AVDEVICE - /*! - \enum VideoDevice::imgctrl_id Control-IDs used for V4L1- and software-controls - */ - typedef enum - { - IMGCTRL_ID_V4L1_BRIGHTNESS, - IMGCTRL_ID_V4L1_HUE, - IMGCTRL_ID_V4L1_COLOR, - IMGCTRL_ID_V4L1_CONTRAST, - IMGCTRL_ID_V4L1_WHITENESS, - IMGCTRL_ID_SOFT_AUTOBRIGHTNESSCONTRASTCORR, - IMGCTRL_ID_SOFT_AUTOCOLORCORR, - IMGCTRL_ID_SOFT_VFLIP, - IMGCTRL_ID_SOFT_HFLIP - } imgctrl_id; - /* NOTE: V4L2_CID_BASE = 0x980900 */ -#endif - - QList<NumericVideoControl> m_numericCtrls; /*!< Supported muneric controls for the current input */ - QList<BooleanVideoControl> m_booleanCtrls; /*!< Supported boolean controls for the current input */ - QList<MenuVideoControl> m_menuCtrls; /*!< Supported menu-controls for the current input */ - QList<ActionVideoControl> m_actionCtrls; /*!< Supported action-controls for the current input */ - - QString full_filename; - QString m_udi; - int descriptor; - videodev_driver m_driver; - QString m_model; -#ifndef COMPILE_DISABLE_AVDEVICE -#ifdef V4L2_CAP_VIDEO_CAPTURE - struct v4l2_capability V4L2_capabilities; - struct v4l2_format fmt; -// struct v4l2_input m_input; -#endif -#ifdef COMPILE_V4L1_CODE - struct video_capability V4L_capabilities; - struct video_buffer V4L_videobuffer; -#endif -#endif - int currentwidth, minwidth, maxwidth, currentheight, minheight, maxheight; - - QVector<rawbuffer> m_rawbuffers; - unsigned int m_streambuffers; - imagebuffer m_currentbuffer; - int m_buffer_size; - - int m_current_input; - pixel_format m_pixelformat; - - io_method m_io_method; - bool m_videocapture; - bool m_videochromakey; - bool m_videoscale; - bool m_videooverlay; - bool m_videoread; - bool m_videoasyncio; - bool m_videostream; - - virtual int checkDevice(); - virtual int initDevice(); - - void setupControls(); -#if !defined(COMPILE_DISABLE_AVDEVICE) && defined(V4L2_CAP_VIDEO_CAPTURE) - bool getMenuCtrlOptions(quint32 id, quint32 maxindex, QStringList * options); - void saveV4L2ControlData(struct v4l2_queryctrl qctrl); - const char *getUnifiedV4L2StdCtrlName(quint32 std_ctrl_id); -#endif - int xioctl(int request, void *arg); - int errnoReturn(const char* s); - int initRead(); - int initMmap(); - int initUserptr(); - -}; - -} - -} - -#endif diff --git a/src/kvilib/ext/avdevice/videodevicepool.cpp b/src/kvilib/ext/avdevice/videodevicepool.cpp deleted file mode 100644 index fdf58719e..000000000 --- a/src/kvilib/ext/avdevice/videodevicepool.cpp +++ /dev/null @@ -1,886 +0,0 @@ -/* - videodevicepool.cpp - Kopete Video Device Low-level Support - - Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com> - Copyright (c) 2010 by Frank Schaefer <fschaefer.oss@googlemail.com> - - Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> - - ************************************************************************* - * * - * 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 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#define ENABLE_AV - -#include <assert.h> -#include <cstdlib> -#include <cerrno> -#include <cstring> - -#include <QDir> -#include <QDebug> - -#include "videodevice.h" -#include "videodevicepool.h" - -#ifdef COMPILE_KDE_SUPPORT - #include <klocale.h> - #include <kglobal.h> - #include <kconfig.h> - #include <kconfiggroup.h> - #include <solid/devicenotifier.h> - #include <solid/deviceinterface.h> - #include <solid/video.h> -#endif - -#define CLEAR(x) memset (&(x), 0, sizeof (x)) - -namespace Kopete { - -namespace AV { - -VideoDevicePool *VideoDevicePool::s_self = NULL; -__u64 VideoDevicePool::m_clients = 0; - -/*! - \fn VideoDevicePool* VideoDevicePool::self() - \return Pointer to the VideoDevicePool object - \brief Returns pointer to a common instance of the VideoDevicePool - */ -VideoDevicePool* VideoDevicePool::self() -{ - qDebug() << "called"; - if (s_self == NULL) - { - qDebug() << "Generated new instance."; - s_self = new VideoDevicePool; - if (s_self) - m_clients = 0; - } - return s_self; -} - -/*! - \fn VideoDevicePool::VideoDevicePool() - \brief Constructor of class VideoDevicePool - */ -VideoDevicePool::VideoDevicePool() -: m_current_device(-1) -{ -#ifdef COMPILE_KDE_SUPPORT - connect( Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(const QString&)), SLOT(deviceAdded(const QString &)) ); - connect( Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(const QString&)), SLOT(deviceRemoved(const QString &)) ); - /* NOTE: No locking needed as long as we don't connect with Qt::ConnectionType = Qt::DirectConnection - while the signals are emitted by other threads - */ - foreach( Solid::Device device, Solid::Device::listFromType(Solid::DeviceInterface::Video, QString()) ) - registerDevice( device ); -#endif -} - -/*! - \fn VideoDevicePool::~VideoDevicePool() - \brief Destructor of class VideoDevicePool - */ -VideoDevicePool::~VideoDevicePool() -{ - foreach ( VideoDevice* vd, m_videodevices ) - delete vd; -} - - - -/*! - \fn bool VideoDevicePool::isOpen() - \return True if the device is open, false otherwise - \brief Returns true if the currently selected device is open and false othwerise - */ -bool VideoDevicePool::isOpen() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->isOpen(); - else - return false; -} - -/*! - \fn int VideoDevicePool::open( int device ) - \param device Index of the device that should be opened. - If a negative index is passed (default), the default device will be opened, - which is either the saved device (if available) or alternatively the device with index 0. - \return The result-code, EXIT_SUCCESS or EXIT_FAILURE - \brief Opens the video device with the specified index. The previously opened device is closed before. - */ -int VideoDevicePool::open( int device ) -{ - qDebug() << "called with device" << device; - if (!m_videodevices.size() || (device >= m_videodevices.size())) - { - qDebug() << "Device not found."; - return EXIT_FAILURE; - } - if (device < 0) - { - qDebug() << "Trying to load saved device."; - device = getSavedDevice(); - if (device < 0) - { - if (m_current_device < 0) - device = 0; - else - device = m_current_device; - qDebug() << "Saved device is not available, using default device:" << device; - } - } - int isopen = EXIT_FAILURE; - if ((device != m_current_device) || !isOpen()) - { - if (isOpen()) - { - if (EXIT_SUCCESS == m_videodevices[m_current_device]->close()) - m_clients--; - else - return EXIT_FAILURE; - } - isopen = m_videodevices[device]->open(); - if (isopen == EXIT_SUCCESS) - { - m_current_device = device; - loadDeviceConfig(); // Load and apply device parameters - m_clients++; - } - } - else - { - isopen = EXIT_SUCCESS; - m_clients++; - } - qDebug() << "Number of clients: " << m_clients; - return isopen; -} - -/*! - \fn int VideoDevicePool::close() - \return The success of the operation: EXIT_SUCCESS or EXIT_FAILURE - \brief Closes the device - */ -int VideoDevicePool::close() -{ - int ret = EXIT_FAILURE; - if ((m_current_device < 0) || (m_current_device >= m_videodevices.size())) - { - qDebug() << "Current device out of range."; - } - else if (!m_clients) - { - ret = EXIT_SUCCESS; - } - else if (m_clients > 1) - { - m_clients--; - qDebug() << "The video device is still in use:" << m_clients << "clients"; - ret = EXIT_SUCCESS; - } - else - { - ret = m_videodevices[m_current_device]->close(); - if (EXIT_SUCCESS == ret) - m_clients--; - } - return ret; -} - - - -/*! - \fn int VideoDevicePool::size() - \return The number of available video devices - \brief Returns the number of available video devices - */ -int VideoDevicePool::size() -{ - return m_videodevices.size(); -} - -/*! - \fn int VideoDevicePool::currentDevice() - \return The index of the current device or -1 if no device available - \brief Returns the index of the current device - */ -int VideoDevicePool::currentDevice() -{ - if (m_videodevices.size()) - return m_current_device; - else // to be sure... - return -1; -} - -/*! - \fn QString Kopete::AV::VideoDevicePool::currentDeviceUdi() - \return The unique device identifier (UDI) of the currently selected device - \brief Returns the unique device identifier (UDI) of the currently selected device - */ -QString VideoDevicePool::currentDeviceUdi() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->udi(); - else - return QString(); -} - -/*! - \fn int VideoDevicePool::inputs() - \return The number of inputs of the currently selected device - \brief Returns the number of available inputs of the currently selected device - */ -int VideoDevicePool::inputs() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->inputs(); - else - return 0; -} - -/*! - \fn int VideoDevicePool::currentInput() - \return The index of the currently selected input or -1, if no input is available - \brief Returns the index of the currently selected input - */ -int VideoDevicePool::currentInput() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->currentInput(); - else - return -1; -} - -/*! - \fn int VideoDevicePool::selectInput( int input ) - \param input Index of input to be selected - \return The result-code, EXIT_SUCCESS or EXIT_FAILURE - \brief Selects the input of the current video device - */ -int VideoDevicePool::selectInput( int input ) -{ - qDebug() << "called with input" << input; - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->selectInput(input); - else - return EXIT_FAILURE; -} - - - -/*! - \fn QList<NumericVideoControl> VideoDevicePool::getSupportedNumericControls() - \return A list of all supported numeric controls for the current input - \brief Returns the supported numeric controls for the current input - */ -QList<NumericVideoControl> VideoDevicePool::getSupportedNumericControls() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->getSupportedNumericControls(); - else - return QList<NumericVideoControl>(); -} - -/*! - \fn QList<BooleanVideoControl> VideoDevicePool::getSupportedBooleanControls() - \return A list of all supported boolean controls for the current input - \brief Returns the supported boolean controls for the current input - */ -QList<BooleanVideoControl> VideoDevicePool::getSupportedBooleanControls() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->getSupportedBooleanControls(); - else - return QList<BooleanVideoControl>(); -} - -/*! - \fn QList<MenuVideoControl> VideoDevicePool::getSupportedMenuControls() - \return A list of all supported menu-controls for the current input - \brief Returns the supported menu-controls for the current input - */ -QList<MenuVideoControl> VideoDevicePool::getSupportedMenuControls() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->getSupportedMenuControls(); - else - return QList<MenuVideoControl>(); -} - -/*! - \fn QList<ActionVideoControl> VideoDevicePool::getSupportedActionControls() - \return A list of all supported action-controls for the current input - \brief Returns the supported action-controls for the current input - */ -QList<ActionVideoControl> VideoDevicePool::getSupportedActionControls() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->getSupportedActionControls(); - else - return QList<ActionVideoControl>(); -} - -/*! - \fn int VideoDevicePool::getControlValue( quint32 ctrl_id, qint32 * value ) - \param ctrl_id ID of the video-control - \param value Pointer to the variable, which recieves the value of the querried video-control. - For boolean controls, the value is 0 or 1. - For menu-controls, the value is the index of the currently selected option. - \return The result-code, currently EXIT_SUCCESS or EXIT_FAILURE - \brief Reads the value of a video-control - */ -int VideoDevicePool::getControlValue( quint32 ctrl_id, qint32 * value ) -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->getControlValue(ctrl_id, value); - else - return EXIT_FAILURE; -} - -/*! - \fn int VideoDevicePool::setControlValue( quint32 ctrl_id, qint32 value ) - \param ctrl_id ID of the video-control - \param value The value that should be set. - For boolean controls, the value must be 0 or 1. - For menu-controls, the value must be the index of the option. - For action-controls, the value is ignored. - \return The result-code, currently EXIT_SUCCESS or EXIT_FAILURE - \brief Sets the value of a video-control - */ -int VideoDevicePool::setControlValue( quint32 ctrl_id, qint32 value ) -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->setControlValue(ctrl_id, value); - else - return EXIT_FAILURE; -} - - - -/*! - \fn int VideoDevicePool::startCapturing() - \return The result-code, EXIT_SUCCESS or EXIT_FAILURE - \brief Starts capturing from the currently selected video device - */ -int VideoDevicePool::startCapturing() -{ - qDebug() << "startCapturing() called."; - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->startCapturing(); - else - return EXIT_FAILURE; -} - - -/*! - \fn int VideoDevicePool::stopCapturing() - \return The result-code, EXIT_SUCCESS or EXIT_FAILURE - \brief Starts capturing from the currently selected video device - */ -int VideoDevicePool::stopCapturing() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->stopCapturing(); - else - return EXIT_FAILURE; -} - -/*! - \fn VideoDevicePool::getFrame() - */ -int VideoDevicePool::getFrame() -{ -// qDebug() << "VideoDevicePool::getFrame() called."; - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->getFrame(); - else - return EXIT_FAILURE; -} - -/*! - \fn VideoDevicePool::getImage( QImage *qimage ) - */ -int VideoDevicePool::getImage( QImage *qimage ) -{ -// qDebug() << "VideoDevicePool::getImage() called."; - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->getImage(qimage); - else - return EXIT_FAILURE; -} - - - -int VideoDevicePool::width() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->width(); - else - return 0; -} - -int VideoDevicePool::minWidth() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->minWidth(); - else - return 0; -} - -int VideoDevicePool::maxWidth() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->maxWidth(); - else - return 0; -} - -int VideoDevicePool::height() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->height(); - else - return 0; -} - -int VideoDevicePool::minHeight() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->minHeight(); - else - return 0; -} - -int VideoDevicePool::maxHeight() -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->maxHeight(); - else - return 0; -} - -int VideoDevicePool::setImageSize( int newwidth, int newheight ) -{ - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - return m_videodevices[m_current_device]->setSize(newwidth, newheight); - else - return EXIT_FAILURE; -} - - - -/*! - \fn void VideoDevicePool::fillDeviceKComboBox( KComboBox *combobox ) - \param combobox Pointer to a KComboBox object - \brief Fills a combobox with the names of all available video devices - */ -void VideoDevicePool::fillDeviceQComboBox(QComboBox *combobox) -{ - qDebug() << "Called."; - if (combobox == NULL) - return; - combobox->clear(); - if (m_videodevices.size()) - { - for (int loop = 0; loop < m_videodevices.size(); loop++) - { - combobox->addItem(m_videodevices[loop]->m_name); - qDebug() << "Added device" << loop << ": " << m_videodevices[loop]->m_name; - } - combobox->setCurrentIndex(m_current_device); - } - combobox->setEnabled(m_videodevices.size()); -} - -/*! - \fn void VideoDevicePool::fillInputKComboBox( KComboBox *combobox ) - \param combobox Pointer to a KComboBox object - \brief Fills a combobox with the names of all available inputs for the currently selected device - */ -void VideoDevicePool::fillInputQComboBox(QComboBox *combobox) -{ - qDebug() << "Called."; - if (combobox == NULL) - return; - combobox->clear(); - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - { - if (m_videodevices[m_current_device]->inputs() > 0) - { - for (int loop = 0; loop < m_videodevices[m_current_device]->inputs(); loop++) - { - combobox->addItem(m_videodevices[m_current_device]->m_input[loop].name); - qDebug() << "Added input" << loop << ": " << m_videodevices[m_current_device]->m_input[loop].name - << " (tuner: " << m_videodevices[m_current_device]->m_input[loop].hastuner << ")"; - } - combobox->setCurrentIndex(m_videodevices[m_current_device]->currentInput()); - } - } - combobox->setEnabled(combobox->count()); -} - -/*! - \fn void VideoDevicePool::fillStandardKComboBox( KComboBox *combobox ) - \param combobox Pointer to a KComboBox object - \brief Fills a combobox with the names of the available signal standards for the currently selected device - */ -void VideoDevicePool::fillStandardQComboBox(QComboBox *combobox) -{ - qDebug() << "Called."; - if (combobox == NULL) - return; - combobox->clear(); - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - { - if (m_videodevices[m_current_device]->inputs() > 0) - { - for (unsigned int loop = 0; loop < 25; loop++) - { - if (m_videodevices[m_current_device]->m_input[currentInput()].m_standards & (1 << loop)) - { - combobox->addItem(m_videodevices[m_current_device]->signalStandardName(1 << loop)); - qDebug() << "Added signal standard" << loop << ": " << m_videodevices[m_current_device]->signalStandardName(1 << loop); - } - - } - combobox->setCurrentIndex(0); // FIXME: set to actual signal standard - } - } - combobox->setEnabled(combobox->count()); -} - - - -/*! - \fn int VideoDevicePool::getSavedDevice() - \return The index of the saved device or -1, if the saved device is not available - \brief Returns the index of the saved device - */ -int VideoDevicePool::getSavedDevice() -{ -#ifdef COMPILE_KDE_SUPPORT - qDebug() << "called"; - if (m_videodevices.size()) - { - KConfigGroup config(KGlobal::config(), "Video Device Settings"); - QString currentdevice = config.readEntry("Current Device", QString()); - qDebug() << "Device name:" << config.readEntry( QString::fromLocal8Bit( "Device %1 Name" ).arg( currentdevice ), QString("NOT SAVED") ); - if (!currentdevice.isEmpty()) - { - qDebug() << "Saved device:" << currentdevice; - QVector<VideoDevice*>::iterator vditerator; - for( vditerator = m_videodevices.begin(); vditerator != m_videodevices.end(); ++vditerator ) - { - if ((*vditerator)->udi() == currentdevice) - { - int devIndex = std::distance (m_videodevices.begin(), vditerator); - qDebug() << "Saved device is available, device index is" << devIndex; - return devIndex; - } - } - qDebug() << "Saved device is not available."; - } - else - qDebug() << "No device saved."; - } -#endif - return -1; -} - -/*! - \fn void VideoDevicePool::loadDeviceConfig() - \brief Loads and applies the configuration for the currently selected device - - Loads the input and the values for all video-controls and applies them. - */ -void VideoDevicePool::loadDeviceConfig() -{ -#ifdef COMPILE_KDE_SUPPORT - qDebug() << "called"; - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - { - KConfigGroup config(KGlobal::config(), "Video Device Settings"); - // Load input and apply - const QString key_currentinput = QString::fromLocal8Bit( "Device %1 Current Input" ).arg( m_videodevices[m_current_device]->udi() ); - const int currentinput = config.readEntry(key_currentinput, 0); - qDebug() << "Setting input to" << currentinput; - if (currentinput != m_videodevices[m_current_device]->currentInput()) - m_videodevices[m_current_device]->selectInput(currentinput); - // Load video-controls and apply - quint32 ctrl_id; - qint32 ctrl_value; - QString ctrl_key; - bool ok = false; - const QString key_control_start = QString::fromLocal8Bit( "Device %1 Input %2 Control " ).arg( m_videodevices[m_current_device]->udi() ).arg( m_videodevices[m_current_device]->currentInput() ); - QStringList ctrl_keys = config.keyList().filter(key_control_start); - qDebug() << "Found" << ctrl_keys.size() << "saved values for video-controls"; - foreach (ctrl_key, ctrl_keys) - { - ctrl_id = QString(ctrl_key).remove(key_control_start).toUInt(&ok); - if (ok) - { - /* NOTE: we do not read the value as int with readEntry() directly - because it doesn't tell us if the saved value was valid. - If not, we do NOT apply a standard value. - */ - QString tmpstr = config.readEntry(ctrl_key, QString()); - ctrl_value = tmpstr.toInt(&ok); - if (ok && !tmpstr.isEmpty()) - { - qDebug() << "Setting control" << ctrl_id << "to value" << ctrl_value; - m_videodevices[m_current_device]->setControlValue(ctrl_id, ctrl_value); - } - else - qDebug() << "Saved value for control" << ctrl_id << "is invalid:" << tmpstr; - } - else - qDebug() << "Invalid key:" << ctrl_key; - } - } - /* TODO: load and apply signal standard */ -#endif -} - -/*! - \fn void VideoDevicePool::saveCurrentDeviceConfig() - \brief Saves the current device configuration - - Saves the current device, the current input and the current values for all supported video-controls. - */ -void VideoDevicePool::saveCurrentDeviceConfig() -{ -#ifdef COMPILE_KDE_SUPPORT - qDebug() << "called"; - if ((m_current_device >= 0) && (m_current_device < m_videodevices.size())) - { - KConfigGroup config(KGlobal::config(), "Video Device Settings"); - // Save current device: - qDebug() << "Current device:" << m_videodevices[m_current_device]->udi(); - config.writeEntry( "Current Device", m_videodevices[m_current_device]->udi() ); - // Save current device name (for debugging only): - qDebug() << "Current device name:" << m_videodevices[m_current_device]->m_name; - const QString name = QString::fromLocal8Bit( "Device %1 Name" ).arg( m_videodevices[m_current_device]->udi() ); - config.writeEntry( name, m_videodevices[m_current_device]->m_name ); - // Open device if closed: - bool wasClosed = false; - if (!m_videodevices[m_current_device]->isOpen()) - { - qDebug() << "Device is currently closed, will be opened."; - wasClosed = true; - if (EXIT_SUCCESS != m_videodevices[m_current_device]->open()) - { - qDebug() << "Failed to open the device. Saving aborted."; - config.sync(); - return; - } - } - // Save current input: - qDebug() << "Current input:" << m_videodevices[m_current_device]->currentInput(); - const QString key_currentinput = QString::fromLocal8Bit( "Device %1 Current Input" ).arg( m_videodevices[m_current_device]->udi() ); - config.writeEntry( key_currentinput, m_videodevices[m_current_device]->currentInput() ); - // --- Save values of the controls ---: - qint32 ctrl_value; - const QString key_control_start = QString::fromLocal8Bit( "Device %1 Input %2 Control " ).arg( m_videodevices[m_current_device]->udi() ).arg( m_videodevices[m_current_device]->currentInput() ); - // Save values of the numeric controls: - QList<NumericVideoControl> numCtrls = m_videodevices[m_current_device]->getSupportedNumericControls(); - NumericVideoControl numCtrl; - foreach (numCtrl, numCtrls) - { - if (EXIT_SUCCESS == m_videodevices[m_current_device]->getControlValue(numCtrl.id, &ctrl_value)) - { - qDebug() << "Numeric control:" << numCtrl.id << "value" << ctrl_value; - config.writeEntry( key_control_start + QString::number(numCtrl.id), ctrl_value ); - } - else - qDebug() << "Error: couldn't get current value for numeric control" << numCtrl.id; - } - // Save values of the boolean controls: - QList<BooleanVideoControl> boolCtrls = m_videodevices[m_current_device]->getSupportedBooleanControls(); - BooleanVideoControl boolCtrl; - foreach (boolCtrl, boolCtrls) - { - if (EXIT_SUCCESS == m_videodevices[m_current_device]->getControlValue(boolCtrl.id, &ctrl_value)) - { - qDebug() << "Boolean control:" << boolCtrl.id << "value" << ctrl_value; - config.writeEntry( key_control_start + QString::number(boolCtrl.id), ctrl_value ); - } - else - qDebug() << "Error: couldn't get current value for boolean control" << numCtrl.id; - } - // Save values of the menu controls: - QList<MenuVideoControl> menuCtrls = m_videodevices[m_current_device]->getSupportedMenuControls(); - MenuVideoControl menuCtrl; - foreach (menuCtrl, menuCtrls) - { - if (EXIT_SUCCESS == m_videodevices[m_current_device]->getControlValue(menuCtrl.id, &ctrl_value)) - { - qDebug() << "Menu-control:" << menuCtrl.id << "value" << ctrl_value; - config.writeEntry( key_control_start + QString::number(menuCtrl.id), ctrl_value ); - } - else - qDebug() << "Error: couldn't get current value for menu-control" << numCtrl.id; - } - // NOTE: Action-video-controls don't have values, so there is nothing to save. - // Close device again (if it was closed before): - if (wasClosed) - { - if (EXIT_SUCCESS == m_videodevices[m_current_device]->close()) - qDebug() << "Device successfully closed."; - else - qDebug() << "Error: failed to close the device."; - } - config.sync(); - } - /* TODO: save signal standard */ -#endif -} - -/*! - \fn VideoDevicePool::showDeviceCapabilities(int device) - */ -int VideoDevicePool::showDeviceCapabilities(int device) -{ - if (device < 0) - device = m_current_device; - if ((device >= 0) && (device < m_videodevices.size())) - return m_videodevices[device]->showDeviceCapabilities(); - else - return EXIT_FAILURE; -} - - - -/*! - \fn void VideoDevicePool::deviceAdded( const QString & udi ) - \param udi Unique device identifier (UDI) of the device that has been connected - \brief Checks the device with the specified UDI and adds to the device pool, if it is a valid video device - */ -void VideoDevicePool::deviceAdded( const QString & udi ) -{ - qDebug() << "called with UDI" << udi; -#ifdef COMPILE_KDE_SUPPORT - Solid::Device dev( udi ); - if ( dev.is<Solid::Video>() ) - { - qDebug() << "Device is a video device, trying to register it."; - if ( registerDevice( dev ) ) - emit deviceRegistered( udi ); - } - else - qDebug() << "Device is not a video device"; -#endif -} - -/*! - \fn void VideoDevicePool::deviceRemoved( const QString & udi ) - \param udi Unique device identifier (UDI) of the device that has been unplugged - \brief Removes the device with the specified UDI from the device pool - */ -void VideoDevicePool::deviceRemoved( const QString & udi ) -{ - qDebug() << "called with UDI" << udi; - int i = 0; - foreach ( VideoDevice* vd, m_videodevices ) - { - if ( vd->udi() == udi ) - { - qDebug() << "Video device with UDI" << udi << "has been removed!"; - delete m_videodevices[i]; // NOTE: device is closed in destructor - m_videodevices.remove( i ); - if (m_current_device == i) - { - if (m_videodevices.size()) - m_current_device = 0; - else - m_current_device = -1; - m_clients = 0; - } - else if (m_current_device > i) - { - m_current_device--; - } - emit deviceUnregistered( udi ); - return; - } - else - i++; - } -} -#ifdef COMPILE_KDE_SUPPORT -/*! - \fn void bool VideoDevicePool::registerDevice( Solid::Device & device ) - \param device The solid device that should be registered - \return True, if the device has been registered; otherwise returns false - \brief Checks if the given device is a valid video device and adds it do the device list - */ -bool VideoDevicePool::registerDevice( Solid::Device & device ) -{ - qDebug() << "called, UDI is:\n " << device.udi(); - const Solid::Device * vendorDevice = &device; - while (vendorDevice->isValid() && vendorDevice->vendor().isEmpty()) - vendorDevice = new Solid::Device(vendorDevice->parentUdi()); - /* NOTE: The device we register has usually an empty vendor string and a less meaningfull product string. - So we go up to the first parent device that has a non-empty vendor string, - because we find the expected strings describing the device there. - */ - if (vendorDevice->isValid()) - qDebug() << "vendor:" << vendorDevice->vendor() << ", product:" << vendorDevice->product(); - else - qDebug() << "vendor:" << device.vendor() << ", product:" << device.product(); - - if (device.isValid()) - { - Solid::Video * solidVideoDevice = device.as<Solid::Video>(); - if (solidVideoDevice) - { - QStringList protocols = solidVideoDevice->supportedProtocols(); - if (protocols.contains("video4linux")) - { - QStringList drivers = solidVideoDevice->supportedDrivers("video4linux"); - if (drivers.contains("video4linux")) - { - VideoDevice* videodevice = new VideoDevice; - videodevice->setUdi( device.udi() ); - videodevice->setFileName(solidVideoDevice->driverHandle("video4linux").toString()); - qDebug() << "V4L device path is" << solidVideoDevice->driverHandle("video4linux").toString(); - if (EXIT_SUCCESS == videodevice->open()) - { - bool cap = videodevice->canCapture(); - videodevice->close(); - if (cap) - { - if (m_videodevices.size() == 0) - m_current_device = 0; - m_videodevices.push_back(videodevice); - qDebug() << "Device is a valid video device, adding it to video device pool."; - return true; - } - else - qDebug() << "Device does not support capturing."; - } - else - qDebug() << "Device could not be opened."; - delete videodevice; - } - } - } - else - qDebug() << "Device is not a video device."; - } - else - qDebug() << "Not a valid Solid device: device is not available in the system."; - return false; -} -#endif -} // namespace AV - -} // namespace Kopete diff --git a/src/kvilib/ext/avdevice/videodevicepool.h b/src/kvilib/ext/avdevice/videodevicepool.h deleted file mode 100644 index 943c25d75..000000000 --- a/src/kvilib/ext/avdevice/videodevicepool.h +++ /dev/null @@ -1,153 +0,0 @@ -//============================================================================= -// -// File : videodevicepool.h -// Creation date : Tue Nov 10 18:08:09 2009 GMT by Fabio Bas -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 file has been taken from the "Kopete, The KDE Instant Messenger" -// sourcecode. Original copyright of the file follows: -//============================================================================= - -/* - videodevicepool.h - Kopete Multiple Video Device handler Class - - Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com> - Copyright (c) 2010 by Frank Schaefer <fschaefer.oss@googlemail.com> - - Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> - - ************************************************************************* - * * - * 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 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef VIDEODEVICEPOOL_H -#define VIDEODEVICEPOOL_H - -#include <iostream> -#include "kvi_settings.h" - - -#include "videoinput.h" -#include <QString> -#include <QImage> -#include <QComboBox> -#include "videodevice.h" - -#ifdef COMPILE_KDE_SUPPORT - #include <solid/device.h> -#endif - -namespace Kopete { - -namespace AV { - -/** -This class allows kopete to check for the existence, open, configure, test, set parameters, grab frames from and close a given video capture card using the Video4Linux API. - -@author Cláudio da Silveira Pinheiro -*/ - -class KVILIB_API VideoDevicePool : public QObject -{ - -Q_OBJECT - -public: - static VideoDevicePool* self(); - ~VideoDevicePool(); - bool isOpen(); - int open( int device = -1 ); - int close(); - - int size(); - int currentDevice(); - QString currentDeviceUdi(); - int inputs(); - int currentInput(); - int selectInput( int newinput ); - - QList<NumericVideoControl> getSupportedNumericControls(); - QList<BooleanVideoControl> getSupportedBooleanControls(); - QList<MenuVideoControl> getSupportedMenuControls(); - QList<ActionVideoControl> getSupportedActionControls(); - int getControlValue( quint32 ctrl_id, qint32 * value ); - int setControlValue( quint32 ctrl_id, qint32 value ); - - int startCapturing(); - int stopCapturing(); - int getFrame(); - int getImage( QImage *qimage ); - - int width(); - int minWidth(); - int maxWidth(); - int height(); - int minHeight(); - int maxHeight(); - int setImageSize( int newwidth, int newheight ); - - void fillDeviceQComboBox( QComboBox *combobox ); - void fillInputQComboBox( QComboBox *combobox ); - void fillStandardQComboBox( QComboBox *combobox ); - - void saveCurrentDeviceConfig(); - -protected: - int m_current_device; - QVector<VideoDevice*> m_videodevices; /*!< Vector of pointers to the available video devices */ -#ifdef COMPILE_KDE_SUPPORT - bool registerDevice( Solid::Device & dev ); -#endif - int showDeviceCapabilities( int device = -1 ); - int getSavedDevice(); - void loadDeviceConfig(); - -private: - static VideoDevicePool* s_self; - static __u64 m_clients; // Number of instances - - VideoDevicePool(); - -protected slots: - /** - * Slot called when a new device is added to the system - */ - void deviceAdded( const QString & udi ); - void deviceRemoved( const QString & udi ); - -signals: - /** - * Provisional signatures, probably more useful to indicate which device was registered - */ - void deviceRegistered( const QString & udi ); - void deviceUnregistered( const QString & udi ); - -}; - -} - -} - -#endif // VIDEODEVICEPOOL_H diff --git a/src/kvilib/ext/avdevice/videoinput.cpp b/src/kvilib/ext/avdevice/videoinput.cpp deleted file mode 100644 index 1f80cd3fb..000000000 --- a/src/kvilib/ext/avdevice/videoinput.cpp +++ /dev/null @@ -1,70 +0,0 @@ -//============================================================================= -// -// File : videoinput.cpp -// Creation date : Tue Nov 10 18:08:09 2009 GMT by Fabio Bas -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 file has been taken from the "Kopete, The KDE Instant Messenger" -// sourcecode. Original copyright of the file follows: -//============================================================================= - -/* - videoinput.cpp - Kopete Video Input Class - - Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com> - - Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> - - ************************************************************************* - * * - * 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 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#include <QDebug> - -#include "videoinput.h" - -namespace Kopete { - -namespace AV { - -VideoInput::VideoInput() -{ - qDebug() << "Executing Video Input's constructor!!!"; - img_softcorr_autobrightnesscontrast = false; - img_softcorr_autocolor = false; - img_softcorr_vflip = false; - img_softcorr_hflip = false; - hastuner = 0; - m_standards = 0; -} - - -VideoInput::~VideoInput() -{ -} - -} - -} diff --git a/src/kvilib/ext/avdevice/videoinput.h b/src/kvilib/ext/avdevice/videoinput.h deleted file mode 100644 index 8262446a8..000000000 --- a/src/kvilib/ext/avdevice/videoinput.h +++ /dev/null @@ -1,81 +0,0 @@ -//============================================================================= -// -// File : videoinput.h -// Creation date : Tue Nov 10 18:08:09 2009 GMT by Fabio Bas -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2009 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 file has been taken from the "Kopete, The KDE Instant Messenger" -// sourcecode. Original copyright of the file follows: -//============================================================================= - -/* - videoinput.h - Kopete Video Input Class - - Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com> - - Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org> - - ************************************************************************* - * * - * 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 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef KOPETE_AVVIDEOINPUT_H -#define KOPETE_AVVIDEOINPUT_H - -#ifdef __linux__ -#include <asm/types.h> -#undef __STRICT_ANSI__ -#endif // __linux__ -#ifndef __u64 //required by videodev.h -#define __u64 unsigned long long -#endif // __u64*/ - -#include <QString> - -namespace Kopete { - -namespace AV { - -/** -@author Kopete Developers -*/ -class VideoInput{ -public: - VideoInput(); - ~VideoInput(); - QString name; - int hastuner; - __u64 m_standards; - bool img_softcorr_autobrightnesscontrast; - bool img_softcorr_autocolor; - bool img_softcorr_vflip; - bool img_softcorr_hflip; -}; - -} - -} - -#endif diff --git a/src/modules/dcc/CMakeLists.txt b/src/modules/dcc/CMakeLists.txt index 8cbbf43a8..3b7d80fca 100644 --- a/src/modules/dcc/CMakeLists.txt +++ b/src/modules/dcc/CMakeLists.txt @@ -20,7 +20,7 @@ set(kvidcc_SRCS DccWindow.cpp ) -if(NOT DEFINED COMPILE_DISABLE_DCC_VIDEO) +if(NOT COMPILE_DISABLE_DCC_VIDEO) list(APPEND kvidcc_SRCS DccVideoWindow.cpp ) diff --git a/src/modules/dcc/DccVideoWindow.cpp b/src/modules/dcc/DccVideoWindow.cpp index e671afa5b..9b1b7cde0 100644 --- a/src/modules/dcc/DccVideoWindow.cpp +++ b/src/modules/dcc/DccVideoWindow.cpp @@ -61,11 +61,6 @@ extern DccBroker * g_pDccBroker; -#ifndef COMPILE_DISABLE_DCC_VIDEO - Kopete::AV::VideoDevicePool *g_pVideoDevicePool=0; - int g_iVideoDevicePoolInstances=0; -#endif - bool kvi_dcc_video_is_valid_codec(const char * codecName) { if(kvi_strEqualCI("sjpeg",codecName)) @@ -91,42 +86,25 @@ static DccVideoCodec * kvi_dcc_video_get_codec(const char * codecName) DccVideoThread::DccVideoThread(KviWindow * wnd,kvi_socket_t fd,KviDccVideoThreadOptions * opt) : DccThread(wnd,fd) { -#ifndef COMPILE_DISABLE_DCC_VIDEO m_pOpt = opt; m_bPlaying = false; m_bRecording = false; - //local video input - if(!g_pVideoDevicePool) - { - g_pVideoDevicePool = Kopete::AV::VideoDevicePool::self(); - if (EXIT_SUCCESS != g_pVideoDevicePool->open()) return; - g_pVideoDevicePool->setImageSize(320, 240); - } - g_iVideoDevicePoolInstances++; -#endif startRecording(); startPlaying(); - } DccVideoThread::~DccVideoThread() { stopRecording(); -#ifndef COMPILE_DISABLE_DCC_VIDEO - g_iVideoDevicePoolInstances--; - if(g_iVideoDevicePoolInstances==0) - g_pVideoDevicePool->close(); delete m_pOpt->pCodec; delete m_pOpt; -#endif } bool DccVideoThread::readWriteStep() { // qDebug("DccVideoThread::readWriteStep()"); -#ifndef COMPILE_DISABLE_DCC_VIDEO // Socket management bool bCanRead; bool bCanWrite; @@ -164,21 +142,20 @@ bool DccVideoThread::readWriteStep() } } } -#endif // !COMPILE_DISABLE_DCC_VOICE return true; } bool DccVideoThread::videoStep() { // qDebug("DccVideoThread::videoStep()"); -#ifndef COMPILE_DISABLE_DCC_VIDEO + // Are we playing ? if(m_bPlaying) { if(m_videoInSignalBuffer.size() > 0) { QImage img(m_videoInSignalBuffer.data(), 320, 240, 1280, QImage::Format_ARGB32); -// qDebug("IMG data %p size %d", m_videoInSignalBuffer.data(), m_videoInSignalBuffer.size()); + //qDebug("IMG data %p size %d", m_videoInSignalBuffer.data(), m_videoInSignalBuffer.size()); if(!img.isNull()) m_inImage = img; } @@ -187,26 +164,25 @@ bool DccVideoThread::videoStep() // Are we recording ? if(m_bRecording) { - //grab the image, compress using the codec - if(g_pVideoDevicePool->getFrame() == EXIT_FAILURE) - return true; - if(g_pVideoDevicePool->getImage(&m_outImage) == EXIT_FAILURE) - return true; - if(m_outImage.numBytes() > 0) + QImage * pImage = ((DccVideoWindow*)parent())->m_pCameraImage; + if(pImage) { - m_videoOutSignalBuffer.append((const unsigned char*) m_outImage.bits(), m_outImage.numBytes()); + // grab the frame + m_videoOutSignalBuffer.append((const unsigned char*) pImage->bits(), pImage->byteCount()); m_pOpt->pCodec->encodeVideo(&m_videoOutSignalBuffer,&m_outFrameBuffer); + + // tell our parent to prepare a new frame + KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); + e->setData(new int(KVI_DCC_VIDEO_THREAD_ACTION_GRAB_FRAME)); + postEvent(DccThread::parent(),e); } } - -#endif // !COMPILE_DISABLE_DCC_VIDEO return true; } bool DccVideoThread::textStep() { // qDebug("DccVideoThread::textStep()"); -#ifndef COMPILE_DISABLE_DCC_VIDEO // Are we playing ? if(m_bPlaying) { @@ -235,13 +211,12 @@ bool DccVideoThread::textStep() m_pOpt->pCodec->encodeText(&m_textOutSignalBuffer,&m_outFrameBuffer); } -#endif // !COMPILE_DISABLE_DCC_VIDEO return true; } bool DccVideoThread::handleIncomingData(KviDccThreadIncomingData * data,bool bCritical) { -// qDebug("DccVideoThread::handleIncomingData"); + //qDebug("DccVideoThread::handleIncomingData"); KVI_ASSERT(data->iLen); KVI_ASSERT(data->buffer); char * aux = data->buffer; @@ -304,8 +279,8 @@ bool DccVideoThread::handleIncomingData(KviDccThreadIncomingData * data,bool bCr void DccVideoThread::restartRecording(int iDevice, int iInput, int) { -#ifndef COMPILE_DISABLE_DCC_VIDEO m_bRecording=false; + /* if(!g_pVideoDevicePool) g_pVideoDevicePool = Kopete::AV::VideoDevicePool::self(); @@ -315,33 +290,29 @@ void DccVideoThread::restartRecording(int iDevice, int iInput, int) if(iInput >= 0) g_pVideoDevicePool->selectInput(iInput); g_pVideoDevicePool->startCapturing(); - +*/ m_bRecording=true; -#endif } void DccVideoThread::startRecording() { -#ifndef COMPILE_DISABLE_DCC_VIDEO //qDebug("Start recording"); if(m_bRecording)return; // already started //ensure capturing - g_pVideoDevicePool->startCapturing(); +// g_pVideoDevicePool->startCapturing(); - qDebug("Posting event"); + //qDebug("Posting event"); KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); e->setData(new int(KVI_DCC_VIDEO_THREAD_ACTION_START_RECORDING)); postEvent(DccThread::parent(),e); m_bRecording = true; -#endif } void DccVideoThread::stopRecording() { -#ifndef COMPILE_DISABLE_DCC_VIDEO - qDebug("Stop recording"); + //qDebug("Stop recording"); if(!m_bRecording)return; // already stopped KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); @@ -349,40 +320,33 @@ void DccVideoThread::stopRecording() postEvent(DccThread::parent(),e); m_bRecording = false; -#endif } void DccVideoThread::startPlaying() { -#ifndef COMPILE_DISABLE_DCC_VIDEO - qDebug("Start playing"); + //qDebug("Start playing"); if(m_bPlaying)return; KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); e->setData(new int(KVI_DCC_VIDEO_THREAD_ACTION_START_PLAYING)); postEvent(DccThread::parent(),e); m_bPlaying = true; - -#endif } void DccVideoThread::stopPlaying() { -#ifndef COMPILE_DISABLE_DCC_VIDEO - qDebug("Stop playing"); + //qDebug("Stop playing"); if(!m_bPlaying)return; KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); e->setData(new int(KVI_DCC_VIDEO_THREAD_ACTION_STOP_PLAYING)); postEvent(DccThread::parent(),e); m_bPlaying = false; -#endif } void DccVideoThread::run() { -qDebug("DccVideoThread::run()"); -#ifndef COMPILE_DISABLE_DCC_VIDEO + //qDebug("DccVideoThread::run()"); for(;;) { // Dequeue events @@ -410,13 +374,12 @@ qDebug("DccVideoThread::run()"); if(!textStep())goto exit_dcc; usleep(FRAME_DURATION*1000); -// qDebug("in %d out %d in_sig %d out_sig %d", m_inFrameBuffer.size(), m_outFrameBuffer.size(), m_videoInSignalBuffer.size(), m_videoOutSignalBuffer.size()); + //qDebug("in %d out %d in_sig %d out_sig %d", m_inFrameBuffer.size(), m_outFrameBuffer.size(), m_videoInSignalBuffer.size(), m_videoOutSignalBuffer.size()); } exit_dcc: -#endif //! COMPILE_DISABLE_DCC_VIDEO kvi_socket_close(m_fd); m_fd = KVI_INVALID_SOCKET; } @@ -463,13 +426,22 @@ DccVideoWindow::DccVideoWindow(DccDescriptor * dcc,const char * name) m_pLayout->addWidget(m_pInVideoLabel, 1, 0, 6, 1); //local video - m_pOutVideoLabel = new QLabel(); - m_pOutVideoLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - m_pOutVideoLabel->setMinimumSize(320, 240); - m_pOutVideoLabel->setFrameShape(QFrame::Box); - m_pOutVideoLabel->setScaledContents(true); - m_pOutVideoLabel->setAlignment(Qt::AlignCenter); - m_pLayout->addWidget(m_pOutVideoLabel, 1, 1, 6, 1); + QByteArray cameraDevice; + if (cameraDevice.isEmpty()) + m_pCamera = new QCamera; + else + m_pCamera = new QCamera(cameraDevice); + + m_pCameraView = new QCameraViewfinder(); + m_pCameraView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_pCameraView->setMinimumSize(320, 240); + m_pCameraView->setMaximumSize(320, 240); + m_pCameraView->setAspectRatioMode(Qt::KeepAspectRatio); + m_pLayout->addWidget(m_pCameraView, 1, 1, 6, 1); + + m_pCamera->setViewfinder(m_pCameraView); + + m_pCameraImage = new QImage(320, 240, QImage::Format_ARGB32); //local video input: config m_pVideoLabel[0] = new QLabel(); @@ -512,6 +484,7 @@ DccVideoWindow::DccVideoWindow(DccDescriptor * dcc,const char * name) connect(m_pCStandards, SIGNAL(currentIndexChanged(int)), this, SLOT(videoInputChanged(int))); startConnection(); + m_pCamera->start(); } DccVideoWindow::~DccVideoWindow() @@ -521,10 +494,20 @@ DccVideoWindow::~DccVideoWindow() delete m_pInVideoLabel; m_pInVideoLabel=0; } - if(m_pOutVideoLabel) + if(m_pCameraView) + { + delete m_pCameraView; + m_pCameraView=0; + } + if(m_pCameraImage) + { + delete m_pCameraImage; + m_pCameraImage=0; + } + if(m_pCamera) { - delete m_pOutVideoLabel; - m_pOutVideoLabel=0; + delete m_pCamera; + m_pCamera=0; } if(m_pCDevices) { @@ -924,6 +907,10 @@ bool DccVideoWindow::event(QEvent *e) case KVI_DCC_VIDEO_THREAD_ACTION_STOP_PLAYING: // m_pPlayingLabel->setEnabled(false); break; + case KVI_DCC_VIDEO_THREAD_ACTION_GRAB_FRAME: + m_pCameraView->render( m_pCameraImage ); + break; + } delete act; return true; @@ -966,7 +953,7 @@ void DccVideoWindow::connected() output(KVI_OUT_DCCMSG,__tr2qs_ctx("Actual codec used is '%s'","dcc"),opt->pCodec->name()); m_pSlaveThread = new DccVideoThread(this,m_pMarshal->releaseSocket(),opt); - +/* #ifndef COMPILE_DISABLE_DCC_VIDEO if(g_pVideoDevicePool) { @@ -978,7 +965,7 @@ void DccVideoWindow::connected() connect(g_pVideoDevicePool, SIGNAL(deviceUnregistered(const QString &) ), SLOT(deviceUnregistered(const QString &)) ); } #endif - +*/ m_pSlaveThread->start(); } @@ -1004,47 +991,10 @@ void DccVideoWindow::startOrStopTalking(bool bStart) void DccVideoWindow::slotUpdateImage() { -#ifndef COMPILE_DISABLE_DCC_VIDEO if(m_pSlaveThread && isVisible()) { - m_pOutVideoLabel->setPixmap(QPixmap::fromImage(m_pSlaveThread->m_outImage)); m_pInVideoLabel->setPixmap(QPixmap::fromImage(m_pSlaveThread->m_inImage)); } -#endif -} - -void DccVideoWindow::deviceRegistered(const QString &) -{ - -#ifndef COMPILE_DISABLE_DCC_VIDEO - g_pVideoDevicePool->fillDeviceQComboBox(m_pCDevices); - g_pVideoDevicePool->fillInputQComboBox(m_pCInputs); - g_pVideoDevicePool->fillStandardQComboBox(m_pCStandards); - - if (g_pVideoDevicePool->size() < 2) // otherwise we are already capturing - { - // update the mVideoImageLabel to show the camera frames - if (EXIT_SUCCESS != g_pVideoDevicePool->open()) return; - g_pVideoDevicePool->setImageSize(320, 240); - g_pVideoDevicePool->startCapturing(); - } -// setVideoInputParameters(); - -// if ( g_pVideoDevicePool->hasDevices() ) -// { -// m_Timer.start(200); //5fps -// } -#endif -} - - -void DccVideoWindow::deviceUnregistered(const QString & ) -{ -#ifndef COMPILE_DISABLE_DCC_VIDEO - g_pVideoDevicePool->fillDeviceQComboBox(m_pCDevices); - g_pVideoDevicePool->fillInputQComboBox(m_pCInputs); - g_pVideoDevicePool->fillStandardQComboBox(m_pCStandards); -#endif } void DccVideoWindow::videoInputChanged(int ) diff --git a/src/modules/dcc/DccVideoWindow.h b/src/modules/dcc/DccVideoWindow.h index bda2db858..413dad549 100644 --- a/src/modules/dcc/DccVideoWindow.h +++ b/src/modules/dcc/DccVideoWindow.h @@ -44,9 +44,8 @@ #include <QComboBox> #include <QGridLayout> -#ifndef COMPILE_DISABLE_DCC_VIDEO - #include "avdevice/videodevicepool.h" -#endif +#include <QCamera> +#include <QCameraViewfinder> #ifdef COMPILE_CRYPT_SUPPORT class KviCryptSessionInfo; @@ -63,6 +62,7 @@ class DccMarshal; #define KVI_DCC_VIDEO_THREAD_ACTION_STOP_RECORDING 1 #define KVI_DCC_VIDEO_THREAD_ACTION_START_PLAYING 2 #define KVI_DCC_VIDEO_THREAD_ACTION_STOP_PLAYING 3 +#define KVI_DCC_VIDEO_THREAD_ACTION_GRAB_FRAME 4 typedef struct _KviDccVideoThreadOptions { @@ -114,8 +114,10 @@ public: protected: KviThemedLabel * m_pLabel; QWidget * m_pContainerWidget; + QImage * m_pCameraImage; + QCameraViewfinder * m_pCameraView; + QCamera * m_pCamera; QLabel * m_pInVideoLabel; - QLabel * m_pOutVideoLabel; QComboBox * m_pCDevices; QComboBox * m_pCInputs; QComboBox * m_pCStandards; @@ -148,11 +150,9 @@ protected slots: void startOrStopTalking(bool bStart); void connectionInProgress(); void slotUpdateImage(); - void deviceRegistered(const QString &); - void deviceUnregistered(const QString &); void textViewRightClicked(); void videoInputChanged(int ); }; -#endif //_VOICE_H_ +#endif //_VIDEO_H_ |
