Commit Graph

1308 Commits

Author SHA1 Message Date
Kevin Mitchell d1cbff37be ao_wasapi: remove volume "restore" on exit
It was complicated and not even very intuitive to the user.
If you are controlling the master volume, you just have to be
prepared to deal with the consequences.
2015-12-20 03:30:28 -08:00
Kevin Mitchell aa5f04c7a0 ao_wasapi: split exclusive/shared specific ao controls
this avoids having to check if we're exclusive or
shared for every control
2015-12-20 03:30:28 -08:00
Kevin Mitchell e15526153e ao_wasapi: add E_NOINTERFACE to error list
this is encountered trying to set up COM proxies in wine
2015-12-20 03:30:28 -08:00
wm4 000285ee8e mixer: fix volume initialization with --af=volume
A manually added af_volume could lead to muted audio when switching to a
new file. af_volume keeps the last volume set by AF_CONTROL_SET_VOLUME
to return it with AF_CONTROL_GET_VOLUME, but the initial value is 0. So
the mixer volume was forced to 0 when unintializing the filter chain and
reading back the previously set volume.
2015-12-11 20:52:37 +01:00
wm4 67a4892ee3 mixer: minor simplification
(Why is this code so complex?)
2015-12-11 20:52:37 +01:00
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
wm4 81109dcbb6 ao_coreaudio_chmap: add more logging 2015-10-26 15:51:50 +01:00
wm4 fa510bd00c af: prevent endless loop when removing filters due to spdif
This code removes filters which can not take spdif inout. This was made
so that PCM filters are transparently dropped in spdif mode.

This entered an endless loop with:

   --af=lavcac3enc:::2 --audio-channels=5.1

The forced number of output channels is incompatible with spdif. It's
trying to insert af_lavrresample as conversion filter to compensate for
it. Of course this doesn't work, which triggers the PCM filter removal.
Then it goes on normally - since the new state is exactly as before, it
will try the same thing again, forever.

Fix by reusing the retry counter, which is a very dumb but very
effective measure against these cases of filter negotiation failure. We
could try to be more clever (for example, if the removed filter is a
conversion filter, we can be sure this won't work, and error out
immediately). But better keep it simple and robust.
2015-10-26 15:51:26 +01:00
wm4 c21c26472c ao_alsa: log format probing in verbose mode
And also remove a redundant log message. (We can tell from the following
probe or error message whether or not the format test is successful.)
2015-10-25 20:09:38 +01:00
wm4 96eb480299 ao_coreaudio_exclusive: fix build
"Let's apply cosmetic last minute changes without testing them."
2015-10-21 22:18:41 +02:00
wm4 d93a9be656 ao_coreaudio: do not accept unknown channel layouts
Coreaudio gives us a channel map with all entries set to
kAudioChannelLabel_Unknown. This is translated to a mpv channel map with
all channels set to NA, which has special meaning: it's an "unknown"
channel map, which acts as wildcard and can be converted from/to any
channel layout. Not really what we want.

I've got this with USB audio, playing stereo. The multichannel layout
consisted of 2 unknown channels, while the stereo channel map was
stereo (as expected).

Note that channel maps with _some_ NA entries are not affected by this,
and must still work.
2015-10-21 18:57:03 +02:00
wm4 dda16ee1fb ao_coreaudio_exclusive: deal with devices return different channel count
If the device returns an unexpected number of channels instead of the
requested count on init, don't immediately error out. Instead, look if
there's a channel map with the given number of channels.

If there isn't, still error out, because we don't want to guess the
channel layout.
2015-10-21 18:54:48 +02:00
wm4 78112c8582 ao_coreaudio: avoid unnecessary format changes
Not particularly important; just being nice and potentially avoiding
problems caused by format setting.
2015-10-21 18:54:36 +02:00
wm4 ff778f6d68 ao_coreaudio: log current format before setting new format 2015-10-21 18:53:50 +02:00
wm4 cee9aeaf6b ao_coreaudio: fix some minor memory leaks 2015-10-21 18:53:34 +02:00
wm4 e157d005ba ao_coreaudio: raise timeout for change-physical-format
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.
2015-10-20 00:25:34 +02:00
wm4 e0f8d79772 af_lavrresample: fix unintended audio drift when setting playback speed
Small adjustments to the playback speed use swr_set_compensation()
to stretch the audio as it is required. But since large adjustments
are now handled by actually reinitializing libswresample, the small
adjustments get rounded off completely with typical frame sizes.

