Skip to content

Commit

Permalink
Add explicit audio converters to voice processor and echo probe
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
igsha committed Apr 16, 2024
1 parent 77e23c4 commit f742898
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
27 changes: 25 additions & 2 deletions plugins/rtp/src/device.vala
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,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();
Expand All @@ -451,8 +475,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);
}
Expand Down
26 changes: 25 additions & 1 deletion plugins/rtp/src/plugin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit f742898

Please sign in to comment.