[MPlayer-dev-eng] [PATCH] ogm subtitle text streams will be passed through iconv()

Kresimir Kukulj madmax at iskon.hr
Thu Nov 28 00:18:29 CET 2002


Normal subtitles (in a separate file) are read and passed through
subcp_recode() which translates subtitle between eg. latin2 and cp1250
codepages.
Subtitles in ogm container are processed on-the-fly and displayed.
This patch adds a call to subcp_recode1(), so this subtitles too are
processed through iconv().
This is usefull if you use ogmtools to produce ogm with audio/video and
subtitle muxed in ogg stream. If your subtitles (subrip format only) are
encoded in cp1250 codepage (and you have to use that codepage to be
compatible with windows OGGDS), mplayer will not display some charaters
correctly (because it probably treats them as latin2).

I couldn't use subcp_recode() because it reallocates memory buffer for
sub->text[x], and demux_ogg_init_sub allocates fixed buffers and expects
them not to change size during the playback.

This is a somewhat ugly, but the rest of iconv() stuff is a bit messy
anyway.

-- 
Kresimir Kukulj                      madmax at iskon.hr
+--------------------------------------------------+
Old PC's never die. They just become Unix terminals.
-------------- next part --------------
diff -ruN main-cvs20021126/libmpdemux/demux_ogg.c main/libmpdemux/demux_ogg.c
--- main-cvs20021126/libmpdemux/demux_ogg.c	Thu Nov  7 00:54:26 2002
+++ main/libmpdemux/demux_ogg.c	Wed Nov 27 23:31:53 2002
@@ -16,6 +16,10 @@
 #include <ogg/ogg.h>
 #include <vorbis/codec.h>
 
+#ifdef USE_ICONV
+#include <iconv.h>
+#endif
+
 #define BLOCK_SIZE 4096
 
 /// Vorbis decoder context : we need the vorbis_info for vorbis timestamping
@@ -170,6 +174,33 @@
   return (ret);
 }
 
+#ifdef USE_ICONV
+static char icbuffer[OGG_SUB_MAX_LINE];
+extern iconv_t icdsc;
+static subtitle* subcp_recode1 (subtitle *sub)
+{
+  int l=sub->lines;
+  size_t ileft, oleft;
+  char *op, *ip;
+
+  while (l){
+     ip = icbuffer;
+     op = sub->text[--l];
+     strcpy(ip, op);
+     ileft = strlen(ip);
+     oleft = OGG_SUB_MAX_LINE - 1;
+		
+     if (iconv(icdsc, &ip, &ileft,
+	      &op, &oleft) == (size_t)(-1)) {
+	mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: error recoding line.\n");
+	return sub;
+     }
+     *op='\0' ;
+  }
+  return sub;
+}
+#endif
+
 void demux_ogg_init_sub () {
   int lcv;
   if(!ogg_sub.text[0]) // not yet allocated
@@ -221,6 +252,9 @@
 
   mp_msg(MSGT_DEMUX,MSGL_DBG2,"ogg sub lines: %d  first: '%s'\n",
       ogg_sub.lines, ogg_sub.text[0]);
+#ifdef USE_ICONV
+  subcp_recode1(&ogg_sub);
+#endif
   vo_sub = &ogg_sub;
   vo_osd_changed(OSDTYPE_SUBTITLE);
 }
@@ -455,6 +489,10 @@
   sh_audio_t* sh_a;
   sh_video_t* sh_v;
 
+#ifdef USE_ICONV
+  subcp_open();
+#endif
+
   s = demuxer->stream;
 
   ogg_d = (ogg_demuxer_t*)calloc(1,sizeof(ogg_demuxer_t));
@@ -995,6 +1033,10 @@
 
   if(!ogg_d)
     return;
+
+#ifdef USE_ICONV
+  subcp_close();
+#endif
 
   if(ogg_d->subs)
     free(ogg_d->subs);
diff -ruN main-cvs20021126/subreader.c main/subreader.c
--- main-cvs20021126/subreader.c	Sat Nov 16 04:25:37 2002
+++ main/subreader.c	Wed Nov 27 23:34:06 2002
@@ -852,7 +852,7 @@
 extern float sub_fps;
 
 #ifdef USE_ICONV
-static iconv_t icdsc;
+iconv_t icdsc;
 
 void	subcp_open (void)
 {


More information about the MPlayer-dev-eng mailing list