core, timeline: don't keep separate stream field

The timeline code kept pairs of stream and demuxer references around.
The reference to the stream is redundant, because it can be accessed
through the demuxer.

Simplify the code by removing the redundant stream reference.

Also, set mpctx->stream to the current segment when using timeline.
Fix a small memory leak in tl_matroska.c introduced earlier.
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 MPContext.demuxer field accesses

Whenever the demuxer is accessed to retrieve metadata, use the newly
introduced master_demuxer field instead. If a timeline is used, the
master_demuxer will still refer to the main file, instead to segments.
Instead of mpctx->demuxer->stream, access mpctx->stream; even though
they are the same, the code becomes shorter. For the TV code, introduce
a function get_tvh() to access the TV handle, instead of duplicating the
code all over the place. Often the demuxer field is checked to determine
whether something is currently played; prefer other methods over that.

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. This may have various wanted and
unwanted effects.
core: manage tracks in the frontend

Introduce a general track struct 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 subtitle selection
code: now every subtitle is simply a track, instead of using a messy
numbering that goes by subtitle type (as it was stored in the
global_sub_pos field). The mplayer fontend will list external subtitle
files as additional tracks.

The timeline code 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. Change demux_lavf not
to set demuxer IDs, since most time they are not set.
core: move implementation for -audiofile to the frontend

This should behave as before, with the same set of caveats.
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, switching the
edition will simply restart playback at the beginning of the file 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 there
seems to be confusion what exactly this mechanism is supposed to do.
That's why the edition code is completely separate for now.

Remove demuxer.num_titles. It was just a rather useless cache for the
return 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
behave 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).
demux_mkv: fix minor memory leak
core: fix DVD subtitle selection

Add all subtitle tracks as reported by libdvdread at playback start.
Display language for subtitle and audio tracks. This commit restores
these features to the state when demux_mpg was default for DVD playback,
and makes them work with demux_lavf and the recent changes to subtitle
selection in the frontend.

demux_mpg, which was the default demuxer for DVD playback, reordered
the subtitle streams according to the "logical" subtitle track number,
which conforms to the track layout reported by libdvdread, and is what
stream_dvd expects for the STREAM_CTRL_GET_LANG call. demux_lavf, on
the other hand, adds the streams in the order it encounters them in
the MPEG stream. It seems this order is essentially random, and can't
be mapped easily to what stream_dvd expects.

Solve this by making demux_lavf hand out the MPEG stream IDs (using the
demuxer_id field). The MPEG IDs are mapped by mplayer.c by special
casing DVD playback (map_id_from/to_demuxer() functions). This mapping
is essentially the same what demux_mpg did. Making demux_lavf reorder
the streams is out of the question, because its stream handling is
already messy enough.

(Note that demux_lavf doesn't export stream IDs for other formats,
because most time libavformat demuxers do not set AVStream.id, and we
don't know which demuxers do. But we know that MPEG is safe.)

Another major complication is that subtitle tracks are added lazily, as
soon as the demuxer encounters the first subtitle packet for a given
subtitle stream. Add the streams in advance. If a yet non-existent
stream is selected, demux_lavf must be made to auto-select that subtitle
stream as soon as it is added. Otherwise, the first subtitle packet
would be lost. This is done by DEMUXER_CTRL_PRESELECT_SUBTITLE.
demux_mpg didn't need this: the frontend code could just set ds->id to
the desired stream number. But demux_lavf's stream IDs don't map
directly to the stream number as used by libdvdread, which is why this
hack is needed.