summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-15 20:26:52 +0100
committerwm4 <wm4@nowhere>2012-11-16 21:21:15 +0100
commitb7052b431c92c2babd032885701fb56dfd3ec452 (patch)
treecf4e45be7d61387cf831d28a19306a0cb4cbf194 /core
parentdd7dc2ee3d060d77dbafb3182127eb1a59c2d79f (diff)
downloadmpv-b7052b431c92c2babd032885701fb56dfd3ec452.tar.bz2
mpv-b7052b431c92c2babd032885701fb56dfd3ec452.tar.xz
command: add sub_reload and sub_remove commands
sub_remove remove an external subtitle track, for whatever this may be needed. sub_reload removes and re-adds an external subtitle track. Also rename sub_load to sub_add, because that seems to be more in line with sub_remove.
Diffstat (limited to 'core')
-rw-r--r--core/command.c25
-rw-r--r--core/input/input.c5
-rw-r--r--core/input/input.h4
-rw-r--r--core/mp_core.h5
-rw-r--r--core/mplayer.c43
5 files changed, 71 insertions, 11 deletions
diff --git a/core/command.c b/core/command.c
index f333f20f54..a9cba1800c 100644
--- a/core/command.c
+++ b/core/command.c
@@ -2205,12 +2205,33 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
break;
#endif /* CONFIG_TV */
- case MP_CMD_SUB_LOAD:
+ case MP_CMD_SUB_ADD:
if (sh_video) {
- add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
+ mp_add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
}
break;
+ case MP_CMD_SUB_REMOVE: {
+ struct track *sub = mp_track_by_tid(mpctx, STREAM_SUB, cmd->args[0].v.i);
+ if (sub)
+ mp_remove_track(mpctx, sub);
+ break;
+ }
+
+ case MP_CMD_SUB_RELOAD: {
+ struct track *sub = mp_track_by_tid(mpctx, STREAM_SUB, cmd->args[0].v.i);
+ if (sh_video && sub && sub->is_external && sub->external_filename)
+ {
+ struct track *nsub = mp_add_subtitles(mpctx, sub->external_filename,
+ sh_video->fps, 0);
+ if (nsub) {
+ mp_remove_track(mpctx, sub);
+ mp_switch_track(mpctx, nsub->type, nsub);
+ }
+ }
+ break;
+ }
+
case MP_CMD_SCREENSHOT:
screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i);
break;
diff --git a/core/input/input.c b/core/input/input.c
index 210aa54a4f..6d60211e65 100644
--- a/core/input/input.c
+++ b/core/input/input.c
@@ -144,7 +144,9 @@ static const mp_cmd_t mp_cmds[] = {
{ MP_CMD_PRINT_TEXT, "print_text", { ARG_STRING } },
{ MP_CMD_SHOW_TEXT, "show_text", { ARG_STRING, OARG_INT(-1), OARG_INT(0) } },
{ MP_CMD_SHOW_PROGRESS, "show_progress", },
- { MP_CMD_SUB_LOAD, "sub_load", { ARG_STRING } },
+ { MP_CMD_SUB_ADD, "sub_add", { ARG_STRING } },
+ { MP_CMD_SUB_REMOVE, "sub_remove", { OARG_INT(-1) } },
+ { MP_CMD_SUB_RELOAD, "sub_reload", { OARG_INT(-1) } },
{ MP_CMD_TV_START_SCAN, "tv_start_scan", },
{ MP_CMD_TV_STEP_CHANNEL, "tv_step_channel", { ARG_INT } },
@@ -231,6 +233,7 @@ static const struct legacy_cmd legacy_cmds[] = {
{"saturation", "add saturation"},
{"hue", "add hue"},
{"switch_vsync", "cycle vsync"},
+ {"sub_load", "sub_add"},
{"sub_select", "cycle sub"},
{"sub_pos", "add sub-pos"},
{"sub_delay", "add sub-delay"},
diff --git a/core/input/input.h b/core/input/input.h
index a1c633ad69..b86f51a1e7 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -47,7 +47,9 @@ enum mp_command_type {
MP_CMD_FRAME_STEP,
MP_CMD_SPEED_MULT,
MP_CMD_RUN,
- MP_CMD_SUB_LOAD,
+ MP_CMD_SUB_ADD,
+ MP_CMD_SUB_REMOVE,
+ MP_CMD_SUB_RELOAD,
MP_CMD_KEYDOWN_EVENTS,
MP_CMD_SET,
MP_CMD_GET_PROPERTY,
diff --git a/core/mp_core.h b/core/mp_core.h
index 910bfb82a4..6da6365ab6 100644
--- a/core/mp_core.h
+++ b/core/mp_core.h
@@ -100,6 +100,7 @@ struct track {
// If this track is from an external file (e.g. subtitle file).
bool is_external;
+ char *external_filename;
// If the track's stream changes with the timeline (ordered chapters).
bool under_timeline;
@@ -274,7 +275,8 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask);
void reinit_audio_chain(struct MPContext *mpctx);
void init_vo_spudec(struct MPContext *mpctx);
double playing_audio_pts(struct MPContext *mpctx);
-void add_subtitles(struct MPContext *mpctx, char *filename, float fps, int noerr);
+struct track *mp_add_subtitles(struct MPContext *mpctx, char *filename,
+ float fps, int noerr);
int reinit_video_chain(struct MPContext *mpctx);
void pause_player(struct MPContext *mpctx);
void unpause_player(struct MPContext *mpctx);
@@ -294,6 +296,7 @@ void mp_switch_track(struct MPContext *mpctx, enum stream_type type,
struct track *track);
struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
int tid);
+bool mp_remove_track(struct MPContext *mpctx, struct track *track);
// timeline/tl_matroska.c
void build_ordered_chapter_timeline(struct MPContext *mpctx);
diff --git a/core/mplayer.c b/core/mplayer.c
index 560733e6ab..39d5c37543 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -943,15 +943,15 @@ static void add_dvd_tracks(struct MPContext *mpctx)
#endif
}
-void add_subtitles(struct MPContext *mpctx, char *filename, float fps,
- int noerr)
+struct track *mp_add_subtitles(struct MPContext *mpctx, char *filename,
+ float fps, int noerr)
{
struct MPOpts *opts = &mpctx->opts;
sub_data *subd = NULL;
struct sh_sub *sh = NULL;
if (filename == NULL)
- return;
+ return NULL;
if (opts->ass_enabled) {
#ifdef CONFIG_ASS
@@ -976,7 +976,7 @@ void add_subtitles(struct MPContext *mpctx, char *filename, float fps,
if (!sh && !subd) {
mp_tmsg(MSGT_CPLAYER, noerr ? MSGL_WARN : MSGL_ERR,
"Cannot load subtitles: %s\n", filename);
- return;
+ return NULL;
}
struct track *track = talloc_ptrtype(NULL, track);
@@ -988,8 +988,10 @@ void add_subtitles(struct MPContext *mpctx, char *filename, float fps,
.is_external = true,
.sh_sub = talloc_steal(track, sh),
.subdata = talloc_steal(track, subd),
+ .external_filename = talloc_strdup(track, filename),
};
MP_TARRAY_APPEND(mpctx, mpctx->tracks, mpctx->num_tracks, track);
+ return track;
}
void init_vo_spudec(struct MPContext *mpctx)
@@ -1983,6 +1985,8 @@ void mp_switch_track(struct MPContext *mpctx, enum stream_type type,
struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
int tid)
{
+ if (tid == -1)
+ return mpctx->current_track[type];
for (int n = 0; n < mpctx->num_tracks; n++) {
struct track *track = mpctx->tracks[n];
if (track->type == type && track->user_tid == tid)
@@ -1991,6 +1995,32 @@ struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
return NULL;
}
+bool mp_remove_track(struct MPContext *mpctx, struct track *track)
+{
+ if (track->under_timeline)
+ return false;
+ if (!track->is_external)
+ return false;
+
+ if (mpctx->current_track[track->type] == track) {
+ mp_switch_track(mpctx, track->type, NULL);
+ if (mpctx->current_track[track->type] == track)
+ return false;
+ }
+
+ int index = 0;
+ while (index < mpctx->num_tracks && mpctx->tracks[index] != track)
+ index++;
+ assert(index < mpctx->num_tracks);
+ while (index + 1 < mpctx->num_tracks) {
+ mpctx->tracks[index] = mpctx->tracks[index + 1];
+ index++;
+ }
+ mpctx->num_tracks--;
+ talloc_free(track);
+ return true;
+}
+
/* Modify video timing to match the audio timeline. There are two main
* reasons this is needed. First, video and audio can start from different
* positions at beginning of file or after a seek (MPlayer starts both
@@ -3540,13 +3570,13 @@ static void open_subtitles_from_options(struct MPContext *mpctx)
double sub_fps = mpctx->sh_video ? mpctx->sh_video->fps : 25;
if (mpctx->opts.sub_name) {
for (int i = 0; mpctx->opts.sub_name[i] != NULL; ++i)
- add_subtitles(mpctx, mpctx->opts.sub_name[i], sub_fps, 0);
+ mp_add_subtitles(mpctx, mpctx->opts.sub_name[i], sub_fps, 0);
}
if (mpctx->opts.sub_auto) { // auto load sub file ...
char **tmp = find_text_subtitles(&mpctx->opts, mpctx->filename);
int nsub = MP_TALLOC_ELEMS(tmp);
for (int i = 0; i < nsub; i++)
- add_subtitles(mpctx, tmp[i], sub_fps, 1);
+ mp_add_subtitles(mpctx, tmp[i], sub_fps, 1);
talloc_free(tmp);
}
}
@@ -3596,6 +3626,7 @@ static void open_external_file(struct MPContext *mpctx, char *filename,
struct track *t = add_stream_track(mpctx, stream, false);
t->is_external = true;
t->title = talloc_strdup(t, filename);
+ t->external_filename = talloc_strdup(t, filename);
num_added++;
}
}