diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 9d27f9d98d..d3d5790c15 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -391,6 +391,15 @@ List of Input Commands The mouse event represents double-click. +``audio_add "" [ [ [<lang>]]]`` + Load the given audio file. See ``sub_add`` command. + +``audio_remove [<id>]`` + Remove the given audio track. See ``sub_remove`` command. + +``audio_reload [<id>]`` + Reload the given audio tracks. See ``sub_reload`` command. + Input Commands that are Possibly Subject to Change -------------------------------------------------- diff --git a/input/cmd_list.c b/input/cmd_list.c index 376f330ce2..28c89884e7 100644 --- a/input/cmd_list.c +++ b/input/cmd_list.c @@ -193,6 +193,12 @@ const struct mp_cmd_def mp_cmds[] = { {"double", 1})), }}, + { MP_CMD_AUDIO_ADD, "audio_add", { ARG_STRING, + OARG_CHOICE(0, ({"select", 0}, {"auto", 1}, {"cached", 2})), + OARG_STRING(""), OARG_STRING("") } }, + { MP_CMD_AUDIO_REMOVE, "audio_remove", { OARG_INT(-1) } }, + { MP_CMD_AUDIO_RELOAD, "audio_reload", { OARG_INT(-1) } }, + {0} }; diff --git a/input/cmd_list.h b/input/cmd_list.h index 84e64273e2..c761be98ee 100644 --- a/input/cmd_list.h +++ b/input/cmd_list.h @@ -73,6 +73,9 @@ enum mp_command_type { MP_CMD_MULTIPLY, MP_CMD_CYCLE_VALUES, MP_CMD_STOP, + MP_CMD_AUDIO_ADD, + MP_CMD_AUDIO_REMOVE, + MP_CMD_AUDIO_RELOAD, MP_CMD_ENABLE_INPUT_SECTION, MP_CMD_DISABLE_INPUT_SECTION, 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)