Commit Graph

660 Commits

Author SHA1 Message Date
wm4 872b19dfcb ao_alsa: fix a log message
So apparently, this essentially happens when the kernel driver doesn't
implement write accesses in the channel map control. Which doesn't
necessarily mean that the channel map is unsupported, or that there is a
bug - it's just lazyness and a consequence of the terrible ALSA kernel
API for the channel mapping stuff.

In these cases, the channel count implicitly selects the channel map,
and snd_pcm_set_chmap() always fails with ENXIO.

I'm actually not sure what happens if dmix is on top of e.g. HDMI, which
actually lets you change the channel mapping.

I'm also not sure why commit d20e24e5d1614354e9c8195ed0b11fe089c489e4
(alsa-lib git repository) does not take care of this.
2015-06-21 18:32:38 +02:00
Marcin Kurczewski 797277a233 Various spelling fixes
Signed-off-by: wm4 <wm4@nowhere>
2015-06-18 19:36:58 +02:00
wm4 d4aaf29a05 ao_wasapi: fix crash on hotplug init error
On init error, the mp_msg macros are actually called. They could cause
a crash because state->log was NULL.
2015-06-17 13:42:31 +02:00
wm4 831d7c3c40 audio: remove S8, U16, U24, U32 formats
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.
2015-06-16 21:11:59 +02:00
wm4 6cc02658fa ao_alsa: if possible, reorder device maps to std layouts
Channel maps reported by the device as SND_CHMAP_TYPE_VAR can be freely
reordered. We don't use this much (out of laziness), but in this case
it's a simple way to reduce necessary reordering (which would be an
extra libavresample invocation), and to make debug output more readable.
2015-06-12 23:15:44 +02:00
wm4 5b269ce696 ao_alsa: make it accept 7.1 over HDMI
SDR/SDL is what lavc outputs for 7.1(rear), while RRC/RLC is what ALSA
uses for some 7.1 layouts, so this makes sense to me.
2015-06-12 23:08:09 +02:00
wm4 478ea1d0f3 ao_alsa: change ALSA braindeath heuristic
If you try to play surround with dmix, it will advertise surround and
lets you set more than 2 channels, but will report a stereo channel map,
with the extra channels identified as NA. We could handle this now, but
we don't want to (because it's excessively stupid).

Do it only if the channel map is not what we requested, instead of just
acting if it contains NA entries at all. This avoids that we hurt
ourselves in the unlikely but possible case we actually have to use
channel maps with NA entries.
2015-06-11 21:42:09 +02:00
wm4 b7d833c2a6 ao_coreaudio: change physical stream format synchronously 2015-06-09 18:26:14 +02:00
wm4 211088943c audio/out/pull: avoid dropping some audio when draining
If the audio API takes a while for starting the audio callback, the
current heuristic can be off. In particular, with very short files, it
can happen that the audio callback is not called before playback is
stopped, so no audio is output at all.

Change draining so that it essentially waits for the ringbuffer to
empty. The assumption is that once the audio API has read the data
via the callback, it will always output it, even if the audio API
is stopped right after the callback has returned.
2015-06-09 18:26:14 +02:00
wm4 a2b1c6d3f6 audio/out/pull: correctly pad partial frames with silence
If a frame could only be partially filled with real audio data, the
silence wasn't written at the correct offset. It could have happened
that the remainder of the frame contained garbage.

