1From 7101460edc84b4fe636b5c11d2f597b20c89e397 Mon Sep 17 00:00:00 20012From: capezotte <carana2099@gmail.com>3Date: Mon, 15 Apr 2024 14:26:58 -03004Subject: [PATCH] add SOUND_INITIALIZED property and pipewire fix56---7 udev_device.c | 34 ++++++++++++++++++++++++++++++++++8 udev_enumerate.c | 4 +++-9 2 files changed, 37 insertions(+), 1 deletion(-)1011diff --git a/udev_device.c b/udev_device.c12index b0577964..b3027a14 10064413--- a/udev_device.c14+++ b/udev_device.c15@@ -16,6 +16,7 @@16 */1718 #include <stdio.h>19+#include <dirent.h>20 #include <unistd.h>21 #include <string.h>22 #include <stdlib.h>23@@ -379,6 +380,38 @@ static int set_properties_from_uevent(struct udev_device *udev_device, const cha24 return 0;25 }2627+static void is_sound_initialized(struct udev_device *udev_device, const char* path) {28+ const char *subsystem;29+ DIR *device_folder;30+ struct dirent *dp;31+ char control[PATH_MAX];32+33+ subsystem = udev_device_get_subsystem(udev_device);34+ if (!subsystem || strcmp(subsystem, "sound") != 0) {35+ return;36+ }37+38+ if (strncmp(strrchr(path, '/'), "/card", 5)) {39+ snprintf(control, PATH_MAX, "%s/..", path);40+ device_folder = opendir(control);41+ } else {42+ device_folder = opendir(path);43+ }44+45+ if (!device_folder) {46+ return;47+ }48+49+ while ((dp = readdir(device_folder)) != NULL) {50+ if (strncmp(dp->d_name, "controlC", 8) == 0) {51+ udev_list_entry_add(&udev_device->properties, "SOUND_INITIALIZED", "1", 0);52+ break;53+ }54+ }55+56+ closedir(device_folder);57+}58+59 static void make_bit(unsigned long *arr, int cnt, const char *str)60 {61 size_t len;62@@ -593,6 +626,7 @@ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *6364 set_properties_from_evdev(udev_device);65 set_properties_from_props(udev_device);66+ is_sound_initialized(udev_device, path);6768 free(driver);69 free(subsystem);70diff --git a/udev_enumerate.c b/udev_enumerate.c71index 6fd49c09..d556ceb3 10064472--- a/udev_enumerate.c73+++ b/udev_enumerate.c74@@ -225,7 +225,7 @@ static int filter_sysattr(struct udev_enumerate *udev_enumerate, struct udev_dev7576 static void add_device(struct udev_enumerate *udev_enumerate, const char *path)77 {78- struct udev_device *udev_device;79+ struct udev_device *udev_device, *parent;8081 udev_device = udev_device_new_from_syspath(udev_enumerate->udev, path);8283@@ -241,6 +241,8 @@ static void add_device(struct udev_enumerate *udev_enumerate, const char *path)84 return;85 }8687+ if ((parent = udev_device_get_parent(udev_device)))88+ udev_list_entry_add(&udev_enumerate->devices, udev_device_get_syspath(parent), NULL, 0);89 udev_list_entry_add(&udev_enumerate->devices, udev_device_get_syspath(udev_device), NULL, 0);9091 udev_device_unref(udev_device);