input: fix missed wakeups, simplify

mp_input_read_cmd() reset the wakeup flag, but only mp_input_wait()
should be able to do that.
player: normalize playlist entries on add

This is not necessarily more correct, but it's less trouble.
player: deal with some corner cases with playlist navigation

The purpose is making accessing the current playlist entry saner when
commands are executed during initialization, termination, or after
playlist navigation commands.

For example, the "playlist_remove current" command will invalidate
playlist->current - but some things still access the playlist entry even
on uninit. Until now, checking stop_play implicitly took care of it, so
it worked, but it was still messy.

Introduce the mpctx->playing field, which points to the current playlist
entry, even if the entry was removed and/or the playlist's current entry
was moved (e.g. due to playlist navigation).
player: reset some VO state when video is terminated

Useful for idle mode or if video is switched off during playback, and
--force-window is used.
win32: don't request window size larger than the screen

An attempt at fixing #1070. Apparently something goes wrong if the
video size is equal to the screen size. Since the window decorations
add to the window size, it must actually be larger than the screen.
Actually I don't know what exactly is going wrong, but since this
commit also slightly improves the behavior otherwise, it's a win
anyway.

Try to keep the window size strictly below screen size, even accounting
for window decorations. Size it down and center the window so that it
fits (by either touching the left/right or top/bottom screen borders).
I haven't found any information on what is the maximum allowed size and
position of a window so that it doesn't collide with the task bar, so
assume that we can use the entire screen, minus 1 pixel to avoid
triggering fullscreen semantics (if that is even possible).
terminal-win: minor simplification

Code should be equivalent.
terminal-unix: move to thread

Do terminal input with a thread, instead of using the central select()
loop. This also changes some details how SIGTERM is handled.

Part of my crusade against mp_input_add_fd().
terminal-unix: don't read from stdin if it's not a terminal

I'm not quite sure what we should actually do (maybe read input
commands?), but interpreting input as terminal key sequences is
definitely weird. So just do nothing.
input: make some fields internal
input: add convenience function for running input sources in threads
input: use an input thread for lirc
input: use an input thread for joystick
input: remove useless joystick.h/lirc.h include files

These really just waste space.
osdep: add POSIX semaphore emulation for OSX

OSX is POSIX conformant, but it's a sad joke: it provides the
<semaphore.h> prototype as the standard demands, but they're empty
wrappers, and all functions just return ENOSYS.

Emulate them similar to how osdep/io.h emulate filesystem functions on
Windows. By including the header, working sem_* functions become
available.

To make it async-signal safe, use a pipe for wakeup (write() is AS-safe,
but mutexes can't be). Actually I'm not sure anymore if we really need
AS-safety, but for now the emulation can do it.

On Linux, the system provides a far more efficient and robust
implementation. We definitely want to avoid using the emulation if
possible, so this code is active on OSX only. For convenience we always
build the source file though, even if the implementation is disabled and
no actual code is generated.

(Linux provides working semaphores, but is formally not POSIX
conformant. On OSX it's the opposite. Is POSIX a complete joke?)
input: remove central select() call

This is now unused. Get rid of it and all surrounding infrastructure,
and replace the remaining "wakeup pipe" with a semaphore.
osdep: fix windows build

Oops.
build: fix everything

A missing dependency entry made ./waf configure always fail.
osdep/semaphore_osx.c: Include osdep/semaphore.h before #ifdef

osdep/semaphore.h is the file that defines the very #define that is
tested in the #ifdef that wraps its inclusion, so it was never compiled.
vo_wayland: pixel perfect buffers

1.  Separate buffer and temporary file handling from the vo to make maintenance
    and reading code easier

2.  Skip resizing as much as possible if back buffer is still busy.

3.  Detach and mark osd buffers for deletion if we want to redraw them and they
    are still busy. This could be a possible case for the video buffers as
    well. Maybe better than double buffering.

All the above steps made it possible to have resizing without any artifacts
even for subtitles. Also fixes dozen of bugs only I knew, like broken subtitles
for rgb565 buffers. I can now sleep at night again.
wayland_common: fix changing videos when fullscreen

I broke it again.