mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-02-04 04:06:29 -05:00
pipewire-pulse: Expose bluetooth headset autoswitch config as a message
Makes it easier for libpulse-based clients to modify this setting if they want.
This commit is contained in:
parent
703380d62d
commit
ed59342d28
4 changed files with 69 additions and 8 deletions
|
|
@ -63,8 +63,11 @@ struct client {
|
|||
struct pw_manager_object *metadata_schema_sm_settings;
|
||||
bool have_force_mono_audio;
|
||||
bool default_force_mono_audio;
|
||||
bool have_bluetooth_headset_autoswitch;
|
||||
bool default_bluetooth_headset_autoswitch;
|
||||
struct pw_manager_object *metadata_sm_settings;
|
||||
bool force_mono_audio;
|
||||
bool bluetooth_headset_autoswitch;
|
||||
|
||||
uint32_t connect_tag;
|
||||
|
||||
|
|
|
|||
|
|
@ -324,5 +324,6 @@ static inline uint32_t port_type_value(const char *port_type)
|
|||
#define METADATA_TARGET_NODE "target.node"
|
||||
#define METADATA_TARGET_OBJECT "target.object"
|
||||
#define METADATA_FEATURES_AUDIO_MONO "node.features.audio.mono"
|
||||
#define METADATA_BLUETOOTH_HEADSET_AUTOSWITCH "bluetooth.autoswitch-to-headset-profile"
|
||||
|
||||
#endif /* PULSE_SERVER_DEFS_H */
|
||||
|
|
|
|||
|
|
@ -133,6 +133,48 @@ static int core_object_force_mono_output(struct client *client, const char *para
|
|||
}
|
||||
}
|
||||
|
||||
static int core_object_bluetooth_headset_autoswitch(struct client *client, const char *params, FILE *response)
|
||||
{
|
||||
if (!client->have_bluetooth_headset_autoswitch) {
|
||||
/* Not supported, return a null value to indicate that */
|
||||
fprintf(response, "null");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!params || params[0] == '\0') {
|
||||
/* No parameter => query the current value */
|
||||
fprintf(response, "%s", client->bluetooth_headset_autoswitch ? "true" : "false");
|
||||
return 0;
|
||||
} else {
|
||||
/* The caller is trying to set a value or clear with a null */
|
||||
int ret;
|
||||
|
||||
if (spa_streq(params, "true")) {
|
||||
ret = pw_manager_set_metadata(client->manager, client->metadata_sm_settings, PW_ID_CORE,
|
||||
METADATA_BLUETOOTH_HEADSET_AUTOSWITCH, "Spa:String:JSON", "true");
|
||||
client->bluetooth_headset_autoswitch = true;
|
||||
} else if (spa_streq(params, "false")) {
|
||||
ret = pw_manager_set_metadata(client->manager, client->metadata_sm_settings, PW_ID_CORE,
|
||||
METADATA_BLUETOOTH_HEADSET_AUTOSWITCH, "Spa:String:JSON", "false");
|
||||
client->bluetooth_headset_autoswitch = false;
|
||||
} else if (spa_streq(params, "null")) {
|
||||
ret = pw_manager_set_metadata(client->manager, client->metadata_sm_settings, PW_ID_CORE,
|
||||
METADATA_BLUETOOTH_HEADSET_AUTOSWITCH, NULL, NULL);
|
||||
client->bluetooth_headset_autoswitch = client->default_bluetooth_headset_autoswitch;
|
||||
} else {
|
||||
fprintf(response, "Value must be true, false, or clear");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
fprintf(response, "Could not set metadata: %s", spa_strerror(ret));
|
||||
else
|
||||
fprintf(response, "%s", params);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
static int core_object_message_handler(struct client *client, struct pw_manager_object *o, const char *message, const char *params, FILE *response)
|
||||
{
|
||||
pw_log_debug(": core %p object message:'%s' params:'%s'", o, message, params);
|
||||
|
|
@ -141,14 +183,15 @@ static int core_object_message_handler(struct client *client, struct pw_manager_
|
|||
fprintf(response,
|
||||
"/core <command> [<params>]\n"
|
||||
"available commands:\n"
|
||||
" help this help\n"
|
||||
" list-handlers show available object handlers\n"
|
||||
" pipewire-pulse:malloc-info show malloc_info\n"
|
||||
" pipewire-pulse:malloc-trim run malloc_trim\n"
|
||||
" pipewire-pulse:log-level update log level with <params>\n"
|
||||
" pipewire-pulse:list-modules list all module names\n"
|
||||
" pipewire-pulse:describe-module describe module info for <params>\n"
|
||||
" pipewire-pulse:force-mono-output force mono mixdown on all hardware outputs"
|
||||
" help this help\n"
|
||||
" list-handlers show available object handlers\n"
|
||||
" pipewire-pulse:malloc-info show malloc_info\n"
|
||||
" pipewire-pulse:malloc-trim run malloc_trim\n"
|
||||
" pipewire-pulse:log-level update log level with <params>\n"
|
||||
" pipewire-pulse:list-modules list all module names\n"
|
||||
" pipewire-pulse:describe-module describe module info for <params>\n"
|
||||
" pipewire-pulse:force-mono-output force mono mixdown on all hardware outputs\n"
|
||||
" pipewire-pulse:bluetooth-headset-autoswitch use bluetooth headset mic if available"
|
||||
);
|
||||
} else if (spa_streq(message, "list-handlers")) {
|
||||
bool first = true;
|
||||
|
|
@ -211,6 +254,8 @@ static int core_object_message_handler(struct client *client, struct pw_manager_
|
|||
}
|
||||
} else if (spa_streq(message, "pipewire-pulse:force-mono-output")) {
|
||||
return core_object_force_mono_output(client, params, response);
|
||||
} else if (spa_streq(message, "pipewire-pulse:bluetooth-headset-autoswitch")) {
|
||||
return core_object_bluetooth_headset_autoswitch(client, params, response);
|
||||
} else {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -984,10 +984,22 @@ static void manager_metadata(void *data, struct pw_manager_object *o,
|
|||
else
|
||||
client->default_force_mono_audio = spa_streq(default_, "true");
|
||||
}
|
||||
|
||||
if (spa_streq(key, METADATA_BLUETOOTH_HEADSET_AUTOSWITCH)) {
|
||||
client->have_bluetooth_headset_autoswitch = true;
|
||||
|
||||
if (spa_json_str_object_find(value, strlen(value),
|
||||
"default", default_, sizeof(default_)) < 0)
|
||||
client->default_bluetooth_headset_autoswitch = false;
|
||||
else
|
||||
client->default_bluetooth_headset_autoswitch = spa_streq(default_, "true");
|
||||
}
|
||||
}
|
||||
if (subject == PW_ID_CORE && o == client->metadata_sm_settings) {
|
||||
if (spa_streq(key, METADATA_FEATURES_AUDIO_MONO))
|
||||
client->force_mono_audio = spa_streq(value, "true");
|
||||
if (spa_streq(key, METADATA_BLUETOOTH_HEADSET_AUTOSWITCH))
|
||||
client->bluetooth_headset_autoswitch = spa_streq(value, "true");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue