summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_coreaudio.c
Commit message (Collapse)AuthorAgeFilesLines
* ao_coreaudio: add a comment for ignoring returned sample countMisaki Kasumi5 days1-0/+1
| | | | Co-authored-by: sfan5 <sfan5@live.de>
* Revert "ao_coreaudio: signal buffer underruns"Misaki Kasumi5 days1-8/+1
| | | | | This reverts commit 0341a6f1d39801160322d3fe16245f8387735f4b. Fixes #13348.
* Revert "ao_coreaudio: switch to ao_read_data_nonblocking()"m154k17 days1-1/+1
| | | | This reverts commit 36d5b5261282dd964f80cd2bb04bb53a7c6d895b.
* ao_coreaudio: register hotplug_cb in normal init() as wellMisaki Kasumi2024-04-031-4/+36
| | | | | | | `hotplug_cb` was registered only in `hotplug_init()`. This commit make it registered in `init()` as well, so that the ao can listen for latency change in playback.
* ao_coreaudio: handle latency change on hotplugMisaki Kasumi2024-03-291-2/+13
| | | | | | | The device latency may change during hotplugging. This commit updates p->hw_latency_ns each time hotplug_cb is called so that it can reflect updated device latency.
* ao_coreaudio: stop audio unit after idle timeoutVilius2024-03-161-2/+79
| | | | | | | | | | | | | | | | | | | | | | | | | Commit 39f7f83 changed ao_driver.reset to use AudioUnitReset instead of AudioOutputUnitStop. The problem with calling AudioOutputUnitStop was that AudioOutputUnitStart takes a significant amount of time after a stop when a wireless audio device is being used. This resulted in lagging that was noticeable to users during seeking and short pause/resume cycles. Switching to AudioUnitReset eliminated this lagging. However with the switch to AudioUnitReset the macOS daemon coreaudiod continued to consume CPU time and did not release a powerd assertion that it created on behalf of mpv, preventing macOS from sleeping. This commit will change ao_coreaudio.reset to call AudioOutputUnitStop after a delay if playback has not resumed. This preserves the faster restart of playback for seeking and short pause/resume cycles and avoids preventing sleep and needless CPU consumption. Fixes #11617 The code changes were authored by @orion1vi and @lhc70000. Co-authored-by: Collider LI <lhc199652@gmail.com>
* ao_coreaudio: switch to ao_read_data_nonblocking()Thomas Weißschuh2023-11-081-1/+1
|
* ao_coreaudio: signal buffer underrunsUmar Getagazov2023-10-291-1/+8
| | | | | Change the resulting buffer sizes to match the actual amount of samples read, and set a flag in case no samples were read at all.
* ao: convert all timing code to nanosecondsDudemanguy2023-10-161-9/+9
| | | | | | | Pull AOs work off of a callback that relies on mpv's internal timer. So like with the related video changes, convert all of these to nanoseconds instead. In many cases, the underlying audio API does actually provide nanosecond resolution as well.
* options: transition options from OPT_FLAG to OPT_BOOLChristoph Heinrich2023-02-211-2/+2
| | | | | | 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-4/+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.
* ao_coreaudio: use AudioUnitReset as ao_driver.reset to prevent long restartLi Chang2023-01-021-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [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.
* audio: remove unused ring.h includeswm42020-08-271-1/+0
| | | | | From what I can tell, this has been copy-pasted from times when ao_coreaudio still used its own ringbuffer, instead of the common code.
* audio: redo internal AO APIwm42020-06-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* options: change option macros and all option declarationswm42020-03-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-2/+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_coreaudio: change license to LGPLwm42017-05-081-7/+7
| | | | | | | | | | | | | | | | All authors have agreed to the relicensing. The code was pretty much rewritten by Stefano Pigozzi. Since the rewrite happened incrementally, and seems to include refactored portions of older code, this relicensing was done on the pre-refactor code do. The original commit adding this AO (as ao_macosx.c) credits Timothy J. Wood as original author. He was asked and agreed to LGPL. It's not entirely sure from which project this code came from, but it's probably libao. In that project, Stanley Seibert made some changes to it (who as a major developer of libao was asked just to be sure), and also Ralph Giles and Ben Hines made two small changes. The latter were not asked, but none of their code survived anyway.
* options: remove deprecated sub-option handling for --vo and --aowm42016-11-251-7/+2
| | | | | | | | 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 "exclusive" sub-optionswm42016-09-051-1/+4
| | | | | | | And introduce a global option which does this. Or more precisely, this deprecates the global wasapi and coreaudio options, and adds a new one that merges their functionality. (Due to the way the sub-option deprecation mechanism works, this is simpler.)
* options: deprecate suboptions for the remaining AO/VOswm42016-09-051-0/+1
|
* ao_coreaudio: actually use stop callbackwm42016-08-091-1/+1
| | | | | | The .pause callback is never used for pull.c-based AOs. This means this always streamed silence instead of deactivating audio.
* ao_coreaudio: remove detected_devicewm42016-04-261-5/+0
| | | | | | | | | | | Setting this here is a race condition. It's called from a CoreAudio callbacks, and there are no locks. It's a string, so this can be potentially severe. It's hard to fix and only CoreAudio supported it, so remove it. This causes the "audio-out-detected-device" property to return nothing on all platforms.
* ao_coreaudio: replace fourcc_repr()wm42016-01-111-4/+4
| | | | Replace with the more general mp_tag_str().
* ao_coreaudio: avoid unnecessary format changeswm42015-10-211-0/+6
| | | | | Not particularly important; just being nice and potentially avoiding problems caused by format setting.
* ao_coreaudio: fix some minor memory leakswm42015-10-211-0/+6
|
* ao_coreaudio: fix device latency, share the codewm42015-07-061-5/+1
| | | | | | | | | ao_coreaudio (using AudioUnit) accounted only for part of the latency - move the code in ao_coreaudio_exclusive to utils, and use that for the AudioUnit code. (There's still the question why CoreAudio and AudioUnit require you to jump through hoops this much, but apparently that's how it is.)
* ao_coreaudio: add exclusive suboptionwm42015-07-031-2/+4
|
* ao_coraudio: reject all non-PCM formatswm42015-07-031-1/+1
| | | | | Currently this is equivalent. On the other hand, all audio code should reject formats that is not in a category known to it.
* ao_coreaudio: restore physical format if it can't be set exactlywm42015-06-301-1/+2
| | | | | | | | May help with (supposedly) bad drivers, which can put the device into some sort of broken state when trying to set a different physical format. When the previous format is restored, it apparently recovers. This might make the change-physical-format suboption more robust.
* ao_coreaudio: log hotplug events explicitlywm42015-06-291-3/+6
|
* 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".
* ao_coreaudio: support non-interleaved outputwm42015-06-261-4/+5
| | | | | This saves us the trouble of interleaving the audio data for no reason.
* ao_coreaudio: explicitly skip input streamswm42015-06-261-4/+14
| | | | | | | This may or may not fix some issues with the format switching code. Actually, it seems somewhat unlikely, but then checking the stream type isn't incorrect either, and is probably something the API user should always be doing.
* ao_coreaudio: change physical stream format synchronouslywm42015-06-091-4/+1
|
* ao_coreaudio: log considered physical formatswm42015-05-051-0/+4
|
* ao_coreaudio: restore old physical format if format was changedwm42015-05-051-0/+16
|
* ao_coreaudio: move channel mapping code to a separate filewm42015-05-051-255/+4
| | | | | | | | | | Move all of the channel map retrieval/negotiation code to a separate file. This will (probably) be helpful when extending ao_coreaudio_exclusive.c. Nothing else changes, other than some minor cosmetics and renaming, and changing some details for decoupling it from the ao_coreaudio.c internals.
* ao_coreaudio_utils: don't require talloc for fourcc_repr()wm42015-05-051-4/+4
| | | | | Instead, apply a trick to make the caller allocate enough space on the stack.
* ao_coreaudio: change physical format before channel negotiationwm42015-05-051-4/+10
| | | | | | If for example the physical format is set to stereo, the reported multichannel layout will actually be stereo. It fixes itself only after the physical format is changed.
* ao_coreaudio: add an option for changing the physical formatwm42015-05-051-0/+55
| | | | | | | | | | | | ao_coreaudio uses AudioUnit - the OSX software mixer. In theory, it supports multichannel audio just fine. But in practice, this might be disabled by default, and the user is supposed to select a multichannel base format in the "Audio MIDI Setup" utility. This option attempts to change this setting automatically. Some possible disadvantages and caveats are listed in the manpage additions. It is off by default, since changing this might be rather bad behavior for a normal application.
* ao_coreaudio: support padded channel layoutswm42015-05-051-2/+6
| | | | | | | If for example the audio settings are set to 5.1 output, but the hardware does 8 channels natively (HDMI), the reported channel layout will have 2 dummy channels. To avoid falling back to stereo, we have to write audio in this format to the device.
* ao_coreaudio: fix out of bounds accesswm42015-05-041-0/+2
| | | | | | ca_label_to_mp_speaker_id() checked whether the last entry was >= 0, but actually this condition was never true, and MP_SPEAKER_ID_UNKNOWN0 is not negative.
* ao_coreaudio: do not signal per-app volumewm42015-04-011-2/+0
| | | | | CoreAudio doesn't seem to have this concept. The volume is reset the next time audio is opened.
* ao_coreaudio: move some helpers to utilswm42015-03-101-16/+0
| | | | Needed by ao_coreaudio_exclusive.c in the next commit.
* ao_coreaudio: add support for hotplug notificationsStefano Pigozzi2015-02-141-17/+90
| | | | | | | | | | This commit adds notifications for hot plugging of devices. It also extends the old behaviour of the `audio-out-detected-device` property which is now backed by the hotplugging code. This allows clients to be notified when the actual audio output device changes. Maybe hotplugging should be supported for ao_coreaudio_exclusive too, but it's device selection code is a bit fragile.
* ao_coreaudio: use device UID instead of ID for selectionStefano Pigozzi2015-02-031-1/+4
| | | | | | | | | | Previously we let the user use the audio device ID, but this is not persistent and can change when plugging in new devices. That of course made it quite worthless for storing it as a user setting for GUIs, or for user scripts. In theory getting the kAudioDevicePropertyDeviceUID can fail but it doesn't on any of my devices, so I'm leaving the error reporting quite high and see if someone complains.
* command: add property returning detected audio deviceStefano Pigozzi2015-02-031-0/+2
| | | | | This can be useful to adjust some other audio related properties at runtime depending on the audio device being used.
* ao_coreaudio: remove useless guardStefano Pigozzi2014-12-271-6/+0
| | | | useless after 069016fd6c
* ao_coreaudio: fix some naming conventionsStefano Pigozzi2014-12-271-5/+5
|
* ao_coreaudio: fix channel mappingStefano Pigozzi2014-12-271-19/+70
| | | | | | | | | | | | | | | There where 3 major errors in the previous code: 1) The kAudioDevicePropertyPreferredChannelLayout selector returns a single layout not an array. 2) The check for AudioChannelLayout allocation size was wrong (didn't account for variable sized struct). 3) Didn't query the kAudioDevicePropertyPreferredChannelsForStereo selector since I didn't know about it's existence. All of these are fixed. Might help with #1367
* ao_coreaudio: fix typoStefano Pigozzi2014-12-271-1/+1
|
* ao_coreaudio: move some code to make output readableStefano Pigozzi2014-12-271-1/+1
|
* ao_coreaudio: add more layout debug outputsStefano Pigozzi2014-12-271-19/+25
| | | Should help remote debugging #1367 with --msg-level=ao=debug
* ao_coreaudio: fix AudioChannelLayout allocationsStefano Pigozzi2014-12-261-34/+46
| | | | | | | | AudioChannelLayout uses a trailing variable sized array so we need to query CoreAudio for the size of the struct it is going to need (or the conversion of that particular layout would fail). Fixes #1366
* ao_coreaudio: fix mono/stereo channel mappingStefano Pigozzi2014-12-161-9/+7
| | | | | | Needed after af3bbb800d since now we use channel mapping all the time. Fixes #1357
* ao_coreaudio: add missing goto for error pathStefano Pigozzi2014-12-161-0/+1
|
* coreaudio: don't output too many channel descriptionsStefano Pigozzi2014-12-051-0/+6
| | | | for #1279 and #1249
* coreaudio: add missing \n in log lineStefano Pigozzi2014-12-051-1/+1
|
* coreaudio: don't print layout a second timeStefano Pigozzi2014-12-051-1/+1
| | | | For #1279
* coreaudio: reject descriptions with too many channelsStefano Pigozzi2014-12-041-0/+7
| | | | This is a fix attempt for #1279 and #1249.
* coreaudio: fix more layout printsStefano Pigozzi2014-12-041-2/+2
|
* coreaudio: fix prints of uint32_t in log_layoutStefano Pigozzi2014-12-041-10/+10
|
* audio: allow more than 20 channel map entrieswm42014-12-011-1/+1
| | | | | | | | | |