Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/audio-set-media-role.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add --audio-set-media-role, disabled by default. This effectively changes the behavior for ao_pipewire
8 changes: 8 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,14 @@ Audio
if you want to force a different audio profile (e.g. with PulseAudio),
or to set your own application name when using libmpv.

``--audio-set-media-role=<yes|no>``
If enabled, mpv will set the appropriate media role on supported audio
servers to indicate whether mpv is playing a video or an audio-only file.
This is disabled by default since per media role volumes have often caused
unexpected and confusing behavior.

Default: no.

``--audio-buffer=<seconds>``
Set the audio output minimum buffer. The audio device might actually create
a larger buffer if it pleases. If the device creates a smaller buffer,
Expand Down
3 changes: 3 additions & 0 deletions audio/out/ao.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ const struct m_sub_options ao_conf = {
{"audio-client-name", OPT_STRING(audio_client_name), .flags = UPDATE_AUDIO},
{"audio-buffer", OPT_DOUBLE(audio_buffer),
.flags = UPDATE_AUDIO, M_RANGE(0, 10)},
{"audio-set-media-role", OPT_BOOL(audio_set_media_role),
.flags = UPDATE_AUDIO},
{0}
},
.size = sizeof(OPT_BASE_STRUCT),
Expand Down Expand Up @@ -180,6 +182,7 @@ static struct ao *ao_alloc(bool probing, struct mpv_global *global,
.log = mp_log_new(ao, log, name),
.def_buffer = opts->audio_buffer,
.client_name = talloc_strdup(ao, opts->audio_client_name),
.set_media_role = opts->audio_set_media_role
};
talloc_free(opts);
ao->priv = m_config_group_from_desc(ao, ao->log, global, &desc, name);
Expand Down
1 change: 1 addition & 0 deletions audio/out/ao.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct ao_opts {
char *audio_device;
char *audio_client_name;
double audio_buffer;
bool audio_set_media_role;
};

struct ao *ao_init_best(struct mpv_global *global,
Expand Down
10 changes: 6 additions & 4 deletions audio/out/ao_audiotrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,12 @@ static int AudioTrack_New(struct ao *ao)
MP_JNI_EXCEPTION_LOG(ao);
tmp = MP_JNI_CALL_OBJECT(attr_builder, AudioAttributesBuilder.setUsage, AudioAttributes.USAGE_MEDIA);
MP_JNI_LOCAL_FREEP(&tmp);
jint content_type = (ao->init_flags & AO_INIT_MEDIA_ROLE_MUSIC) ?
AudioAttributes.CONTENT_TYPE_MUSIC : AudioAttributes.CONTENT_TYPE_MOVIE;
tmp = MP_JNI_CALL_OBJECT(attr_builder, AudioAttributesBuilder.setContentType, content_type);
MP_JNI_LOCAL_FREEP(&tmp);
if (ao->set_media_role) {
jint content_type = (ao->init_flags & AO_INIT_MEDIA_ROLE_MUSIC) ?
AudioAttributes.CONTENT_TYPE_MUSIC : AudioAttributes.CONTENT_TYPE_MOVIE;
tmp = MP_JNI_CALL_OBJECT(attr_builder, AudioAttributesBuilder.setContentType, content_type);
MP_JNI_LOCAL_FREEP(&tmp);
}
jobject attr = MP_JNI_CALL_OBJECT(attr_builder, AudioAttributesBuilder.build);
MP_JNI_LOCAL_FREEP(&attr_builder);

Expand Down
5 changes: 4 additions & 1 deletion audio/out/ao_pipewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ static int init(struct ao *ao)
struct pw_properties *props = pw_properties_new(
PW_KEY_MEDIA_TYPE, "Audio",
PW_KEY_MEDIA_CATEGORY, "Playback",
PW_KEY_MEDIA_ROLE, ao->init_flags & AO_INIT_MEDIA_ROLE_MUSIC ? "Music" : "Movie",
PW_KEY_NODE_NAME, ao->client_name,
PW_KEY_NODE_DESCRIPTION, ao->client_name,
PW_KEY_APP_NAME, ao->client_name,
Expand All @@ -588,6 +587,10 @@ static int init(struct ao *ao)
NULL
);

if (ao->set_media_role)
pw_properties_set(props, PW_KEY_MEDIA_ROLE,
ao->init_flags & AO_INIT_MEDIA_ROLE_MUSIC ? "Music" : "Movie");

if (pipewire_init_boilerplate(ao) < 0)
goto error_props;

Expand Down
5 changes: 5 additions & 0 deletions audio/out/ao_pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ static int init(struct ao *ao)
}
(void)pa_proplist_sets(proplist, PA_PROP_MEDIA_ICON_NAME, ao->client_name);

if (ao->set_media_role)
(void)pa_proplist_sets(proplist, PA_PROP_MEDIA_ROLE,
ao->init_flags & AO_INIT_MEDIA_ROLE_MUSIC
? "music" : "video");

if (!(format = pa_format_info_new()))
goto unlock_and_fail;

Expand Down
3 changes: 3 additions & 0 deletions audio/out/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ struct ao {
// Application name to report to the audio API.
char *client_name;

// Whether mpv should set the media role to the audio server
bool set_media_role;

// Used during init: if init fails, redirect to this ao
char *redirect;

Expand Down
Loading