[MPlayer-dev-eng] [PATCH] subtitle reload, slave mode - 4th try
Salvatore Falco
sfalco at studenti.ing.uniroma1.it
Mon Oct 25 13:50:12 CEST 2004
This patch adds three new slave commands:
sub_load <subtitles_file>
Loads the subtitles from file <subtitles_file>, and adds them to the
subtitles list.
sub_reload <add_subtitles_file> [<remove_subtitles_file>]
If only <add_subtitles_file> argument is provided, subtitles from this
file are reloaded; if <remove_subtitles_file> argument is provided,
subtitles from <add_subtitles_file> replace those from <remove_subtitles_file>.
sub_remove [<subtitles_file>]
If <subtitles_file> argument is present, the command removes the subtitles
loaded from this file; if no argument is provided, all the subtitles
are removed.
I have tested the patch, and it works. However I noticed a bug in the subs
rendering: if the subtitles are removed when a subtitle is displaying, the subtitle
keeps on being displaying for ever - even if the command issues a vo_osd_changed(OSDTYPE_SUBTITLE).
I tried looking for this bug, but, currently, I can't find it.
Best regards, Salvatore Falco
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-------------- next part --------------
diff -Nur MPlayer-20041012/DOCS/tech/slave.txt MPlayer-20041012.patched/DOCS/tech/slave.txt
--- MPlayer-20041012/DOCS/tech/slave.txt 2004-09-19 20:36:18.000000000 +0200
+++ MPlayer-20041012.patched/DOCS/tech/slave.txt 2004-10-23 00:12:55.044639240 +0200
@@ -48,6 +48,20 @@
sub_step
???
+sub_load <subtitles_file>
+ Loads the subtitles from file <subtitles_file>, and adds them to the
+ subtitles list.
+
+sub_reload <add_subtitles_file> [<remove_subtitles_file>]
+ If only <add_subtitles_file> argument is provided, subtitles from this
+ file are reloaded; if <remove_subtitles_file> argument is provided,
+ subtitles from <add_subtitles_file> replace those from <remove_subtitles_file>.
+
+sub_remove [<subtitles_file>]
+ If <subtitles_file> argument is present, the command removes the subtitles
+ loaded from this file; if no argument is provided, all the subtitles
+ are removed.
+
osd [<level>]
Toggle OSD mode or set it to level when <level> >= 0.
diff -Nur MPlayer-20041012/help/help_mp-en.h MPlayer-20041012.patched/help/help_mp-en.h
--- MPlayer-20041012/help/help_mp-en.h 2004-10-09 22:04:27.000000000 +0200
+++ MPlayer-20041012.patched/help/help_mp-en.h 2004-10-23 01:18:28.191710000 +0200
@@ -151,7 +151,11 @@
" DOCS/HTML/en/bugreports.html and follow the instructions there. We can't and\n"\
" won't help unless you provide this information when reporting a possible bug.\n"
#define MSGTR_LoadingConfig "Loading config '%s'\n"
-#define MSGTR_AddedSubtitleFile "SUB: added subtitle file (%d): %s\n"
+#define MSGTR_AddedSubtitleFile "SUB: added (position %d) subtitles from file [%s]\n"
+#define MSGTR_SubtitleFileNotFound "SUB: subtitles from file [%s] not found\n"
+#define MSGTR_SubtitleFileReloaded "SUB: reloaded subtitles file [%s] (in place of [%s])\n"
+#define MSGTR_SubtitleFileRemoved "SUB: removed subtitles file [%s]\n"
+#define MSGTR_SubtitleFilesRemoved "SUB: removed all subtitles files\n"
#define MSGTR_ErrorOpeningOutputFile "Error opening file [%s] for writing!\n"
#define MSGTR_CommandLine "CommandLine:"
#define MSGTR_RTCDeviceNotOpenable "Failed to open %s: %s (it should be readable by the user.)\n"
diff -Nur MPlayer-20041012/help/help_mp-it.h MPlayer-20041012.patched/help/help_mp-it.h
--- MPlayer-20041012/help/help_mp-it.h 2004-10-07 02:14:23.000000000 +0200
+++ MPlayer-20041012.patched/help/help_mp-it.h 2004-10-23 01:17:40.249998248 +0200
@@ -137,6 +137,11 @@
" versione di gcc. Se ritieni sia colpa di MPlayer, leggi DOCS/it/bugreports.html\n"\
" e segui le istruzioni. Non possiamo aiutarti, e non lo faremo, se non\n"\
" fornisci queste informazioni quando segnali un possibile problema.\n"
+#define MSGTR_AddedSubtitleFile "SUB: aggiunti (in posizione %d) i sottotitoli dal file [%s]\n"
+#define MSGTR_SubtitleFileNotFound "SUB: sottotitoli del file [%s] non trovati\n"
+#define MSGTR_SubtitleFileReloaded "SUB: ricaricati i sottotitoli del file [%s] (al posto di [%s])\n"
+#define MSGTR_SubtitleFileRemoved "SUB: rimossi i sottotitoli del file [%s]\n"
+#define MSGTR_SubtitleFilesRemoved "SUB: rimossi tutti i sottotitoli\n"
// mencoder.c:
diff -Nur MPlayer-20041012/input/input.c MPlayer-20041012.patched/input/input.c
--- MPlayer-20041012/input/input.c 2004-10-10 19:39:06.000000000 +0200
+++ MPlayer-20041012.patched/input/input.c 2004-10-22 22:52:22.565287768 +0200
@@ -77,6 +77,9 @@
{ MP_CMD_SUB_POS, "sub_pos", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_SUB_ALIGNMENT, "sub_alignment",0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
{ MP_CMD_SUB_VISIBILITY, "sub_visibility", 0, { {-1,{0}} } },
+ { MP_CMD_SUB_LOAD, "sub_load", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } },
+ { MP_CMD_SUB_RELOAD, "sub_reload", 1, { {MP_CMD_ARG_STRING,{0}}, {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } },
+ { MP_CMD_SUB_REMOVE, "sub_remove", 0, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } },
{ MP_CMD_SUB_SELECT, "vobsub_lang", 0, { {-1,{0}} } }, // for compatibility
{ MP_CMD_SUB_SELECT, "sub_select", 0, { {-1,{0}} } },
{ MP_CMD_GET_PERCENT_POS, "get_percent_pos", 0, { {-1,{0}} } },
diff -Nur MPlayer-20041012/input/input.h MPlayer-20041012.patched/input/input.h
--- MPlayer-20041012/input/input.h 2004-10-10 19:39:06.000000000 +0200
+++ MPlayer-20041012.patched/input/input.h 2004-10-22 22:54:34.010305088 +0200
@@ -57,6 +57,9 @@
#define MP_CMD_VO_ROOTWIN 53
#define MP_CMD_SWITCH_VSYNC 54
#define MP_CMD_SWITCH_RATIO 55
+#define MP_CMD_SUB_LOAD 56
+#define MP_CMD_SUB_RELOAD 57
+#define MP_CMD_SUB_REMOVE 58
#define MP_CMD_GUI_EVENTS 5000
#define MP_CMD_GUI_LOADFILE 5001
diff -Nur MPlayer-20041012/mplayer.c MPlayer-20041012.patched/mplayer.c
--- MPlayer-20041012/mplayer.c 2004-10-10 19:39:07.000000000 +0200
+++ MPlayer-20041012.patched/mplayer.c 2004-10-23 01:25:48.648750352 +0200
@@ -725,6 +725,117 @@
mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
}
+/**
+ \brief adds a subtitles file during playback - only used in slave mode.
+ \param add_filename is the path to the subtitles file to load; if not found, no subtitles are added.
+ After a successful load, the command displays the loaded subtitles.
+ */
+void load_subtitles_file(char *add_filename)
+{
+ sub_data *subd;
+
+ if (set_of_sub_size >= MAX_SUBTITLE_FILES || add_filename == NULL) return;
+
+ subd = sub_read_file(strdup(add_filename), sh_video->fps);
+ if(subd == NULL) {
+ mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, add_filename);
+ return;
+ }
+ subdata = subd;
+ set_of_subtitles[set_of_sub_pos = set_of_sub_size] = subdata;
+ ++set_of_sub_size;
+ mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_AddedSubtitleFile, set_of_sub_size, add_filename);
+
+ return;
+}
+
+/**
+ \brief reloads a subtitles file during playback - only used in slave mode.
+ \param search is the path to the subtitle file which needs to be updated; if not found, no subtitles are added.
+ \param replace is the path to the new subtitle file; if equal to NULL, search is used in its place.
+ After a successful reload, the command displays the reloaded subtitles.
+ */
+void reload_subtitles_file(char *search, char *replace)
+{
+ sub_data *subd, *sub_search;
+ int counter;
+
+ if (search == NULL) return;
+ if (replace == NULL) replace = search;
+
+ for (counter = 0; counter < set_of_sub_size; ++counter) {
+ sub_search = set_of_subtitles[counter];
+ if (strcmp(search, sub_search->filename) != 0) continue;
+
+ subd = sub_read_file(strdup(replace), sh_video->fps);
+ if(!subd) {
+ mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, replace);
+ return;
+ }
+ subdata = subd;
+ sub_free(set_of_subtitles[counter]);
+ set_of_subtitles[set_of_sub_pos = counter] = subdata;
+ mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_SubtitleFileReloaded, replace, search);
+ return;
+ }
+ /* we didn't find the subtitles to reload */
+ mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_SubtitleFileNotFound, search);
+ return;
+}
+
+/**
+ \brief remove subtitles file/files during playback - only used in slave mode
+ \param remove_filename is the path the subtitles file to remove; if equal to NULL, all subtitles are removed
+ If only one subtitles file is removed, the \c set_of_subtitles structure is re-arranged, so all subtitles are consecutive,
+ and the first subtitles structure is displayed.
+ */
+void remove_subtitles_file(char *remove_filename)
+{
+ sub_data *sub_search;
+ int counter;
+ short remove_all = 0; /* false */
+ char *removed_file;
+
+ if (remove_filename == NULL) remove_all = 1;
+
+ for (counter = 0; counter < set_of_sub_size; ++counter) {
+ sub_search = set_of_subtitles[counter];
+ removed_file = strdup(sub_search->filename);
+ if ((remove_all) || (strcmp(remove_filename, sub_search->filename) == 0)) {
+ sub_free(sub_search);
+ set_of_subtitles[counter] = NULL;
+ if (remove_all) mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_SubtitleFileRemoved, removed_file);
+ else {
+ mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_SubtitleFileRemoved, removed_file);
+ break;
+ }
+ }
+ }
+
+ if (remove_all) {
+ set_of_sub_size = 0;
+ mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_SubtitleFilesRemoved);
+ } else {
+ if (counter >= set_of_sub_size) {
+ mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_SubtitleFileNotFound, remove_filename);
+ return;
+ }
+ /* re-arrange the set_of_subtitles structure, so that it does not contain a hole were the removed subtitles were */
+ for ( ; counter + 1 < set_of_sub_size ; ++counter) {
+ set_of_subtitles[counter] = set_of_subtitles[counter + 1];
+ set_of_subtitles[counter + 1] = NULL;
+ }
+ --set_of_sub_size;
+ }
+ if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
+ else {
+ subdata = NULL;
+ set_of_sub_size = 0;
+ set_of_sub_pos = -1;
+ }
+ return;
+}
+
// FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
void update_set_of_subtitles()
// subdata was changed, set_of_sub... have to be updated.
@@ -3153,6 +3264,35 @@
}
#endif
} break;
+ case MP_CMD_SUB_LOAD:
+ {
+#ifdef USE_SUB
+ if (sh_video) {
+ load_subtitles_file(cmd->args[0].v.s);
+ vo_osd_changed(OSDTYPE_SUBTITLE);
+ }
+#endif
+ } break;
+ case MP_CMD_SUB_RELOAD:
+ {
+#ifdef USE_SUB
+ if (sh_video) {
+ if (cmd->nargs > 1) reload_subtitles_file(cmd->args[1].v.s, cmd->args[0].v.s);
+ else reload_subtitles_file(cmd->args[0].v.s, NULL);
+ vo_osd_changed(OSDTYPE_SUBTITLE);
+ }
+#endif
+ } break;
+ case MP_CMD_SUB_REMOVE:
+ {
+#ifdef USE_SUB
+ if (sh_video) {
+ if (cmd->nargs > 0) remove_subtitles_file(cmd->args[0].v.s);
+ else remove_subtitles_file(NULL);
+ vo_osd_changed(OSDTYPE_SUBTITLE);
+ }
+#endif
+ } break;
case MP_CMD_GET_SUB_VISIBILITY:
{
#ifdef USE_SUB
More information about the MPlayer-dev-eng
mailing list