(This didn't happen in the more common case of playing dummy silence.)
2015-06-09 18:26:14 +02:00
wm4 8653ed2183 ao_alsa: refine channel count mismatch error message
I suspect we need to hand this more gracefully in some cases.
2015-06-09 18:21:56 +02:00
wm4 b2d058ef00 ao_alsa: refuse to use spdif if AES flags can't be set
Seems like a good idea to avoid accidentally playing noise by writing
spdif data to pure PCM devices.
2015-06-04 21:54:08 +02:00
wm4 c277c17a93 ao_alsa: hack against potential spdif failure 2015-06-04 13:10:33 +02:00
wm4 7556f367d6 ao_coreaudio_exclusive: move generic functions to utils 2015-06-02 22:25:34 +02:00
wm4 7c0d3b9a50 ao_coreaudio_exclusive: react to device removal
Listening to kAudioDevicePropertyDeviceHasChanged does not send any
property change notifications when the device dies. Makes no sense,
but I suppose in CoreAudio logic a dead/removed device can't send
any notifications.

This caused the player to essentially pause playback if the audio
device was removed during playback.

Fix by listening to the kAudioHardwarePropertyDevices property too,
which will actually be sent in this specific case. Then, if
querying the already dead device fails, we know we have to reload.
2015-06-02 22:25:30 +02:00
wm4 87a94a5655 ao_coreaudio_exclusive: make property listeners event-based
In short, instead of letting the coreaudio property listener set atomic
flags (which are then polled), make the property listeners actually
active.

The format change listener used during audio output now simply calls
ao_request_reload() on its own. All code involved is thread-safe, so
there's no need to do it during this audio callback (we assumed the
callback was never run concurrently with itself).

