Commit Graph

888 Commits

Author SHA1 Message Date
wm4 c0077ac936 ao_alsa: reinitialize if device got broken
Apparently, physically disconnecting the audio device (consider USB
audio) breaks the ALSA device handle forever. It will signal ENODEV.
Fortunately, it's easy for us to handle this, and we can just use
existing mechanisms that will make the playback core close and reopen
the AO. Whether the immediate reopening will actually succeeds really is
ALSA's problem, though.
2015-01-21 19:38:18 +01:00
wm4 1e6b4d31aa ao_coreaudio: reset possibly random errno value
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.)
2015-01-20 14:32:01 +01:00
wm4 d44b4ccba1 ao: never autoselect ao_null
Before this commit, ao_null was used as last fallback. This doesn't make
too much sense. Why would you decode audio just to discard it? Let audio
initialization fail instead. This also handles the weird but possible
corner-case that ao_null might fail initializing, in which case e.g.
ao_pcm could be autoselected. (This happened once, and had to be fixed
manually.)
2015-01-20 14:28:34 +01:00
wm4 3c2ca0cecc ao: refactor --audio-device selection code
This removes the slightly duplicated code for picking the required AO
driver if --audio-device forces one. Now --audio-device reuses the same
code as --ao for this.

As a consequence, ao_alloc_pb() and ao_create() can be merged into
ao_init(). Although the ao_init() argument list, which is already pretty
big, grows by one, it's better than having all these similar sounding
functions around.

Actually, I just wanted to do the change the following commit will do,
but I found this code was more of a mess than it had to be.
2015-01-20 14:25:47 +01:00
wm4 ae641d200a af: remove old filter compatibility hack 2015-01-15 20:13:15 +01:00
wm4 388cf6dc96 audio/filter: switch remaining filters to refcounting
All of these filters are very similar in frame management, and copy data
to a new frame during filtering.
2015-01-15 20:13:14 +01:00
wm4 87fe7d8788 audio/filter: switch remaining in-place filters to refcounting
Adds about 7 lines of boilerplate per filter. This could be avoided by
providing a different entrypoint (something like af->filter_inplace),
which would basically mirror the old interface exactly for this kind of
filter. But I feel like it would just be a hack to support all those
old, useless filters better. (The ideal solution would be using a
language that can do closures to provide a compat. wrapper, but
whatever.)

af_bs2b has terribly repetitious code for setting up filter functions
for each format (most of them useless, in addition to bs2b being
useless), so I did something terrible with macros.

af_sinesuppress had commented code for float filtering (maybe it was
broken; it has been commented every since it was added in 2006). Remove
this code.
2015-01-15 20:13:12 +01:00
wm4 ba0e8b754c af: verify filter input formats
Just to make sure all filters get the correct format. Together wih the
check in af_add_output_frame(), this asserts that

    af->prev->fmt_out == af->fmt_in

This also requires setting the "in" pseudo-filter (s->first) formats
correctly. Before this commit, the fmt_in/fmt_out fields weren't used
for this filter.
2015-01-15 20:10:46 +01:00
wm4 c757a06845 ao_alsa: fix a small memory leak 2015-01-14 22:16:36 +01:00
wm4 e865d255d0 af_lavcac3enc: use refcounted frames 2015-01-14 22:16:30 +01:00
wm4 5d972491bb af_lavfi: use refcounted frames 2015-01-14 22:15:56 +01:00
wm4 9c974b2a1b audio/filter: actually set fmt_in/fmt_out fields 2015-01-14 22:15:51 +01:00
wm4 f6a0a1554c af_scaletempo: use refcounted frames 2015-01-14 22:15:39 +01:00
wm4 218c749a16 af_lavrresample: use refcounted frames 2015-01-14 22:15:31 +01:00
wm4 7b8862760d audio: add missing declaration 2015-01-14 22:15:00 +01:00
wm4 c8ecb66269 ao_pcm: add append mode
Pretty useful for debugging, although a bit useless or possibly
misleading too (see comments in the manpage).
2015-01-14 22:14:56 +01:00
wm4 4cabd08e8a audio: fix initial audio PTS
Commit 5e25a3d2 broke handling of the initial frame (the one decoded
with initial_audio_decode()). It didn't update the pts_offset field,
leading to a shift in timestamps by one audio frame.

