summaryrefslogtreecommitdiff
path: root/lib/wireplumber/src
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-09-01 14:17:36 +0200
committerAylur <[email protected]>2024-09-01 14:17:36 +0200
commit3e3f045d650a839d21f7b649da7aa5c19bd2e38b (patch)
tree9a974eb0d38932d474940288c662bd1f01ea3088 /lib/wireplumber/src
parent408faee16911ccfaa3e7dad69f9938fd4a696704 (diff)
monorepo structuring
Diffstat (limited to 'lib/wireplumber/src')
-rw-r--r--lib/wireplumber/src/audio.c503
-rw-r--r--lib/wireplumber/src/device.c371
-rw-r--r--lib/wireplumber/src/endpoint.c554
-rw-r--r--lib/wireplumber/src/meson.build72
-rw-r--r--lib/wireplumber/src/profile.c84
-rw-r--r--lib/wireplumber/src/video.c428
-rw-r--r--lib/wireplumber/src/wireplumber.c503
7 files changed, 2515 insertions, 0 deletions
diff --git a/lib/wireplumber/src/audio.c b/lib/wireplumber/src/audio.c
new file mode 100644
index 0000000..15582d7
--- /dev/null
+++ b/lib/wireplumber/src/audio.c
@@ -0,0 +1,503 @@
+#include "audio.h"
+
+#include <wp/wp.h>
+
+#include "device.h"
+#include "endpoint.h"
+#include "glib-object.h"
+#include "wp.h"
+
+struct _AstalWpAudio {
+ GObject parent_instance;
+};
+
+typedef struct {
+ AstalWpWp *wp;
+} AstalWpAudioPrivate;
+
+G_DEFINE_FINAL_TYPE_WITH_PRIVATE(AstalWpAudio, astal_wp_audio, G_TYPE_OBJECT);
+
+typedef enum {
+ ASTAL_WP_AUDIO_SIGNAL_MICROPHONE_ADDED,
+ ASTAL_WP_AUDIO_SIGNAL_MICROPHONE_REMOVED,
+ ASTAL_WP_AUDIO_SIGNAL_SPEAKER_ADDED,
+ ASTAL_WP_AUDIO_SIGNAL_SPEAKER_REMOVED,
+ ASTAL_WP_AUDIO_SIGNAL_STREAM_ADDED,
+ ASTAL_WP_AUDIO_SIGNAL_STREAM_REMOVED,
+ ASTAL_WP_AUDIO_SIGNAL_RECORDER_ADDED,
+ ASTAL_WP_AUDIO_SIGNAL_RECORDER_REMOVED,
+ ASTAL_WP_AUDIO_SIGNAL_DEVICE_ADDED,
+ ASTAL_WP_AUDIO_SIGNAL_DEVICE_REMOVED,
+ ASTAL_WP_AUDIO_N_SIGNALS
+} AstalWpWpSignals;
+
+static guint astal_wp_audio_signals[ASTAL_WP_AUDIO_N_SIGNALS] = {
+ 0,
+};
+
+typedef enum {
+ ASTAL_WP_AUDIO_PROP_MICROPHONES = 1,
+ ASTAL_WP_AUDIO_PROP_SPEAKERS,
+ ASTAL_WP_AUDIO_PROP_STREAMS,
+ ASTAL_WP_AUDIO_PROP_RECORDERS,
+ ASTAL_WP_AUDIO_PROP_DEVICES,
+ ASTAL_WP_AUDIO_PROP_DEFAULT_SPEAKER,
+ ASTAL_WP_AUDIO_PROP_DEFAULT_MICROPHONE,
+ ASTAL_WP_AUDIO_N_PROPERTIES,
+} AstalWpAudioProperties;
+
+static GParamSpec *astal_wp_audio_properties[ASTAL_WP_AUDIO_N_PROPERTIES] = {
+ NULL,
+};
+
+/**
+ * astal_wp_audio_get_speaker:
+ * @self: the AstalWpAudio object
+ * @id: the id of the endpoint
+ *
+ * gets the speaker with the given id
+ *
+ * Returns: (transfer none) (nullable)
+ */
+AstalWpEndpoint *astal_wp_audio_get_speaker(AstalWpAudio *self, guint id) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = astal_wp_wp_get_endpoint(priv->wp, id);
+ if (astal_wp_endpoint_get_media_class(endpoint) == ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER)
+ return endpoint;
+ return NULL;
+}
+
+/**
+ * astal_wp_audio_get_microphone:
+ * @self: the AstalWpAudio object
+ * @id: the id of the endpoint
+ *
+ * gets the microphone with the given id
+ *
+ * Returns: (transfer none) (nullable)
+ */
+AstalWpEndpoint *astal_wp_audio_get_microphone(AstalWpAudio *self, guint id) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = astal_wp_wp_get_endpoint(priv->wp, id);
+ if (astal_wp_endpoint_get_media_class(endpoint) == ASTAL_WP_MEDIA_CLASS_AUDIO_MICROPHONE)
+ return endpoint;
+ return NULL;
+}
+
+/**
+ * astal_wp_audio_get_recorder:
+ * @self: the AstalWpAudio object
+ * @id: the id of the endpoint
+ *
+ * gets the recorder with the given id
+ *
+ * Returns: (transfer none) (nullable)
+ */
+AstalWpEndpoint *astal_wp_audio_get_recorder(AstalWpAudio *self, guint id) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = astal_wp_wp_get_endpoint(priv->wp, id);
+ if (astal_wp_endpoint_get_media_class(endpoint) == ASTAL_WP_MEDIA_CLASS_AUDIO_RECORDER)
+ return endpoint;
+ return NULL;
+}
+
+/**
+ * astal_wp_audio_get_stream:
+ * @self: the AstalWpAudio object
+ * @id: the id of the endpoint
+ *
+ * gets the stream with the given id
+ *
+ * Returns: (transfer none) (nullable)
+ */
+AstalWpEndpoint *astal_wp_audio_get_stream(AstalWpAudio *self, guint id) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = astal_wp_wp_get_endpoint(priv->wp, id);
+ if (astal_wp_endpoint_get_media_class(endpoint) == ASTAL_WP_MEDIA_CLASS_AUDIO_STREAM)
+ return endpoint;
+ return NULL;
+}
+
+/**
+ * astal_wp_audio_get_device:
+ * @self: the AstalWpAudio object
+ * @id: the id of the device
+ *
+ * gets the device with the given id
+ *
+ * Returns: (transfer none) (nullable)
+ */
+AstalWpDevice *astal_wp_audio_get_device(AstalWpAudio *self, guint id) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+
+ return astal_wp_wp_get_device(priv->wp, id);
+}
+
+/**
+ * astal_wp_audio_get_microphones:
+ * @self: the AstalWpAudio object
+ *
+ * a GList containing the microphones
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpEndpoint))
+ */
+GList *astal_wp_audio_get_microphones(AstalWpAudio *self) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_endpoints(priv->wp);
+ GList *mics = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_endpoint_get_media_class(l->data) == ASTAL_WP_MEDIA_CLASS_AUDIO_MICROPHONE) {
+ mics = g_list_append(mics, l->data);
+ }
+ }
+ g_list_free(eps);
+ return mics;
+}
+
+/**
+ * astal_wp_audio_get_speakers:
+ * @self: the AstalWpAudio object
+ *
+ * a GList containing the speakers
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpEndpoint))
+ */
+GList *astal_wp_audio_get_speakers(AstalWpAudio *self) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_endpoints(priv->wp);
+ GList *speakers = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_endpoint_get_media_class(l->data) == ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER) {
+ speakers = g_list_append(speakers, l->data);
+ }
+ }
+ g_list_free(eps);
+ return speakers;
+}
+
+/**
+ * astal_wp_audio_get_recorders:
+ * @self: the AstalWpAudio object
+ *
+ * a GList containing the recorders
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpEndpoint))
+ */
+GList *astal_wp_audio_get_recorders(AstalWpAudio *self) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_endpoints(priv->wp);
+ GList *recorders = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_endpoint_get_media_class(l->data) == ASTAL_WP_MEDIA_CLASS_AUDIO_RECORDER) {
+ recorders = g_list_append(recorders, l->data);
+ }
+ }
+ g_list_free(eps);
+ return recorders;
+}
+
+/**
+ * astal_wp_audio_get_streams:
+ * @self: the AstalWpAudio object
+ *
+ * a GList containing the streams
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpEndpoint))
+ */
+GList *astal_wp_audio_get_streams(AstalWpAudio *self) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_endpoints(priv->wp);
+ GList *streams = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_endpoint_get_media_class(l->data) == ASTAL_WP_MEDIA_CLASS_AUDIO_STREAM) {
+ streams = g_list_append(streams, l->data);
+ }
+ }
+ g_list_free(eps);
+ return streams;
+}
+
+/**
+ * astal_wp_audio_get_devices:
+ * @self: the AstalWpAudio object
+ *
+ * a GList containing the devices
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpDevice))
+ */
+GList *astal_wp_audio_get_devices(AstalWpAudio *self) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_devices(priv->wp);
+ GList *list = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_device_get_device_type(l->data) == ASTAL_WP_DEVICE_TYPE_AUDIO) {
+ list = g_list_append(list, l->data);
+ }
+ }
+ g_list_free(eps);
+ return list;
+}
+
+/**
+ * astal_wp_audio_get_endpoint:
+ * @self: the AstalWpAudio object
+ * @id: the id of the endpoint
+ *
+ * the endpoint with the given id
+ *
+ * Returns: (transfer none) (nullable)
+ */
+AstalWpEndpoint *astal_wp_audio_get_endpoint(AstalWpAudio *self, guint id) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = astal_wp_wp_get_endpoint(priv->wp, id);
+ return endpoint;
+}
+
+/**
+ * astal_wp_audio_get_default_speaker
+ *
+ * gets the default speaker object
+ *
+ * Returns: (nullable) (transfer none)
+ */
+AstalWpEndpoint *astal_wp_audio_get_default_speaker(AstalWpAudio *self) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+ return astal_wp_wp_get_default_speaker(priv->wp);
+}
+
+/**
+ * astal_wp_audio_get_default_microphone
+ *
+ * gets the default microphone object
+ *
+ * Returns: (nullable) (transfer none)
+ */
+AstalWpEndpoint *astal_wp_audio_get_default_microphone(AstalWpAudio *self) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+ return astal_wp_wp_get_default_microphone(priv->wp);
+}
+
+static void astal_wp_audio_get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec) {
+ AstalWpAudio *self = ASTAL_WP_AUDIO(object);
+
+ switch (property_id) {
+ case ASTAL_WP_AUDIO_PROP_MICROPHONES:
+ g_value_set_pointer(value, astal_wp_audio_get_microphones(self));
+ break;
+ case ASTAL_WP_AUDIO_PROP_SPEAKERS:
+ g_value_set_pointer(value, astal_wp_audio_get_speakers(self));
+ break;
+ case ASTAL_WP_AUDIO_PROP_STREAMS:
+ g_value_set_pointer(value, astal_wp_audio_get_streams(self));
+ break;
+ case ASTAL_WP_AUDIO_PROP_RECORDERS:
+ g_value_set_pointer(value, astal_wp_audio_get_recorders(self));
+ break;
+ case ASTAL_WP_AUDIO_PROP_DEFAULT_SPEAKER:
+ g_value_set_object(value, astal_wp_audio_get_default_speaker(self));
+ break;
+ case ASTAL_WP_AUDIO_PROP_DEVICES:
+ g_value_set_pointer(value, astal_wp_audio_get_devices(self));
+ break;
+ case ASTAL_WP_AUDIO_PROP_DEFAULT_MICROPHONE:
+ g_value_set_object(value, astal_wp_audio_get_default_microphone(self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_wp_audio_device_added(AstalWpAudio *self, gpointer object) {
+ AstalWpDevice *device = ASTAL_WP_DEVICE(object);
+ if (astal_wp_device_get_device_type(device) == ASTAL_WP_DEVICE_TYPE_AUDIO) {
+ g_signal_emit_by_name(self, "device-added", device);
+ g_object_notify(G_OBJECT(self), "devices");
+ }
+}
+
+static void astal_wp_audio_device_removed(AstalWpAudio *self, gpointer object) {
+ AstalWpDevice *device = ASTAL_WP_DEVICE(object);
+ if (astal_wp_device_get_device_type(device) == ASTAL_WP_DEVICE_TYPE_AUDIO) {
+ g_signal_emit_by_name(self, "device-removed", device);
+ g_object_notify(G_OBJECT(self), "devices");
+ }
+}
+
+static void astal_wp_audio_object_added(AstalWpAudio *self, gpointer object) {
+ AstalWpEndpoint *endpoint = ASTAL_WP_ENDPOINT(object);
+ switch (astal_wp_endpoint_get_media_class(endpoint)) {
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_MICROPHONE:
+ g_signal_emit_by_name(self, "microphone-added", endpoint);
+ g_object_notify(G_OBJECT(self), "microphones");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER:
+ g_signal_emit_by_name(self, "speaker-added", endpoint);
+ g_object_notify(G_OBJECT(self), "speakers");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_STREAM:
+ g_signal_emit_by_name(self, "stream-added", endpoint);
+ g_object_notify(G_OBJECT(self), "streams");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_RECORDER:
+ g_signal_emit_by_name(self, "recorder-added", endpoint);
+ g_object_notify(G_OBJECT(self), "recorders");
+ break;
+ default:
+ break;
+ }
+}
+
+static void astal_wp_audio_object_removed(AstalWpAudio *self, gpointer object) {
+ AstalWpEndpoint *endpoint = ASTAL_WP_ENDPOINT(object);
+ switch (astal_wp_endpoint_get_media_class(endpoint)) {
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_MICROPHONE:
+ g_signal_emit_by_name(self, "microphone-removed", endpoint);
+ g_object_notify(G_OBJECT(self), "microphones");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER:
+ g_signal_emit_by_name(self, "speaker-removed", endpoint);
+ g_object_notify(G_OBJECT(self), "speakers");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_STREAM:
+ g_signal_emit_by_name(self, "stream-removed", endpoint);
+ g_object_notify(G_OBJECT(self), "streams");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_RECORDER:
+ g_signal_emit_by_name(self, "recorder-removed", endpoint);
+ g_object_notify(G_OBJECT(self), "recorders");
+ break;
+ default:
+ break;
+ }
+}
+
+AstalWpAudio *astal_wp_audio_new(AstalWpWp *wp) {
+ AstalWpAudio *self = g_object_new(ASTAL_WP_TYPE_AUDIO, NULL);
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+ priv->wp = g_object_ref(wp);
+
+ g_signal_connect_swapped(priv->wp, "endpoint-added", G_CALLBACK(astal_wp_audio_object_added),
+ self);
+ g_signal_connect_swapped(priv->wp, "endpoint-removed",
+ G_CALLBACK(astal_wp_audio_object_removed), self);
+ g_signal_connect_swapped(priv->wp, "device-added", G_CALLBACK(astal_wp_audio_device_added),
+ self);
+ g_signal_connect_swapped(priv->wp, "device-removed", G_CALLBACK(astal_wp_audio_device_removed),
+ self);
+
+ return self;
+}
+
+static void astal_wp_audio_dispose(GObject *object) {
+ AstalWpAudio *self = ASTAL_WP_AUDIO(object);
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+ g_clear_object(&priv->wp);
+}
+
+static void astal_wp_audio_init(AstalWpAudio *self) {
+ AstalWpAudioPrivate *priv = astal_wp_audio_get_instance_private(self);
+}
+
+static void astal_wp_audio_class_init(AstalWpAudioClass *class) {
+ GObjectClass *object_class = G_OBJECT_CLASS(class);
+ object_class->get_property = astal_wp_audio_get_property;
+ object_class->dispose = astal_wp_audio_dispose;
+
+ /**
+ * AstalWpAudio:microphones: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_audio_properties[ASTAL_WP_AUDIO_PROP_MICROPHONES] =
+ g_param_spec_pointer("microphones", "microphones", "microphones", G_PARAM_READABLE);
+ /**
+ * AstalWpAudio:speakers: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_audio_properties[ASTAL_WP_AUDIO_PROP_SPEAKERS] =
+ g_param_spec_pointer("speakers", "speakers", "speakers", G_PARAM_READABLE);
+ /**
+ * AstalWpAudio:recorders: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_audio_properties[ASTAL_WP_AUDIO_PROP_RECORDERS] =
+ g_param_spec_pointer("recorders", "recorders", "recorders", G_PARAM_READABLE);
+ /**
+ * AstalWpAudio:streams: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_audio_properties[ASTAL_WP_AUDIO_PROP_STREAMS] =
+ g_param_spec_pointer("streams", "streams", "streams", G_PARAM_READABLE);
+ /**
+ * AstalWpAudio:devices: (type GList(AstalWpDevice)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_audio_properties[ASTAL_WP_AUDIO_PROP_DEVICES] =
+ g_param_spec_pointer("devices", "devices", "devices", G_PARAM_READABLE);
+ /**
+ * AstalWpAudio:default-speaker:
+ *
+ * The AstalWndpoint object representing the default speaker
+ */
+ astal_wp_audio_properties[ASTAL_WP_AUDIO_PROP_DEFAULT_SPEAKER] =
+ g_param_spec_object("default-speaker", "default-speaker", "default-speaker",
+ ASTAL_WP_TYPE_ENDPOINT, G_PARAM_READABLE);
+ /**
+ * AstalWpAudio:default-microphone:
+ *
+ * The AstalWndpoint object representing the default speaker
+ */
+ astal_wp_audio_properties[ASTAL_WP_AUDIO_PROP_DEFAULT_MICROPHONE] =
+ g_param_spec_object("default-microphone", "default-microphone", "default-microphone",
+ ASTAL_WP_TYPE_ENDPOINT, G_PARAM_READABLE);
+
+ g_object_class_install_properties(object_class, ASTAL_WP_AUDIO_N_PROPERTIES,
+ astal_wp_audio_properties);
+
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_MICROPHONE_ADDED] =
+ g_signal_new("microphone-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL,
+ NULL, NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_MICROPHONE_REMOVED] =
+ g_signal_new("microphone-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL,
+ NULL, NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_SPEAKER_ADDED] =
+ g_signal_new("speaker-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_SPEAKER_REMOVED] =
+ g_signal_new("speaker-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_STREAM_ADDED] =
+ g_signal_new("stream-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_STREAM_REMOVED] =
+ g_signal_new("stream-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_RECORDER_ADDED] =
+ g_signal_new("recorder-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_RECORDER_REMOVED] =
+ g_signal_new("recorder-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL,
+ NULL, NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_DEVICE_ADDED] =
+ g_signal_new("device-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_DEVICE);
+ astal_wp_audio_signals[ASTAL_WP_AUDIO_SIGNAL_MICROPHONE_REMOVED] =
+ g_signal_new("device-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_DEVICE);
+}
diff --git a/lib/wireplumber/src/device.c b/lib/wireplumber/src/device.c
new file mode 100644
index 0000000..af0760c
--- /dev/null
+++ b/lib/wireplumber/src/device.c
@@ -0,0 +1,371 @@
+#include <wp/wp.h>
+
+#include "device-private.h"
+#include "profile.h"
+
+struct _AstalWpDevice {
+ GObject parent_instance;
+
+ guint id;
+ gchar *description;
+ gchar *icon;
+ gint active_profile;
+ AstalWpDeviceType type;
+};
+
+typedef struct {
+ WpDevice *device;
+ GHashTable *profiles;
+} AstalWpDevicePrivate;
+
+G_DEFINE_FINAL_TYPE_WITH_PRIVATE(AstalWpDevice, astal_wp_device, G_TYPE_OBJECT);
+
+G_DEFINE_ENUM_TYPE(AstalWpDeviceType, astal_wp_device_type,
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_DEVICE_TYPE_AUDIO, "Audio/Device"),
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_DEVICE_TYPE_VIDEO, "Video/Device"));
+
+typedef enum {
+ ASTAL_WP_DEVICE_PROP_ID = 1,
+ ASTAL_WP_DEVICE_PROP_DESCRIPTION,
+ ASTAL_WP_DEVICE_PROP_ICON,
+ ASTAL_WP_DEVICE_PROP_PROFILES,
+ ASTAL_WP_DEVICE_PROP_ACTIVE_PROFILE,
+ ASTAL_WP_DEVICE_PROP_DEVICE_TYPE,
+ ASTAL_WP_DEVICE_N_PROPERTIES,
+} AstalWpDeviceProperties;
+
+static GParamSpec *astal_wp_device_properties[ASTAL_WP_DEVICE_N_PROPERTIES] = {
+ NULL,
+};
+
+/**
+ * astal_wp_device_get_id
+ * @self: the AstalWpDevice object
+ *
+ * gets the id of this device
+ *
+ */
+guint astal_wp_device_get_id(AstalWpDevice *self) { return self->id; }
+
+/**
+ * astal_wp_device_get_description
+ * @self: the AstalWpDevice object
+ *
+ * gets the description of this device
+ *
+ */
+const gchar *astal_wp_device_get_description(AstalWpDevice *self) { return self->description; }
+
+/**
+ * astal_wp_device_get_icon
+ * @self: the AstalWpDevice object
+ *
+ * gets the icon of this device
+ *
+ */
+const gchar *astal_wp_device_get_icon(AstalWpDevice *self) {
+ g_return_val_if_fail(self != NULL, "audio-card-symbolic");
+ return self->icon;
+}
+
+/**
+ * astal_wp_device_get_device_type
+ * @self: the AstalWpDevice object
+ *
+ * gets the type of this device
+ *
+ */
+AstalWpDeviceType astal_wp_device_get_device_type(AstalWpDevice *self) { return self->type; }
+
+/**
+ * astal_wp_device_get_active_profile
+ * @self: the AstalWpDevice object
+ *
+ * gets the currently active profile of this device
+ *
+ */
+gint astal_wp_device_get_active_profile(AstalWpDevice *self) { return self->active_profile; }
+
+/**
+ * astal_wp_device_set_active_profile
+ * @self: the AstalWpDevice object
+ * @profile_id: the id of the profile
+ *
+ * sets the profile for this device
+ *
+ */
+void astal_wp_device_set_active_profile(AstalWpDevice *self, int profile_id) {
+ AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
+
+ WpSpaPodBuilder *builder =
+ wp_spa_pod_builder_new_object("Spa:Pod:Object:Param:Profile", "Profile");
+ wp_spa_pod_builder_add_property(builder, "index");
+ wp_spa_pod_builder_add_int(builder, profile_id);
+ WpSpaPod *pod = wp_spa_pod_builder_end(builder);
+ wp_pipewire_object_set_param(WP_PIPEWIRE_OBJECT(priv->device), "Profile", 0, pod);
+
+ wp_spa_pod_builder_unref(builder);
+}
+
+/**
+ * astal_wp_device_get_profile:
+ * @self: the AstalWpDevice object
+ * @id: the id of the profile
+ *
+ * gets the profile with the given id
+ *
+ * Returns: (transfer none) (nullable)
+ */
+AstalWpProfile *astal_wp_device_get_profile(AstalWpDevice *self, gint id) {
+ AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
+
+ return g_hash_table_lookup(priv->profiles, GINT_TO_POINTER(id));
+}
+
+/**
+ * astal_wp_device_get_profiles:
+ * @self: the AstalWpDevice object
+ *
+ * gets a GList containing the profiles
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpProfile))
+ */
+GList *astal_wp_device_get_profiles(AstalWpDevice *self) {
+ AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
+ return g_hash_table_get_values(priv->profiles);
+}
+
+static void astal_wp_device_get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec) {
+ AstalWpDevice *self = ASTAL_WP_DEVICE(object);
+
+ switch (property_id) {
+ case ASTAL_WP_DEVICE_PROP_ID:
+ g_value_set_uint(value, self->id);
+ break;
+ case ASTAL_WP_DEVICE_PROP_DESCRIPTION:
+ g_value_set_string(value, self->description);
+ break;
+ case ASTAL_WP_DEVICE_PROP_ICON:
+ g_value_set_string(value, self->icon);
+ break;
+ case ASTAL_WP_DEVICE_PROP_PROFILES:
+ g_value_set_pointer(value, astal_wp_device_get_profiles(self));
+ break;
+ case ASTAL_WP_DEVICE_PROP_DEVICE_TYPE:
+ g_value_set_enum(value, astal_wp_device_get_device_type(self));
+ break;
+ case ASTAL_WP_DEVICE_PROP_ACTIVE_PROFILE:
+ g_value_set_int(value, self->active_profile);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_wp_device_set_property(GObject *object, guint property_id, const GValue *value,
+ GParamSpec *pspec) {
+ AstalWpDevice *self = ASTAL_WP_DEVICE(object);
+
+ switch (property_id) {
+ case ASTAL_WP_DEVICE_PROP_ACTIVE_PROFILE:
+ astal_wp_device_set_active_profile(self, g_value_get_int(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_wp_device_update_profiles(AstalWpDevice *self) {
+ AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
+ g_hash_table_remove_all(priv->profiles);
+
+ WpIterator *iter =
+ wp_pipewire_object_enum_params_sync(WP_PIPEWIRE_OBJECT(priv->device), "EnumProfile", NULL);
+ if (iter == NULL) return;
+ GValue profile = G_VALUE_INIT;
+ while (wp_iterator_next(iter, &profile)) {
+ WpSpaPod *pod = g_value_get_boxed(&profile);
+
+ gint index;
+ gchar *description;
+ wp_spa_pod_get_object(pod, NULL, "index", "i", &index, "description", "s", &description,
+ NULL);
+
+ g_hash_table_insert(
+ priv->profiles, GINT_TO_POINTER(index),
+ g_object_new(ASTAL_WP_TYPE_PROFILE, "index", index, "description", description, NULL));
+ g_value_unset(&profile);
+ }
+ wp_iterator_unref(iter);
+
+ g_object_notify(G_OBJECT(self), "profiles");
+}
+
+static void astal_wp_device_update_active_profile(AstalWpDevice *self) {
+ AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
+
+ WpIterator *iter =
+ wp_pipewire_object_enum_params_sync(WP_PIPEWIRE_OBJECT(priv->device), "Profile", NULL);
+ if (iter == NULL) return;
+ GValue profile = G_VALUE_INIT;
+ while (wp_iterator_next(iter, &profile)) {
+ WpSpaPod *pod = g_value_get_boxed(&profile);
+
+ gint index;
+ gchar *description;
+ wp_spa_pod_get_object(pod, NULL, "index", "i", &index, "description", "s", &description,
+ NULL);
+
+ g_hash_table_insert(
+ priv->profiles, GINT_TO_POINTER(index),
+ g_object_new(ASTAL_WP_TYPE_PROFILE, "index", index, "description", description, NULL));
+
+ self->active_profile = index;
+ g_value_unset(&profile);
+ }
+ wp_iterator_unref(iter);
+
+ g_object_notify(G_OBJECT(self), "active-profile-id");
+}
+
+static void astal_wp_device_params_changed(AstalWpDevice *self, const gchar *prop) {
+ if (g_strcmp0(prop, "EnumProfile") == 0) {
+ astal_wp_device_update_profiles(self);
+ } else if (g_strcmp0(prop, "Profile") == 0) {
+ astal_wp_device_update_active_profile(self);
+ }
+}
+
+static void astal_wp_device_update_properties(AstalWpDevice *self) {
+ AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
+ if (priv->device == NULL) return;
+ self->id = wp_proxy_get_bound_id(WP_PROXY(priv->device));
+ const gchar *description =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->device), "device.description");
+ if (description == NULL) {
+ description =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->device), "device.name");
+ }
+ if (description == NULL) {
+ description = "unknown";
+ }
+ g_free(self->description);
+ self->description = g_strdup(description);
+
+ const gchar *icon =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->device), "device.icon-name");
+ if (icon == NULL) {
+ icon = "audio-card-symbolic";
+ }
+ g_free(self->icon);
+ self->icon = g_strdup(icon);
+
+ const gchar *type =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->device), "media.class");
+ GEnumClass *enum_class = g_type_class_ref(ASTAL_WP_TYPE_DEVICE_TYPE);
+ if (g_enum_get_value_by_nick(enum_class, type) != NULL)
+ self->type = g_enum_get_value_by_nick(enum_class, type)->value;
+ g_type_class_unref(enum_class);
+
+ astal_wp_device_update_profiles(self);
+ astal_wp_device_update_active_profile(self);
+
+ g_object_notify(G_OBJECT(self), "id");
+ g_object_notify(G_OBJECT(self), "device-type");
+ g_object_notify(G_OBJECT(self), "icon");
+ g_object_notify(G_OBJECT(self), "description");
+}
+
+AstalWpDevice *astal_wp_device_create(WpDevice *device) {
+ AstalWpDevice *self = g_object_new(ASTAL_WP_TYPE_DEVICE, NULL);
+ AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
+
+ priv->device = g_object_ref(device);
+
+ g_signal_connect_swapped(priv->device, "params-changed",
+ G_CALLBACK(astal_wp_device_params_changed), self);
+
+ astal_wp_device_update_properties(self);
+ return self;
+}
+
+static void astal_wp_device_init(AstalWpDevice *self) {
+ AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
+ priv->device = NULL;
+
+ priv->profiles = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref);
+
+ self->description = NULL;
+ self->icon = NULL;
+}
+
+static void astal_wp_device_dispose(GObject *object) {
+ AstalWpDevice *self = ASTAL_WP_DEVICE(object);
+ AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
+
+ g_clear_object(&priv->device);
+}
+
+static void astal_wp_device_finalize(GObject *object) {
+ AstalWpDevice *self = ASTAL_WP_DEVICE(object);
+ g_free(self->description);
+ g_free(self->icon);
+}
+
+static void astal_wp_device_class_init(AstalWpDeviceClass *class) {
+ GObjectClass *object_class = G_OBJECT_CLASS(class);
+ object_class->dispose = astal_wp_device_dispose;
+ object_class->finalize = astal_wp_device_finalize;
+ object_class->get_property = astal_wp_device_get_property;
+ object_class->set_property = astal_wp_device_set_property;
+ /**
+ * AstalWpDevice:id
+ *
+ * The id of this device.
+ */
+ astal_wp_device_properties[ASTAL_WP_DEVICE_PROP_ID] =
+ g_param_spec_uint("id", "id", "id", 0, UINT_MAX, 0, G_PARAM_READABLE);
+ /**
+ * AstalWpDevice:description
+ *
+ * The description of this device.
+ */
+ astal_wp_device_properties[ASTAL_WP_DEVICE_PROP_DESCRIPTION] =
+ g_param_spec_string("description", "description", "description", NULL, G_PARAM_READABLE);
+ /**
+ * AstalWpDevice:icon
+ *
+ * The icon name for this device.
+ */
+ astal_wp_device_properties[ASTAL_WP_DEVICE_PROP_ICON] =
+ g_param_spec_string("icon", "icon", "icon", NULL, G_PARAM_READABLE);
+ /**
+ * AstalWpDevice:device-type: (type AstalWpDeviceType)
+ *
+ * The type of this device
+ */
+ astal_wp_device_properties[ASTAL_WP_DEVICE_PROP_DEVICE_TYPE] =
+ g_param_spec_enum("device-type", "device-type", "device-type", ASTAL_WP_TYPE_DEVICE_TYPE, 1,
+ G_PARAM_READABLE);
+ /**
+ * AstalWpDevice:profiles: (type GList(AstalWpProfile)) (transfer container)
+ *
+ * A list of available profiles
+ */
+ astal_wp_device_properties[ASTAL_WP_DEVICE_PROP_PROFILES] =
+ g_param_spec_pointer("profiles", "profiles", "profiles", G_PARAM_READABLE);
+ /**
+ * AstalWpDevice:active-profile-id
+ *
+ * The id of the currently active profile.
+ */
+ astal_wp_device_properties[ASTAL_WP_DEVICE_PROP_ACTIVE_PROFILE] =
+ g_param_spec_int("active-profile-id", "active-profile-id", "active-profile-id", G_MININT,
+ G_MAXINT, 0, G_PARAM_READWRITE);
+
+ g_object_class_install_properties(object_class, ASTAL_WP_DEVICE_N_PROPERTIES,
+ astal_wp_device_properties);
+}
diff --git a/lib/wireplumber/src/endpoint.c b/lib/wireplumber/src/endpoint.c
new file mode 100644
index 0000000..13979d1
--- /dev/null
+++ b/lib/wireplumber/src/endpoint.c
@@ -0,0 +1,554 @@
+#include "endpoint.h"
+
+#include <wp/wp.h>
+
+#include "device.h"
+#include "endpoint-private.h"
+#include "glib.h"
+#include "wp.h"
+
+struct _AstalWpEndpoint {
+ GObject parent_instance;
+
+ guint id;
+ gdouble volume;
+ gboolean mute;
+ gchar *description;
+ gchar *name;
+ AstalWpMediaClass type;
+ gboolean is_default;
+ gboolean lock_channels;
+
+ gchar *icon;
+};
+
+typedef struct {
+ WpNode *node;
+ WpPlugin *mixer;
+ WpPlugin *defaults;
+ AstalWpWp *wp;
+
+ gboolean is_default_node;
+ AstalWpMediaClass media_class;
+
+ gulong default_signal_handler_id;
+ gulong mixer_signal_handler_id;
+
+} AstalWpEndpointPrivate;
+
+G_DEFINE_FINAL_TYPE_WITH_PRIVATE(AstalWpEndpoint, astal_wp_endpoint, G_TYPE_OBJECT);
+
+G_DEFINE_ENUM_TYPE(AstalWpMediaClass, astal_wp_media_class,
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_MEDIA_CLASS_AUDIO_MICROPHONE, "Audio/Source"),
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER, "Audio/Sink"),
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_MEDIA_CLASS_AUDIO_RECORDER, "Stream/Input/Audio"),
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_MEDIA_CLASS_AUDIO_STREAM, "Stream/Output/Audio"),
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_MEDIA_CLASS_VIDEO_SOURCE, "Video/Source"),
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_MEDIA_CLASS_VIDEO_SINK, "Video/Sink"),
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_MEDIA_CLASS_VIDEO_RECORDER, "Stream/Input/Video"),
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_MEDIA_CLASS_VIDEO_STREAM, "Stream/Output/Video"));
+
+typedef enum {
+ ASTAL_WP_ENDPOINT_PROP_ID = 1,
+ ASTAL_WP_ENDPOINT_PROP_VOLUME,
+ ASTAL_WP_ENDPOINT_PROP_MUTE,
+ ASTAL_WP_ENDPOINT_PROP_DESCRIPTION,
+ ASTAL_WP_ENDPOINT_PROP_NAME,
+ ASTAL_WP_ENDPOINT_PROP_MEDIA_CLASS,
+ ASTAL_WP_ENDPOINT_PROP_DEFAULT,
+ ASTAL_WP_ENDPOINT_PROP_ICON,
+ ASTAL_WP_ENDPOINT_PROP_VOLUME_ICON,
+ ASTAL_WP_ENDPOINT_PROP_LOCK_CHANNELS,
+ ASTAL_WP_ENDPOINT_N_PROPERTIES,
+} AstalWpEndpointProperties;
+
+static GParamSpec *astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_N_PROPERTIES] = {
+ NULL,
+};
+
+void astal_wp_endpoint_update_volume(AstalWpEndpoint *self) {
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+
+ gdouble volume = 0;
+ gboolean mute;
+ GVariant *variant = NULL;
+ GVariantIter *channels = NULL;
+
+ g_signal_emit_by_name(priv->mixer, "get-volume", self->id, &variant);
+
+ if (variant == NULL) return;
+
+ g_variant_lookup(variant, "volume", "d", &volume);
+ g_variant_lookup(variant, "mute", "b", &mute);
+ g_variant_lookup(variant, "channelVolumes", "a{sv}", &channels);
+
+ if (channels != NULL) {
+ const gchar *key;
+ const gchar *channel_str;
+ gdouble channel_volume;
+ GVariant *varvol;
+
+ while (g_variant_iter_loop(channels, "{&sv}", &key, &varvol)) {
+ g_variant_lookup(varvol, "volume", "d", &channel_volume);
+ g_variant_lookup(varvol, "channel", "&s", &channel_str);
+ if (channel_volume > volume) volume = channel_volume;
+ }
+ }
+
+ if (mute != self->mute) {
+ self->mute = mute;
+ g_object_notify(G_OBJECT(self), "mute");
+ }
+
+ if (volume != self->volume) {
+ self->volume = volume;
+ g_object_notify(G_OBJECT(self), "volume");
+ }
+
+ g_object_notify(G_OBJECT(self), "volume-icon");
+}
+
+/**
+ * astal_wp_endpoint_set_volume:
+ * @self: the AstalWpEndpoint object
+ * @volume: The new volume level to set.
+ *
+ * Sets the volume level for this endpoint. The volume is clamped to be between
+ * 0 and 1.5.
+ */
+void astal_wp_endpoint_set_volume(AstalWpEndpoint *self, gdouble volume) {
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+
+ gboolean ret;
+ if (volume >= 1.5) volume = 1.5;
+ if (volume <= 0) volume = 0;
+
+ gboolean mute;
+ GVariant *variant = NULL;
+ GVariantIter *channels = NULL;
+
+ g_auto(GVariantBuilder) vol_b = G_VARIANT_BUILDER_INIT(G_VARIANT_TYPE_VARDICT);
+ g_signal_emit_by_name(priv->mixer, "get-volume", self->id, &variant);
+
+ if (variant == NULL) return;
+
+ g_variant_lookup(variant, "mute", "b", &mute);
+ g_variant_lookup(variant, "channelVolumes", "a{sv}", &channels);
+
+ if (channels != NULL && !self->lock_channels) {
+ g_auto(GVariantBuilder) channel_volumes_b = G_VARIANT_BUILDER_INIT(G_VARIANT_TYPE_VARDICT);
+
+ const gchar *key;
+ const gchar *channel_str;
+ gdouble channel_volume;
+ GVariant *varvol;
+
+ while (g_variant_iter_loop(channels, "{&sv}", &key, &varvol)) {
+ g_auto(GVariantBuilder) channel_b = G_VARIANT_BUILDER_INIT(G_VARIANT_TYPE_VARDICT);
+ g_variant_lookup(varvol, "volume", "d", &channel_volume);
+ g_variant_lookup(varvol, "channel", "&s", &channel_str);
+ gdouble vol = self->volume == 0 ? volume : channel_volume * volume / self->volume;
+ g_variant_builder_add(&channel_b, "{sv}", "volume", g_variant_new_double(vol));
+ g_variant_builder_add(&channel_volumes_b, "{sv}", key,
+ g_variant_builder_end(&channel_b));
+ }
+
+ g_variant_builder_add(&vol_b, "{sv}", "channelVolumes",
+ g_variant_builder_end(&channel_volumes_b));
+ } else {
+ GVariant *volume_variant = g_variant_new_double(volume);
+ g_variant_builder_add(&vol_b, "{sv}", "volume", volume_variant);
+ }
+
+ g_signal_emit_by_name(priv->mixer, "set-volume", self->id, g_variant_builder_end(&vol_b), &ret);
+}
+
+/**
+ * astal_wp_endpoint_set_mute:
+ * @self: the AstalWpEndpoint instance.
+ * @mute: A boolean indicating whether to mute the endpoint.
+ *
+ * Sets the mute status for the endpoint.
+ */
+void astal_wp_endpoint_set_mute(AstalWpEndpoint *self, gboolean mute) {
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+
+ gboolean ret;
+ GVariant *variant = NULL;
+ GVariantBuilder b = G_VARIANT_BUILDER_INIT(G_VARIANT_TYPE_VARDICT);
+ g_variant_builder_add(&b, "{sv}", "mute", g_variant_new_boolean(mute));
+ variant = g_variant_builder_end(&b);
+
+ g_signal_emit_by_name(priv->mixer, "set-volume", self->id, variant, &ret);
+}
+
+/**
+ * astal_wp_endpoint_get_media_class:
+ * @self: the AstalWpEndpoint instance.
+ *
+ * gets the media class of the endpoint.
+ */
+AstalWpMediaClass astal_wp_endpoint_get_media_class(AstalWpEndpoint *self) { return self->type; }
+
+/**
+ * astal_wp_endpoint_get_id:
+ * @self: the AstalWpEndpoint instance.
+ *
+ * gets the id of the endpoint.
+ */
+guint astal_wp_endpoint_get_id(AstalWpEndpoint *self) { return self->id; }
+
+/**
+ * astal_wp_endpoint_get_mute:
+ * @self: the AstalWpEndpoint instance.
+ *
+ * gets the mute status of the endpoint.
+ */
+gboolean astal_wp_endpoint_get_mute(AstalWpEndpoint *self) { return self->mute; }
+
+/**
+ * astal_wp_endpoint_get_volume:
+ * @self: the AstalWpEndpoint instance.
+ *
+ * gets the volume
+ */
+gdouble astal_wp_endpoint_get_volume(AstalWpEndpoint *self) { return self->volume; }
+
+const gchar *astal_wp_endpoint_get_description(AstalWpEndpoint *self) { return self->description; }
+
+const gchar *astal_wp_endpoint_get_name(AstalWpEndpoint *self) { return self->name; }
+
+const gchar *astal_wp_endpoint_get_icon(AstalWpEndpoint *self) { return self->icon; }
+
+gboolean astal_wp_endpoint_get_is_default(AstalWpEndpoint *self) { return self->is_default; }
+
+void astal_wp_endpoint_set_is_default(AstalWpEndpoint *self, gboolean is_default) {
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+
+ if (!is_default) return;
+ gboolean ret;
+ const gchar *name =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "node.name");
+ const gchar *media_class =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "media.class");
+ g_signal_emit_by_name(priv->defaults, "set-default-configured-node-name", media_class, name,
+ &ret);
+}
+
+gboolean astal_wp_endpoint_get_lock_channels(AstalWpEndpoint *self) { return self->lock_channels; }
+
+void astal_wp_endpoint_set_lock_channels(AstalWpEndpoint *self, gboolean lock_channels) {
+ self->lock_channels = lock_channels;
+ astal_wp_endpoint_set_volume(self, self->volume);
+}
+
+const gchar *astal_wp_endpoint_get_volume_icon(AstalWpEndpoint *self) {
+ if (self->type == ASTAL_WP_MEDIA_CLASS_AUDIO_MICROPHONE) {
+ if (self->mute) return "microphone-sensitivity-muted-symbolic";
+ if (self->volume <= 0.33) return "microphone-sensitivity-low-symbolic";
+ if (self->volume <= 0.66) return "microphone-sensitivity-medium-symbolic";
+ return "microphone-sensitivity-high-symbolic";
+
+ } else {
+ if (self->mute) return "audio-volume-muted-symbolic";
+ if (self->volume <= 0.33) return "audio-volume-low-symbolic";
+ if (self->volume <= 0.66) return "audio-volume-medium-symbolic";
+ if (self->volume <= 1) return "audio-volume-high-symbolic";
+ return "audio-volume-overamplified-symbolic";
+ }
+}
+
+static void astal_wp_endpoint_get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec) {
+ AstalWpEndpoint *self = ASTAL_WP_ENDPOINT(object);
+
+ switch (property_id) {
+ case ASTAL_WP_ENDPOINT_PROP_ID:
+ g_value_set_uint(value, self->id);
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_MUTE:
+ g_value_set_boolean(value, self->mute);
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_VOLUME:
+ g_value_set_double(value, self->volume);
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_DESCRIPTION:
+ g_value_set_string(value, self->description);
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_NAME:
+ g_value_set_string(value, self->name);
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_ICON:
+ g_value_set_string(value, self->icon);
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_VOLUME_ICON:
+ g_value_set_string(value, astal_wp_endpoint_get_volume_icon(self));
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_MEDIA_CLASS:
+ g_value_set_enum(value, self->type);
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_DEFAULT:
+ g_value_set_boolean(value, self->is_default);
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_LOCK_CHANNELS:
+ g_value_set_boolean(value, self->lock_channels);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_wp_endpoint_set_property(GObject *object, guint property_id, const GValue *value,
+ GParamSpec *pspec) {
+ AstalWpEndpoint *self = ASTAL_WP_ENDPOINT(object);
+
+ switch (property_id) {
+ case ASTAL_WP_ENDPOINT_PROP_MUTE:
+ astal_wp_endpoint_set_mute(self, g_value_get_boolean(value));
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_VOLUME:
+ astal_wp_endpoint_set_volume(self, g_value_get_double(value));
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_DEFAULT:
+ astal_wp_endpoint_set_is_default(self, g_value_get_boolean(value));
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_ICON:
+ g_free(self->icon);
+ self->icon = g_strdup(g_value_get_string(value));
+ break;
+ case ASTAL_WP_ENDPOINT_PROP_LOCK_CHANNELS:
+ astal_wp_endpoint_set_lock_channels(self, g_value_get_boolean(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_wp_endpoint_update_properties(AstalWpEndpoint *self) {
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+ if (priv->node == NULL) return;
+ self->id = wp_proxy_get_bound_id(WP_PROXY(priv->node));
+ astal_wp_endpoint_update_volume(self);
+
+ const gchar *description =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "node.description");
+ if (description == NULL) {
+ description = wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "node.nick");
+ }
+ if (description == NULL) {
+ description = wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "node.name");
+ }
+ g_free(self->description);
+ self->description = g_strdup(description);
+
+ const gchar *name =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "media.name");
+ g_free(self->name);
+ self->name = g_strdup(name);
+
+ const gchar *type =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "media.class");
+ GEnumClass *enum_class = g_type_class_ref(ASTAL_WP_TYPE_MEDIA_CLASS);
+ if (g_enum_get_value_by_nick(enum_class, type) != NULL)
+ self->type = g_enum_get_value_by_nick(enum_class, type)->value;
+ g_type_class_unref(enum_class);
+
+ const gchar *icon = NULL;
+ switch (self->type) {
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER:
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_MICROPHONE:
+ const gchar *dev =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "device.id");
+ guint device_id = g_ascii_strtoull(dev, NULL, 10);
+ AstalWpDevice *device = astal_wp_wp_get_device(priv->wp, device_id);
+ icon = astal_wp_device_get_icon(device);
+ if (icon == NULL) {
+ icon = self->type == ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER
+ ? "audio-card-symbolic"
+ : "audio-input-microphone-symbolic";
+ }
+ break;
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_STREAM:
+ case ASTAL_WP_MEDIA_CLASS_AUDIO_RECORDER:
+ icon =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "media.icon-name");
+ if (icon == NULL)
+ icon = wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node),
+ "window.icon-name");
+ if (icon == NULL)
+ icon = wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node),
+ "application.icon-name");
+ if (icon == NULL) icon = "application-x-executable-symbolic";
+ break;
+ default:
+ icon = "audio-card-symbolic";
+ }
+ g_free(self->icon);
+ self->icon = g_strdup(icon);
+
+ g_object_notify(G_OBJECT(self), "id");
+ g_object_notify(G_OBJECT(self), "description");
+ g_object_notify(G_OBJECT(self), "name");
+ g_object_notify(G_OBJECT(self), "icon");
+ g_object_notify(G_OBJECT(self), "media-class");
+}
+
+static void astal_wp_endpoint_default_changed_as_default(AstalWpEndpoint *self) {
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+
+ GEnumClass *enum_class = g_type_class_ref(ASTAL_WP_TYPE_MEDIA_CLASS);
+ const gchar *media_class = g_enum_get_value(enum_class, priv->media_class)->value_nick;
+ guint defaultId;
+ g_signal_emit_by_name(priv->defaults, "get-default-node", media_class, &defaultId);
+ g_type_class_unref(enum_class);
+
+ if (defaultId != self->id) {
+ if (priv->node != NULL) g_object_unref(priv->node);
+ AstalWpEndpoint *default_endpoint = astal_wp_wp_get_endpoint(priv->wp, defaultId);
+ if (default_endpoint != NULL &&
+ astal_wp_endpoint_get_media_class(default_endpoint) == priv->media_class) {
+ AstalWpEndpointPrivate *default_endpoint_priv =
+ astal_wp_endpoint_get_instance_private(default_endpoint);
+ priv->node = g_object_ref(default_endpoint_priv->node);
+ astal_wp_endpoint_update_properties(self);
+ }
+ }
+}
+
+static void astal_wp_endpoint_default_changed(AstalWpEndpoint *self) {
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+
+ guint defaultId;
+ const gchar *media_class =
+ wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "media.class");
+ g_signal_emit_by_name(priv->defaults, "get-default-node", media_class, &defaultId);
+
+ if (self->is_default && defaultId != self->id) {
+ self->is_default = FALSE;
+ g_object_notify(G_OBJECT(self), "is-default");
+ } else if (!self->is_default && defaultId == self->id) {
+ self->is_default = TRUE;
+ g_object_notify(G_OBJECT(self), "is-default");
+ }
+}
+
+static void astal_wp_endpoint_mixer_changed(AstalWpEndpoint *self, guint node_id) {
+ if (self->id != node_id) return;
+ astal_wp_endpoint_update_volume(self);
+}
+
+AstalWpEndpoint *astal_wp_endpoint_init_as_default(AstalWpEndpoint *self, WpPlugin *mixer,
+ WpPlugin *defaults, AstalWpMediaClass type,
+ AstalWpWp *wp) {
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+
+ priv->mixer = g_object_ref(mixer);
+ priv->defaults = g_object_ref(defaults);
+
+ priv->media_class = type;
+ priv->is_default_node = TRUE;
+ self->is_default = TRUE;
+ priv->wp = g_object_ref(wp);
+
+ priv->default_signal_handler_id = g_signal_connect_swapped(
+ priv->defaults, "changed", G_CALLBACK(astal_wp_endpoint_default_changed_as_default), self);
+ priv->mixer_signal_handler_id = g_signal_connect_swapped(
+ priv->mixer, "changed", G_CALLBACK(astal_wp_endpoint_mixer_changed), self);
+
+ astal_wp_endpoint_default_changed_as_default(self);
+ astal_wp_endpoint_update_properties(self);
+ return self;
+}
+
+AstalWpEndpoint *astal_wp_endpoint_create(WpNode *node, WpPlugin *mixer, WpPlugin *defaults,
+ AstalWpWp *wp) {
+ AstalWpEndpoint *self = g_object_new(ASTAL_WP_TYPE_ENDPOINT, NULL);
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+
+ priv->mixer = g_object_ref(mixer);
+ priv->defaults = g_object_ref(defaults);
+ priv->node = g_object_ref(node);
+ priv->is_default_node = FALSE;
+ priv->wp = g_object_ref(wp);
+
+ priv->default_signal_handler_id = g_signal_connect_swapped(
+ priv->defaults, "changed", G_CALLBACK(astal_wp_endpoint_default_changed), self);
+ priv->mixer_signal_handler_id = g_signal_connect_swapped(
+ priv->mixer, "changed", G_CALLBACK(astal_wp_endpoint_mixer_changed), self);
+
+ astal_wp_endpoint_update_properties(self);
+ astal_wp_endpoint_default_changed(self);
+ return self;
+}
+
+static void astal_wp_endpoint_init(AstalWpEndpoint *self) {
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+ priv->node = NULL;
+ priv->mixer = NULL;
+ priv->defaults = NULL;
+ priv->wp = NULL;
+
+ self->volume = 0;
+ self->mute = TRUE;
+ self->description = NULL;
+ self->name = NULL;
+}
+
+static void astal_wp_endpoint_dispose(GObject *object) {
+ AstalWpEndpoint *self = ASTAL_WP_ENDPOINT(object);
+ AstalWpEndpointPrivate *priv = astal_wp_endpoint_get_instance_private(self);
+
+ g_signal_handler_disconnect(priv->defaults, priv->default_signal_handler_id);
+ g_signal_handler_disconnect(priv->mixer, priv->mixer_signal_handler_id);
+
+ g_clear_object(&priv->node);
+ g_clear_object(&priv->mixer);
+ g_clear_object(&priv->defaults);
+ g_clear_object(&priv->wp);
+}
+
+static void astal_wp_endpoint_finalize(GObject *object) {
+ AstalWpEndpoint *self = ASTAL_WP_ENDPOINT(object);
+ g_free(self->description);
+ g_free(self->name);
+}
+
+static void astal_wp_endpoint_class_init(AstalWpEndpointClass *class) {
+ GObjectClass *object_class = G_OBJECT_CLASS(class);
+ object_class->dispose = astal_wp_endpoint_dispose;
+ object_class->finalize = astal_wp_endpoint_finalize;
+ object_class->get_property = astal_wp_endpoint_get_property;
+ object_class->set_property = astal_wp_endpoint_set_property;
+
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_ID] =
+ g_param_spec_uint("id", "id", "id", 0, UINT_MAX, 0, G_PARAM_READABLE);
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_VOLUME] =
+ g_param_spec_double("volume", "volume", "volume", 0, G_MAXFLOAT, 0, G_PARAM_READWRITE);
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_MUTE] =
+ g_param_spec_boolean("mute", "mute", "mute", TRUE, G_PARAM_READWRITE);
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_DESCRIPTION] =
+ g_param_spec_string("description", "description", "description", NULL, G_PARAM_READABLE);
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_NAME] =
+ g_param_spec_string("name", "name", "name", NULL, G_PARAM_READABLE);
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_ICON] = g_param_spec_string(
+ "icon", "icon", "icon", "audio-card-symbolic", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_VOLUME_ICON] = g_param_spec_string(
+ "volume-icon", "volume-icon", "volume-icon", "audio-volume-muted", G_PARAM_READABLE);
+ /**
+ * AstalWpEndpoint:media-class: (type AstalWpMediaClass)
+ *
+ * The media class of this endpoint
+ */
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_MEDIA_CLASS] =
+ g_param_spec_enum("media-class", "media-class", "media-class", ASTAL_WP_TYPE_MEDIA_CLASS, 1,
+ G_PARAM_READABLE);
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_DEFAULT] =
+ g_param_spec_boolean("is_default", "is_default", "is_default", FALSE, G_PARAM_READWRITE);
+ astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_LOCK_CHANNELS] = g_param_spec_boolean(
+ "lock_channels", "lock_channels", "lock channels", FALSE, G_PARAM_READWRITE);
+
+ g_object_class_install_properties(object_class, ASTAL_WP_ENDPOINT_N_PROPERTIES,
+ astal_wp_endpoint_properties);
+}
diff --git a/lib/wireplumber/src/meson.build b/lib/wireplumber/src/meson.build
new file mode 100644
index 0000000..8b69c41
--- /dev/null
+++ b/lib/wireplumber/src/meson.build
@@ -0,0 +1,72 @@
+srcs = files(
+ 'audio.c',
+ 'device.c',
+ 'endpoint.c',
+ 'profile.c',
+ 'video.c',
+ 'wireplumber.c',
+)
+
+deps = [
+ dependency('gobject-2.0'),
+ dependency('gio-2.0'),
+ dependency('wireplumber-0.5'),
+]
+
+astal_wireplumber_lib = library(
+ 'astal-wireplumber',
+ sources: srcs,
+ include_directories: astal_wireplumber_inc,
+ dependencies: deps,
+ version: meson.project_version(),
+ install: true,
+)
+
+libastal_wireplumber = declare_dependency(link_with: astal_wireplumber_lib, include_directories: astal_wireplumber_inc)
+
+# astal_wireplumber_executable = executable(
+# 'astal-wireplumber',
+# files('astal-wireplumber.c'),
+# dependencies : [
+# dependency('gobject-2.0'),
+# dependency('gio-2.0'),
+# dependency('json-glib-1.0'),
+# libastal_wireplumber
+# ],
+# install : true)
+
+pkg_config_name = 'astal-wireplumber-' + lib_so_version
+
+if get_option('introspection')
+ gir = gnome.generate_gir(
+ astal_wireplumber_lib,
+ sources: srcs + astal_wireplumber_headers + astal_wireplumber_subheaders,
+ nsversion: '0.1',
+ namespace: 'AstalWp',
+ symbol_prefix: 'astal_wp',
+ identifier_prefix: 'AstalWp',
+ includes: ['GObject-2.0', 'Gio-2.0'],
+ header: 'astal-wp.h',
+ export_packages: pkg_config_name,
+ install: true,
+ )
+
+ if get_option('vapi')
+ gnome.generate_vapi(
+ pkg_config_name,
+ sources: [gir[0]],
+ packages: ['gobject-2.0', 'gio-2.0'],
+ install: true,
+ )
+ endif
+endif
+
+pkg_config.generate(
+ name: 'astal-wireplumber',
+ version: meson.project_version(),
+ libraries: [astal_wireplumber_lib],
+ filebase: pkg_config_name,
+ subdirs: 'astal',
+ description: 'astal wireplumber module',
+ url: 'https://github.com/astal-sh/wireplumber',
+)
diff --git a/lib/wireplumber/src/profile.c b/lib/wireplumber/src/profile.c
new file mode 100644
index 0000000..291dc7f
--- /dev/null
+++ b/lib/wireplumber/src/profile.c
@@ -0,0 +1,84 @@
+#include "profile.h"
+
+#include <wp/wp.h>
+
+struct _AstalWpProfile {
+ GObject parent_instance;
+
+ gint index;
+ gchar *description;
+};
+
+G_DEFINE_FINAL_TYPE(AstalWpProfile, astal_wp_profile, G_TYPE_OBJECT);
+
+typedef enum {
+ ASTAL_WP_PROFILE_PROP_INDEX = 1,
+ ASTAL_WP_PROFILE_PROP_DESCRIPTION,
+ ASTAL_WP_PROFILE_N_PROPERTIES,
+} AstalWpProfileProperties;
+
+static GParamSpec *astal_wp_profile_properties[ASTAL_WP_PROFILE_N_PROPERTIES] = {
+ NULL,
+};
+
+gint astal_wp_profile_get_index(AstalWpProfile *self) { return self->index; }
+
+const gchar *astal_wp_profile_get_description(AstalWpProfile *self) { return self->description; }
+
+static void astal_wp_profile_get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec) {
+ AstalWpProfile *self = ASTAL_WP_PROFILE(object);
+
+ switch (property_id) {
+ case ASTAL_WP_PROFILE_PROP_INDEX:
+ g_value_set_int(value, self->index);
+ break;
+ case ASTAL_WP_PROFILE_PROP_DESCRIPTION:
+ g_value_set_string(value, self->description);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_wp_profile_set_property(GObject *object, guint property_id, const GValue *value,
+ GParamSpec *pspec) {
+ AstalWpProfile *self = ASTAL_WP_PROFILE(object);
+
+ switch (property_id) {
+ case ASTAL_WP_PROFILE_PROP_INDEX:
+ self->index = g_value_get_int(value);
+ break;
+ case ASTAL_WP_PROFILE_PROP_DESCRIPTION:
+ g_free(self->description);
+ self->description = g_strdup(g_value_get_string(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_wp_profile_init(AstalWpProfile *self) { self->description = NULL; }
+
+static void astal_wp_profile_finalize(GObject *object) {
+ AstalWpProfile *self = ASTAL_WP_PROFILE(object);
+ g_free(self->description);
+}
+
+static void astal_wp_profile_class_init(AstalWpProfileClass *class) {
+ GObjectClass *object_class = G_OBJECT_CLASS(class);
+ object_class->finalize = astal_wp_profile_finalize;
+ object_class->get_property = astal_wp_profile_get_property;
+ object_class->set_property = astal_wp_profile_set_property;
+
+ astal_wp_profile_properties[ASTAL_WP_PROFILE_PROP_DESCRIPTION] =
+ g_param_spec_string("description", "description", "description", NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ astal_wp_profile_properties[ASTAL_WP_PROFILE_PROP_INDEX] =
+ g_param_spec_int("index", "index", "index", G_MININT, G_MAXINT, 0,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_properties(object_class, ASTAL_WP_PROFILE_N_PROPERTIES,
+ astal_wp_profile_properties);
+}
diff --git a/lib/wireplumber/src/video.c b/lib/wireplumber/src/video.c
new file mode 100644
index 0000000..00cdd82
--- /dev/null
+++ b/lib/wireplumber/src/video.c
@@ -0,0 +1,428 @@
+#include "video.h"
+
+#include <wp/wp.h>
+
+#include "device.h"
+#include "endpoint.h"
+#include "wp.h"
+
+struct _AstalWpVideo {
+ GObject parent_instance;
+};
+
+typedef struct {
+ AstalWpWp *wp;
+} AstalWpVideoPrivate;
+
+G_DEFINE_FINAL_TYPE_WITH_PRIVATE(AstalWpVideo, astal_wp_video, G_TYPE_OBJECT);
+
+typedef enum {
+ ASTAL_WP_VIDEO_SIGNAL_SOURCE_ADDED,
+ ASTAL_WP_VIDEO_SIGNAL_SOURCE_REMOVED,
+ ASTAL_WP_VIDEO_SIGNAL_SINK_ADDED,
+ ASTAL_WP_VIDEO_SIGNAL_SINK_REMOVED,
+ ASTAL_WP_VIDEO_SIGNAL_STREAM_ADDED,
+ ASTAL_WP_VIDEO_SIGNAL_STREAM_REMOVED,
+ ASTAL_WP_VIDEO_SIGNAL_RECORDER_ADDED,
+ ASTAL_WP_VIDEO_SIGNAL_RECORDER_REMOVED,
+ ASTAL_WP_VIDEO_SIGNAL_DEVICE_ADDED,
+ ASTAL_WP_VIDEO_SIGNAL_DEVICE_REMOVED,
+ ASTAL_WP_VIDEO_N_SIGNALS
+} AstalWpWpSignals;
+
+static guint astal_wp_video_signals[ASTAL_WP_VIDEO_N_SIGNALS] = {
+ 0,
+};
+
+typedef enum {
+ ASTAL_WP_VIDEO_PROP_SOURCE = 1,
+ ASTAL_WP_VIDEO_PROP_SINK,
+ ASTAL_WP_VIDEO_PROP_STREAMS,
+ ASTAL_WP_VIDEO_PROP_RECORDERS,
+ ASTAL_WP_VIDEO_PROP_DEVICES,
+ ASTAL_WP_VIDEO_N_PROPERTIES,
+} AstalWpVideoProperties;
+
+static GParamSpec *astal_wp_video_properties[ASTAL_WP_VIDEO_N_PROPERTIES] = {
+ NULL,
+};
+
+/**
+ * astal_wp_video_get_source:
+ * @self: the AstalWpVideo object
+ * @id: the id of the endpoint
+ *
+ * Returns: (transfer none) (nullable): the source with the given id
+ */
+AstalWpEndpoint *astal_wp_video_get_speaker(AstalWpVideo *self, guint id) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = astal_wp_wp_get_endpoint(priv->wp, id);
+ if (astal_wp_endpoint_get_media_class(endpoint) == ASTAL_WP_MEDIA_CLASS_VIDEO_SOURCE)
+ return endpoint;
+ return NULL;
+}
+
+/**
+ * astal_wp_video_get_sink:
+ * @self: the AstalWpVideo object
+ * @id: the id of the endpoint
+ *
+ * Returns: (transfer none) (nullable): the sink with the given id
+ */
+AstalWpEndpoint *astal_wp_video_get_sink(AstalWpVideo *self, guint id) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = astal_wp_wp_get_endpoint(priv->wp, id);
+ if (astal_wp_endpoint_get_media_class(endpoint) == ASTAL_WP_MEDIA_CLASS_VIDEO_SINK)
+ return endpoint;
+ return NULL;
+}
+
+/**
+ * astal_wp_video_get_stream:
+ * @self: the AstalWpVideo object
+ * @id: the id of the endpoint
+ *
+ * Returns: (transfer none) (nullable): the stream with the given id
+ */
+AstalWpEndpoint *astal_wp_video_get_stream(AstalWpVideo *self, guint id) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = astal_wp_wp_get_endpoint(priv->wp, id);
+ if (astal_wp_endpoint_get_media_class(endpoint) == ASTAL_WP_MEDIA_CLASS_VIDEO_STREAM)
+ return endpoint;
+ return NULL;
+}
+
+/**
+ * astal_wp_video_get_recorder:
+ * @self: the AstalWpVideo object
+ * @id: the id of the endpoint
+ *
+ * Returns: (transfer none) (nullable): the recorder with the given id
+ */
+AstalWpEndpoint *astal_wp_video_get_recorder(AstalWpVideo *self, guint id) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = astal_wp_wp_get_endpoint(priv->wp, id);
+ if (astal_wp_endpoint_get_media_class(endpoint) == ASTAL_WP_MEDIA_CLASS_VIDEO_RECORDER)
+ return endpoint;
+ return NULL;
+}
+
+/**
+ * astal_wp_video_get_device:
+ * @self: the AstalWpVideo object
+ * @id: the id of the device
+ *
+ * Returns: (transfer none) (nullable): the device with the given id
+ */
+AstalWpDevice *astal_wp_video_get_device(AstalWpVideo *self, guint id) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+
+ AstalWpDevice *device = astal_wp_wp_get_device(priv->wp, id);
+ if (astal_wp_device_get_device_type(device) == ASTAL_WP_DEVICE_TYPE_VIDEO) return device;
+ return NULL;
+}
+
+/**
+ * astal_wp_video_get_sources:
+ * @self: the AstalWpVideo object
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpEndpoint)): a GList containing the
+ * video sources
+ */
+GList *astal_wp_video_get_sources(AstalWpVideo *self) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_endpoints(priv->wp);
+ GList *list = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_endpoint_get_media_class(l->data) == ASTAL_WP_MEDIA_CLASS_VIDEO_SOURCE) {
+ list = g_list_append(list, l->data);
+ }
+ }
+ g_list_free(eps);
+ return list;
+}
+
+/**
+ * astal_wp_video_get_sinks
+ * @self: the AstalWpVideo object
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpEndpoint)): a GList containing the
+ * video sinks
+ */
+GList *astal_wp_video_get_sinks(AstalWpVideo *self) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_endpoints(priv->wp);
+ GList *list = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_endpoint_get_media_class(l->data) == ASTAL_WP_MEDIA_CLASS_VIDEO_SINK) {
+ list = g_list_append(list, l->data);
+ }
+ }
+ g_list_free(eps);
+ return list;
+}
+
+/**
+ * astal_wp_video_get_recorders:
+ * @self: the AstalWpVideo object
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpEndpoint)): a GList containing the
+ * video recorders
+ */
+GList *astal_wp_video_get_recorders(AstalWpVideo *self) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_endpoints(priv->wp);
+ GList *list = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_endpoint_get_media_class(l->data) == ASTAL_WP_MEDIA_CLASS_VIDEO_RECORDER) {
+ list = g_list_append(list, l->data);
+ }
+ }
+ g_list_free(eps);
+ return list;
+}
+
+/**
+ * astal_wp_video_get_streams:
+ * @self: the AstalWpVideo object
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpEndpoint)): a GList containing the
+ * video streams
+ */
+GList *astal_wp_video_get_streams(AstalWpVideo *self) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_endpoints(priv->wp);
+ GList *list = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_endpoint_get_media_class(l->data) == ASTAL_WP_MEDIA_CLASS_VIDEO_STREAM) {
+ list = g_list_append(list, l->data);
+ }
+ }
+ g_list_free(eps);
+ return list;
+}
+
+/**
+ * astal_wp_video_get_devices:
+ * @self: the AstalWpAudio object
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpVideo)): a GList containing the
+ * devices
+ */
+GList *astal_wp_video_get_devices(AstalWpVideo *self) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+ GList *eps = astal_wp_wp_get_devices(priv->wp);
+ GList *list = NULL;
+
+ for (GList *l = eps; l != NULL; l = l->next) {
+ if (astal_wp_device_get_device_type(l->data) == ASTAL_WP_DEVICE_TYPE_VIDEO) {
+ list = g_list_append(list, l->data);
+ }
+ }
+ g_list_free(eps);
+ return list;
+}
+
+static void astal_wp_video_get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec) {
+ AstalWpVideo *self = ASTAL_WP_VIDEO(object);
+
+ switch (property_id) {
+ case ASTAL_WP_VIDEO_PROP_SOURCE:
+ g_value_set_pointer(value, astal_wp_video_get_sources(self));
+ break;
+ case ASTAL_WP_VIDEO_PROP_SINK:
+ g_value_set_pointer(value, astal_wp_video_get_sinks(self));
+ break;
+ case ASTAL_WP_VIDEO_PROP_RECORDERS:
+ g_value_set_pointer(value, astal_wp_video_get_recorders(self));
+ break;
+ case ASTAL_WP_VIDEO_PROP_STREAMS:
+ g_value_set_pointer(value, astal_wp_video_get_streams(self));
+ break;
+ case ASTAL_WP_VIDEO_PROP_DEVICES:
+ g_value_set_pointer(value, astal_wp_video_get_devices(self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+void astal_wp_video_device_added(AstalWpVideo *self, gpointer object) {
+ AstalWpDevice *device = ASTAL_WP_DEVICE(object);
+ if (astal_wp_device_get_device_type(device) == ASTAL_WP_DEVICE_TYPE_VIDEO) {
+ g_signal_emit_by_name(self, "device-added", device);
+ g_object_notify(G_OBJECT(self), "devices");
+ }
+}
+
+static void astal_wp_video_device_removed(AstalWpVideo *self, gpointer object) {
+ AstalWpDevice *device = ASTAL_WP_DEVICE(object);
+ if (astal_wp_device_get_device_type(device) == ASTAL_WP_DEVICE_TYPE_VIDEO) {
+ g_signal_emit_by_name(self, "device-removed", device);
+ g_object_notify(G_OBJECT(self), "devices");
+ }
+}
+
+static void astal_wp_video_object_added(AstalWpVideo *self, gpointer object) {
+ AstalWpEndpoint *endpoint = ASTAL_WP_ENDPOINT(object);
+ switch (astal_wp_endpoint_get_media_class(endpoint)) {
+ case ASTAL_WP_MEDIA_CLASS_VIDEO_SOURCE:
+ g_signal_emit_by_name(self, "source-added", endpoint);
+ g_object_notify(G_OBJECT(self), "sources");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_VIDEO_SINK:
+ g_signal_emit_by_name(self, "sink-added", endpoint);
+ g_object_notify(G_OBJECT(self), "sinks");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_VIDEO_STREAM:
+ g_signal_emit_by_name(self, "stream-added", endpoint);
+ g_object_notify(G_OBJECT(self), "streams");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_VIDEO_RECORDER:
+ g_signal_emit_by_name(self, "recorder-added", endpoint);
+ g_object_notify(G_OBJECT(self), "recorders");
+ break;
+ default:
+ break;
+ }
+}
+
+static void astal_wp_video_object_removed(AstalWpAudio *self, gpointer object) {
+ AstalWpEndpoint *endpoint = ASTAL_WP_ENDPOINT(object);
+ switch (astal_wp_endpoint_get_media_class(endpoint)) {
+ case ASTAL_WP_MEDIA_CLASS_VIDEO_SOURCE:
+ g_signal_emit_by_name(self, "source-removed", endpoint);
+ g_object_notify(G_OBJECT(self), "sources");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_VIDEO_SINK:
+ g_signal_emit_by_name(self, "sink-removed", endpoint);
+ g_object_notify(G_OBJECT(self), "sinks");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_VIDEO_STREAM:
+ g_signal_emit_by_name(self, "stream-removed", endpoint);
+ g_object_notify(G_OBJECT(self), "streams");
+ break;
+ case ASTAL_WP_MEDIA_CLASS_VIDEO_RECORDER:
+ g_signal_emit_by_name(self, "recorder-removed", endpoint);
+ g_object_notify(G_OBJECT(self), "recorders");
+ break;
+ default:
+ break;
+ }
+}
+
+AstalWpVideo *astal_wp_video_new(AstalWpWp *wp) {
+ AstalWpVideo *self = g_object_new(ASTAL_WP_TYPE_VIDEO, NULL);
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+ priv->wp = g_object_ref(wp);
+ g_signal_connect_swapped(priv->wp, "endpoint-added", G_CALLBACK(astal_wp_video_object_added),
+ self);
+ g_signal_connect_swapped(priv->wp, "endpoint-removed",
+ G_CALLBACK(astal_wp_video_object_removed), self);
+ g_signal_connect_swapped(priv->wp, "device-added", G_CALLBACK(astal_wp_video_device_added),
+ self);
+ g_signal_connect_swapped(priv->wp, "device-removed", G_CALLBACK(astal_wp_video_device_removed),
+ self);
+
+ return self;
+}
+
+static void astal_wp_video_dispose(GObject *object) {
+ AstalWpVideo *self = ASTAL_WP_VIDEO(object);
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+ g_clear_object(&priv->wp);
+}
+
+static void astal_wp_video_init(AstalWpVideo *self) {
+ AstalWpVideoPrivate *priv = astal_wp_video_get_instance_private(self);
+}
+
+static void astal_wp_video_class_init(AstalWpVideoClass *class) {
+ GObjectClass *object_class = G_OBJECT_CLASS(class);
+ object_class->get_property = astal_wp_video_get_property;
+ object_class->dispose = astal_wp_video_dispose;
+
+ /**
+ * AstalWpVideo:sources: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_video_properties[ASTAL_WP_VIDEO_PROP_SOURCE] =
+ g_param_spec_pointer("sources", "sources", "sources", G_PARAM_READABLE);
+
+ /**
+ * AstalWpVideo:sinks: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_video_properties[ASTAL_WP_VIDEO_PROP_SINK] =
+ g_param_spec_pointer("sinks", "sinks", "sinks", G_PARAM_READABLE);
+
+ /**
+ * AstalWpVideo:recorder: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_video_properties[ASTAL_WP_VIDEO_PROP_RECORDERS] =
+ g_param_spec_pointer("recorders", "recorders", "recorders", G_PARAM_READABLE);
+
+ /**
+ * AstalWpVideo:streams: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_video_properties[ASTAL_WP_VIDEO_PROP_STREAMS] =
+ g_param_spec_pointer("streams", "streams", "streams", G_PARAM_READABLE);
+
+ /**
+ * AstalWpVideo:devices: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_video_properties[ASTAL_WP_VIDEO_PROP_DEVICES] =
+ g_param_spec_pointer("devices", "devices", "devices", G_PARAM_READABLE);
+
+ g_object_class_install_properties(object_class, ASTAL_WP_VIDEO_N_PROPERTIES,
+ astal_wp_video_properties);
+
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_SOURCE_ADDED] =
+ g_signal_new("source-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_SOURCE_REMOVED] =
+ g_signal_new("source-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_SINK_ADDED] =
+ g_signal_new("sink-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_SINK_REMOVED] =
+ g_signal_new("sink-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_STREAM_ADDED] =
+ g_signal_new("stream-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_SOURCE_REMOVED] =
+ g_signal_new("stream-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_RECORDER_ADDED] =
+ g_signal_new("recorder-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_RECORDER_REMOVED] =
+ g_signal_new("recorder-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL,
+ NULL, NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_DEVICE_ADDED] =
+ g_signal_new("device-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_DEVICE);
+ astal_wp_video_signals[ASTAL_WP_VIDEO_SIGNAL_DEVICE_REMOVED] =
+ g_signal_new("device-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_DEVICE);
+}
diff --git a/lib/wireplumber/src/wireplumber.c b/lib/wireplumber/src/wireplumber.c
new file mode 100644
index 0000000..f1fa516
--- /dev/null
+++ b/lib/wireplumber/src/wireplumber.c
@@ -0,0 +1,503 @@
+#include <wp/wp.h>
+
+#include "audio.h"
+#include "device-private.h"
+#include "endpoint-private.h"
+#include "glib-object.h"
+#include "glib.h"
+#include "video.h"
+#include "wp.h"
+
+struct _AstalWpWp {
+ GObject parent_instance;
+
+ AstalWpEndpoint *default_speaker;
+ AstalWpEndpoint *default_microphone;
+
+ AstalWpAudio *audio;
+ AstalWpVideo *video;
+
+ AstalWpScale scale;
+};
+
+typedef struct {
+ WpCore *core;
+ WpObjectManager *obj_manager;
+
+ WpPlugin *mixer;
+ WpPlugin *defaults;
+ gint pending_plugins;
+
+ GHashTable *endpoints;
+ GHashTable *devices;
+} AstalWpWpPrivate;
+
+G_DEFINE_FINAL_TYPE_WITH_PRIVATE(AstalWpWp, astal_wp_wp, G_TYPE_OBJECT);
+
+G_DEFINE_ENUM_TYPE(AstalWpScale, astal_wp_scale,
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_SCALE_LINEAR, "linear"),
+ G_DEFINE_ENUM_VALUE(ASTAL_WP_SCALE_CUBIC, "cubic"));
+
+typedef enum {
+ ASTAL_WP_WP_SIGNAL_ENDPOINT_ADDED,
+ ASTAL_WP_WP_SIGNAL_ENDPOINT_REMOVED,
+ ASTAL_WP_WP_SIGNAL_DEVICE_ADDED,
+ ASTAL_WP_WP_SIGNAL_DEVICE_REMOVED,
+ ASTAL_WP_WP_N_SIGNALS
+} AstalWpWpSignals;
+
+static guint astal_wp_wp_signals[ASTAL_WP_WP_N_SIGNALS] = {
+ 0,
+};
+
+typedef enum {
+ ASTAL_WP_WP_PROP_AUDIO = 1,
+ ASTAL_WP_WP_PROP_VIDEO,
+ ASTAL_WP_WP_PROP_ENDPOINTS,
+ ASTAL_WP_WP_PROP_DEVICES,
+ ASTAL_WP_WP_PROP_DEFAULT_SPEAKER,
+ ASTAL_WP_WP_PROP_DEFAULT_MICROPHONE,
+ ASTAL_WP_WP_PROP_SCALE,
+ ASTAL_WP_WP_N_PROPERTIES,
+} AstalWpWpProperties;
+
+static GParamSpec *astal_wp_wp_properties[ASTAL_WP_WP_N_PROPERTIES] = {
+ NULL,
+};
+
+/**
+ * astal_wp_wp_get_endpoint:
+ * @self: the AstalWpWp object
+ * @id: the id of the endpoint
+ *
+ * Returns: (transfer none) (nullable): the endpoint with the given id
+ */
+AstalWpEndpoint *astal_wp_wp_get_endpoint(AstalWpWp *self, guint id) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ AstalWpEndpoint *endpoint = g_hash_table_lookup(priv->endpoints, GUINT_TO_POINTER(id));
+ return endpoint;
+}
+
+/**
+ * astal_wp_wp_get_endpoints:
+ * @self: the AstalWpWp object
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpEndpoint)): a GList containing the
+ * endpoints
+ */
+GList *astal_wp_wp_get_endpoints(AstalWpWp *self) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+ return g_hash_table_get_values(priv->endpoints);
+}
+
+/**
+ * astal_wp_wp_get_device:
+ * @self: the AstalWpWp object
+ * @id: the id of the device
+ *
+ * Returns: (transfer none) (nullable): the device with the given id
+ */
+AstalWpDevice *astal_wp_wp_get_device(AstalWpWp *self, guint id) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ AstalWpDevice *device = g_hash_table_lookup(priv->devices, GUINT_TO_POINTER(id));
+ return device;
+}
+
+/**
+ * astal_wp_wp_get_devices:
+ * @self: the AstalWpWp object
+ *
+ * Returns: (transfer container) (nullable) (type GList(AstalWpDevice)): a GList containing the
+ * devices
+ */
+GList *astal_wp_wp_get_devices(AstalWpWp *self) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+ return g_hash_table_get_values(priv->devices);
+}
+
+/**
+ * astal_wp_wp_get_audio
+ *
+ * Returns: (nullable) (transfer none): gets the audio object
+ */
+AstalWpAudio *astal_wp_wp_get_audio(AstalWpWp *self) { return self->audio; }
+
+/**
+ * astal_wp_wp_get_video
+ *
+ * Returns: (nullable) (transfer none): gets the video object
+ */
+AstalWpVideo *astal_wp_wp_get_video(AstalWpWp *self) { return self->video; }
+
+/**
+ * astal_wp_wp_get_default_speaker
+ *
+ * Returns: (nullable) (transfer none): gets the default speaker object
+ */
+AstalWpEndpoint *astal_wp_wp_get_default_speaker(AstalWpWp *self) { return self->default_speaker; }
+
+/**
+ * astal_wp_wp_get_default_microphone
+ *
+ * Returns: (nullable) (transfer none): gets the default microphone object
+ */
+AstalWpEndpoint *astal_wp_wp_get_default_microphone(AstalWpWp *self) {
+ return self->default_microphone;
+}
+
+AstalWpScale astal_wp_wp_get_scale(AstalWpWp *self) { return self->scale; }
+
+void astal_wp_wp_set_scale(AstalWpWp *self, AstalWpScale scale) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+ self->scale = scale;
+
+ if (priv->mixer == NULL) return;
+
+ g_object_set(priv->mixer, "scale", self->scale, NULL);
+
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, priv->endpoints);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ AstalWpEndpoint *ep = ASTAL_WP_ENDPOINT(value);
+ astal_wp_endpoint_update_volume(ep);
+ }
+
+ astal_wp_endpoint_update_volume(self->default_speaker);
+ astal_wp_endpoint_update_volume(self->default_microphone);
+}
+
+static void astal_wp_wp_get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec) {
+ AstalWpWp *self = ASTAL_WP_WP(object);
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ switch (property_id) {
+ case ASTAL_WP_WP_PROP_AUDIO:
+ g_value_set_object(value, astal_wp_wp_get_audio(self));
+ break;
+ case ASTAL_WP_WP_PROP_VIDEO:
+ g_value_set_object(value, astal_wp_wp_get_video(self));
+ break;
+ case ASTAL_WP_WP_PROP_ENDPOINTS:
+ g_value_set_pointer(value, g_hash_table_get_values(priv->endpoints));
+ break;
+ case ASTAL_WP_WP_PROP_DEVICES:
+ g_value_set_pointer(value, g_hash_table_get_values(priv->devices));
+ break;
+ case ASTAL_WP_WP_PROP_DEFAULT_SPEAKER:
+ g_value_set_object(value, self->default_speaker);
+ break;
+ case ASTAL_WP_WP_PROP_DEFAULT_MICROPHONE:
+ g_value_set_object(value, self->default_microphone);
+ break;
+ case ASTAL_WP_WP_PROP_SCALE:
+ g_value_set_enum(value, self->scale);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_wp_wp_set_property(GObject *object, guint property_id, const GValue *value,
+ GParamSpec *pspec) {
+ AstalWpWp *self = ASTAL_WP_WP(object);
+
+ switch (property_id) {
+ case ASTAL_WP_WP_PROP_SCALE:
+ astal_wp_wp_set_scale(self, g_value_get_enum(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void astal_wp_wp_object_added(AstalWpWp *self, gpointer object) {
+ // print pipewire properties
+ // WpIterator *iter = wp_pipewire_object_new_properties_iterator(WP_PIPEWIRE_OBJECT(object));
+ // GValue item = G_VALUE_INIT;
+ // const gchar *key, *value;
+ //
+ // g_print("\n\n");
+ // while (wp_iterator_next (iter, &item)) {
+ // WpPropertiesItem *pi = g_value_get_boxed (&item);
+ // key = wp_properties_item_get_key (pi);
+ // value = wp_properties_item_get_value (pi);
+ // g_print("%s: %s\n", key, value);
+ // g_value_unset(&item);
+ // }
+
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ if (WP_IS_NODE(object)) {
+ WpNode *node = WP_NODE(object);
+ AstalWpEndpoint *endpoint =
+ astal_wp_endpoint_create(node, priv->mixer, priv->defaults, self);
+
+ g_hash_table_insert(priv->endpoints,
+ GUINT_TO_POINTER(wp_proxy_get_bound_id(WP_PROXY(node))), endpoint);
+
+ g_signal_emit_by_name(self, "endpoint-added", endpoint);
+ g_object_notify(G_OBJECT(self), "endpoints");
+ } else if (WP_IS_DEVICE(object)) {
+ WpDevice *node = WP_DEVICE(object);
+ AstalWpDevice *device = astal_wp_device_create(node);
+ g_hash_table_insert(priv->devices, GUINT_TO_POINTER(wp_proxy_get_bound_id(WP_PROXY(node))),
+ device);
+ g_signal_emit_by_name(self, "device-added", device);
+ g_object_notify(G_OBJECT(self), "devices");
+ }
+}
+
+static void astal_wp_wp_object_removed(AstalWpWp *self, gpointer object) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ if (WP_IS_NODE(object)) {
+ guint id = wp_proxy_get_bound_id(WP_PROXY(object));
+ AstalWpEndpoint *endpoint =
+ g_object_ref(g_hash_table_lookup(priv->endpoints, GUINT_TO_POINTER(id)));
+
+ g_hash_table_remove(priv->endpoints, GUINT_TO_POINTER(id));
+
+ g_signal_emit_by_name(self, "endpoint-removed", endpoint);
+ g_object_notify(G_OBJECT(self), "endpoints");
+ g_object_unref(endpoint);
+ } else if (WP_IS_DEVICE(object)) {
+ guint id = wp_proxy_get_bound_id(WP_PROXY(object));
+ AstalWpDevice *device =
+ g_object_ref(g_hash_table_lookup(priv->devices, GUINT_TO_POINTER(id)));
+ g_hash_table_remove(priv->devices, GUINT_TO_POINTER(id));
+
+ g_signal_emit_by_name(self, "device-removed", device);
+ g_object_notify(G_OBJECT(self), "devices");
+ g_object_unref(device);
+ }
+}
+
+static void astal_wp_wp_objm_installed(AstalWpWp *self) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ astal_wp_endpoint_init_as_default(self->default_speaker, priv->mixer, priv->defaults,
+ ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER, self);
+ astal_wp_endpoint_init_as_default(self->default_microphone, priv->mixer, priv->defaults,
+ ASTAL_WP_MEDIA_CLASS_AUDIO_MICROPHONE, self);
+}
+
+static void astal_wp_wp_plugin_activated(WpObject *obj, GAsyncResult *result, AstalWpWp *self) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ GError *error = NULL;
+ wp_object_activate_finish(obj, result, &error);
+ if (error) {
+ g_critical("Failed to activate component: %s\n", error->message);
+ return;
+ }
+
+ if (--priv->pending_plugins == 0) {
+ priv->defaults = wp_plugin_find(priv->core, "default-nodes-api");
+ priv->mixer = wp_plugin_find(priv->core, "mixer-api");
+ g_object_set(priv->mixer, "scale", self->scale, NULL);
+
+ g_signal_connect_swapped(priv->obj_manager, "object-added",
+ G_CALLBACK(astal_wp_wp_object_added), self);
+ g_signal_connect_swapped(priv->obj_manager, "object-removed",
+ G_CALLBACK(astal_wp_wp_object_removed), self);
+
+ wp_core_install_object_manager(priv->core, priv->obj_manager);
+ }
+}
+
+static void astal_wp_wp_plugin_loaded(WpObject *obj, GAsyncResult *result, AstalWpWp *self) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ GError *error = NULL;
+ wp_core_load_component_finish(priv->core, result, &error);
+ if (error) {
+ g_critical("Failed to load component: %s\n", error->message);
+ return;
+ }
+
+ wp_object_activate(obj, WP_PLUGIN_FEATURE_ENABLED, NULL,
+ (GAsyncReadyCallback)astal_wp_wp_plugin_activated, self);
+}
+
+/**
+ * astal_wp_wp_get_default
+ *
+ * Returns: (nullable) (transfer none): gets the default wireplumber object.
+ */
+AstalWpWp *astal_wp_wp_get_default() {
+ static AstalWpWp *self = NULL;
+
+ if (self == NULL) self = g_object_new(ASTAL_WP_TYPE_WP, NULL);
+
+ return self;
+}
+
+/**
+ * astal_wp_get_default_wp
+ *
+ * Returns: (nullable) (transfer none): gets the default wireplumber object.
+ */
+AstalWpWp *astal_wp_get_default_wp() { return astal_wp_wp_get_default(); }
+
+static void astal_wp_wp_dispose(GObject *object) {
+ AstalWpWp *self = ASTAL_WP_WP(object);
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ g_clear_object(&self->video);
+ g_clear_object(&self->audio);
+
+ wp_core_disconnect(priv->core);
+ g_clear_object(&self->default_speaker);
+ g_clear_object(&self->default_microphone);
+ g_clear_object(&priv->mixer);
+ g_clear_object(&priv->defaults);
+ g_clear_object(&priv->obj_manager);
+ g_clear_object(&priv->core);
+
+ if (priv->endpoints != NULL) {
+ g_hash_table_destroy(priv->endpoints);
+ priv->endpoints = NULL;
+ }
+}
+
+static void astal_wp_wp_finalize(GObject *object) {
+ AstalWpWp *self = ASTAL_WP_WP(object);
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+}
+
+static void astal_wp_wp_init(AstalWpWp *self) {
+ AstalWpWpPrivate *priv = astal_wp_wp_get_instance_private(self);
+
+ priv->endpoints = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref);
+ priv->devices = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref);
+
+ wp_init(7);
+ priv->core = wp_core_new(NULL, NULL, NULL);
+
+ if (!wp_core_connect(priv->core)) {
+ g_critical("could not connect to PipeWire\n");
+ return;
+ }
+
+ priv->obj_manager = wp_object_manager_new();
+ wp_object_manager_request_object_features(priv->obj_manager, WP_TYPE_NODE,
+ WP_OBJECT_FEATURES_ALL);
+ wp_object_manager_request_object_features(priv->obj_manager, WP_TYPE_GLOBAL_PROXY,
+ WP_OBJECT_FEATURES_ALL);
+
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY,
+ "media.class", "=s", "Audio/Sink", NULL);
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY,
+ "media.class", "=s", "Audio/Source", NULL);
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY,
+ "media.class", "=s", "Stream/Output/Audio", NULL);
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY,
+ "media.class", "=s", "Stream/Input/Audio", NULL);
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_DEVICE,
+ WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "media.class", "=s",
+ "Audio/Device", NULL);
+
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY,
+ "media.class", "=s", "Video/Sink", NULL);
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY,
+ "media.class", "=s", "Video/Source", NULL);
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY,
+ "media.class", "=s", "Stream/Output/Video", NULL);
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY,
+ "media.class", "=s", "Stream/Input/Video", NULL);
+ wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_DEVICE,
+ WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "media.class", "=s",
+ "Video/Device", NULL);
+ // wp_object_manager_add_interest(priv->obj_manager, WP_TYPE_CLIENT, NULL);
+
+ g_signal_connect_swapped(priv->obj_manager, "installed", (GCallback)astal_wp_wp_objm_installed,
+ self);
+
+ self->default_speaker = g_object_new(ASTAL_WP_TYPE_ENDPOINT, NULL);
+ self->default_microphone = g_object_new(ASTAL_WP_TYPE_ENDPOINT, NULL);
+
+ self->audio = astal_wp_audio_new(self);
+ self->video = astal_wp_video_new(self);
+
+ priv->pending_plugins = 2;
+ wp_core_load_component(priv->core, "libwireplumber-module-default-nodes-api", "module", NULL,
+ "default-nodes-api", NULL,
+ (GAsyncReadyCallback)astal_wp_wp_plugin_loaded, self);
+ wp_core_load_component(priv->core, "libwireplumber-module-mixer-api", "module", NULL,
+ "mixer-api", NULL, (GAsyncReadyCallback)astal_wp_wp_plugin_loaded, self);
+}
+
+static void astal_wp_wp_class_init(AstalWpWpClass *class) {
+ GObjectClass *object_class = G_OBJECT_CLASS(class);
+ object_class->finalize = astal_wp_wp_finalize;
+ object_class->dispose = astal_wp_wp_dispose;
+ object_class->get_property = astal_wp_wp_get_property;
+ object_class->set_property = astal_wp_wp_set_property;
+
+ astal_wp_wp_properties[ASTAL_WP_WP_PROP_AUDIO] =
+ g_param_spec_object("audio", "audio", "audio", ASTAL_WP_TYPE_AUDIO, G_PARAM_READABLE);
+ astal_wp_wp_properties[ASTAL_WP_WP_PROP_VIDEO] =
+ g_param_spec_object("video", "video", "video", ASTAL_WP_TYPE_VIDEO, G_PARAM_READABLE);
+ /**
+ * AstalWpWp:scale: (type AstalWpScale)
+ *
+ * The scale used for the volume
+ */
+ astal_wp_wp_properties[ASTAL_WP_WP_PROP_SCALE] =
+ g_param_spec_enum("scale", "scale", "scale", ASTAL_WP_TYPE_SCALE, ASTAL_WP_SCALE_CUBIC,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+
+ /**
+ * AstalWpWp:endpoints: (type GList(AstalWpEndpoint)) (transfer container)
+ *
+ * A list of AstalWpEndpoint objects
+ */
+ astal_wp_wp_properties[ASTAL_WP_WP_PROP_ENDPOINTS] =
+ g_param_spec_pointer("endpoints", "endpoints", "endpoints", G_PARAM_READABLE);
+ /**
+ * AstalWpWp:devices: (type GList(AstalWpDevice)) (transfer container)
+ *
+ * A list of AstalWpDevice objects
+ */
+ astal_wp_wp_properties[ASTAL_WP_WP_PROP_DEVICES] =
+ g_param_spec_pointer("devices", "devices", "devices", G_PARAM_READABLE);
+ /**
+ * AstalWpWp:default-speaker:
+ *
+ * The AstalWndpoint object representing the default speaker
+ */
+ astal_wp_wp_properties[ASTAL_WP_WP_PROP_DEFAULT_SPEAKER] =
+ g_param_spec_object("default-speaker", "default-speaker", "default-speaker",
+ ASTAL_WP_TYPE_ENDPOINT, G_PARAM_READABLE);
+ /**
+ * AstalWpWp:default-microphone:
+ *
+ * The AstalWndpoint object representing the default speaker
+ */
+ astal_wp_wp_properties[ASTAL_WP_WP_PROP_DEFAULT_MICROPHONE] =
+ g_param_spec_object("default-microphone", "default-microphone", "default-microphone",
+ ASTAL_WP_TYPE_ENDPOINT, G_PARAM_READABLE);
+
+ g_object_class_install_properties(object_class, ASTAL_WP_WP_N_PROPERTIES,
+ astal_wp_wp_properties);
+
+ astal_wp_wp_signals[ASTAL_WP_WP_SIGNAL_ENDPOINT_ADDED] =
+ g_signal_new("endpoint-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_wp_signals[ASTAL_WP_WP_SIGNAL_ENDPOINT_REMOVED] =
+ g_signal_new("endpoint-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL,
+ NULL, NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_ENDPOINT);
+ astal_wp_wp_signals[ASTAL_WP_WP_SIGNAL_DEVICE_ADDED] =
+ g_signal_new("device-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_DEVICE);
+ astal_wp_wp_signals[ASTAL_WP_WP_SIGNAL_DEVICE_REMOVED] =
+ g_signal_new("device-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE, 1, ASTAL_WP_TYPE_DEVICE);
+}