Commit Graph

1789 Commits

Author SHA1 Message Date
Dudemanguy 8ddc0e8888 audio: fix crash during uninit on ao_lavc
The buffer state can be null when using --ao=lavc, so just check it
first. Fixes #10175.
2023-01-24 16:39:33 +01:00
Li Chang ec2a9d4332 ao_coreaudio: use AudioUnitReset as ao_driver.reset to prevent long restart
[motivation]
Seeking on MacOS appears to be lagged when users connect
to wireless audio output (airpods for example).

This commit attempts to fix mpv-player/mpv#10270

[observation]
1. When using other media player (VLC to be exact) simultaneously,
the lagging on seek disappear. We could guess that the AudioDevice
is on some sort of "warm-up" state.

See mpv-player/mpv#9243 for detailed description.

2. `AudioOutputUnitStart` takes significant longer time after each seek
or pause/play when using wireless output devices compares to wired devices.

[rationale]
After investigate codes in ao_coreaudio.c, it appears that the the `stop`
function was used as `ao_driver.reset` function. Therefore every seek
and pause would call `AudioOutputUnitStop`.

It turns out that `ao_driver.reset` function is used in `ao_reset`.
And `ao_reset` function is used to clean up the state of current `ao`
so I think `AudioUnitReset` is more proper than `AudioOutputUnitStop`
under this semantics.

Since ao_coreaudio use pull base mechanism, audio playback behaviors
upon pause/seek could be handled by callback function
(streaming silence when paused) so there is no need to stop AudioUnit when resetting.
Therefore using `AudioUnitReset` as `ao_driver.reset` looks proper.

Additionally, after using proper reset, the AudioUnit that represents
hardware I/O devices doesn't need to be restart everytime seek/pause actions happen.
Restarting wireless devices simply takes longer in MacOS which is
the root cause of lagging observed by users when they seek or pause/play media.

[method]
Use `AudioUnitReset` for ao_driver.reset.
2023-01-24 15:56:56 +01:00
Thomas Weißschuh 7753a73a17 ao_pipewire: clean up when hotplug_init fails 2023-01-24 15:56:56 +01:00
Thomas Weißschuh dadcb2e614 ao_pipewire: destroy context on connection failure 2023-01-24 15:56:56 +01:00
Thomas Weißschuh f8b7170871 ao_pipewire: free properties on failure 2023-01-24 15:56:56 +01:00
rcombs 71346393e2 ao_coreaudio: use device's nominal sample rate for latency properties
Fixes sync issues when using high-latency devices at non-native sample rates

Closes #10984
2023-01-24 15:56:56 +01:00
Thomas Weißschuh 495206dd41 ao_pipewire: log sample queueing
This allows us to more easily see the datapath from mpv to pipewire.

We know how often the callbacks are triggered, how big the buffers are
and how much data mpv provides to pipewire.
2023-01-24 15:56:56 +01:00
Thomas Weißschuh af1e00b2ce ao_pipewire: log version information and metadata 2023-01-24 15:56:56 +01:00
Thomas Weißschuh 2e5d0d6e07 ao_pipewire: reload ao on stream disconnect
This allows the core of mpv to know about issues in the AO.
Otherwise playback will just freeze as no more data callbacks are sent
by PipeWire.
Also it allows mpv to try to reconnect the AO or find another, working
AO.
2022-11-07 10:36:40 -08:00
Thomas Weißschuh b7cf35c9a4 ao_pipewire: explicitly remove stream hook
We want to add more logic to the stream event handler.
This logic should not be triggered during normal stream shutdown, so we
remove the listener beforehand.
2022-11-07 10:36:40 -08:00
Thomas Weißschuh bf7ade420d ao_pipewire: log generic stream errors 2022-11-07 10:36:40 -08:00
Aman Karmani 9f0381c51b Revert "ao/audiounit: include AVAudioSession buffer in latency calc"
This reverts commit 8b114e574a.
2022-11-07 18:45:55 +02:00
rcombs 89bd6ead6c ao_coreaudio: specify UTF-8 as text encoding for CFString conversions
This matches our internal expectations, as well as fixes handling
of non-ASCII device descriptions.
2022-10-29 00:00:09 +03:00
Thomas Weißschuh c9af75e888 ao_pipewire: compatibility for libpipewire 0.3.19 2022-10-26 21:56:33 +03:00
Thomas Weißschuh c3be7e2585 ao: promote ao_pipewire
The AO is feature-complete now.
As PipeWire also provides compatibility with PulseAudio, ALSA and Jack
we should put it before those for the autodetection to work.
2022-10-24 11:09:34 -07:00
Thomas Weißschuh b9a9e0a6f1 ao_pipewire: test for session to contain audio sinks
The pure presence of PipeWire does not mean that it is actually driving
the audio session. For example it could only be meant for video.

