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 *****************************************************************************/
34 #include <vlc_common.h>
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\", \"subviewer\", \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\", " \
61 "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\", "\
62 "\"mpsub\", \"jacosub\", \"psb\", \"realtext\", \"dks\", \"subviewer1\", " \
63 " and \"auto\" (meaning autodetection, this should always work).")
65 static const char *const ppsz_sub_type[] =
67 "auto", "microdvd", "subrip", "subviewer", "ssa1",
68 "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2",
69 "aqt", "pjs", "mpsub", "jacosub", "psb", "realtext", "dks",
74 set_shortname( N_("Subtitles"));
75 set_description( N_("Text subtitles parser") );
76 set_capability( "demux", 0 );
77 set_category( CAT_INPUT );
78 set_subcategory( SUBCAT_INPUT_DEMUX );
79 add_float( "sub-fps", 0.0, NULL,
80 N_("Frames per second"),
81 SUB_FPS_LONGTEXT, true );
82 add_integer( "sub-delay", 0, NULL,
83 N_("Subtitles delay"),
84 SUB_DELAY_LONGTEXT, true );
85 add_string( "sub-type", "auto", NULL, N_("Subtitles format"),
86 SUB_TYPE_LONGTEXT, true );
87 change_string_list( ppsz_sub_type, NULL, NULL );
88 set_callbacks( Open, Close );
90 add_shortcut( "subtitle" );
93 /*****************************************************************************
95 *****************************************************************************/
98 SUB_TYPE_UNKNOWN = -1,
106 SUB_TYPE_SUBVIEWER, /* SUBVIEWER 2 */
107 SUB_TYPE_DVDSUBTITLE, /* Mplayer calls it subviewer2 */
116 SUB_TYPE_SUBVIEW1 /* SUBVIEWER 1 - mplayer calls it subrip09,
117 and Gnome subtitles SubViewer 1.0 */
127 static int TextLoad( text_t *, stream_t *s );
128 static void TextUnload( text_t * );
145 int64_t i_next_demux_date;
146 int64_t i_microsecperframe;
151 subtitle_t *subtitle;
161 int i_time_resolution;
173 static int ParseMicroDvd ( demux_t *, subtitle_t *, int );
174 static int ParseSubRip ( demux_t *, subtitle_t *, int );
175 static int ParseSubViewer ( demux_t *, subtitle_t *, int );
176 static int ParseSSA ( demux_t *, subtitle_t *, int );
177 static int ParseVplayer ( demux_t *, subtitle_t *, int );
178 static int ParseSami ( demux_t *, subtitle_t *, int );
179 static int ParseDVDSubtitle( demux_t *, subtitle_t *, int );
180 static int ParseMPL2 ( demux_t *, subtitle_t *, int );
181 static int ParseAQT ( demux_t *, subtitle_t *, int );
182 static int ParsePJS ( demux_t *, subtitle_t *, int );
183 static int ParseMPSub ( demux_t *, subtitle_t *, int );
184 static int ParseJSS ( demux_t *, subtitle_t *, int );
185 static int ParsePSB ( demux_t *, subtitle_t *, int );
186 static int ParseRealText ( demux_t *, subtitle_t *, int );
187 static int ParseDKS ( demux_t *, subtitle_t *, int );
188 static int ParseSubViewer1 ( demux_t *, subtitle_t *, int );
192 const char *psz_type_name;
194 const char *psz_name;
195 int (*pf_read)( demux_t *, subtitle_t*, int );
196 } sub_read_subtitle_function [] =
198 { "microdvd", SUB_TYPE_MICRODVD, "MicroDVD", ParseMicroDvd },
199 { "subrip", SUB_TYPE_SUBRIP, "SubRIP", ParseSubRip },
200 { "subviewer", SUB_TYPE_SUBVIEWER, "SubViewer", ParseSubViewer },
201 { "ssa1", SUB_TYPE_SSA1, "SSA-1", ParseSSA },
202 { "ssa2-4", SUB_TYPE_SSA2_4, "SSA-2/3/4", ParseSSA },
203 { "ass", SUB_TYPE_ASS, "SSA/ASS", ParseSSA },
204 { "vplayer", SUB_TYPE_VPLAYER, "VPlayer", ParseVplayer },
205 { "sami", SUB_TYPE_SAMI, "SAMI", ParseSami },
206 { "dvdsubtitle",SUB_TYPE_DVDSUBTITLE, "DVDSubtitle", ParseDVDSubtitle },
207 { "mpl2", SUB_TYPE_MPL2, "MPL2", ParseMPL2 },
208 { "aqt", SUB_TYPE_AQT, "AQTitle", ParseAQT },
209 { "pjs", SUB_TYPE_PJS, "PhoenixSub", ParsePJS },
210 { "mpsub", SUB_TYPE_MPSUB, "MPSub", ParseMPSub },
211 { "jacosub", SUB_TYPE_JACOSUB, "JacoSub", ParseJSS },
212 { "psb", SUB_TYPE_PSB, "PowerDivx", ParsePSB },
213 { "realtext", SUB_TYPE_RT, "RealText", ParseRealText },
214 { "dks", SUB_TYPE_DKS, "DKS", ParseDKS },
215 { "subviewer1", SUB_TYPE_SUBVIEW1, "Subviewer 1", ParseSubViewer1 },
216 { NULL, SUB_TYPE_UNKNOWN, "Unknown", NULL }
219 static int Demux( demux_t * );
220 static int Control( demux_t *, int, va_list );
222 /*static void Fix( demux_t * );*/
224 /*****************************************************************************
226 *****************************************************************************/
227 static int Open ( vlc_object_t *p_this )
229 demux_t *p_demux = (demux_t*)p_this;
234 int (*pf_read)( demux_t *, subtitle_t*, int );
237 if( !p_demux->b_force )
239 msg_Dbg( p_demux, "subtitle demux discarded" );
243 p_demux->pf_demux = Demux;
244 p_demux->pf_control = Control;
245 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
249 p_sys->psz_header = NULL;
250 p_sys->i_subtitle = 0;
251 p_sys->i_subtitles = 0;
252 p_sys->subtitle = NULL;
253 p_sys->i_microsecperframe = 40000;
255 p_sys->jss.b_inited = false;
256 p_sys->mpsub.b_inited = false;
259 f_fps = var_CreateGetFloat( p_demux, "sub-original-fps" ); /* FIXME */
261 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
263 msg_Dbg( p_demux, "Movie fps: %f", f_fps );
265 /* Check for override of the fps */
266 f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
269 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
270 msg_Dbg( p_demux, "Override subtitle fps %f", f_fps );
273 /* Get or probe the type */
274 p_sys->i_type = SUB_TYPE_UNKNOWN;
275 psz_type = var_CreateGetString( p_demux, "sub-type" );
276 if( psz_type && *psz_type )
282 if( sub_read_subtitle_function[i].psz_type_name == NULL )
285 if( !strcmp( sub_read_subtitle_function[i].psz_type_name,
288 p_sys->i_type = sub_read_subtitle_function[i].i_type;
295 /* Probe if unknown type */
296 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
301 msg_Dbg( p_demux, "autodetecting subtitle format" );
302 for( i_try = 0; i_try < 256; i_try++ )
307 if( ( s = stream_ReadLine( p_demux->s ) ) == NULL )
310 if( strcasestr( s, "<SAMI>" ) )
312 p_sys->i_type = SUB_TYPE_SAMI;
315 else if( sscanf( s, "{%d}{%d}", &i_dummy, &i_dummy ) == 2 ||
316 sscanf( s, "{%d}{}", &i_dummy ) == 1)
318 p_sys->i_type = SUB_TYPE_MICRODVD;
322 "%d:%d:%d,%d --> %d:%d:%d,%d",
323 &i_dummy,&i_dummy,&i_dummy,&i_dummy,
324 &i_dummy,&i_dummy,&i_dummy,&i_dummy ) == 8 )
326 p_sys->i_type = SUB_TYPE_SUBRIP;
329 else if( !strncasecmp( s, "!: This is a Sub Station Alpha v1", 33 ) )
331 p_sys->i_type = SUB_TYPE_SSA1;
334 else if( !strncasecmp( s, "ScriptType: v4.00+", 18 ) )
336 p_sys->i_type = SUB_TYPE_ASS;
339 else if( !strncasecmp( s, "ScriptType: v4.00", 17 ) )
341 p_sys->i_type = SUB_TYPE_SSA2_4;
344 else if( !strncasecmp( s, "Dialogue: Marked", 16 ) )
346 p_sys->i_type = SUB_TYPE_SSA2_4;
349 else if( !strncasecmp( s, "Dialogue:", 9 ) )
351 p_sys->i_type = SUB_TYPE_ASS;
354 else if( strcasestr( s, "[INFORMATION]" ) )
356 p_sys->i_type = SUB_TYPE_SUBVIEWER; /* I hope this will work */
359 else if( sscanf( s, "%d:%d:%d.%d %d:%d:%d",
360 &i_dummy, &i_dummy, &i_dummy, &i_dummy,
361 &i_dummy, &i_dummy, &i_dummy ) == 7 ||
362 sscanf( s, "@%d @%d", &i_dummy, &i_dummy) == 2)
364 p_sys->i_type = SUB_TYPE_JACOSUB;
367 else if( sscanf( s, "%d:%d:%d:", &i_dummy, &i_dummy, &i_dummy ) == 3 ||
368 sscanf( s, "%d:%d:%d ", &i_dummy, &i_dummy, &i_dummy ) == 3 )
370 p_sys->i_type = SUB_TYPE_VPLAYER;
373 else if( sscanf( s, "{T %d:%d:%d:%d", &i_dummy, &i_dummy,
374 &i_dummy, &i_dummy ) == 4 )
376 p_sys->i_type = SUB_TYPE_DVDSUBTITLE;
379 else if( sscanf( s, "[%d:%d:%d]%c",
380 &i_dummy, &i_dummy, &i_dummy, &p_dummy ) == 4 )
382 p_sys->i_type = SUB_TYPE_DKS;
385 else if( strstr( s, "*** START SCRIPT" ) )
387 p_sys->i_type = SUB_TYPE_SUBVIEW1;
390 else if( sscanf( s, "[%d][%d]", &i_dummy, &i_dummy ) == 2 ||
391 sscanf( s, "[%d][]", &i_dummy ) == 1)
393 p_sys->i_type = SUB_TYPE_MPL2;
396 else if( sscanf (s, "FORMAT=%d", &i_dummy) == 1 ||
397 ( sscanf (s, "FORMAT=TIM%c", &p_dummy) == 1
400 p_sys->i_type = SUB_TYPE_MPSUB;
403 else if( sscanf( s, "-->> %d", &i_dummy) == 1 )
405 p_sys->i_type = SUB_TYPE_AQT;
408 else if( sscanf( s, "%d,%d,", &i_dummy, &i_dummy ) == 2 )
410 p_sys->i_type = SUB_TYPE_PJS;
413 else if( sscanf( s, "{%d:%d:%d}",
414 &i_dummy, &i_dummy, &i_dummy ) == 3 )
416 p_sys->i_type = SUB_TYPE_PSB;
419 else if( strcasestr( s, "<time" ) )
421 p_sys->i_type = SUB_TYPE_RT;
431 /* It will nearly always work even for non seekable stream thanks the
432 * caching system, and if it fails we lose just a few sub */
433 if( stream_Seek( p_demux->s, 0 ) )
435 msg_Warn( p_demux, "failed to rewind" );
439 /* Quit on unknown subtitles */
440 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
442 msg_Err( p_demux, "failed to recognize subtitle type" );
449 if( sub_read_subtitle_function[i].i_type == p_sys->i_type )
451 msg_Dbg( p_demux, "detected %s format",
452 sub_read_subtitle_function[i].psz_name );
453 pf_read = sub_read_subtitle_function[i].pf_read;
458 msg_Dbg( p_demux, "loading all subtitles..." );
460 /* Load the whole file */
461 TextLoad( &p_sys->txt, p_demux->s );
466 if( p_sys->i_subtitles >= i_max )
469 if( !( p_sys->subtitle = realloc( p_sys->subtitle,
470 sizeof(subtitle_t) * i_max ) ) )
472 free( p_sys->subtitle );
473 TextUnload( &p_sys->txt );
479 if( pf_read( p_demux, &p_sys->subtitle[p_sys->i_subtitles],
480 p_sys->i_subtitles ) )
483 p_sys->i_subtitles++;
486 TextUnload( &p_sys->txt );
488 msg_Dbg(p_demux, "loaded %d subtitles", p_sys->i_subtitles );
490 /* Fix subtitle (order and time) *** */
491 p_sys->i_subtitle = 0;
493 if( p_sys->i_subtitles > 0 )
495 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_stop;
497 if( p_sys->i_length <= 0 )
498 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_start+1;
501 /* *** add subtitle ES *** */
502 if( p_sys->i_type == SUB_TYPE_SSA1 ||
503 p_sys->i_type == SUB_TYPE_SSA2_4 ||
504 p_sys->i_type == SUB_TYPE_ASS )
506 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','s','a',' ' ) );
510 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','u','b','t' ) );
512 if( p_sys->psz_header != NULL )
514 fmt.i_extra = strlen( p_sys->psz_header ) + 1;
515 fmt.p_extra = strdup( p_sys->psz_header );
517 p_sys->es = es_out_Add( p_demux->out, &fmt );
522 /*****************************************************************************
523 * Close: Close subtitle demux
524 *****************************************************************************/
525 static void Close( vlc_object_t *p_this )
527 demux_t *p_demux = (demux_t*)p_this;
528 demux_sys_t *p_sys = p_demux->p_sys;
531 for( i = 0; i < p_sys->i_subtitles; i++ )
532 free( p_sys->subtitle[i].psz_text );
533 free( p_sys->subtitle );
538 /*****************************************************************************
540 *****************************************************************************/
541 static int Control( demux_t *p_demux, int i_query, va_list args )
543 demux_sys_t *p_sys = p_demux->p_sys;
549 case DEMUX_GET_LENGTH:
550 pi64 = (int64_t*)va_arg( args, int64_t * );
551 *pi64 = p_sys->i_length;
555 pi64 = (int64_t*)va_arg( args, int64_t * );
556 if( p_sys->i_subtitle < p_sys->i_subtitles )
558 *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;
564 i64 = (int64_t)va_arg( args, int64_t );
565 p_sys->i_subtitle = 0;
566 while( p_sys->i_subtitle < p_sys->i_subtitles &&
567 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
572 if( p_sys->i_subtitle >= p_sys->i_subtitles )
576 case DEMUX_GET_POSITION:
577 pf = (double*)va_arg( args, double * );
578 if( p_sys->i_subtitle >= p_sys->i_subtitles )
582 else if( p_sys->i_subtitles > 0 )
584 *pf = (double)p_sys->subtitle[p_sys->i_subtitle].i_start /
585 (double)p_sys->i_length;
593 case DEMUX_SET_POSITION:
594 f = (double)va_arg( args, double );
595 i64 = f * p_sys->i_length;
597 p_sys->i_subtitle = 0;
598 while( p_sys->i_subtitle < p_sys->i_subtitles &&
599 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
603 if( p_sys->i_subtitle >= p_sys->i_subtitles )
607 case DEMUX_SET_NEXT_DEMUX_TIME:
608 p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t );
613 case DEMUX_GET_ATTACHMENTS:
614 case DEMUX_GET_TITLE_INFO:
615 case DEMUX_HAS_UNSUPPORTED_META:
619 msg_Err( p_demux, "unknown query %d in subtitle control", i_query );
624 /*****************************************************************************
625 * Demux: Send subtitle to decoder
626 *****************************************************************************/
627 static int Demux( demux_t *p_demux )
629 demux_sys_t *p_sys = p_demux->p_sys;
632 if( p_sys->i_subtitle >= p_sys->i_subtitles )
635 i_maxdate = p_sys->i_next_demux_date - var_GetTime( p_demux->p_parent, "spu-delay" );;
636 if( i_maxdate <= 0 && p_sys->i_subtitle < p_sys->i_subtitles )
638 /* Should not happen */
639 i_maxdate = p_sys->subtitle[p_sys->i_subtitle].i_start + 1;
642 while( p_sys->i_subtitle < p_sys->i_subtitles &&
643 p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
646 int i_len = strlen( p_sys->subtitle[p_sys->i_subtitle].psz_text ) + 1;
655 if( ( p_block = block_New( p_demux, i_len ) ) == NULL )
661 if( p_sys->subtitle[p_sys->i_subtitle].i_start < 0 )
667 p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
668 p_block->i_dts = p_block->i_pts;
669 if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )
672 p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;
675 memcpy( p_block->p_buffer,
676 p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );
677 if( p_block->i_pts > 0 )
679 es_out_Send( p_demux->out, p_sys->es, p_block );
683 block_Release( p_block );
689 p_sys->i_next_demux_date = 0;
694 /*****************************************************************************
695 * Fix: fix time stamp and order of subtitle
696 *****************************************************************************/
697 #ifdef USE_THIS_UNUSED_PIECE_OF_CODE
698 static void Fix( demux_t *p_demux )
700 demux_sys_t *p_sys = p_demux->p_sys;
704 /* *** fix order (to be sure...) *** */
705 /* We suppose that there are near in order and this durty bubble sort
706 * wont take too much time
711 for( i_index = 1; i_index < p_sys->i_subtitles; i_index++ )
713 if( p_sys->subtitle[i_index].i_start <
714 p_sys->subtitle[i_index - 1].i_start )
718 p_sys->subtitle + i_index - 1,
719 sizeof( subtitle_t ) );
720 memcpy( p_sys->subtitle + i_index - 1,
721 p_sys->subtitle + i_index,
722 sizeof( subtitle_t ) );
723 memcpy( p_sys->subtitle + i_index,
725 sizeof( subtitle_t ) );
733 static int TextLoad( text_t *txt, stream_t *s )
739 txt->i_line_count = 0;
741 txt->line = calloc( i_line_max, sizeof( char * ) );
743 /* load the complete file */
746 char *psz = stream_ReadLine( s );
751 txt->line[txt->i_line_count++] = psz;
752 if( txt->i_line_count >= i_line_max )
755 txt->line = realloc( txt->line, i_line_max * sizeof( char * ) );
759 if( txt->i_line_count <= 0 )
767 static void TextUnload( text_t *txt )
771 for( i = 0; i < txt->i_line_count; i++ )
773 free( txt->line[i] );
777 txt->i_line_count = 0;
780 static char *TextGetLine( text_t *txt )
782 if( txt->i_line >= txt->i_line_count )
785 return txt->line[txt->i_line++];
787 static void TextPreviousLine( text_t *txt )
789 if( txt->i_line > 0 )
793 /*****************************************************************************
794 * Specific Subtitle function
795 *****************************************************************************/
798 * {n1}{n2}Line1|Line2|Line3....
799 * where n1 and n2 are the video frame number (n2 can be empty)
801 static int ParseMicroDvd( demux_t *p_demux, subtitle_t *p_subtitle,
805 demux_sys_t *p_sys = p_demux->p_sys;
806 text_t *txt = &p_sys->txt;
814 const char *s = TextGetLine( txt );
818 psz_text = malloc( strlen(s) + 1 );
824 if( sscanf( s, "{%d}{}%[^\r\n]", &i_start, psz_text ) == 2 ||
825 sscanf( s, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
828 if( i_start != 1 || i_stop != 1 )
831 /* We found a possible setting of the framerate "{1}{1}23.976" */
832 /* Check if it's usable, and if the sub-fps is not set */
833 f_fps = us_strtod( psz_text, NULL );
834 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
835 p_sys->i_microsecperframe = (int64_t)((float)1000000 / f_fps);
840 /* replace | by \n */
841 for( i = 0; psz_text[i] != '\0'; i++ )
843 if( psz_text[i] == '|' )
848 p_subtitle->i_start = i_start * p_sys->i_microsecperframe;
849 p_subtitle->i_stop = i_stop * p_sys->i_microsecperframe;
850 p_subtitle->psz_text = psz_text;
854 /* ParseSubRipSubViewer
857 * h1:m1:s1,d1 --> h2:m2:s2,d2
862 * Format SubViewer v1/v2
863 * h1:m1:s1.d1,h2:m2:s2.d2
868 * We ignore line number for SubRip
870 static int ParseSubRipSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
874 demux_sys_t *p_sys = p_demux->p_sys;
875 text_t *txt = &p_sys->txt;
880 const char *s = TextGetLine( txt );
881 int h1, m1, s1, d1, h2, m2, s2, d2;
886 if( sscanf( s, psz_fmt,
888 &h2, &m2, &s2, &d2 ) == 8 )
890 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
891 (int64_t)m1 * 60*1000 +
893 (int64_t)d1 ) * 1000;
895 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
896 (int64_t)m2 * 60*1000 +
898 (int64_t)d2 ) * 1000;
903 /* Now read text until an empty line */
904 psz_text = strdup("");
909 const char *s = TextGetLine( txt );
922 p_subtitle->psz_text = psz_text;
926 i_old = strlen( psz_text );
927 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
930 strcat( psz_text, s );
931 strcat( psz_text, "\n" );
933 /* replace [br] by \n */
938 while( ( p = strstr( psz_text, "[br]" ) ) )
941 memmove( p, &p[3], strlen(&p[3])+1 );
948 static int ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle,
952 return ParseSubRipSubViewer( p_demux, p_subtitle,
953 "%d:%d:%d,%d --> %d:%d:%d,%d",
958 static int ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
963 return ParseSubRipSubViewer( p_demux, p_subtitle,
964 "%d:%d:%d.%d,%d:%d:%d.%d",
970 static int ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle,
973 demux_sys_t *p_sys = p_demux->p_sys;
974 text_t *txt = &p_sys->txt;
978 const char *s = TextGetLine( txt );
979 int h1, m1, s1, c1, h2, m2, s2, c2;
986 /* We expect (SSA2-4):
987 * Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
988 * Dialogue: Marked=0,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
990 * 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.
994 * Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
995 * Dialogue: Layer#,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
998 /* The output text is - at least, not removing numbers - 18 chars shorter than the input text. */
999 psz_text = malloc( strlen(s) );
1004 "Dialogue: %15[^,],%d:%d:%d.%d,%d:%d:%d.%d,%[^\r\n]",
1010 /* The dec expects: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */
1011 /* (Layer comes from ASS specs ... it's empty for SSA.) */
1012 if( p_sys->i_type == SUB_TYPE_SSA1 )
1014 /* SSA1 has only 8 commas before the text starts, not 9 */
1015 memmove( &psz_text[1], psz_text, strlen(psz_text)+1 );
1020 int i_layer = ( p_sys->i_type == SUB_TYPE_ASS ) ? atoi( temp ) : 0;
1022 /* ReadOrder, Layer, %s(rest of fields) */
1023 snprintf( temp, sizeof(temp), "%d,%d,", i_idx, i_layer );
1024 memmove( psz_text + strlen(temp), psz_text, strlen(psz_text)+1 );
1025 memcpy( psz_text, temp, strlen(temp) );
1028 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1029 (int64_t)m1 * 60*1000 +
1030 (int64_t)s1 * 1000 +
1031 (int64_t)c1 * 10 ) * 1000;
1032 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1033 (int64_t)m2 * 60*1000 +
1034 (int64_t)s2 * 1000 +
1035 (int64_t)c2 * 10 ) * 1000;
1036 p_subtitle->psz_text = psz_text;
1041 /* All the other stuff we add to the header field */
1042 if( !p_sys->psz_header )
1043 p_sys->psz_header = strdup( "" );
1044 if( !p_sys->psz_header )
1048 realloc( p_sys->psz_header,
1049 strlen( p_sys->psz_header ) + strlen( s ) + 2 );
1050 strcat( p_sys->psz_header, s );
1051 strcat( p_sys->psz_header, "\n" );
1057 * h:m:s:Line1|Line2|Line3....
1059 * h:m:s Line1|Line2|Line3....
1061 static int ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle,
1064 VLC_UNUSED( i_idx );
1066 demux_sys_t *p_sys = p_demux->p_sys;
1067 text_t *txt = &p_sys->txt;
1073 const char *s = TextGetLine( txt );
1077 return VLC_EGENERIC;
1079 psz_text = malloc( strlen( s ) + 1 );
1083 if( sscanf( s, "%d:%d:%d%*c%[^\r\n]",
1084 &h1, &m1, &s1, psz_text ) == 4 )
1086 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1087 (int64_t)m1 * 60*1000 +
1088 (int64_t)s1 * 1000 ) * 1000;
1089 p_subtitle->i_stop = 0;
1095 /* replace | by \n */
1096 for( i = 0; psz_text[i] != '\0'; i++ )
1098 if( psz_text[i] == '|' )
1101 p_subtitle->psz_text = psz_text;
1107 static char *ParseSamiSearch( text_t *txt,
1108 char *psz_start, const char *psz_str )
1110 if( psz_start && strcasestr( psz_start, psz_str ) )
1112 char *s = strcasestr( psz_start, psz_str );
1113 return &s[strlen( psz_str )];
1118 char *p = TextGetLine( txt );
1122 if( strcasestr( p, psz_str ) )
1124 char *s = strcasestr( p, psz_str );
1125 return &s[strlen( psz_str )];
1129 static int ParseSami( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1131 VLC_UNUSED( i_idx );
1132 demux_sys_t *p_sys = p_demux->p_sys;
1133 text_t *txt = &p_sys->txt;
1138 unsigned int i_text;
1139 char text[8192]; /* Arbitrary but should be long enough */
1141 /* search "Start=" */
1142 if( !( s = ParseSamiSearch( txt, NULL, "Start=" ) ) )
1143 return VLC_EGENERIC;
1145 /* get start value */
1146 i_start = strtol( s, &s, 0 );
1149 if( !( s = ParseSamiSearch( txt, s, "<P" ) ) )
1150 return VLC_EGENERIC;
1153 if( !( s = ParseSamiSearch( txt, s, ">" ) ) )
1154 return VLC_EGENERIC;
1158 /* now get all txt until a "Start=" line */
1162 /* Search non empty line */
1163 while( s && *s == '\0' )
1164 s = TextGetLine( txt );
1170 if( !strncasecmp( s, "<br", 3 ) )
1174 else if( strcasestr( s, "Start=" ) )
1176 TextPreviousLine( txt );
1179 s = ParseSamiSearch( txt, s, ">" );
1181 else if( !strncmp( s, " ", 6 ) )
1186 else if( *s == '\t' )
1196 if( c != '\0' && i_text+1 < sizeof(text) )
1199 text[i_text] = '\0';
1203 p_subtitle->i_start = i_start * 1000;
1204 p_subtitle->i_stop = 0;
1205 p_subtitle->psz_text = strdup( text );
1217 * TODO it can have a header
1224 * LANG support would be cool
1225 * CODEPAGE is probably mandatory FIXME
1227 static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle,
1230 VLC_UNUSED( i_idx );
1232 demux_sys_t *p_sys = p_demux->p_sys;
1233 text_t *txt = &p_sys->txt;
1238 const char *s = TextGetLine( txt );
1242 return VLC_EGENERIC;
1246 &h1, &m1, &s1, &c1 ) == 4 )
1248 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1249 (int64_t)m1 * 60*1000 +
1250 (int64_t)s1 * 1000 +
1251 (int64_t)c1 * 10) * 1000;
1252 p_subtitle->i_stop = 0;
1257 /* Now read text until a line containing "}" */
1258 psz_text = strdup("");
1263 const char *s = TextGetLine( txt );
1270 return VLC_EGENERIC;
1273 i_len = strlen( s );
1274 if( i_len == 1 && s[0] == '}')
1276 p_subtitle->psz_text = psz_text;
1280 i_old = strlen( psz_text );
1281 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1284 strcat( psz_text, s );
1285 strcat( psz_text, "\n" );
1291 * [n1][n2]Line1|Line2|Line3...
1292 * where n1 and n2 are the video frame number (n2 can be empty)
1294 static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1296 VLC_UNUSED( i_idx );
1298 demux_sys_t *p_sys = p_demux->p_sys;
1299 text_t *txt = &p_sys->txt;
1305 const char *s = TextGetLine( txt );
1310 return VLC_EGENERIC;
1312 psz_text = malloc( strlen(s) + 1 );
1318 if( sscanf( s, "[%d][] %[^\r\n]", &i_start, psz_text ) == 2 ||
1319 sscanf( s, "[%d][%d] %[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
1321 p_subtitle->i_start = (int64_t)i_start * 100000;
1322 p_subtitle->i_stop = (int64_t)i_stop * 100000;
1328 for( i = 0; psz_text[i] != '\0'; )
1330 /* replace | by \n */
1331 if( psz_text[i] == '|' )
1335 if( psz_text[i] == '/' && ( i == 0 || psz_text[i-1] == '\n' ) )
1336 memmove( &psz_text[i], &psz_text[i+1], strlen(&psz_text[i+1])+1 );
1340 p_subtitle->psz_text = psz_text;
1344 static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1346 VLC_UNUSED( i_idx );
1348 demux_sys_t *p_sys = p_demux->p_sys;
1349 text_t *txt = &p_sys->txt;
1350 char *psz_text = strdup( "" );
1352 int i_firstline = 1;
1358 const char *s = TextGetLine( txt );
1361 return VLC_EGENERIC;
1364 if( sscanf (s, "-->> %d", &t) == 1)
1366 p_subtitle->i_start = (int64_t)t; /* * FPS*/
1367 p_subtitle->i_stop = 0;
1369 /* Starting of a subtitle */
1374 /* We have been too far: end of the subtitle, begin of next */
1377 TextPreviousLine( txt );
1384 i_old = strlen( psz_text ) + 1;
1385 psz_text = realloc( psz_text, i_old + strlen( s ) + 1 );
1388 strcat( psz_text, s );
1389 strcat( psz_text, "\n" );
1390 if( txt->i_line == txt->i_line_count )
1394 p_subtitle->psz_text = psz_text;
1398 static int ParsePJS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1400 VLC_UNUSED( i_idx );
1402 demux_sys_t *p_sys = p_demux->p_sys;
1403 text_t *txt = &p_sys->txt;
1409 const char *s = TextGetLine( txt );
1413 return VLC_EGENERIC;
1415 psz_text = malloc( strlen(s) + 1 );
1420 if( sscanf (s, "%d,%d,\"%[^\n\r]", &t1, &t2, psz_text ) == 3 )
1422 /* 1/10th of second ? Frame based ? FIXME */
1423 p_subtitle->i_start = 10 * t1;
1424 p_subtitle->i_stop = 10 * t2;
1425 /* Remove latest " */
1426 psz_text[ strlen(psz_text) - 1 ] = '\0';
1433 /* replace | by \n */
1434 for( i = 0; psz_text[i] != '\0'; i++ )
1436 if( psz_text[i] == '|' )
1440 p_subtitle->psz_text = psz_text;
1441 msg_Dbg( p_demux, "%s", psz_text );
1445 static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1447 VLC_UNUSED( i_idx );
1449 demux_sys_t *p_sys = p_demux->p_sys;
1450 text_t *txt = &p_sys->txt;
1451 char *psz_text = strdup( "" );
1453 if( !p_sys->mpsub.b_inited )
1455 p_sys->mpsub.f_total = 0.0;
1456 p_sys->mpsub.f_factor = 0.0;
1458 p_sys->mpsub.b_inited = true;
1467 const char *s = TextGetLine( txt );
1469 return VLC_EGENERIC;
1471 if( strstr( s, "FORMAT" ) )
1473 if( sscanf (s, "FORMAT=TIM%c", &p_dummy ) == 1 && p_dummy == 'E')
1475 p_sys->mpsub.f_factor = 100.0;
1479 psz_temp = malloc( strlen(s) );
1483 if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
1486 f_fps = us_strtod( psz_temp, NULL );
1487 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
1488 var_SetFloat( p_demux, "sub-fps", f_fps );
1490 p_sys->mpsub.f_factor = 1.0;
1497 f1 = us_strtod( s, &psz_temp );
1500 f2 = us_strtod( psz_temp, NULL );
1501 p_sys->mpsub.f_total += f1 * p_sys->mpsub.f_factor;
1502 p_subtitle->i_start = (int64_t)(10000.0 * p_sys->mpsub.f_total);
1503 p_sys->mpsub.f_total += f2 * p_sys->mpsub.f_factor;
1504 p_subtitle->i_stop = (int64_t)(10000.0 * p_sys->mpsub.f_total);
1511 const char *s = TextGetLine( txt );
1514 return VLC_EGENERIC;
1516 int i_len = strlen( s );
1520 int i_old = strlen( psz_text );
1522 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1526 strcat( psz_text, s );
1527 strcat( psz_text, "\n" );
1530 p_subtitle->psz_text = psz_text;
1534 static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1536 VLC_UNUSED( i_idx );
1538 demux_sys_t *p_sys = p_demux->p_sys;
1539 text_t *txt = &p_sys->txt;
1540 char *psz_text, *psz_orig;
1541 char *psz_text2, *psz_orig2;
1542 int h1, h2, m1, m2, s1, s2, f1, f2;
1544 if( !p_sys->jss.b_inited )
1546 p_sys->jss.i_comment = 0;
1547 p_sys->jss.i_time_resolution = 30;
1548 p_sys->jss.i_time_shift = 0;
1550 p_sys->jss.b_inited = true;
1553 /* Parse the main lines */
1556 const char *s = TextGetLine( txt );
1558 return VLC_EGENERIC;
1560 psz_orig = malloc( strlen( s ) + 1 );
1563 psz_text = psz_orig;
1565 /* Complete time lines */
1566 if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]",
1567 &h1, &m1, &s1, &f1, &h2, &m2, &s2, &f2, psz_text ) == 9 )
1569 p_subtitle->i_start = ( (int64_t)( h1 *3600 + m1 * 60 + s1 ) +
1570 (int64_t)( ( f1 + p_sys->jss.i_time_shift ) / p_sys->jss.i_time_resolution ) )
1572 p_subtitle->i_stop = ( (int64_t)( h2 *3600 + m2 * 60 + s2 ) +
1573 (int64_t)( ( f2 + p_sys->jss.i_time_shift ) / p_sys->jss.i_time_resolution ) )
1577 /* Short time lines */
1578 else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 )
1580 p_subtitle->i_start = (int64_t)(
1581 ( f1 + p_sys->jss.i_time_shift ) / p_sys->jss.i_time_resolution * 1000000.0 );
1582 p_subtitle->i_stop = (int64_t)(
1583 ( f2 + p_sys->jss.i_time_shift ) / p_sys->jss.i_time_resolution * 1000000.0 );
1586 /* General Directive lines */
1587 /* Only TIME and SHIFT are supported so far */
1588 else if( s[0] == '#' )
1590 int h = 0, m =0, sec = 1, f = 1;
1594 strcpy( psz_text, s );
1596 switch( toupper( psz_text[1] ) )
1599 shift = isalpha( psz_text[2] ) ? 6 : 2 ;
1601 if( sscanf( &psz_text[shift], "%d", &h ) )
1603 /* Negative shifting */
1610 if( sscanf( &psz_text[shift], "%*d:%d", &m ) )
1612 if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) )
1614 sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f );
1619 sscanf( &psz_text[shift], "%d:%d.%d",
1627 sscanf( &psz_text[shift], "%d.%d", &sec, &f);
1630 p_sys->jss.i_time_shift = ( ( h * 3600 + m * 60 + sec )
1631 * p_sys->jss.i_time_resolution + f ) * inv;
1636 shift = isalpha( psz_text[2] ) ? 8 : 2 ;
1638 sscanf( &psz_text[shift], "%d", &p_sys->jss.i_time_resolution );
1645 /* Unkown type line, probably a comment */
1652 while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
1654 const char *s2 = TextGetLine( txt );
1657 return VLC_EGENERIC;
1659 int i_len = strlen( s2 );
1663 int i_old = strlen( psz_text );
1665 psz_text = realloc( psz_text, i_old + i_len + 1 );
1669 psz_orig = psz_text;
1670 strcat( psz_text, s2 );
1673 /* Skip the blanks */
1674 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1676 /* Parse the directives */
1677 if( isalpha( *psz_text ) || *psz_text == '[' )
1679 while( *psz_text != ' ' )
1682 /* Directives are NOT parsed yet */
1683 /* This has probably a better place in a decoder ? */
1684 /* directive = malloc( strlen( psz_text ) + 1 );
1685 if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/
1688 /* Skip the blanks after directives */
1689 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1691 /* Clean all the lines from inline comments and other stuffs */
1692 psz_orig2 = calloc( strlen( psz_text) + 1, 1 );
1693 psz_text2 = psz_orig2;
1695 for( ; *psz_text != '\0' && *psz_text != '\n' && *psz_text != '\r'; )
1700 p_sys->jss.i_comment++;
1703 if( p_sys->jss.i_comment )
1705 p_sys->jss.i_comment = 0;
1706 if( (*(psz_text + 1 ) ) == ' ' ) psz_text++;
1710 if( !p_sys->jss.i_comment )
1718 if( (*(psz_text + 1 ) ) == ' ' || (*(psz_text + 1 ) ) == '\t' )
1720 if( !p_sys->jss.i_comment )
1727 if( (*(psz_text + 1 ) ) == 'n' )
1734 if( ( toupper(*(psz_text + 1 ) ) == 'C' ) ||
1735 ( toupper(*(psz_text + 1 ) ) == 'F' ) )
1737 psz_text++; psz_text++;
1740 if( (*(psz_text + 1 ) ) == 'B' || (*(psz_text + 1 ) ) == 'b' ||
1741 (*(psz_text + 1 ) ) == 'I' || (*(psz_text + 1 ) ) == 'i' ||
1742 (*(psz_text + 1 ) ) == 'U' || (*(psz_text + 1 ) ) == 'u' ||
1743 (*(psz_text + 1 ) ) == 'D' || (*(psz_text + 1 ) ) == 'N' )
1748 if( (*(psz_text + 1 ) ) == '~' || (*(psz_text + 1 ) ) == '{' ||
1749 (*(psz_text + 1 ) ) == '\\' )
1751 else if( *(psz_text + 1 ) == '\r' || *(psz_text + 1 ) == '\n' ||
1752 *(psz_text + 1 ) == '\0' )
1758 if( !p_sys->jss.i_comment )
1760 *psz_text2 = *psz_text;
1767 p_subtitle->psz_text = psz_orig2;
1768 msg_Dbg( p_demux, "%s", p_subtitle->psz_text );
1773 static int ParsePSB( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1775 VLC_UNUSED( i_idx );
1777 demux_sys_t *p_sys = p_demux->p_sys;
1778 text_t *txt = &p_sys->txt;
1786 const char *s = TextGetLine( txt );
1789 return VLC_EGENERIC;
1791 psz_text = malloc( strlen( s ) + 1 );
1795 if( sscanf( s, "{%d:%d:%d}{%d:%d:%d}%[^\r\n]",
1796 &h1, &m1, &s1, &h2, &m2, &s2, psz_text ) == 7 )
1798 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1799 (int64_t)m1 * 60*1000 +
1800 (int64_t)s1 * 1000 ) * 1000;
1801 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1802 (int64_t)m2 * 60*1000 +
1803 (int64_t)s2 * 1000 ) * 1000;
1809 /* replace | by \n */
1810 for( i = 0; psz_text[i] != '\0'; i++ )
1812 if( psz_text[i] == '|' )
1815 p_subtitle->psz_text = psz_text;
1819 static int64_t ParseRealTime( char *psz, int *h, int *m, int *s, int *f )
1821 if( strlen( psz ) == 0 ) return 0;
1822 if( sscanf( psz, "%d:%d:%d.%d", h, m, s, f ) == 4 ||
1823 sscanf( psz, "%d:%d.%d", m, s, f ) == 3 ||
1824 sscanf( psz, "%d.%d", s, f ) == 2 ||
1825 sscanf( psz, "%d:%d", m, s ) == 2 ||
1826 sscanf( psz, "%d", s ) == 1 )
1828 return (int64_t)((( *h * 60 + *m ) * 60 ) + *s ) * 1000 * 1000
1829 + (int64_t)*f * 10 * 1000;
1831 else return VLC_EGENERIC;
1834 static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1836 VLC_UNUSED( i_idx );
1837 demux_sys_t *p_sys = p_demux->p_sys;
1838 text_t *txt = &p_sys->txt;
1840 char psz_end[12]= "", psz_begin[12] = "";
1844 int h1 = 0, m1 = 0, s1 = 0, f1 = 0;
1845 int h2 = 0, m2 = 0, s2 = 0, f2 = 0;
1846 const char *s = TextGetLine( txt );
1849 return VLC_EGENERIC;
1851 psz_text = malloc( strlen( s ) + 1 );
1855 /* Find the good begining. This removes extra spaces at the beginning
1857 char *psz_temp = strcasestr( s, "<time");
1858 if( psz_temp != NULL )
1860 /* Line has begin and end */
1861 if( ( sscanf( psz_temp,
1862 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\" %*[e|E]nd=\"%[^\"]%*[^>]%[^\n\r]",
1863 psz_begin, psz_end, psz_text) != 3 ) &&
1864 /* Line has begin and no end */
1866 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\"%*[^>]%[^\n\r]",
1867 psz_begin, psz_text ) != 2) )
1868 /* Line is not recognized */
1875 int64_t i_time = ParseRealTime( psz_begin, &h1, &m1, &s1, &f1 );
1878 p_subtitle->i_start = i_time;
1881 i_time = ParseRealTime( psz_end, &h2, &m2, &s2, &f2 );
1884 p_subtitle->i_stop = i_time;
1888 /* Line is not recognized */
1893 /* Get the following Lines */
1896 const char *s = TextGetLine( txt );
1899 return VLC_EGENERIC;
1901 int i_len = strlen( s );
1902 if( i_len == 0 ) break;
1904 if( strcasestr( s, "<time" ) ||
1905 strcasestr( s, "<clear/") )
1907 TextPreviousLine( txt );
1911 int i_old = strlen( psz_text );
1913 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1917 strcat( psz_text, s );
1918 strcat( psz_text, "\n" );
1921 /* Remove the starting ">" that remained after the sscanf */
1922 memmove( &psz_text[0], &psz_text[1], strlen( psz_text ) );
1924 p_subtitle->psz_text = psz_text;
1929 static int ParseDKS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1931 VLC_UNUSED( i_idx );
1933 demux_sys_t *p_sys = p_demux->p_sys;
1934 text_t *txt = &p_sys->txt;
1941 char *s = TextGetLine( txt );
1944 return VLC_EGENERIC;
1946 psz_text = malloc( strlen( s ) + 1 );
1950 if( sscanf( s, "[%d:%d:%d]%[^\r\n]",
1951 &h1, &m1, &s1, psz_text ) == 4 )
1953 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1954 (int64_t)m1 * 60*1000 +
1955 (int64_t)s1 * 1000 ) * 1000;
1957 char *s = TextGetLine( txt );
1959 return VLC_EGENERIC;
1961 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1962 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1963 (int64_t)m2 * 60*1000 +
1964 (int64_t)s2 * 1000 ) * 1000;
1970 /* replace [br] by \n */
1972 while( ( p = strstr( psz_text, "[br]" ) ) )
1975 memmove( p, &p[3], strlen(&p[3])+1 );
1978 p_subtitle->psz_text = psz_text;
1982 static int ParseSubViewer1( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1984 VLC_UNUSED( i_idx );
1986 demux_sys_t *p_sys = p_demux->p_sys;
1987 text_t *txt = &p_sys->txt;
1994 char *s = TextGetLine( txt );
1997 return VLC_EGENERIC;
1999 if( sscanf( s, "[%d:%d:%d]", &h1, &m1, &s1 ) == 3 )
2001 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
2002 (int64_t)m1 * 60*1000 +
2003 (int64_t)s1 * 1000 ) * 1000;
2005 char *s = TextGetLine( txt );
2007 return VLC_EGENERIC;
2009 psz_text = strdup( s );
2013 s = TextGetLine( txt );
2015 return VLC_EGENERIC;
2017 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
2018 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
2019 (int64_t)m2 * 60*1000 +
2020 (int64_t)s2 * 1000 ) * 1000;
2025 p_subtitle->psz_text = psz_text;