From 2eb0052663ab68e8cf4706287a44f7e0302ff96c Mon Sep 17 00:00:00 2001 From: Igor Sharonov Date: Mon, 15 Apr 2024 12:21:10 +0300 Subject: [PATCH] windows: Enable wasapi on windows --- CMakeLists.txt | 1 + meson_options.txt | 1 + plugins/rtp/CMakeLists.txt | 4 ++++ plugins/rtp/meson.build | 3 +++ plugins/rtp/src/plugin.vala | 25 +++++++++++++++++++------ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d236776..99d81319 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ endif () include(CTest) option(PLUGIN_RTP_WEBRTC_AUDIO_PROCESSING "Use WebRTC audio processing" ON) +option(WITH_WASAPI "Use wasapi instead of directsound on windows" ON) # https://gitlab.kitware.com/cmake/cmake/-/issues/19804 if (WIN32) diff --git a/meson_options.txt b/meson_options.txt index ec85ef0e..b384cb41 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -16,3 +16,4 @@ option('plugin-rtp-vp9', type: 'feature', value: 'disabled', description: 'VP9 c option('plugin-rtp-webrtc-audio-processing', type: 'feature', description: 'Voice preprocessing') option('use-soup2', type: 'boolean', value: false, description: 'Use libsoup version 2 instead of 3') +option('with-wasapi', type: 'boolean', value: true, description: 'Use wasapi insted of directsound on windows') diff --git a/plugins/rtp/CMakeLists.txt b/plugins/rtp/CMakeLists.txt index be0ad926..a3eda885 100644 --- a/plugins/rtp/CMakeLists.txt +++ b/plugins/rtp/CMakeLists.txt @@ -58,6 +58,10 @@ if(RTP_ENABLE_MSDK) set(RTP_DEFINITIONS ${RTP_DEFINITIONS} ENABLE_MSDK) endif() +if(WIN32 AND WITH_WASAPI) + list(APPEND RTP_DEFINITIONS WITH_WASAPI) +endif() + vala_precompile(RTP_VALA_C SOURCES src/codec_util.vala diff --git a/plugins/rtp/meson.build b/plugins/rtp/meson.build index aad4591a..61e8a8b8 100644 --- a/plugins/rtp/meson.build +++ b/plugins/rtp/meson.build @@ -55,5 +55,8 @@ endif if get_option('plugin-rtp-vp9').allowed() vala_args += ['-D', 'ENABLE_VP9'] endif +if host_machine.system() == 'windows' and get_option('with-wasapi') + 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) dep_rtp = declare_dependency(link_with: lib_rtp, include_directories: include_directories('.')) diff --git a/plugins/rtp/src/plugin.vala b/plugins/rtp/src/plugin.vala index c189a28b..6b6a0885 100644 --- a/plugins/rtp/src/plugin.vala +++ b/plugins/rtp/src/plugin.vala @@ -42,6 +42,19 @@ public class Dino.Plugins.Rtp.Plugin : RootInterface, VideoCallPlugin, Object { if (pause_count < 0) warning("Pause count below zero!"); } + private bool is_skipped(Gst.Device device) { + bool is_noprops = device.properties == null; +#if WITH_WASAPI + bool is_disabled_sound = device.properties.get_string("device.api") == "directsound"; +#else + bool is_disabled_sound = device.properties.get_string("device.api") == "wasapi"; +#endif + bool is_proplist = device.properties.has_name("pipewire-proplist") && device.has_classes("Audio"); + bool is_monitor = device.properties.get_string("device.class") == "monitor"; + bool is_in_devices = devices.any_match((it) => it.matches(device)); + return is_noprops || is_disabled_sound || is_proplist || is_monitor || is_in_devices; + } + private void init_device_monitor() { if (device_monitor != null) return; device_monitor = new Gst.DeviceMonitor(); @@ -49,11 +62,8 @@ public class Dino.Plugins.Rtp.Plugin : RootInterface, VideoCallPlugin, Object { device_monitor.get_bus().add_watch(Priority.DEFAULT, on_device_monitor_message); device_monitor.start(); foreach (Gst.Device device in device_monitor.get_devices()) { - if (device.properties == null) continue; - if (device.properties.get_string("device.api") == "wasapi") continue; - if (device.properties.has_name("pipewire-proplist") && device.has_classes("Audio")) continue; - if (device.properties.get_string("device.class") == "monitor") continue; - if (devices.any_match((it) => it.matches(device))) continue; + if (is_skipped(device)) continue; + debug(@"(Init) Add name=$(device.name) device=$(device.display_name)"); devices.add(new Device(this, device)); } } @@ -227,20 +237,23 @@ public class Dino.Plugins.Rtp.Plugin : RootInterface, VideoCallPlugin, Object { switch (message.type) { case Gst.MessageType.DEVICE_ADDED: message.parse_device_added(out gst_device); - if (devices.any_match((it) => it.matches(gst_device))) return Source.CONTINUE; + if (is_skipped(gst_device)) return Source.CONTINUE; device = new Device(this, gst_device); + debug(@"(Notify) Add name=$(gst_device.name) device=$(gst_device.display_name)"); devices.add(device); break; #if GST_1_16 case Gst.MessageType.DEVICE_CHANGED: message.parse_device_changed(out gst_device, out old_gst_device); device = devices.first_match((it) => it.matches(old_gst_device)); + debug(@"(Notify) Change name=$(gst_device.name) device=$(gst_device.display_name)"); if (device != null) device.update(gst_device); break; #endif case Gst.MessageType.DEVICE_REMOVED: message.parse_device_removed(out gst_device); device = devices.first_match((it) => it.matches(gst_device)); + debug(@"(Notify) Remove name=$(gst_device.name) device=$(gst_device.display_name)"); if (device != null) devices.remove(device); break; default: