+ free( psz_text );
+
+ /* All the other stuff we add to the header field */
+ if( !p_sys->psz_header )
+ p_sys->psz_header = strdup( "" );
+ if( !p_sys->psz_header )
+ return VLC_ENOMEM;
+
+ p_sys->psz_header =
+ realloc( p_sys->psz_header,
+ strlen( p_sys->psz_header ) + strlen( s ) + 2 );
+ strcat( p_sys->psz_header, s );
+ strcat( p_sys->psz_header, "\n" );
+ }
+}
+
+/* ParseVplayer
+ * Format
+ * h:m:s:Line1|Line2|Line3....
+ * or
+ * h:m:s Line1|Line2|Line3....
+ */
+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;
+ int i;
+
+ for( ;; )
+ {
+ const char *s = TextGetLine( txt );
+ int h1, m1, s1;
+
+ if( !s )
+ return VLC_EGENERIC;
+
+ psz_text = malloc( strlen( s ) + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
+
+ if( sscanf( s, "%d:%d:%d%*c%[^\r\n]",
+ &h1, &m1, &s1, psz_text ) == 4 )
+ {
+ p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
+ (int64_t)m1 * 60*1000 +
+ (int64_t)s1 * 1000 ) * 1000;
+ p_subtitle->i_stop = 0;
+ break;
+ }
+ free( psz_text );
+ }
+
+ /* replace | by \n */
+ for( i = 0; psz_text[i] != '\0'; i++ )
+ {
+ if( psz_text[i] == '|' )
+ psz_text[i] = '\n';
+ }
+ p_subtitle->psz_text = psz_text;
+ return VLC_SUCCESS;
+}
+
+/* ParseSami
+ */
+static char *ParseSamiSearch( text_t *txt,
+ char *psz_start, const char *psz_str )
+{
+ if( psz_start && strcasestr( psz_start, psz_str ) )
+ {
+ char *s = strcasestr( psz_start, psz_str );
+ return &s[strlen( psz_str )];
+ }
+
+ for( ;; )
+ {
+ char *p = TextGetLine( txt );
+ if( !p )
+ return NULL;
+
+ if( strcasestr( p, psz_str ) )
+ {
+ char *s = strcasestr( p, psz_str );
+ return &s[strlen( psz_str )];
+ }
+ }
+}
+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;
+
+ char *s;
+ int64_t i_start;
+
+ unsigned int i_text;
+ char text[8192]; /* Arbitrary but should be long enough */
+
+ /* search "Start=" */
+ if( !( s = ParseSamiSearch( txt, NULL, "Start=" ) ) )
+ return VLC_EGENERIC;
+
+ /* get start value */
+ i_start = strtol( s, &s, 0 );
+
+ /* search <P */
+ if( !( s = ParseSamiSearch( txt, s, "<P" ) ) )
+ return VLC_EGENERIC;
+
+ /* search > */
+ if( !( s = ParseSamiSearch( txt, s, ">" ) ) )
+ return VLC_EGENERIC;
+
+ i_text = 0;
+ text[0] = '\0';
+ /* now get all txt until a "Start=" line */
+ for( ;; )
+ {
+ char c = '\0';
+ /* Search non empty line */
+ while( s && *s == '\0' )
+ s = TextGetLine( txt );
+ if( !s )
+ break;
+
+ if( *s == '<' )