qcap: Port to libv4l2.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2019-04-10 09:46:25 -05:00 committed by Alexandre Julliard
parent f098cd6d3a
commit 34ef3c89ad
6 changed files with 293 additions and 427 deletions

61
configure vendored
View File

@ -870,7 +870,7 @@ with_sane
with_sdl with_sdl
with_tiff with_tiff
with_udev with_udev
with_v4l with_v4l2
with_vkd3d with_vkd3d
with_vulkan with_vulkan
with_xcomposite with_xcomposite
@ -2541,7 +2541,7 @@ Optional Packages:
--without-sdl do not use SDL --without-sdl do not use SDL
--without-tiff do not use TIFF --without-tiff do not use TIFF
--without-udev do not use udev (plug and play support) --without-udev do not use udev (plug and play support)
--without-v4l do not use v4l1 (v4l support) --without-v4l2 do not use v4l2 (video capture)
--without-vkd3d do not use vkd3d (Direct3D 12 support) --without-vkd3d do not use vkd3d (Direct3D 12 support)
--without-vulkan do not use Vulkan --without-vulkan do not use Vulkan
--without-xcomposite do not use the Xcomposite extension --without-xcomposite do not use the Xcomposite extension
@ -4045,9 +4045,9 @@ if test "${with_udev+set}" = set; then :
fi fi
# Check whether --with-v4l was given. # Check whether --with-v4l2 was given.
if test "${with_v4l+set}" = set; then : if test "${with_v4l2+set}" = set; then :
withval=$with_v4l; withval=$with_v4l2;
fi fi
@ -7734,10 +7734,9 @@ fi
done done
for ac_header in linux/videodev.h linux/videodev2.h libv4l1.h for ac_header in linux/videodev2.h
do : do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "linux/videodev2.h" "ac_cv_header_linux_videodev2_h" "#ifdef HAVE_SYS_TIME_H
ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "#ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <sys/types.h> #include <sys/types.h>
@ -7745,9 +7744,9 @@ ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "#ifdef HAVE
#include <asm/types.h> #include <asm/types.h>
#endif #endif
" "
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : if test "x$ac_cv_header_linux_videodev2_h" = xyes; then :
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 #define HAVE_LINUX_VIDEODEV2_H 1
_ACEOF _ACEOF
fi fi
@ -13483,15 +13482,15 @@ esac
fi fi
if test "x$with_v4l" != "xno" if test "x$with_v4l2" != "xno"
then then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -lv4l1" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -lv4l2" >&5
$as_echo_n "checking for -lv4l1... " >&6; } $as_echo_n "checking for -lv4l2... " >&6; }
if ${ac_cv_lib_soname_v4l1+:} false; then : if ${ac_cv_lib_soname_v4l2+:} false; then :
$as_echo_n "(cached) " >&6 $as_echo_n "(cached) " >&6
else else
ac_check_soname_save_LIBS=$LIBS ac_check_soname_save_LIBS=$LIBS
LIBS="-lv4l1 $LIBS" LIBS="-lv4l2 $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
@ -13501,22 +13500,22 @@ LIBS="-lv4l1 $LIBS"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
#endif #endif
char v4l1_open (); char v4l2_open ();
int int
main () main ()
{ {
return v4l1_open (); return v4l2_open ();
; ;
return 0; return 0;
} }
_ACEOF _ACEOF
if ac_fn_c_try_link "$LINENO"; then : if ac_fn_c_try_link "$LINENO"; then :
case "$LIBEXT" in case "$LIBEXT" in
dll) ac_cv_lib_soname_v4l1=`$ac_cv_path_LDD conftest.exe | grep "v4l1" | sed -e "s/dll.*/dll/"';2,$d'` ;; dll) ac_cv_lib_soname_v4l2=`$ac_cv_path_LDD conftest.exe | grep "v4l2" | sed -e "s/dll.*/dll/"';2,$d'` ;;
dylib) ac_cv_lib_soname_v4l1=`$OTOOL -L conftest$ac_exeext | grep "libv4l1\\.[0-9A-Za-z.]*dylib" | sed -e "s/^.*\/\(libv4l1\.[0-9A-Za-z.]*dylib\).*$/\1/"';2,$d'` ;; dylib) ac_cv_lib_soname_v4l2=`$OTOOL -L conftest$ac_exeext | grep "libv4l2\\.[0-9A-Za-z.]*dylib" | sed -e "s/^.*\/\(libv4l2\.[0-9A-Za-z.]*dylib\).*$/\1/"';2,$d'` ;;
*) ac_cv_lib_soname_v4l1=`$READELF -d conftest$ac_exeext | grep "NEEDED.*libv4l1\\.$LIBEXT" | sed -e "s/^.*\\[\\(libv4l1\\.$LIBEXT[^ ]*\\)\\].*$/\1/"';2,$d'` *) ac_cv_lib_soname_v4l2=`$READELF -d conftest$ac_exeext | grep "NEEDED.*libv4l2\\.$LIBEXT" | sed -e "s/^.*\\[\\(libv4l2\\.$LIBEXT[^ ]*\\)\\].*$/\1/"';2,$d'`
if ${ac_cv_lib_soname_v4l1:+false} :; then : if ${ac_cv_lib_soname_v4l2:+false} :; then :
ac_cv_lib_soname_v4l1=`$LDD conftest$ac_exeext | grep "libv4l1\\.$LIBEXT" | sed -e "s/^.*\(libv4l1\.$LIBEXT[^ ]*\).*$/\1/"';2,$d'` ac_cv_lib_soname_v4l2=`$LDD conftest$ac_exeext | grep "libv4l2\\.$LIBEXT" | sed -e "s/^.*\(libv4l2\.$LIBEXT[^ ]*\).*$/\1/"';2,$d'`
fi ;; fi ;;
esac esac
fi fi
@ -13524,27 +13523,27 @@ rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_soname_save_LIBS LIBS=$ac_check_soname_save_LIBS
fi fi
if ${ac_cv_lib_soname_v4l1:+false} :; then : if ${ac_cv_lib_soname_v4l2:+false} :; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
$as_echo "not found" >&6; } $as_echo "not found" >&6; }
else else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_soname_v4l1" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_soname_v4l2" >&5
$as_echo "$ac_cv_lib_soname_v4l1" >&6; } $as_echo "$ac_cv_lib_soname_v4l2" >&6; }
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define SONAME_LIBV4L1 "$ac_cv_lib_soname_v4l1" #define SONAME_LIBV4L2 "$ac_cv_lib_soname_v4l2"
_ACEOF _ACEOF
fi fi
fi fi
if test "x$ac_cv_lib_soname_v4l1" = "x"; then : if test "x$ac_cv_lib_soname_v4l2" = "x"; then :
case "x$with_v4l" in case "x$with_v4l2" in
x) as_fn_append wine_notices "|libv4l ${notice_platform}development files not found." ;; x) as_fn_append wine_notices "|libv4l2 ${notice_platform}development files not found." ;;
xno) ;; xno) ;;
*) as_fn_error $? "libv4l ${notice_platform}development files not found. *) as_fn_error $? "libv4l2 ${notice_platform}development files not found.
This is an error since --with-v4l was requested." "$LINENO" 5 ;; This is an error since --with-v4l2 was requested." "$LINENO" 5 ;;
esac esac
fi fi

