player: when loading external file, always add all track types

Until now, using --sub-file would add only subtitle tracks from the
given file. (E.g. if you passed a video file, only the subtitle tracks
from it were added, not the video or audio tracks.)

This is slightly messy (because streams are hidden), and users don't
even want it, as shown by #5132. Change it to always add all streams.
But if there's no stream of the wanted type, we still report an error
and do not add any streams. It's also made sure none of the other track
types are autoselected.

Also adjust the error messages on load failure slightly.

Fixes #5132.
This commit is contained in:
wm4 2017-12-07 10:32:29 +01:00 committed by Kevin Mitchell
parent 520fc74036
commit 80d43ee4e6
1 changed files with 24 additions and 13 deletions

View File

@ -601,23 +601,34 @@ struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
if (opts->rebase_start_time)
demux_set_ts_offset(demuxer, -demuxer->start_time);
bool has_any = false;
for (int n = 0; n < demux_get_num_stream(demuxer); n++) {
struct sh_stream *sh = demux_get_stream(demuxer, n);
if (sh->type == filter || filter == STREAM_TYPE_COUNT) {
has_any = true;
break;
}
}
if (!has_any) {
free_demuxer_and_stream(demuxer);
char *tname = mp_tprintf(20, "%s ", stream_type_name(filter));
if (filter == STREAM_TYPE_COUNT)
tname = "";
MP_ERR(mpctx, "No %sstreams in file %s.\n", tname, disp_filename);
return false;
}
struct track *first = NULL;
for (int n = 0; n < demux_get_num_stream(demuxer); n++) {
struct sh_stream *sh = demux_get_stream(demuxer, n);
if (filter == STREAM_TYPE_COUNT || sh->type == filter) {
struct track *t = add_stream_track(mpctx, demuxer, sh);
t->is_external = true;
t->title = talloc_strdup(t, mp_basename(disp_filename));
t->external_filename = talloc_strdup(t, filename);
struct track *t = add_stream_track(mpctx, demuxer, sh);
t->is_external = true;
t->title = talloc_strdup(t, mp_basename(disp_filename));
t->external_filename = talloc_strdup(t, filename);
t->no_default = sh->type != filter;
if (!first && (filter == STREAM_TYPE_COUNT || sh->type == filter))
first = t;
// --external-file special semantics
t->no_default = filter == STREAM_TYPE_COUNT;
}
}
if (!first) {
free_demuxer_and_stream(demuxer);
MP_WARN(mpctx, "No streams added from file %s.\n", disp_filename);
goto err_out;
}
return first;