From 0ca02a72f4539415ab5cd77279caa90420407153 Mon Sep 17 00:00:00 2001 From: Igor Sharonov Date: Mon, 15 Apr 2024 12:21:10 +0300 Subject: [PATCH] Add explicit audio converters to voice processor and echo probe The VoiceProcessor and EchoProbe plugins have fixed caps: rate=48000,channels=1. There is no such cap on windows, hence append explicit resampler and converter. --- plugins/rtp/src/device.vala | 27 +++++++++++++++++++++++++-- plugins/rtp/src/plugin.vala | 26 +++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/plugins/rtp/src/device.vala b/plugins/rtp/src/device.vala index e0438dfd..a9f9bb11 100644 --- a/plugins/rtp/src/device.vala +++ b/plugins/rtp/src/device.vala @@ -470,6 +470,30 @@ public class Dino.Plugins.Rtp.Device : MediaDevice, Object { return target; } +#if WITH_VOICE_PROCESSOR + private Gst.Element create_voice_processor() { + Gst.Bin bin = new Gst.Bin("voiceprocessorbin"); + Gst.Element converter = Gst.ElementFactory.make("audioconvert", @"dsp_convert_$id"); + Gst.Element resampler = Gst.ElementFactory.make("audioresample", @"dsp_resmaple_$id"); + + Gst.Element voiceproc = new VoiceProcessor(plugin.echoprobe as EchoProbe, element as Gst.Audio.StreamVolume); + voiceproc.name = @"dsp_$id"; + + bin.add_many(converter, resampler, voiceproc); + converter.link(resampler); + resampler.link(voiceproc); + + Gst.Pad sink_pad = bin.find_unlinked_pad(Gst.PadDirection.SINK); + Gst.Pad src_pad = bin.find_unlinked_pad(Gst.PadDirection.SRC); + Gst.Pad ghost_source = new Gst.GhostPad("source", src_pad); + Gst.Pad ghost_sink = new Gst.GhostPad("sink", sink_pad); + bin.add_pad(ghost_source); + bin.add_pad(ghost_sink); + + return (Gst.Element)bin; + } +#endif + private void create() { debug("Creating device %s", id); plugin.pause(); @@ -488,8 +512,7 @@ public class Dino.Plugins.Rtp.Device : MediaDevice, Object { element.link(filter); #if WITH_VOICE_PROCESSOR if (media == "audio" && plugin.echoprobe != null) { - dsp = new VoiceProcessor(plugin.echoprobe as EchoProbe, element as Gst.Audio.StreamVolume); - dsp.name = @"dsp_$id"; + dsp = create_voice_processor(); pipe.add(dsp); filter.link(dsp); } diff --git a/plugins/rtp/src/plugin.vala b/plugins/rtp/src/plugin.vala index 5996910f..97c6fb47 100644 --- a/plugins/rtp/src/plugin.vala +++ b/plugins/rtp/src/plugin.vala @@ -58,6 +58,27 @@ public class Dino.Plugins.Rtp.Plugin : RootInterface, VideoCallPlugin, Object { } } +#if WITH_VOICE_PROCESSOR + private Gst.Element create_echo_bin(Gst.Element element) { + Gst.Bin bin = new Gst.Bin("echoprobebin"); + Gst.Element converter = Gst.ElementFactory.make("audioconvert", "echo_convert_"); + Gst.Element resampler = Gst.ElementFactory.make("audioresample", "echo_resample_"); + + bin.add_many(element, converter, resampler); + element.link(converter); + converter.link(resampler); + + Gst.Pad sink_pad = bin.find_unlinked_pad(Gst.PadDirection.SINK); + Gst.Pad src_pad = bin.find_unlinked_pad(Gst.PadDirection.SRC); + Gst.Pad ghost_source = new Gst.GhostPad("source", src_pad); + Gst.Pad ghost_sink = new Gst.GhostPad("sink", sink_pad); + bin.add_pad(ghost_source); + bin.add_pad(ghost_sink); + + return (Gst.Element)bin; + } +#endif + private void init_call_pipe() { if (pipe != null) return; pipe = new Gst.Pipeline(null); @@ -80,7 +101,10 @@ public class Dino.Plugins.Rtp.Plugin : RootInterface, VideoCallPlugin, Object { #if WITH_VOICE_PROCESSOR // Audio echo probe echoprobe = new EchoProbe(); - if (echoprobe != null) pipe.add(echoprobe); + if (echoprobe != null) { + echoprobe = create_echo_bin(echoprobe); + pipe.add(echoprobe); + } #endif // Pipeline