1
mirror of https://github.com/mpv-player/mpv synced 2024-12-28 06:03:45 +01:00

redone subcp_recode: get rid of static buffer, skip lines that failed to

convert instead of removing all remaining lines and remove subcp_recode1
since subcp_recode should now work just as well.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@20298 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2006-10-18 16:09:59 +00:00
parent 6d4ad204b2
commit 325912bf97
2 changed files with 12 additions and 46 deletions

View File

@ -293,7 +293,7 @@ void demux_ogg_add_sub (ogg_stream_t* os,ogg_packet* pack) {
mp_msg(MSGT_DEMUX,MSGL_DBG2,"Ogg sub lines: %d first: '%s'\n", mp_msg(MSGT_DEMUX,MSGL_DBG2,"Ogg sub lines: %d first: '%s'\n",
ogg_sub.lines, ogg_sub.text[0]); ogg_sub.lines, ogg_sub.text[0]);
#ifdef USE_ICONV #ifdef USE_ICONV
subcp_recode1(&ogg_sub); subcp_recode(&ogg_sub);
#endif #endif
vo_sub = &ogg_sub; vo_sub = &ogg_sub;
vo_osd_changed(OSDTYPE_SUBTITLE); vo_osd_changed(OSDTYPE_SUBTITLE);

View File

@ -1116,69 +1116,35 @@ void subcp_close (void)
} }
} }
#define ICBUFFSIZE 512 subtitle* subcp_recode (subtitle *sub)
static char icbuffer[ICBUFFSIZE];
static subtitle* subcp_recode (subtitle *sub)
{ {
int l=sub->lines; int l=sub->lines;
size_t ileft, oleft; size_t ileft, oleft;
char *op, *ip, *ot; char *op, *ip, *ot;
if(icdsc == (iconv_t)(-1)) return sub;
while (l){ while (l){
op = icbuffer;
ip = sub->text[--l]; ip = sub->text[--l];
ileft = strlen(ip); ileft = strlen(ip);
oleft = ICBUFFSIZE - 1; oleft = 4 * ileft;
if (!(ot = malloc(oleft + 1))){
mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: error allocating mem.\n");
continue;
}
op = ot;
if (iconv(icdsc, &ip, &ileft, if (iconv(icdsc, &ip, &ileft,
&op, &oleft) == (size_t)(-1)) { &op, &oleft) == (size_t)(-1)) {
mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: error recoding line (1).\n"); mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: error recoding line.\n");
l++; free(ot);
break; continue;
}
if (!(ot = malloc(op - icbuffer + 1))){
mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: error allocating mem.\n");
l++;
break;
} }
*op='\0' ; *op='\0' ;
strcpy (ot, icbuffer);
free (sub->text[l]); free (sub->text[l]);
sub->text[l] = ot; sub->text[l] = ot;
} }
if (l){
for (l = sub->lines; l;)
free (sub->text[--l]);
return ERR;
}
return sub; return sub;
} }
// for demux_ogg.c:
subtitle* subcp_recode1 (subtitle *sub)
{
int l=sub->lines;
size_t ileft, oleft;
if(icdsc == (iconv_t)(-1)) return sub;
while (l){
char *ip = icbuffer;
char *op = sub->text[--l];
strlcpy(ip, op, ICBUFFSIZE);
ileft = strlen(ip);
oleft = ICBUFFSIZE - 1;
if (iconv(icdsc, &ip, &ileft,
&op, &oleft) == (size_t)(-1)) {
mp_msg(MSGT_SUBREADER,MSGL_V,"SUB: error recoding line (2).\n");
return sub;
}
*op='\0' ;
}
return sub;
}
#endif #endif
#ifdef USE_FRIBIDI #ifdef USE_FRIBIDI