aboutsummaryrefslogtreecommitdiff
path: root/src/sound.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-11-17 01:12:12 +0100
committerdec05eba <dec05eba@protonmail.com>2024-11-17 01:12:12 +0100
commit0ee68146a7cfbabdb1aa20355cb1479fe7277bd0 (patch)
tree03c101a8b46b7ddd078cb135e3311687fd50c138 /src/sound.cpp
parentbf577eec0b025f22195e0a9538e7350a9a7abbe0 (diff)
Disable application audio recording on pulseaudio4.3.0
Diffstat (limited to 'src/sound.cpp')
-rw-r--r--src/sound.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/sound.cpp b/src/sound.cpp
index bd26d89..b500a57 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -399,6 +399,12 @@ static void pa_server_info_cb(pa_context*, const pa_server_info *server_info, vo
audio_devices->default_input = server_info->default_source_name;
}
+static void server_info_callback(pa_context*, const pa_server_info *server_info, void *userdata) {
+ bool *is_server_pipewire = (bool*)userdata;
+ if(server_info->server_name && strstr(server_info->server_name, "PipeWire"))
+ *is_server_pipewire = true;
+}
+
static void get_pulseaudio_default_inputs(AudioDevices &audio_devices) {
int state = 0;
int pa_ready = 0;
@@ -493,3 +499,50 @@ AudioDevices get_pulseaudio_inputs() {
pa_mainloop_free(main_loop);
return audio_devices;
}
+
+bool pulseaudio_server_is_pipewire() {
+ int state = 0;
+ int pa_ready = 0;
+ pa_operation *pa_op = NULL;
+ bool is_server_pipewire = false;
+
+ pa_mainloop *main_loop = pa_mainloop_new();
+ if(!main_loop)
+ return is_server_pipewire;
+
+ pa_context *ctx = pa_context_new(pa_mainloop_get_api(main_loop), "gpu-screen-recorder");
+ if(pa_context_connect(ctx, NULL, PA_CONTEXT_NOFLAGS, NULL) < 0)
+ goto done;
+
+ pa_context_set_state_callback(ctx, pa_state_cb, &pa_ready);
+
+ for(;;) {
+ // Not ready
+ if(pa_ready == 0) {
+ pa_mainloop_iterate(main_loop, 1, NULL);
+ continue;
+ }
+
+ switch(state) {
+ case 0: {
+ pa_op = pa_context_get_server_info(ctx, server_info_callback, &is_server_pipewire);
+ ++state;
+ break;
+ }
+ }
+
+ // Couldn't get connection to the server
+ if(pa_ready == 2 || (state == 1 && pa_op && pa_operation_get_state(pa_op) == PA_OPERATION_DONE))
+ break;
+
+ pa_mainloop_iterate(main_loop, 1, NULL);
+ }
+
+ done:
+ if(pa_op)
+ pa_operation_unref(pa_op);
+ pa_context_disconnect(ctx);
+ pa_context_unref(ctx);
+ pa_mainloop_free(main_loop);
+ return is_server_pipewire;
+}