diff --git a/ext/openh264/gstopenh264dec.cpp b/ext/openh264/gstopenh264dec.cpp index e608380488..e42dc093b7 100644 --- a/ext/openh264/gstopenh264dec.cpp +++ b/ext/openh264/gstopenh264dec.cpp @@ -27,6 +27,7 @@ #include "config.h" #endif +#include "gstopenh264elements.h" #include "gstopenh264dec.h" #include @@ -59,6 +60,7 @@ static GstFlowReturn gst_openh264dec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame); static gboolean gst_openh264dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query); +static gboolean openh264dec_element_init (GstPlugin * plugin); #if HAVE_OPENH264_MAIN_PROFILE #define SUPPORTED_PROFILE_STR "profile=(string){ constrained-baseline, baseline, main, high, constrained-high, progressive-high }" @@ -88,6 +90,7 @@ G_DEFINE_TYPE_WITH_CODE (GstOpenh264Dec, gst_openh264dec, GST_TYPE_VIDEO_DECODER, GST_DEBUG_CATEGORY_INIT (gst_openh264dec_debug_category, "openh264dec", 0, "debug category for openh264dec element")); +GST_ELEMENT_REGISTER_DEFINE_CUSTOM (openh264dec, openh264dec_element_init); static void gst_openh264dec_class_init (GstOpenh264DecClass * klass) @@ -448,3 +451,14 @@ gst_openh264dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) return TRUE; } + +static gboolean +openh264dec_element_init (GstPlugin * plugin) +{ + if (openh264_element_init (plugin)) + return gst_element_register (plugin, "openh264dec", GST_RANK_MARGINAL, + GST_TYPE_OPENH264DEC); + + GST_ERROR ("Incorrect library version loaded, expecting %s", g_strCodecVer); + return FALSE; +} diff --git a/ext/openh264/gstopenh264element.c b/ext/openh264/gstopenh264element.c new file mode 100644 index 0000000000..5d8f9d3767 --- /dev/null +++ b/ext/openh264/gstopenh264element.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014, Ericsson AB. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include "gstopenh264elements.h" + + +gboolean +openh264_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + + if (g_once_init_enter (&res)) { + gsize value; + OpenH264Version libver; + /* g_stCodecVersion is the version detected at build time as defined in the + * headers and WelsGetCodecVersion() is the version detected at runtime. + * This is a safeguard to avoid crashes since OpenH264 has been changing + * ABI without changing the SONAME. + */ + libver = WelsGetCodecVersion (); + value = memcmp (&libver, &g_stCodecVersion, sizeof (libver)) == 0; + g_once_init_leave (&res, value); + } + + return res; +} diff --git a/ext/openh264/gstopenh264elements.h b/ext/openh264/gstopenh264elements.h new file mode 100644 index 0000000000..572f6a8e07 --- /dev/null +++ b/ext/openh264/gstopenh264elements.h @@ -0,0 +1,37 @@ +/* GStreamer + * Copyright (C) <2020> The GStreamer Contributors. + * + * 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_OPENH264_ELEMENT_H__ +#define __GST_OPENH264_ELEMENT_H__ + +#include + +#include + +G_BEGIN_DECLS + +gboolean openh264_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (openh264dec); +GST_ELEMENT_REGISTER_DECLARE (openh264enc); + +G_END_DECLS + +#endif /* __GST_OPENH264_ELEMENT_H__ */ diff --git a/ext/openh264/gstopenh264enc.cpp b/ext/openh264/gstopenh264enc.cpp index 0f054592d1..dff3db6dd9 100644 --- a/ext/openh264/gstopenh264enc.cpp +++ b/ext/openh264/gstopenh264enc.cpp @@ -27,6 +27,7 @@ #include "config.h" #endif +#include "gstopenh264elements.h" #include "gstopenh264enc.h" #include @@ -162,6 +163,7 @@ static void gst_openh264enc_set_usage_type (GstOpenh264Enc * openh264enc, gint usage_type); static void gst_openh264enc_set_rate_control (GstOpenh264Enc * openh264enc, gint rc_mode); +static gboolean openh264enc_element_init (GstPlugin * plugin); #define DEFAULT_BITRATE (128000) @@ -235,6 +237,7 @@ G_DEFINE_TYPE_WITH_CODE (GstOpenh264Enc, gst_openh264enc, G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL); GST_DEBUG_CATEGORY_INIT (gst_openh264enc_debug_category, "openh264enc", 0, "debug category for openh264enc element")); +GST_ELEMENT_REGISTER_DEFINE_CUSTOM (openh264enc, openh264enc_element_init); static void gst_openh264enc_class_init (GstOpenh264EncClass * klass) @@ -1056,3 +1059,13 @@ gst_openh264enc_finish (GstVideoEncoder * encoder) return GST_FLOW_OK; } +static gboolean +openh264enc_element_init (GstPlugin * plugin) +{ + if (openh264_element_init (plugin)) + return gst_element_register (plugin, "openh264enc", GST_RANK_MARGINAL, + GST_TYPE_OPENH264ENC); + + GST_ERROR ("Incorrect library version loaded, expecting %s", g_strCodecVer); + return FALSE; +} diff --git a/ext/openh264/gstopenh264plugin.c b/ext/openh264/gstopenh264plugin.c index d659a488c8..715241ee17 100644 --- a/ext/openh264/gstopenh264plugin.c +++ b/ext/openh264/gstopenh264plugin.c @@ -31,31 +31,18 @@ #include #endif -#include -#include -#include -#include -#include "gstopenh264dec.h" -#include "gstopenh264enc.h" +#include "gstopenh264elements.h" + static gboolean plugin_init (GstPlugin * plugin) { - /* g_stCodecVersion is the version detected at build time as defined in the - * headers and WelsGetCodecVersion() is the version detected at runtime. - * This is a safeguard to avoid crashes since OpenH264 has been changing - * ABI without changing the SONAME. - */ - OpenH264Version libver = WelsGetCodecVersion (); - if (memcmp (&libver, &g_stCodecVersion, sizeof (libver)) == 0) { - gst_element_register (plugin, "openh264dec", GST_RANK_MARGINAL, - GST_TYPE_OPENH264DEC); - gst_element_register (plugin, "openh264enc", GST_RANK_MARGINAL, - GST_TYPE_OPENH264ENC); - } else { - GST_ERROR ("Incorrect library version loaded, expecting %s", g_strCodecVer); - } - return TRUE; + gboolean ret = FALSE; + + ret |= GST_ELEMENT_REGISTER (openh264dec, plugin); + ret |= GST_ELEMENT_REGISTER (openh264enc, plugin); + + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/openh264/meson.build b/ext/openh264/meson.build index 7f893cf91f..6147f9e3da 100644 --- a/ext/openh264/meson.build +++ b/ext/openh264/meson.build @@ -1,6 +1,7 @@ openh264_sources = [ 'gstopenh264dec.cpp', 'gstopenh264enc.cpp', + 'gstopenh264element.c', 'gstopenh264plugin.c', ]