Skip to content

Commit

Permalink
windows: Enable wasapi on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
igsha authored and mxlgv committed Apr 19, 2024
1 parent c438592 commit 2eb0052
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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')
4 changes: 4 additions & 0 deletions plugins/rtp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions plugins/rtp/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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('.'))
25 changes: 19 additions & 6 deletions plugins/rtp/src/plugin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,28 @@ 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();
device_monitor.show_all = true;
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));
}
}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2eb0052

Please sign in to comment.