The listener installed temporarily during ca_change_format() is changed
to post a semaphore. Get rid of the weird retry logic and replace it
with a flat loop + timeout. It appears the maximum wait time could be
2500ms; reduce the total timeout to 500ms instead.
2015-06-02 21:04:40 +02:00
wm4 37d505f363 ao: allow ao_uninit(NULL) 2015-06-02 21:03:04 +02:00
wm4 302901ddaf ao_alsa: hack back mono output
The ALSA API is inconsistent and doesn't report support. Just requesting
1 channel actually works. Whatever.
2015-05-25 22:10:35 +02:00
wm4 92b9d75d72 threads: use utility+POSIX functions instead of weird wrappers
There is not much of a reason to have these wrappers around. Use POSIX
standard functions directly, and use a separate utility function to take
care of the timespec calculations. (Course POSIX for using this weird
format for time values.)
2015-05-11 23:44:36 +02:00
wm4 ca9964a4fb ao: make better use of atomics
The main reason for this was compatibility; but some associated problems
have been solved in the previous commit.
2015-05-11 23:27:41 +02:00
wm4 8b7035c8ff ao: log reordered versions of channel maps
Useful for debugging cases when no standard orders are used.
2015-05-08 19:45:16 +02:00
wm4 ad9bce2a5c ao_alsa: log requested numbers of channels if ALSA rejects them 2015-05-08 14:24:20 +02:00
wm4 b91b4944bd audio: define only a single NA speaker ID
Remove the requirement from mp_chmap that speaker entries must be
unique. Use this to get rid of all the redundant NA speaker IDs.
2015-05-07 23:07:14 +02:00
wm4 1bcb82ec93 ao_coreaudio_utils: don't list some formats as "unusable"
While mpv has no internal equivalent representation, they can still be
used as physical CoreAudio formats. Thus this label is confusing.
2015-05-07 20:55:00 +02:00
wm4 cd5ab98ff9 ao_sndio: add notice about padding channels
(I won't do this, but someone else seeing this might.)
2015-05-06 21:48:40 +02:00
wm4 85fc6b2a05 ao_alsa: use new padding channels support
Sometimes, ALSA will return channel layouts with padded channels (NA
speakers). Use them instead of failing.

This still includes the old "braindeath" code to retry with a layout
without NA channels. This might be helpful for performance, and also the
padded channel layout string looks confusing.

To be fair, I have not encountered a case yet which would really need
this, and for which the old "braindeath" code did not fix it.
2015-05-06 21:48:40 +02:00
wm4 d577872a28 ao_alsa: move ALSA -> mp channel map to a function
One side effect is that the warning about too many channels goes away,
and is replaced with printing the ALSA channel map as "unknown".
2015-05-06 21:48:40 +02:00
wm4 0ae0e90eb5 ao_coreaudio_exclusive: check new format before waiting for change
It seems if the format was already set, setting the same format will
not cause a property change.
2015-05-06 21:48:39 +02:00
wm4 4444ff48fa ao_coreaudio_exclusive: use atomics instead of volatile
volatile barely means anything.

The polling is kind of bad too, but relatively harmless as device
opening/closing is a rare event, and the format change is not expected
to take long.

Remove the pointless talloc call too (must have been a leftover
from previous refactoring).
2015-05-06 21:48:36 +02:00
wm4 028739932b ao_coreaudio_exclusive: rename "digital" -> "compressed"
PCM is digital too.
2015-05-06 18:54:53 +02:00
wm4 1e1045b13e ao_coreaudio_exclusive: explicitly check for spdif formats 2015-05-06 18:51:31 +02:00
wm4 32bc61ae07 ao_coreaudio_exclusive: merge init_digital() function
No reason to keep them separate. It's an artifact from the old
ao_coreaudio.c, which kept usage of two different APIs in the same file.
Removes a forward reference too.
2015-05-06 18:46:51 +02:00
wm4 4ffcf2531b ao_coreaudio_utils: decide formats by comparing raw bits
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.
2015-05-05 22:10:33 +02:00
wm4 656703e279 ao_coreaudio: log considered physical formats 2015-05-05 22:09:44 +02:00
wm4 86d65c80e1 ao_coreaudio: restore old physical format if format was changed 2015-05-05 22:09:39 +02:00
wm4 934109a35b ao_coreaudio: move channel mapping code to a separate file
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.
2015-05-05 21:47:19 +02:00
wm4 399267393b ao_coreaudio_utils: don't require talloc for fourcc_repr()
Instead, apply a trick to make the caller allocate enough space on the
stack.
2015-05-05 21:47:04 +02:00
wm4 7a5f5a8adf ao_coreaudio_utils: unbreak default device selection
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.
2015-05-05 21:46:54 +02:00
wm4 bbedceb467 ao_coreaudio_exclusive: fix latency calculation non-sense
Didn't use the properties it was supposed to use.
2015-05-05 21:46:39 +02:00
wm4 fd6809f98a ao_coreaudio_utils: refine format selection
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.
2015-05-05 21:46:17 +02:00
wm4 66f4e7cce4 ao_coreaudio: change physical format before channel negotiation
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.
2015-05-05 21:45:55 +02:00
wm4 8121529a6c ao_coreaudio: add an option for changing the physical format
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.
2015-05-05 01:11:16 +02:00
wm4 305a85cc9a ao_coreaudio_utils: add a format negotiation helper function 2015-05-05 01:11:16 +02:00
wm4 4d8a7e0394 ao_coreaudio: support padded channel layouts
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.
2015-05-05 01:11:16 +02:00
wm4 eead97f103 ao_coreaudio: fix out of bounds access
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.
2015-05-04 23:54:38 +02:00
wm4 382434d45a ao_coreaudio_exclusive: check format explicitly on change notifcation
This should for now be equivalent; it's merely more explicit and will
be required if we add PCM support.

Note that the property listeners actually tell you what property
exactly changed, but resolving the current listener mess would be too
hard. So check for changes manually.
2015-04-29 23:10:45 +02:00
wm4 34a5229b23 ao_coreaudio_utils: log mp format with CoreAudio format description
As a consequence, it also logs whether mpv can a this format at all.
2015-04-29 23:07:36 +02:00
wm4 32b835c03b ao_coreaudio_utils: add function for ASBD -> mp format lookup
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.
2015-04-29 23:06:10 +02:00
wm4 3295ce48ab ao_coreaudio_utils: float is not a signed integer format
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.
2015-04-29 22:39:28 +02:00
wm4 8b4ca58062 ao_coreaudio_exclusive: move code for getting original format
Should be almost equivalent, unless there are streams on which this call
does not work for unknown reasons.
2015-04-28 22:11:43 +02:00