ring: use a different type for read/write pointers

uint_least32_t could be larger than uint32_t, so the return values of
mp_ring_get_wpos/rpos must be adjusted. Actually just use unsigned long
as type instead, because that is less awkward than uint_least32_t.
audio/out: adjust documentation comments
audio/out/push: add mechanism for event-based waiting

Until now, we've always calculated a timeout based on a heuristic when
to refill the audio buffers. Allow AOs to do it completely event-based
by providing wait and wakeup callbacks.

This also shuffles around the heuristic used for other AOs, and there is
a minor possibility that behavior slightly changes in real-world cases.
But in general it should be much more robust now.

ao_pulse.c now makes use of event-based waiting. It already did before,
but the code for time-based waiting was also involved. This commit also
removes one awkward artifact of the PulseAudio API out of the generic
code: the callback asking for more data can be reentrant, and thus
requires a separate lock for waiting (or a recursive mutex).
input: separate wakeup pipe creation into a separate function

Error handling is slightly reduced: we assume that setting a pipe
to non-blocking can never fail.
audio/out/push: add a way to wait for the audio device with poll()

Will be used for ALSA.
ao_alsa: use poll() to wait for device

This means the audio feed thread is woken up exactly at the time new
data is needed, instead of using a time-based heuristic.
audio: change handling of an EOF corner case

This code handles buggy AOs (even if all AOs are bug-free, it's good for
robustness). Move handling of it to the AO feed thread. Now this check
doesn't require magic numbers and does exactly what's it supposed to do.
audio/out/push: handle draining correctly

This did not flush remaining audio in the buffer correctly (in case an
AO has an internal block size). So we have to make the audio feed thread
to write the remaining audio, and wait until it's done.

Checking the avoid_ao_wait variable should be enough to be sure that all
data that can be written was written to the AO driver.