Compensate for this by accounting for the rounding error and keeping
track of fractional samples that should have been output to achieve
the correct ratio.

This fixes display sync mode behavior, which requires these adjustments
to be relatively accurate.
2015-10-14 18:51:12 +02:00
wm4 3804376ccc af_lavrresample: reinit resampler on large speed changes
swr/avresample_set_compensation() was made for small speed adjustments.
Non-documentation says it should be used for changes not larger than 1%,
so reinitialize the sampler if the change is larger than that.
2015-10-12 21:12:05 +02:00
wm4 280251656c af_lavrresample: use libswsresample dynamic rate adjustment feature
swr_set_compensation() changes the apparent sample rate on the fly (who
would have guessed). It is thus very well-suited for adjusting audio
speed on the fly during playback (like needed by the display-sync mode).
It skips the relatively slow resampler reinitialization.

If this doesn't work (libswresample soxr backend), then fall back to the
old method.
2015-10-07 21:54:45 +02:00
wm4 0a41c6f0ec audio: make spdif re-probe from normal decoding work
The previous commit handled not falling back to normal decoding if the
AO was reloaded (I think...), and this tries to re-engage spdif pass-
through if it was previously falling back to normal decoding (e.g.
because it temporarily switched to an audio device incapable of
passthrough).
2015-10-06 20:21:29 +02:00
Kevin Mitchell 8f33c65fe0 ao_alsa: add debug messages for format search 2015-10-06 02:24:36 -07:00
Kevin Mitchell beae60bcd5 ao_alsa: fix failure to find any sampleformat
Set format to invalid after each failed test. This way the final check
for valid format will actually fail if no formats work.
2015-10-06 02:24:36 -07:00
wm4 54fbda2ba4 audio: add option for falling back to ao_null
The manpage entry explains this.

(Maybe this option could be always enabled and removed. I don't quite
remember what valid use-cases there are for just disabling audio
entirely, other than that this is also needed for audio decoder init
failure.)
2015-10-05 19:12:23 +02:00
wm4 e694d67366 ao: rework audio output driver probing
Make the code a bit more uniform. Always build a "dummy" audio output
list before probing, which means that opening preferred devices and
pure auto-probing is done with the same code. We can drop the second
ao_init() call.

This also makes the next commit easier, which wants to selectively
fallback to ao_null. This could have been implemented by passing a
different requested audio output list (instead of reading it from
MPOptions), but I think it's better if this rather special feature
is handled internally in the AO code. This also makes sure the AO
code can handle its own options (such as the audio output list) in
a self-contained way.
2015-10-05 19:10:22 +02:00
wm4 ad2ab5893e ao_alsa: improve handling of device disconnection
This can happen with USB audio. There was already code for this, but
something in mpv and ALSA changed - and now the old code is not
necessarily triggered anymore. It probably depends on the exact
situation.
2015-09-28 22:03:14 +02:00
wm4 144571da9b ao_coreaudio_utils: fix error handling in device listing code
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.
2015-09-28 22:03:14 +02:00
wm4 21e5e4da4b audio/filter: remove reentrancy flag
This flag was used by some filters and made sure none of these filters
were inserted twice. This triggers only if the user explicitly tries to
add multiple filters (and not e.g. due to auto-insertion), so at best
this warned the user from doing something potentially pointless. At
worst, it blocked some (mildly) legitimate use-cases. Get rid of it.

