player/command: add visual-impaired flags to track add command

This commit is contained in:
Kacper Michajłow
2025-03-07 21:06:43 +01:00
parent 3147eca943
commit 7b9290f620
5 changed files with 36 additions and 17 deletions
+1 -1
View File
@@ -1 +1 @@
add `hearing-impaired` flag to track add command
add `hearing-impaired` and `visual-impaired` flags to track add command
+4
View File
@@ -669,6 +669,10 @@ Track Manipulation
Marks the track as suitable for the hearing impaired.
<visual-impaired>
Marks the track as suitable for the visually impaired.
The ``title`` argument sets the track title in the UI.
The ``lang`` argument sets the track language, and can also influence
+15 -9
View File
@@ -6216,8 +6216,9 @@ static void cmd_track_add(void *p)
struct MPContext *mpctx = cmd->mpctx;
int type = *(int *)cmd->priv;
int select = cmd->args[1].v.i & 3;
bool is_albumart = type == STREAM_VIDEO && cmd->args[4].v.b;
bool hearing_impaired = cmd->args[1].v.i & 4;
enum track_flags flags = cmd->args[1].v.i & ~3;
if (type == STREAM_VIDEO && cmd->args[4].v.b)
flags |= TRACK_ATTACHED_PICTURE;
if (mpctx->stop_play) {
cmd->success = false;
@@ -6237,7 +6238,7 @@ static void cmd_track_add(void *p)
}
}
int first = mp_add_external_file(mpctx, cmd->args[0].v.s, type,
cmd->abort->cancel, is_albumart, hearing_impaired);
cmd->abort->cancel, flags);
if (first < 0) {
cmd->success = false;
return;
@@ -6300,11 +6301,13 @@ static void cmd_track_reload(void *p)
if (t && t->is_external && t->external_filename) {
char *filename = talloc_strdup(NULL, t->external_filename);
bool is_albumart = t->attached_picture;
bool hearing_impaired = t->hearing_impaired_track;
enum track_flags flags = 0;
flags |= t->attached_picture ? TRACK_ATTACHED_PICTURE : 0;
flags |= t->hearing_impaired_track ? TRACK_HEARING_IMPAIRED : 0;
flags |= t->visual_impaired_track ? TRACK_VISUAL_IMPAIRED : 0;
mp_remove_track(mpctx, t);
nt_num = mp_add_external_file(mpctx, filename, type, cmd->abort->cancel,
is_albumart, hearing_impaired);
flags);
talloc_free(filename);
}
@@ -7151,7 +7154,8 @@ const struct mp_cmd_def mp_cmds[] = {
{"url", OPT_STRING(v.s)},
{"flags", OPT_FLAGS(v.i,
{"select", 0}, {"auto", 1}, {"cached", 2},
{"hearing-impaired", 1 << 4}),
{"hearing-impaired", TRACK_HEARING_IMPAIRED},
{"visual-impaired", TRACK_VISUAL_IMPAIRED}),
.flags = MP_CMD_OPT_ARG},
{"title", OPT_STRING(v.s), .flags = MP_CMD_OPT_ARG},
{"lang", OPT_STRING(v.s), .flags = MP_CMD_OPT_ARG},
@@ -7166,7 +7170,8 @@ const struct mp_cmd_def mp_cmds[] = {
{"url", OPT_STRING(v.s)},
{"flags", OPT_FLAGS(v.i,
{"select", 0}, {"auto", 1}, {"cached", 2},
{"hearing-impaired", 1 << 4}),
{"hearing-impaired", TRACK_HEARING_IMPAIRED},
{"visual-impaired", TRACK_VISUAL_IMPAIRED}),
.flags = MP_CMD_OPT_ARG},
{"title", OPT_STRING(v.s), .flags = MP_CMD_OPT_ARG},
{"lang", OPT_STRING(v.s), .flags = MP_CMD_OPT_ARG},
@@ -7181,7 +7186,8 @@ const struct mp_cmd_def mp_cmds[] = {
{"url", OPT_STRING(v.s)},
{"flags", OPT_FLAGS(v.i,
{"select", 0}, {"auto", 1}, {"cached", 2},
{"hearing-impaired", 1 << 4}),
{"hearing-impaired", TRACK_HEARING_IMPAIRED},
{"visual-impaired", TRACK_VISUAL_IMPAIRED}),
.flags = MP_CMD_OPT_ARG},
{"title", OPT_STRING(v.s), .flags = MP_CMD_OPT_ARG},
{"lang", OPT_STRING(v.s), .flags = MP_CMD_OPT_ARG},
+7 -1
View File
@@ -491,6 +491,12 @@ struct mp_abort_entry {
#define WHITE_CIRCLE "\xe2\x97\x8b"
#define BLACK_CIRCLE "\xe2\x97\x8f"
enum track_flags {
TRACK_ATTACHED_PICTURE = 1 << 0,
TRACK_HEARING_IMPAIRED = 1 << 2,
TRACK_VISUAL_IMPAIRED = 1 << 3,
};
// audio.c
void reset_audio_state(struct MPContext *mpctx);
void reinit_audio_chain(struct MPContext *mpctx);
@@ -529,7 +535,7 @@ void mp_abort_trigger_locked(struct MPContext *mpctx,
struct mp_abort_entry *abort);
int mp_add_external_file(struct MPContext *mpctx, char *filename,
enum stream_type filter, struct mp_cancel *cancel,
bool cover_art, bool hearing_impaired);
enum track_flags flags);
void mark_track_selection(struct MPContext *mpctx, int order,
enum stream_type type, int value);
#define FLAG_MARK_SELECTION 1
+9 -6
View File
@@ -826,7 +826,7 @@ bool mp_remove_track(struct MPContext *mpctx, struct track *track)
// the demuxer is changed to be slaved to mpctx->playback_abort instead.
int mp_add_external_file(struct MPContext *mpctx, char *filename,
enum stream_type filter, struct mp_cancel *cancel,
bool cover_art, bool hearing_impaired)
enum track_flags flags)
{
struct MPOpts *opts = mpctx->opts;
if (!filename || mp_cancel_test(cancel))
@@ -915,9 +915,10 @@ int mp_add_external_file(struct MPContext *mpctx, char *filename,
t->external_filename = mp_normalize_user_path(t, mpctx->global, filename);
t->no_default = sh->type != filter;
t->no_auto_select = t->no_default;
t->hearing_impaired_track = hearing_impaired;
t->hearing_impaired_track = flags & TRACK_HEARING_IMPAIRED;
t->visual_impaired_track = flags & TRACK_VISUAL_IMPAIRED;
// if we found video, and we are loading cover art, flag as such.
t->attached_picture = t->type == STREAM_VIDEO && cover_art;
t->attached_picture = t->type == STREAM_VIDEO && (flags & TRACK_ATTACHED_PICTURE);
if (first_num < 0 && (filter == STREAM_TYPE_COUNT || sh->type == filter))
first_num = mpctx->num_tracks - 1;
}
@@ -946,7 +947,7 @@ static void open_external_files(struct MPContext *mpctx, char **files,
for (int n = 0; files && files[n]; n++)
// when given filter is set to video, we are loading up cover art
mp_add_external_file(mpctx, files[n], filter, mpctx->playback_abort,
filter == STREAM_VIDEO, false);
filter == STREAM_VIDEO ? TRACK_ATTACHED_PICTURE : 0);
talloc_free(tmp);
}
@@ -986,9 +987,11 @@ void autoload_external_files(struct MPContext *mpctx, struct mp_cancel *cancel)
if (e->type == STREAM_VIDEO && (sc[STREAM_VIDEO] || !sc[STREAM_AUDIO]))
goto skip;
enum track_flags flags = 0;
flags |= e->hearing_impaired ? TRACK_HEARING_IMPAIRED : 0;
// when given filter is set to video, we are loading up cover art
int first = mp_add_external_file(mpctx, e->fname, e->type, cancel,
e->type == STREAM_VIDEO, e->hearing_impaired);
flags |= e->type == STREAM_VIDEO ? TRACK_ATTACHED_PICTURE : 0;
int first = mp_add_external_file(mpctx, e->fname, e->type, cancel, flags);
if (first < 0)
goto skip;