Currently there is no proper API to detect this (see [0]), so we check
for the presence of audio sinks.

As soon as a proper API exists, we should use that.

[0] https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1835
2022-10-24 11:09:34 -07:00
Thomas Weißschuh e4505ce744 ao_pipewire: init_boilerplate(): simplify errorhandling 2022-10-24 11:09:34 -07:00
Cœur 67260f8aac audio/format: fix Type 'struct entry' has incompatible definitions in different translation units
`struct entry` already exists from <search.h>, so the one we declare in audio/format.c needs to be named differently
2022-10-23 14:57:24 +02:00
Thomas Weißschuh 161bdd9359 ao_pipewire: allow specification of remote name 2022-10-06 13:16:35 -07:00
Thomas Weißschuh a1e29f1555 ao_pipewire: small cleanups and restructring
* Remove unneeded braces.
* Don't use non-standard %m in printf.
* Organize struct priv a bit.
2022-10-06 13:16:35 -07:00
Thomas Weißschuh b2aaf7250f ao_pipewire: don't try to lock nonexistent loop 2022-09-28 15:53:33 -07:00
Thomas Weißschuh 5e49c09f2e ao_pipewire: use target.object
Specifying the id of the target node during stream connect is
deprecated.  Instead the property target.object should be used to link
by target serial or name.  Using the name allows us to drop a bunch of
custom code.
2022-09-28 15:53:05 -07:00
Peter DeLong f46bbde5e6 af_scaletempo2: fix crash when the number of channels increases
When af_scaletempo2.c:process() detects a format change, it goes back
through mp_scaletempo2_init() to reinitialize everything.  However,
mp_scaletempo2.input_buffer is not necessarily reallocated due to a
check in af_scaletempo2_internals.c:resize_input_buffer().  This is a
problem if the number of audio channels increases, since without
reallocating, the buffer for the new channel(s) will at best point to
NULL, and at worst uninitialized memory.

Since resize_input_buffer() is only called from two places, pull size
check out into mp_scaletempo2_fill_input_buffer().  This allows each
caller to decide whether they want to resize or not.  We could be
smarter about when to reallocate, but that would add a lot of machinery
for a case I don't expect to be hit often in practice.
2022-09-23 18:15:00 +02:00
rcombs ba81e4ed88 ao_audiounit: get the channel layout from the AU itself
Fixes 5.1/7.1 output mapping on tvOS 16,
and also makes the AC3-layout hack unnecessary.

Also adds some diagnostic log messages.
2022-09-15 11:52:50 -05:00
Thomas Weißschuh 38a7562ebe ao_pipewire: listen to hotplug events 2022-09-11 20:24:42 -07:00
Thomas Weißschuh f36eeaf4e8 ao_pipewire: use proper hotplug init APIs 2022-09-11 20:24:42 -07:00
Thomas Weißschuh aa7223cd8c ao_pipewire: create is_sink_node helper 2022-09-11 20:24:42 -07:00
Thomas Weißschuh 235a66bfc8 audio: list devices for all AOs with hotplug_init
Previously we would only call list_devs() on available AOs if an AO
*did not* have a hotplug_init() callback or for the first one that *did*
have it.

This is problematic when multiple fully functional hotplug-capable AOs
are available.

The second one would not be able to contribute discovered devices.

This problem prevents ao_pipewire from introducing full hotplug support
with hotplug_init().
2022-09-11 20:24:42 -07:00
Thomas Weißschuh 013ec877f6 audio: try to use playback AO as hotplug AO first
When a platform has multiple valid AOs that can provide hotplug events
we should try to use the one that also provides playback.

Concretely this will help when introducing hotplug support for
ao_pipewire.

Currently ao_pulse is probed by ao_hotplug_get_device_list() before
ao_pipewire and on the common setups where both AOs could work pulse
will be selected for hotplug handling.
This means that hotplug_init() of ao_pipewire will never be called and
list_devs() has to do its own initialization.
But if ao_pulse is non-functional or not compiled-in suddenly
ao_pipewire *must* implement hotplug_init() for hotplugging events to
work for all.

