[vlc-devel] [PATCH] add V4L2 video_output module
Rémi Denis-Courmont
remi at remlab.net
Tue Jan 17 19:16:36 CET 2012
Le lundi 16 janvier 2012 00:08:02 Francois Cartegnie, vous avez écrit :
> ---
> configure.ac | 5 +
> modules/video_output/Modules.am | 3 +
> modules/video_output/v4l2_output.c | 650
> ++++++++++++++++++++++++++++++++++++ 3 files changed, 658 insertions(+), 0
> deletions(-)
> create mode 100644 modules/video_output/v4l2_output.c
>
> diff --git a/configure.ac b/configure.ac
> index e6b30ed..0583033 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1840,6 +1840,8 @@ AC_ARG_ENABLE(libv4l2,
> [AS_HELP_STRING([--disable-libv4l2], [disable userspace V4L2 library
> (default auto)])])
> AC_ARG_ENABLE(pvr, [AS_HELP_STRING([--enable-pvr],
> [support PVR V4L2 cards (default disabled)])])
> +AC_ARG_ENABLE(v4l2_output, [AS_HELP_STRING([--enable-v4l2out],
> + [support V4L2 output (default auto)])])
> have_v4l2="no"
> AC_CHECK_HEADERS([linux/videodev2.h sys/videoio.h], [
> have_v4l2="yes"
> @@ -1855,6 +1857,9 @@ AS_IF([test "$have_v4l2" = "yes"], [
> AS_IF([test "${enable_pvr}" = "yes"], [
> VLC_ADD_PLUGIN([pvr])
> ])
> + AS_IF([test "${enable_v4l2out}" != "no"], [
> + VLC_ADD_PLUGIN([v4l2_output])
> + ])
I still don't see the point.
> ])
> AM_CONDITIONAL(HAVE_V4L2, [test "${have_v4l2}" != "no"])
>
> diff --git a/modules/video_output/Modules.am
> b/modules/video_output/Modules.am index 1c26b92..f40481b 100644
> --- a/modules/video_output/Modules.am
> +++ b/modules/video_output/Modules.am
> @@ -14,6 +14,9 @@ SOURCES_yuv = yuv.c
> SOURCES_vout_macosx = macosx.m opengl.h opengl.c
> SOURCES_vout_ios = ios.m opengl.h opengl.c
> SOURCES_android_surface = androidsurface.c
> +SOURCES_v4l2_output = v4l2_output.c \
> + ../access/v4l2/v4l2_common.c \
> + ../access/v4l2/v4l2_common.h
>
> ### OpenGL ###
> # TODO: merge all three source files (?)
> diff --git a/modules/video_output/v4l2_output.c
> b/modules/video_output/v4l2_output.c new file mode 100644
> index 0000000..8b18d64
> --- /dev/null
> +++ b/modules/video_output/v4l2_output.c
> @@ -0,0 +1,650 @@
> +/*************************************************************************
> **** + * v4l2_output.c : V4L2 output module for vlc
> +
> **************************************************************************
> *** + * Copyright (C) 2012 the VideoLAN team
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
> 02110-1301, USA. +
> **************************************************************************
> ***/ +
> +#ifdef HAVE_CONFIG_H
> +# include <config.h>
> +#endif
> +
> +#include <stdarg.h>
> +#include <assert.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <fcntl.h>
> +#include <sys/ioctl.h>
> +#include <errno.h>
> +#include <sys/mman.h>
> +
> +#include <vlc_common.h>
> +#include <vlc_plugin.h>
> +#include <vlc_vout_display.h>
> +#include <vlc_picture_pool.h>
> +
> +#include "../access/v4l2/v4l2.h"
> +#include "../access/v4l2/v4l2_common.h"
> +
> +#define V4L2_DEVICE_TEXT N_("Device")
> +#define V4L2_DEVICE_LONGTEXT N_("V4L2 output device")
> +#define V4L2_PROFILE_TEXT N_("Loopback application profile")
> +#define V4L2_PROFILE_LONGTEXT N_("Profile (chroma + size) for special apps
> using v4l2loopback") +#define V4L2_CHROMA_TEXT N_("Chroma used")
> +#define V4L2_CHROMA_LONGTEXT N_("Force use of a specific chroma for
> output. Default is I420.") +
> +#define CFG_PREFIX "v4l2_output_"
> +
> +struct vout_display_sys_t {
> + picture_pool_t *pool;
> + int fd;
> + int i_imagesize;
Probably wrong type.
> + bool b_streaming;
> + struct buffer_t *buffers;
> + int (* poollock)(picture_t *);
> + int i_buffers;
> +};
> +
> +struct picture_sys_t {
> + vout_display_sys_t *p_vdsys;
> + int i_target_buffer;
> + bool b_buffer_ready;
> +};
> +
> +static int Open (vlc_object_t *);
> +static void Close(vlc_object_t *);
> +
> +static picture_pool_t *Pool (vout_display_t *, unsigned);
> +static int MMAPPoolLock(picture_t *);
> +static void PictureDisplayRW(vout_display_t *, picture_t *,
> subpicture_t *); +static void PictureDisplayMMAP(vout_display_t
> *, picture_t *, subpicture_t *); +static int
> Control(vout_display_t *, int, va_list);
> +
> +static const char * const psz_profiles_texts[] = { N_("None"),
> N_("Skype"), N_("Flash Plugin") }; +static const char * const
> psz_profiles_values[] = { NULL, "skype", "flashplugin" }; +
> +/*
> + * Module descriptor
> + */
> +vlc_module_begin ()
> + set_shortname (N_("V4L2 Output"))
> + set_description (N_("V4L2 Output"))
> + set_category (CAT_VIDEO)
> + set_subcategory (SUBCAT_VIDEO_VOUT)
> + set_capability ("vout display", 0)
> + set_callbacks (Open, Close)
> + add_string(CFG_PREFIX "dev", "/dev/video0", V4L2_DEVICE_TEXT,
> V4L2_DEVICE_LONGTEXT, false)
> + add_string(CFG_PREFIX "profile",
> NULL, V4L2_PROFILE_TEXT, V4L2_PROFILE_LONGTEXT, true)
> +
> change_string_list( psz_profiles_values, psz_profiles_texts, 0 )
I don't think this makes no sense. The format restrictions depend on the
hardware, and retrieved through the V4L2 device driver.
+
> add_string(CFG_PREFIX "chroma", NULL, V4L2_CHROMA_TEXT,
> V4L2_CHROMA_LONGTEXT, true)
This does not make much sense either. Laurent spent some time to define proper
chroma negotiation to aovid this.
> +vlc_module_end ()
> +
> +/* applications profiles for v4l2loopback output */
> +static struct {
> + const char const * psz_name;
> + const int i_width;
> + const int i_height;
> + const int i_chroma;
> +} const app_profiles[] = {
> + /* apps requested profiles */
> + { "skype", 640, 480, V4L2_PIX_FMT_YUV420 },
> + { "flashplugin", 0, 0, V4L2_PIX_FMT_RGB32 },
> + { NULL, 0, 0, 0 }
> +};
> +
> +/* same/from v4l2 access IsPixelFormatSupported() */
> +static bool is_fallback_v4l2_chroma( uint32_t i_pixelformat )
> +{
> + static const uint32_t const p_chroma_fallbacks[] =
> + {
> + V4L2_PIX_FMT_YUV420,
> + V4L2_PIX_FMT_YVU420,
> + V4L2_PIX_FMT_YUV422P,
> + V4L2_PIX_FMT_YUYV,
> + V4L2_PIX_FMT_UYVY,
> + V4L2_PIX_FMT_BGR24,
> + V4L2_PIX_FMT_BGR32
> + // minus mjpeg/jpeg
> + };
I think we have common core functions for this.
--
Rémi Denis-Courmont
http://www.remlab.net/
http://fi.linkedin.com/in/remidenis
More information about the vlc-devel
mailing list