diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-02-27 01:43:16 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-02-27 01:43:16 +0100 |
commit | ae2929d4f723cef7a148c671f0c71e5cb0f87592 (patch) | |
tree | 80f9ec5d58b69c1c35afbd9a21bdff9a5b729df1 /include | |
parent | d9eb44fae0953863b49c46666380dbffaec60b6b (diff) |
Pipewire: auto change default_output/default_input connected nodes when the default devices are changed in system audio settings
Diffstat (limited to 'include')
-rw-r--r-- | include/pipewire_audio.h | 32 | ||||
-rw-r--r-- | include/sound.hpp | 2 |
2 files changed, 32 insertions, 2 deletions
diff --git a/include/pipewire_audio.h b/include/pipewire_audio.h index e2ffd49..1cf6666 100644 --- a/include/pipewire_audio.h +++ b/include/pipewire_audio.h @@ -10,6 +10,7 @@ #define GSR_PIPEWIRE_AUDIO_MAX_STREAM_NODES 128 #define GSR_PIPEWIRE_AUDIO_MAX_PORTS 256 +#define GSR_PIPEWIRE_AUDIO_MAX_LINKS 256 #define GSR_PIPEWIRE_AUDIO_MAX_REQUESTED_LINKS 32 #define GSR_PIPEWIRE_AUDIO_MAX_VIRTUAL_SINKS 32 @@ -37,14 +38,31 @@ typedef struct { char *name; } gsr_pipewire_audio_port; +typedef struct { + uint32_t id; + uint32_t output_node_id; + uint32_t input_node_id; +} gsr_pipewire_audio_link; + typedef enum { GSR_PIPEWIRE_AUDIO_LINK_INPUT_TYPE_STREAM, /* Application */ GSR_PIPEWIRE_AUDIO_LINK_INPUT_TYPE_SINK /* Combined (virtual) sink */ } gsr_pipewire_audio_link_input_type; +typedef enum { + GSR_PIPEWIRE_AUDIO_REQUESTED_TYPE_STANDARD, + GSR_PIPEWIRE_AUDIO_REQUESTED_TYPE_DEFAULT_OUTPUT, + GSR_PIPEWIRE_AUDIO_REQUESTED_TYPE_DEFAULT_INPUT +} gsr_pipewire_audio_requested_type; + typedef struct { - char **output_names; - int num_output_names; + char *name; + gsr_pipewire_audio_requested_type type; +} gsr_pipewire_audio_requested_output; + +typedef struct { + gsr_pipewire_audio_requested_output *outputs; + int num_outputs; char *input_name; bool inverted; gsr_pipewire_audio_node_type output_type; @@ -60,12 +78,20 @@ typedef struct { struct spa_hook registry_listener; int server_version_sync; + struct pw_proxy *metadata_proxy; + struct spa_hook metadata_listener; + char default_output_device_name[128]; + char default_input_device_name[128]; + gsr_pipewire_audio_node stream_nodes[GSR_PIPEWIRE_AUDIO_MAX_STREAM_NODES]; int num_stream_nodes; gsr_pipewire_audio_port ports[GSR_PIPEWIRE_AUDIO_MAX_PORTS]; int num_ports; + gsr_pipewire_audio_link links[GSR_PIPEWIRE_AUDIO_MAX_LINKS]; + int num_links; + gsr_pipewire_audio_requested_link requested_links[GSR_PIPEWIRE_AUDIO_MAX_REQUESTED_LINKS]; int num_requested_links; @@ -118,6 +144,8 @@ bool gsr_pipewire_audio_add_link_from_apps_to_sink_inverted(gsr_pipewire_audio * If a device or a new device starts outputting audio after this function is called and the device name matches then it will automatically link the audio sources. |source_names| and |sink_name_input| are case-insensitive matches. + |source_names| can include "default_output" or "default_input" to use the default output/input + and it will automatically switch when the default output/input is changed in system audio settings. */ bool gsr_pipewire_audio_add_link_from_sources_to_sink(gsr_pipewire_audio *self, const char **source_names, int num_source_names, const char *sink_name_input); diff --git a/include/sound.hpp b/include/sound.hpp index 95bd6f2..87e2e2d 100644 --- a/include/sound.hpp +++ b/include/sound.hpp @@ -62,6 +62,8 @@ typedef enum { /* Get a sound device by name, returning the device into the |device| parameter. |device_name| can be a device name or "default_output" or "default_input". + If the device name is "default_output" or "default_input" then it will automatically switch which + device is records from when the default output/input is changed in the system audio settings. Returns 0 on success, or a negative value on failure. */ int sound_device_get_by_name(SoundDevice *device, const char *device_name, const char *description, unsigned int num_channels, unsigned int period_frame_size, AudioFormat audio_format); |