Also if the hotplug ao_pulse connects to a PulseAudio instance that is
not emulated by the same PipeWire instance as the playback ao_pipewire
the hotplug events are useless.
2022-09-11 20:24:42 -07:00
Thomas Weißschuh 535cd6f313 ao_pipewire: handle AOCONTROL_UPDATE_MEDIA_ROLE 2022-09-10 12:32:52 -07:00
Thomas Weißschuh 3167a77aa3 audio: add AOCONTROL_UPDATE_MEDIA_ROLE
This is used to notify an AO about the type of media that is being
played.
Either a movie or music.
2022-09-10 12:32:52 -07:00
Thomas Weißschuh 221bf540a1 ao_pipewire: fix indent 2022-09-10 12:32:52 -07:00
Niklas Haas 9be52e5dd8 ad_lavc: strip non-normalized floats
`opus` codec likes returning denormalized floats in some cases, causing
wacky issues.

Fixes #10290
2022-09-02 01:27:31 +02:00
Thomas Weißschuh 211ce69f74 ao_pipewire: for_each_sink(): report errors 2022-08-28 10:46:54 -07:00
Philip Langdale ed7717298b audio: fix lack of reinitialization on format change with pull AOs
uau did some investigation and noticed that we do not send a wakeup
event when we encounter end-of-stream in ao_read_data(), in contrast to
the equivalent logic for push AOs in ao_play_data().

Inserting that wakeup fixes the original problem of lack of
reinitialization on a format change without the problems we saw with
the previous attempted fix.

Fixes #10566
2022-08-23 11:01:52 -07:00
Thomas Weißschuh 6c1f01d284 ao_pipewire: make sure not to exceed the available buffer
The error description in #10545 could indicate that we are overflowing
we are corrupting the buffer metadata ourselves through out-of-bound
writes.
This check is also present in pw-cat so it seems to be expected for
b->requested to exceed the actual available buffer space.

Potential fix for #10545
2022-08-21 18:38:53 +02:00
Thomas Weißschuh e735f7f61a ao_pipewire: restructure logic a bit 2022-08-17 15:48:12 -07:00
Thomas Weißschuh dbfee1be3d ao_pipewire: only try to read requested data 2022-08-17 15:48:12 -07:00
Thomas Weißschuh 0638a91ff4 ao_pipewire: report all available info about chunk
This allows the audio server better to make sense of the data instead of
having to use heuristics.
2022-08-17 15:48:12 -07:00
Thomas Weißschuh c9ecaedc44 ao_pipewire: tell audio server about number of queued samples 2022-08-09 09:24:55 -07:00
Thomas Weißschuh 9add44b11a ao_pipewire: use mpv logging 2022-08-04 09:25:19 -07:00
Christoph Heinrich 490e263529 af_rubberband: add new engine option in rubberband 3.0.0 2022-08-03 15:29:02 +00:00
Thomas Weißschuh 0044c19f0d ao_pipewire: prevent deprecation warning for pw_stream_get_time() 2022-07-08 17:19:23 -07:00
Wim Taymans c7b17beaf1 ao_pipewire: pipewire uses linear volume
Don't use cube root volumes, pipewire uses linear volumes.
2022-07-08 07:45:09 -07:00
Wim Taymans c01bb44e36 ao_pipewire: don't access core after disconnect
pw_core_disconnect frees the core, so accessing it afterward to
destroy the context is not allowed.

Instead, just destroy the context, the first thing it does is disconnect
all cores for us.
2022-07-08 07:45:09 -07:00
Wim Taymans 60ed51008d ao_pipewire: zero listeners
The listeners need to be cleared because removing them might invoke the
removed handler, which could otherwise point to invalid memory.
2022-07-08 07:45:09 -07:00
Alex B d38ff1c958 ao_pipewire: support ao-volume on non-stereo channel layouts
mpv only remembers volume for two channels.
Always apply the same volume to all channels in case of
non-stereo layout similarly to ao_pulse.
Don't try to do anything smart when averaging volumes,
normally they are equal anyway.
2022-07-08 06:39:23 -07:00
Jan Ekström 8123adadbd audio/chmap: add mp_iterate_builtin_layouts
Mostly useful for unit tests in order to access the channel
layouts from chmap which have mapped channels.
2022-06-15 21:19:10 +03:00
Jan Ekström edfd17ab18 ad_lavc: switch to AVChannelLayout when available 2022-06-15 21:19:10 +03:00
Jan Ekström e7483ced5d af_lavcac3enc: switch to AVChannelLayout when available 2022-06-14 22:41:20 +03:00