[MPlayer-dev-eng] [PATCH] subtitle reload, slave mode - 2nd try

Salvatore Falco sfalco at studenti.ing.uniroma1.it
Tue Oct 12 15:24:38 CEST 2004


On Tue, Oct 12, 2004 at 11:08:28AM +0200, Salvatore Falco wrote:
> Hello.
> 
> This patch adds a new slave command (and related documentation):
> 
> sub_reload <search_file> <replace_file>
>     Substitutes subtitles from file with absolute path <search> with subtitles from
>     file with absolute path <replace>
> 
> Therefore it is possible to update text subtitles during video playback.
> Main aim of this patch is to support projects such as KSubtile
> (http://ksubtile.sourceforge.net/), which is a subtitle management software,
> and currently under development.
> 
>     Best regards,
> 	Salvatore Falco
-------------- 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-12 14:18:12.709993808 +0200
@@ -48,6 +48,10 @@
 sub_step
     ???
 
+sub_reload <search> <replace>
+    Substitutes subtitles from file with path <search> with subtitles from
+    file with path <replace>
+
 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-12 14:18:12.710993656 +0200
@@ -152,6 +152,7 @@
 "  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_SubFileReloaded "SUB: removed subtitle file %s, added subtitle file %s\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-12 14:18:12.711993504 +0200
@@ -137,6 +137,7 @@
 "  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_SubFileReloaded "SUB: rimossi sottotitoli del file %s, aggiunti sottotitoli del file %s\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-12 14:18:12.712993352 +0200
@@ -77,6 +77,7 @@
   { 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_RELOAD, "sub_reload", 2, { {MP_CMD_ARG_STRING,{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-12 14:18:12.712993352 +0200
@@ -57,6 +57,7 @@
 #define MP_CMD_VO_ROOTWIN 53
 #define MP_CMD_SWITCH_VSYNC 54
 #define MP_CMD_SWITCH_RATIO 55
+#define MP_CMD_SUB_RELOAD 56
 
 #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-12 14:18:12.716992744 +0200
@@ -725,6 +725,33 @@
     mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
 }
 
+/** \brief reloads the subtitle file during playback - only used in slave mode
+    \param search the to the old subtitle file, which needs to be updated
+    \param replace the path to the new subtitle file
+ */
+void reload_subtitles_file(char *search, char *replace)
+{
+    sub_data *subd, *sub_search;
+    int counter;
+
+    if (search == NULL || replace == NULL) return;
+
+    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(replace, sh_video->fps);
+	if(!subd) {
+	    mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, replace);
+	    break;
+	}
+	if (subdata == set_of_subtitles[counter]) subdata = subd;
+	sub_free(set_of_subtitles[counter]);
+	set_of_subtitles[counter] = subd;
+	mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_SubFileReloaded, search, replace);
+	break;
+    }
+}
+
 // 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.
@@ -3143,6 +3170,15 @@
       }
 #endif
     } break;
+    case MP_CMD_SUB_RELOAD:
+    {
+#ifdef USE_SUB
+	if (sh_video) {
+	    reload_subtitles_file(cmd->args[0].v.s, cmd->args[1].v.s);
+	    vo_osd_changed(OSDTYPE_SUBTITLE);
+	}
+#endif
+    } break;
     case MP_CMD_SUB_VISIBILITY:
     {
 #ifdef USE_SUB


More information about the MPlayer-dev-eng mailing list