v4l2: allow per feature registration

Split plugin into features including
dynamic types which can be indiviually
registered during a static build.

More details here:

https://gitlab.freedesktop.org/gstreamer/gst-build/-/merge_requests/199
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/661

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/876>
This commit is contained in:
Stéphane Cerveau 2021-02-16 15:29:06 +01:00
parent 7cd54ccfc1
commit b20209ce0d
8 changed files with 110 additions and 25 deletions

View file

@ -40,6 +40,7 @@
#include <unistd.h>
#include "ext/videodev2.h"
#include "gstv4l2elements.h"
#include "v4l2-utils.h"
#include "gstv4l2object.h"
@ -55,13 +56,8 @@
#include "gstv4l2mpeg4enc.h"
#include "gstv4l2vp8enc.h"
#include "gstv4l2vp9enc.h"
#include "gstv4l2deviceprovider.h"
#include "gstv4l2transform.h"
/* used in gstv4l2object.c and v4l2_calls.c */
GST_DEBUG_CATEGORY (v4l2_debug);
#define GST_CAT_DEFAULT v4l2_debug
#ifdef GST_V4L2_ENABLE_PROBE
/* This is a minimalist probe, for speed, we only enumerate formats */
static GstCaps *
@ -248,37 +244,25 @@ gst_v4l2_probe_and_register (GstPlugin * plugin)
static gboolean
plugin_init (GstPlugin * plugin)
{
gboolean ret = FALSE;
const gchar *paths[] = { "/dev", "/dev/v4l2", NULL };
const gchar *names[] = { "video", NULL };
GST_DEBUG_CATEGORY_INIT (v4l2_debug, "v4l2", 0, "V4L2 API calls");
/* Add some dependency, so the dynamic features get updated upon changes in
* /dev/video* */
gst_plugin_add_dependency (plugin,
NULL, paths, names, GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_PREFIX);
if (!gst_element_register (plugin, "v4l2src", GST_RANK_PRIMARY,
GST_TYPE_V4L2SRC) ||
!gst_element_register (plugin, "v4l2sink", GST_RANK_NONE,
GST_TYPE_V4L2SINK) ||
!gst_element_register (plugin, "v4l2radio", GST_RANK_NONE,
GST_TYPE_V4L2RADIO) ||
!gst_device_provider_register (plugin, "v4l2deviceprovider",
GST_RANK_PRIMARY, GST_TYPE_V4L2_DEVICE_PROVIDER)
/* etc. */
#ifdef GST_V4L2_ENABLE_PROBE
|| !gst_v4l2_probe_and_register (plugin)
ret |= gst_v4l2_probe_and_register (plugin);
#endif
)
return FALSE;
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif /* ENABLE_NLS */
ret |= GST_ELEMENT_REGISTER (v4l2src, plugin);
ret |= GST_ELEMENT_REGISTER (v4l2sink, plugin);
ret |= GST_ELEMENT_REGISTER (v4l2radio, plugin);
ret |= GST_DEVICE_PROVIDER_REGISTER (v4l2deviceprovider, plugin);
return TRUE;
return ret;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,

View file

@ -32,6 +32,7 @@
#include "gstv4l2object.h"
#include "v4l2-utils.h"
#include "gstv4l2elements.h"
#ifdef HAVE_GUDEV
#include <gudev/gudev.h>
@ -44,6 +45,8 @@ static GstV4l2Device *gst_v4l2_device_new (const gchar * device_path,
G_DEFINE_TYPE (GstV4l2DeviceProvider, gst_v4l2_device_provider,
GST_TYPE_DEVICE_PROVIDER);
GST_DEVICE_PROVIDER_REGISTER_DEFINE (v4l2deviceprovider, "v4l2deviceprovider",
GST_RANK_PRIMARY, GST_TYPE_V4L2_DEVICE_PROVIDER);
static void gst_v4l2_device_provider_finalize (GObject * object);
static GList *gst_v4l2_device_provider_probe (GstDeviceProvider * provider);

50
sys/v4l2/gstv4l2element.c Normal file
View file

@ -0,0 +1,50 @@
/* GStreamer
*
* Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
* 2006 Edgard Lima <edgard.lima@gmail.com>
*
* gstv4l2.c: plugin for v4l2 elements
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gst/gst-i18n-plugin.h"
#include <gst/gst.h>
#include "gstv4l2elements.h"
/* used in gstv4l2object.c and v4l2_calls.c */
GST_DEBUG_CATEGORY (v4l2_debug);
#define GST_CAT_DEFAULT v4l2_debug
void
v4l2_element_init (GstPlugin * plugin)
{
static gsize res = FALSE;
if (g_once_init_enter (&res)) {
GST_DEBUG_CATEGORY_INIT (v4l2_debug, "v4l2", 0, "V4L2 API calls");
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif /* ENABLE_NLS */
g_once_init_leave (&res, TRUE);
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 Julian Bouzas <julian.bouzas@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __GST_V4L2_ELEMENTS_H__
#define __GST_V4L2_ELEMENTS_H__
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
G_BEGIN_DECLS
void v4l2_element_init (GstPlugin * plugin);
GST_ELEMENT_REGISTER_DECLARE (v4l2radio);
GST_ELEMENT_REGISTER_DECLARE (v4l2sink);
GST_ELEMENT_REGISTER_DECLARE (v4l2src);
GST_DEVICE_PROVIDER_REGISTER_DECLARE (v4l2deviceprovider);
G_END_DECLS
#endif /* __GST_V4L2_ELEMENTS_H__ */

View file

@ -44,6 +44,7 @@
#include "gst/gst-i18n-plugin.h"
#include "gstv4l2elements.h"
#include "gstv4l2object.h"
#include "gstv4l2tuner.h"
#include "gstv4l2radio.h"
@ -273,6 +274,8 @@ G_DEFINE_TYPE_WITH_CODE (GstV4l2Radio, gst_v4l2radio, GST_TYPE_ELEMENT,
gst_v4l2radio_uri_handler_init);
G_IMPLEMENT_INTERFACE (GST_TYPE_TUNER,
gst_v4l2radio_tuner_interface_reinit));
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (v4l2radio,
"v4l2radio", GST_RANK_NONE, GST_TYPE_V4L2RADIO, v4l2_element_init (plugin));
static void gst_v4l2radio_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);

View file

@ -59,6 +59,7 @@
#include "gstv4l2tuner.h"
#include "gstv4l2vidorient.h"
#include "gstv4l2elements.h"
#include "gstv4l2sink.h"
#include "gst/gst-i18n-plugin.h"
@ -95,7 +96,8 @@ G_DEFINE_TYPE_WITH_CODE (GstV4l2Sink, gst_v4l2sink, GST_TYPE_VIDEO_SINK,
gst_v4l2sink_color_balance_interface_init);
G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_ORIENTATION,
gst_v4l2sink_video_orientation_interface_init));
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (v4l2sink,
"v4l2sink", GST_RANK_NONE, GST_TYPE_V4L2SINK, v4l2_element_init (plugin));
static void gst_v4l2sink_finalize (GstV4l2Sink * v4l2sink);

View file

@ -54,6 +54,7 @@
#include <gst/video/gstvideometa.h>
#include <gst/video/gstvideopool.h>
#include "gstv4l2elements.h"
#include "gstv4l2src.h"
#include "gstv4l2colorbalance.h"
@ -98,6 +99,8 @@ G_DEFINE_TYPE_WITH_CODE (GstV4l2Src, gst_v4l2src, GST_TYPE_PUSH_SRC,
gst_v4l2src_color_balance_interface_init);
G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_ORIENTATION,
gst_v4l2src_video_orientation_interface_init));
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (v4l2src,
"v4l2src", GST_RANK_PRIMARY, GST_TYPE_V4L2SRC, v4l2_element_init (plugin));
struct PreferredCapsInfo
{

View file

@ -1,5 +1,6 @@
v4l2_sources = [
'gstv4l2.c',
'gstv4l2element.c',
'gstv4l2allocator.c',
'gstv4l2codec.c',
'gstv4l2colorbalance.c',