core, timeline: don't keep separate stream field

The timeline code kept pairs of struct stream and struct demuxer
around. The reference to the stream is redundant, because we always
create a demuxer for the stream. Simply it by always accessing the
stream through the demuxer references, instead of keeping the redundant
stream reference around.

Also, set mpctx->stream to the current segment when using timeline.
core: change how timeline code adds sources

Since the mplayer core might put essentially random things into the
MPContext.sources array, the various timeline builders (timeline/tl_*.c)
shouldn't completely replace it. Rather make them append to it.

Additionally, directly pass the demuxer the timeline is created from to
builders, instead of having them access MPContext.demuxer. The timeline
builders are guaranteed that the "main" file is already part of the
sources array.

Also fix a minor memory leak in tl_matroska introduced earlier by me.
demuxer: add more fields for sh_stream access

The struct sh_stream was introduced to make generic access to different
stream types (audio/video/sub) easier (as opposed to having duplicate
code accessing to a/v/s streams, because the types for these streams
are different). Add some more fields to facilitate use of generic access
further.

The previous solution to this was duplicating everything for each
stream type, and the plan is to reduce this code duplication.

Move enum stream_type from stheader.h to demuxer.h. demuxer.h seems to
be the more popular header.
core: move audio/video/sub selection to mplayer.c

command.c took care of all the details when switching these tracks. It's
cleaner if command.c doesn't know much about internals, and just acts as
a bridge between user interface and core.

Remove the sub_source/sub_vob/sub_demux/sub_file properties. They were
mostly of internal use, and got into the way. They could be added back
later.

Attempt to make stream selection more uniform. We don't try to remove
duplicated code yet.

Audio track selection when using timeline (as with mkv ordered chapters)
is somewhat broken by this commit (the track is reset). In general it
seems the existing code doesn't take much care about switching tracks
across the timeline. For example, video stream selection was kept per
timeline source, instead of making it persistent across all parts.
This has to be fixed later.
command: remove sub_log command

Not very useful, and introduced special cases. Just get rid of it, can
be reintroduced if in a better way if someone misses this feature.
command: remove sub_remove command

This messes deeply with the subtitle bookkeeping data structures, and
would have to be reimplemented anyway.

It's not sure what this was even useful for. Possibly for slave mode.
core: refactor: reduce accesses to MPContext.demuxer

For coming changes, it will be relatively easy to have more than one
demuxer be active at a time. The plan is to remove the demuxer_demuxers
hack, which combined several demuxers into one to support -audiofile
and -subfile. Make preparations so this can be done later: do not access
the demuxer field directly, and access them through the stream headers
instead.

Introduce a master_demuxer field, which should be used instead of the
demuxer field if a) the demuxer for the master file for Matroska ordered
chapters should be accessed, or b) demuxer access is needed for a
special purpose (i.e. access is not directly bound to video/audio/sub).
The demuxer field will be removed later.

Note that the code before always accessed the current timeline segment,
and would e.g. read file metadata of the current segment. Now it always
returns metadata for the master file. There may have various wanted and
unwanted effects.
core: manage tracks in the frontend

Introduce a general struct track for every audio/video/subtitle track
known to the frontend. External files (subtitles) are now represented
as tracks too. This mainly serves to clean up the horrible subtitle
managment code: now every subtitle is simply a track, instead of using
a messy numbering that goes by subtitle type (it was stored in the
global_sub_pos field).

Subtitle handling is cleaned up to some degree, without changing the
inner working of the subtitle mechanism. Managing external subtitle
files is now done with track handling. In particular, the mplayer
fontend will list external subtitle files as additional tracks.

The code works with the assumption that every track can have its own
demuxer. This will allow to reimplement -audiofile in the frontend.

Track cycling is now done by the fronend, instead of the individual
demuxers. The change also works towards getting rid of all the insane
stream IDs (especially in the former demuxer_switch_audio/_video
function, which took and returned two different type of IDs).

Stream selection is done by the frontend. The intention is that demuxers
start out with no streams selected, and the frontend selects the streams
it wants. Some demuxers can't handle having no initial stream selection,
so the initial stream IDs are still passed to the demuxer.

Timeline support now tries to match the exact demuxer IDs of all
tracks. This may cause problems when Matroska files with different
track numberings are used with EDL timelines. (Demuxers other than
demux_mkv don't pass their internal stream IDs as demuxer_id. To
mitigate similar issues with the audio/video track being added in
random order, change sh_stream.demuxer_id to be stream type specific
for demuxers other than demux_mkv. Essentially changes what demuxer_id
was meant to be.)
core: move support -audiofile to the frontend
core: move track selection to the frontend

This is about the code that decides which track to play initially given
the user's --vid/--aid/--sid and --alang/--slang options.

Proper support for correct DVD subtitle selection is removed with this
commit. It was buggy and didn't work as intended, because demux_lavf
seems to return subtitle streams in a different order than the (now
removed) internal mpeg demuxer. (mplayer-svn has the same problem
with demux_lavf, but uses the internal demuxer by default.)
mplayer: better formatting for track list printing
mplayer: do not cancel playback if VF/VO config fails

Usually failing to initialize the video chain does not stop playback,
and continues with audio-only. But when VF/VO config failed (the second
step in initializing them), playback was canceled and advanced to the
next file.

Make it more consistent and just switch off video if it fails.

Also, if no audio track is selected, go to next file anyway. The player
core goes into some sort of idle mode if no video and audio track is
selected, and we don't want to trigger it here. (It's unclear whether
that is a bug or feature: it's meant to work around some corner cases,
but maybe it shouldn't be triggered when switching off video & audio
tracks in normal playback.)
video_out: free memory if initializing a VO fails

This was a minor memory leak with no real impact.
core: runtime Matroska edition switching

Add a new slave property which switches the current Matroska edition.
Since each edition can define an entirely new timeline, chapters, and
track layout, switching the edition will simply restart playback with
the new edition selected.

Add 'E' as new keybinding to step the edition property.

DVD titles are still separate. Apparently they work similarly, but I
don't have any multi-title DVDs for testing. Also, cdda (for audio CDs)
uses the same mechanism as DVDs to report a number of titles, so that
mechanism is probably not very sane. The edition code is completely
separate for this reason. Remove demuxer.num_titles, it was just a
rather useless cached value of the DVD titles related STREAM_CTRL.

One rather obscure corner case isn't taken care of: if the ordered
chapters file has file local options set, they are reset on playback
restart. This is unexpected, because edition switching is meant to look
like seeking back to the beginning of the file.
mplayer: don't clear OSD when new file is played

When switching editions, it would be nice to display an OSD message to
notify the user which edition is being played. This would be consistent
with visual feedback like on tracking switching, seeking, and so on.

Rather than introducing awkward hacks and special cases to determine
whether a file is being "restarted" (as it happens on edition switching)
to avoid clearing the OSD messages, simply never clear the OSD stack.

This is more consistent with handling of OSD bars too: they didn't
disappear when going to a new file (especially noticable when seeking
past the end of the file).