demux_lavf: fix initial video stream selection

One bug in initial video stream selection when opening the demuxer was
fixed earlier by cb4394aea32 ("demux_lavf: fix initial "-vid"-based
video selection"). However, this still doesn't always work right due
to the nonsensical way demuxer->video->id is initialized. Before
demuxer-specific code runs, demuxer.c initializes it to the value of
the --vid option, or -2 for disabled or -1 for autoselect. However, in
a running demuxer, the value of the field is demuxer->v_streams[]
index which does not need to match --vid value for the stream. The
demux_lavf video selection code considered each stream one by one as
they were being added. As a result, the code could first select one
stream based on the demuxer->video->id value from demuxer.c, set
demuxer->video->id to the corresponding v_streams index value, and
then later reinterpret that as --vid specifying a _different_ stream.

Move video stream selection to the end of demuxer initialization. This
ensures there is no ambiguity whether demuxer->video->id is still the
--vid value or after-stream-selection v_streams index. It also ensures
the code will not try to autoselect a stream that is added later after
demuxer initialization (which, while perhaps desirable in some cases,
would not work correctly without extra code). Also, remove some code
which set demuxer->audio->sh and demuxer->video->sh in fill_buffer();
this should not be needed if other code is working correctly, as
anything selecting the stream should have already initialized those
fields.
stream_file: print strerror() when failing to open a file

stream_file always printed "File not found" if it could not open a
file, even though this could be due to other reasons such as
permission problems. Print strerror() information instead. This
changes the output for "mplayer /etc/shadow" from
File not found: '/etc/shadow'
to
Cannot open file '/etc/shadow': Permission denied
stream_file: refuse to open directories

It's pointless.
demux_lmlm4: avoid printing error from check_file()

lmlm4_check_file() did a seek back before returning failure. This
triggered a "Invalid seek to negative position" error when trying to
play very short files (mainly ones too short to actually contain
anything playable). As there's no need to change stream position
before returning demuxer detection failure, fix the spurious message
by simply removing the seek.
input/lirc: don't show errors even if LIRC init fails

LIRC support is enabled by default if the machine has liblircclient
development headers installed, and it's also enabled in at least some
distro packages. However, most machines will not have the LIRC daemon
running. In this case the LIRC input initialization code printed three
lines of errors: two from the liblircclient lirc_init() function
called with verbose mode enabled, and one from the player input code.
The first two lines also ignored message level settings as they were
output directly by the library. Disable these messages: call
lirc_init() without verbose mode, and move the player message from
MSGL_ERR to MSGL_V. The first change unfortunately means that there
are no details about the error available in case you expected LIRC
support to work.
gl_common: fix compilation on OS X 10.8

As of OS X 10.8 Apple completely removed X11 from the system.
gl_common.h was including gl.h using the path <GL/gl.h>. This path
comes from the X11 headers, which are missing in 10.8.

Change gl_common.h to include gl.h from Apple's OpenGL implementation
as <OpenGL/gl.h> if X11/XQuartz is not detected.
cocoa_common: make fullscreen menubar/dock hiding conditional

cocoa_common was hiding the dock and menubar unconditionally when
going fullscreen. This means they were hidden even if they weren't on
the screen mplayer2 was going fullscreen on, resulting in poor user
experience.

Change the fullscreen function in the cocoa backend to check that
mplayer2 is on the same screen as the menubar/dock before hiding them.
ad_ffmpeg: add sanity check against decoder overreads

The libavcodec Musepack SV8 decoder returned 2 bytes consumed for 1
byte input, which triggered a crash due to negative input packet size
later. Add a sanity check to prevent crashes with this type of minor
decoder overreads. Also add a check to parser consumed data.
demux_lavf: assume audio codec_tag 0 means unset

Libavformat does not distinguish between "no codec_tag given" and
"codec_tag given, value is 0". 0 can be a valid value. Change
demux_lavf to assume that 0 always means unset for audio. This
prevents incorrect selection of the PCM decoder, which includes
"format 0x0" in its codecs.conf entry. The video case accepts 0 iff
codec_id is RAWVIDEO, but there's no obvious similar check possible
for audio. Thus this could possibly cause issues if a file really uses
0 to mean uncompressed audio.
command: fix crash when setting nonexistent property

Commit ebaaa41f2a4 accidentally removed the final terminator of the
properties array.
cocoa_common: refactor menu generation

This commit is supposed to make the menu generation a little more
readable. It also fixes menu generation for the `cmd+q` entry.
cleanup: osx_common: remove unused functions

Remove functions that aren't called anymore:

 *  `osx_foreground_hack` was replaced by the NSApplication's
    activateIgnoringOtherApps: in cocoa_common.
 *  Aspect ratio functions were not called by the "new" cocoa backend,
    since the corresponding menu item was deleted.
cocoa_common.m: add missing config.h include

This is needed for the check on CONFIG_SDL in this file.
macosx_finder_args: add SDL specific code path

SDL bootstrap code (include SDL.h in mplayer.c) creates its own minimal
Cocoa Application and creates a new argv to abstract away OSX specific
stuff (like -psn). For this reason the original code was not entering the
correct code path. This resulted in mplayer2 spamming to system.log.

Add a different code path to handle the case where SDL boostrap code ran.

Also, sort the files by filename for both SDL and no-SDL code paths: when
files are double clicked or drag and dropped to the mplayer2 icon they can
be in random order. Opening them with command + down arrow already
worked correctly.
cocoa_common: don't require a depth buffer

mplayer2's video outputs are not using an OpenGL depth buffer, so it's
pointless to specifically require it.
cocoa_common: add HiDPI/retina support

With a HiDPI screen, for performance and backwards compatibility
reasons, AppKit requests an OpenGL surface with a pixel number that
equals the user points number. After the image is rendered to this
smaller surface, it is upscaled so that its dimensions are comparable
across screens of different DPIs. The applied scaling is not that good
and makes the video/subtitles blurry; this is not acceptable for a
video player.

Request AppKit to use a high resolution OpenGL surface to back the
mplayer2 OpenGL view. Also set the window pixel size information
correctly in the VO object by converting user points to actual pixels.

All the system version checks are done at runtime so that the feature
is available on OSX 10.7 even with a binary compiled with older SDKs.
vo_sharedbuffer: remove this VO

Since slave mode is not planned to be kept, this VO is useless and I'm
removing it.

This VO was useful for OSX GUIs. Since in cocoa you can't embed views in
windows from other processes, this VO was writing to a sharedbuffer with
mmap. The OSX GUIs would then read from the buffer and render the image
with an external renderer.

If in the future we will want to support GUIs we will need to reasearch the
IOSurface framework. This allows to share kernel managed image data
across processes and integrates well with OpenGL.
core: intentionally cripple slave mode

Rename -slave to -slave-broken to prevent slave mode applications from
working. Do this to prevent horrible user experiences, in case someone
should attempt to try this version of mplayer with smplayer and others.
This also makes it clear that we don't intend to keep slave mode
compatibility, because the slave mode protocol is horrible and bad.

See the changes in options.rst for further reasons and comments.
vf_expand: remove OSD support

It's not clear why this video filter supported OSD rendering.
The manpage says:
    "Can be used for placing subtitles/OSD in the resulting black bands."
But every single VO already does this if vf_expand adds black borders.
This feature is 100% pointless.
image_writer: make JPG default and increase quality (for screenshots)

The assumption is that JPG screenshots are more useful in general.
Lossless screenshots made from lossy videos are just a waste of space.

Increase JPEG quality a bit. There's a tradeoff between quality and
size, and since JPEG is the default now, attempt to balance the
JPEG settings to provide sane defaults for general use cases.