From 4f16edf0d07e5fd42221d5e3727c6d5aa548cdb7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 24 Feb 2021 12:52:08 +0100 Subject: [PATCH] srtp: 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: --- ext/srtp/gstsrtp.c | 23 ----------------- ext/srtp/gstsrtpdec.c | 22 +++++----------- ext/srtp/gstsrtpdec.h | 1 - ext/srtp/gstsrtpelement.c | 41 ++++++++++++++++++++++++++++++ ext/srtp/gstsrtpelements.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++ ext/srtp/gstsrtpenc.c | 19 ++++---------- ext/srtp/gstsrtpenc.h | 2 -- ext/srtp/gstsrtpplugin.c | 45 +++++++++++++++++++++++++++++++++ ext/srtp/meson.build | 2 ++ 9 files changed, 162 insertions(+), 56 deletions(-) create mode 100644 ext/srtp/gstsrtpelement.c create mode 100644 ext/srtp/gstsrtpelements.h create mode 100644 ext/srtp/gstsrtpplugin.c diff --git a/ext/srtp/gstsrtp.c b/ext/srtp/gstsrtp.c index b607b2c..5a34945 100644 --- a/ext/srtp/gstsrtp.c +++ b/ext/srtp/gstsrtp.c @@ -297,26 +297,3 @@ cipher_key_size (GstSrtpCipherType cipher) return size; } - -static gboolean -plugin_init (GstPlugin * plugin) -{ - srtp_init (); - - if (!gst_srtp_enc_plugin_init (plugin)) - return FALSE; - - if (!gst_srtp_dec_plugin_init (plugin)) - return FALSE; - - gst_type_mark_as_plugin_api (GST_TYPE_SRTP_AUTH_TYPE, 0); - gst_type_mark_as_plugin_api (GST_TYPE_SRTP_CIPHER_TYPE, 0); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - srtp, - "GStreamer SRTP", - plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/ext/srtp/gstsrtpdec.c b/ext/srtp/gstsrtpdec.c index 6d19299..f688d62 100644 --- a/ext/srtp/gstsrtpdec.c +++ b/ext/srtp/gstsrtpdec.c @@ -115,8 +115,8 @@ * */ +#include "gstsrtpelements.h" #include "gstsrtpdec.h" - #include #include @@ -177,7 +177,11 @@ GST_STATIC_PAD_TEMPLATE ("rtcp_src", static guint gst_srtp_dec_signals[LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE (GstSrtpDec, gst_srtp_dec, GST_TYPE_ELEMENT); +G_DEFINE_TYPE_WITH_CODE (GstSrtpDec, gst_srtp_dec, GST_TYPE_ELEMENT, + GST_DEBUG_CATEGORY_INIT (gst_srtp_dec_debug, "srtpdec", 0, "SRTP dec"); + ); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (srtpdec, "srtpdec", GST_RANK_NONE, + GST_TYPE_SRTP_DEC, srtp_element_init (plugin)); static void gst_srtp_dec_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); @@ -1570,17 +1574,3 @@ gst_srtp_dec_change_state (GstElement * element, GstStateChange transition) } return res; } - - -/* entry point to initialize the plug-in - * initialize the plug-in itself - * register the element factories and other features - */ -gboolean -gst_srtp_dec_plugin_init (GstPlugin * srtpdec) -{ - GST_DEBUG_CATEGORY_INIT (gst_srtp_dec_debug, "srtpdec", 0, "SRTP dec"); - - return gst_element_register (srtpdec, "srtpdec", GST_RANK_NONE, - GST_TYPE_SRTP_DEC); -} diff --git a/ext/srtp/gstsrtpdec.h b/ext/srtp/gstsrtpdec.h index ba8bcff..5b46f6c 100644 --- a/ext/srtp/gstsrtpdec.h +++ b/ext/srtp/gstsrtpdec.h @@ -98,7 +98,6 @@ struct _GstSrtpDecClass GType gst_srtp_dec_get_type (void); -gboolean gst_srtp_dec_plugin_init (GstPlugin * plugin); G_END_DECLS diff --git a/ext/srtp/gstsrtpelement.c b/ext/srtp/gstsrtpelement.c new file mode 100644 index 0000000..231b70d --- /dev/null +++ b/ext/srtp/gstsrtpelement.c @@ -0,0 +1,41 @@ +/* + * GStreamer - GStreamer SRTP encoder and decoder + * + * Copyright 2009-2013 Collabora Ltd. + * @author: Gabriel Millaire + * @author: Olivier Crete + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#define GLIB_DISABLE_DEPRECATION_WARNINGS + +#include "gstsrtpelements.h" + + +void +srtp_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + + if (g_once_init_enter (&res)) { + srtp_init (); + gst_type_mark_as_plugin_api (GST_TYPE_SRTP_AUTH_TYPE, 0); + gst_type_mark_as_plugin_api (GST_TYPE_SRTP_CIPHER_TYPE, 0); + g_once_init_leave (&res, TRUE); + } +} diff --git a/ext/srtp/gstsrtpelements.h b/ext/srtp/gstsrtpelements.h new file mode 100644 index 0000000..0a223fb --- /dev/null +++ b/ext/srtp/gstsrtpelements.h @@ -0,0 +1,63 @@ +/* + * GStreamer - GStreamer SRTP encoder + * + * Copyright 2011-2013 Collabora Ltd. + * @author: Olivier Crete + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef __GST_SRTP_ELEMENTS_H__ +#define __GST_SRTP_ELEMENTS_H__ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "gstsrtp.h" +#include "gstsrtpenums.h" +#include "gstsrtp-enumtypes.h" + +#include + +void srtp_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (srtpdec); +GST_ELEMENT_REGISTER_DECLARE (srtpenc); + +#endif /* __GST_SRTP_ELEMENTS_H__ */ diff --git a/ext/srtp/gstsrtpenc.c b/ext/srtp/gstsrtpenc.c index d677afc..5e17f2c 100644 --- a/ext/srtp/gstsrtpenc.c +++ b/ext/srtp/gstsrtpenc.c @@ -106,6 +106,7 @@ * will be added to every buffer. */ +#include "gstsrtpelements.h" #include "gstsrtpenc.h" #include @@ -201,7 +202,10 @@ GST_STATIC_PAD_TEMPLATE ("rtcp_src_%u", GST_STATIC_CAPS ("application/x-srtcp") ); -G_DEFINE_TYPE (GstSrtpEnc, gst_srtp_enc, GST_TYPE_ELEMENT); +G_DEFINE_TYPE_WITH_CODE (GstSrtpEnc, gst_srtp_enc, GST_TYPE_ELEMENT, + GST_DEBUG_CATEGORY_INIT (gst_srtp_enc_debug, "srtpenc", 0, "SRTP Enc");); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (srtpenc, "srtpenc", GST_RANK_NONE, + GST_TYPE_SRTP_ENC, srtp_element_init (plugin)); static guint gst_srtp_enc_signals[LAST_SIGNAL] = { 0 }; @@ -1492,16 +1496,3 @@ gst_srtp_enc_sink_event_rtcp (GstPad * pad, GstObject * parent, { return gst_srtp_enc_sink_event (pad, parent, event, TRUE); } - -/* entry point to initialize the plug-in - * initialize the plug-in itself - * register the element factories and other features - */ -gboolean -gst_srtp_enc_plugin_init (GstPlugin * srtpenc) -{ - GST_DEBUG_CATEGORY_INIT (gst_srtp_enc_debug, "srtpenc", 0, "SRTP Enc"); - - return gst_element_register (srtpenc, "srtpenc", GST_RANK_NONE, - GST_TYPE_SRTP_ENC); -} diff --git a/ext/srtp/gstsrtpenc.h b/ext/srtp/gstsrtpenc.h index df2f8fd..ed02df4 100644 --- a/ext/srtp/gstsrtpenc.h +++ b/ext/srtp/gstsrtpenc.h @@ -95,8 +95,6 @@ struct _GstSrtpEncClass GType gst_srtp_enc_get_type (void); -gboolean gst_srtp_enc_plugin_init (GstPlugin * plugin); - G_END_DECLS #endif /* __GST_SRTPENC_H__ */ diff --git a/ext/srtp/gstsrtpplugin.c b/ext/srtp/gstsrtpplugin.c new file mode 100644 index 0000000..7fb6269 --- /dev/null +++ b/ext/srtp/gstsrtpplugin.c @@ -0,0 +1,45 @@ +/* + * GStreamer - GStreamer SRTP encoder and decoder + * + * Copyright 2009-2013 Collabora Ltd. + * @author: Gabriel Millaire + * @author: Olivier Crete + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#define GLIB_DISABLE_DEPRECATION_WARNINGS + +#include "gstsrtpelements.h" + + +static gboolean +plugin_init (GstPlugin * plugin) +{ + gboolean ret = FALSE; + + ret |= GST_ELEMENT_REGISTER (srtpenc, plugin); + ret |= GST_ELEMENT_REGISTER (srtpdec, plugin); + + return ret; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + srtp, + "GStreamer SRTP", + plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/ext/srtp/meson.build b/ext/srtp/meson.build index affdac3..7f94719 100644 --- a/ext/srtp/meson.build +++ b/ext/srtp/meson.build @@ -1,5 +1,7 @@ srtp_sources = [ 'gstsrtp.c', + 'gstsrtpelement.c', + 'gstsrtpplugin.c', 'gstsrtpdec.c', 'gstsrtpenc.c', ] -- 2.7.4