changeset 10917:d45870f67728

Forced subtitles patch by Arne Driescher <driescher@mpi-magdeburg.mpg.de> For a given subtitle language you can now chose to display only the forced subtitles. Defaut is set to "show all subtitles" so that current mplayer behaviour is not changed. For DVD: Use -forced_subs_only additionally to e.g. -slang en if you are only interested in the forced subtitles. For VobSub: The idx file is now parsed for the "forced subs: ON/OFF" tag and used according to its settings. Key: You can toggle the display of forced subtitles by pressing "F" (upper case letter).
author attila
date Sun, 21 Sep 2003 14:21:43 +0000
parents c36db88bfbc4
children d2dc9562422e
files DOCS/de/mplayer.1 DOCS/en/mplayer.1 cfg-mplayer.h input/input.c input/input.h mplayer.c spudec.c spudec.h vobsub.c vobsub.h
diffstat 10 files changed, 95 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/de/mplayer.1	Sun Sep 21 13:20:06 2003 +0000
+++ b/DOCS/de/mplayer.1	Sun Sep 21 14:21:43 2003 +0000
@@ -923,6 +923,9 @@
 .PD 1
 .
 .TP
+.B \-forcedsubsonly
+Nur "erzwungene" DVD-Untertitel in der z.B. mit \-slang gewähten Sprache darstellen. 
+.TP
 .B \-noautosub
 Deaktiviert das automatische Laden von Untertiteln.
 .TP
@@ -1126,6 +1129,9 @@
 .PD 1
 .
 .TP
+.B \-forcedsubsonly
+Display only "forced subtitles" for the DVD subtitle stream selected by e.g. \-slang.
+.TP
 .B \-spugauss <0.0\-3.0>
 Varianzparameter der Gaußschen Unschärfe bei \-spuaa 4. Höhere Werte stehen
 für mehr Unschärfe. Der Standardwert ist 1.0.
@@ -3346,6 +3352,8 @@
 de\-/\:aktiviert die Anzeige von Untertiteln
 .IPs j\ \ \ \ 
 schaltet durch die vorhandenen Untertitelsprachen
+.IPs F\ \ \ \ 
+de\-/\:aktiviert "erzwungene Untertitel"
 .IPs a\ \ \ \ 
 wechselt die Ausrichtung der Untertitel: oben, mittig, unten
 .IPs "z und x"
--- a/DOCS/en/mplayer.1	Sun Sep 21 13:20:06 2003 +0000
+++ b/DOCS/en/mplayer.1	Sun Sep 21 14:21:43 2003 +0000
@@ -287,6 +287,8 @@
 toggle subtitle visibility
 .IPs j\ \ \ \ 
 switch subtitle language
+.IP F\ \ \ \ 
+toggle display of "forced subtitles"
 .IPs a\ \ \ \ 
 toggle subtitle aligment: top/middle/bottom
 .IPs "z and x"
@@ -1121,6 +1123,10 @@
 .PD 1
 .
 .TP
+.B \-forcedsubsonly
+Display only "forced subtitles" for the DVD subtitle stream selected by e.g.
+\-slang.
+.TP
 .B \-fribidi_charset <charset\ name>
 Specifies the charset that will be passed to FriBiDi when decoding a non-utf8
 subtitles. Default is "ISO8859-8".
