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 9760acb commit 6e00e09
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
4 changes: 0 additions & 4 deletions plugins/rtp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ else()
endif()

if(WIN32 AND WITH_WASAPI)
if(WITH_WEBRTC)
message(FATAL_ERROR "Cannot build with both wasapi and webrtc")
endif()

list(APPEND RTP_DEFINITIONS WITH_WASAPI)
endif()

Expand Down
3 changes: 0 additions & 3 deletions plugins/rtp/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ if get_option('plugin-rtp-vp9').allowed()
vala_args += ['-D', 'ENABLE_VP9']
endif
if host_machine.system() == 'windows' and get_option('with-wasapi')
if get_option('with-webrtc')
error('Cannot build with both wasapi and webrtc')
endif
vala_args += ['-D', 'WITH_WASAPI']
endif
lib_rtp = shared_library('rtp', sources, name_prefix: '', c_args: c_args, vala_args: vala_args, include_directories: include_directories('src'), dependencies: dependencies, kwargs: install_options)
Expand Down
20 changes: 20 additions & 0 deletions plugins/rtp/src/device.vala
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,25 @@ public class Dino.Plugins.Rtp.Device : MediaDevice, Object {
return target;
}

private Gst.Element create_voice_processor_bin(Gst.Element 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");

bin.add_many(converter, resampler, voice_processor);
converter.link(resampler);
resampler.link(voice_processor);

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

private void create() {
debug("Creating device %s", id);
plugin.pause();
Expand All @@ -456,6 +475,7 @@ public class Dino.Plugins.Rtp.Device : MediaDevice, Object {
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_bin(dsp);
pipe.add(dsp);
filter.link(dsp);
}
Expand Down
24 changes: 23 additions & 1 deletion plugins/rtp/src/plugin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ public class Dino.Plugins.Rtp.Plugin : RootInterface, VideoCallPlugin, Object {
}
}

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

private void init_call_pipe() {
if (pipe != null) return;
pipe = new Gst.Pipeline(null);
Expand All @@ -90,7 +109,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 6e00e09

Please sign in to comment.