From ae46833836453b7fc64f2cff9cb69d6cfd73f947 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 22 May 2015 21:00:24 +0200 Subject: player: use an array for stream ID options and such This makes the code slightly more generic. --- options/options.c | 40 +++++++++++++++++++++------------------- options/options.h | 13 ++++--------- player/command.c | 6 ++---- player/core.h | 4 ++-- player/loadfile.c | 52 +++++++++++++++++++++------------------------------- sub/find_subfiles.c | 4 ++-- 6 files changed, 52 insertions(+), 67 deletions(-) diff --git a/options/options.c b/options/options.c index 44d4beae30..b2bd5c2e95 100644 --- a/options/options.c +++ b/options/options.c @@ -194,18 +194,18 @@ const m_option_t mp_opts[] = { OPT_CHOICE("index", index_mode, 0, ({"default", 1}, {"recreate", 0})), // select audio/video/subtitle stream - OPT_TRACKCHOICE("aid", audio_id), - OPT_TRACKCHOICE("vid", video_id), - OPT_TRACKCHOICE("sid", sub_id), - OPT_TRACKCHOICE("secondary-sid", sub2_id), - OPT_TRACKCHOICE("ff-aid", audio_id_ff), - OPT_TRACKCHOICE("ff-vid", video_id_ff), - OPT_TRACKCHOICE("ff-sid", sub_id_ff), - OPT_FLAG_STORE("no-sub", sub_id, 0, -2), - OPT_FLAG_STORE("no-video", video_id, 0, -2), - OPT_FLAG_STORE("no-audio", audio_id, 0, -2), - OPT_STRINGLIST("alang", audio_lang, 0), - OPT_STRINGLIST("slang", sub_lang, 0), + OPT_TRACKCHOICE("aid", stream_id[0][STREAM_AUDIO]), + OPT_TRACKCHOICE("vid", stream_id[0][STREAM_VIDEO]), + OPT_TRACKCHOICE("sid", stream_id[0][STREAM_SUB]), + OPT_TRACKCHOICE("secondary-sid", stream_id[1][STREAM_SUB]), + OPT_TRACKCHOICE("ff-aid", stream_id_ff[STREAM_AUDIO]), + OPT_TRACKCHOICE("ff-vid", stream_id_ff[STREAM_VIDEO]), + OPT_TRACKCHOICE("ff-sid", stream_id_ff[STREAM_SUB]), + OPT_FLAG_STORE("no-sub", stream_id[0][STREAM_SUB], 0, -2), + OPT_FLAG_STORE("no-video", stream_id[0][STREAM_VIDEO], 0, -2), + OPT_FLAG_STORE("no-audio", stream_id[0][STREAM_AUDIO], 0, -2), + OPT_STRINGLIST("alang", stream_lang[STREAM_AUDIO], 0), + OPT_STRINGLIST("slang", stream_lang[STREAM_SUB], 0), OPT_CHOICE("audio-display", audio_display, 0, ({"no", 0}, {"attachment", 1})), @@ -730,13 +730,15 @@ const struct MPOpts mp_default_opts = { .consolecontrols = 1, .play_frames = -1, .keep_open = 0, - .audio_id = -1, - .video_id = -1, - .sub_id = -1, - .audio_id_ff = -1, - .video_id_ff = -1, - .sub_id_ff = -1, - .sub2_id = -2, + .stream_id = { { [STREAM_AUDIO] = -1, + [STREAM_VIDEO] = -1, + [STREAM_SUB] = -1, }, + { [STREAM_AUDIO] = -2, + [STREAM_VIDEO] = -2, + [STREAM_SUB] = -2, }, }, + .stream_id_ff = { [STREAM_AUDIO] = -1, + [STREAM_VIDEO] = -1, + [STREAM_SUB] = -1, }, .audio_display = 1, .sub_visibility = 1, .sub_pos = 100, diff --git a/options/options.h b/options/options.h index 374649888e..208431110e 100644 --- a/options/options.h +++ b/options/options.h @@ -4,6 +4,7 @@ #include #include #include "m_option.h" +#include "common/common.h" typedef struct mp_vo_opts { struct m_obj_settings *video_driver_list, *vo_defs; @@ -170,15 +171,9 @@ typedef struct MPOpts { int ignore_path_in_watch_later_config; int pause; int keep_open; - int audio_id; - int video_id; - int sub_id; - int sub2_id; - int audio_id_ff; - int video_id_ff; - int sub_id_ff; - char **audio_lang; - char **sub_lang; + int stream_id[2][STREAM_TYPE_COUNT]; + int stream_id_ff[STREAM_TYPE_COUNT]; + char **stream_lang[STREAM_TYPE_COUNT]; int audio_display; char **display_tags; int sub_visibility; diff --git a/player/command.c b/player/command.c index 36cbf6cded..e203dd93ab 100644 --- a/player/command.c +++ b/player/command.c @@ -4623,12 +4623,10 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re autoload_external_files(mpctx); if (cmd->args[0].v.i) { // somewhat fuzzy and not ideal - struct track *a = select_track(mpctx, STREAM_AUDIO, opts->audio_id, - opts->audio_id_ff, opts->audio_lang); + struct track *a = select_default_track(mpctx, 0, STREAM_AUDIO); if (a && a->is_external) mp_switch_track(mpctx, STREAM_AUDIO, a); - struct track *s = select_track(mpctx, STREAM_SUB, opts->sub_id, - opts->sub_id_ff, opts->sub_lang); + struct track *s = select_default_track(mpctx, 0, STREAM_SUB); if (s && s->is_external) mp_switch_track(mpctx, STREAM_SUB, s); diff --git a/player/core.h b/player/core.h index 055a48bda4..64fd4ec1a5 100644 --- a/player/core.h +++ b/player/core.h @@ -402,8 +402,8 @@ void print_track_list(struct MPContext *mpctx); void reselect_demux_streams(struct MPContext *mpctx); void prepare_playlist(struct MPContext *mpctx, struct playlist *pl); void autoload_external_files(struct MPContext *mpctx); -struct track *select_track(struct MPContext *mpctx, enum stream_type type, - int tid, int ffid, char **langs); +struct track *select_default_track(struct MPContext *mpctx, int order, + enum stream_type type); // main.c int mp_initialize(struct MPContext *mpctx, char **argv); diff --git a/player/loadfile.c b/player/loadfile.c index 3dc0e0318a..a60b1b8638 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -453,9 +453,13 @@ static bool compare_track(struct track *t1, struct track *t2, char **langs, } return t1->user_tid <= t2->user_tid; } -struct track *select_track(struct MPContext *mpctx, enum stream_type type, - int tid, int ffid, char **langs) +struct track *select_default_track(struct MPContext *mpctx, int order, + enum stream_type type) { + struct MPOpts *opts = mpctx->opts; + int tid = opts->stream_id[order][type]; + int ffid = order == 0 ? opts->stream_id_ff[type] : -1; + char **langs = order == 0 ? opts->stream_lang[type] : NULL; if (ffid != -1) tid = -1; // prefer selecting ffid if (tid == -2 || ffid == -2) @@ -508,15 +512,14 @@ static void check_previous_track_selection(struct MPContext *mpctx) char *h = track_layout_hash(mpctx); if (strcmp(h, mpctx->track_layout_hash) != 0) { - // Reset selection, but only if they're not "auto" or "off". - if (opts->video_id >= 0) - mpctx->opts->video_id = -1; - if (opts->audio_id >= 0) - mpctx->opts->audio_id = -1; - if (opts->sub_id >= 0) - mpctx->opts->sub_id = -1; - if (opts->sub2_id >= 0) - mpctx->opts->sub2_id = -2; + // Reset selection, but only if they're not "auto" or "off". The + // defaults are -1 (default selection), or -2 (off) for secondary tracks. + for (int t = 0; t < STREAM_TYPE_COUNT; t++) { + for (int i = 0; i < NUM_PTRACKS; i++) { + if (opts->stream_id[i][t] >= 0) + opts->stream_id[i][t] = i == 0 ? -1 : -2; + } + } talloc_free(mpctx->track_layout_hash); mpctx->track_layout_hash = NULL; } @@ -609,15 +612,8 @@ void mp_mark_user_track_selection(struct MPContext *mpctx, int order, { struct track *track = mpctx->current_track[order][type]; int user_tid = track ? track->user_tid : -2; - if (type == STREAM_VIDEO && order == 0) { - mpctx->opts->video_id = user_tid; - } else if (type == STREAM_AUDIO && order == 0) { - mpctx->opts->audio_id = user_tid; - } else if (type == STREAM_SUB && order == 0) { - mpctx->opts->sub_id = user_tid; - } else if (type == STREAM_SUB && order == 1) { - mpctx->opts->sub2_id = user_tid; - } + + mpctx->opts->stream_id[order][type] = user_tid; } struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type, @@ -1151,17 +1147,11 @@ goto_reopen_demuxer: ; check_previous_track_selection(mpctx); - mpctx->current_track[0][STREAM_VIDEO] = - select_track(mpctx, STREAM_VIDEO, opts->video_id, opts->video_id_ff, - NULL); - mpctx->current_track[0][STREAM_AUDIO] = - select_track(mpctx, STREAM_AUDIO, opts->audio_id, opts->audio_id_ff, - opts->audio_lang); - mpctx->current_track[0][STREAM_SUB] = - select_track(mpctx, STREAM_SUB, opts->sub_id, opts->sub_id_ff, - opts->sub_lang); - mpctx->current_track[1][STREAM_SUB] = - select_track(mpctx, STREAM_SUB, opts->sub2_id, -1, NULL); + assert(NUM_PTRACKS == 2); // opts->stream_id is hardcoded to 2 + for (int t = 0; t < STREAM_TYPE_COUNT; t++) { + for (int i = 0; i < NUM_PTRACKS; i++) + mpctx->current_track[i][t] = select_default_track(mpctx, i, t); + } for (int t = 0; t < STREAM_TYPE_COUNT; t++) { for (int i = 0; i < NUM_PTRACKS; i++) { struct track *track = mpctx->current_track[i][t]; diff --git a/sub/find_subfiles.c b/sub/find_subfiles.c index d016b1f625..aa0a181f40 100644 --- a/sub/find_subfiles.c +++ b/sub/find_subfiles.c @@ -142,11 +142,11 @@ static void append_dir_subtitles(struct mpv_global *global, int fuzz = -1; switch (type) { case STREAM_SUB: - langs = opts->sub_lang; + langs = opts->stream_lang[type]; fuzz = opts->sub_auto; break; case STREAM_AUDIO: - langs = opts->audio_lang; + langs = opts->stream_lang[type]; fuzz = opts->audiofile_auto; break; } -- cgit v1.2.3