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

Salvatore Falco sfalco at studenti.ing.uniroma1.it
Tue Oct 12 11:08:28 CEST 2004


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-20041005/DOCS/tech/slave.txt MPlayer-20041005.patched/DOCS/tech/slave.txt
--- MPlayer-20041005/DOCS/tech/slave.txt	2004-09-19 20:36:18.000000000 +0200
+++ MPlayer-20041005.patched/DOCS/tech/slave.txt	2004-10-06 00:54:54.624997528 +0200
@@ -48,6 +48,10 @@
 sub_step
     ???
 
+sub_reload <search> <replace>
+    Substitutes subtitles from file with absolute path <search> with subtitles from
+    file with absolute path <replace>
+
 osd [<level>]
     Toggle OSD mode or set it to level when <level> >= 0.
 
diff -Nur MPlayer-20041005/input/input.c MPlayer-20041005.patched/input/input.c
--- MPlayer-20041005/input/input.c	2004-09-15 16:08:46.000000000 +0200
+++ MPlayer-20041005.patched/input/input.c	2004-10-06 00:55:28.288879840 +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-20041005/input/input.h MPlayer-20041005.patched/input/input.h
--- MPlayer-20041005/input/input.h	2004-09-15 11:45:34.000000000 +0200
+++ MPlayer-20041005.patched/input/input.h	2004-10-06 00:55:46.692082128 +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-20041005/mplayer.c MPlayer-20041005.patched/mplayer.c
--- MPlayer-20041005/mplayer.c	2004-09-28 16:00:48.000000000 +0200
+++ MPlayer-20041005.patched/mplayer.c	2004-10-06 01:26:33.695294960 +0200
@@ -725,6 +725,32 @@
     printf("SUB: added subtitle file (%d): %s\n", set_of_sub_size, filename);
 }
 
+/// \brief reloads the subtitle file during playback - only used in slave mode
+/// \param search the absolute path to the old subtitle file, which needs to be updated
+/// \param replace the absolute path to the new subtitle file
+void reload_subtitles_file(char *search, char *replace)
+{
+    sub_data *subd, *sub_search;
+    int counter;
+
+    if (filename == 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, "SUB: removed subtitle file %s, added subtitle file %s\n", 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.
@@ -3140,6 +3166,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