Split guess_cp() in two functions:

- guess_buffer_cp() determines the encoding of text, given a pointer to a 
buffer and its length;
- guess_cp() reads some data from stream and calls guess_buffer_cp()


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@18941 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
eugeni 2006-07-07 18:07:39 +00:00
parent 93647f42c5
commit 2f2d8cef15
2 changed files with 23 additions and 10 deletions

View File

@ -1303,20 +1303,15 @@ struct subreader {
};
#ifdef HAVE_ENCA
#define MAX_GUESS_BUFFER_SIZE (256*1024)
void* guess_cp(stream_t *st, char *preferred_language, char *fallback)
void* guess_buffer_cp(unsigned char* buffer, int buflen, char *preferred_language, char *fallback)
{
const char **languages;
size_t langcnt, buflen;
size_t langcnt;
EncaAnalyser analyser;
EncaEncoding encoding;
unsigned char *buffer;
char *detected_sub_cp = NULL;
int i;
buffer = malloc(MAX_GUESS_BUFFER_SIZE);
buflen = stream_read(st,buffer, MAX_GUESS_BUFFER_SIZE);
languages = enca_get_languages(&langcnt);
mp_msg(MSGT_SUBREADER, MSGL_V, "ENCA supported languages: ");
for (i = 0; i < langcnt; i++) {
@ -1339,9 +1334,6 @@ void* guess_cp(stream_t *st, char *preferred_language, char *fallback)
}
free(languages);
free(buffer);
stream_reset(st);
stream_seek(st,0);
if (!detected_sub_cp) {
detected_sub_cp = strdup(fallback);
@ -1350,6 +1342,26 @@ void* guess_cp(stream_t *st, char *preferred_language, char *fallback)
return detected_sub_cp;
}
#define MAX_GUESS_BUFFER_SIZE (256*1024)
void* guess_cp(stream_t *st, char *preferred_language, char *fallback)
{
size_t buflen;
unsigned char *buffer;
char *detected_sub_cp = NULL;
buffer = malloc(MAX_GUESS_BUFFER_SIZE);
buflen = stream_read(st,buffer, MAX_GUESS_BUFFER_SIZE);
detected_sub_cp = guess_buffer_cp(buffer, buflen, preferred_language, fallback);
free(buffer);
stream_reset(st);
stream_seek(st,0);
return detected_sub_cp;
}
#undef MAX_GUESS_BUFFER_SIZE
#endif
sub_data* sub_read_file (char *filename, float fps) {

View File

@ -73,6 +73,7 @@ struct stream_st;
void subcp_open (struct stream_st *st); /* for demux_ogg.c */
void subcp_close (void); /* for demux_ogg.c */
#ifdef HAVE_ENCA
void* guess_buffer_cp(unsigned char* buffer, int buflen, char *preferred_language, char *fallback);
void* guess_cp(struct stream_st *st, char *preferred_language, char *fallback);
#endif
char ** sub_filenames(char *path, char *fname);