summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_coreaudio_utils.c
Commit message (Collapse)AuthorAgeFilesLines
* ao/avfoundation: optimise preprocessors for included coreaudio codeRobert Kopaczewski11 days1-4/+4
|
* ao_avfoundation: initial avfoundation ao supportMisaki Kasumi2024-03-291-1/+2
|
* various: replace some OOM handlingsfan52023-11-241-4/+2
| | | | | | We prefer to fail fast rather than degrade in unpredictable ways. The example in sub/ is particularly egregious because the code just skips the work it's meant to do when an allocation fails.
* ao/coreaudio_exclusive: fix segfault when changing formatsleetoburrito2023-11-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PR #12747 missed updating a variable declaration in `ca_change_physical_format_sync`, which ultimately leads to the thread crashing. The problem reproduces consistently on AS Macs (I don't have an Intel Mac to test on anymore), and produces stack traces like the following: ``` Thread 3 Crashed:: mpv 0 libsystem_kernel.dylib 0x18cebd11c __pthread_kill + 8 1 libsystem_pthread.dylib 0x18cef4cc0 pthread_kill + 288 2 libsystem_c.dylib 0x18ce04ad4 __abort + 136 3 libsystem_c.dylib 0x18cdf56c4 __stack_chk_fail + 96 4 mpv 0x1026b66d0 ca_change_physical_format_sync + 420 5 mpv 0x1026b3b70 init + 1052 6 mpv 0x1025c5afc ao_init + 332 7 mpv 0x1025c5bec ao_init + 572 8 mpv 0x1025c5830 ao_init_best + 1228 9 mpv 0x102622fac fill_audio_out_buffers + 1820 10 mpv 0x1026450d0 run_playloop + 132 11 mpv 0x10263f958 play_current_file + 5116 12 mpv 0x10263e4e8 mp_play_files + 452 13 mpv 0x102641308 mpv_main + 128 14 mpv 0x10269f520 playback_thread + 40 15 libsystem_pthread.dylib 0x18cef5034 _pthread_start + 136 16 libsystem_pthread.dylib 0x18ceefe3c thread_start + 8 ``` Note that non-exclusive output seems to be unaffected. To reproduce this problem (and/or test this fix), pass `--audio-exclusive=yes` to mpv.
* semaphore_osx: change mp_sem_timedwait to mp_timeKacper Michajłow2023-10-261-2/+2
|
* semaphore_osx: don't overwrite global symbolsKacper Michajłow2023-10-261-5/+5
|
* ao: convert all timing code to nanosecondsDudemanguy2023-10-161-6/+6
| | | | | | | 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.
* osdep: move cfstr<->cstr conversions to a new apple_utils.c filercombs2023-06-251-15/+0
|
* ao_coreaudio: use device's nominal sample rate for latency propertiesrcombs2022-12-101-1/+9
| | | | | | Fixes sync issues when using high-latency devices at non-native sample rates Closes #10984
* ao/audiounit: improve a/v syncAman Gupta2019-04-051-1/+17
| | | | | | | This more closely mimics ao_coreaudio, on which this driver was originally based. Signed-off-by: Aman Gupta <aman@tmm1.net>
* 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.
* audio/out: add AudioUnit output driver for iOSAman Gupta2016-11-011-4/+9
|
* ao_creoaudio: print OSStatus as decimal signed integer toowm42016-07-131-1/+1
| | | | | OSStatus is quite inconsistent. Sometimes it's a FourCC, sometimes it reads as decimal signed number.
* ao_coreaudio: error out when selecting invalid devicewm42016-07-081-0/+7
| | | | | | | | | | | | | | | | When selecting a device that simply doesn't exist with --audio-device, AudioUnit will still initialize and start playback without complaining. But it will never call the audio render callback, which leads to audio playback simply not progressing. I couldn't find a way to get AudioUnit to report an error at all, so here's a crappy hack that takes care of this in most cases. We assume that all devices have a kAudioDevicePropertyDeviceIsAlive property. Invalid devices will error when querying the property (with 'obj!' as status code). This is not the correct fix, because we try to double-guess AudioUnit's behavior by accessing a lower label API. Suggestions welcome.
* ao_coreaudio_exclusive: list formats when searching substreamwm42016-04-151-0/+3
| | | | Should help debug problems with AC3 passthrough not working.
* ao_coreaudio: remove unused functionwm42016-04-151-24/+0
|
* ao_coreaudio: replace fourcc_repr()wm42016-01-111-28/+3
| | | | Replace with the more general mp_tag_str().
* ao_coreaudio: log current format before setting new formatwm42015-10-211-0/+2
|
* ao_coreaudio: raise timeout for change-physical-formatwm42015-10-201-1/+1
| | | | | | | | | | Reportedly fixes operation with "USB connected Parasound ZDAC v.2". (OSX and USB audio sure is not nice at all.) This might be perceived as hang by some users, so it's quite possible that this will have to be adjusted again somehow. Fixes #2409.
* ao_coreaudio_utils: fix error handling in device listing codewm42015-09-281-3/+10
| | | | | | | | This could sometimes cause crashes in hotplug events. (Apparently in cases when CoreAudio changes its state asynchronously, or such.) CA_GET_STR() does not set the string if there was an error, so errors have to be strictly checked before using it.
* ao_coreaudio: fix device latency, share the codewm42015-07-061-0/+22
| | | | | | | | | 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_exclusive: continue even if setting physical format failswm42015-07-061-0/+1
| | | | | Makes it work with (apparently) crappy drivers, which refuse to set the physical format in some cases.
* ao_coreaudio_utils: reduce spamwm42015-07-031-1/+0
|
* ao_coreaudio_utils: fix format back-mappingwm42015-07-031-5/+7
| | | | | | | | | | | Mapping of spdif formats was imperfect. Since the first format on the list is somehow AAC, it was returned first, which is confusing, because CoreAudio calls all spdif formats AC3. Since the spdif formats have some rather arbitrary, reverse mapping the formats didn"t actually work either. Fix by explicitly ignoring these when spdif is used. Also, don't forget to set the samplerate in ca_asbd_to_mpformat(), or it will work only in some cases.
* ao_coreaudio: restore physical format if it can't be set exactlywm42015-06-301-1/+12
| | | | | | | | 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.
* audio: fix format function consistency issueswm42015-06-261-5/+5
| | | | | | | | | | | 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".
* audio: replace format name tablewm42015-06-261-4/+3
| | | | Having a big switch() is simpler.
* ao_coreaudio_utils: use a macrowm42015-06-261-1/+1
| | | | | This is actually the last line of code outside of format.c/h which still tries to fiddle with the format bitfields.
* ao_coreaudio: support non-interleaved outputwm42015-06-261-1/+7
| | | | | This saves us the trouble of interleaving the audio data for no reason.
* ao_coreaudio_utils: compare full AudioStreamBasicDescriptionwm42015-06-251-1/+3
| | | | | | Originally, this was written for comparing the sample format only, but ca_change_physical_format_sync() actually expects that the full format is compared. (For all other uses it doesn't matter.)
* audio: remove S8, U16, U24, U32 formatswm42015-06-161-1/+1
| | | | | | | | | | | | | They are useless. Not only are they actually rarely in use; but libavcodec doesn't even output them, as libavcodec has no such sample formats for decoded audio. Even if it should happen that we actually still need them (e.g. if doing direct hardware output), there are better solutions. Swapping the sign is a fast and lossless operation and can be done inplace, so AO actually needing it could do this directly. If you wonder why we keep U8 instead of S8: because libavcodec does it.
* ao_coreaudio: change physical stream format synchronouslywm42015-06-091-1/+1
|
* ao_coreaudio_exclusive: move generic functions to utilswm42015-06-021-2/+196
|
* ao_coreaudio_utils: don't list some formats as "unusable"wm42015-05-071-1/+1
| | | | | While mpv has no internal equivalent representation, they can still be used as physical CoreAudio formats. Thus this label is confusing.
* ao_coreaudio_utils: decide formats by comparing raw bitswm42015-05-051-5/+6
| | | | | | | | | | | | | | | | Instead of trying to use af_format_conversion_score() (which tries to be all kinds of clever), just compare the raw bits as a quality measure. Do this because otherwise, weird formats like padded 24 bit formats will be excluded, even though they might be the highest precision formats for some hardware. This means that for now, the user would have to check whether the format is usable at all before calling ca_asbd_is_better(). But since this is currently only used for ao_coreaudio.c and for the physical format, it doesn't matter. If coreaudio-exclusive should get PCM support, the best would be to revert this change, and to add support for 24 bit formats directly.
* ao_coreaudio_utils: don't require talloc for fourcc_repr()wm42015-05-051-12/+6
| | | | | Instead, apply a trick to make the caller allocate enough space on the stack.
* ao_coreaudio_utils: unbreak default device selectionwm42015-05-051-4/+3
| | | | | | It appears this is the reason coreaudio-exclusive does not work without explicitly specifying a device, even if the default device maps to something passthrough-capable.
* ao_coreaudio_utils: refine format selectionwm42015-05-051-19/+25
| | | | | | | | | | | Instead of always picking a somehow better format over the previous one, select a format that is equal to or better the requested format, but is also reasonably close. Drop the mFormatID comparison - checking the sample format handles this already. Make sure to exclude channel counts that can't be used.
* ao_coreaudio_utils: add a format negotiation helper functionwm42015-05-051-0/+34
|
* ao_coreaudio_utils: log mp format with CoreAudio format descriptionwm42015-04-291-2/+4
| | | | As a consequence, it also logs whether mpv can a this format at all.
* ao_coreaudio_utils: add function for ASBD -> mp format lookupwm42015-04-291-7/+56
| | | | | | | | | | Useful with some of the following commits. ca_fill_asbd() should behave exactly as before. Instead of actually implementing the inverse function of ca_fill_asbd(), just loop over the (small) list of mpv functions and check if any mpv equivalent to a given ASBD exists.
* ao_coreaudio_utils: float is not a signed integer formatwm42015-04-291-3/+3
| | | | | | | | | kAudioFormatFlagIsSignedInteger implicates that it's only used with integer formats. The mpv internal flag on the other hand signals the presence of a sign, and this is set on float formats. Until now, this probably worked fine, because at least AudioUnit is ignoring the uncorrect flag.
* ao_coreaudio_utils: change audio format loggingwm42015-04-281-3/+3
| | | | Make it easier to distinguish the fields.
* ao_coreaudio: fix inverted conditionwm42015-04-101-3/+4
| | | | And also use the correct type for the printf call below.
* ao_coreaudio: do not error if retrieving info for verbose mode failswm42015-04-071-6/+6
| | | | | | The message log level shouldn't get to decide whether something fails or not. So replace the fatal error check on the verbose output code path with a warning.
* ao_coreaudio: move some helpers to utilswm42015-03-101-0/+17
| | | | Needed by ao_coreaudio_exclusive.c in the next commit.
* ao_coreaudio: fix small memory leakStefano Pigozzi2015-02-031-0/+4
|
* ao_coreaudio: use device UID instead of ID for selectionStefano Pigozzi2015-02-031-12/+38
| | | | | | | | | | 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.
* ao_coreaudio: reset possibly random errno valuewm42015-01-201-1/+2
| | | | | | | | | | In general, you need to check errno when using strtol(), but as far as I know, strtol() won't reset errno on success. This has to be done manually. The code could have failed sporadically if strtol() succeeded, and errno was already set to one of the checked values. (This strtol() still isn't fully error checked, but I don't know if it's intentional, e.g. for parsing a numeric prefix only.)
* coreaudio: only list output devicesStefano Pigozzi2014-10-281-0/+12
|
* coreaudio: redirect IEC61937 to coreaudio_exclusiveStefano Pigozzi2014-10-231-1/+1
|
* coreaudio: use the new device selection APIStefano Pigozzi2014-10-121-25/+19
| | | | | The CoreAudio API is built around device IDs so we store the integer as string and read it back.
* audio: cleanup spdif format definitionswm42014-09-231-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, there was AF_FORMAT_AC3 (the original spdif format, used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS and DTS-HD), which was handled as some sort of superset for AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used IEC61937-framing, but still was handled as something "separate". Technically, all of them are pretty similar, but may use different bitrates. Since digital passthrough pretends to be PCM (just with special headers that wrap digital packets), this is easily detectable by the higher samplerate or higher number of channels, so I don't know why you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs. AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is just a mess. Simplify this by handling all these formats the same way. AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3). All AOs just accept all spdif formats now - whether that works or not is not really clear (seems inconsistent due to earlier attempts to make DTS-HD work). But on the other hand, enabling spdif requires manual user interaction, so it doesn't matter much if initialization fails in slightly less graceful ways if it can't work at all. At a later point, we will support passthrough with ao_pulse. It seems the PulseAudio API wants to know the codec type (or maybe not - feeding it DTS while telling it it's AC3 works), add separate formats for each codecs. While this reminds of the earlier chaos, it's stricter, and most code just uses AF_FORMAT_IS_IEC61937(). Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to include special formats, so that it always describes the fundamental sample format type. This also ensures valid AF formats are never 0 (this was probably broken in one of the earlier commits from today).
* audio: drop swapped-endian audio formatswm42014-09-231-1/+2
| | | | | | | | | | | | | | | | | | | | 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_coreaudio: move channel mapping away from utilsStefano Pigozzi2014-07-021-123/+0
| | | | | Channel mapping functions are only used in the AUHAL based coreaudio, so move them there.
* ao_coreaudio: fill asbd with an helper functionStefano Pigozzi2014-07-021-0/+26
|
* ao_coreaudio: move device related functions to the new AOStefano Pigozzi2014-07-021-249/+0
|
* ao_coreaudio: move spdif code to a new AOStefano Pigozzi2014-07-021-0/+62
| | | | | | | | | | | | | | | | The mplayer1/2/mpv CoreAudio audio output historically contained both usage of AUHAL APIs (these go through the CoreAudio audio server) and the Device based APIs (used only for output of compressed formats in exclusive mode). The latter is a very unwieldy and low level API and pretty much forces us to write a lot of code for little workr. Also with the widespread of HDMI, the actual need for outputting compressed audio directly to the device is getting lower (it was very useful with S/PDIF for bandwidth constraints not allowing a number if channels transmitted in LPCM). Considering how invasive it is (uses hog/exclusive mode), the new AO (`ao_coreaudio_device`) is not going to be autoprobed but the user will have to select it.
* Audit and replace all ctype.h useswm42014-07-011-2/+2
| | | | | | | | | | | | | | | | Something like "char *s = ...; isdigit(s[0]);" triggers undefined behavior, because char can be signed, and thus s[0] can be a negative value. The is*() functions require unsigned char _or_ EOF. EOF is a special value outside of unsigned char range, thus the argument to the is*() functions can't be a char. This undefined behavior can actually trigger crashes if the implementation of these functions e.g. uses lookup tables, which are then indexed with out-of-range values. Replace all <ctype.h> uses with our own custom mp_is*() functions added with misc/ctype.h. As a bonus, these functions are locale-independent. (Although currently, we _require_ C locale for other reasons.)
* ao_coreaudio: skip unknown channel labelsStefano Pigozzi2014-05-101-0/+2
| | | | | | | | | | | | | I don't think this is really a very good idea because it is conceptually incorrect but other prominent multimedia programs use this approach (VLC and xbmc), and it seems to make the conversion more robust in certain cases. For example it has been reported, that configuring a receiver that can output 7.1 to output 5.1, will make CoreAudio report 8 channel descriptions, and the last 2 descriptions will be tagged kAudioChannelLabel_Unknown. Fixes #737
* ao_coreaudio: cosmetic change of loop ending conditionStefano Pigozzi2014-05-101-1/+1
|
* ao_coreaudio: use description-based channel layoutsStefano Pigozzi2014-05-101-74/+47
| | | | | | | | | | | | CoreAudio supports 3 kinds of layouts: bitmap based, tag based, and speaker description based (using either channel labels or positional data). Pre