diff --git a/ext/webrtcdsp/gstwebrtcdsp.cpp b/ext/webrtcdsp/gstwebrtcdsp.cpp index 87de1bcfc2..27b286fa5f 100644 --- a/ext/webrtcdsp/gstwebrtcdsp.cpp +++ b/ext/webrtcdsp/gstwebrtcdsp.cpp @@ -274,7 +274,11 @@ struct _GstWebrtcDsp webrtc::VoiceDetection::Likelihood voice_detection_likelihood; }; -G_DEFINE_TYPE (GstWebrtcDsp, gst_webrtc_dsp, GST_TYPE_AUDIO_FILTER); +G_DEFINE_TYPE_WITH_CODE (GstWebrtcDsp, gst_webrtc_dsp, GST_TYPE_AUDIO_FILTER, + GST_DEBUG_CATEGORY_INIT (webrtc_dsp_debug, "webrtcdsp", 0, + "libwebrtcdsp wrapping elements");); +GST_ELEMENT_REGISTER_DEFINE (webrtcdsp, "webrtcdsp", GST_RANK_NONE, + GST_TYPE_WEBRTC_DSP); static const gchar * webrtc_error_to_string (gint err) @@ -1118,27 +1122,3 @@ gst_webrtc_dsp_class_init (GstWebrtcDspClass * klass) gst_type_mark_as_plugin_api (GST_TYPE_WEBRTC_ECHO_SUPPRESSION_LEVEL, (GstPluginAPIFlags) 0); gst_type_mark_as_plugin_api (GST_TYPE_WEBRTC_VOICE_DETECTION_LIKELIHOOD, (GstPluginAPIFlags) 0); } - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT - (webrtc_dsp_debug, "webrtcdsp", 0, "libwebrtcdsp wrapping elements"); - - if (!gst_element_register (plugin, "webrtcdsp", GST_RANK_NONE, - GST_TYPE_WEBRTC_DSP)) { - return FALSE; - } - if (!gst_element_register (plugin, "webrtcechoprobe", GST_RANK_NONE, - GST_TYPE_WEBRTC_ECHO_PROBE)) { - return FALSE; - } - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - webrtcdsp, - "Voice pre-processing using WebRTC Audio Processing Library", - plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/ext/webrtcdsp/gstwebrtcdsp.h b/ext/webrtcdsp/gstwebrtcdsp.h index 12a9415f6f..2074659230 100644 --- a/ext/webrtcdsp/gstwebrtcdsp.h +++ b/ext/webrtcdsp/gstwebrtcdsp.h @@ -52,6 +52,8 @@ struct _GstWebrtcDspClass GType gst_webrtc_dsp_get_type (void); +GST_ELEMENT_REGISTER_DECLARE (webrtcdsp); + G_END_DECLS #endif /* __GST_WEBRTC_DSP_H__ */ diff --git a/ext/webrtcdsp/gstwebrtcdspplugin.cpp b/ext/webrtcdsp/gstwebrtcdspplugin.cpp new file mode 100644 index 0000000000..cec0a05f41 --- /dev/null +++ b/ext/webrtcdsp/gstwebrtcdspplugin.cpp @@ -0,0 +1,90 @@ +/* + * WebRTC Audio Processing Elements + * + * Copyright 2016 Collabora Ltd + * @author: Nicolas Dufresne + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * SECTION:element-webrtcdsp + * @short_description: Audio Filter using WebRTC Audio Processing library + * + * A voice enhancement filter based on WebRTC Audio Processing library. This + * library provides a whide variety of enhancement algorithms. This element + * tries to enable as much as possible. The currently enabled enhancements are + * High Pass Filter, Echo Canceller, Noise Suppression, Automatic Gain Control, + * and some extended filters. + * + * While webrtcdsp element can be used alone, there is an exception for the + * echo canceller. The audio canceller need to be aware of the far end streams + * that are played to loud speakers. For this, you must place a webrtcechoprobe + * element at that far end. Note that the sample rate must match between + * webrtcdsp and the webrtechoprobe. Though, the number of channels can differ. + * The probe is found by the DSP element using it's object name. By default, + * webrtcdsp looks for webrtcechoprobe0, which means it just work if you have + * a single probe and DSP. + * + * The probe can only be used within the same top level GstPipeline. + * Additionally, to simplify the code, the probe element must be created + * before the DSP sink pad is activated. It does not need to be in any + * particular state and does not even need to be added to the pipeline yet. + * + * # Example launch line + * + * As a convenience, the echo canceller can be tested using an echo loop. In + * this configuration, one would expect a single echo to be heard. + * + * |[ + * gst-launch-1.0 pulsesrc ! webrtcdsp ! webrtcechoprobe ! pulsesink + * ]| + * + * In real environment, you'll place the probe before the playback, but only + * process the far end streams. The DSP should be placed as close as possible + * to the audio capture. The following pipeline is astracted and does not + * represent a real pipeline. + * + * |[ + * gst-launch-1.0 far-end-src ! audio/x-raw,rate=48000 ! webrtcechoprobe ! pulsesink \ + * pulsesrc ! audio/x-raw,rate=48000 ! webrtcdsp ! far-end-sink + * ]| + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstwebrtcdsp.h" +#include "gstwebrtcechoprobe.h" + + +static gboolean +plugin_init (GstPlugin * plugin) +{ + gboolean ret = FALSE; + + ret |= GST_ELEMENT_REGISTER (webrtcdsp, plugin); + ret |= GST_ELEMENT_REGISTER (webrtcechoprobe, plugin); + + return ret; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + webrtcdsp, + "Voice pre-processing using WebRTC Audio Processing Library", + plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/ext/webrtcdsp/gstwebrtcechoprobe.cpp b/ext/webrtcdsp/gstwebrtcechoprobe.cpp index cfa5b55b2f..acdb3d8a7d 100644 --- a/ext/webrtcdsp/gstwebrtcechoprobe.cpp +++ b/ext/webrtcdsp/gstwebrtcechoprobe.cpp @@ -78,6 +78,8 @@ static GList *gst_aec_probes = NULL; G_DEFINE_TYPE (GstWebrtcEchoProbe, gst_webrtc_echo_probe, GST_TYPE_AUDIO_FILTER); +GST_ELEMENT_REGISTER_DEFINE (webrtcechoprobe, "webrtcechoprobe", + GST_RANK_NONE, GST_TYPE_WEBRTC_ECHO_PROBE); static gboolean gst_webrtc_echo_probe_setup (GstAudioFilter * filter, const GstAudioInfo * info) diff --git a/ext/webrtcdsp/gstwebrtcechoprobe.h b/ext/webrtcdsp/gstwebrtcechoprobe.h index 29f0eb4caf..36fd34f179 100644 --- a/ext/webrtcdsp/gstwebrtcechoprobe.h +++ b/ext/webrtcdsp/gstwebrtcechoprobe.h @@ -87,6 +87,8 @@ struct _GstWebrtcEchoProbeClass GType gst_webrtc_echo_probe_get_type (void); +GST_ELEMENT_REGISTER_DECLARE (webrtcechoprobe); + GstWebrtcEchoProbe *gst_webrtc_acquire_echo_probe (const gchar * name); void gst_webrtc_release_echo_probe (GstWebrtcEchoProbe * probe); gint gst_webrtc_echo_probe_read (GstWebrtcEchoProbe * self, diff --git a/ext/webrtcdsp/meson.build b/ext/webrtcdsp/meson.build index 45c020fc33..c42cc9091a 100644 --- a/ext/webrtcdsp/meson.build +++ b/ext/webrtcdsp/meson.build @@ -1,6 +1,7 @@ webrtc_sources = [ 'gstwebrtcdsp.cpp', - 'gstwebrtcechoprobe.cpp' + 'gstwebrtcechoprobe.cpp', + 'gstwebrtcdspplugin.cpp' ] webrtc_dep = dependency('webrtc-audio-processing', version : ['>= 0.2', '< 0.4'],