From 95fd83a269db6e2a04e40fe0c40cc02a051f316d Mon Sep 17 00:00:00 2001 From: xylosper Date: Tue, 3 Feb 2015 17:15:14 +0900 Subject: command: new commands audio_add/audio_remove/audio_reload These commands are counterparts of sub_add/sub_remove/sub_reload which work for external audio file. Signed-off-by: wm4 (minor simplification) --- player/command.c | 53 ++++++++++++++++++++++++++++++----------------------- player/core.h | 3 ++- player/loadfile.c | 15 +++++---------- 3 files changed, 37 insertions(+), 34 deletions(-) (limited to 'player') diff --git a/player/command.c b/player/command.c index 85e5b17be0..f20e6050b4 100644 --- a/player/command.c +++ b/player/command.c @@ -4557,51 +4557,58 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd) break; } - case MP_CMD_SUB_ADD: { + case MP_CMD_SUB_ADD: + case MP_CMD_AUDIO_ADD: { if (!mpctx->playing) return -1; + int type = cmd->id == MP_CMD_SUB_ADD ? STREAM_SUB : STREAM_AUDIO; if (cmd->args[1].v.i == 2) { - struct track *sub = find_track_with_url(mpctx, STREAM_SUB, + struct track *t = find_track_with_url(mpctx, type, cmd->args[0].v.s); - if (sub) { - mp_switch_track(mpctx, sub->type, sub); - mp_mark_user_track_selection(mpctx, 0, sub->type); + if (t) { + mp_switch_track(mpctx, t->type, t); + mp_mark_user_track_selection(mpctx, 0, t->type); return 0; } } - struct track *sub = mp_add_subtitles(mpctx, cmd->args[0].v.s); - if (!sub) + struct track *t = mp_add_external_file(mpctx, cmd->args[0].v.s, type); + if (!t) return -1; if (cmd->args[1].v.i == 1) { - sub->no_default = true; + t->no_default = true; } else { - mp_switch_track(mpctx, sub->type, sub); - mp_mark_user_track_selection(mpctx, 0, sub->type); + mp_switch_track(mpctx, t->type, t); + mp_mark_user_track_selection(mpctx, 0, t->type); } char *title = cmd->args[2].v.s; if (title && title[0]) - sub->title = talloc_strdup(sub, title); + t->title = talloc_strdup(t, title); char *lang = cmd->args[3].v.s; if (lang && lang[0]) - sub->lang = talloc_strdup(sub, lang); + t->lang = talloc_strdup(t, lang); break; } - case MP_CMD_SUB_REMOVE: { - struct track *sub = mp_track_by_tid(mpctx, STREAM_SUB, cmd->args[0].v.i); - if (!sub) + case MP_CMD_SUB_REMOVE: + case MP_CMD_AUDIO_REMOVE: { + int type = cmd->id == MP_CMD_SUB_REMOVE ? STREAM_SUB : STREAM_AUDIO; + struct track *t = mp_track_by_tid(mpctx, type, cmd->args[0].v.i); + if (!t) return -1; - mp_remove_track(mpctx, sub); + mp_remove_track(mpctx, t); break; } - case MP_CMD_SUB_RELOAD: { - struct track *sub = mp_track_by_tid(mpctx, STREAM_SUB, cmd->args[0].v.i); - if (sub && sub->is_external && sub->external_filename) { - struct track *nsub = mp_add_subtitles(mpctx, sub->external_filename); - if (nsub) { - mp_remove_track(mpctx, sub); - mp_switch_track(mpctx, nsub->type, nsub); + case MP_CMD_SUB_RELOAD: + case MP_CMD_AUDIO_RELOAD: { + 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); + if (t && t->is_external && t->external_filename) { + struct track *nt = mp_add_external_file(mpctx, t->external_filename, + type); + if (nt) { + mp_remove_track(mpctx, t); + mp_switch_track(mpctx, nt->type, nt); return 0; } } diff --git a/player/core.h b/player/core.h index 06abd0eff8..d6475eb385 100644 --- a/player/core.h +++ b/player/core.h @@ -373,7 +373,8 @@ int mp_nav_in_menu(struct MPContext *mpctx); // loadfile.c void uninit_player(struct MPContext *mpctx, unsigned int mask); -struct track *mp_add_subtitles(struct MPContext *mpctx, char *filename); +struct track *mp_add_external_file(struct MPContext *mpctx, char *filename, + enum stream_type filter); void mp_switch_track(struct MPContext *mpctx, enum stream_type type, struct track *track); void mp_switch_track_n(struct MPContext *mpctx, int order, diff --git a/player/loadfile.c b/player/loadfile.c index bf4121ba00..bb15068ead 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -646,8 +646,8 @@ bool mp_remove_track(struct MPContext *mpctx, struct track *track) return true; } -static struct track *open_external_file(struct MPContext *mpctx, char *filename, - enum stream_type filter) +struct track *mp_add_external_file(struct MPContext *mpctx, char *filename, + enum stream_type filter) { struct MPOpts *opts = mpctx->opts; if (!filename) @@ -714,19 +714,14 @@ static void open_audiofiles_from_options(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; for (int n = 0; opts->audio_files && opts->audio_files[n]; n++) - open_external_file(mpctx, opts->audio_files[n], STREAM_AUDIO); -} - -struct track *mp_add_subtitles(struct MPContext *mpctx, char *filename) -{ - return open_external_file(mpctx, filename, STREAM_SUB); + mp_add_external_file(mpctx, opts->audio_files[n], STREAM_AUDIO); } static void open_subtitles_from_options(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; for (int i = 0; opts->sub_name && opts->sub_name[i] != NULL; i++) - mp_add_subtitles(mpctx, opts->sub_name[i]); + mp_add_external_file(mpctx, opts->sub_name[i], STREAM_SUB); } static void autoload_external_files(struct MPContext *mpctx) @@ -751,7 +746,7 @@ static void autoload_external_files(struct MPContext *mpctx) if (strcmp(mpctx->sources[n]->stream->url, filename) == 0) goto skip; } - struct track *track = open_external_file(mpctx, filename, list[i].type); + struct track *track = mp_add_external_file(mpctx, filename, list[i].type); if (track) { track->auto_loaded = true; if (!track->lang) -- cgit v1.2.3