ao_alsa: always unset ALSA error handler, cleanup on init error

The ALSA device was not closed when initialization failed.

The ALSA error handler (set with snd_lib_error_set_handler()) was not
unset when closing ao_alsa. If this is not done, the handler will still
be called when other libraries using ALSA cause errors, even though
ao_alsa was long closed. Since these messages were prefixed with
"[AO_ALSA]", they were misleading and implying ao_alsa was still used.

For some reason, our error handler is still called even after doing
snd_lib_error_set_handler(NULL), which should be impossible. Checking
with the debuggers, inserting printf(), as well as the alsa-lib source
code all suggest our error handler should not be called, but it still
happens. It's a complete mystery.
vf_lavfi: allow setting avopts
video/out: introduce vo_control for gl_common based VOs

Instead of having separate callbacks for each backend-handled feature
(like MPGLContext.fullscreen, MPGLContext.border, etc.), pass the
VOCTRL responsible for this directly to the backend. This allows
removing a bunch of callbacks, that currently must be set even for
optional/lesser features (like VOCTRL_BORDER).

This requires changes to all VOs using gl_common, as well as all
backends that support gl_common.

Also introduce VOCTRL_CHECK_EVENTS. vo.check_events is now optional.
VO backends can use VOCTRL_CHECK_EVENTS instead to implementing
check_events. This has the advantage that the event handling code in
VOs doesn't have to be duplicated if vo_control() is used.
x11: use vo_x11_control() for all VOs
w32: use vo_w32_control() for all VOs
vo: remove vo.check_events callback

Use VOCTRL_CHECK_EVENTS instead. Change the remaining VOs to use it.
Only vo_sdl and vo_caca actually need this, and vo_null, vo_lavc, and
vo_image had stubs only.
core: do mouse cursor hiding business in frontend

Do this so that not every VO backend has to setup a timer for cursor
hiding and interpret the --cursor-autohide option.
x11: remove cursor hiding logic, use VOCTRL_SET_CURSOR_VISIBILITY
vo_sdl: use VOCTRL_SET_CURSOR_VISIBILITY
w32: use VOCTRL_SET_CURSOR_VISIBILITY

This didn't even implement --cursor-autohide. Now it does, and the
behavior of the VOs under Windows change accordingly.
cocoa_common: implement mouse movement notifications

Notify the core of mouse movement events. The coordinates are converted to a
coordinate system with the origin in upper left corner, since Cocoa has it in
the lower left corner.
cocoa_common: implement VOCTRL_SET_CURSOR_VISIBILITY

Pass along cursor visibility hints to be more consistent with OSX's behaviour.
wayland: introduce vo_wayland_config

This removes the need for exposing vo_wayland_fullscreen and other functions
also this will be usefull for other vos in the future.
wayland: use VOCTRL_SET_CURSOR_VISIBILITY
cocoa_common: send mouse moved events to core when dragging

This change fixes mouse autohide when dragging mouse.
timer: refactor, add 64 bit timer function

Make OS specific timer code export a mp_raw_time_us() function, and
add generic implementations of GetTimer()/GetTimerMS() using this
function. New mpv code is supposed to call mp_time_us() in situations
where precision is absolutely needed, or mp_time_s() otherwise.

Make it so that mp_time_us() will return a value near program start.
We don't set it to 0 though to avoid confusion with relative vs.
absolute time. Instead, pick an arbitrary offset.

Move the test program in timer-darwin.c to timer.c, and modify it to
work with the generic timer functions.
timer: use gettimeofday() on Windows

MinGW-w64 emulates this via GetSystemTimeAsFileTime(), which has
supposedly the best and most stable timer source out of most others.

http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64/trunk/mingw-w64-crt/misc/gettimeofday.c
vo: rip out VO timer wakeup mechanism again

This was used by some VOs to do timing of cursor autohiding, but we
recently moved that out of the VOs. Even though this mechanism might
be a good idea and could be needed again in future (but for what?),
it's unused now. So better just get rid of it.
Replace all calls to GetTimer()/GetTimerMS()

GetTimer() is generally replaced with mp_time_us(). Both calls return
microseconds, but the latter uses int64_t, us defined to never wrap,
and never returns 0 or negative values.

GetTimerMS() has no direct replacement. Instead the other functions are
used.

For some code, switch to mp_time_sec(), which returns the time as double
float value in seconds. The returned time is offset to program start
time, so there is enough precision left to deliver microsecond
resolution for at least 100 years. Unless it's casted to a float
(or the CPU reduces precision), which is why we still use mp_time_us()
out of paranoia in places where precision is clearly needed.

Always switch to the correct time. The whole point of the new timer
calls is that they don't wrap, and storing microseconds in unsigned int
variables would negate this.

In some cases, remove wrap-around handling for time values.
Replace calls to usec_sleep()

This is just dumb sed replacement to mp_sleep_us().

Also remove the now unused usec_sleep() wrapper.