Commit Graph

2051 Commits

Author SHA1 Message Date
nanahi 1d82932cce various: use fopen wrapper for cloexec handling 2026-06-04 04:58:16 +02:00
Kacper Michajłow f5d4d9b029 swresample: pass input layout in mpv's order via custom channel order
Drop the swr_set_channel_mapping() + transpose_order() + reorder_in[]
plumbing. Instead, build the swr input channel layout directly from the
mpv chmap as AV_CHANNEL_ORDER_CUSTOM, so the labels in the layout already
match the positions of the channels in the input data.

For all unknown map, we return all UNSPEC, so the swr expands to default
layout for this channel number.
2026-06-01 16:53:48 +02:00
llyyr 9e06c3248a ao_pipewire: avoid passing NULL to mp_msg 2026-05-22 17:51:57 +00:00
llyyr 1a78f9fa8e ao_pipewire: avoid deadlock when starting thread loop
loop_start starts a thread which immediately acquires the thread loop
lock. Locking the loop before loop_start can therefore deadlock the
newly created thread during initialization.

Locking the thread loop before loop_start was always incorrect, but
Pipewire commit fb49e0795c28* made the issue visible by switching
pw_thread_loop_lock to the underlying SPA loop lock.

To fix this, we just avoid starting the loop until after we're connected
to the server.

* https://github.com/PipeWire/pipewire/commit/fb49e0795c28c892116b03369785ba86c27c968d
2026-05-22 17:51:57 +00:00
llyyr d8be86067c ao_pulse: fix subscribe_cb using wrong bitmask for event type
PA_SUBSCRIPTION_MASK_SINK is a pa_subscription_mask constant used when
registering with pa_context_subscribe(), not a
pa_subscription_event_type mask. Masking the event type with it would
never match PA_SUBSCRIPTION_EVENT_NEW or PA_SUBSCRIPTION_EVENT_REMOVE,
causing hotplug events to be silently dropped.

Fixes: e01750020d
2026-05-03 06:44:37 +02:00
Richasy 986dd6387d ao_wasapi: fix retry budget on DEVICE_INVALIDATED
The retry path in wasapi_thread_init() used MP_TIME_US_TO_NS, giving a
total budget of ~15 us before MP_FATAL killed the audio thread. The
resulting log line "Retrying in 1000 ns" makes the unit confusion
obvious.

In practice AUDCLNT_E_DEVICE_INVALIDATED is most often hit right after
the system resumes from sleep, or when the default endpoint changes,
where the audio endpoint typically needs hundreds of milliseconds to
come back. The current budget never covers that window, so the first
playback after wake-up permanently fell back to "no audio" until the
user manually restarted playback.

Switch the retry schedule to milliseconds: start at 1 ms (~one Windows
timer tick, effectively an immediate yield), multiply by 10 each
iteration, and cap at 1 s -- i.e. 1/10/100/1000 ms, 4 retries, ~1.1 s
total. Use MP_TIME_NS_TO_MS for the warning so the unit in the log
matches reality.
2026-05-01 05:01:00 +02:00
Kacper Michajłow e757931859 af_scaletempo: limit options to resonable range
This fixes multiple overflows when passing huge values. Which causes
either invalid memory accesses when memory allocations are wrong size or
huge allocations leading to OOM.

Reported by: Trail of Bits
2026-03-23 23:34:20 +01:00
Rudi Heitbaum 8ace278cbe various: fix Wdiscarded-qualifiers warnings
Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-03-15 14:49:00 +01:00
Simonas Kazlauskas 1af136bceb ao_pipewire: remove the node.always-process attribute
With `node.always-process` mpv will force pipewire to continuously keep
driving the source node, even when paused, which causes a relatively
significant increase in power consumption due to frequent CPU wakeups.

I have tested mpv with this option disabled, both for music and video,
pausing and seeking around in various ways and could not notice any
problems with this option disabled. And with it disabled pipewire
properly becomes idle a couple seconds after video/audio is paused.

Pipewire documentation suggests that this option is largely useful for
JACK clients, which `mpv` isn't. Using GitHub-wide search it seems like
the other two notable uses of this property are really just SDL and
OpenAL. All other applications I use work well without this property
being set as well.

Note that this change does not affect the output devices differently as
far as I can tell. Both with and without `always-process` pipewire will
suspend the output device after some idle time and in case
`always-process` is enabled, it will redirect `mpv` to `Dummy-Driver`
instead.
2026-01-17 04:55:01 +00:00
llyyr f7be2ee3e9 ao_aaudio: set content type if --audio-set-media-role is enabled 2025-12-13 15:18:12 +01:00
llyyr e99daecbdb ao_audiotrack: set content type if --audio-set-media-role is enabled 2025-12-13 14:46:55 +01:00
llyyr d07e4c7935 ao_pulse: set media.role if --audio-set-media-role enabled 2025-12-13 14:46:55 +01:00
llyyr 1a802b1810 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:
b7325b2f64

