player: correctly set track information on adding external files

Before this commit, auto_loaded and lang were only set for the first
track in auto-loaded external files. Likewise, for the title and
lang arguments to the sub-add and audio-add commands.

Fixes #5432
This commit is contained in:
Zehua Chen 2018-01-27 15:27:58 -05:00 committed by Kevin Mitchell
parent 6161cfd781
commit 000a0e2775
No known key found for this signature in database
GPG Key ID: 559A34B46A917232
3 changed files with 44 additions and 34 deletions

View File

@ -5295,24 +5295,29 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
return 0;
}
}
struct track *t = mp_add_external_file(mpctx, cmd->args[0].v.s, type);
if (!t)
int first = mp_add_external_file(mpctx, cmd->args[0].v.s, type);
if (first < 0)
return -1;
if (cmd->args[1].v.i == 1) {
t->no_default = true;
} else {
if (mpctx->playback_initialized) {
mp_switch_track(mpctx, t->type, t, FLAG_MARK_SELECTION);
} else {
opts->stream_id[0][t->type] = t->user_tid;
for (int n = first; n < mpctx->num_tracks; n++) {
struct track *t = mpctx->tracks[n];
if (cmd->args[1].v.i == 1){
t->no_default = true;
} else if (n == first) {
if (mpctx->playback_initialized) {
mp_switch_track(mpctx, t->type, t, FLAG_MARK_SELECTION);
} else {
opts->stream_id[0][t->type] = t->user_tid;
}
}
char *title = cmd->args[2].v.s;
if (title && title[0])
t->title = talloc_strdup(t, title);
char *lang = cmd->args[3].v.s;
if (lang && lang[0])
t->lang = talloc_strdup(t, lang);
}
char *title = cmd->args[2].v.s;
if (title && title[0])
t->title = talloc_strdup(t, title);
char *lang = cmd->args[3].v.s;
if (lang && lang[0])
t->lang = talloc_strdup(t, lang);
if (mpctx->playback_initialized)
print_track_list(mpctx, "Track added:");
break;
@ -5338,14 +5343,15 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
}
int type = cmd->id == MP_CMD_SUB_RELOAD ? STREAM_SUB : STREAM_AUDIO;
struct track *t = mp_track_by_tid(mpctx, type, cmd->args[0].v.i);
struct track *nt = NULL;
int nt_num = -1;
if (t && t->is_external && t->external_filename) {
char *filename = talloc_strdup(NULL, t->external_filename);
mp_remove_track(mpctx, t);
nt = mp_add_external_file(mpctx, filename, type);
nt_num = mp_add_external_file(mpctx, filename, type);
talloc_free(filename);
}
if (nt) {
if (nt_num >= 0) {
struct track *nt = mpctx->tracks[nt_num];
mp_switch_track(mpctx, nt->type, nt, 0);
print_track_list(mpctx, "Reloaded:");
return 0;

View File

@ -487,8 +487,8 @@ struct playlist_entry *mp_check_playlist_resume(struct MPContext *mpctx,
// loadfile.c
void mp_abort_playback_async(struct MPContext *mpctx);
void uninit_player(struct MPContext *mpctx, unsigned int mask);
struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
enum stream_type filter);
int mp_add_external_file(struct MPContext *mpctx, char *filename,
enum stream_type filter);
#define FLAG_MARK_SELECTION 1
void mp_switch_track(struct MPContext *mpctx, enum stream_type type,
struct track *track, int flags);

View File

@ -576,12 +576,12 @@ bool mp_remove_track(struct MPContext *mpctx, struct track *track)
// Add the given file as additional track. Only tracks of type "filter" are
// included; pass STREAM_TYPE_COUNT to disable filtering.
struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
enum stream_type filter)
int mp_add_external_file(struct MPContext *mpctx, char *filename,
enum stream_type filter)
{
struct MPOpts *opts = mpctx->opts;
if (!filename)
return NULL;
return -1;
char *disp_filename = filename;
if (strncmp(disp_filename, "memory://", 9) == 0)
@ -622,10 +622,10 @@ struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
if (filter == STREAM_TYPE_COUNT)
tname = "";
MP_ERR(mpctx, "No %sstreams in file %s.\n", tname, disp_filename);
return false;
return -1;
}
struct track *first = NULL;
int first_num = -1;
for (int n = 0; n < demux_get_num_stream(demuxer); n++) {
struct sh_stream *sh = demux_get_stream(demuxer, n);
struct track *t = add_stream_track(mpctx, demuxer, sh);
@ -634,15 +634,15 @@ struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
t->external_filename = talloc_strdup(t, filename);
t->no_default = sh->type != filter;
t->no_auto_select = filter == STREAM_TYPE_COUNT;
if (!first && (filter == STREAM_TYPE_COUNT || sh->type == filter))
first = t;
if (first_num < 0 && (filter == STREAM_TYPE_COUNT || sh->type == filter))
first_num = mpctx->num_tracks - 1;
}
return first;
return first_num;
err_out:
MP_ERR(mpctx, "Can not open external file %s.\n", disp_filename);
return false;
return -1;
}
static void open_external_files(struct MPContext *mpctx, char **files,
@ -688,11 +688,15 @@ void autoload_external_files(struct MPContext *mpctx)
goto skip;
if (list[i].type == STREAM_AUDIO && !sc[STREAM_VIDEO])
goto skip;
struct track *track = mp_add_external_file(mpctx, filename, list[i].type);
if (track) {
track->auto_loaded = true;
if (!track->lang)
track->lang = talloc_strdup(track, lang);
int first = mp_add_external_file(mpctx, filename, list[i].type);
if (first < 0)
goto skip;
for (int n = first; n < mpctx->num_tracks; n++) {
struct track *t = mpctx->tracks[n];
t->auto_loaded = true;
if (!t->lang)
t->lang = talloc_strdup(t, lang);
}
skip:;
}