--- a/cfg-mplayer.h	Sun Sep 21 13:20:06 2003 +0000
+++ b/cfg-mplayer.h	Sun Sep 21 14:21:43 2003 +0000
@@ -347,6 +347,7 @@
 	// these should be moved to -common, and suppot in mencoder too
 	{"vobsub", &vobsub_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
 	{"vobsubid", &vobsub_id, CONF_TYPE_INT, CONF_RANGE, 0, 31, NULL},
+        {"forcedsubsonly", &forced_subs_only,CONF_TYPE_FLAG, 0, 0, 1, NULL},
 
 	{"sstep", &step_sec, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
 
--- a/input/input.c	Sun Sep 21 13:20:06 2003 +0000
+++ b/input/input.c	Sun Sep 21 14:21:43 2003 +0000
@@ -93,6 +93,7 @@
   { MP_CMD_TV_SET_HUE, "tv_set_hue", 1,  { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
   { MP_CMD_TV_SET_SATURATION, "tv_set_saturation", 1,  { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
 #endif
+  { MP_CMD_SUB_FORCED_ONLY, "forced_subs_only",  0, { {-1,{0}} } },
 #ifdef HAS_DVBIN_SUPPORT
   { MP_CMD_DVB_SET_CHANNEL, "dvb_set_channel", 1, { { MP_CMD_ARG_INT, {0}}, {-1,{0}}  }},
 #endif
@@ -300,6 +301,7 @@
   { { 'a', 0 }, "sub_alignment" },
   { { 'v', 0 }, "sub_visibility" },
   { { 'j', 0 }, "vobsub_lang" },
+  { { 'F', 0 }, "forced_subs_only" },
 #ifdef USE_EDL
   { { 'i', 0 }, "edl_mark" },
 #endif
--- a/input/input.h	Sun Sep 21 13:20:06 2003 +0000
+++ b/input/input.h	Sun Sep 21 14:21:43 2003 +0000
@@ -51,6 +51,7 @@
 #define MP_CMD_TV_SET_SATURATION 47
 #define MP_CMD_GET_VO_FULLSCREEN 48
 #define MP_CMD_GET_SUB_VISIBILITY 49
+#define MP_CMD_SUB_FORCED_ONLY 50
 
 #define MP_CMD_GUI_EVENTS       5000
 #define MP_CMD_GUI_LOADFILE     5001
--- a/mplayer.c	Sun Sep 21 13:20:06 2003 +0000
+++ b/mplayer.c	Sun Sep 21 14:21:43 2003 +0000
@@ -243,6 +243,7 @@
 char* dvdsub_lang=NULL;
 static char* spudec_ifo=NULL;
 char* filename=NULL; //"MI2-Trailer.avi";
+int forced_subs_only=0;
 
 // cache2:
        int stream_cache_size=-1;
@@ -1256,6 +1257,8 @@
       sub_auto=0; // don't do autosub for textsubs if vobsub found
       inited_flags|=INITED_VOBSUB;
       vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
+      // check if vobsub requested only to display forced subtitles
+      forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
     }
 
 //============ Open & Sync STREAM --- fork cache2 ====================
@@ -1597,6 +1600,10 @@
 
 }
 
+// Apply current settings for forced subs
+if (vo_spudec!=NULL)
+  spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
+
 #ifdef USE_SUB
 if(sh_video) {
 // after reading video params we should load subtitles because
@@ -3063,6 +3070,12 @@
     }
 #endif
         break;
+    case MP_CMD_SUB_FORCED_ONLY:
+      if (vo_spudec) {
+	forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
+	spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
+      }    
+      break;
     case MP_CMD_SCREENSHOT :
       if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
       break;
--- a/spudec.c	Sun Sep 21 13:20:06 2003 +0000
+++ b/spudec.c	Sun Sep 21 14:21:43 2003 +0000
@@ -89,6 +89,8 @@
   int font_start_level;  /* Darkest value used for the computed font */
   vo_functions_t *hw_spu;
   int spu_changed;
+  unsigned int forced_subs_only;     /* flag: 0=display all subtitle, !0 display only forced subtitles */
+  unsigned int is_forced_sub;         /* true if current subtitle is a forced subtitle */
 } spudec_handle_t;
 
 static void spudec_queue_packet(spudec_handle_t *this, packet_t *packet)
@@ -371,8 +373,10 @@
 	/* Menu ID, 1 byte */
 	mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Menu ID\n");
         /* shouldn't a Menu ID type force display start? */
-	//this->start_pts = pts100 + date;
-	//this->end_pts = UINT_MAX;
+	start_pts = pts100 + date;
+	end_pts = UINT_MAX;
+	display = 1;
+	this->is_forced_sub=~0; // current subtitle is forced
 	break;
       case 0x01:
 	/* Start display */
@@ -380,6 +384,7 @@
 	start_pts = pts100 + date;
 	end_pts = UINT_MAX;
 	display = 1;
+	this->is_forced_sub=0;
 	break;
       case 0x02:
 	/* Stop display */
@@ -604,6 +609,14 @@
     return ret;
 }
 
+void spudec_set_forced_subs_only(void * const this, const unsigned int flag)
+{
+  if(this){
+      ((spudec_handle_t *)this)->forced_subs_only=flag;
+      mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPU: Display only forced subs now %s\n", flag ? "enabled": "disabled");
+  }
+}
+
 void spudec_draw(void *this, void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride))
 {
     spudec_handle_t *spu = (spudec_handle_t *)this;
@@ -752,7 +765,14 @@
   spudec_handle_t *spu = (spudec_handle_t *)me;
   scale_pixel *table_x;
   scale_pixel *table_y;
+
   if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts) {
+
+    // check if only forced subtitles are requested 
+    if( (spu->forced_subs_only) && !(spu->is_forced_sub) ){ 
+	return;
+    }
+
     if (!(spu_aamode&16) && (spu->orig_frame_width == 0 || spu->orig_frame_height == 0
 	|| (spu->orig_frame_width == dxs && spu->orig_frame_height == dys))) {
       if (spu->image)
@@ -1125,6 +1145,9 @@
       memcpy(this->cuspal, cuspal, sizeof(this->cuspal));
       this->auto_palette = 0;
     }
+    // forced subtitles default: show all subtitles
+    this->forced_subs_only=0;
+    this->is_forced_sub=0;
   }
   else
     mp_msg(MSGT_SPUDEC,MSGL_FATAL, "FATAL: spudec_init: calloc");
--- a/spudec.h	Sun Sep 21 13:20:06 2003 +0000
+++ b/spudec.h	Sun Sep 21 14:21:43 2003 +0000
@@ -19,5 +19,6 @@
 int spudec_changed(void *this);
 void spudec_calc_bbox(void *me, unsigned int dxs, unsigned int dys, unsigned int* bbox);
 void spudec_draw_scaled(void *me, unsigned int dxs, unsigned int dys, void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
+void spudec_set_forced_subs_only(void * const this, const unsigned int flag);
 #endif
 
--- a/vobsub.c	Sun Sep 21 13:20:06 2003 +0000
+++ b/vobsub.c	Sun Sep 21 14:21:43 2003 +0000
@@ -576,6 +576,7 @@
     unsigned int have_palette;
     unsigned int orig_frame_width, orig_frame_height;
     unsigned int origin_x, origin_y;
+    unsigned int forced_subs;
     /* index */
     packet_queue_t *spu_streams;
     unsigned int spu_streams_size;
@@ -888,6 +889,26 @@
 }
 
 static int
+vobsub_parse_forced_subs(vobsub_t *vob, const char *line)
+{
+    const char *p;
+
+    p  = line;
+    while (isspace(*p))
+	++p;
+
+    if (strncasecmp("on",p,2) == 0){
+	    vob->forced_subs=~0;
+	    return 0;
+    } else if (strncasecmp("off",p,3) == 0){
+	    vob->forced_subs=0;
+	    return 0;
+    }
+	
+    return -1;
+}
+
+static int
 vobsub_parse_one_line(vobsub_t *vob, rar_stream_t *fd)
 {
     ssize_t line_size;
@@ -920,6 +941,8 @@
 	else if (strncmp("custom colors:", line, 14) == 0)
 	    //custom colors: ON/OFF, tridx: XXXX, colors: XXXXXX, XXXXXX, XXXXXX,XXXXXX
 	    res = vobsub_parse_cuspal(vob, line) + vobsub_parse_tridx(line) + vobsub_parse_custom(vob, line);
+	else if (strncmp("forced subs:", line, 12) == 0)
+		res = vobsub_parse_forced_subs(vob, line + 12);
 	else {
 	    mp_msg(MSGT_VOBSUB,MSGL_V, "vobsub: ignoring %s", line);
 	    continue;
@@ -1017,6 +1040,7 @@
 	vob->spu_streams_size = 0;
 	vob->spu_streams_current = 0;
 	vob->delay = 0;
+	vob->forced_subs=0;
 	buf = malloc((strlen(name) + 5) * sizeof(char));
 	if (buf) {
 	    rar_stream_t *fd;
@@ -1149,6 +1173,15 @@
     return (index < vob->spu_streams_size) ? vob->spu_streams[index].id : NULL;
 }
 
+unsigned int 
+vobsub_get_forced_subs_flag(void const * const vobhandle)
+{
+  if (vobhandle)
+    return ((vobsub_t*) vobhandle)->forced_subs;
+  else
+    return 0;
+}
+
 int
 vobsub_set_from_lang(void *vobhandle, unsigned char * lang)
 {
@@ -1256,6 +1289,9 @@
 	}
 	putc('\n', me->fidx);
     }
+
+    fprintf(me->fidx,"# ON: displays only forced subtitles, OFF: shows everything\n"
+	    "forced subs: OFF\n");
 }
 
 void *
--- a/vobsub.h	Sun Sep 21 13:20:06 2003 +0000
+++ b/vobsub.h	Sun Sep 21 14:21:43 2003 +0000
@@ -14,5 +14,7 @@
 extern void vobsub_out_output(void *me, const unsigned char *packet, int len, double pts);
 extern void vobsub_out_close(void *me);
 extern int vobsub_set_from_lang(void *vobhandle, unsigned char * lang);
+extern unsigned int vobsub_get_forced_subs_flag(void const * const vobhandle);
+
 #endif /* MPLAYER_VOBSUB_H */