Commit 7746a9f0 authored by Derk-Jan Hartman's avatar Derk-Jan Hartman

* modules/codec/subsdec/subsdec.c: reordered the list of encodings. Should

  make it easier for users to find their charset now.
* modules/demux/util/sub.?: try to find filename.subext based on filename.avi
  Very basic now, but might be become more advanced in the feature. (that's
  why it's so much code )
parent cb2a5e40
......@@ -2,7 +2,7 @@
* subsdec.c : SPU decoder thread
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
* $Id: subsdec.c,v 1.6 2003/08/23 12:59:31 hartman Exp $
* $Id: subsdec.c,v 1.7 2003/08/23 19:20:29 hartman Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Samuel Hocevar <sam@zoy.org>
......@@ -48,22 +48,25 @@ static vout_thread_t *FindVout( subsdec_thread_t * );
/*****************************************************************************
* Module descriptor.
*****************************************************************************/
static char *ppsz_encodings[] = { N_("System Default"),
"ASCII", "ISO-8859-1", "ISO-8859-2", "ISO-8859-3",
"ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", "ISO-8859-8",
"ISO-8859-9", "ISO-8859-10", "ISO-8859-13", "ISO-8859-14", "ISO-8859-15",
"ISO-8859-16", "ISO-2022-JP", "ISO-2022-JP-1", "ISO-2022-JP-2", "ISO-2022-CN",
"ISO-2022-CN-EXT", "ISO-2022-KR",
"CP850", "CP862", "CP866", "CP874", "CP932", "CP949", "CP950", "CP1133",
"CP1250", "CP1251", "CP1252", "CP1253", "CP1254", "CP1255", "CP1256", "CP1257", "CP1258",
"MacRoman", "MacCentralEurope", "MacIceland", "MacCroatian", "MacRomania",
"MacCyrillic", "MacUkraine", "MacGreek", "MacTurkish", "MacHebrew", "MacArabic",
"MacThai", "Macintosh",
"UTF-7", "UTF-8", "UTF-16", "UTF-16BE", "UTF-16LE", "UTF-32", "UTF-32BE", "UTF-32LE",
"C99", "JAVA", "UCS-2", "UCS-2BE", "UCS-2LE", "UCS-4", "UCS-4BE", "UCS-4LE",
"KOI8-R", "KOI8-U", "KOI8-RU", "KOI8-T",
"EUC-JP", "EUC-CN", "EUC-KR", "EUC-TW",
"SHIFT_JIS", "HZ", "GBK", "GB18030", "BIG5", "BIG5-HKSCS", "JOHAB", "ARMSCII-8",
static char *ppsz_encodings[] = { N_("System Default"), "ASCII", "UTF-8", "",
"ISO-8859-1", "CP1252", "MacRoman", "MacIceland","ISO-8859-15", "",
"ISO-8859-2", "CP1250", "MacCentralEurope", "MacCroatian", "MacRomania", "",
"ISO-8859-5", "CP1251", "MacCyrillic", "MacUkraine", "KOI8-R", "KOI8-U", "KOI8-RU", "",
"ISO-8859-6", "CP1256", "MacArabic", "",
"ISO-8859-7", "CP1253", "MacGreek", "",
"ISO-8859-8", "CP1255", "MacHebrew", "",
"ISO-8859-9", "CP1254", "MacTurkish", "",
"ISO-8859-13", "CP1257", "",
"ISO-2022-JP", "ISO-2022-JP-1", "ISO-2022-JP-2", "EUC-JP", "SHIFT_JIS", "",
"ISO-2022-CN", "ISO-2022-CN-EXT", "EUC-CN", "EUC-TW", "BIG5", "BIG5-HKSCS", "",
"ISO-2022-KR", "EUC-KR", "",
"MacThai", "KOI8-T", "",
"ISO-8859-3", "ISO-8859-4", "ISO-8859-10", "ISO-8859-14", "ISO-8859-16", "",
"CP850", "CP862", "CP866", "CP874", "CP932", "CP949", "CP950", "CP1133", "CP1258", "",
"Macintosh", "",
"UTF-7", "UTF-16", "UTF-16BE", "UTF-16LE", "UTF-32", "UTF-32BE", "UTF-32LE",
"C99", "JAVA", "UCS-2", "UCS-2BE", "UCS-2LE", "UCS-4", "UCS-4BE", "UCS-4LE", "",
"HZ", "GBK", "GB18030", "JOHAB", "ARMSCII-8",
"Georgian-Academy", "Georgian-PS", "TIS-620", "MuleLao-1", "VISCII", "TCVN",
"HPROMAN8", "NEXTSTEP", NULL };
......
/*****************************************************************************
* sub.c
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: sub.c,v 1.20 2003/07/27 23:58:32 fenrir Exp $
* Copyright (C) 1999-2003 VideoLAN
* $Id: sub.c,v 1.21 2003/08/23 19:20:29 hartman Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -35,6 +35,9 @@
#include "sub.h"
#if (!defined( WIN32 ) || defined(__MINGW32__))
# include <dirent.h>
#endif
static int Open ( vlc_object_t *p_this );
......@@ -62,6 +65,9 @@ static char *ppsz_sub_type[] = { "microdvd", "subrip", "ssa1", "ssa2-4", "vplaye
#define SUB_TYPE_LONGTEXT \
"One from \"microdvd\", \"subrip\", \"ssa1\", \"ssa2-4\", \"vplayer\" " \
"\"sami\" (nothing for autodetection, it should always work)."
#define SUB_AUTO_LONGTEXT \
"Automatically detect a subtitle file, if no subtitle filename is" \
"is specified"
vlc_module_begin();
set_description( _("Text subtitles demux") );
......@@ -69,6 +75,8 @@ vlc_module_begin();
add_category_hint( "Subtitles", NULL, VLC_TRUE );
add_file( "sub-file", NULL, NULL,
"Subtitles file name", "Subtitles file name", VLC_TRUE );
add_bool( "sub-autodetect-file", VLC_TRUE, NULL, "Autodetect subtitle filename",
SUB_AUTO_LONGTEXT, VLC_FALSE );
add_float( "sub-fps", 0.0, NULL,
"Frames per second",
SUB_FPS_LONGTEXT, VLC_TRUE );
......@@ -95,6 +103,7 @@ static int Open ( vlc_object_t *p_this )
/* Initialize the variables */
var_Create( p_this, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
var_Create( p_this, "sub-autodetect-file", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_this, "sub-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
var_Create( p_this, "sub-delay", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_this, "sub-type", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
......@@ -226,6 +235,93 @@ static struct
{ NULL, SUB_TYPE_UNKNOWN, "Unknow", NULL }
};
/*****************************************************************************
* sub_detect: Use the original filename to find a subtitle file
*****************************************************************************/
char* sub_detect( subtitle_demux_t *p_sub, char *psz_filename)
{
DIR *p_dir_handle;
struct dirent *p_dir_afile;
char * ppsz_sub_exts[] = { "sub", "srt", "smi", "ssa", NULL};
char *psz_result, *psz_basename, *psz_dir, *psz_file_noext, *psz_extension;
int i;
size_t i_dirlen = 0;
if( psz_filename && *psz_filename )
{
#ifdef WIN32
psz_basename = strrchr( psz_filename , '\\' );
#else
psz_basename = strrchr( psz_filename , '/' );
#endif
if( psz_basename )
{
i_dirlen = ( 1 + psz_basename ) - psz_filename;
psz_dir = (char*)malloc( i_dirlen + 1 );
if( !psz_dir )
{
return "";
}
strncpy( psz_dir, psz_filename, i_dirlen );
psz_dir[i_dirlen] = '\0';
++psz_basename;
}
else
{
psz_basename = psz_filename;
}
psz_extension = strrchr( psz_basename , '.' );
if( psz_extension )
{
size_t i_baselen = ( 1 + psz_extension ) - psz_basename;
psz_file_noext = (char*)malloc( i_baselen + 1 );
if( !psz_file_noext )
{
return "";
}
strncpy( psz_file_noext, psz_basename, i_baselen );
psz_file_noext[i_baselen] = '\0';
++psz_extension;
}
else return "";
p_dir_handle = opendir( psz_dir );
if( p_dir_handle ) {
int i_found = 0;
while(( p_dir_afile = readdir( p_dir_handle ))) {
for (i = 0; ppsz_sub_exts[i]; i++) {
if( strcmp( ppsz_sub_exts[i], 1 + strrchr( p_dir_afile->d_name, '.' ) ) == 0 ) {
i_found = 1;
break;
}
}
if( i_found )
{
msg_Dbg( p_sub, "autodetected subtitlefile: %s", strdup( p_dir_afile->d_name ) );
if( psz_dir )
{
psz_result = (char*)malloc( i_dirlen + strlen( p_dir_afile->d_name ) +1 );
strncpy( psz_result, psz_dir, i_dirlen );
char *psz_append = psz_result + i_dirlen;
strncpy( psz_append, p_dir_afile->d_name, strlen( p_dir_afile->d_name ) );
psz_result[i_dirlen + strlen( p_dir_afile->d_name )] = '\0';
return psz_result;
}
else return strdup( p_dir_afile->d_name );
}
}
closedir( p_dir_handle );
}
}
return "";
}
/*****************************************************************************
* sub_open: Open a subtitle file and add subtitle ES
*****************************************************************************/
......@@ -250,17 +346,28 @@ static int sub_open ( subtitle_demux_t *p_sub,
if( !psz_name || !*psz_name)
{
msg_Dbg( p_sub, "variable psz_name empty" );
var_Get( p_sub, "sub-file", &val );
if( !val.psz_string || !*val.psz_string )
{
msg_Dbg( p_sub, "variable sub-file empty too" );
var_Get( p_sub, "sub-autodetect-file", &val );
if( val.b_bool )
{
msg_Dbg( p_sub, "lets try autodetect" );
psz_name = strdup( sub_detect( p_sub, p_input->psz_source));
}
else
{
if( val.psz_string ) free( val.psz_string );
return VLC_EGENERIC;
}
psz_name = val.psz_string;
}
else
{
psz_name = strdup( psz_name );
psz_name = strdup( val.psz_string );
if( val.psz_string ) free( val.psz_string );
}
}
/* *** load the file *** */
......
/*****************************************************************************
* sub.h
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: sub.h,v 1.6 2003/07/24 21:50:28 gbazin Exp $
* Copyright (C) 2001-2003 VideoLAN
* $Id: sub.h,v 1.7 2003/08/23 19:20:29 hartman Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment