summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_pulse.c
Commit message (Collapse)AuthorAgeFilesLines
* ao_pulse: reenable latency hacks by defaultsfan54 days1-0/+1
| | | | | | | | | | | | | | As far as I can tell PulseAudio introduced a bug in 16.0 where if a stream is (un)paused too often the reported latency will momentarily spike by 3000% or more. Apparently in certain cases just pausing once and waiting can also cause this. Save the remaining users of PA the trouble of debugging the various obscure issues that can arise from this (desync is a harmless example) by enabling the latency hack code again. ref: <https://github.com/mpv-player/mpv/issues/12057> <https://github.com/mpv-player/mpv/issues/10333>
* ALL: use new mp_thread abstractionKacper Michajłow2023-11-051-1/+0
|
* Revert "ao/pulse: implement period_size"sfan52023-08-201-1/+0
| | | | | | | This is why you don't merge three year old contributions without checking that they're even applicable anymore. This reverts commit 5a94c86029a2d0e5452c07a7c12d2a6981f607df.
* ao/pulse: implement period_sizeNicolas F2023-08-201-0/+1
| | | | | | | | The idea behind period_size is that it's the minimum amount of data that your audio subsystem wants to fetch. For PulseAudio, this is given by the minreq buffer attribute, which is in bytes for all channels. Hence the divisions.
* options: transition options from OPT_FLAG to OPT_BOOLChristoph Heinrich2023-02-211-4/+4
| | | | | | c78482045444c488bb7948305d583a55d17cd236 introduced a bool option type as a replacement for the flag type, but didn't actually transition and remove the flag type because it would have been too much mundane work.
* various: drop unused #include "config.h"Thomas Weißschuh2023-02-201-1/+0
| | | | | | Most sources don't need config.h. The inclusion only leads to lots of unneeded recompilation if the configuration is changed.
* audio: simplify implementation of property ao-volumeThomas Weißschuh2023-01-251-15/+4
| | | | | | | | | | | | | | ao-volume is represented in the code with a `struct ao_control_vol_t` which contains volumes for two channels, left and right. However the code implementing this property in command.c never treats these values individually. They are always averaged together. On the other hand the code in the AOs handling these values also has to handle the case where *not* exactly two channels are handled. So let's remove the `struct ao_control_vol_t` and replace it with a simple float. This makes the semantics clear to AO authors and allows us to drop some code from the AOs and command.c.
* various: replace abort() with MP_ASSERT_UNREACHABLE() where appropriatesfan52023-01-121-2/+3
| | | | | | | | In debug mode the macro causes an assertion failure. In release mode it works differently and tells the compiler that it can assume the codepath will never execute. For this reason I was conversative in replacing it, e.g. in mpv-internal code that exhausts all valid values of an enum or when a condition is clear from directly preceding code.
* ao/pulse: fix incorrect state reported after resetsfan52021-04-291-0/+1
| | | | fixes #8768
* ao/pulse: signal the mainloop when ops are doneThomas Weißschuh2021-03-111-2/+5
| | | | | | | | Without the explicit signal the call to pa_threaded_mainloop_wait() will not return as soon as possible. Fixes 4f07607888541e6eb40fc5c3a1edfeb84aacb0f7 See #8633
* ao/pulse: wait for command completion when setting volume or muteThomas Weißschuh2021-03-091-13/+8
| | | | | | | | | | | | | | | | This makes the behavior of all control messages consistent, fixing an inconsistency that has been with us since 4d8266c739915184d3787d7ab727ac03378b341b - which is the initial rework of the polyaudio AO into the pulseaudio AO. Muting the stream also directly triggers an update to the OSD. When not waiting for the command completion this read of the mute property may read the old state. A stale read. Note that this somehow was not triggered on native Pulseaudio, but it is an issue on Pipewire. See https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/868
* ao/pulse: create the stream corkedsfan52020-08-261-1/+1
| | | | | | | | | Previously get_state() would keep setting the cork status while paused, but it only does for that after underflows now. Correct this oversight by creating the stream corked for start() to uncork it at a later time. fixes #8026
* ao/pulse: fix reporting of playing statesfan52020-07-121-2/+7
| | | | | | | When get_state() corks the stream after an underrun happens priv->playing is incorrectly reset to true, which can cause the player to miss the underrun entirely. Stop resetting priv->playing during corking (but not uncorking) to fix this.
* ao/pulse: flush stream on underrunsfan52020-07-121-1/+1
| | | | | | | | | | The underflow callback introduced in d27ad96 can be called when the buffer is still full, causing playback to never resume afterwards since get_state() reports free_samples == 0. Fix this by fully resetting on underrun, which flushes the stream and ensures free buffer space. fixes #7874
* ao/pulse: properly set device_bufferNicolas F2020-06-071-0/+8
| | | | | | | | | Previously, device_buffer defaulted to 0 on pulse. This meant that commit baa7b5c would always wait with a timeout of 0, leading to high CPU usage for PulseAudio users. By setting device_buffer to the number of samples per channel that PulseAudio sets as its target, this commit fixes this behaviour.
* audio: further simplify internal audio API somewhatwm42020-06-021-7/+12
| | | | | | | | | | | | Instead of the relatively subtle underflow handling, simply signal whether the stream is in a playing state. Should make it more robust. Should affect ao_alsa and ao_pulse only (and ao_openal, but it's broken). For ao_pulse, I'm just guessing. How the hell do you query whether a stream is playing? Who knows. Seems to work, judging from very superficial testing.
* audio: redo internal AO APIwm42020-06-011-93/+67
| | | | | | | | | | | | | | | | | | | | | | | | | This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm, ao_lavc. There are changes to the other AOs too, but that's only about renaming ao_driver.resume to ao_driver.start. ao_openal is broken because I didn't manage to fix it, so it exits with an error message. If you want it, why don't _you_ put effort into it? I see no reason to waste my own precious lifetime over this (I realize the irony). ao_alsa loses the poll() mechanism, but it was mostly broken and didn't really do what it was supposed to. There doesn't seem to be anything in the ALSA API to watch the playback status without polling (unless you want to use raw UNIX signals). No idea if ao_pulse is correct, or whether it's subtly broken now. There is no documentation, so I can't tell what is correct, without reverse engineering the whole project. I recommend using ALSA. This was supposed to be just a simple fix, but somehow it expanded scope like a train wreck. Very high chance of regressions, but probably only for the AOs listed above. The rest you can figure out from reading the diff.
* audio: remove ao_driver.drainwm42020-05-271-10/+0
| | | | | | | | | | The recent change to the common code removed all calls to ->drain. It's currently emulated via a timed sleep and polling ao_eof_reached(). That is actually fallback code for AOs which lacked draining. I could just readd the drain call, but it was a bad idea anyway. My plan to handle this better is to require the AO to signal a underrun, even if AOPLAY_FINAL_CHUNK is not set. Also reinstate not possibly waiting for ao_lavc.c. ao_pcm.c did not have anything to handle this; whatever.
* options: change option macros and all option declarationswm42020-03-181-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change all OPT_* macros such that they don't define the entire m_option initializer, and instead expand only to a part of it, which sets certain fields. This requires changing almost every option declaration, because they all use these macros. A declaration now always starts with {"name", ... followed by designated initializers only (possibly wrapped in macros). The OPT_* macros now initialize the .offset and .type fields only, sometimes also .priv and others. I think this change makes the option macros less tricky. The old code had to stuff everything into macro arguments (and attempted to allow setting arbitrary fields by letting the user pass designated initializers in the vararg parts). Some of this was made messy due to C99 and C11 not allowing 0-sized varargs with ',' removal. It's also possible that this change is pointless, other than cosmetic preferences. Not too happy about some things. For example, the OPT_CHOICE() indentation I applied looks a bit ugly. Much of this change was done with regex search&replace, but some places required manual editing. In particular, code in "obscure" areas (which I didn't include in compilation) might be broken now. In wayland_common.c the author of some option declarations confused the flags parameter with the default value (though the default value was also properly set below). I fixed this with this change.
* audio/out: rip out old unused app/softvolume reportingwm42019-10-111-3/+0
| | | | | | | | | | | This was all dead code. Commit 995c47da9a (over 3 years ago) removed all uses of the controls. It would be nice if AOs could apply a linear gain volume, that only affects the AO's audio stream for low-latency volume adjust and muting. AOCONTROL_HAS_SOFT_VOLUME was supposed to signal this, but to use it, we'd have to thoroughly check whether it really uses the expected semantics, so there's really nothing useful left in this old code.
* ao_pulse: add the newly added mappings for TrueHD/DTS-HD formatsJan Ekström2019-09-271-6/+11
| | | | | Originally DTS-HD was mapped to PA_ENCODING_DTS_IEC61937 which I'm actually not sure if it ever worked.
* ao_pulse: add --pulse-allow-suspendedTérence Clastres2019-09-211-1/+3
| | | | | | | | | | This flag makes mpv continue using the PulseAudio driver even if the sink is suspended. This can be useful if JACK is running with PulseAudio in bridge mode and the sink-input assigned to mpv is the one JACK controls, thus being suspended. By forcing mpv to still use PulseAudio in this case, the user can now adjust the sink to an unsuspended one.
* ao_pulse: fix tlength calculationTom Yan2018-09-011-3/+3
| | | | also remove the now unused non-sensical af_fmt_seconds_to_bytes.
* ao_pulse: reduce requested device buffer sizewm42018-04-151-1/+1
| | | | | | Same deal as with the previous commit for ALSA. Untested.
* ao_pulse: reorder format choiceNiklas Haas2017-06-231-2/+2
| | | | | | | | | | | | Right now, the current order pretty much means that pulse defaults to S16 for arbitrary unsupported formats, but fallback to float would make more sense since it's the easiest to convert everything to without requiring dithering, and PA will probably just internally convert things to float anyway. Also move S32 above S16, which essentially means format_maps is sorted by preference. (Although ao_pulse currently ignores this and always picks the first as a fallback)
* ao_pulse, ao_rsound: change license to LGPLwm42017-05-081-7/+7
| | | | | | | | All authors have agreed. One exception is 71247a97b35, whose author was not asked, but we deem the change as trivial. (And technically it was replaced when the audio chain dropped non-native endian sample formats.)
* options: remove remaining deprecated audio device selection optionswm42017-04-231-3/+1
|
* options: remove deprecated sub-option handling for --vo and --aowm42016-11-251-1/+1
| | | | | | | | Long planned. Leads to some sanity. There still are some rather gross things. Especially g_groups is ugly, and a hack that can hopefully be removed. (There is a plan for it, but whether it's implemented depends on how much energy is left.)
* audio/out: deprecate device sub-optionswm42016-09-051-1/+1
| | | | | We have --audio-device, which can force the device. Also add something describing to this extent to the manpage.
* options: deprecate suboptions for the remaining AO/VOswm42016-09-051-0/+1
|
* ao_pulse: fix some volume control rounding issueswm42016-07-141-2/+3
| | | | | Volume could get easily "stuck" or making too huge steps when doing things like "add ao-volume 1".
* ao_pulse: attempt to fall back to an arbitrary sample formatwm42016-01-051-2/+7
| | | | | | | | | | | | | | | | | | | | | | | Normally, PulseAudio accepts any combination of sample format, sample rate, channel count/map. Sometimes it does not. For example, the channel rate or channel count have fixed maximum values. We should not fail fatally in such cases, but attempt to fall back to a working format. We could just send pass an "unset" format to Pulse, but this is not too attractive. Pulse could use a format which we do not support, and also doing so much for an obscure corner case is not reasonable. So just pick a format that is very likely supported. This still could fail at runtime (the stream could fail instead of going to the ready state), but this sounds also too complicated. In particular, it doesn't look like pulse will tell us the cause of the stream failure. (Or maybe it does - but I didn't find anything.) Last but not least, our fallback could be less dumb, and e.g. try to fix only one of samplerate or channel count first to reduce the loss, but this is also not particularly worthy the effort. Fixes #2654.
* ao_pulse: check for sample rate boundswm42016-01-051-1/+1
| | | | | | | pa_format_info_valid() does not do this. (Although there is a proposed patch on the PulseAudio mailing list.) See #2654.
* ao_pulse: move format setting into a functionwm42016-01-051-20/+26
| | | | No real functional changes.
* audio: fix format function consistency issueswm42015-06-261-1/+1
| | | | | | | | | | | Replace all the check macros with function calls. Give them all the same case and naming schema. Drop af_fmt2bits(). Only af_fmt2bps() survives as af_fmt_to_bytes(). Introduce af_fmt_is_pcm(), and use it in situations that used !AF_FORMAT_IS_SPECIAL. Nobody really knew what a "special" format was. It simply meant "not PCM".
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* ao_pulse: drop video role; fixes random mutingwm42015-03-241-1/+0
| | | | | | | | | The details are described in #1173. This "features" causes problems to users so often, it's better to remove it. Fixes #1173.
* ao_pulse: listen for hotplug eventswm42015-02-121-7/+41
| | | | | | | | | | | | | | | This requires jumping through multiple hoops on fire. Since the PulseAudio API is virtually undocumented, I'm not sure if this is correct either. We only react to sink events, and only to the NEW/REMOVE events. CHANGE events are ignored, because PulseAudio fires them far too often - even if the system is completely idle! If pa_sink_info.name can change, we're in trouble. pa_sink_info.description is not so important, but it'd also be a bit un-nice if it can change, and we don't update it. The weird way how the actual AO and the hotplug context share the same struct (ao) comes in handy here, although context_success_cb() still had to be duplicated from success_cb() - the unused argument has a different type.
* ao_pulse: plug a memory leakBen Boeckel2015-01-251-0/+3
|
* ao_pulse: exit AO if stream failswm42015-01-111-1/+5
| | | | | | This can for example reproduced by killing the pulseaudio server. If this happens, just try to reload the AO, instead of breaking everything forever.
* ao_pulse: disable latency calculation hacks by defaultwm42015-01-071-1/+0
| | | | | | | | | | | | | | This used to be required to workaround PulseAudio bugs. Even later, when the bugs were (partially?) fixed in PulseAudio, I had the feeling the hacks gave better behavior. On the other hand, I couldn't actually reproduce any bad behavior without the hacks lately. On top of this, it seems our hacks sometimes perform much worse than PulseAudio's native implementation (see #1430). So disable the hacks by default, but still leave the code and the option in case it still helps somewhere. Also, being able to blame PulseAudio's code by using its native API is much easier than trying to debug our own (mplayer2-derived) hacks.
* audio/out: consistently use double return type for get_delaywm42014-11-091-3/+3
| | | | | ao_get_delay() returns double, but the get_delay callback still returned float.
* audio: add --audio-client-name optionwm42014-11-071-5/+2
| | | | | | The main need I see for this is with libmpv - it would be confusing if some application showed up as "mpv" on whateverthehell PulseAudio uses it for (generally it does show up on various PA GUI tools).
* ao_pulse: implement AO device listing APIwm42014-10-101-1/+38
| | | | | | | | | | | | | | | | While conceptually this sink stuff in PulseAudio does just the right thing, actually listing the sinks is unbelievable complicated. Not only is the idea that listing them should happen asynchronously completely bullshit (who the fuck runs the PulseAudio server on a separate computer), but the way this is done is full of bullshit too. Why separate callbacks for each device? Why this obtuse mainloop shit? Especially the mainloop shit makes it actively worse than doing things manually with pthread primitives, and the reason for that (different mainloop implementations for GUIs?) is laughable too. It's like they chose the most complicated API possible just because they attempted to "abstract" basic mechanisms in order to handle "everything". While I don't claim to design the best APIs, this API is fucking terrible without any excuse. (End of rant.)
* ao_pulse: move setup code to separate functionwm42014-10-101-23/+48
| | | | | | | All the dumb crap in pa_init_boilerplate() is needed to talk to the audio server at all. Might also fix some subtle bugs in the init code (which is strange, because the original file was contributed by the devil himself).
* ao_pulse: don't use pa_format_info_to_sample_spec()wm42014-10-061-9/+4
| | | | | | | | | | | This function is available starting with PulseAudio 2.0, while we only require 1.0. This broke compilation on Ubuntu 12.04.5 LTS. Use our own function to calculate the buffer size, which is actually simpler and needs slightly less code. Hopefully fixes #1154. CC: @mpv-player/stable
* ao_pulse: change suspend circumvention logicwm42014-10-041-1/+6
| | | | | | | | | | | | | | Commit 957097 attempted to use PA_STREAM_FAIL_ON_SUSPEND to make ao_pulse exit if the stream was started suspended. Unfortunately, PA_STREAM_FAIL_ON_SUSPEND is active even during playback. If you pause mpv, pulseaudio will close the actual audio device after a while (or something like this), and unpausing won't work. Instead, it will spam "Entity killed" error messages. Undo this change and check for suspended audio manually during init. CC: @mpv-player/stable
* ao_pulse: refuse to start suspendedwm42014-10-031-1/+1
| | | | | | | | | | | | Sometimes, ao_pulse starts in suspended mode, which means playback is essentially paused in pulseaudio. This gives the impression that mpv is hanging, since it times video against the audio playback progress, and audio never makes progress in this state. I'm not sure if this will help - possibly it does with mixed pulseaudio/alsa setups. However, if the alsa setup has the pulseaudio plugin, alsa will hang too. But there's still a chance we get less blame for pulseaudio messes.
* ao_pulse: digital pass-throughwm42014-09-231-20/+46
| | | | | | | | Should be able to pass-through AC3, DTS, and others. It seems PulseAudio wants players to fallback to PCM on certain events signaled by the server, but we don't implement that. There's not much documentation available anyway.
* ao_pulse: correctly wait for stream statewm42014-09-231-1/+8
| | | | | This works similar to condition variables; for some reason this apparently worked fine until now, but it breaks with passthrough mode.
* ao_pulse: use pa_stream_new_extended()wm42014-09-231-3/+8
| | | | Needed for compressed audio pass-through later.
* audio: drop swapped-endian audio formatswm42014-09-231-6/+3
| | | | | | | | | | | | | | | | | | | | Until now, the audio chain could handle both little endian and big endian formats. This actually doesn't make much sense, since the audio API and the HW will most likely prefer native formats. Or at the very least, it should be trivial for audio drivers to do the byte swapping themselves. From now on, the audio chain contains native-endian formats only. All AOs and some filters are adjusted. af_convertsignendian.c is now wrongly named, but the filter name is adjusted. In some cases, the audio infrastructure was reused on the demuxer side, but that is relatively easy to rectify. This is a quite intrusive and radical change. It's possible that it will break some things (especially if they're obscure or not Linux), so watch out for regressions. It's probably still better to do it the bulldozer way, since slow transition and researching foreign platforms would take a lot of time and effort.
* ao_pulse: dump library version etc.wm42014-09-101-0/+6
| | | | | | | Might help with debugging. Unfortunately, there doesn't seem to be a way to get the actual pulseaudio server version.
* ao_pulse: fix typo in error messagewm42014-09-081-1/+1
| | | | Closes #1076.
* audio/out: remove old thingswm42014-09-061-2/+3
| | | | | | | | Remove the unnecessary indirection through ao fields. Also fix the inverted result of AOCONTROL_HAS_TEMP_VOLUME. Hopefully the change is equivalent. But actually, it looks like the old code did it wrong.
* ao_pulse: allow disabling timing bug workaroundswm42014-07-261-3/+38
| | | | | | | | | |