View File

@ -81,7 +81,7 @@ AC_ARG_WITH(sane, AS_HELP_STRING([--without-sane],[do not use SANE (scanner
AC_ARG_WITH(sdl, AS_HELP_STRING([--without-sdl],[do not use SDL])) AC_ARG_WITH(sdl, AS_HELP_STRING([--without-sdl],[do not use SDL]))
AC_ARG_WITH(tiff, AS_HELP_STRING([--without-tiff],[do not use TIFF])) AC_ARG_WITH(tiff, AS_HELP_STRING([--without-tiff],[do not use TIFF]))
AC_ARG_WITH(udev, AS_HELP_STRING([--without-udev],[do not use udev (plug and play support)])) AC_ARG_WITH(udev, AS_HELP_STRING([--without-udev],[do not use udev (plug and play support)]))
AC_ARG_WITH(v4l, AS_HELP_STRING([--without-v4l],[do not use v4l1 (v4l support)])) AC_ARG_WITH(v4l2, AS_HELP_STRING([--without-v4l2],[do not use v4l2 (video capture)]))
AC_ARG_WITH(vkd3d, AS_HELP_STRING([--without-vkd3d],[do not use vkd3d (Direct3D 12 support)])) AC_ARG_WITH(vkd3d, AS_HELP_STRING([--without-vkd3d],[do not use vkd3d (Direct3D 12 support)]))
AC_ARG_WITH(vulkan, AS_HELP_STRING([--without-vulkan],[do not use Vulkan])) AC_ARG_WITH(vulkan, AS_HELP_STRING([--without-vulkan],[do not use Vulkan]))
AC_ARG_WITH(xcomposite,AS_HELP_STRING([--without-xcomposite],[do not use the Xcomposite extension]), AC_ARG_WITH(xcomposite,AS_HELP_STRING([--without-xcomposite],[do not use the Xcomposite extension]),
@ -674,7 +674,7 @@ AC_CHECK_HEADERS([pthread_np.h],,,
#include <pthread.h> #include <pthread.h>
#endif]) #endif])
AC_CHECK_HEADERS([linux/videodev.h linux/videodev2.h libv4l1.h],,, AC_CHECK_HEADERS([linux/videodev2.h],,,
[#ifdef HAVE_SYS_TIME_H [#ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
@ -1417,13 +1417,13 @@ fi
WINE_NOTICE_WITH(sane,[test "x$ac_cv_lib_soname_sane" = "x"], WINE_NOTICE_WITH(sane,[test "x$ac_cv_lib_soname_sane" = "x"],
[libsane ${notice_platform}development files not found, scanners won't be supported.]) [libsane ${notice_platform}development files not found, scanners won't be supported.])
dnl **** Check for libv4l1 **** dnl **** Check for libv4l2 ****
if test "x$with_v4l" != "xno" if test "x$with_v4l2" != "xno"
then then
WINE_CHECK_SONAME(v4l1,v4l1_open,,,) WINE_CHECK_SONAME(v4l2,v4l2_open)
fi fi
WINE_NOTICE_WITH(v4l,[test "x$ac_cv_lib_soname_v4l1" = "x"], WINE_NOTICE_WITH(v4l2,[test "x$ac_cv_lib_soname_v4l2" = "x"],
[libv4l ${notice_platform}development files not found.]) [libv4l2 ${notice_platform}development files not found.])
dnl **** Check for libgphoto2 **** dnl **** Check for libgphoto2 ****
if test "x$with_gphoto" != "xno" if test "x$with_gphoto" != "xno"

View File

@ -20,6 +20,7 @@
#ifndef _QCAP_MAIN_H_DEFINED #ifndef _QCAP_MAIN_H_DEFINED
#define _QCAP_MAIN_H_DEFINED #define _QCAP_MAIN_H_DEFINED
#include "wine/heap.h"
#include "wine/strmbase.h" #include "wine/strmbase.h"
extern DWORD ObjectRefCount(BOOL increment) DECLSPEC_HIDDEN; extern DWORD ObjectRefCount(BOOL increment) DECLSPEC_HIDDEN;

View File

@ -1,11 +1,8 @@
/* /*
* DirectShow capture services (QCAP.DLL) * v4l2 backend to the VFW Capture filter
* *
* Copyright 2005 Maarten Lankhorst * Copyright 2005 Maarten Lankhorst
* * Copyright 2019 Zebediah Figura
* This file contains the part of the vfw capture interface that
* does the actual Video4Linux(1/2) stuff required for capturing
* and setting/getting media format..
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -22,6 +19,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#define BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD /* work around ioctl breakage on Android */
#include "config.h" #include "config.h"
#include "wine/port.h" #include "wine/port.h"
@ -43,11 +42,8 @@
#ifdef HAVE_ASM_TYPES_H #ifdef HAVE_ASM_TYPES_H
#include <asm/types.h> #include <asm/types.h>
#endif #endif
#ifdef HAVE_LIBV4L1_H #ifdef HAVE_LINUX_VIDEODEV2_H
#include <libv4l1.h> #include <linux/videodev2.h>
#endif
#ifdef HAVE_LINUX_VIDEODEV_H
#include <linux/videodev.h>
#endif #endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
@ -67,33 +63,34 @@
#include "capture.h" #include "capture.h"
#include "qcap_main.h" #include "qcap_main.h"
WINE_DEFAULT_DEBUG_CHANNEL(qcap_v4l); WINE_DEFAULT_DEBUG_CHANNEL(qcap);
#ifdef VIDIOCMCAPTURE #ifdef HAVE_LINUX_VIDEODEV2_H
WINE_DECLARE_DEBUG_CHANNEL(winediag);
static typeof(open) *video_open = open; static typeof(open) *video_open = open;
static typeof(close) *video_close = close; static typeof(close) *video_close = close;
static typeof(ioctl) *video_ioctl = ioctl; static typeof(ioctl) *video_ioctl = ioctl;
static typeof(read) *video_read = read; static typeof(read) *video_read = read;
static typeof(mmap) *video_mmap = mmap;
static typeof(munmap) *video_munmap = munmap;
static void video_init(void) static BOOL video_init(void)
{ {
#ifdef SONAME_LIBV4L1 #ifdef SONAME_LIBV4L2
static void *video_lib; static void *video_lib;
if (video_lib) if (video_lib)
return; return TRUE;
video_lib = wine_dlopen(SONAME_LIBV4L1, RTLD_NOW, NULL, 0); if (!(video_lib = wine_dlopen(SONAME_LIBV4L2, RTLD_NOW, NULL, 0)))
if (!video_lib) return FALSE;
return; video_open = wine_dlsym(video_lib, "v4l2_open", NULL, 0);
video_open = wine_dlsym(video_lib, "v4l1_open", NULL, 0); video_close = wine_dlsym(video_lib, "v4l2_close", NULL, 0);
video_close = wine_dlsym(video_lib, "v4l1_close", NULL, 0); video_ioctl = wine_dlsym(video_lib, "v4l2_ioctl", NULL, 0);
video_ioctl = wine_dlsym(video_lib, "v4l1_ioctl", NULL, 0); video_read = wine_dlsym(video_lib, "v4l2_read", NULL, 0);
video_read = wine_dlsym(video_lib, "v4l1_read", NULL, 0);
video_mmap = wine_dlsym(video_lib, "v4l1_mmap", NULL, 0); return TRUE;
video_munmap = wine_dlsym(video_lib, "v4l1_munmap", NULL, 0); #else
return FALSE;
#endif #endif
} }
@ -109,62 +106,39 @@ struct _Capture
IPin *pOut; IPin *pOut;
int fd, mmap; int fd, mmap;
BOOL iscommitted, stopped; BOOL iscommitted, stopped;
struct video_picture pict;
int dbrightness, dhue, dcolour, dcontrast;
/* mmap (V4l1) */ __u32 pixelformat;
struct video_mmap *grab_buf; int depth;
struct video_mbuf gb_buffers;
unsigned char *pmap;
int buffers;
/* read (V4l1) */ int image_size;
int imagesize; unsigned char *image_data;
char * grab_data;
int curframe;
HANDLE thread; HANDLE thread;
Renderer renderer; Renderer renderer;
}; };
struct renderlist
{
int depth;
const char* name;
Renderer renderer;
};
static void renderer_RGB(const Capture *capBox, LPBYTE bufferin, const BYTE *stream); static void renderer_RGB(const Capture *capBox, LPBYTE bufferin, const BYTE *stream);
static void renderer_YUV(const Capture *capBox, LPBYTE bufferin, const BYTE *stream); static void renderer_YUV(const Capture *capBox, LPBYTE bufferin, const BYTE *stream);
static const struct renderlist renderlist_V4l[] = { static const struct
{ 0, "NULL renderer", NULL }, {
{ 8, "Gray scales", NULL }, /* 1, Don't support */ int depth;
{ 0, "High 240 cube (BT848)", NULL }, /* 2, Don't support */ __u32 pixelformat;
{ 16, "16 bit RGB (565)", NULL }, /* 3, Don't support */ Renderer renderer;
{ 24, "24 bit RGB values", renderer_RGB }, /* 4, Supported, */ }
{ 32, "32 bit RGB values", renderer_RGB }, /* 5, Supported */ renderlist_V4l[] =
{ 16, "15 bit RGB (555)", NULL }, /* 6, Don't support */ {
{ 16, "YUV 422 (Not P)", renderer_YUV }, /* 7, Supported */ {24, V4L2_PIX_FMT_BGR24, renderer_RGB},
{ 16, "YUYV (Not P)", renderer_YUV }, /* 8, Supported */ {32, V4L2_PIX_FMT_BGR32, renderer_RGB},
{ 16, "UYVY (Not P)", renderer_YUV }, /* 9, Supported */ {16, V4L2_PIX_FMT_YUYV, renderer_YUV},
{ 16, "YUV 420 (Not P)", NULL }, /* 10, Not supported, if I had to guess it's YYUYYV */ {16, V4L2_PIX_FMT_UYVY, renderer_YUV},
{ 12, "YUV 411 (Not P)", renderer_YUV }, /* 11, Supported */ {12, V4L2_PIX_FMT_Y41P, renderer_YUV},
{ 0, "Raw capturing (BT848)", NULL }, /* 12, Don't support */ {16, V4L2_PIX_FMT_YUV422P, renderer_YUV},
{ 16, "YUV 422 (Planar)", renderer_YUV }, /* 13, Supported */ {12, V4L2_PIX_FMT_YUV411P, renderer_YUV},
{ 12, "YUV 411 (Planar)", renderer_YUV }, /* 14, Supported */ {12, V4L2_PIX_FMT_YUV420, renderer_YUV},
{ 12, "YUV 420 (Planar)", renderer_YUV }, /* 15, Supported */ {10, V4L2_PIX_FMT_YUV410, renderer_YUV},
{ 10, "YUV 410 (Planar)", renderer_YUV }, /* 16, Supported */
/* FIXME: add YUV420 support */
{ 0, NULL, NULL },
}; };
static const int fallback_V4l[] = { 4, 5, 7, 8, 9, 13, 15, 14, 16, 11, -1 };
/* Fallback: First try raw formats (Should try yuv first perhaps?), then yuv */
/* static const Capture defbox; */
static int xioctl(int fd, int request, void * arg) static int xioctl(int fd, int request, void * arg)
{ {
int r; int r;
@ -177,69 +151,17 @@ static int xioctl(int fd, int request, void * arg)
} }
/* Prepare the capture buffers */ /* Prepare the capture buffers */
static HRESULT V4l_Prepare(Capture *capBox) static HRESULT V4l_Prepare(Capture *device)
{ {
TRACE("%p: Preparing for %dx%d resolution\n", capBox, capBox->width, capBox->height); device->image_size = device->depth * device->height * device->width / 8;
if (!(device->image_data = heap_alloc(device->image_size)))
/* Try mmap */ return E_OUTOFMEMORY;
capBox->mmap = 0;
if (xioctl(capBox->fd, VIDIOCGMBUF, &capBox->gb_buffers) != -1 &&
capBox->gb_buffers.frames)
{
capBox->buffers = capBox->gb_buffers.frames;
if (capBox->gb_buffers.frames > 1)
capBox->buffers = 1;
TRACE("%p: Using %d/%d buffers\n", capBox,
capBox->buffers, capBox->gb_buffers.frames);
capBox->pmap = video_mmap( 0, capBox->gb_buffers.size, PROT_READ|PROT_WRITE,
MAP_SHARED, capBox->fd, 0 );
if (capBox->pmap != MAP_FAILED)
{
int i;
capBox->grab_buf = CoTaskMemAlloc(sizeof(struct video_mmap) * capBox->buffers);
if (!capBox->grab_buf)
{
video_munmap(capBox->pmap, capBox->gb_buffers.size);
return E_OUTOFMEMORY;
}
/* Setup mmap capture buffers. */
for (i = 0; i < capBox->buffers; i++)
{
capBox->grab_buf[i].format = capBox->pict.palette;
capBox->grab_buf[i].frame = i;
capBox->grab_buf[i].width = capBox->width;
capBox->grab_buf[i].height = capBox->height;
}
capBox->mmap = 1;
}
}
if (!capBox->mmap)
{
capBox->buffers = 1;
capBox->imagesize = renderlist_V4l[capBox->pict.palette].depth *
capBox->height * capBox->width / 8;
capBox->grab_data = CoTaskMemAlloc(capBox->imagesize);
if (!capBox->grab_data)
return E_OUTOFMEMORY;
}
TRACE("Using mmap: %d\n", capBox->mmap);
return S_OK; return S_OK;
} }
static void V4l_Unprepare(Capture *capBox) static void V4l_Unprepare(Capture *device)
{ {
if (capBox->mmap) heap_free(device->image_data);
{
for (capBox->curframe = 0; capBox->curframe < capBox->buffers; capBox->curframe++)
xioctl(capBox->fd, VIDIOCSYNC, &capBox->grab_buf[capBox->curframe]);
video_munmap(capBox->pmap, capBox->gb_buffers.size);
CoTaskMemFree(capBox->grab_buf);
}
else
CoTaskMemFree(capBox->grab_data);
} }
HRESULT qcap_driver_destroy(Capture *capBox) HRESULT qcap_driver_destroy(Capture *capBox)
@ -254,52 +176,53 @@ HRESULT qcap_driver_destroy(Capture *capBox)
return S_OK; return S_OK;
} }
HRESULT qcap_driver_set_format(Capture *capBox, AM_MEDIA_TYPE * mT) HRESULT qcap_driver_set_format(Capture *device, AM_MEDIA_TYPE *mt)
{ {
struct v4l2_format format = {0};
int newheight, newwidth; int newheight, newwidth;
struct video_window window; VIDEOINFOHEADER *vih;
VIDEOINFOHEADER *format; int fd = device->fd;
TRACE("%p\n", capBox); vih = (VIDEOINFOHEADER *)mt->pbFormat;
if (vih->bmiHeader.biBitCount != 24 || vih->bmiHeader.biCompression != BI_RGB)
format = (VIDEOINFOHEADER *) mT->pbFormat;
if (format->bmiHeader.biBitCount != 24 ||
format->bmiHeader.biCompression != BI_RGB)
{ {
FIXME("unsupported media type %d %d\n", format->bmiHeader.biBitCount, FIXME("Unsupported compression %#x, bpp %u.\n", vih->bmiHeader.biCompression,
format->bmiHeader.biCompression ); vih->bmiHeader.biBitCount);
return VFW_E_INVALIDMEDIATYPE; return VFW_E_INVALIDMEDIATYPE;
} }
newwidth = format->bmiHeader.biWidth; newwidth = vih->bmiHeader.biWidth;
newheight = format->bmiHeader.biHeight; newheight = vih->bmiHeader.biHeight;
TRACE("%p -> (%p) - %d %d\n", capBox, mT, newwidth, newheight); if (device->height == newheight && device->width == newwidth)
if (capBox->height == newheight && capBox->width == newwidth)
return S_OK; return S_OK;
if(-1 == xioctl(capBox->fd, VIDIOCGWIN, &window)) format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (xioctl(fd, VIDIOC_G_FMT, &format) == -1)
{ {
ERR("ioctl(VIDIOCGWIN) failed (%d)\n", errno); ERR("Failed to get current format: %s\n", strerror(errno));
return E_FAIL; return VFW_E_TYPE_NOT_ACCEPTED;
} }
window.width = newwidth;
window.height = newheight; format.fmt.pix.width = newwidth;
if (xioctl(capBox->fd, VIDIOCSWIN, &window) == -1) format.fmt.pix.height = newheight;
if (!xioctl(fd, VIDIOC_S_FMT, &format)
&& format.fmt.pix.width == newwidth
&& format.fmt.pix.height == newheight)
{ {
TRACE("using software resize: %dx%d -> %dx%d\n", device->width = newwidth;
window.width, window.height, capBox->width, capBox->height); device->height = newheight;
capBox->swresize = TRUE; device->swresize = FALSE;
} }
else else
{ {
capBox->height = window.height; TRACE("Using software resize: %dx%d -> %dx%d.\n",
capBox->width = window.width; format.fmt.pix.width, format.fmt.pix.height, device->width, device->height);
capBox->swresize = FALSE; device->swresize = TRUE;
} }
capBox->outputwidth = window.width; device->outputwidth = format.fmt.pix.width;
capBox->outputheight = window.height; device->outputheight = format.fmt.pix.height;
return S_OK; return S_OK;
} }
@ -349,109 +272,92 @@ HRESULT qcap_driver_get_format(const Capture *capBox, AM_MEDIA_TYPE ** mT)
return S_OK; return S_OK;
} }
HRESULT qcap_driver_get_prop_range( Capture *capBox, static __u32 v4l2_cid_from_qcap_property(VideoProcAmpProperty property)
VideoProcAmpProperty Property, LONG *pMin, LONG *pMax,
LONG *pSteppingDelta, LONG *pDefault, LONG *pCapsFlags )
{ {
TRACE("%p -> %d %p %p %p %p %p\n", capBox, Property, switch (property)
pMin, pMax, pSteppingDelta, pDefault, pCapsFlags);
switch (Property)
{ {
case VideoProcAmp_Brightness: case VideoProcAmp_Brightness:
*pDefault = capBox->dbrightness; return V4L2_CID_BRIGHTNESS;
break;
case VideoProcAmp_Contrast: case VideoProcAmp_Contrast:
*pDefault = capBox->dcontrast; return V4L2_CID_CONTRAST;
break;
case VideoProcAmp_Hue: case VideoProcAmp_Hue:
*pDefault = capBox->dhue; return V4L2_CID_HUE;
break;
case VideoProcAmp_Saturation: case VideoProcAmp_Saturation:
*pDefault = capBox->dcolour; return V4L2_CID_SATURATION;
break;
default: default:
FIXME("Not implemented %d\n", Property); FIXME("Unhandled property %d.\n", property);
return E_NOTIMPL; return 0;
} }
*pMin = 0; }
*pMax = 65535;
*pSteppingDelta = 65536/256; HRESULT qcap_driver_get_prop_range(Capture *device, VideoProcAmpProperty property,
*pCapsFlags = VideoProcAmp_Flags_Manual; LONG *min, LONG *max, LONG *step, LONG *default_value, LONG *flags)
{
struct v4l2_queryctrl ctrl;
ctrl.id = v4l2_cid_from_qcap_property(property);
if (xioctl(device->fd, VIDIOC_QUERYCTRL, &ctrl) == -1)
{
WARN("Failed to query control: %s\n", strerror(errno));
return E_PROP_ID_UNSUPPORTED;
}
*min = ctrl.minimum;
*max = ctrl.maximum;
*step = ctrl.step;
*default_value = ctrl.default_value;
*flags = VideoProcAmp_Flags_Manual;
return S_OK; return S_OK;
} }
HRESULT qcap_driver_get_prop( Capture *capBox, HRESULT qcap_driver_get_prop(Capture *device, VideoProcAmpProperty property,
VideoProcAmpProperty Property, LONG *lValue, LONG *Flags ) LONG *value, LONG *flags)
{ {
TRACE("%p -> %d %p %p\n", capBox, Property, lValue, Flags); struct v4l2_control ctrl;
switch (Property) ctrl.id = v4l2_cid_from_qcap_property(property);
if (xioctl(device->fd, VIDIOC_G_CTRL, &ctrl) == -1)
{ {
case VideoProcAmp_Brightness: WARN("Failed to get property: %s\n", strerror(errno));
*lValue = capBox->pict.brightness;
break;
case VideoProcAmp_Contrast:
*lValue = capBox->pict.contrast;
break;
case VideoProcAmp_Hue:
*lValue = capBox->pict.hue;
break;
case VideoProcAmp_Saturation:
*lValue = capBox->pict.colour;
break;
default:
FIXME("Not implemented %d\n", Property);
return E_NOTIMPL;
}
*Flags = VideoProcAmp_Flags_Manual;
return S_OK;
}
HRESULT qcap_driver_set_prop(Capture *capBox, VideoProcAmpProperty Property,
LONG lValue, LONG Flags)
{
TRACE("%p -> %d %d %d\n", capBox, Property, lValue, Flags);
switch (Property)
{
case VideoProcAmp_Brightness:
capBox->pict.brightness = lValue;
break;
case VideoProcAmp_Contrast:
capBox->pict.contrast = lValue;
break;
case VideoProcAmp_Hue:
capBox->pict.hue = lValue;
break;
case VideoProcAmp_Saturation:
capBox->pict.colour = lValue;
break;
default:
FIXME("Not implemented %d\n", Property);
return E_NOTIMPL;
}
if (xioctl(capBox->fd, VIDIOCSPICT, &capBox->pict) == -1)
{
ERR("ioctl(VIDIOCSPICT) failed (%d)\n",errno);
return E_FAIL; return E_FAIL;
} }
*value = ctrl.value;
*flags = VideoProcAmp_Flags_Manual;
return S_OK; return S_OK;
} }
static void renderer_RGB(const Capture *capBox, LPBYTE bufferin, const BYTE *stream) HRESULT qcap_driver_set_prop(Capture *device, VideoProcAmpProperty property,
LONG value, LONG flags)
{ {
int depth = renderlist_V4l[capBox->pict.palette].depth; struct v4l2_control ctrl;
int size = capBox->height * capBox->width * depth / 8;
ctrl.id = v4l2_cid_from_qcap_property(property);
ctrl.value = value;
if (xioctl(device->fd, VIDIOC_S_CTRL, &ctrl) == -1)
{
WARN("Failed to set property: %s\n", strerror(errno));
return E_FAIL;
}
return S_OK;
}
static void renderer_RGB(const Capture *device, BYTE *bufferin, const BYTE *stream)
{
int size = device->height * device->width * device->depth / 8;
int pointer, offset; int pointer, offset;
switch (depth) switch (device->pixelformat)
{ {
case 24: case V4L2_PIX_FMT_BGR24:
memcpy(bufferin, stream, size); memcpy(bufferin, stream, size);
break; break;
case 32: case V4L2_PIX_FMT_BGR32:
pointer = 0; pointer = 0;
offset = 1; offset = 1;
while (pointer + offset <= size) while (pointer + offset <= size)
@ -466,44 +372,43 @@ static void renderer_RGB(const Capture *capBox, LPBYTE bufferin, const BYTE *str
} }
break; break;
default: default:
ERR("Unknown bit depth %d\n", depth); FIXME("Unhandled pixel format %#x.\n", device->pixelformat);
return; return;
} }
} }
static void renderer_YUV(const Capture *capBox, LPBYTE bufferin, const BYTE *stream) static void renderer_YUV(const Capture *device, BYTE *bufferin, const BYTE *stream)
{ {
enum YUV_Format format; enum YUV_Format format;
switch (capBox->pict.palette) switch (device->pixelformat)
{ {
case 7: /* YUV422 - same as YUYV */ case V4L2_PIX_FMT_YUYV:
case 8: /* YUYV */
format = YUYV; format = YUYV;
break; break;
case 9: /* UYVY */ case V4L2_PIX_FMT_UYVY:
format = UYVY; format = UYVY;
break; break;
case 11: /* YUV411 */ case V4L2_PIX_FMT_Y41P:
format = UYYVYY; format = UYYVYY;
break; break;
case 13: /* YUV422P */ case V4L2_PIX_FMT_YUV422P:
format = YUVP_421; format = YUVP_421;
break; break;
case 14: /* YUV411P */ case V4L2_PIX_FMT_YUV411P:
format = YUVP_441; format = YUVP_441;
break; break;
case 15: /* YUV420P */ case V4L2_PIX_FMT_YUV420:
format = YUVP_422; format = YUVP_422;
break; break;
case 16: /* YUV410P */ case V4L2_PIX_FMT_YUV410:
format = YUVP_444; format = YUVP_444;
break; break;
default: default:
ERR("Unknown palette %d\n", capBox->pict.palette); FIXME("Unhandled pixel format %#x.\n", device->pixelformat);
return; return;
} }
YUV_To_RGB24(format, bufferin, stream, capBox->width, capBox->height); YUV_To_RGB24(format, bufferin, stream, device->width, device->height);
} }
static void Resize(const Capture * capBox, LPBYTE output, const BYTE *input) static void Resize(const Capture * capBox, LPBYTE output, const BYTE *input)
@ -562,36 +467,18 @@ static void Resize(const Capture * capBox, LPBYTE output, const BYTE *input)
} }
} }
static void V4l_GetFrame(Capture * capBox, unsigned char ** pInput) static void V4l_GetFrame(Capture *device, unsigned char **buffer)
{ {
if (capBox->mmap) while (video_read(device->fd, device->image_data, device->image_size) == -1)
{ {
if (xioctl(capBox->fd, VIDIOCSYNC, &capBox->grab_buf[capBox->curframe]) == -1) if (errno != EAGAIN)
WARN("Syncing ioctl failed: %d\n", errno); {
ERR("Failed to read frame: %s\n", strerror(errno));
*pInput = capBox->pmap + capBox->gb_buffers.offsets[capBox->curframe]; break;
}
} }
else TRACE("Successfully read a frame.\n");
{ *buffer = device->image_data;
int retval;
while ((retval = video_read(capBox->fd, capBox->grab_data, capBox->imagesize)) == -1)
if (errno != EAGAIN) break;
if (retval == -1)
WARN("Error occurred while reading from device: %s\n", strerror(errno));
*pInput = (unsigned char*) capBox->grab_data;
}
}
static void V4l_FreeFrame(Capture * capBox)
{
TRACE("\n");
if (capBox->mmap)
{
if (xioctl(capBox->fd, VIDIOCMCAPTURE, &capBox->grab_buf[capBox->curframe]) == -1)
ERR("Freeing frame for capture failed: %s\n", strerror(errno));
}
if (++capBox->curframe == capBox->buffers)
capBox->curframe = 0;
} }
static DWORD WINAPI ReadThread(LPVOID lParam) static DWORD WINAPI ReadThread(LPVOID lParam)
@ -612,10 +499,6 @@ static DWORD WINAPI ReadThread(LPVOID lParam)
} }
pOutput = CoTaskMemAlloc(capBox->width * capBox->height * capBox->bitDepth / 8); pOutput = CoTaskMemAlloc(capBox->width * capBox->height * capBox->bitDepth / 8);
capBox->curframe = 0;
do {
V4l_FreeFrame(capBox);
} while (capBox->curframe != 0);
while (1) while (1)
{ {
@ -644,7 +527,6 @@ static DWORD WINAPI ReadThread(LPVOID lParam)
hr = BaseOutputPinImpl_Deliver((BaseOutputPin *)capBox->pOut, pSample); hr = BaseOutputPinImpl_Deliver((BaseOutputPin *)capBox->pOut, pSample);
TRACE("%p -> Frame %u: %x\n", capBox, ++framecount, hr); TRACE("%p -> Frame %u: %x\n", capBox, ++framecount, hr);
IMediaSample_Release(pSample); IMediaSample_Release(pSample);
V4l_FreeFrame(capBox);
} }
if (FAILED(hr) && hr != VFW_E_NOT_CONNECTED) if (FAILED(hr) && hr != VFW_E_NOT_CONNECTED)
{ {
@ -777,137 +659,127 @@ HRESULT qcap_driver_stop(Capture *capBox, FILTER_STATE *state)
return S_OK; return S_OK;
} }
static int negotiate_format(Capture *device)
{
struct v4l2_format format = {0};
int fd = device->fd;
unsigned int i;
format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (xioctl(fd, VIDIOC_G_FMT, &format) == -1)
{
ERR("Failed to get device format: %s\n", strerror(errno));
return -1;
}
for (i = 0; i < ARRAY_SIZE(renderlist_V4l); ++i)
{
if (renderlist_V4l[i].pixelformat == format.fmt.pix.pixelformat)
{
TRACE("Using device-reported format %#x.\n", format.fmt.pix.pixelformat);
device->depth = renderlist_V4l[i].depth;
device->renderer = renderlist_V4l[i].renderer;
device->pixelformat = format.fmt.pix.pixelformat;
device->width = format.fmt.pix.width;
device->height = format.fmt.pix.height;
return 0;
}
}
for (i = 0; i < ARRAY_SIZE(renderlist_V4l); ++i)
{
format.fmt.pix.pixelformat = renderlist_V4l[i].pixelformat;
if (!xioctl(fd, VIDIOC_S_FMT, &format)
&& format.fmt.pix.pixelformat == renderlist_V4l[i].pixelformat)
{
TRACE("Using format %#x.\n", format.fmt.pix.pixelformat);
device->depth = renderlist_V4l[i].depth;
device->renderer = renderlist_V4l[i].renderer;
device->pixelformat = format.fmt.pix.pixelformat;
device->width = format.fmt.pix.width;
device->height = format.fmt.pix.height;
return 0;
}
}
FIXME("Could not negotiate an acceptable format.\n");
return -1;
}
Capture * qcap_driver_init( IPin *pOut, USHORT card ) Capture * qcap_driver_init( IPin *pOut, USHORT card )
{ {
Capture * capBox = NULL; struct v4l2_capability caps = {{0}};
char device[20]; Capture *device = NULL;
struct video_capability capa; BOOL have_libv4l2;
struct video_picture pict; char path[20];
struct video_window window; int fd;
YUV_Init(); YUV_Init();
video_init(); have_libv4l2 = video_init();
capBox = CoTaskMemAlloc(sizeof(Capture)); if (!(device = CoTaskMemAlloc(sizeof(*device))))
if (!capBox) return NULL;
goto error;
/* capBox->vtbl = &defboxVtbl; */ InitializeCriticalSection(&device->CritSect);
device->CritSect.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": Capture.CritSect");
InitializeCriticalSection( &capBox->CritSect ); sprintf(path, "/dev/video%i", card);
capBox->CritSect.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": Capture.CritSect"); TRACE("Opening device %s.\n", path);
sprintf(device, "/dev/video%i", card);
TRACE("opening %s\n", device);
#ifdef O_CLOEXEC #ifdef O_CLOEXEC
if ((capBox->fd = video_open(device, O_RDWR | O_NONBLOCK | O_CLOEXEC)) == -1 && errno == EINVAL) if ((fd = video_open(path, O_RDWR | O_NONBLOCK | O_CLOEXEC)) == -1 && errno == EINVAL)
#endif #endif
capBox->fd = video_open(device, O_RDWR | O_NONBLOCK); fd = video_open(path, O_RDWR | O_NONBLOCK);
if (capBox->fd == -1) if (fd == -1)
{ {
WARN("open failed (%d)\n", errno); WARN("Failed to open video device: %s\n", strerror(errno));
goto error; goto error;
} }
fcntl( capBox->fd, F_SETFD, FD_CLOEXEC ); /* in case O_CLOEXEC isn't supported */ fcntl(fd, F_SETFD, FD_CLOEXEC); /* in case O_CLOEXEC isn't supported */
device->fd = fd;
memset(&capa, 0, sizeof(capa)); if (xioctl(fd, VIDIOC_QUERYCAP, &caps) == -1)
if (xioctl(capBox->fd, VIDIOCGCAP, &capa) == -1)
{ {
WARN("ioctl(VIDIOCGCAP) failed (%d)\n", errno); WARN("Failed to query device capabilities: %s\n", strerror(errno));
goto error; goto error;
} }
if (!(capa.type & VID_TYPE_CAPTURE)) if (!(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{ {
WARN("not a video capture device\n"); WARN("Device does not support single-planar video capture.\n");
goto error; goto error;
} }
TRACE("%d inputs on %s\n", capa.channels, capa.name ); if (!(caps.capabilities & V4L2_CAP_READWRITE))
if (xioctl(capBox->fd, VIDIOCGPICT, &pict) == -1)
{ {
ERR("ioctl(VIDIOCGPICT) failed (%d)\n", errno ); WARN("Device does not support read().\n");
if (!have_libv4l2)
#ifdef SONAME_LIBV4L2
ERR_(winediag)("Reading from %s requires libv4l2, but it could not be loaded.\n", path);
#else
ERR_(winediag)("Reading from %s requires libv4l2, but Wine was compiled without libv4l2 support.\n", path);
#endif
goto error; goto error;
} }
TRACE("depth %d palette %d (%s) hue %d color %d contrast %d\n", if (negotiate_format(device) == -1)
pict.depth, pict.palette, renderlist_V4l[pict.palette].name,
pict.hue, pict.colour, pict.contrast );
capBox->dbrightness = pict.brightness;
capBox->dcolour = pict.colour;
capBox->dhue = pict.hue;
capBox->dcontrast = pict.contrast;
if (!renderlist_V4l[pict.palette].renderer)
{
int palet = pict.palette, i;
TRACE("No renderer available for %s, falling back to defaults\n",
renderlist_V4l[pict.palette].name);
capBox->renderer = NULL;
for (i = 0; fallback_V4l[i] >=0 ; i++)
{
int n = fallback_V4l[i];
if (renderlist_V4l[n].renderer == NULL)
continue;
pict.depth = renderlist_V4l[n].depth;
pict.palette = n;
if (xioctl(capBox->fd, VIDIOCSPICT, &pict) == -1)
{
TRACE("Could not render with %s (%d)\n",
renderlist_V4l[n].name, n);
continue;
}
TRACE("using renderer %s (%d)\n",
renderlist_V4l[n].name, n);
capBox->renderer = renderlist_V4l[n].renderer;
break;
}
if (!capBox->renderer)
{
ERR("video format %s isn't available\n",
renderlist_V4l[palet].name);
goto error;
}
}
else
{
TRACE("Using the suggested format\n");
capBox->renderer = renderlist_V4l[pict.palette].renderer;
}
memcpy(&capBox->pict, &pict, sizeof(struct video_picture));
memset(&window, 0, sizeof(window));
if (xioctl(capBox->fd, VIDIOCGWIN, &window) == -1)
{
WARN("VIDIOCGWIN failed (%d)\n", errno);
goto error; goto error;
}
capBox->height = capBox->outputheight = window.height; device->outputwidth = device->width;
capBox->width = capBox->outputwidth = window.width; device->outputheight = device->height;
capBox->swresize = FALSE; device->swresize = FALSE;
capBox->bitDepth = 24; device->bitDepth = 24;
capBox->pOut = pOut; device->pOut = pOut;
capBox->fps = 3; device->fps = 3;
capBox->stopped = FALSE; device->stopped = FALSE;
capBox->curframe = 0; device->iscommitted = FALSE;
capBox->iscommitted = FALSE;
TRACE("format: %d bits - %d x %d\n", capBox->bitDepth, capBox->width, capBox->height); TRACE("Format: %d bpp - %dx%d.\n", device->bitDepth, device->width, device->height);
return capBox; return device;
error: error:
if (capBox) qcap_driver_destroy(device);
qcap_driver_destroy( capBox );
return NULL; return NULL;
} }

