Commit Graph

1203 Commits

Author SHA1 Message Date
wm4 eec844a06e ao: disambiguate default device list entries
If there were many AO drivers without device selection, this added a
"Default" entry for each AO. These entries were not distinguishable, as
the device list feature is meant not to require to display the "raw"
device name in GUIs.

Disambiguate them by adding the driver name. If the AO is the first, the
name will remain just "Default". (The condition checks "num > 1",
because the very first entry is the dummy for AO autoselection.)
2015-11-27 14:42:10 +01:00
wm4 4c111fbcde af_lavrresample: fix build on Libav
Of course, only FFmpeg has av_clipd(), while Libav does not. (Nevermind
that it doesn't do much more than the mpv MPCLAMP() macro. Supposedly,
libavutil can provide optimized platform-specific versions for av_clip*,
but of course nothing actually does for av_clipf() or av_clipd().)
2015-11-26 00:25:28 +01:00
wm4 0425741754 af_lavrresample: clamp float output to range
libswresample doesn't do it - although it should, but the patch is stuck
in limbo.

Probably reduces problems with artifacts on downmixing in some cases.
2015-11-25 22:07:18 +01:00
wm4 06df54a111 ao_alsa: filter audio device list
Remove known useless device entries from the --audio-device list (and
corresponding property). Do this because the list is supposed to be a
high level list of devices the user can select. ALSA does not provide
such a list (in an useable manner), and ao_alsa.c is still in the best
position to improve the situation somewhat.
2015-11-24 19:47:58 +01:00
wm4 ef918b239e ao_alsa: list bidirectional devices too
The ALSA doxygen says:

    IOID - input / output identification ("Input" or "Output"), NULL
    means both

This bug was blatantly introduced with commit cf94fce4.
2015-11-24 19:21:41 +01:00
Kevin Mitchell 00b7fb3023 ao_wasapi: get rid of Vistablob hack
This was required to work around XP linking issues and is no longer
required.
2015-11-24 04:42:37 -08:00
Kevin Mitchell e10727baa7 ao_wasapi: only report per-app volume in shared mode
otherwise we were incorrectly adjusting the hardware master volume
in exclusive mode with softvol=auto
2015-11-19 07:14:50 -08:00
wm4 7e285a6f71 ao_wasapi: work around DTS passthrough failure
Apparently, some audio drivers do not support the DTS subtype, but
passthrough works anyway if the AC3 subtype is set. Just retry with
AC3 if the proper format doesn't work. The audio device which
exposed this behavior reported itself as
"M601d-A3/A3R (Intel(R) Display Audio)".

xbmc/kodi even always passes DTS as AC3.
2015-11-19 00:08:07 +01:00
Kevin Mitchell 9f858cc759 ao_openal: fix sign of speaker angle in comment 2015-11-18 08:27:47 -08:00
Justas Lavišius ca77bcd543 ao_openal: fix virtual speaker positioning
Place speakers in standard positions equidistant from the listener.

use standard coordinate system
2015-11-18 08:26:07 -08:00
Kevin Mitchell 0e0f07bbef ao_openal: accommodate more sample formats
Try and and choose the closest sample format to the one requested.

fixes #2494
2015-11-17 01:54:38 -08:00
Kevin Mitchell c7a39b8521 ao_openal: move uninit before init
the next commit will use uninit within init
2015-11-17 01:32:48 -08:00
wm4 9774be0d15 af_lavrresample: simplify set_compensation usage
Just set the ratio directly by working around the intended semantics of
the API function. The silly rounding stuff we had isn't needed anymore
(and not entirely correct anyway).

Note that since the compensation is virtually active forever, we need to
reset if it's not needed. So always run this code to be sure to reset
it.

