1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-15 11:31:02 +00:00

modifications to use iconv(3) function to recode text of subs (autodetect)

added option -subcp <cpname> # for example cp1250, latin2 etc.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2152 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
atlka 2001-10-10 13:07:42 +00:00
parent 8137a7a4b2
commit 0a5c47a028
3 changed files with 145 additions and 1 deletions

View File

@ -37,6 +37,9 @@ extern int vo_dbpp;
#ifdef USE_SUB
extern int sub_unicode;
extern int sub_utf8;
#ifdef USE_ICONV
extern char *sub_cp;
#endif
#endif
#ifdef USE_OSD
@ -119,6 +122,9 @@ struct config conf[]={
{"encode", &encode_name, CONF_TYPE_STRING, 0, 0, 0},
#ifdef USE_SUB
{"sub", &sub_name, CONF_TYPE_STRING, 0, 0, 0},
#ifdef USE_ICONV
{"subcp", &sub_cp, CONF_TYPE_STRING, 0, 0, 0},
#endif
{"subdelay", &sub_delay, CONF_TYPE_FLOAT, 0, 0.0, 10.0},
{"subfps", &sub_fps, CONF_TYPE_FLOAT, 0, 0.0, 10.0},
{"noautosub", &sub_auto, CONF_TYPE_FLAG, 0, 1, 0},

53
configure vendored
View File

@ -160,6 +160,7 @@ params:
--enable-xmmp use XMMP audio drivers
--enable-lirc enable LIRC (remote control) support
--disable-iconv do not use iconv(3) function [autodetect]
--disable-ossaudio disable OSS sound support [autodetect]
--disable-alsa disable alsa sound support [autodetect]
--disable-esd disable esd sound support [autodetect]
@ -902,6 +903,42 @@ else
$_cc $TMPC -o $TMPO $_x11libdir -lX11 -lXext -lGL -lm $_socklib > /dev/null 2>&1 && _gl=yes
fi
cat > $TMPC << EOF
#include <stdio.h>
#include <unistd.h>
#include <iconv.h>
#define INBUFSIZE 1024
#define OUTBUFSIZE 4096
char inbuffer[INBUFSIZE];
char outbuffer[OUTBUFSIZE];
main()
{ ssize_t numread;
iconv_t icdsc;
char *tocode="UTF-8";
char *fromcode="cp1250";
if ((icdsc = iconv_open (tocode, fromcode)) != (iconv_t)(-1)){
while ((numread = read (0, inbuffer, INBUFSIZE))){
char *iptr=inbuffer;
char *optr=outbuffer;
size_t inleft=numread;
size_t outleft=OUTBUFSIZE;
if (iconv (icdsc,
(const char **)&iptr, &inleft, &optr, &outleft)
!=(size_t)(-1)){
write (1, outbuffer, OUTBUFSIZE - outleft);
}
}
if (iconv_close (icdsc) == -1) ;
}
}
EOF
_iconv=yes
$_cc $TMPC -o $TMPO -lm > /dev/null 2>&1 || \
{ _iconv=no ; echo "iconv(3) function not detected!" ;}
cat > $TMPC << EOF
#include <GL/gl.h>
int main( void ) { return 0; }
@ -1216,6 +1253,9 @@ for ac_option do
--enable-fbdev)
_fbdev=yes
;;
--enable-iconv)
_iconv=yes
;;
--enable-mlib)
_mlib=yes
;;
@ -1326,6 +1366,9 @@ for ac_option do
--disable-fbdev)
_fbdev=no
;;
--disable-iconv)
_iconv=no
;;
--disable-termcap)
_termcap=no
;;
@ -1585,6 +1628,7 @@ echo "Checking for PNG support ... $_png"
echo "Checking for OggVorbis support ... $_vorbis"
echo "Checking for Win32 DLL support ... $_win32dll"
echo "Checking for DirectShow ... $_dshow"
echo "Checking for iconv function ... $_iconv"
# check if compiler supports C++ and C++-libs are installed correctly
if [ $_win32dll = yes -a $_dshow = yes ] ; then
@ -1844,6 +1888,12 @@ else
_xmmpaudio='#undef USE_XMMP_AUDIO'
fi
if [ "$_iconv" = "yes" ]; then
_iconv='#define USE_ICONV'
else
_iconv='#undef USE_ICONV'
fi
if [ "$_lirc" = "yes" ]; then
_lircdefs='#define HAVE_LIRC'
_lirclibs='-llirc_client'
@ -2279,6 +2329,9 @@ $_divx4def
try to recompile MPlayer with this option disabled! */
$_select
/* define this to use iconv(3) function to codepage conversions */
$_iconv
/* XMMP support: (test code) */
$_xmmpaudio
#define LIBDIR "/usr/local/lib"