View File

@ -32,7 +32,7 @@
#include "wine/debug.h" #include "wine/debug.h"
/* This is not used if V4L support is missing */ /* This is not used if V4L support is missing */
#if defined(HAVE_LINUX_VIDEODEV_H) || defined(HAVE_LIBV4L1_H) #ifdef HAVE_LINUX_VIDEODEV2_H
WINE_DEFAULT_DEBUG_CHANNEL(qcap); WINE_DEFAULT_DEBUG_CHANNEL(qcap);

View File

@ -411,9 +411,6 @@
/* Define to 1 if you have the <libunwind.h> header file. */ /* Define to 1 if you have the <libunwind.h> header file. */
#undef HAVE_LIBUNWIND_H #undef HAVE_LIBUNWIND_H
/* Define to 1 if you have the <libv4l1.h> header file. */
#undef HAVE_LIBV4L1_H
/* Define if you have the libxml2 library */ /* Define if you have the libxml2 library */
#undef HAVE_LIBXML2 #undef HAVE_LIBXML2
@ -501,9 +498,6 @@
/* Define to 1 if you have the <linux/videodev2.h> header file. */ /* Define to 1 if you have the <linux/videodev2.h> header file. */
#undef HAVE_LINUX_VIDEODEV2_H #undef HAVE_LINUX_VIDEODEV2_H
/* Define to 1 if you have the <linux/videodev.h> header file. */
#undef HAVE_LINUX_VIDEODEV_H
/* Define to 1 if you have the `llrint' function. */ /* Define to 1 if you have the `llrint' function. */
#undef HAVE_LLRINT #undef HAVE_LLRINT
@ -1410,8 +1404,8 @@
/* Define to the soname of the libtiff library. */ /* Define to the soname of the libtiff library. */
#undef SONAME_LIBTIFF #undef SONAME_LIBTIFF
/* Define to the soname of the libv4l1 library. */ /* Define to the soname of the libv4l2 library. */
#undef SONAME_LIBV4L1 #undef SONAME_LIBV4L2
/* Define to the soname of the libvkd3d library. */ /* Define to the soname of the libvkd3d library. */
#undef SONAME_LIBVKD3D #undef SONAME_LIBVKD3D