Also note that libswresample itself had a precision issue, until it
was fixed in FFmpeg commit 351e625d.
2015-11-11 19:28:37 +01:00
wm4 ac64ce71d6 dec_audio: add missing include
Was masked by FFmpeg's terrible headers, but failed with Libav.
2015-11-08 20:01:20 +01:00
wm4 0ff3ffb2be audio: interpolate audio timestamps
Deal with jittering Matroska crap timestamps. This reuses the mechanism
that is needed for frames without PTS, and adds a heuristic to it. If
the interpolated timestamp is less than 1ms away from the real one, it
might be due to Matroska timestamp rounding (or other file formats with
such rounding, or files remuxed from Matroska).

While there actually isn't much of a need to do this (audio PTS
jittering by such a low amount doesn't negatively influence much), it
helps with identifying jitter from other sources.
2015-11-08 18:06:24 +01:00
wm4 d91434756b audio: move PTS setting out of the decoder
Instead of requiring the decoder to set the PTS directly on the
dec_audio context (including handling absence of PTS etc.), transfer the
packet PTS to the decoded audio frame. Marginally simpler, and gives
more control to the generic code.
2015-11-08 17:22:56 +01:00
wm4 2dc18a2f82 chmap: remove MPlayer layouts
Unused; last uses removed with the previous two commits.
2015-11-07 15:22:30 +01:00
wm4 a7f51f8fd4 ao_jack: remove "alsa" std-channel-layout choice
Same deal as with previous commit. "waveext" is less arbitrary and at
least supports 3/7 channels.
2015-11-07 15:20:34 +01:00
wm4 5a7c22a1ac ao_alsa: remove the last bits of legacy channel map fallback
Essentially we'd use something random, just because it's part of the srt
of traditionally used ALSA channel mappings. But each driver can do its
own things.

This doesn't let me sleep at night, so remove it.
2015-11-07 15:18:05 +01:00
wm4 617aff6cda audio: fix af_fmt_change_bytes() with spdif formats
This could accidentally change some spdif formats to AAC (because AAC is
the first on the list and will match first). spdif formats are
inherently uninterchangeable, so treat them as their own class of
formats (like int vs. float).

Might fix some issues with ao_wasapi.c.
2015-11-07 15:07:50 +01:00
wm4 3108a3a001 audio: do not require full audio chain reinit for speed changes
Actually, it didn't really require that before (most work was avoided),
but some bits had to be run anyway. Separate the speed change into a
light-weight function, which merely updates already created filters, and
a heavy-weight one which messes with filter insertion.

This also happens to fix the case where the filters would "forget" the
current speed (force resampling, change speed, hit a volume control to
force af_volume insertion - it will reset speed and desync).

Since we now always run the light-weight function, remove the
af_scaletempo verbose message that is printed on speed setting. Other
than that, all setters are cheap.
2015-11-04 21:49:54 +01:00
wm4 e3db686e87 af_lavcac3enc: simplify/fix AVPacket handling
For some reason, the encoder didn't like that the AVPacket already had
fields set. I'm not quite sure, but this might just be invalid API
usage. Do it as it's recommended.
2015-11-04 21:49:54 +01:00
wm4 be49da72ea ao_alsa: fix 7.1 over HDMI
We need to effectively swap the last channel pair. See commit 4e358a96
and 5a18c5ea for details.

Doing this seems rather strange, as 7.1 just extends 5.1 with 2 new
speakers, and 5.1 doesn't need this change. Going by the HDMI standard
and the Intel HDA sources (cited in the referenced commits), it also
looks like 7.1 should simply append two channels to 5.1 as well. But
swapping them is apparently correct. This is also what XBMC does. (I
didn't find any other applications doing 7.1 PCM using the ALSA channel
map API. VLC seems to ignore the 7.1 case.) Testing reveals that at
least the end result is correct.

"Normal" ALSA 7.1 is unaffected by this, as it reports a different
(and saner) channel layout.
2015-11-04 21:48:37 +01:00
wm4 46f59f25c2 ao_alsa: map mp_chmaps back to ALSA in a different way
Instead of constructing an ALSA channel map from mpv ones from scratch,
try to find the original ALSA channel map again. Th result is that we
need to convert channel maps only in one direction. If we need to map
a mp_chmap to ALSA, we fetch the device's channel map list, convert
each entry to mp_chmap, and find the first one which fits.

This seems helpful for the following commit. For now, this only gets rid
of mapping back the trivial MONO mapping, which alone would still be
acceptable, but with other channel layout mogrifications it gets messy
fast. While we need to do something awkward to keep our channel map
reordering for VAR chmaps (which basically gives nicer output and
possibly slightly better performance), this is still the better
solution.
2015-11-04 21:48:37 +01:00
wm4 0ca8b290a4 ao_alsa: print more chmap info at debug verbosity 2015-11-04 21:48:37 +01:00
wm4 5a18c5ea91 Revert "af_lavrresample: don't drop sl/sr channels for 7.1 on ALSA"
This reverts commit 4e358a9636.

Testing shows the channel pairs must indeed be swapped (details see
commit message of the reverted commit). Making the downmix code move
sl/sr to sdl/sdr is not an appropriate solution anymore, and it's
better to fix the unusual channel layout in ao_alsa.c directly.

(Not reverting the change in chmap.c; this is still correct.)
2015-11-04 21:48:37 +01:00
wm4 4e358a9636 af_lavrresample: don't drop sl/sr channels for 7.1 on ALSA
ao_alsa: attempt to fix 7.1 over HDMI

The last 2 channels of 7.1 (RLC/RRC in ALSA) were exported as sdl/sdr
instead of sl/sr (I don't even know why I chose sdl/sdr, but SL/SR
and RLC/RRC are different in the ALSA API). libsw/avresample do not
move the sl/sr channels to sdl/sdr when rematrixing, so silence was
sent for 2 channels. If my selection of sdl/sdr is essentially API
abuse, there's no reason why they should do this differently.

The mess here is really that ALSa doesn't map the HDMI layouts cleanly.
Most ALSA drivers export 7.1 in a way compatible to our expectations,
but Intel HDA/HDMI does not:

mpv/ffmpeg:   fl-fr-fc-lfe-bl-br-sl-sr
ALSA/generic: FL FR FC LFE RL RR SL  SR  [1]
ALSA/HDMI:    FL FR LFE FC RL RR RLC RRC [2]

The HDMI layout is layout 0x13 (going by CEA-861-B). The comment in
the kernel code has to be correct too. The early standard defines only
1 other layout, which replaces RLC/RRC with FRC/FLC - this probably
corresponds to what we call "7.1(wide)".

So it appears when ALSA requests RLC/RRC, we should feed it sl/sr.

To make it more complicated, Kodi/xbmc apparently also have to deal with
ALSA being special, but instead of sending sl/sr to RLC/RRC, they swap
the last two pairs of the layout, and send sl/sr to RL/RR and bl/br to
RLC/RRC. Or I might have misunderstood their code. I don't have a
7.1-capable A/V receiver, so I can't test this.

For now, go with the simpler solution, and wait until someone tests it.
If the speakers end up swapped, a completely different solution will be
needed.

