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.
This commit is contained in:
Igor Sharonov 2024-04-15 12:21:10 +03:00 committed by Maxim Logaev
parent fc2d2dab8d
commit 0ca02a72f4
2 changed files with 50 additions and 3 deletions

View file

@ -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);
}

View file

@ -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