"subviewer1"
};
-vlc_module_begin();
- set_shortname( N_("Subtitles"));
- set_description( N_("Text subtitles parser") );
- set_capability( "demux", 0 );
- set_category( CAT_INPUT );
- set_subcategory( SUBCAT_INPUT_DEMUX );
+vlc_module_begin ()
+ set_shortname( N_("Subtitles"))
+ set_description( N_("Text subtitles parser") )
+ set_capability( "demux", 0 )
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_DEMUX )
add_float( "sub-fps", 0.0, NULL,
N_("Frames per second"),
- SUB_FPS_LONGTEXT, true );
+ SUB_FPS_LONGTEXT, true )
add_integer( "sub-delay", 0, NULL,
N_("Subtitles delay"),
- SUB_DELAY_LONGTEXT, true );
+ SUB_DELAY_LONGTEXT, true )
add_string( "sub-type", "auto", NULL, N_("Subtitles format"),
- SUB_TYPE_LONGTEXT, true );
+ SUB_TYPE_LONGTEXT, true )
change_string_list( ppsz_sub_type, NULL, NULL );
- set_callbacks( Open, Close );
+ set_callbacks( Open, Close )
- add_shortcut( "subtitle" );
-vlc_module_end();
+ add_shortcut( "subtitle" )
+vlc_module_end ()
/*****************************************************************************
* Prototypes:
{ "subviewer1", SUB_TYPE_SUBVIEW1, "Subviewer 1", ParseSubViewer1 },
{ NULL, SUB_TYPE_UNKNOWN, "Unknown", NULL }
};
+/* When adding support for more formats, be sure to add their file extension
+ * to src/input/subtitles.c to enable auto-detection.
+ */
static int Demux( demux_t * );
static int Control( demux_t *, int, va_list );
/* Quit on unknown subtitles */
if( p_sys->i_type == SUB_TYPE_UNKNOWN )
{
- msg_Err( p_demux, "failed to recognize subtitle type" );
+ msg_Warn( p_demux, "failed to recognize subtitle type" );
free( p_sys );
return VLC_EGENERIC;
}
case DEMUX_SET_TIME:
i64 = (int64_t)va_arg( args, int64_t );
p_sys->i_subtitle = 0;
- while( p_sys->i_subtitle < p_sys->i_subtitles &&
- p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
+ while( p_sys->i_subtitle < p_sys->i_subtitles )
{
+ const subtitle_t *p_subtitle = &p_sys->subtitle[p_sys->i_subtitle];
+
+ if( p_subtitle->i_start > i64 )
+ break;
+ if( p_subtitle->i_stop > p_subtitle->i_start && p_subtitle->i_stop > i64 )
+ break;
+
p_sys->i_subtitle++;
}
case DEMUX_GET_ATTACHMENTS:
case DEMUX_GET_TITLE_INFO:
case DEMUX_HAS_UNSUPPORTED_META:
+ case DEMUX_CAN_RECORD:
return VLC_EGENERIC;
default:
while( p_sys->i_subtitle < p_sys->i_subtitles &&
p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
{
+ const subtitle_t *p_subtitle = &p_sys->subtitle[p_sys->i_subtitle];
+
block_t *p_block;
- int i_len = strlen( p_sys->subtitle[p_sys->i_subtitle].psz_text ) + 1;
+ int i_len = strlen( p_subtitle->psz_text ) + 1;
- if( i_len <= 1 )
+ if( i_len <= 1 || p_subtitle->i_start < 0 )
{
- /* empty subtitle */
p_sys->i_subtitle++;
continue;
}
continue;
}
- if( p_sys->subtitle[p_sys->i_subtitle].i_start < 0 )
- {
- p_sys->i_subtitle++;
- continue;
- }
+ p_block->i_dts =
+ p_block->i_pts = 1 + p_subtitle->i_start;
+ if( p_subtitle->i_stop > 0 && p_subtitle->i_stop >= p_subtitle->i_start )
+ p_block->i_length = p_subtitle->i_stop - p_subtitle->i_start;
- p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
- p_block->i_dts = p_block->i_pts;
- if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )
- {
- p_block->i_length =
- p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;
- }
+ memcpy( p_block->p_buffer, p_subtitle->psz_text, i_len );
+
+ es_out_Send( p_demux->out, p_sys->es, p_block );
- memcpy( p_block->p_buffer,
- p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );
- if( p_block->i_pts > 0 )
- {
- es_out_Send( p_demux->out, p_sys->es, p_block );
- }
- else
- {
- block_Release( p_block );
- }
p_sys->i_subtitle++;
}
(int64_t)m2 * 60*1000 +
(int64_t)s2 * 1000 +
(int64_t)d2 ) * 1000;
- break;
+ if( p_subtitle->i_start < p_subtitle->i_stop )
+ break;
}
}
psz_text = strdup("");
if( !psz_text )
return VLC_ENOMEM;
+
for( ;; )
{
const char *s = TextGetLine( txt );
int i_len;
int i_old;
- if( !s )
- {
- free( psz_text );
- return VLC_EGENERIC;
- }
-
- i_len = strlen( s );
+ i_len = s ? strlen( s ) : 0;
if( i_len <= 0 )
{
p_subtitle->psz_text = psz_text;
i_old = strlen( psz_text );
psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
if( !psz_text )
+ {
return VLC_ENOMEM;
+ }
strcat( psz_text, s );
strcat( psz_text, "\n" );
return ParseSubRipSubViewer( p_demux, p_subtitle,
"%d:%d:%d.%d,%d:%d:%d.%d",
- true );
+ true )
}
/* ParseSSA
const char *s = TextGetLine( txt );
if( !s )
+ {
+ free( psz_text );
return VLC_EGENERIC;
+ }
/* Data Lines */
if( sscanf (s, "-->> %d", &t) == 1)
const char *s = TextGetLine( txt );
if( !s )
+ {
+ free( psz_text );
return VLC_EGENERIC;
+ }
if( strstr( s, "FORMAT" ) )
{
psz_temp = malloc( strlen(s) );
if( !psz_temp )
+ {
+ free( psz_text );
return VLC_ENOMEM;
+ }
if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
{
const char *s = TextGetLine( txt );
if( !s )
+ {
+ free( psz_text );
return VLC_EGENERIC;
+ }
int i_len = strlen( s );
if( i_len == 0 )
}
}
- while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
- {
+ while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
+ {
const char *s2 = TextGetLine( txt );
if( !s2 )
+ {
+ free( psz_orig );
return VLC_EGENERIC;
+ }
int i_len = strlen( s2 );
if( i_len == 0 )
psz_orig = psz_text;
strcat( psz_text, s2 );
- }
+ }
/* Skip the blanks */
while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
VLC_UNUSED( i_idx );
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
- char *psz_text;
- char psz_end[12]= "", psz_begin[12] = "";
+ char *psz_text = NULL;
for( ;; )
{
int h1 = 0, m1 = 0, s1 = 0, f1 = 0;
int h2 = 0, m2 = 0, s2 = 0, f2 = 0;
const char *s = TextGetLine( txt );
+ free( psz_text );
if( !s )
return VLC_EGENERIC;
char *psz_temp = strcasestr( s, "<time");
if( psz_temp != NULL )
{
+ char psz_end[12], psz_begin[12];
/* Line has begin and end */
if( ( sscanf( psz_temp,
- "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\" %*[e|E]nd=\"%[^\"]%*[^>]%[^\n\r]",
+ "<%*[t|T]ime %*[b|B]egin=\"%11[^\"]\" %*[e|E]nd=\"%11[^\"]%*[^>]%[^\n\r]",
psz_begin, psz_end, psz_text) != 3 ) &&
/* Line has begin and no end */
( sscanf( psz_temp,
- "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\"%*[^>]%[^\n\r]",
+ "<%*[t|T]ime %*[b|B]egin=\"%11[^\"]\"%*[^>]%[^\n\r]",
psz_begin, psz_text ) != 2) )
/* Line is not recognized */
{
- free( psz_text );
continue;
}
}
break;
}
- /* Line is not recognized */
- else continue;
- free( psz_text );
}
/* Get the following Lines */
const char *s = TextGetLine( txt );
if( !s )
+ {
+ free( psz_text );
return VLC_EGENERIC;
+ }
int i_len = strlen( s );
if( i_len == 0 ) break;
char *s = TextGetLine( txt );
if( !s )
+ {
+ free( psz_text );
return VLC_EGENERIC;
+ }
if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
s = TextGetLine( txt );
if( !s )
+ {
+ free( psz_text );
return VLC_EGENERIC;
+ }
if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +