audio/out: consistently use double return type for get_delay

ao_get_delay() returns double, but the get_delay callback still
returned float.
atomics: add atomic_compare_exchange_strong()

As usual, we use C11 semantics, and emulate it if <stdatomic.h> is not
available.

It's a bit messy with __sync_val_compare_and_swap(). We assume it has
"strong" semantics (it can't fail sporadically), but I'm not sure if
this is really the case. On the other hand, weak semantics don't seem to
be possible, since the builtin can't distinguish between the two failure
cases that could occur. Also, to match the C11 interface, use of gcc
builtins is unavoidable. Add a check to the build system to make sure
the compiler supports them (although I don't think there's any compiler
which supports __sync_*, but not these extensions).

Needed for the following commit.
audio/out/pull: avoid deadlock if audio callback stops

If the audio callback suddenly stops, and the AO provides no "reset"
callback, then reset() could deadlock by waiting on the audio callback
forever.

The waiting was needed to enter a consistent state, where the audio
callback guarantees it won't access the ringbuffer. This in turn is
needed because mp_ring_reset() is not concurrency-safe.

This active waiting is unavoidable. But the way it was implemented, the
audio callback had to call ao_read_data() at least once when reset() is
called. Fix this by making ao_read_data() set a flag upon entering and
leaving, which basically turns p->state into some sort of spinlock.

The audio callback actually never needs to spin, because there are only
2 states: playing audio, or playing silence. This might be a bit
surprising, because usually atomic_compare_exchange_strong() requires a
retry-loop idiom for correct operation.

This commit is needed because ao_wasapi can (or will in the future)
randomly stop the audio callback in certain corner cases. Then the
player would hang forever in reset().
command: send property-change event on playlist change
audio: use AVBufferRef to allocate audio frames

A first step towards refcounted audio frames.

Amazingly, the API just does what we want, and the code becomes
simpler. We will need to NIH allocation from a pool, though.
dvd, bluray: reload demuxer on title changes

Causes the player to reload the demuxer and to relist the found
streams. Probably slightly dangerous/broken, because the demuxer
thread and possibly even the decoders will keep reading data from
the new title before the new demuxer takes over.

Fixes #1250.
player: don't try to use duration 0
audio: add mp_audio_pool

A helper to allocate refcounted audio frames from a pool. This will
replace the static buffer many audio filters use (af->data), because
such static buffers are incompatible with refcounting.
audio: add function to convert AVFrame to mp_audio references

This is somewhat duplicated from ad_lavc.c and af_lavfi.c, but will
eventually be used by both.
af_format: remove redundant message prefixes
audio: change how filters are inserted on playback speed changes

Use a pseudo-filter when changing speed with resampling, instead of
somehow changing a samplerate somewhere. This uses the same underlying
mechanism, but is a bit more structured and cleaner. It also makes some
of the following changes easier.

Since we now always use filters to change audio speed, move most of the
work set_playback_speed() does to recreate_audio_filters().
audio: clear buffer array too with mp_audio_set_null_data()
audio: add mp_audio_make_writeable()
audio: make decoders output refcounted frames

This rewrites the audio decode loop to some degree. Audio filters don't
do refcounted frames yet, so af.c contains a hacky "emulation".

Remove some of the weird heuristic-heavy code in dec_audio.c. Instead of
estimating how much audio we need to filter, we always filter full
frames. Maybe this should be adjusted later: in case filtering increases
the volume of the audio data, we should try not to buffer too much
filter output by reducing the input that is fed at once.

For ad_spdif.c and ad_mpg123.c, we don't avoid extra copying yet - it
doesn't seem worth the trouble.
vo_opengl: don't reset user-set gamma when using vo_cmdline
encode: don't segfault when bailing out due to resolution change

Somehow this code expects lastimg is always set.
vf_sub: don't crash if no subtitle context is available

Happens with --vf=sub,sub (only the first one gets the context).
vf_sub: fix previous commit

The previous fix breaks another obscure case: if the second vf_sub adds
margins, the image is accidentally not extended, which would return in
an assertion failure when returning the bogus image.
demux_mkv: adjust subtitle preroll again

Revert commit 24e52f66; even though the old beheavior doesn't make sense
(as the commit message assured), it turns out that this works better:
typically, it means preroll will start from the previous video key frame
(the video CUE index will contain clusters with video key frames only),
which often coincides with subtitle changes. Thus the old behavior is
actually better.

Change the code that uses CueDuration elements. Instead of merely
checking whether preroll should be done, find the first cluster that
needs to be read to get all subtitle packets. (The intention is to
compensate for the enlarged preroll cluster-range due to reverting
commit 24e52f66.)
audio: refuse to allocate frames in invalid format