View File

@ -12,10 +12,15 @@
#include <string.h>
#include <ctype.h>
#include "config.h"
#include "subreader.h"
#define ERR (void *)-1
#ifdef USE_ICONV
#include <iconv.h>
char *sub_cp=NULL;
#endif
int sub_uses_time=0;
int sub_errs=0;
@ -399,7 +404,73 @@ int sub_autodetect (FILE *fd) {
return -1; // too many bad lines
}
extern int sub_utf8;
#ifdef USE_ICONV
static iconv_t icdsc;
void subcp_open (void)
{
char *tocp = "UTF-8";
icdsc = (iconv_t)(-1);
if (sub_cp){
if ((icdsc = iconv_open (tocp, sub_cp)) != (iconv_t)(-1)){
printf ("SUB: opened iconv descriptor.\n");
sub_utf8 = 2;
} else
printf ("SUB: error opening iconv descriptor.\n");
}
}
void subcp_close (void)
{
if (icdsc != (iconv_t)(-1)){
(void) iconv_close (icdsc);
printf ("SUB: closed iconv descriptor.\n");
}
}
#define ICBUFFSIZE 512
static char icbuffer[ICBUFFSIZE];
subtitle* subcp_recode (subtitle *sub)
{
int l=sub->lines;
size_t ileft, oleft, otlen;
char *op, *ip, *ot;
while (l){
op = icbuffer;
ip = sub->text[--l];
ileft = strlen(ip);
oleft = ICBUFFSIZE - 1;
if (iconv(icdsc, (const char **) &ip, &ileft,
&op, &oleft) == (size_t)(-1)) {
printf ("SUB: error recoding line.\n");
l++;
break;
}
if (!(ot = (char *)malloc(op - icbuffer + 1))){
printf ("SUB: error allocating mem.\n");
l++;
break;
}
*op='\0' ;
strcpy (ot, icbuffer);
free (sub->text[l]);
sub->text[l] = ot;
}
if (l){
for (l = sub->lines; l;)
free (sub->text[--l]);
return ERR;
}
return sub;
}
#endif
subtitle* sub_read_file (char *filename) {
FILE *fd;
@ -425,6 +496,10 @@ subtitle* sub_read_file (char *filename) {
rewind (fd);
#ifdef USE_ICONV
subcp_open();
#endif
sub_num=0;n_max=32;
first=(subtitle *)malloc(n_max*sizeof(subtitle));
if(!first) return NULL;
@ -437,11 +512,18 @@ subtitle* sub_read_file (char *filename) {
}
sub=func[sub_format](fd,&first[sub_num]);
if(!sub) break; // EOF
#ifdef USE_ICONV
if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub);
#endif
if(sub==ERR) ++sub_errs; else ++sub_num; // Error vs. Valid
}
fclose(fd);
#ifdef USE_ICONV
subcp_close();
#endif
// printf ("SUB: Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use");
printf ("SUB: Read %i subtitles", sub_num);
if (sub_errs) printf (", %i bad line(s).\n", sub_errs);
@ -465,7 +547,6 @@ char * strreplace( char * in,char * what,char * whereof )
char * sub_filename(char* path, char * fname )
{
extern int sub_utf8;
char * sub_name1;
char * sub_name2;
char * aviptr1, * aviptr2, * tmp;
@ -509,7 +590,11 @@ char * sub_filename(char* path, char * fname )
for(j=0;j<=1;j++){
char* sub_name=j?sub_name1:sub_name2;
#ifdef USE_ICONV
for ( i=(sub_cp?2:0);i<(sizeof(sub_exts)/sizeof(char*));i++ ) {
#else
for ( i=0;i<(sizeof(sub_exts)/sizeof(char*));i++ ) {
#endif
strcpy(j?aviptr1:aviptr2,sub_exts[i]);
// printf("trying: '%s'\n",sub_name);
if((f=fopen( sub_name,"rt" ))) {