See also: https://gitlab.freedesktop.org/pipewire/wireplumber/-/issues/489
2025-12-13 14:46:55 +01:00
Jun Bo Bi 57d9d4eb42 ao/aaudio: implement aaudio backend for android 2025-11-25 20:29:42 +01:00
Jun Bo Bi 24000e3b3f meson: added option to disable audiotrack 2025-11-25 20:29:42 +01:00
llyyr b2156c7d30 ao_wasapi_utils,command,hwdec_vulkan: remove double semicolons
Cosmetic
2025-11-14 20:44:46 +00:00
Kacper Michajłow a21e47c45d ao_pipewire: fix mapping of wide channels 2025-11-14 21:41:15 +01:00
Thomas Lange 7815181b19 ao_pipewire: fix copy paste error in channel mapping 2025-11-13 18:57:22 +01:00
nanahi 8ac52fd1ab various: use mp_sleep_ns 2025-10-27 20:00:59 +01:00
Dudemanguy 29307c26ba Reapply "various: expand paths for all file/directory related options"
This reverts commit 43fda5442f.
2025-08-08 01:07:00 +00:00
Louis Pate 86e12929aa various: fix Wpedantic warnings 2025-08-01 11:56:38 +02:00
Dudemanguy 43fda5442f Revert "various: expand paths for all file/directory related options"
Since the option system now handles all the path expansion
automatically, these recent changes can be reverted for simplicity.

This reverts commit be15be3a83.
2025-07-22 17:52:41 +00:00
Dudemanguy 1fbf1e1d91 encode: simplify all initial blocking logic for encoding
0ab3184526 introduced most of the stuff
being removed here. The idea is that when doing encoding the core should
wait until everything is initialized. This is true, but the old
implementation is overly complicated and confusing. What we need is for
both the AO to be initialized and the VO to be reconfigured for encoding
to start. Because of the way initialization works, the VO reconfig
always happens first. Changing the order in playloop would of course
break this assumption, but we can trust that nobody would arbitrarily do
that. So all that needs to be done here is that write_video should wait
until the AO is up before pushing frames. And that only applies in
encoding mode and if there is a selected audio stream in the first
place. This is a simple check.

With that in place, all of this extra junk can be dropped. We don't need
special booleans or events for the simple task of making sure the AO and
VO are both up.
2025-07-14 22:09:49 +00:00
Roman Bochagov 59d5f774a4 ao_avfoundation: fix memory leak
Fix memory leak in ao_avfoundation caused by audio device switching.

Fixes #16283
2025-06-09 19:31:48 +02:00
nanahi b47c805fa2 various: remove redundant return
void return type functions don't need a final return statement.
2025-04-27 00:10:31 +02:00
Dudemanguy d9dadf07ae Revert "ao: correctly set state.playing for non-gapless audio after eof"
There's no good explanation, but I can no longer reproduce the issue
described in the commit. The code as is can cause a "File descriptor in
bad state" message when looping or advancing in a playlist because it
jumps a bit too early to the eof part. Perhaps something in alsa somehow
changed, but the non-gapless audio freezing thing doesn't happen
anymore. The audio state correctly updates on play/pause without these
lines. Since this is known to cause problems elsewhere, just revert it
for now. If the alsa problem crops up again in the future, we can
revisit it then.

This reverts commit d33e54250e.
2025-03-13 12:21:38 +01:00
Kacper Michajłow 1c49cfdb97 various: use mp_assert macro 2025-03-04 20:07:29 +01:00
llyyr c9970b5ba6 ao_pipewire: don't load client-rt.conf properties
Deprecated in https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/24bcacc6195ffbf8e40c9ea1374eb6666252eadc

Fixes: #15914
2025-02-20 15:49:01 +00:00
Dudemanguy 838df2c252 ad_lavc: flag options with UPDATE_AD 2025-01-29 15:07:42 +00:00
Dudemanguy be15be3a83 various: expand paths for all file/directory related options
There's several path-related options that do not handle common shortcuts
(like ~/). Fix this by using mp_get_user_path where appropriate which
expands the path so users get more intuitive behavior. Fixes #15598.
2025-01-29 14:49:06 +00:00
nanahi 0903e9fbd4 various: fix range for float options
The range of these options should be capped to FLT_MAX
instead of DBL_MAX.
2025-01-24 04:25:15 +00:00
Kacper Michajłow d66047589a ao_pulse: remove unnecessary casts and use the proper print specifier 2025-01-05 22:32:40 +01:00
Tim Lodemann 31d1defb7a ao_openal: fix null pointer dereference when creating OpenAL context
When the monitor goes to sleep, the OpenAL context was not properly
handled, resulting in a null pointer dereference and a crash. This
fix ensures that the OpenAL context is created and set correctly,
avoiding crashes under these conditions.

Fixes: #15648
2025-01-05 21:22:35 +01:00
Barnabás Pőcze 55f41fd8fa ao/pulse: only print server protocol after connection
The server's protocol version is not available until a connection is
properly established. Currently the value of `PA_INVALID_INDEX` is printed
due to calling `pa_context_get_server_protocol_version()` before connecting.

Fix this by doing the call after the connection has been set up.

Fixes: f744aadb77 ("ao_pulse: dump library version etc.")
2025-01-05 21:21:52 +01:00
Kacper Michajłow 59d1dc43b9 various: fix typos 2025-01-04 15:59:49 +02:00
Kacper Michajłow efcee92d0e various: remove double new line at the end of file 2025-01-04 15:59:49 +02:00
Misaki Kasumi 06fe665b78 ao_coreaudio: set kAudioOutputUnitProperty_ChannelMap
This fixes #15584
2025-01-03 13:44:00 +01:00
Callum Moffat 748fc2b752 ao_audiounit: add --audio-exclusiv support, make non-exclusive default 2024-12-31 13:51:44 +01:00
Dudemanguy d33e54250e ao: correctly set state.playing for non-gapless audio after eof
The problem here is likely ao_alsa specific and has the same symptons as
what the previous commit fixed (audio not playing when the file changes
but the details are a bit different here and the sample rate does not
matter. When using gapless audio (the default), the core player
immediately marks the audio status as EOF after it starts draining and
allows the remaining audio buffers to play while it marches on. This
works fine. When not using gapless audio, it doesn't immediately set EOF
and instead waits for the audio to finish playing before it does
anything else. The problem is that ao_is_playing is always true so the
core waits forever thinking audio is still playing when it actually
isn't.

ao_play_data is what is in charge of setting the mp_pcm_state with it
calling out to the backend for additional help. Unfortunately, this
doesn't work for alsa because it's too dumb to signal the desired states
in this edge case so we have to help it a bit. The main thing to notice
here is that even though we can get EOF from a frame, there can still be
additional valid samples that compe after it. So we can't just
immediately quit after EOF is seen. The approach here is to simply save
if we got eof sometime in the past, wait until we get no more samples,
mark state.playing as false and then jump over to the eof code. This
will set p->playing to false as desired which allows the core code to
set EOF and finally we can go through the reset logic and actually play
audio for the next file.
2024-12-11 17:12:22 +00:00
Kacper Michajłow d673356990 common: ensure MP_HANDLE_OOM is used only on pointers
To make it clear it should be used for memory allocation and not generic
error checking.
2024-11-30 17:08:42 +02:00
Kacper Michajłow 7b114d7d54 ad_lavc: remove unnecesary variable 2024-11-30 17:08:42 +02:00
Kacper Michajłow 4b11f66eb1 various: use avcodec_get_supported_config() to resolve deprecation warn
See: https://github.com/FFmpeg/FFmpeg/commit/3305767560a6303f474fffa3afb10c500059b455
2024-11-20 20:42:33 +01:00
davince 46fe3cded0 ao_audiotrack: make audiotrack jni multi-instance and multi-thread safe
The detailed issue is here:
#15212

problem: Since The AudioTrack is not an mpv instance level but a global object, it cannot support multiple mpv instances at the same time. For example, if you create two instances and then destroy one of them, the other instance may crash.

Add jni usage count to fix this.
2024-11-06 18:54:50 +01:00
der richter 84adbd9d35 ao_coreaudio: fix CoreAudio deprecations 2024-11-05 18:34:15 +01:00
Misaki Kasumi 6fadaf66c8 osdep: remove semaphore-mac
It is only used in one place in ao_coreaudio_utils.c,
and can be replaced by condvar.
Removing it can reduce the maintenance burden.
2024-10-12 17:26:39 +02:00
Kacper Michajłow 7202406fe8 various: remove global.h inclusion where not needed 2024-10-01 12:23:44 +02:00
Misaki Kasumi c3d9243a3e ao_coreaudio: fix nan in ca_get_device_latency_ns 2024-09-28 14:15:55 +02:00
llyyr a44a726301 ao_alsa: assume device lost if we couldn't recover after 10 attempts
ALSA API reports -EPIPE even when the the device is lost, which we
currently always assume to be an XRUN. If we assumed XRUN 10 times and
didn't manage to recover, just consider the device lost and try to
reconnect. Allows ao_alsa to recover from alsa server being killed then
reinitialized. And even in the worst case, this should be better than
the status quo of mpv attempting to prepare a PCM device indefinitely
until the user restarts mpv.

This is admittedly not ideal, and I don't think the -EPIPE hack is
necessary anymore, but I can only test on my setup and removing the
'assume -EPIPE is an XRUN' hack might break some setups for whatever
mysterious reasons.
2024-09-14 14:08:30 +02:00
llyyr 44da754018 ao_alsa: don't early exit out of the loop if we have an error
This would cause us to exit out of the loop with a goto anytime we ran
into XRUN or DRAINING and preparing PCM for use failed.
2024-09-14 14:08:30 +02:00
Kacper Michajłow 24f42acd1d ad_spdif: update list of DTS_HD profiles 2024-08-01 13:27:08 +02:00