1 /*****************************************************************************
2 * subtitle.c: Demux for subtitle text files.
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Derk-Jan Hartman <hartman at videolan dot org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
35 #include <vlc_plugin.h>
36 #include <vlc_input.h>
39 #ifdef HAVE_SYS_TYPES_H
40 # include <sys/types.h>
44 #include <vlc_demux.h>
45 #include <vlc_charset.h>
47 /*****************************************************************************
49 *****************************************************************************/
50 static int Open ( vlc_object_t *p_this );
51 static void Close( vlc_object_t *p_this );
53 #define SUB_DELAY_LONGTEXT \
54 N_("Apply a delay to all subtitles (in 1/10s, eg 100 means 10s).")
55 #define SUB_FPS_LONGTEXT \
56 N_("Override the normal frames per second settings. " \
57 "This will only work with MicroDVD and SubRIP (SRT) subtitles.")
58 #define SUB_TYPE_LONGTEXT \
59 N_("Force the subtiles format. Valid values are : \"microdvd\", " \
60 "\"subrip\", \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\" " \
61 "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\" "\
62 "\"mpsub\" \"jacosub\" \"psb\" \"realtext\" \"dks\" and \"auto\" " \
63 "(meaning autodetection, this should always work).")
65 static const char *ppsz_sub_type[] =
67 "auto", "microdvd", "subrip", "subviewer", "ssa1",
68 "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2",
69 "aqt", "pjs", "mpsub", "jacosub", "psb", "rt", "dks"
73 set_shortname( _("Subtitles"));
74 set_description( _("Text subtitles parser") );
75 set_capability( "demux", 0 );
76 set_category( CAT_INPUT );
77 set_subcategory( SUBCAT_INPUT_DEMUX );
78 add_float( "sub-fps", 0.0, NULL,
79 N_("Frames per second"),
80 SUB_FPS_LONGTEXT, true );
81 add_integer( "sub-delay", 0, NULL,
82 N_("Subtitles delay"),
83 SUB_DELAY_LONGTEXT, true );
84 add_string( "sub-type", "auto", NULL, N_("Subtitles format"),
85 SUB_TYPE_LONGTEXT, true );
86 change_string_list( ppsz_sub_type, NULL, NULL );
87 set_callbacks( Open, Close );
89 add_shortcut( "subtitle" );
92 /*****************************************************************************
94 *****************************************************************************/
97 SUB_TYPE_UNKNOWN = -1,
105 SUB_TYPE_SUBVIEWER, //SUBVIEWER 2!
106 SUB_TYPE_DVDSUBTITLE,
125 static int TextLoad( text_t *, stream_t *s );
126 static void TextUnload( text_t * );
143 int64_t i_next_demux_date;
144 int64_t i_microsecperframe;
149 subtitle_t *subtitle;
154 static int ParseMicroDvd ( demux_t *, subtitle_t *, int );
155 static int ParseSubRip ( demux_t *, subtitle_t *, int );
156 static int ParseSubViewer ( demux_t *, subtitle_t *, int );
157 static int ParseSSA ( demux_t *, subtitle_t *, int );
158 static int ParseVplayer ( demux_t *, subtitle_t *, int );
159 static int ParseSami ( demux_t *, subtitle_t *, int );
160 static int ParseDVDSubtitle( demux_t *, subtitle_t *, int );
161 static int ParseMPL2 ( demux_t *, subtitle_t *, int );
162 static int ParseAQT ( demux_t *, subtitle_t *, int );
163 static int ParsePJS ( demux_t *, subtitle_t *, int );
164 static int ParseMPSub ( demux_t *, subtitle_t *, int );
165 static int ParseJSS ( demux_t *, subtitle_t *, int );
166 static int ParsePSB ( demux_t *, subtitle_t *, int );
167 static int ParseRealText ( demux_t *, subtitle_t *, int );
168 static int ParseDKS ( demux_t *, subtitle_t *, int );
169 static int ParseSub1 ( demux_t *, subtitle_t *, int );
173 const char *psz_type_name;
175 const char *psz_name;
176 int (*pf_read)( demux_t *, subtitle_t*, int );
177 } sub_read_subtitle_function [] =
179 { "microdvd", SUB_TYPE_MICRODVD, "MicroDVD", ParseMicroDvd },
180 { "subrip", SUB_TYPE_SUBRIP, "SubRIP", ParseSubRip },
181 { "subviewer", SUB_TYPE_SUBVIEWER, "SubViewer", ParseSubViewer },
182 { "ssa1", SUB_TYPE_SSA1, "SSA-1", ParseSSA },
183 { "ssa2-4", SUB_TYPE_SSA2_4, "SSA-2/3/4", ParseSSA },
184 { "ass", SUB_TYPE_ASS, "SSA/ASS", ParseSSA },
185 { "vplayer", SUB_TYPE_VPLAYER, "VPlayer", ParseVplayer },
186 { "sami", SUB_TYPE_SAMI, "SAMI", ParseSami },
187 { "dvdsubtitle",SUB_TYPE_DVDSUBTITLE, "DVDSubtitle", ParseDVDSubtitle },
188 { "mpl2", SUB_TYPE_MPL2, "MPL2", ParseMPL2 },
189 { "aqt", SUB_TYPE_AQT, "AQTitle", ParseAQT },
190 { "pjs", SUB_TYPE_PJS, "PhoenixSub", ParsePJS },
191 { "mpsub", SUB_TYPE_MPSUB, "MPSub", ParseMPSub },
192 { "jacosub", SUB_TYPE_JACOSUB, "JacoSub", ParseJSS },
193 { "psb", SUB_TYPE_PSB, "PowerDivx", ParsePSB },
194 { "realtext", SUB_TYPE_RT, "RealText", ParseRealText },
195 { "dks", SUB_TYPE_DKS, "DKS", ParseDKS },
196 { "subviewer1", SUB_TYPE_SUBVIEW1, "Subviewer 1", ParseSub1 },
197 { NULL, SUB_TYPE_UNKNOWN, "Unknown", NULL }
200 static int Demux( demux_t * );
201 static int Control( demux_t *, int, va_list );
203 /*static void Fix( demux_t * );*/
205 /*****************************************************************************
207 *****************************************************************************/
208 static int Open ( vlc_object_t *p_this )
210 demux_t *p_demux = (demux_t*)p_this;
215 int (*pf_read)( demux_t *, subtitle_t*, int );
218 if( !p_demux->b_force )
220 msg_Dbg( p_demux, "subtitle demux discarded" );
224 p_demux->pf_demux = Demux;
225 p_demux->pf_control = Control;
226 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
230 p_sys->psz_header = NULL;
231 p_sys->i_subtitle = 0;
232 p_sys->i_subtitles = 0;
233 p_sys->subtitle = NULL;
234 p_sys->i_microsecperframe = 40000;
237 f_fps = var_CreateGetFloat( p_demux, "sub-original-fps" ); /* FIXME */
239 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
241 msg_Dbg( p_demux, "Movie fps: %f", f_fps );
243 /* Check for override of the fps */
244 f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
247 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
248 msg_Dbg( p_demux, "Override subtitle fps %f", f_fps );
251 /* Get or probe the type */
252 p_sys->i_type = SUB_TYPE_UNKNOWN;
253 psz_type = var_CreateGetString( p_demux, "sub-type" );
260 if( sub_read_subtitle_function[i].psz_type_name == NULL )
263 if( !strcmp( sub_read_subtitle_function[i].psz_type_name,
266 p_sys->i_type = sub_read_subtitle_function[i].i_type;
273 /* Probe if unknown type */
274 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
279 msg_Dbg( p_demux, "autodetecting subtitle format" );
280 for( i_try = 0; i_try < 256; i_try++ )
285 if( ( s = stream_ReadLine( p_demux->s ) ) == NULL )
288 if( strcasestr( s, "<SAMI>" ) )
290 p_sys->i_type = SUB_TYPE_SAMI;
293 else if( sscanf( s, "{%d}{%d}", &i_dummy, &i_dummy ) == 2 ||
294 sscanf( s, "{%d}{}", &i_dummy ) == 1)
296 p_sys->i_type = SUB_TYPE_MICRODVD;
300 "%d:%d:%d,%d --> %d:%d:%d,%d",
301 &i_dummy,&i_dummy,&i_dummy,&i_dummy,
302 &i_dummy,&i_dummy,&i_dummy,&i_dummy ) == 8 )
304 p_sys->i_type = SUB_TYPE_SUBRIP;
307 else if( !strncasecmp( s, "!: This is a Sub Station Alpha v1", 33 ) )
309 p_sys->i_type = SUB_TYPE_SSA1;
312 else if( !strncasecmp( s, "ScriptType: v4.00+", 18 ) )
314 p_sys->i_type = SUB_TYPE_ASS;
317 else if( !strncasecmp( s, "ScriptType: v4.00", 17 ) )
319 p_sys->i_type = SUB_TYPE_SSA2_4;
322 else if( !strncasecmp( s, "Dialogue: Marked", 16 ) )
324 p_sys->i_type = SUB_TYPE_SSA2_4;
327 else if( !strncasecmp( s, "Dialogue:", 9 ) )
329 p_sys->i_type = SUB_TYPE_ASS;
332 else if( strcasestr( s, "[INFORMATION]" ) )
334 p_sys->i_type = SUB_TYPE_SUBVIEWER; /* I hope this will work */
337 else if( sscanf( s, "%d:%d:%d.%d %d:%d:%d",
338 &i_dummy, &i_dummy, &i_dummy, &i_dummy,
339 &i_dummy, &i_dummy, &i_dummy ) == 7 ||
340 sscanf( s, "@%d @%d", &i_dummy, &i_dummy) == 2)
342 p_sys->i_type = SUB_TYPE_JACOSUB;
345 else if( sscanf( s, "%d:%d:%d:", &i_dummy, &i_dummy, &i_dummy ) == 3 ||
346 sscanf( s, "%d:%d:%d ", &i_dummy, &i_dummy, &i_dummy ) == 3 )
348 p_sys->i_type = SUB_TYPE_VPLAYER;
351 else if( sscanf( s, "{T %d:%d:%d:%d", &i_dummy, &i_dummy,
352 &i_dummy, &i_dummy ) == 4 )
354 p_sys->i_type = SUB_TYPE_DVDSUBTITLE;
357 else if( sscanf( s, "[%d:%d:%d]%c",
358 &i_dummy, &i_dummy, &i_dummy, &p_dummy ) == 4 )
360 p_sys->i_type = SUB_TYPE_DKS;
363 else if( strstr( s, "*** START SCRIPT" ) )
365 p_sys->i_type = SUB_TYPE_SUBVIEW1;
368 else if( sscanf( s, "[%d][%d]", &i_dummy, &i_dummy ) == 2 ||
369 sscanf( s, "[%d][]", &i_dummy ) == 1)
371 p_sys->i_type = SUB_TYPE_MPL2;
374 else if( sscanf (s, "FORMAT=%d", &i_dummy) == 1 ||
375 ( sscanf (s, "FORMAT=TIM%c", &p_dummy) == 1
378 p_sys->i_type = SUB_TYPE_MPSUB;
381 else if( sscanf( s, "-->> %d", &i_dummy) == 1 )
383 p_sys->i_type = SUB_TYPE_AQT;
386 else if( sscanf( s, "%d,%d,", &i_dummy, &i_dummy ) == 2 )
388 p_sys->i_type = SUB_TYPE_PJS;
391 else if( sscanf( s, "{%d:%d:%d}",
392 &i_dummy, &i_dummy, &i_dummy ) == 3 )
394 p_sys->i_type = SUB_TYPE_PSB;
397 else if( strcasestr( s, "<time" ) )
399 p_sys->i_type = SUB_TYPE_RT;
409 /* It will nearly always work even for non seekable stream thanks the
410 * caching system, and if it fails we lose just a few sub */
411 if( stream_Seek( p_demux->s, 0 ) )
413 msg_Warn( p_demux, "failed to rewind" );
417 /* Quit on unknown subtitles */
418 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
420 msg_Err( p_demux, "failed to recognize subtitle type" );
427 if( sub_read_subtitle_function[i].i_type == p_sys->i_type )
429 msg_Dbg( p_demux, "detected %s format",
430 sub_read_subtitle_function[i].psz_name );
431 pf_read = sub_read_subtitle_function[i].pf_read;
436 msg_Dbg( p_demux, "loading all subtitles..." );
438 /* Load the whole file */
439 TextLoad( &p_sys->txt, p_demux->s );
444 if( p_sys->i_subtitles >= i_max )
447 if( !( p_sys->subtitle = realloc( p_sys->subtitle,
448 sizeof(subtitle_t) * i_max ) ) )
450 msg_Err( p_demux, "out of memory");
451 free( p_sys->subtitle );
452 TextUnload( &p_sys->txt );
458 if( pf_read( p_demux, &p_sys->subtitle[p_sys->i_subtitles],
459 p_sys->i_subtitles ) )
462 p_sys->i_subtitles++;
465 TextUnload( &p_sys->txt );
467 msg_Dbg(p_demux, "loaded %d subtitles", p_sys->i_subtitles );
469 /* Fix subtitle (order and time) *** */
470 p_sys->i_subtitle = 0;
472 if( p_sys->i_subtitles > 0 )
474 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_stop;
476 if( p_sys->i_length <= 0 )
477 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_start+1;
480 /* *** add subtitle ES *** */
481 if( p_sys->i_type == SUB_TYPE_SSA1 ||
482 p_sys->i_type == SUB_TYPE_SSA2_4 ||
483 p_sys->i_type == SUB_TYPE_ASS )
485 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','s','a',' ' ) );
489 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','u','b','t' ) );
491 if( p_sys->psz_header != NULL )
493 fmt.i_extra = strlen( p_sys->psz_header ) + 1;
494 fmt.p_extra = strdup( p_sys->psz_header );
496 p_sys->es = es_out_Add( p_demux->out, &fmt );
501 /*****************************************************************************
502 * Close: Close subtitle demux
503 *****************************************************************************/
504 static void Close( vlc_object_t *p_this )
506 demux_t *p_demux = (demux_t*)p_this;
507 demux_sys_t *p_sys = p_demux->p_sys;
510 for( i = 0; i < p_sys->i_subtitles; i++ )
511 free( p_sys->subtitle[i].psz_text );
512 free( p_sys->subtitle );
517 /*****************************************************************************
519 *****************************************************************************/
520 static int Control( demux_t *p_demux, int i_query, va_list args )
522 demux_sys_t *p_sys = p_demux->p_sys;
528 case DEMUX_GET_LENGTH:
529 pi64 = (int64_t*)va_arg( args, int64_t * );
530 *pi64 = p_sys->i_length;
534 pi64 = (int64_t*)va_arg( args, int64_t * );
535 if( p_sys->i_subtitle < p_sys->i_subtitles )
537 *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;
543 i64 = (int64_t)va_arg( args, int64_t );
544 p_sys->i_subtitle = 0;
545 while( p_sys->i_subtitle < p_sys->i_subtitles &&
546 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
551 if( p_sys->i_subtitle >= p_sys->i_subtitles )
555 case DEMUX_GET_POSITION:
556 pf = (double*)va_arg( args, double * );
557 if( p_sys->i_subtitle >= p_sys->i_subtitles )
561 else if( p_sys->i_subtitles > 0 )
563 *pf = (double)p_sys->subtitle[p_sys->i_subtitle].i_start /
564 (double)p_sys->i_length;
572 case DEMUX_SET_POSITION:
573 f = (double)va_arg( args, double );
574 i64 = f * p_sys->i_length;
576 p_sys->i_subtitle = 0;
577 while( p_sys->i_subtitle < p_sys->i_subtitles &&
578 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
582 if( p_sys->i_subtitle >= p_sys->i_subtitles )
586 case DEMUX_SET_NEXT_DEMUX_TIME:
587 p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t );
592 case DEMUX_GET_ATTACHMENTS:
593 case DEMUX_GET_TITLE_INFO:
594 case DEMUX_HAS_UNSUPPORTED_META:
598 msg_Err( p_demux, "unknown query %d in subtitle control", i_query );
603 /*****************************************************************************
604 * Demux: Send subtitle to decoder
605 *****************************************************************************/
606 static int Demux( demux_t *p_demux )
608 demux_sys_t *p_sys = p_demux->p_sys;
611 if( p_sys->i_subtitle >= p_sys->i_subtitles )
614 i_maxdate = p_sys->i_next_demux_date - var_GetTime( p_demux->p_parent, "spu-delay" );;
615 if( i_maxdate <= 0 && p_sys->i_subtitle < p_sys->i_subtitles )
617 /* Should not happen */
618 i_maxdate = p_sys->subtitle[p_sys->i_subtitle].i_start + 1;
621 while( p_sys->i_subtitle < p_sys->i_subtitles &&
622 p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
625 int i_len = strlen( p_sys->subtitle[p_sys->i_subtitle].psz_text ) + 1;
634 if( ( p_block = block_New( p_demux, i_len ) ) == NULL )
640 if( p_sys->subtitle[p_sys->i_subtitle].i_start < 0 )
646 p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
647 p_block->i_dts = p_block->i_pts;
648 if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )
651 p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;
654 memcpy( p_block->p_buffer,
655 p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );
656 if( p_block->i_pts > 0 )
658 es_out_Send( p_demux->out, p_sys->es, p_block );
662 block_Release( p_block );
668 p_sys->i_next_demux_date = 0;
673 /*****************************************************************************
674 * Fix: fix time stamp and order of subtitle
675 *****************************************************************************/
676 #ifdef USE_THIS_UNUSED_PIECE_OF_CODE
677 static void Fix( demux_t *p_demux )
679 demux_sys_t *p_sys = p_demux->p_sys;
683 /* *** fix order (to be sure...) *** */
684 /* We suppose that there are near in order and this durty bubble sort
685 * wont take too much time
690 for( i_index = 1; i_index < p_sys->i_subtitles; i_index++ )
692 if( p_sys->subtitle[i_index].i_start <
693 p_sys->subtitle[i_index - 1].i_start )
697 p_sys->subtitle + i_index - 1,
698 sizeof( subtitle_t ) );
699 memcpy( p_sys->subtitle + i_index - 1,
700 p_sys->subtitle + i_index,
701 sizeof( subtitle_t ) );
702 memcpy( p_sys->subtitle + i_index,
704 sizeof( subtitle_t ) );
712 static int TextLoad( text_t *txt, stream_t *s )
718 txt->i_line_count = 0;
720 txt->line = calloc( i_line_max, sizeof( char * ) );
722 /* load the complete file */
725 char *psz = stream_ReadLine( s );
730 txt->line[txt->i_line_count++] = psz;
731 if( txt->i_line_count >= i_line_max )
734 txt->line = realloc( txt->line, i_line_max * sizeof( char * ) );
738 if( txt->i_line_count <= 0 )
746 static void TextUnload( text_t *txt )
750 for( i = 0; i < txt->i_line_count; i++ )
752 free( txt->line[i] );
756 txt->i_line_count = 0;
759 static char *TextGetLine( text_t *txt )
761 if( txt->i_line >= txt->i_line_count )
764 return txt->line[txt->i_line++];
766 static void TextPreviousLine( text_t *txt )
768 if( txt->i_line > 0 )
772 /*****************************************************************************
773 * Specific Subtitle function
774 *****************************************************************************/
777 * {n1}{n2}Line1|Line2|Line3....
778 * where n1 and n2 are the video frame number (n2 can be empty)
780 static int ParseMicroDvd( demux_t *p_demux, subtitle_t *p_subtitle,
784 demux_sys_t *p_sys = p_demux->p_sys;
785 text_t *txt = &p_sys->txt;
793 const char *s = TextGetLine( txt );
797 psz_text = malloc( strlen(s) + 1 );
803 if( sscanf( s, "{%d}{}%[^\r\n]", &i_start, psz_text ) == 2 ||
804 sscanf( s, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
807 if( i_start != 1 || i_stop != 1 )
810 /* We found a possible setting of the framerate "{1}{1}23.976" */
811 /* Check if it's usable, and if the sub-fps is not set */
812 f_fps = us_strtod( psz_text, NULL );
813 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
814 p_sys->i_microsecperframe = (int64_t)((float)1000000 / f_fps);
819 /* replace | by \n */
820 for( i = 0; psz_text[i] != '\0'; i++ )
822 if( psz_text[i] == '|' )
827 p_subtitle->i_start = i_start * p_sys->i_microsecperframe;
828 p_subtitle->i_stop = i_stop * p_sys->i_microsecperframe;
829 p_subtitle->psz_text = psz_text;
833 /* ParseSubRipSubViewer
836 * h1:m1:s1,d1 --> h2:m2:s2,d2
841 * Format SubViewer v1/v2
842 * h1:m1:s1.d1,h2:m2:s2.d2
847 * We ignore line number for SubRip
849 static int ParseSubRipSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
853 demux_sys_t *p_sys = p_demux->p_sys;
854 text_t *txt = &p_sys->txt;
859 const char *s = TextGetLine( txt );
860 int h1, m1, s1, d1, h2, m2, s2, d2;
865 if( sscanf( s, psz_fmt,
867 &h2, &m2, &s2, &d2 ) == 8 )
869 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
870 (int64_t)m1 * 60*1000 +
872 (int64_t)d1 ) * 1000;
874 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
875 (int64_t)m2 * 60*1000 +
877 (int64_t)d2 ) * 1000;
882 /* Now read text until an empty line */
883 psz_text = strdup("");
888 const char *s = TextGetLine( txt );
901 p_subtitle->psz_text = psz_text;
905 i_old = strlen( psz_text );
906 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
909 strcat( psz_text, s );
910 strcat( psz_text, "\n" );
912 /* replace [br] by \n */
917 while( ( p = strstr( psz_text, "[br]" ) ) )
920 memmove( p, &p[3], strlen(&p[3])+1 );
927 static int ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle,
931 return ParseSubRipSubViewer( p_demux, p_subtitle,
932 "%d:%d:%d,%d --> %d:%d:%d,%d",
937 static int ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
942 return ParseSubRipSubViewer( p_demux, p_subtitle,
943 "%d:%d:%d.%d,%d:%d:%d.%d",
949 static int ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle,
952 demux_sys_t *p_sys = p_demux->p_sys;
953 text_t *txt = &p_sys->txt;
957 const char *s = TextGetLine( txt );
958 int h1, m1, s1, c1, h2, m2, s2, c2;
965 /* We expect (SSA2-4):
966 * Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
967 * Dialogue: Marked=0,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
969 * SSA-1 is similar but only has 8 commas up untill the subtitle text. Probably the Effect field is no present, but not 100 % sure.
973 * Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
974 * Dialogue: Layer#,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
977 /* The output text is - at least, not removing numbers - 18 chars shorter than the input text. */
978 psz_text = malloc( strlen(s) );
983 "Dialogue: %15[^,],%d:%d:%d.%d,%d:%d:%d.%d,%[^\r\n]",
989 /* The dec expects: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */
990 /* (Layer comes from ASS specs ... it's empty for SSA.) */
991 if( p_sys->i_type == SUB_TYPE_SSA1 )
993 /* SSA1 has only 8 commas before the text starts, not 9 */
994 memmove( &psz_text[1], psz_text, strlen(psz_text)+1 );
999 int i_layer = ( p_sys->i_type == SUB_TYPE_ASS ) ? atoi( temp ) : 0;
1001 /* ReadOrder, Layer, %s(rest of fields) */
1002 snprintf( temp, sizeof(temp), "%d,%d,", i_idx, i_layer );
1003 memmove( psz_text + strlen(temp), psz_text, strlen(psz_text)+1 );
1004 memcpy( psz_text, temp, strlen(temp) );
1007 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1008 (int64_t)m1 * 60*1000 +
1009 (int64_t)s1 * 1000 +
1010 (int64_t)c1 * 10 ) * 1000;
1011 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1012 (int64_t)m2 * 60*1000 +
1013 (int64_t)s2 * 1000 +
1014 (int64_t)c2 * 10 ) * 1000;
1015 p_subtitle->psz_text = psz_text;
1020 /* All the other stuff we add to the header field */
1021 if( !p_sys->psz_header )
1022 p_sys->psz_header = strdup( "" );
1023 if( !p_sys->psz_header )
1027 realloc( p_sys->psz_header,
1028 strlen( p_sys->psz_header ) + strlen( s ) + 2 );
1029 strcat( p_sys->psz_header, s );
1030 strcat( p_sys->psz_header, "\n" );
1036 * h:m:s:Line1|Line2|Line3....
1038 * h:m:s Line1|Line2|Line3....
1040 static int ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle,
1043 VLC_UNUSED( i_idx );
1045 demux_sys_t *p_sys = p_demux->p_sys;
1046 text_t *txt = &p_sys->txt;
1052 const char *s = TextGetLine( txt );
1056 return VLC_EGENERIC;
1058 psz_text = malloc( strlen( s ) + 1 );
1062 if( sscanf( s, "%d:%d:%d%*c%[^\r\n]",
1063 &h1, &m1, &s1, psz_text ) == 4 )
1065 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1066 (int64_t)m1 * 60*1000 +
1067 (int64_t)s1 * 1000 ) * 1000;
1068 p_subtitle->i_stop = 0;
1074 /* replace | by \n */
1075 for( i = 0; psz_text[i] != '\0'; i++ )
1077 if( psz_text[i] == '|' )
1080 p_subtitle->psz_text = psz_text;
1086 static char *ParseSamiSearch( text_t *txt,
1087 char *psz_start, const char *psz_str )
1089 if( psz_start && strcasestr( psz_start, psz_str ) )
1091 char *s = strcasestr( psz_start, psz_str );
1092 return &s[strlen( psz_str )];
1097 char *p = TextGetLine( txt );
1101 if( strcasestr( p, psz_str ) )
1103 char *s = strcasestr( p, psz_str );
1104 return &s[strlen( psz_str )];
1108 static int ParseSami( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1110 VLC_UNUSED( i_idx );
1111 demux_sys_t *p_sys = p_demux->p_sys;
1112 text_t *txt = &p_sys->txt;
1117 unsigned int i_text;
1118 char text[8192]; /* Arbitrary but should be long enough */
1120 /* search "Start=" */
1121 if( !( s = ParseSamiSearch( txt, NULL, "Start=" ) ) )
1122 return VLC_EGENERIC;
1124 /* get start value */
1125 i_start = strtol( s, &s, 0 );
1128 if( !( s = ParseSamiSearch( txt, s, "<P" ) ) )
1129 return VLC_EGENERIC;
1132 if( !( s = ParseSamiSearch( txt, s, ">" ) ) )
1133 return VLC_EGENERIC;
1137 /* now get all txt until a "Start=" line */
1141 /* Search non empty line */
1142 while( s && *s == '\0' )
1143 s = TextGetLine( txt );
1149 if( !strncasecmp( s, "<br", 3 ) )
1153 else if( strcasestr( s, "Start=" ) )
1155 TextPreviousLine( txt );
1158 s = ParseSamiSearch( txt, s, ">" );
1160 else if( !strncmp( s, " ", 6 ) )
1165 else if( *s == '\t' )
1175 if( c != '\0' && i_text+1 < sizeof(text) )
1178 text[i_text] = '\0';
1182 p_subtitle->i_start = i_start * 1000;
1183 p_subtitle->i_stop = 0;
1184 p_subtitle->psz_text = strdup( text );
1196 * TODO it can have a header
1203 * LANG support would be cool
1204 * CODEPAGE is probably mandatory FIXME
1206 static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle,
1209 VLC_UNUSED( i_idx );
1211 demux_sys_t *p_sys = p_demux->p_sys;
1212 text_t *txt = &p_sys->txt;
1217 const char *s = TextGetLine( txt );
1221 return VLC_EGENERIC;
1225 &h1, &m1, &s1, &c1 ) == 4 )
1227 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1228 (int64_t)m1 * 60*1000 +
1229 (int64_t)s1 * 1000 +
1230 (int64_t)c1 * 10) * 1000;
1231 p_subtitle->i_stop = 0;
1236 /* Now read text until a line containing "}" */
1237 psz_text = strdup("");
1242 const char *s = TextGetLine( txt );
1249 return VLC_EGENERIC;
1252 i_len = strlen( s );
1253 if( i_len == 1 && s[0] == '}')
1255 p_subtitle->psz_text = psz_text;
1259 i_old = strlen( psz_text );
1260 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1263 strcat( psz_text, s );
1264 strcat( psz_text, "\n" );
1270 * [n1][n2]Line1|Line2|Line3...
1271 * where n1 and n2 are the video frame number (n2 can be empty)
1273 static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1275 VLC_UNUSED( i_idx );
1277 demux_sys_t *p_sys = p_demux->p_sys;
1278 text_t *txt = &p_sys->txt;
1284 const char *s = TextGetLine( txt );
1289 return VLC_EGENERIC;
1291 psz_text = malloc( strlen(s) + 1 );
1297 if( sscanf( s, "[%d][] %[^\r\n]", &i_start, psz_text ) == 2 ||
1298 sscanf( s, "[%d][%d] %[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
1300 p_subtitle->i_start = (int64_t)i_start * 100000;
1301 p_subtitle->i_stop = (int64_t)i_stop * 100000;
1307 for( i = 0; psz_text[i] != '\0'; )
1309 /* replace | by \n */
1310 if( psz_text[i] == '|' )
1314 if( psz_text[i] == '/' && ( i == 0 || psz_text[i-1] == '\n' ) )
1315 memmove( &psz_text[i], &psz_text[i+1], strlen(&psz_text[i+1])+1 );
1319 p_subtitle->psz_text = psz_text;
1323 static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1325 VLC_UNUSED( i_idx );
1327 demux_sys_t *p_sys = p_demux->p_sys;
1328 text_t *txt = &p_sys->txt;
1329 char *psz_text = strdup( "" );
1331 int i_firstline = 1;
1337 const char *s = TextGetLine( txt );
1340 return VLC_EGENERIC;
1343 if( sscanf (s, "-->> %d", &t) == 1)
1345 p_subtitle->i_start = (int64_t)t; /* * FPS*/
1346 p_subtitle->i_stop = 0;
1348 /* Starting of a subtitle */
1353 /* We have been too far: end of the subtitle, begin of next */
1356 TextPreviousLine( txt );
1363 i_old = strlen( psz_text ) + 1;
1364 psz_text = realloc( psz_text, i_old + strlen( s ) + 1 );
1367 strcat( psz_text, s );
1368 strcat( psz_text, "\n" );
1369 if( txt->i_line == txt->i_line_count )
1373 p_subtitle->psz_text = psz_text;
1377 static int ParsePJS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1379 VLC_UNUSED( i_idx );
1381 demux_sys_t *p_sys = p_demux->p_sys;
1382 text_t *txt = &p_sys->txt;
1388 const char *s = TextGetLine( txt );
1392 return VLC_EGENERIC;
1394 psz_text = malloc( strlen(s) + 1 );
1399 if( sscanf (s, "%d,%d,\"%[^\n\r]", &t1, &t2, psz_text ) == 3 )
1401 /* 1/10th of second ? Frame based ? FIXME */
1402 p_subtitle->i_start = 10 * t1;
1403 p_subtitle->i_stop = 10 * t2;
1404 /* Remove latest " */
1405 psz_text[ strlen(psz_text) - 1 ] = '\0';
1412 /* replace | by \n */
1413 for( i = 0; psz_text[i] != '\0'; i++ )
1415 if( psz_text[i] == '|' )
1419 p_subtitle->psz_text = psz_text;
1420 msg_Dbg( p_demux, "%s", psz_text );
1424 static float mpsub_total = 0.0;
1425 static float mpsub_factor = 0.0;
1427 static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1429 VLC_UNUSED( i_idx );
1431 demux_sys_t *p_sys = p_demux->p_sys;
1432 text_t *txt = &p_sys->txt;
1433 char *psz_text = strdup( "" );
1441 const char *s = TextGetLine( txt );
1443 return VLC_EGENERIC;
1445 if( strstr( s, "FORMAT" ) )
1447 if( sscanf (s, "FORMAT=TIM%c", &p_dummy ) == 1 && p_dummy == 'E')
1449 mpsub_factor = 100.0;
1453 psz_temp = malloc( strlen(s) );
1457 if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
1460 f_fps = us_strtod( psz_temp, NULL );
1461 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
1462 var_SetFloat( p_demux, "sub-fps", f_fps );
1471 if( sscanf (s, "%f %f", &f1, &f2 ) == 2 )
1473 mpsub_total += f1 * mpsub_factor;
1474 p_subtitle->i_start = (int64_t)(10000.0 * mpsub_total);
1475 mpsub_total += f2 * mpsub_factor;
1476 p_subtitle->i_stop = (int64_t)(10000.0 * mpsub_total);
1483 const char *s = TextGetLine( txt );
1486 return VLC_EGENERIC;
1488 int i_len = strlen( s );
1492 int i_old = strlen( psz_text );
1494 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1498 strcat( psz_text, s );
1499 strcat( psz_text, "\n" );
1502 p_subtitle->psz_text = psz_text;
1506 static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1508 VLC_UNUSED( i_idx );
1510 demux_sys_t *p_sys = p_demux->p_sys;
1511 text_t *txt = &p_sys->txt;
1512 char *psz_text, *psz_orig;
1513 char *psz_text2, *psz_orig2;
1514 int h1, h2, m1, m2, s1, s2, f1, f2;
1516 static int i_comment = 0;
1518 static int jss_time_resolution = 30;
1519 static int jss_time_shift = 0;
1521 /* Parse the main lines */
1524 const char *s = TextGetLine( txt );
1526 return VLC_EGENERIC;
1528 psz_orig = malloc( strlen( s ) + 1 );
1531 psz_text = psz_orig;
1533 /* Complete time lines */
1534 if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]",
1535 &h1, &m1, &s1, &f1, &h2, &m2, &s2, &f2, psz_text ) == 9 )
1537 p_subtitle->i_start = ( (int64_t)( h1 *3600 + m1 * 60 + s1 ) +
1538 (int64_t)( ( f1 + jss_time_shift ) / jss_time_resolution ) )
1540 p_subtitle->i_stop = ( (int64_t)( h2 *3600 + m2 * 60 + s2 ) +
1541 (int64_t)( ( f2 + jss_time_shift ) / jss_time_resolution ) )
1545 /* Short time lines */
1546 else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 )
1548 p_subtitle->i_start = (int64_t)(
1549 ( f1 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
1550 p_subtitle->i_stop = (int64_t)(
1551 ( f2 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
1554 /* General Directive lines */
1555 /* Only TIME and SHIFT are supported so far */
1556 else if( s[0] == '#' )
1558 int h = 0, m =0, sec = 1, f = 1;
1562 strcpy( psz_text, s );
1564 switch( toupper( psz_text[1] ) )
1567 shift = isalpha( psz_text[2] ) ? 6 : 2 ;
1569 if( sscanf( &psz_text[shift], "%d", &h ) )
1571 /* Negative shifting */
1578 if( sscanf( &psz_text[shift], "%*d:%d", &m ) )
1580 if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) )
1582 sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f );
1587 sscanf( &psz_text[shift], "%d:%d.%d",
1595 sscanf( &psz_text[shift], "%d.%d", &sec, &f);
1598 jss_time_shift = ( ( h * 3600 + m * 60 + sec )
1599 * jss_time_resolution + f ) * inv;
1604 shift = isalpha( psz_text[2] ) ? 8 : 2 ;
1606 sscanf( &psz_text[shift], "%d", &jss_time_resolution );
1613 /* Unkown type line, probably a comment */
1620 while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
1622 const char *s2 = TextGetLine( txt );
1625 return VLC_EGENERIC;
1627 int i_len = strlen( s2 );
1631 int i_old = strlen( psz_text );
1633 psz_text = realloc( psz_text, i_old + i_len + 1 );
1637 psz_orig = psz_text;
1638 strcat( psz_text, s2 );
1641 /* Skip the blanks */
1642 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1644 /* Parse the directives */
1645 if( isalpha( *psz_text ) || *psz_text == '[' )
1647 while( *psz_text != ' ' )
1650 /* Directives are NOT parsed yet */
1651 /* This has probably a better place in a decoder ? */
1652 /* directive = malloc( strlen( psz_text ) + 1 );
1653 if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/
1656 /* Skip the blanks after directives */
1657 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1659 /* Clean all the lines from inline comments and other stuffs */
1660 psz_orig2 = calloc( strlen( psz_text) + 1, 1 );
1661 psz_text2 = psz_orig2;
1663 for( ; *psz_text != '\0' && *psz_text != '\n' && *psz_text != '\r'; )
1674 if( (*(psz_text + 1 ) ) == ' ' ) psz_text++;
1686 if( (*(psz_text + 1 ) ) == ' ' || (*(psz_text + 1 ) ) == '\t' )
1695 if( (*(psz_text + 1 ) ) == 'n' )
1702 if( ( toupper(*(psz_text + 1 ) ) == 'C' ) ||
1703 ( toupper(*(psz_text + 1 ) ) == 'F' ) )
1705 psz_text++; psz_text++;
1708 if( (*(psz_text + 1 ) ) == 'B' || (*(psz_text + 1 ) ) == 'b' ||
1709 (*(psz_text + 1 ) ) == 'I' || (*(psz_text + 1 ) ) == 'i' ||
1710 (*(psz_text + 1 ) ) == 'U' || (*(psz_text + 1 ) ) == 'u' ||
1711 (*(psz_text + 1 ) ) == 'D' || (*(psz_text + 1 ) ) == 'N' )
1716 if( (*(psz_text + 1 ) ) == '~' || (*(psz_text + 1 ) ) == '{' ||
1717 (*(psz_text + 1 ) ) == '\\' )
1719 else if( *(psz_text + 1 ) == '\r' || *(psz_text + 1 ) == '\n' ||
1720 *(psz_text + 1 ) == '\0' )
1728 *psz_text2 = *psz_text;
1735 p_subtitle->psz_text = psz_orig2;
1736 msg_Dbg( p_demux, "%s", p_subtitle->psz_text );
1741 static int ParsePSB( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1743 VLC_UNUSED( i_idx );
1745 demux_sys_t *p_sys = p_demux->p_sys;
1746 text_t *txt = &p_sys->txt;
1754 const char *s = TextGetLine( txt );
1757 return VLC_EGENERIC;
1759 psz_text = malloc( strlen( s ) + 1 );
1763 if( sscanf( s, "{%d:%d:%d}{%d:%d:%d}%[^\r\n]",
1764 &h1, &m1, &s1, &h2, &m2, &s2, psz_text ) == 7 )
1766 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1767 (int64_t)m1 * 60*1000 +
1768 (int64_t)s1 * 1000 ) * 1000;
1769 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1770 (int64_t)m2 * 60*1000 +
1771 (int64_t)s2 * 1000 ) * 1000;
1777 /* replace | by \n */
1778 for( i = 0; psz_text[i] != '\0'; i++ )
1780 if( psz_text[i] == '|' )
1783 p_subtitle->psz_text = psz_text;
1787 static int64_t ParseRealTime( char *psz, int *h, int *m, int *s, int *f )
1789 if( strlen( psz ) == 0 ) return 0;
1790 if( sscanf( psz, "%d:%d:%d.%d", h, m, s, f ) == 4 ||
1791 sscanf( psz, "%d:%d.%d", m, s, f ) == 3 ||
1792 sscanf( psz, "%d.%d", s, f ) == 2 ||
1793 sscanf( psz, "%d:%d", m, s ) == 2 ||
1794 sscanf( psz, "%d", s ) == 1 )
1796 return (int64_t)((( *h * 60 + *m ) * 60 ) + *s ) * 1000 * 1000
1797 + (int64_t)*f * 10 * 1000;
1799 else return VLC_EGENERIC;
1802 static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1804 VLC_UNUSED( i_idx );
1805 demux_sys_t *p_sys = p_demux->p_sys;
1806 text_t *txt = &p_sys->txt;
1808 char psz_end[12]= "", psz_begin[12] = "";
1812 int h1 = 0, m1 = 0, s1 = 0, f1 = 0;
1813 int h2 = 0, m2 = 0, s2 = 0, f2 = 0;
1814 const char *s = TextGetLine( txt );
1817 return VLC_EGENERIC;
1819 psz_text = malloc( strlen( s ) + 1 );
1823 /* Find the good begining. This removes extra spaces at the beginning
1825 char *psz_temp = strcasestr( s, "<time");
1826 if( psz_temp != NULL )
1828 /* Line has begin and end */
1829 if( ( sscanf( psz_temp,
1830 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\" %*[e|E]nd=\"%[^\"]%*[^>]%[^\n\r]",
1831 psz_begin, psz_end, psz_text) != 3 ) &&
1832 /* Line has begin and no end */
1834 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\"%*[^>]%[^\n\r]",
1835 psz_begin, psz_text ) != 2) )
1836 /* Line is not recognized */
1843 int64_t i_time = ParseRealTime( psz_begin, &h1, &m1, &s1, &f1 );
1846 p_subtitle->i_start = i_time;
1849 i_time = ParseRealTime( psz_end, &h2, &m2, &s2, &f2 );
1852 p_subtitle->i_stop = i_time;
1856 /* Line is not recognized */
1861 /* Get the following Lines */
1864 const char *s = TextGetLine( txt );
1867 return VLC_EGENERIC;
1869 int i_len = strlen( s );
1870 if( i_len == 0 ) break;
1872 if( strcasestr( s, "<time" ) ||
1873 strcasestr( s, "<clear/") )
1875 TextPreviousLine( txt );
1879 int i_old = strlen( psz_text );
1881 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1885 strcat( psz_text, s );
1886 strcat( psz_text, "\n" );
1889 /* Remove the starting ">" that remained after the sscanf */
1890 memmove( &psz_text[0], &psz_text[1], strlen( psz_text ) );
1892 p_subtitle->psz_text = psz_text;
1897 static int ParseDKS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1899 VLC_UNUSED( i_idx );
1901 demux_sys_t *p_sys = p_demux->p_sys;
1902 text_t *txt = &p_sys->txt;
1909 char *s = TextGetLine( txt );
1912 return VLC_EGENERIC;
1914 psz_text = malloc( strlen( s ) + 1 );
1918 if( sscanf( s, "[%d:%d:%d]%[^\r\n]",
1919 &h1, &m1, &s1, psz_text ) == 4 )
1921 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1922 (int64_t)m1 * 60*1000 +
1923 (int64_t)s1 * 1000 ) * 1000;
1925 char *s = TextGetLine( txt );
1927 return VLC_EGENERIC;
1929 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1930 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1931 (int64_t)m2 * 60*1000 +
1932 (int64_t)s2 * 1000 ) * 1000;
1938 /* replace [br] by \n */
1940 while( ( p = strstr( psz_text, "[br]" ) ) )
1943 memmove( p, &p[3], strlen(&p[3])+1 );
1946 p_subtitle->psz_text = psz_text;
1950 static int ParseSub1( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1952 VLC_UNUSED( i_idx );
1954 demux_sys_t *p_sys = p_demux->p_sys;
1955 text_t *txt = &p_sys->txt;
1962 char *s = TextGetLine( txt );
1965 return VLC_EGENERIC;
1967 if( sscanf( s, "[%d:%d:%d]", &h1, &m1, &s1 ) == 3 )
1969 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1970 (int64_t)m1 * 60*1000 +
1971 (int64_t)s1 * 1000 ) * 1000;
1973 char *s = TextGetLine( txt );
1975 return VLC_EGENERIC;
1977 psz_text = strdup( s );
1981 s = TextGetLine( txt );
1983 return VLC_EGENERIC;
1985 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1986 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1987 (int64_t)m2 * 60*1000 +
1988 (int64_t)s2 * 1000 ) * 1000;
1993 p_subtitle->psz_text = psz_text;