Skip to content

Commit a962a2b

Browse files
committed
ao_pipewire: avoid setting any media.role by default
This adds option `--audio-set-media-role` to configure whether mpv should set media roles to supported audio APIs or not. Disabled by default. By default, WirePlumber restores the volume of each application to whatever the last application with the same media role used. This is completely insane behavior, and I couldn’t find any way for a user to opt out of it on my end. The `state-stream.lua` script responsible for this mess only uses media.role if the property is present, so the only reliable workaround is simply not to set one at all. This WirePlumber behavior is inherited from PulseAudio, which also exhibits the same behavior to this day. This commit also mirrors the same change made to ao_pulse in 2015: b7325b2 See also: https://gitlab.freedesktop.org/pipewire/wireplumber/-/issues/489
1 parent 2e5e293 commit a962a2b

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add --audio-set-media-role

DOCS/man/options.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,11 @@ Audio
23872387
if you want to force a different audio profile (e.g. with PulseAudio),
23882388
or to set your own application name when using libmpv.
23892389

2390+
``--audio-set-media-role=<yes|no>``
2391+
If enabled, mpv will set the appropriate media role on supported audio
2392+
servers depending on whether mpv is playing a video with audio or an
2393+
audio only file. Default: no.
2394+
23902395
``--audio-buffer=<seconds>``
23912396
Set the audio output minimum buffer. The audio device might actually create
23922397
a larger buffer if it pleases. If the device creates a smaller buffer,

audio/out/ao.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ const struct m_sub_options ao_conf = {
145145
{"audio-client-name", OPT_STRING(audio_client_name), .flags = UPDATE_AUDIO},
146146
{"audio-buffer", OPT_DOUBLE(audio_buffer),
147147
.flags = UPDATE_AUDIO, M_RANGE(0, 10)},
148+
{"audio-set-media-role", OPT_BOOL(audio_set_media_role),
149+
.flags = UPDATE_AUDIO},
148150
{0}
149151
},
150152
.size = sizeof(OPT_BASE_STRUCT),
@@ -180,6 +182,7 @@ static struct ao *ao_alloc(bool probing, struct mpv_global *global,
180182
.log = mp_log_new(ao, log, name),
181183
.def_buffer = opts->audio_buffer,
182184
.client_name = talloc_strdup(ao, opts->audio_client_name),
185+
.set_media_role = opts->audio_set_media_role
183186
};
184187
talloc_free(opts);
185188
ao->priv = m_config_group_from_desc(ao, ao->log, global, &desc, name);

audio/out/ao.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct ao_opts {
7979
char *audio_device;
8080
char *audio_client_name;
8181
double audio_buffer;
82+
bool audio_set_media_role;
8283
};
8384

8485
struct ao *ao_init_best(struct mpv_global *global,

audio/out/ao_pipewire.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ static int init(struct ao *ao)
577577
struct pw_properties *props = pw_properties_new(
578578
PW_KEY_MEDIA_TYPE, "Audio",
579579
PW_KEY_MEDIA_CATEGORY, "Playback",
580-
PW_KEY_MEDIA_ROLE, ao->init_flags & AO_INIT_MEDIA_ROLE_MUSIC ? "Music" : "Movie",
581580
PW_KEY_NODE_NAME, ao->client_name,
582581
PW_KEY_NODE_DESCRIPTION, ao->client_name,
583582
PW_KEY_APP_NAME, ao->client_name,
@@ -588,6 +587,10 @@ static int init(struct ao *ao)
588587
NULL
589588
);
590589

590+
if (ao->set_media_role)
591+
pw_properties_set(props, PW_KEY_MEDIA_ROLE,
592+
ao->init_flags & AO_INIT_MEDIA_ROLE_MUSIC ? "Music" : "Movie");
593+
591594
if (pipewire_init_boilerplate(ao) < 0)
592595
goto error_props;
593596

audio/out/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ struct ao {
5555
// Application name to report to the audio API.
5656
char *client_name;
5757

58+
// Whether mpv should set the media role to the audio server
59+
bool set_media_role;
60+
5861
// Used during init: if init fails, redirect to this ao
5962
char *redirect;
6063

0 commit comments

Comments
 (0)