threads: avoid timeout calculation overflow

It's quite possible to overflow the calculation by setting the timeout
to high values. Limit it to INT_MAX, which should be safe. The issue is
mainly the secs variable.

timespec.tv_sec will normally be 64 bit on sane systems, and we assume
it can't overflow by adding INT_MAX to it.
threads: add a dispatch queue thing

Makes working with the (still) single-threaded playback thread easier.

Might be reusable for other stuff.
options: add --no-terminal switch

Mostly useful for internal reasons. This code will be enabled by
default if mpv is started via the client API.
timer: init only once

This avoids trouble if another mpv instance is initialized in the same
process.

Since timeBeginPeriod/timeEndPeriod are hereby not easily matched
anymore, use an atexit() handler to call timeEndPeriod, so that we
can be sure these calls are matched, even if we allow multiple
initializations later when introducing the client API.
Add a client API

Add a client API, which is intended to be a stable API to get some rough
control over the player. Basically, it reflects what can be done with
input.conf commands or the old slavemode. It will replace the old
slavemode (and enable the implementation of a new slave protocol).
lua: port to client API

This is partial only, and it still accesses some MPContext internals.
Specifically, chapter and track lists are still read directly, and OSD
access is special-cased too.

The OSC seems to work fine, except using the fast-forward/backward
buttons. These buttons behave differently, because the OSC code had
certain assumptions how often its update code is called.

The Lua interface changes slightly.

Note that this has the odd property that Lua script and video start
at the same time, asynchronously. If this becomes an issue, explicit
synchronization could be added.
lua: add a timer API
build: include a copy of syms.py from upstream waf

The alternatives to copying this small bit of code are even worse.

This is unmodified, except for the added line 3.
build: add option to build a library

This library will export the client API functions.

Note that this doesn't allow compiling the command line player to link
against this library yet. The reason is that there's lots of weird stuff
required to setup the execution environment (mostly Windows and OSX
specifics), as well as things which are out of scope of the client API
and every application has to do on its own. However, since the mpv
command line player basically reuses functions from the mpv core to
implement these things, it's not very easy to separate the command
line player form the mpv core.
Add a client API example
Merge branch 'client_api'
vo_vdpau: Ensure presentation time is within bounds

When a time sync happens the last sync time is the minimum time that can be
used for presentation.
vo_vdpau: Discard zero timestamps

Some drivers do not supply timestamps, use old timestamp in these conditions.
vo_opengl: fix typo in gamma function's parameter

The correct value is 0.081, not 0.18. The scale factor also needed
slight adjustment due to the order of operations.