Commit 0d558bdf authored by Laurent Aimar's avatar Laurent Aimar

* sub.c : begun clean up

parent 211ab3ef
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* sub.c * sub.c
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: sub.c,v 1.4 2003/02/08 19:10:21 massiot Exp $ * $Id: sub.c,v 1.5 2003/02/09 13:25:42 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -116,7 +116,6 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -116,7 +116,6 @@ static int sub_open ( subtitle_demux_t *p_sub,
int i_max; int i_max;
int (*pf_read_subtitle)( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_microsecperframe ) = NULL; int (*pf_read_subtitle)( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_microsecperframe ) = NULL;
p_sub->i_sub_type = SUB_TYPE_UNKNOWN; p_sub->i_sub_type = SUB_TYPE_UNKNOWN;
p_sub->p_es = NULL; p_sub->p_es = NULL;
p_sub->i_subtitles = 0; p_sub->i_subtitles = 0;
...@@ -128,9 +127,13 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -128,9 +127,13 @@ static int sub_open ( subtitle_demux_t *p_sub,
psz_name = config_GetPsz( p_sub, "sub-file" ); psz_name = config_GetPsz( p_sub, "sub-file" );
if( !psz_name || !*psz_name ) if( !psz_name || !*psz_name )
{ {
return( -1 ); return VLC_EGENERIC;
} }
} }
else
{
psz_name = strdup( psz_name );
}
if( config_GetFloat( p_sub, "sub-fps" ) >= 1.0 ) if( config_GetFloat( p_sub, "sub-fps" ) >= 1.0 )
{ {
...@@ -146,11 +149,13 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -146,11 +149,13 @@ static int sub_open ( subtitle_demux_t *p_sub,
if( !( p_file = fopen( psz_name, "rb" ) ) ) if( !( p_file = fopen( psz_name, "rb" ) ) )
{ {
msg_Err( p_sub, "cannot open `%s' subtitle file", psz_name ); msg_Err( p_sub, "cannot open `%s' subtitle file", psz_name );
free( psz_name );
return VLC_EGENERIC;
} }
else else
{ {
msg_Dbg( p_sub, "opened `%s'", psz_name ); msg_Dbg( p_sub, "opened `%s'", psz_name );
free( psz_name );
} }
psz_file_type = config_GetPsz( p_sub, "sub-type" ); psz_file_type = config_GetPsz( p_sub, "sub-type" );
...@@ -226,8 +231,6 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -226,8 +231,6 @@ static int sub_open ( subtitle_demux_t *p_sub,
{ {
i_sub_type = SUB_TYPE_SSA2_4; // could be wrong i_sub_type = SUB_TYPE_SSA2_4; // could be wrong
} }
} }
} }
...@@ -253,18 +256,18 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -253,18 +256,18 @@ static int sub_open ( subtitle_demux_t *p_sub,
default: default:
msg_Err( p_sub, "unknown subtitile file" ); msg_Err( p_sub, "unknown subtitile file" );
fclose( p_file ); fclose( p_file );
return( -1 ); return VLC_EGENERIC;
} }
if( fseek( p_file, 0L, SEEK_SET ) < 0 ) if( fseek( p_file, 0L, SEEK_SET ) < 0 )
{ {
msg_Err( p_input, "cannot read file from begining" ); msg_Err( p_input, "cannot read file from begining" );
fclose( p_file ); fclose( p_file );
return( -1 ); return VLC_EGENERIC;
} }
for( i_max = 0;; ) for( i_max = 0;; )
{ {
if( p_sub->i_subtitles <= i_max ) if( p_sub->i_subtitles >= i_max )
{ {
i_max += 128; i_max += 128;
if( p_sub->subtitle ) if( p_sub->subtitle )
...@@ -287,7 +290,6 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -287,7 +290,6 @@ static int sub_open ( subtitle_demux_t *p_sub,
} }
msg_Dbg( p_sub, "loaded %d subtitles", p_sub->i_subtitles ); msg_Dbg( p_sub, "loaded %d subtitles", p_sub->i_subtitles );
/* *** Close the file *** */ /* *** Close the file *** */
fclose( p_file ); fclose( p_file );
...@@ -308,7 +310,7 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -308,7 +310,7 @@ static int sub_open ( subtitle_demux_t *p_sub,
p_sub->p_es->i_cat = SPU_ES; p_sub->p_es->i_cat = SPU_ES;
p_sub->i_previously_selected = 0; p_sub->i_previously_selected = 0;
return( 0 ); return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
...@@ -321,12 +323,12 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate ) ...@@ -321,12 +323,12 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
{ {
p_sub->i_previously_selected = 1; p_sub->i_previously_selected = 1;
p_sub->pf_seek( p_sub, i_maxdate ); p_sub->pf_seek( p_sub, i_maxdate );
return( 0 ); return VLC_SUCCESS;
} }
else if( !p_sub->p_es->p_decoder_fifo && p_sub->i_previously_selected ) else if( !p_sub->p_es->p_decoder_fifo && p_sub->i_previously_selected )
{ {
p_sub->i_previously_selected = 0; p_sub->i_previously_selected = 0;
return( 0 ); return VLC_SUCCESS;
} }
while( p_sub->i_subtitle < p_sub->i_subtitles && while( p_sub->i_subtitle < p_sub->i_subtitles &&
...@@ -385,7 +387,7 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate ) ...@@ -385,7 +387,7 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
memcpy( p_data->p_payload_start, memcpy( p_data->p_payload_start,
p_sub->subtitle[p_sub->i_subtitle].psz_text, p_sub->subtitle[p_sub->i_subtitle].psz_text,
i_len ); i_len );
if( p_sub->p_es->p_decoder_fifo ) if( p_sub->p_es->p_decoder_fifo && p_pes->i_pts > 0 )
{ {
input_DecodePES( p_sub->p_es->p_decoder_fifo, p_pes ); input_DecodePES( p_sub->p_es->p_decoder_fifo, p_pes );
...@@ -395,7 +397,6 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate ) ...@@ -395,7 +397,6 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
input_DeletePES( p_sub->p_input->p_method_data, p_pes ); input_DeletePES( p_sub->p_input->p_method_data, p_pes );
} }
p_sub->i_subtitle++; p_sub->i_subtitle++;
} }
return( 0 ); return( 0 );
...@@ -473,7 +474,6 @@ static void sub_fix( subtitle_demux_t *p_sub ) ...@@ -473,7 +474,6 @@ static void sub_fix( subtitle_demux_t *p_sub )
} }
} while( !i_done ); } while( !i_done );
/* *** and at the end add delay *** */ /* *** and at the end add delay *** */
i_delay = (mtime_t)config_GetInt( p_sub, "sub-delay" ) * 100000; i_delay = (mtime_t)config_GetInt( p_sub, "sub-delay" ) * 100000;
if( i_delay != 0 ) if( i_delay != 0 )
...@@ -517,6 +517,9 @@ static int sub_MicroDvdRead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_mi ...@@ -517,6 +517,9 @@ static int sub_MicroDvdRead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_mi
} }
i_start = 0; i_start = 0;
i_stop = 0; i_stop = 0;
buffer[MAX_LINE] = '\0';
memset( buffer_text, '\0', MAX_LINE );
if( sscanf( buffer, "{%d}{}%[^\r\n]", &i_start, buffer_text ) == 2 || if( sscanf( buffer, "{%d}{}%[^\r\n]", &i_start, buffer_text ) == 2 ||
sscanf( buffer, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, buffer_text ) == 3) sscanf( buffer, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, buffer_text ) == 3)
{ {
...@@ -524,7 +527,7 @@ static int sub_MicroDvdRead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_mi ...@@ -524,7 +527,7 @@ static int sub_MicroDvdRead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_mi
} }
} }
/* replace | by \n */ /* replace | by \n */
for( i = 0; i < MAX_LINE; i++ ) for( i = 0; i < strlen( buffer_text ); i++ )
{ {
if( buffer_text[i] == '|' ) if( buffer_text[i] == '|' )
{ {
...@@ -580,7 +583,7 @@ static int sub_SubRipRead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_micr ...@@ -580,7 +583,7 @@ static int sub_SubRipRead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_micr
for( i_buffer_text = 0;; ) for( i_buffer_text = 0;; )
{ {
int i_len; int i_len;
if( fgets( buffer, MAX_LINE, p_file ) <= 0) if( fgets( buffer, MAX_LINE, p_file ) <= 0 )
{ {
return( -1 ); return( -1 );
} }
...@@ -611,7 +614,6 @@ static int sub_SubRipRead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_micr ...@@ -611,7 +614,6 @@ static int sub_SubRipRead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_micr
} }
} }
} }
} }
...@@ -629,7 +631,7 @@ static int sub_SSARead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_microse ...@@ -629,7 +631,7 @@ static int sub_SSARead( FILE *p_file, subtitle_t *p_subtitle, mtime_t i_microse
{ {
int h1, m1, s1, c1, h2, m2, s2, c2; int h1, m1, s1, c1, h2, m2, s2, c2;
int i_dummy; int i_dummy;
if( fgets( buffer, MAX_LINE, p_file ) <= 0) if( fgets( buffer, MAX_LINE, p_file ) <= 0 )
{ {
return( -1 ); return( -1 );
} }
......
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