Also see #2322.
2015-09-20 14:44:44 +02:00
wm4 4e0e24c3c2 af_lavfi: implement af-metadata property
Works like vf-metadata. Unfortunately requires some code duplication
(even though it's not much).

Fixes #2311.
2015-09-11 23:04:02 +02:00
wm4 f095e86b61 af: use generic statuc codes
The reason MPlayer traditionally duplicated them all over the place is
that it wanted every component to be a self-contained library (e.g.
audio filters were in "libaf"). But this is not necessarily helpful, and
this change makes the following commit a bit simpler.
2015-09-11 23:03:04 +02:00
wm4 e76f503fff ao_lavc: minor simplification 2015-09-11 09:01:49 +02:00
Kevin Mitchell 1557d2d470 ao_alsa: use sample format determination code 2015-09-10 23:58:09 -07:00
Kevin Mitchell 7eacfdcd25 ao_alsa: add double to sample format list 2015-09-10 23:58:09 -07:00
Kevin Mitchell 09c61e0a45 ao_alsa: put spdif formats into find_alsa_format 2015-09-10 23:58:09 -07:00
Kevin Mitchell b7144ad8bf audio/format: revise af_format_conversion_score
* (de)planarize -1
* pad 1 byte -8
* truncate 1 byte -1024
* float -> int 1048576 * (8 - dst_bytes)
* int -> float -512

Now the score is negative if and only if the conversion is lossy
(e.g. previously s24 -> float was given a negative (lossy) score),
However, int->float is still considered bad
(s16->float is worse than than s16->s32).

This penalizes any loss of precision more than performance / bandwidth hits.
For example, previously s24->s16p was considered equal to s24->u8.

Finally, we penalize padding more than (de)planarizing as this will
increase the output size for example with ao_lavc.
2015-09-10 23:58:09 -07:00
wm4 e9822f6012 ao_oss: use new sample format determination code 2015-09-10 23:39:46 +02:00
wm4 e721660e6d ao_lavc: use new sample format determination code
This is just a refactor, which makes it use the previously introduced
function, and allows us to make af_format_conversion_score() private.

(We drop 2 unlikely warning messages too... who cares.)
2015-09-10 23:38:42 +02:00
wm4 60a617df31 audio/format: add function for determining sample conversion candidates 2015-09-10 23:30:51 +02:00
wm4 e45f469280 audio/format: fix interlaved vs. non-interleaved conversions
This mixed up the returned score for some interleaved/non-interleaved
comparisons. Changing interleaving subtracted 1 point, while extending
sample size by 1 byte also subtracted 1 point.

(This scoring system is not ideal - it'd be much cleaner to do a 3-way
sample format comparison instead, and sort the formats according to the
comparison instead of the score.)
2015-09-10 23:29:31 +02:00
wm4 dc04541ba8 audio/format: actually prefer float over double sample format
...for int->float conversions. This code accidentally inverted the
condition.
2015-09-10 23:25:27 +02:00
wm4 af0b903afa af_lavrresample: remove unnecessary indirections
Not sure why struct af_resample_opts even exists. It seems useful to
group the fields set by user options. But storing the current format
conversion parameters doesn't seem very elegant, and having a separate
instance in the "ctx" field isn't helpful either.
2015-09-08 22:21:19 +02:00
wm4 4eae4a5da7 af_lavrresample: add normalize suboption 2015-09-08 22:16:30 +02:00
wm4 23f6f3f50c af_lavrresample: add missing include statement
Apparently, this broke compilation with Libav under some circumstances.
Looking at it again, it shouldn't have, but this change doesn't hurt
anyway.
2015-09-04 22:16:13 +02:00
wm4 d04d2380e3 audio/filter: remove af_bs2b too
Some users still use this filter, so the filter was going to be kept.
But I overlooked that libavfilter provides this filter. Remove the
redundant wrapper from mpv. Something like --af=lavfi=bs2b should work
and give exactly the same results.
2015-09-04 00:23:39 +02:00
wm4 091bfa3abf audio/filter: remove some useless filters
All of these filters are considered not useful anymore by us. Some have
replacements in libavfilter (useable through af_lavfi).

af_center, af_extrastereo, af_karaoke, af_sinesuppress, af_sub,
af_surround, af_sweep: pretty simple and useless filters which probably
nobody ever wants.

af_ladspa: has a replacement in libavfilter.

af_hrtf: the algorithm doesn't work properly on most sources, and the
implementation was buggy and complicated. (The filter was inherited from
MPlayer; but even in mpv times we had to apply fixes that fixed major
issues with added noise.) There is a ladspa filter if you still want to
use it.

af_export: I'm not even sure what this is supposed to do. Possibly it
was meant for GUIs rendering audio visualizations, but it couldn't
really work well. For example, the size of the audio depended on the
samplerate (fixed number of samples only), and it couldn't retrieve the
complete audio, only fragments. If this is really needed for GUIs, mpv
should add native visualization, or a proper API for it.
2015-09-03 23:55:36 +02:00
wm4 cf94fce467 ao_alsa: fix minor memory leak
So snd_device_name_get_hint() return values do in fact have to be freed.

Also, change listing semantics slightly: if io==NULL, skip the entry,
instead of assuming it's an output device.
2015-08-25 15:45:57 +02:00
wm4 dd5c87e1d7 audio: remove unused legacy libavutil header
It was never used, but is a leftover from old times.
2015-08-07 02:41:39 +02:00
wm4 e0c55cbfea audio: remove af_dummy
Was used internally once; has no function anymore.
2015-08-01 21:20:55 +02:00
wm4 41101c2996 win32: revert wchar_t changes
Revert "win32: more wchar_t -> WCHAR replacements"
Revert "win32: replace wchar_t with WCHAR"

Doing a "partial" port of this makes no sense anymore from my
perspective. Revert the changes, as they're confusing without
context, maintenance, and progress. These changes were a bit
premature anyway, and might actually cause other issues
(locale neutrality etc. as it was pointed out).
2015-08-01 21:09:11 +02:00
wm4 fefac2c941 win32: more wchar_t -> WCHAR replacements
This was essentially missing from commit 0b52ac8a.

Since L"..." string literals have the type wchar_t[], we can't use them
for UTF-16 strings. Use C11 u"..." string literals instead. These have
the type char16_t[], but we simply assume char16_t is the same
underlying type as WCHAR. In practice, they're both unsigned short.

For this reason use -std=c11 on Windows. Since Windows is a "special"
environment (we require either MinGW or Cygwin), we don't need to worry
too much about compiler compatibility.
2015-07-30 21:50:11 +02:00
wm4 0b52ac8a78 win32: replace wchar_t with WCHAR
WCHAR is more portable. While at least MinGW, Cygwin, and MSVC actually
use 16 bit wchar_t, Midipix will have 32 bit wchar_t. In that context,
using WCHAR instead is more portable.

This affects only non-MinGW parts, so not all uses of wchar_t need to
be changed. For example, terminal-win.c won't be used on Midipix at
all. (Most of io.c won't either, so the search & replace here is more
than necessary, but also not harmful.)

(Midipix is not useable yet, so this is just preparation.)
2015-07-29 00:01:32 +02:00
shdown 5c8dd832bb audio: fix restoring volume
Was broken by 68bbab0e42, which changed
the number of fields to scan, but not the expected return value.
2015-07-27 15:07:51 +02:00
wm4 253f6f1a95 af_lavrresample: always reinit resampler on filter reinit
This was a minor optimization to potentially avoid resampler
reconfiguration when the filter is reinitialized. But filter
reinitialization is a rare event, and the case when no reconfiguration
is needed is even rarer. As such, this is an unnecessary micro-
optimization and only adds potential for bugs.
2015-07-19 22:54:03 +02:00
wm4 8749900b5f af_lavrresample: don't unnecessarily print remix message
This message bloats verbose log output if e.g. audio speed is frequently
readjusted, such as when syncing audio to video. So don't print the
message if only speed is changed. (This case requires reconfiguration,
but can't change the input/output channel maps.)

Also do not print the message if no remixing is done at all.
2015-07-19 22:50:08 +02:00
wm4 459124f66f af: fix behavior with pathologic filter chains
Some filter chains require a huge number of auto-inserted conversion
filters. There is an overly stupid safeguard against infinite filter
insertions, which counts the number of conversion filters inserted. This
triggered accidentally in this case. Fix by resetting this counter after
a non-conversion filter was successfully configured.
2015-07-07 13:24:11 +02:00
wm4 7c032bde3e ao_coreaudio: fix device latency, share the code
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.)
2015-07-06 17:49:28 +02:00
wm4 e4b963e643 ao_coreaudio_exclusive: continue even if setting physical format fails
Makes it work with (apparently) crappy drivers, which refuse to set the
physical format in some cases.
2015-07-06 00:04:20 +02:00
wm4 a4d5c19355 ao_coreaudio_exclusive: fix some verbose output 2015-07-04 17:25:12 +02:00
wm4 fc79fd0474 ao: don't pass along AO arguments when redirecting
Only causes problems.
2015-07-03 19:28:01 +02:00
wm4 514af9fbd1 ao_coreaudio: add exclusive suboption 2015-07-03 19:28:00 +02:00
wm4 e9e323f35d ao_coreaudio_exclusive: support PCM
Until now, this was for AC3 only. For PCM, we used AudioUnit in
ao_coreaudio, and the only reason ao_coreaudio_exclusive exists
is that there is no other way to passthrough AC3.

PCM support is actually rather simple. The most complicated
issue is that modern OS X versions actually do not support
copying through the data; instead everything must go through
float. So we have to deal with virtual and physical format
being different, which causes some complications.

This possibly also doesn't support some other things correctly.
For one, if the device allows non-interleaved output only, we
will probably fail. (I couldn't test it, so I don't even know
what is required. Supporting it would probably be rather
simple, and we already do it with AudioUnit.)
2015-07-03 19:28:00 +02:00
wm4 65e3657bc4 ao_coraudio: reject all non-PCM formats
Currently this is equivalent. On the other hand, all audio code should
reject formats that is not in a category known to it.
2015-07-03 19:28:00 +02:00
wm4 74e2c8a6ef ao_coreaudio_utils: reduce spam 2015-07-03 19:28:00 +02:00
wm4 ae3e151b27 ao_coreaudio_utils: fix format back-mapping
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.
2015-07-03 19:28:00 +02:00
wm4 d4ab91f016 ao_coreaudio_exclusive: do not set ao->bps
This field is basically deprecated or for convenience only, and
this code doesn't need it.
2015-07-03 19:28:00 +02:00
wm4 597657110f ao_coreaudio_exclusive: dump all latency info in verbose mode 2015-07-03 19:28:00 +02:00
wm4 ec21be498f ao_coreaudio_exclusive: factor format selection 2015-07-03 19:28:00 +02:00
wm4 8a20e5306c ao_coreaudio_exclusive: separate out stream selection 2015-07-03 19:28:00 +02:00
wm4 7faa80ace8 af_lavrresample: log actual channel layout conversions
With all the reordering etc. that can go on in this filter, it's useful
to see what upmix/downmix it's actually performing.
2015-06-30 22:39:57 +02:00
wm4 2f8eabe216 ao_coreaudio: restore physical format if it can't be set exactly
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.
2015-06-30 00:02:12 +02:00
wm4 302aaddc26 ao_coreaudio: support native mono output
We can be pretty sure that AudioUnit will remix for us.

Before this commit, we usually upmixed to stereo, because the
stereo and multichannel layouts were the only whitelisted ones.
2015-06-29 23:55:03 +02:00
wm4 956b8658fb ao_coreaudio: log hotplug events explicitly 2015-06-29 23:54:18 +02:00
wm4 6ffb1e2b66 ao_wasapi: fix regression
This probably fixes the regression introduced with commit 6147bcce.
2015-06-27 17:59:27 +02:00
wm4 0969502316 chmap_sel: add a mechanism for preferred conversions
And use it for the mono case. This is slightly more formal and will make
it easier to add more such cases.
2015-06-27 12:09:30 +02:00
wm4 e0a7e094bc chmap_sel: remove outdated incomplete comment 2015-06-27 11:13:12 +02:00
wm4 6147bcce35 audio: fix format function consistency issues
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".
2015-06-26 23:06:37 +02:00
wm4 d6737c5fab audio: replace format name table
Having a big switch() is simpler.
2015-06-26 23:06:21 +02:00
wm4 efb50cabe6 audio: remove bitmask format definition mess
Audio formats used a semi-clever schema to encode the properties of the
PCM encoding as bitfields into the format integer value.

The af_fmt_change_bits() implementation becomes a bit weird, but it's
an improvement to the rest of the code.

(I've always disliked it, so why not get rid of it.)
2015-06-26 23:05:16 +02:00
wm4 554b4217a0 ao_coreaudio_utils: use a macro
This is actually the last line of code outside of format.c/h which still
tries to fiddle with the format bitfields.
2015-06-26 23:04:44 +02:00
wm4 e4e7fade96 ao_sndio: fix comment
So whoever (nobody?) would want to deal with this broken and obscure AO
for an obscure audio API could add support for some more channel
layouts.
2015-06-26 23:03:37 +02:00
wm4 cd6d846b70 ao_coreaudio: support non-interleaved output
This saves us the trouble of interleaving the audio data for
no reason.
2015-06-26 15:58:11 +02:00
wm4 8134a0601b ao_coreaudio: explicitly skip input streams
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.
2015-06-26 15:56:19 +02:00
wm4 3c61e6eb4e ao_coreaudio_utils: compare full AudioStreamBasicDescription
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.)
2015-06-25 20:17:14 +02:00
wm4 5a3cdb8f1e audio: output human-readable channel layouts too
This gets you the "logical" channel layout, instead of the exact thing
we're sending to the AO. (Tired of the cryptic shit ALSA gives me.)
2015-06-25 19:10:24 +02:00
wm4 fd1194de3c audio: fix channel map fallback selection (again)
The speaker replacement nonsense sometimes made blatantly incorrect
decisions. In this case, it prefered a 7.1(rear) upmix over outputting
5.1(side) as 5.1, which makes no sense at all. This happened because 5.1
and 7.1(rear) appeared equivalent to the final selection, as both of
them lose the sl-sr channels. The old code was too stupid to select the
one with the lower number of channels as well.

Redo this. There's really no reason why there should be a separate final
decision, so move the speaker replacement logic into the
mp_chmap_is_better() function.

Improve some other details. For example, we never should compare the
plain number of channels for deciding upmix/downmix, because due to NA
channels this is essentially meaningless. Remove the NA channels when
doing this comparison. Also, explicitly handle exact matches.
Conceptually this is not necessary, but it avoids that we have to
needlessly shuffle audio data around.
2015-06-25 17:32:00 +02:00
wm4 5d71188c99 ao: standardize channel layout name in debug output further 2015-06-25 13:15:32 +02:00
wm4 62269871aa af: move af_from_dB() function to af_volume.c
And also simplify it (it certainly had the most awkward API you could
think of for such a simple function).
2015-06-23 15:11:23 +02:00
wm4 4c6a600943 af_volume: add a replaygain fallback option 2015-06-23 15:07:19 +02:00
wm4 e7d5a5e688 af_lavrresample: free and reallocate resample context on reconfig
This avoids keeping "bad" state from previous reconfig calls, such as
the internal_sample_format option (which is set only on the first
reconfig call).

There's no advantage to keeping the resample contexts around anyway.
2015-06-22 17:05:42 +02:00
wm4 cd78e0c5bf af_lavrresample: fix comment
mp_format is not a libavresample input format here, and the comment was
more confusing than it helped.
2015-06-22 16:06:40 +02:00
wm4 3d55340c6d af: restore detaching of PCM filters when using spdif
Basically, af_fix_format_conversion() behaves stupid you insert a
conversion filter that won't work, and adding back the conversion test
function is the simplest fix to it.
2015-06-22 16:03:07 +02:00
wm4 17e8815e37 af_lavrresample: don't flush in uninitialized state
libswresample verbosely complains.
2015-06-22 16:03:03 +02:00
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
wm4 be882175d8 demux: merge extradata fields
MPlayer traditionally had completely separate sh_ structs for
audio/video/subs, without a good way to share fields. This meant that
fields shared across all these headers had to be duplicated. This commit
deduplicates essentially the last remaining duplicated fields.
2015-06-21 18:06:14 +02:00
wm4 2b64eee8d5 demux: rename sh_stream.format to sh_stream.codec_tag
Why not. "format" sounds too misleading for the actual importance and
meaning of this field.
2015-06-21 16:56:35 +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 762623cdef af_lavrresample: include osdep/endian.h
The 24 bit conversion code needs the relevant preprocessor symbols.
2015-06-17 13:41:45 +02:00
wm4 b2781c11ed af: remove conversion filter search
This attempted to find a minimal filter graph for a format conversion
involving multiple conversion filters. With the last 2 commits it
becomes dead code - remove it.
2015-06-16 22:49:21 +02:00
wm4 552dc0d564 af_convert24: remove this filter 2015-06-16 22:40:37 +02:00
wm4 5a9f817bfd af_lavrresample: integrate 24 bit (3 bytes per sample) output
Now af_lavrresample can output 24 bit samples directly, by doing the
conversion "inline". Luckily, S32->S24 can be done in-place, so this
isn't too much work. But the output conversion logic (which seems to be
adding up) gets slightly more complicated again.

Normally this is done by af_convert24. But having multiple conversion
filters complicates some aspects of the filter chain. S24 output is the
only thing the code for multiple conversion filters is still needed for,
and getting rid of that is preferable.
2015-06-16 22:38:37 +02:00
wm4 8ee9c170be af_lavrresample: always fill reorder
If the code path for additional output conversion is active,
reorder_planes() is always called, even if the reorder_out array wasn't
filled. This is obviously wrong - always fill this array.
2015-06-16 21:40:29 +02:00