- /* Now read text until a line containing "}" */
- for( i_buffer_text = 0;; )
- {
- int i_len;
- if( ( s = TextGetLine( txt ) ) == NULL )
- {
- return( VLC_EGENERIC );
- }
-
- i_len = strlen( s );
- if( i_len == 1 && s[0] == '}' )
- {
- /* "}" -> end of this subtitle */
- buffer_text[__MAX( i_buffer_text - 1, 0 )] = '\0';
- p_subtitle->i_start = i_start;
- p_subtitle->i_stop = 0;
- p_subtitle->psz_text = strdup( buffer_text );
- return 0;
- }
- else
- {
- if( i_buffer_text + i_len + 1 < 10 * MAX_LINE )
- {
- memcpy( buffer_text + i_buffer_text,
- s,
- i_len );
- i_buffer_text += i_len;
-
- buffer_text[i_buffer_text] = '\n';
- i_buffer_text++;
- }
- }
- }
+ /* Now read text until a line containing "}" */
+ 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 );
+ if( i_len == 1 && s[0] == '}')
+ {
+ p_subtitle->psz_text = psz_text;
+ return VLC_SUCCESS;
+ }
+
+ 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" );
+ }
+}
+
+/* ParseMPL2
+ * Format
+ * [n1][n2]Line1|Line2|Line3...
+ * where n1 and n2 are the video frame number (n2 can be empty)
+ */
+static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle )
+{
+ 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 i_start;
+ int i_stop;
+
+ if( !s )
+ return VLC_EGENERIC;
+
+ psz_text = malloc( strlen(s) + 1 );
+
+ i_start = 0;
+ i_stop = 0;
+ if( sscanf( s, "[%d][] %[^\r\n]", &i_start, psz_text ) == 2 ||
+ sscanf( s, "[%d][%d] %[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
+ {
+ p_subtitle->i_start = (int64_t)i_start * 100000;
+ p_subtitle->i_stop = (int64_t)i_stop * 100000;
+ break;