*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Derk-Jan Hartman <hartman at videolan dot org>
+ * Jean-Baptiste Kempf <jb@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define SUB_TYPE_LONGTEXT \
N_("Force the subtiles format. Valid values are : \"microdvd\", " \
"\"subrip\", \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\" " \
- "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\" and \"auto\" (meaning autodetection, this " \
+ "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\" "\
+ "\"mpsub\" \"jacosub\" and \"auto\" (meaning autodetection, this " \
"should always work).")
static const char *ppsz_sub_type[] =
{
"auto", "microdvd", "subrip", "subviewer", "ssa1",
"ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2",
- "aqt", "pjs"
+ "aqt", "pjs", "mpsub", "jacosub"
};
vlc_module_begin();
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
+ if( p_sys == NULL )
+ return VLC_ENOMEM;
+
p_sys->psz_header = NULL;
p_sys->i_subtitle = 0;
p_sys->i_subtitles = 0;
static int ParseMicroDvd( demux_t *p_demux, subtitle_t *p_subtitle,
int i_idx )
{
+ VLC_UNUSED( i_idx );
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
char *psz_text;
static int ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle,
int i_idx )
{
+ VLC_UNUSED( i_idx );
return ParseSubRipSubViewer( p_demux, p_subtitle,
"%d:%d:%d,%d --> %d:%d:%d,%d",
false );
static int ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
int i_idx )
{
+ VLC_UNUSED( i_idx );
+
return ParseSubRipSubViewer( p_demux, p_subtitle,
"%d:%d:%d.%d,%d:%d:%d.%d",
true );
static int ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle,
int i_idx )
{
+ VLC_UNUSED( i_idx );
+
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
char *psz_text;
}
static int ParseSami( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
{
+ VLC_UNUSED( i_idx );
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle,
int i_idx )
{
+ VLC_UNUSED( i_idx );
+
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
char *psz_text;
*/
static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
{
+ VLC_UNUSED( i_idx );
+
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
char *psz_text;
static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
{
+ VLC_UNUSED( i_idx );
+
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
char *psz_text = strdup( "" );
static int ParsePJS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
{
+ VLC_UNUSED( i_idx );
+
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
char *psz_text;
return VLC_EGENERIC;
psz_text = malloc( strlen(s) + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
/* Data Lines */
if( sscanf (s, "%d,%d,\"%[^\n\r]", &t1, &t2, psz_text ) == 3 )
static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
{
+ VLC_UNUSED( i_idx );
+
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
char *psz_text = strdup( "" );
for( ;; )
{
- const char *s = TextGetLine( txt );
float f1, f2;
char p_dummy;
char *psz_temp;
+ const char *s = TextGetLine( txt );
if( !s )
return VLC_EGENERIC;
+
if( strstr( s, "FORMAT" ) )
{
if( sscanf (s, "FORMAT=TIM%c", &p_dummy ) == 1 && p_dummy == 'E')
}
psz_temp = malloc( strlen(s) );
+ if( !psz_temp )
+ return VLC_ENOMEM;
+
if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
{
float f_fps;
static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
{
+ VLC_UNUSED( i_idx );
+
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
char *psz_text, *psz_orig;
return VLC_EGENERIC;
psz_text = malloc( strlen( s ) + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
psz_orig = psz_text;
+ /* Complete time lines */
if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]",
&h1, &m1, &s1, &f1, &h2, &m2, &s2, &f2, psz_text ) == 9 )
{
(int64_t)( ( f2 + jss_time_shift ) / jss_time_resolution ) )
* 1000000;
}
+ /* Short time lines */
else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 )
{
p_subtitle->i_start = (int64_t)(
p_subtitle->i_stop = (int64_t)(
( f2 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
}
+ /* General Directive lines */
+ /* Only TIME and SHIFT are supported so far */
else if( s[0] == '#' )
{
int h = 0, m =0, sec = 1, f = 1;
switch( toupper( psz_text[1] ) )
{
- case 'S':
- shift = isalpha( psz_text[2] ) ? 6 : 2 ;
+ case 'S':
+ shift = isalpha( psz_text[2] ) ? 6 : 2 ;
- if( sscanf( &psz_text[shift], "%d", &h ) )
+ if( sscanf( &psz_text[shift], "%d", &h ) )
+ {
+ /* Negative shifting */
+ if( h < 0 )
{
- /* Negative shifting */
- if( h < 0 )
- {
- h *= -1;
- inv = -1;
- }
+ h *= -1;
+ inv = -1;
+ }
- if( sscanf( &psz_text[shift], "%*d:%d", &m ) )
+ if( sscanf( &psz_text[shift], "%*d:%d", &m ) )
+ {
+ if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) )
{
- if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) )
- {
- sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f );
- }
- else
- {
- h = 0;
- sscanf( &psz_text[shift], "%d:%d.%d", &m, &sec, &f );
- m *= inv;
- }
+ sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f );
}
else
{
- h = m = 0;
- sscanf( &psz_text[shift], "%d.%d", &sec, &f);
- sec *= inv;
+ h = 0;
+ sscanf( &psz_text[shift], "%d:%d.%d",
+ &m, &sec, &f );
+ m *= inv;
}
- jss_time_shift = ( ( h * 3600 + m * 60 + sec )
- * jss_time_resolution + f ) * inv;
}
- break;
+ else
+ {
+ h = m = 0;
+ sscanf( &psz_text[shift], "%d.%d", &sec, &f);
+ sec *= inv;
+ }
+ jss_time_shift = ( ( h * 3600 + m * 60 + sec )
+ * jss_time_resolution + f ) * inv;
+ }
+ break;
- case 'T':
- shift = isalpha( psz_text[2] ) ? 8 : 2 ;
+ case 'T':
+ shift = isalpha( psz_text[2] ) ? 8 : 2 ;
- sscanf( &psz_text[shift], "%d", &jss_time_resolution );
- break;
+ sscanf( &psz_text[shift], "%d", &jss_time_resolution );
+ break;
}
free( psz_text );
continue;
}
else
- /* Unkown line */
+ /* Unkown type line, probably a comment */
{
free( psz_text );
continue;
{ psz_text++ ;};
/* Directives are NOT parsed yet */
+ /* This has probably a better place in a decoder ? */
/* directive = malloc( strlen( psz_text ) + 1 );
if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/
}
/* Skip the blanks after directives */
while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
+
+ /* Clean all the lines from inline comments and other stuffs */
psz_text2 = calloc( strlen( psz_text) + 1, 1 );
psz_orig2 = psz_text2;
return VLC_SUCCESS;
}
}
+