Fix by calling the actual decode function in a single place. This
requires slightly more changes than what would be necessary to fix the
bug, but it also somewhat simplifies the data flow.
2015-01-14 22:14:46 +01:00
wm4 3cb2add636 audio: fix assertion failure on audio decoding
There are several cases in which a decoder may need several packets to
produce some output audio. Commit 5e25a3d2 broke this.

Fixes #1471.
2015-01-14 07:58:01 +01:00
wm4 ecca64e182 af_convert24: use refcounted frames
This requires allocating a fully new frame. 32->24 could be in-place,
but this is not possible for 24->32.
2015-01-13 20:17:08 +01:00
wm4 983f5efa3c audio/filters: use refcounted frames for some in-place filters
These are also quite simple, but require requesting write access to the
frames. The error handling (for OOM) is a bit annoying.
2015-01-13 20:17:03 +01:00
wm4 1fde40732e audio/filters: use refcounted frames for some simple filters
These are read-only, and very trivial to convert.
2015-01-13 20:16:59 +01:00
wm4 772c42a95c af_volume: use refcounted frames 2015-01-13 20:15:53 +01:00
wm4 5e25a3d216 audio: use refcounted frames in the filter chain
The goal is switching the whole audio chain to using refcounted frames.
This brings the architecture closer to FFmpeg, enables better
integration with libavfilter, will reduce useless copying somewhat, and
will probably allow better timestamp tracking.

For now, every filter goes through a semi-awful wrapper in
af_do_filter(), though. This will be fixed step by step, and the wrapper
should eventually be removed. Another thing that will have to be done is
improving the timestamp handling and avoiding extra copies for the AO.

Some of the new code is rather similar to the video filter code (the
core filter code basically just has types replaced). Such code
duplication is normally very unwanted, but in this case there's probably
no other choice. On the other hand, this code is pretty simple (even if
somewhat tricky). Maybe there will be unified filter code in the future,
but this is still far away.
2015-01-13 20:15:43 +01:00
wm4 97becbc31b audio: add some utility functions for refcounted frames
Used in the following commits.
2015-01-13 20:14:25 +01:00
wm4 0bbd65b09c audio/filter: remove unused af_calc_filter_multiplier()
The purpose of this function was to filter only as much audio input as
needed to produce a certain amount of audio output. This could (in
theory) avoid excessive buffering when e.g. changing playback speed with
resampling.

Use of this was already removed in commit 5fd8a1e0. No problems were
experienced, so let's assume this feature is practically worthless.
(Though it's possible that it was quite useful over a decade ago, or in
some cornercases with evil files.)
2015-01-13 20:14:02 +01:00
wm4 2c9180f47b ao_pulse: exit AO if stream fails
This can for example reproduced by killing the pulseaudio server. If
this happens, just try to reload the AO, instead of breaking everything
forever.
2015-01-11 04:19:40 +01:00
wm4 7f2b78846b ao_alsa: fix dtshd passthrough
We must not try to remap channels with this. Whethever ALSA gives us,
and whatever we do with it, the result will probably be nonsense.

