From f94d9f1cc5d9679cda2bf44b3a257852a29e4ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Fri, 11 Dec 2020 12:59:32 +0100 Subject: [PATCH] audiomixer: 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: --- gst/audiomixer/gstaudiointerleave.c | 6 +- gst/audiomixer/gstaudiomixer.c | 128 +----------------------- gst/audiomixer/gstaudiomixerelement.c | 42 ++++++++ gst/audiomixer/gstaudiomixerelements.h | 49 +++++++++ gst/audiomixer/gstaudiomixerplugin.c | 38 +++++++ gst/audiomixer/gstliveadder.c | 133 +++++++++++++++++++++++++ gst/audiomixer/meson.build | 3 + 7 files changed, 271 insertions(+), 128 deletions(-) create mode 100644 gst/audiomixer/gstaudiomixerelement.c create mode 100644 gst/audiomixer/gstaudiomixerelements.h create mode 100644 gst/audiomixer/gstaudiomixerplugin.c create mode 100644 gst/audiomixer/gstliveadder.c diff --git a/gst/audiomixer/gstaudiointerleave.c b/gst/audiomixer/gstaudiointerleave.c index 42ceb4aa19..037a810532 100644 --- a/gst/audiomixer/gstaudiointerleave.c +++ b/gst/audiomixer/gstaudiointerleave.c @@ -39,10 +39,8 @@ #include "config.h" #endif +#include "gstaudiomixerelements.h" #include "gstaudiointerleave.h" -#include - -#include #define GST_CAT_DEFAULT gst_audio_interleave_debug GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); @@ -55,6 +53,8 @@ enum G_DEFINE_TYPE (GstAudioInterleavePad, gst_audio_interleave_pad, GST_TYPE_AUDIO_AGGREGATOR_PAD); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (audiointerleave, "audiointerleave", + GST_RANK_NONE, GST_TYPE_AUDIO_INTERLEAVE, audiomixer_element_init (plugin)); static void gst_audio_interleave_pad_get_property (GObject * object, guint prop_id, diff --git a/gst/audiomixer/gstaudiomixer.c b/gst/audiomixer/gstaudiomixer.c index 5205e2e261..e7e4136727 100644 --- a/gst/audiomixer/gstaudiomixer.c +++ b/gst/audiomixer/gstaudiomixer.c @@ -60,15 +60,9 @@ #include "config.h" #endif -#include "gstaudiomixer.h" -#include -#include /* strcmp */ +#include "gstaudiomixerelements.h" #include "gstaudiomixerorc.h" -#include "gstaudiointerleave.h" - -#define GST_CAT_DEFAULT gst_audiomixer_debug -GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); #define DEFAULT_PAD_VOLUME (1.0) #define DEFAULT_PAD_MUTE (FALSE) @@ -95,6 +89,8 @@ enum G_DEFINE_TYPE (GstAudioMixerPad, gst_audiomixer_pad, GST_TYPE_AUDIO_AGGREGATOR_CONVERT_PAD); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (audiomixer, "audiomixer", + GST_RANK_NONE, GST_TYPE_AUDIO_MIXER, audiomixer_element_init (plugin)); static void gst_audiomixer_pad_get_property (GObject * object, guint prop_id, @@ -461,121 +457,3 @@ gst_audiomixer_child_proxy_init (gpointer g_iface, gpointer iface_data) iface->get_child_by_index = gst_audiomixer_child_proxy_get_child_by_index; iface->get_children_count = gst_audiomixer_child_proxy_get_children_count; } - -/* Empty liveadder alias with non-zero latency */ - -typedef GstAudioMixer GstLiveAdder; -typedef GstAudioMixerClass GstLiveAdderClass; - -static GType gst_live_adder_get_type (void); -#define GST_TYPE_LIVE_ADDER gst_live_adder_get_type () - -G_DEFINE_TYPE (GstLiveAdder, gst_live_adder, GST_TYPE_AUDIO_MIXER); - -enum -{ - LIVEADDER_PROP_LATENCY = 1 -}; - -static void -gst_live_adder_init (GstLiveAdder * self) -{ -} - -static void -gst_live_adder_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - switch (prop_id) { - case LIVEADDER_PROP_LATENCY: - { - GParamSpec *parent_spec = - g_object_class_find_property (G_OBJECT_CLASS - (gst_live_adder_parent_class), "latency"); - GObjectClass *pspec_class = g_type_class_peek (parent_spec->owner_type); - GValue v = { 0 }; - - g_value_init (&v, G_TYPE_UINT64); - - g_value_set_uint64 (&v, g_value_get_uint (value) * GST_MSECOND); - - G_OBJECT_CLASS (pspec_class)->set_property (object, - parent_spec->param_id, &v, parent_spec); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gst_live_adder_get_property (GObject * object, guint prop_id, GValue * value, - GParamSpec * pspec) -{ - switch (prop_id) { - case LIVEADDER_PROP_LATENCY: - { - GParamSpec *parent_spec = - g_object_class_find_property (G_OBJECT_CLASS - (gst_live_adder_parent_class), "latency"); - GObjectClass *pspec_class = g_type_class_peek (parent_spec->owner_type); - GValue v = { 0 }; - - g_value_init (&v, G_TYPE_UINT64); - - G_OBJECT_CLASS (pspec_class)->get_property (object, - parent_spec->param_id, &v, parent_spec); - - g_value_set_uint (value, g_value_get_uint64 (&v) / GST_MSECOND); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - -static void -gst_live_adder_class_init (GstLiveAdderClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->set_property = gst_live_adder_set_property; - gobject_class->get_property = gst_live_adder_get_property; - - g_object_class_install_property (gobject_class, LIVEADDER_PROP_LATENCY, - g_param_spec_uint ("latency", "Buffer latency", - "Additional latency in live mode to allow upstream " - "to take longer to produce buffers for the current " - "position (in milliseconds)", 0, G_MAXUINT, - 30, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)); -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "audiomixer", 0, - "audio mixing element"); - - if (!gst_element_register (plugin, "audiomixer", GST_RANK_NONE, - GST_TYPE_AUDIO_MIXER)) - return FALSE; - - if (!gst_element_register (plugin, "liveadder", GST_RANK_NONE, - GST_TYPE_LIVE_ADDER)) - return FALSE; - - if (!gst_element_register (plugin, "audiointerleave", GST_RANK_NONE, - GST_TYPE_AUDIO_INTERLEAVE)) - return FALSE; - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - audiomixer, - "Mixes multiple audio streams", - plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/gst/audiomixer/gstaudiomixerelement.c b/gst/audiomixer/gstaudiomixerelement.c new file mode 100644 index 0000000000..e5d3e681bd --- /dev/null +++ b/gst/audiomixer/gstaudiomixerelement.c @@ -0,0 +1,42 @@ +/* GStreamer + * Copyright (C) 1999,2000 Erik Walthinsen + * 2001 Thomas + * 2005,2006 Wim Taymans + * 2013 Sebastian Dröge + * Copyright (C) 2020 Huawei Technologies Co., Ltd. + * @Author: Stéphane Cerveau + * + * audiomixer.c: AudioMixer element, N in, one out, samples are added + * + * 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. + */ + + +#include "gstaudiomixerelements.h" + +#define GST_CAT_DEFAULT gst_audiomixer_debug +GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); + +void +audiomixer_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + if (g_once_init_enter (&res)) { + GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "audiomixer", 0, + "audio mixing element"); + g_once_init_leave (&res, TRUE); + } +} diff --git a/gst/audiomixer/gstaudiomixerelements.h b/gst/audiomixer/gstaudiomixerelements.h new file mode 100644 index 0000000000..289f07a4d6 --- /dev/null +++ b/gst/audiomixer/gstaudiomixerelements.h @@ -0,0 +1,49 @@ +/* GStreamer + * Copyright (C) 1999,2000 Erik Walthinsen + * 2001 Thomas + * 2005,2006 Wim Taymans + * 2013 Sebastian Dröge + * Copyright (C) 2020 Huawei Technologies Co., Ltd. + * @Author: Stéphane Cerveau + * + * + * 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_AUDIO_MIXER_ELEMENTS_H__ +#define __GST_AUDIO_MIXER_ELEMENTS_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "gstaudiomixer.h" +#include "gstaudiointerleave.h" + +G_BEGIN_DECLS + +G_GNUC_INTERNAL void audiomixer_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (audiomixer); +GST_ELEMENT_REGISTER_DECLARE (liveadder); +GST_ELEMENT_REGISTER_DECLARE (audiointerleave); + + +#endif /* __GST_AUDIO_MIXER_ELEMENTS_H__ */ diff --git a/gst/audiomixer/gstaudiomixerplugin.c b/gst/audiomixer/gstaudiomixerplugin.c new file mode 100644 index 0000000000..c66534254a --- /dev/null +++ b/gst/audiomixer/gstaudiomixerplugin.c @@ -0,0 +1,38 @@ +/* GStreamer + * Copyright (C) 2020 Huawei Technologies Co., Ltd. + * @Author: Stéphane Cerveau + * + * 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. + */ + +#include "gstaudiomixerelements.h" + +static gboolean +plugin_init (GstPlugin * plugin) +{ + gboolean ret = FALSE; + + ret |= GST_ELEMENT_REGISTER (audiomixer, plugin); + ret |= GST_ELEMENT_REGISTER (liveadder, plugin); + ret |= GST_ELEMENT_REGISTER (audiointerleave, plugin); + + return ret; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + audiomixer, + "Mixes multiple audio streams", + plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/gst/audiomixer/gstliveadder.c b/gst/audiomixer/gstliveadder.c new file mode 100644 index 0000000000..e770765161 --- /dev/null +++ b/gst/audiomixer/gstliveadder.c @@ -0,0 +1,133 @@ +/* GStreamer + * Copyright (C) 1999,2000 Erik Walthinsen + * 2001 Thomas + * 2005,2006 Wim Taymans + * 2013 Sebastian Dröge + * Copyright (C) 2020 Huawei Technologies Co., Ltd. + * @Author: Stéphane Cerveau + * + * audiomixer.c: AudioMixer element, N in, one out, samples are added + * + * 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. + */ +/** + * SECTION:element-liveadder + * @title: liveadder + * + * + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstaudiomixerelements.h" +#include "gstaudiomixerorc.h" + +#include "gstaudiointerleave.h" + +/* Empty liveadder alias with non-zero latency */ + +typedef GstAudioMixer GstLiveAdder; +typedef GstAudioMixerClass GstLiveAdderClass; + +static GType gst_live_adder_get_type (void); +#define GST_TYPE_LIVE_ADDER gst_live_adder_get_type () + +G_DEFINE_TYPE (GstLiveAdder, gst_live_adder, GST_TYPE_AUDIO_MIXER); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (liveadder, "liveadder", + GST_RANK_NONE, GST_TYPE_LIVE_ADDER, audiomixer_element_init (plugin)); + +enum +{ + LIVEADDER_PROP_LATENCY = 1 +}; + +static void +gst_live_adder_init (GstLiveAdder * self) +{ +} + +static void +gst_live_adder_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + switch (prop_id) { + case LIVEADDER_PROP_LATENCY: + { + GParamSpec *parent_spec = + g_object_class_find_property (G_OBJECT_CLASS + (gst_live_adder_parent_class), "latency"); + GObjectClass *pspec_class = g_type_class_peek (parent_spec->owner_type); + GValue v = { 0 }; + + g_value_init (&v, G_TYPE_UINT64); + + g_value_set_uint64 (&v, g_value_get_uint (value) * GST_MSECOND); + + G_OBJECT_CLASS (pspec_class)->set_property (object, + parent_spec->param_id, &v, parent_spec); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_live_adder_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) +{ + switch (prop_id) { + case LIVEADDER_PROP_LATENCY: + { + GParamSpec *parent_spec = + g_object_class_find_property (G_OBJECT_CLASS + (gst_live_adder_parent_class), "latency"); + GObjectClass *pspec_class = g_type_class_peek (parent_spec->owner_type); + GValue v = { 0 }; + + g_value_init (&v, G_TYPE_UINT64); + + G_OBJECT_CLASS (pspec_class)->get_property (object, + parent_spec->param_id, &v, parent_spec); + + g_value_set_uint (value, g_value_get_uint64 (&v) / GST_MSECOND); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_live_adder_class_init (GstLiveAdderClass * klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->set_property = gst_live_adder_set_property; + gobject_class->get_property = gst_live_adder_get_property; + + g_object_class_install_property (gobject_class, LIVEADDER_PROP_LATENCY, + g_param_spec_uint ("latency", "Buffer latency", + "Additional latency in live mode to allow upstream " + "to take longer to produce buffers for the current " + "position (in milliseconds)", 0, G_MAXUINT, + 30, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)); +} diff --git a/gst/audiomixer/meson.build b/gst/audiomixer/meson.build index 4e02a708de..3f82d23990 100644 --- a/gst/audiomixer/meson.build +++ b/gst/audiomixer/meson.build @@ -1,6 +1,9 @@ audiomixer_sources = [ 'gstaudiomixer.c', + 'gstaudiomixerelement.c', + 'gstliveadder.c', 'gstaudiointerleave.c', + 'gstaudiomixerplugin.c' ] orcsrc = 'gstaudiomixerorc'