[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/sound/core/pcm_lib.c?id=refs/tags/v4.3#n2434
[2] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/sound/pci/hda/patch_hdmi.c?id=refs/tags/v4.3#n307
2015-11-03 00:28:00 +01:00
wm4 9d4aff8ac7 ao_alsa: minor cleanups 2015-11-03 00:23:28 +01:00
wm4 e162a5bf04 ao_alsa: simplify dmix non-NA hack
There's really no need to do this deep in the chmap sslection code. This
will setup the device further than before, but that doesn't matter.
2015-11-03 00:23:28 +01:00
wm4 8d415b2e01 ao_alsa: move channel map setting code out of main init function
This grew way too large.
2015-11-03 00:23:28 +01:00
wm4 d634394da6 ao_alsa: make failure of buffer parameter setting non-fatal
These calls actually can leave the ALSA configuration space empty (how
very useful), which is why snd_pcm_hw_params() can fail. An earlier
change intended to make this non-fatal, but it didn't work for this
reason.

Backup the old parameters, so we can retry with the non-empty
configuration space. (It has to be non-empty, because the previous
setters didn't fail.)

Note that the buffer settings are not very important to us. They're
a leftover from MPlayer, which needed to write enough data to the
audio device to not underrun while decoding and displaying a video
frame. In mpv, most of these things happen asynchronously, _and_
there is a dedicated thread just for feeding the audio device, so
we should be pretty imune even against extreme buffer settings. But
I suppose it's still useful to prevent PulseAudio from making the
buffer too large, so still keep this code.
2015-11-03 00:23:28 +01:00
wm4 609de236a9 ao_alsa: disable resampling first thing
Again, this could have bad access, is unlikely, and has no bad
consequences. It's noteworthy that vlc and the ALSA PCM example both do
this first, even if they set the sample rate later.
2015-11-03 00:23:28 +01:00
wm4 3f0d831af0 ao_alsa: set access type before format
I'm worried that not restricting the access type before restricting the
format will cause problems. While it's unlikely, it might prevent
failures in some corner cases. Also, since we by default always use
interleaved access (buggy ALSA plugins), this will have no effects at
all.
2015-11-03 00:23:28 +01:00
wm4 587bb5e811 ao_alsa: handle channel count mismatch safeguard after chmap negotiation
If the API doesn't list padded channel maps, but the final device
channel map is padded, and if unpadded output is not possible (unlike in
the somewhat similar dmix case), then we shouldn't apply the channel
count mismatch fallback in the beginning. Do it after channel map
negotiation instead.
2015-11-03 00:23:28 +01:00
wm4 c2220c526d ao_alsa: apply non-NA fallback only if input is stereo
Doesn't matter much; effectively this prevents just log spam in some
cases where the map is legitimately padded. Normally this is really
only needed for the dmix ALSA case. (See git blame for details.)
2015-11-03 00:23:28 +01:00
wm4 b58e4abc01 ao_alsa: treat SND_CHMAP_UNKNOWN as NA channel too
Apparently required by nVidia HDMI. It should not be, and NA would
definitely be more correct here, so this could be considered a driver
bug. Maybe.
2015-11-03 00:23:28 +01:00
wm4 3fb161ecd2 ao_alsa: remove log message on pausing
This was annoying.
2015-11-03 00:23:27 +01:00
wm4 3c081dfd93 Replace deprecated av_free_packet() calls
av_free_packet() got finally deprecated. Use av_packet_unref() instead,
which has almost the same semantics, has existed for a while, and is
available in all FFmpeg and Libav versions we support.
2015-10-28 23:48:56 +01:00
wm4 aaec2aba38 player: add audio drop/duplicate mode
Not very robust in the moment.
2015-10-27 20:56:46 +01:00
wm4 919707efb7 ao_coreaudio_exclusive: check for maximum channel count
Until recently, the channel layout code happened to catch this, but now
an explicit check is needed. Otherwise, it'd try to pad the missing
channels with NA in the channel map fallback code.
2015-10-26 16:00:24 +01:00
wm4 0cc440f291 ao_coreaudio_exclusive: fallback to stereo on unknown channel layouts
This is intended for the case when CoreAudio returns only unknown
channel layouts, or no channel layout matches the number of channels the
CoreAudio device forces. Assume that outputting stereo or mono to the
first channels is safe, and that it's better than outputting nothing.

It's notable that XBMC/kodi falls back to a static channel layout in
this case. For some messed up reason, the layout it uses happens to
match with the channel order in ALSA's/mpv's "7.1(alsa)" layout.
2015-10-26 15:55:11 +01:00
wm4 0524907c18 ao_coreaudio_chmap: minor refactor
Share some code between ca_init_chmap() and ca_get_active_chmap(), which
also makes it look slightly nicer. No functional changes, other than the
additional log message.
2015-10-26 15:55:01 +01:00
wm4 c971fefd41 ao_coreaudio_chmap: allow stereo as fallback; avoid mono fallback
If no channel layouts were determined (which can actually happen with
some "strange" devices), the selection code was falling back to mono,
because mono is always added as a fallback. This doesn't seem quite
right.

Allow a fallback to stereo too, if no channel layout could be retrieved
at all. So we always assume that mono and stereo work, if no other
layouts are available.

(I still don't know what the CoreAudio stereo layout is supposed to do.
It could be used to swap left and right channels. It could also be used
to pad/move the channels, but I have never seen that. And it can be set
to non-stereo channels, which breaks mpv. Whatever.)
2015-10-26 15:54:45 +01:00
wm4 9ed289ef90 ao_coreaudio: fix another minor memory leak
How stupid, even the cleanup gotos were already there.
2015-10-26 15:54:36 +01:00
wm4 f3a003e550 audio: bump maximum number of channels to 16
The main reason is that ao_coreaudio_exclusive needs this for some OSX
devices. They want packed audio, and special-casing this in the
coreaudio code would be too much of a pain.

The maximum of channels we can support is 64 (because FFmpeg uses 64 bit
masks for channel layouts), but since struct mp_audio can get pretty
big (has static allocations of 2 pointers for each channel for planar
mode), it's less wasteful to stay lower for now.
2015-10-26 15:54:19 +01:00
wm4 48c2e9d67d audio: use AVFrames with more than 8 channels correctly
Requires messy dealing with the extended_ fields.

Don't bother with af_lavfi and ao_lavc for now. There are probably no
valid use-cases for these.
2015-10-26 15:54:00 +01:00
wm4 0ffaf653a2 af_lavrresample: make planarization pass work with >8 channels
av_get_default_channel_layout() fails with channel counts larger than 8.
The channel layout doesn't need to make sense, so pick an arbitrary
fallback.

libswresample also has options for setting the channel counts directly,
but better not introduce new concepts in the code. Also, libavresample
doesn't have these options.
2015-10-26 15:53:47 +01:00
wm4 76d1b430b0 audio: improve mp_chmap_to_lavc_unchecked() unknown chmap behavior
Change it so that it will always return a bitmask with the correct
number of channels set if an unknown channel map is passed. This didn't
work for channel counts larger than 8, as there are not any standard
channel layouts defined with more than 8 channels (both in mpv and
FFmpeg). Instead, it returned 0.

This will help when raising the maximum allowed channel count in mpv.
Some code in af_lavrresample relies on it, more or less.

One change is that unknown channel maps won't result in lavc standard
channel layouts anymore, just a set of random speakers. This should be
fine, as the caller of mp_chmap_to_lavc_unchecked() should handle these
cases. For mp_chmap_reorder_to_lavc() this is not so clear anymore, but
should also be ok.

For normal channel maps, simply dropping NA channels is still the
correct and wanted behavior.

Currently, the mpv maximum channel count is 8. This commit is
preparation for raising this limit.
2015-10-26 15:52:21 +01:00
wm4 ec27d573f4 audio: always log channel maps before determining final map
Until now, this was done only in debug verbosity, while some AOs logged
equivalent information in verbose mode. Clean this up.
2015-10-26 15:52:08 +01:00
wm4 72d3c5ef00 ao_coreaudio: fix potential UB in error cases
mNumberChannelDescriptions being 0 is pretty much an error, but if it
can happen, then the code checking the chmap below will trigger UB, as
chmap is not initialized at all.

Also, simplify the code a little: we never change the number of
channels, so this is just fine.
2015-10-26 15:51:59 +01:00