Untested, as I don't have the required hardware.
2015-01-09 03:58:47 +01:00
wm4 5a7719594e ao: remove coreaudio_exclusive from autoprobing list
Apparently this was a mistake.
2015-01-07 22:31:34 +01:00
wm4 dc2d0539c7 ao_pulse: disable latency calculation hacks by default
This used to be required to workaround PulseAudio bugs. Even later, when
the bugs were (partially?) fixed in PulseAudio, I had the feeling the
hacks gave better behavior. On the other hand, I couldn't actually
reproduce any bad behavior without the hacks lately. On top of this, it
seems our hacks sometimes perform much worse than PulseAudio's native
implementation (see #1430).

So disable the hacks by default, but still leave the code and the option
in case it still helps somewhere. Also, being able to blame PulseAudio's
code by using its native API is much easier than trying to debug our own
(mplayer2-derived) hacks.
2015-01-07 22:23:38 +01:00
wm4 f61b8b312d win32: request UTF-16 API variants, Vista+ APIs, and COM C macros
Put the Vista+ (_WIN32_WINNT) and the COM C (COBJMACROS) defines into
the build system, instead of defining them over and over in the code.
2015-01-07 21:42:44 +01:00
wm4 0f4bf347c5 player: print used number of threads in verbose mode
Also, don't use av_log() for mpv output.
2015-01-05 12:17:55 +01:00
wm4 fda44ecc92 af_volume: dump applied replaygain in verbose mode 2015-01-04 01:35:48 +01:00
Kevin Mitchell 6a6620a554 ao/wasapi: style/code formatting tweaks 2015-01-02 14:50:59 -08:00
Kevin Mitchell 155c8e20ef ao/wasapi: improve exclusive mode format search
fixes #1376
2015-01-02 14:08:47 -08:00
Kevin Mitchell 81948634ca ao/wasapi: revamp set_waveformatex
* bits instead of bytes
* add valid_bits argument
* just pass in the mp_chmap and get the number and wavext channel map from that
* indicate valid bits in waveformat_to_str
* make appropriate accomodations in try_format
2015-01-02 14:08:47 -08:00
Kevin Mitchell 121352cd95 ao/wasapi: add CO_E_NOTINITIALIZED to explain_err
someone on irc reported seeing this error
2015-01-02 14:08:47 -08:00
wm4 4075518011 ao_portaudio: remove this audio output
It's just completely useless. We have good native support for all 3
desktop platforms, and ao_sdl or ao_openal as fallbacks.
2014-12-29 18:53:12 +01:00
wm4 adeada149b ao_alsa: print channel map if setting it fails
This message is printed when the audio device advertised a channel map,
but couldn't set it - which is probably a dmix bug (we'll never know,
ALSA doesn't take bug reports).

Print the requested map, so that the user (maybe) can make a connection
when seeing the message and the actually used channel map, which might
be less confusing. Or at least less useless.
2014-12-29 18:49:11 +01:00
Stefano Pigozzi 21d93690cb ao: add debug log with the detected channel maps
This could be helpful with bug reports.
2014-12-29 17:56:53 +01:00
Stefano Pigozzi 54aea7d5de chmap_sel: add multichannel fallback heuristic
Instead of just failing during channel map selection, try to select a close
layout that makes most sense and upmix/downmix to that instead of failing AO
initialization. The heuristic is rather simple, and uses the following steps:

1) If mono is required always prefer stereo to a multichannel upmix.
2) Search for an upmix that is an exact superset of the required channel map.
3) Search for a downmix that is the exact subset of the required channel map.
4) Search for either an upmix or downmix that is the closest (minimum difference
   of channels) to the required channel map.
2014-12-29 17:56:53 +01:00
Stefano Pigozzi 461ba50ed6 chmap: add a 7.1(rear) layout name
This is common on Apple systems so it's handy to have a label for it.
2014-12-29 17:56:53 +01:00
Stefano Pigozzi 894b172a76 ao_coreaudio: remove useless guard
useless after 069016fd6c
2014-12-27 12:33:44 +01:00
Stefano Pigozzi 15e30e58b2 ao_coreaudio: fix some naming conventions 2014-12-27 12:33:44 +01:00
Stefano Pigozzi 069016fd6c ao_coreaudio: fix channel mapping
There where 3 major errors in the previous code:

1) The kAudioDevicePropertyPreferredChannelLayout selector returns a single
   layout not an array.
2) The check for AudioChannelLayout allocation size was wrong (didn't account
   for variable sized struct).
3) Didn't query the kAudioDevicePropertyPreferredChannelsForStereo selector
   since I didn't know about it's existence.

All of these are fixed.

Might help with #1367
2014-12-27 12:04:58 +01:00
Stefano Pigozzi 9aa7df3446 ao_coreaudio: fix typo 2014-12-27 00:29:21 +01:00
Stefano Pigozzi 4d99315730 ao_coreaudio: move some code to make output readable 2014-12-27 00:27:50 +01:00
Stefano Pigozzi 1391e765a2 ao_coreaudio: add more layout debug outputs
Should help remote debugging #1367 with --msg-level=ao=debug
2014-12-27 00:16:48 +01:00
wm4 3fdb6be316 win32: add mmap() emulation
Makes all of overlay_add work on windows/mingw.

Since we now don't explicitly check for mmap() anymore (it's always
present), this also requires us to make af_export.c compile, but I
haven't tested it.
2014-12-26 17:30:10 +01:00
Stefano Pigozzi 9317071bc3 ao_coreaudio: fix AudioChannelLayout allocations
AudioChannelLayout uses a trailing variable sized array so we need to
query CoreAudio for the size of the struct it is going to need (or the
conversion of that particular layout would fail).

Fixes #1366
2014-12-26 15:04:36 +01:00
wm4 759656d0ba ao_alsa: fix unpause path atfer previous commit
The resume code was accidentally fully removed from this code path.
2014-12-23 13:20:32 +01:00