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 }
218 /* When adding support for more formats, be sure to add their file extension
219 * to src/input/subtitles.c to enable auto-detection.
222 static int Demux( demux_t * );
223 static int Control( demux_t *, int, va_list );
225 /*static void Fix( demux_t * );*/
227 /*****************************************************************************
229 *****************************************************************************/
230 static int Open ( vlc_object_t *p_this )
232 demux_t *p_demux = (demux_t*)p_this;
237 int (*pf_read)( demux_t *, subtitle_t*, int );
240 if( !p_demux->b_force )
242 msg_Dbg( p_demux, "subtitle demux discarded" );
246 p_demux->pf_demux = Demux;
247 p_demux->pf_control = Control;
248 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
252 p_sys->psz_header = NULL;
253 p_sys->i_subtitle = 0;
254 p_sys->i_subtitles = 0;
255 p_sys->subtitle = NULL;
256 p_sys->i_microsecperframe = 40000;
258 p_sys->jss.b_inited = false;
259 p_sys->mpsub.b_inited = false;
262 f_fps = var_CreateGetFloat( p_demux, "sub-original-fps" ); /* FIXME */
264 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
266 msg_Dbg( p_demux, "Movie fps: %f", f_fps );
268 /* Check for override of the fps */
269 f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
272 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
273 msg_Dbg( p_demux, "Override subtitle fps %f", f_fps );
276 /* Get or probe the type */
277 p_sys->i_type = SUB_TYPE_UNKNOWN;
278 psz_type = var_CreateGetString( p_demux, "sub-type" );
279 if( psz_type && *psz_type )
285 if( sub_read_subtitle_function[i].psz_type_name == NULL )
288 if( !strcmp( sub_read_subtitle_function[i].psz_type_name,
291 p_sys->i_type = sub_read_subtitle_function[i].i_type;
298 /* Probe if unknown type */
299 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
304 msg_Dbg( p_demux, "autodetecting subtitle format" );
305 for( i_try = 0; i_try < 256; i_try++ )
310 if( ( s = stream_ReadLine( p_demux->s ) ) == NULL )
313 if( strcasestr( s, "<SAMI>" ) )
315 p_sys->i_type = SUB_TYPE_SAMI;
318 else if( sscanf( s, "{%d}{%d}", &i_dummy, &i_dummy ) == 2 ||
319 sscanf( s, "{%d}{}", &i_dummy ) == 1)
321 p_sys->i_type = SUB_TYPE_MICRODVD;
325 "%d:%d:%d,%d --> %d:%d:%d,%d",
326 &i_dummy,&i_dummy,&i_dummy,&i_dummy,
327 &i_dummy,&i_dummy,&i_dummy,&i_dummy ) == 8 )
329 p_sys->i_type = SUB_TYPE_SUBRIP;
332 else if( !strncasecmp( s, "!: This is a Sub Station Alpha v1", 33 ) )
334 p_sys->i_type = SUB_TYPE_SSA1;
337 else if( !strncasecmp( s, "ScriptType: v4.00+", 18 ) )
339 p_sys->i_type = SUB_TYPE_ASS;
342 else if( !strncasecmp( s, "ScriptType: v4.00", 17 ) )
344 p_sys->i_type = SUB_TYPE_SSA2_4;
347 else if( !strncasecmp( s, "Dialogue: Marked", 16 ) )
349 p_sys->i_type = SUB_TYPE_SSA2_4;
352 else if( !strncasecmp( s, "Dialogue:", 9 ) )
354 p_sys->i_type = SUB_TYPE_ASS;
357 else if( strcasestr( s, "[INFORMATION]" ) )
359 p_sys->i_type = SUB_TYPE_SUBVIEWER; /* I hope this will work */
362 else if( sscanf( s, "%d:%d:%d.%d %d:%d:%d",
363 &i_dummy, &i_dummy, &i_dummy, &i_dummy,
364 &i_dummy, &i_dummy, &i_dummy ) == 7 ||
365 sscanf( s, "@%d @%d", &i_dummy, &i_dummy) == 2)
367 p_sys->i_type = SUB_TYPE_JACOSUB;
370 else if( sscanf( s, "%d:%d:%d:", &i_dummy, &i_dummy, &i_dummy ) == 3 ||
371 sscanf( s, "%d:%d:%d ", &i_dummy, &i_dummy, &i_dummy ) == 3 )
373 p_sys->i_type = SUB_TYPE_VPLAYER;
376 else if( sscanf( s, "{T %d:%d:%d:%d", &i_dummy, &i_dummy,
377 &i_dummy, &i_dummy ) == 4 )
379 p_sys->i_type = SUB_TYPE_DVDSUBTITLE;
382 else if( sscanf( s, "[%d:%d:%d]%c",
383 &i_dummy, &i_dummy, &i_dummy, &p_dummy ) == 4 )
385 p_sys->i_type = SUB_TYPE_DKS;
388 else if( strstr( s, "*** START SCRIPT" ) )
390 p_sys->i_type = SUB_TYPE_SUBVIEW1;
393 else if( sscanf( s, "[%d][%d]", &i_dummy, &i_dummy ) == 2 ||
394 sscanf( s, "[%d][]", &i_dummy ) == 1)
396 p_sys->i_type = SUB_TYPE_MPL2;
399 else if( sscanf (s, "FORMAT=%d", &i_dummy) == 1 ||
400 ( sscanf (s, "FORMAT=TIM%c", &p_dummy) == 1
403 p_sys->i_type = SUB_TYPE_MPSUB;
406 else if( sscanf( s, "-->> %d", &i_dummy) == 1 )
408 p_sys->i_type = SUB_TYPE_AQT;
411 else if( sscanf( s, "%d,%d,", &i_dummy, &i_dummy ) == 2 )
413 p_sys->i_type = SUB_TYPE_PJS;
416 else if( sscanf( s, "{%d:%d:%d}",
417 &i_dummy, &i_dummy, &i_dummy ) == 3 )
419 p_sys->i_type = SUB_TYPE_PSB;
422 else if( strcasestr( s, "<time" ) )
424 p_sys->i_type = SUB_TYPE_RT;
434 /* It will nearly always work even for non seekable stream thanks the
435 * caching system, and if it fails we lose just a few sub */
436 if( stream_Seek( p_demux->s, 0 ) )
438 msg_Warn( p_demux, "failed to rewind" );
442 /* Quit on unknown subtitles */
443 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
445 msg_Err( p_demux, "failed to recognize subtitle type" );
452 if( sub_read_subtitle_function[i].i_type == p_sys->i_type )
454 msg_Dbg( p_demux, "detected %s format",
455 sub_read_subtitle_function[i].psz_name );
456 pf_read = sub_read_subtitle_function[i].pf_read;
461 msg_Dbg( p_demux, "loading all subtitles..." );
463 /* Load the whole file */
464 TextLoad( &p_sys->txt, p_demux->s );
469 if( p_sys->i_subtitles >= i_max )
472 if( !( p_sys->subtitle = realloc( p_sys->subtitle,
473 sizeof(subtitle_t) * i_max ) ) )
475 free( p_sys->subtitle );
476 TextUnload( &p_sys->txt );
482 if( pf_read( p_demux, &p_sys->subtitle[p_sys->i_subtitles],
483 p_sys->i_subtitles ) )
486 p_sys->i_subtitles++;
489 TextUnload( &p_sys->txt );
491 msg_Dbg(p_demux, "loaded %d subtitles", p_sys->i_subtitles );
493 /* Fix subtitle (order and time) *** */
494 p_sys->i_subtitle = 0;
496 if( p_sys->i_subtitles > 0 )
498 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_stop;
500 if( p_sys->i_length <= 0 )
501 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_start+1;
504 /* *** add subtitle ES *** */
505 if( p_sys->i_type == SUB_TYPE_SSA1 ||
506 p_sys->i_type == SUB_TYPE_SSA2_4 ||
507 p_sys->i_type == SUB_TYPE_ASS )
509 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','s','a',' ' ) );
513 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','u','b','t' ) );
515 if( p_sys->psz_header != NULL )
517 fmt.i_extra = strlen( p_sys->psz_header ) + 1;
518 fmt.p_extra = strdup( p_sys->psz_header );
520 p_sys->es = es_out_Add( p_demux->out, &fmt );
525 /*****************************************************************************
526 * Close: Close subtitle demux
527 *****************************************************************************/
528 static void Close( vlc_object_t *p_this )
530 demux_t *p_demux = (demux_t*)p_this;
531 demux_sys_t *p_sys = p_demux->p_sys;
534 for( i = 0; i < p_sys->i_subtitles; i++ )
535 free( p_sys->subtitle[i].psz_text );
536 free( p_sys->subtitle );
541 /*****************************************************************************
543 *****************************************************************************/
544 static int Control( demux_t *p_demux, int i_query, va_list args )
546 demux_sys_t *p_sys = p_demux->p_sys;
552 case DEMUX_GET_LENGTH:
553 pi64 = (int64_t*)va_arg( args, int64_t * );
554 *pi64 = p_sys->i_length;
558 pi64 = (int64_t*)va_arg( args, int64_t * );
559 if( p_sys->i_subtitle < p_sys->i_subtitles )
561 *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;
567 i64 = (int64_t)va_arg( args, int64_t );
568 p_sys->i_subtitle = 0;
569 while( p_sys->i_subtitle < p_sys->i_subtitles )
571 const subtitle_t *p_subtitle = &p_sys->subtitle[p_sys->i_subtitle];
573 if( p_subtitle->i_start > i64 )
575 if( p_subtitle->i_stop > p_subtitle->i_start && p_subtitle->i_stop > i64 )
581 if( p_sys->i_subtitle >= p_sys->i_subtitles )
585 case DEMUX_GET_POSITION:
586 pf = (double*)va_arg( args, double * );
587 if( p_sys->i_subtitle >= p_sys->i_subtitles )
591 else if( p_sys->i_subtitles > 0 )
593 *pf = (double)p_sys->subtitle[p_sys->i_subtitle].i_start /
594 (double)p_sys->i_length;
602 case DEMUX_SET_POSITION:
603 f = (double)va_arg( args, double );
604 i64 = f * p_sys->i_length;
606 p_sys->i_subtitle = 0;
607 while( p_sys->i_subtitle < p_sys->i_subtitles &&
608 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
612 if( p_sys->i_subtitle >= p_sys->i_subtitles )
616 case DEMUX_SET_NEXT_DEMUX_TIME:
617 p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t );
622 case DEMUX_GET_ATTACHMENTS:
623 case DEMUX_GET_TITLE_INFO:
624 case DEMUX_HAS_UNSUPPORTED_META:
625 case DEMUX_CAN_RECORD:
629 msg_Err( p_demux, "unknown query %d in subtitle control", i_query );
634 /*****************************************************************************
635 * Demux: Send subtitle to decoder
636 *****************************************************************************/
637 static int Demux( demux_t *p_demux )
639 demux_sys_t *p_sys = p_demux->p_sys;
642 if( p_sys->i_subtitle >= p_sys->i_subtitles )
645 i_maxdate = p_sys->i_next_demux_date - var_GetTime( p_demux->p_parent, "spu-delay" );;
646 if( i_maxdate <= 0 && p_sys->i_subtitle < p_sys->i_subtitles )
648 /* Should not happen */
649 i_maxdate = p_sys->subtitle[p_sys->i_subtitle].i_start + 1;
652 while( p_sys->i_subtitle < p_sys->i_subtitles &&
653 p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
655 const subtitle_t *p_subtitle = &p_sys->subtitle[p_sys->i_subtitle];
658 int i_len = strlen( p_subtitle->psz_text ) + 1;
660 if( i_len <= 1 || p_subtitle->i_start < 0 )
666 if( ( p_block = block_New( p_demux, i_len ) ) == NULL )
673 p_block->i_pts = 1 + p_subtitle->i_start;
674 if( p_subtitle->i_stop > 0 && p_subtitle->i_stop >= p_subtitle->i_start )
675 p_block->i_length = p_subtitle->i_stop - p_subtitle->i_start;
677 memcpy( p_block->p_buffer, p_subtitle->psz_text, i_len );
679 es_out_Send( p_demux->out, p_sys->es, p_block );
685 p_sys->i_next_demux_date = 0;
690 /*****************************************************************************
691 * Fix: fix time stamp and order of subtitle
692 *****************************************************************************/
693 #ifdef USE_THIS_UNUSED_PIECE_OF_CODE
694 static void Fix( demux_t *p_demux )
696 demux_sys_t *p_sys = p_demux->p_sys;
700 /* *** fix order (to be sure...) *** */
701 /* We suppose that there are near in order and this durty bubble sort
702 * wont take too much time
707 for( i_index = 1; i_index < p_sys->i_subtitles; i_index++ )
709 if( p_sys->subtitle[i_index].i_start <
710 p_sys->subtitle[i_index - 1].i_start )
714 p_sys->subtitle + i_index - 1,
715 sizeof( subtitle_t ) );
716 memcpy( p_sys->subtitle + i_index - 1,
717 p_sys->subtitle + i_index,
718 sizeof( subtitle_t ) );
719 memcpy( p_sys->subtitle + i_index,
721 sizeof( subtitle_t ) );
729 static int TextLoad( text_t *txt, stream_t *s )
735 txt->i_line_count = 0;
737 txt->line = calloc( i_line_max, sizeof( char * ) );
739 /* load the complete file */
742 char *psz = stream_ReadLine( s );
747 txt->line[txt->i_line_count++] = psz;
748 if( txt->i_line_count >= i_line_max )
751 txt->line = realloc( txt->line, i_line_max * sizeof( char * ) );
755 if( txt->i_line_count <= 0 )
763 static void TextUnload( text_t *txt )
767 for( i = 0; i < txt->i_line_count; i++ )
769 free( txt->line[i] );
773 txt->i_line_count = 0;
776 static char *TextGetLine( text_t *txt )
778 if( txt->i_line >= txt->i_line_count )
781 return txt->line[txt->i_line++];
783 static void TextPreviousLine( text_t *txt )
785 if( txt->i_line > 0 )
789 /*****************************************************************************
790 * Specific Subtitle function
791 *****************************************************************************/
794 * {n1}{n2}Line1|Line2|Line3....
795 * where n1 and n2 are the video frame number (n2 can be empty)
797 static int ParseMicroDvd( demux_t *p_demux, subtitle_t *p_subtitle,
801 demux_sys_t *p_sys = p_demux->p_sys;
802 text_t *txt = &p_sys->txt;
810 const char *s = TextGetLine( txt );
814 psz_text = malloc( strlen(s) + 1 );
820 if( sscanf( s, "{%d}{}%[^\r\n]", &i_start, psz_text ) == 2 ||
821 sscanf( s, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
824 if( i_start != 1 || i_stop != 1 )
827 /* We found a possible setting of the framerate "{1}{1}23.976" */
828 /* Check if it's usable, and if the sub-fps is not set */
829 f_fps = us_strtod( psz_text, NULL );
830 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
831 p_sys->i_microsecperframe = (int64_t)((float)1000000 / f_fps);
836 /* replace | by \n */
837 for( i = 0; psz_text[i] != '\0'; i++ )
839 if( psz_text[i] == '|' )
844 p_subtitle->i_start = i_start * p_sys->i_microsecperframe;
845 p_subtitle->i_stop = i_stop * p_sys->i_microsecperframe;
846 p_subtitle->psz_text = psz_text;
850 /* ParseSubRipSubViewer
853 * h1:m1:s1,d1 --> h2:m2:s2,d2
858 * Format SubViewer v1/v2
859 * h1:m1:s1.d1,h2:m2:s2.d2
864 * We ignore line number for SubRip
866 static int ParseSubRipSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
870 demux_sys_t *p_sys = p_demux->p_sys;
871 text_t *txt = &p_sys->txt;
876 const char *s = TextGetLine( txt );
877 int h1, m1, s1, d1, h2, m2, s2, d2;
882 if( sscanf( s, psz_fmt,
884 &h2, &m2, &s2, &d2 ) == 8 )
886 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
887 (int64_t)m1 * 60*1000 +
889 (int64_t)d1 ) * 1000;
891 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
892 (int64_t)m2 * 60*1000 +
894 (int64_t)d2 ) * 1000;
899 /* Now read text until an empty line */
900 psz_text = strdup("");
906 const char *s = TextGetLine( txt );
910 i_len = s ? strlen( s ) : 0;
913 p_subtitle->psz_text = psz_text;
917 i_old = strlen( psz_text );
918 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
923 strcat( psz_text, s );
924 strcat( psz_text, "\n" );
926 /* replace [br] by \n */
931 while( ( p = strstr( psz_text, "[br]" ) ) )
934 memmove( p, &p[3], strlen(&p[3])+1 );
941 static int ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle,
945 return ParseSubRipSubViewer( p_demux, p_subtitle,
946 "%d:%d:%d,%d --> %d:%d:%d,%d",
951 static int ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
956 return ParseSubRipSubViewer( p_demux, p_subtitle,
957 "%d:%d:%d.%d,%d:%d:%d.%d",
963 static int ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle,
966 demux_sys_t *p_sys = p_demux->p_sys;
967 text_t *txt = &p_sys->txt;
971 const char *s = TextGetLine( txt );
972 int h1, m1, s1, c1, h2, m2, s2, c2;
979 /* We expect (SSA2-4):
980 * Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
981 * Dialogue: Marked=0,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
983 * 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.
987 * Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
988 * Dialogue: Layer#,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
991 /* The output text is - at least, not removing numbers - 18 chars shorter than the input text. */
992 psz_text = malloc( strlen(s) );
997 "Dialogue: %15[^,],%d:%d:%d.%d,%d:%d:%d.%d,%[^\r\n]",
1003 /* The dec expects: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */
1004 /* (Layer comes from ASS specs ... it's empty for SSA.) */
1005 if( p_sys->i_type == SUB_TYPE_SSA1 )
1007 /* SSA1 has only 8 commas before the text starts, not 9 */
1008 memmove( &psz_text[1], psz_text, strlen(psz_text)+1 );
1013 int i_layer = ( p_sys->i_type == SUB_TYPE_ASS ) ? atoi( temp ) : 0;
1015 /* ReadOrder, Layer, %s(rest of fields) */
1016 snprintf( temp, sizeof(temp), "%d,%d,", i_idx, i_layer );
1017 memmove( psz_text + strlen(temp), psz_text, strlen(psz_text)+1 );
1018 memcpy( psz_text, temp, strlen(temp) );
1021 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1022 (int64_t)m1 * 60*1000 +
1023 (int64_t)s1 * 1000 +
1024 (int64_t)c1 * 10 ) * 1000;
1025 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1026 (int64_t)m2 * 60*1000 +
1027 (int64_t)s2 * 1000 +
1028 (int64_t)c2 * 10 ) * 1000;
1029 p_subtitle->psz_text = psz_text;
1034 /* All the other stuff we add to the header field */
1035 if( !p_sys->psz_header )
1036 p_sys->psz_header = strdup( "" );
1037 if( !p_sys->psz_header )
1041 realloc( p_sys->psz_header,
1042 strlen( p_sys->psz_header ) + strlen( s ) + 2 );
1043 strcat( p_sys->psz_header, s );
1044 strcat( p_sys->psz_header, "\n" );
1050 * h:m:s:Line1|Line2|Line3....
1052 * h:m:s Line1|Line2|Line3....
1054 static int ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle,
1057 VLC_UNUSED( i_idx );
1059 demux_sys_t *p_sys = p_demux->p_sys;
1060 text_t *txt = &p_sys->txt;
1066 const char *s = TextGetLine( txt );
1070 return VLC_EGENERIC;
1072 psz_text = malloc( strlen( s ) + 1 );
1076 if( sscanf( s, "%d:%d:%d%*c%[^\r\n]",
1077 &h1, &m1, &s1, psz_text ) == 4 )
1079 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1080 (int64_t)m1 * 60*1000 +
1081 (int64_t)s1 * 1000 ) * 1000;
1082 p_subtitle->i_stop = 0;
1088 /* replace | by \n */
1089 for( i = 0; psz_text[i] != '\0'; i++ )
1091 if( psz_text[i] == '|' )
1094 p_subtitle->psz_text = psz_text;
1100 static char *ParseSamiSearch( text_t *txt,
1101 char *psz_start, const char *psz_str )
1103 if( psz_start && strcasestr( psz_start, psz_str ) )
1105 char *s = strcasestr( psz_start, psz_str );
1106 return &s[strlen( psz_str )];
1111 char *p = TextGetLine( txt );
1115 if( strcasestr( p, psz_str ) )
1117 char *s = strcasestr( p, psz_str );
1118 return &s[strlen( psz_str )];
1122 static int ParseSami( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1124 VLC_UNUSED( i_idx );
1125 demux_sys_t *p_sys = p_demux->p_sys;
1126 text_t *txt = &p_sys->txt;
1131 unsigned int i_text;
1132 char text[8192]; /* Arbitrary but should be long enough */
1134 /* search "Start=" */
1135 if( !( s = ParseSamiSearch( txt, NULL, "Start=" ) ) )
1136 return VLC_EGENERIC;
1138 /* get start value */
1139 i_start = strtol( s, &s, 0 );
1142 if( !( s = ParseSamiSearch( txt, s, "<P" ) ) )
1143 return VLC_EGENERIC;
1146 if( !( s = ParseSamiSearch( txt, s, ">" ) ) )
1147 return VLC_EGENERIC;
1151 /* now get all txt until a "Start=" line */
1155 /* Search non empty line */
1156 while( s && *s == '\0' )
1157 s = TextGetLine( txt );
1163 if( !strncasecmp( s, "<br", 3 ) )
1167 else if( strcasestr( s, "Start=" ) )
1169 TextPreviousLine( txt );
1172 s = ParseSamiSearch( txt, s, ">" );
1174 else if( !strncmp( s, " ", 6 ) )
1179 else if( *s == '\t' )
1189 if( c != '\0' && i_text+1 < sizeof(text) )
1192 text[i_text] = '\0';
1196 p_subtitle->i_start = i_start * 1000;
1197 p_subtitle->i_stop = 0;
1198 p_subtitle->psz_text = strdup( text );
1210 * TODO it can have a header
1217 * LANG support would be cool
1218 * CODEPAGE is probably mandatory FIXME
1220 static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle,
1223 VLC_UNUSED( i_idx );
1225 demux_sys_t *p_sys = p_demux->p_sys;
1226 text_t *txt = &p_sys->txt;
1231 const char *s = TextGetLine( txt );
1235 return VLC_EGENERIC;
1239 &h1, &m1, &s1, &c1 ) == 4 )
1241 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1242 (int64_t)m1 * 60*1000 +
1243 (int64_t)s1 * 1000 +
1244 (int64_t)c1 * 10) * 1000;
1245 p_subtitle->i_stop = 0;
1250 /* Now read text until a line containing "}" */
1251 psz_text = strdup("");
1256 const char *s = TextGetLine( txt );
1263 return VLC_EGENERIC;
1266 i_len = strlen( s );
1267 if( i_len == 1 && s[0] == '}')
1269 p_subtitle->psz_text = psz_text;
1273 i_old = strlen( psz_text );
1274 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1277 strcat( psz_text, s );
1278 strcat( psz_text, "\n" );
1284 * [n1][n2]Line1|Line2|Line3...
1285 * where n1 and n2 are the video frame number (n2 can be empty)
1287 static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1289 VLC_UNUSED( i_idx );
1291 demux_sys_t *p_sys = p_demux->p_sys;
1292 text_t *txt = &p_sys->txt;
1298 const char *s = TextGetLine( txt );
1303 return VLC_EGENERIC;
1305 psz_text = malloc( strlen(s) + 1 );
1311 if( sscanf( s, "[%d][] %[^\r\n]", &i_start, psz_text ) == 2 ||
1312 sscanf( s, "[%d][%d] %[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
1314 p_subtitle->i_start = (int64_t)i_start * 100000;
1315 p_subtitle->i_stop = (int64_t)i_stop * 100000;
1321 for( i = 0; psz_text[i] != '\0'; )
1323 /* replace | by \n */
1324 if( psz_text[i] == '|' )
1328 if( psz_text[i] == '/' && ( i == 0 || psz_text[i-1] == '\n' ) )
1329 memmove( &psz_text[i], &psz_text[i+1], strlen(&psz_text[i+1])+1 );
1333 p_subtitle->psz_text = psz_text;
1337 static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1339 VLC_UNUSED( i_idx );
1341 demux_sys_t *p_sys = p_demux->p_sys;
1342 text_t *txt = &p_sys->txt;
1343 char *psz_text = strdup( "" );
1345 int i_firstline = 1;
1351 const char *s = TextGetLine( txt );
1354 return VLC_EGENERIC;
1357 if( sscanf (s, "-->> %d", &t) == 1)
1359 p_subtitle->i_start = (int64_t)t; /* * FPS*/
1360 p_subtitle->i_stop = 0;
1362 /* Starting of a subtitle */
1367 /* We have been too far: end of the subtitle, begin of next */
1370 TextPreviousLine( txt );
1377 i_old = strlen( psz_text ) + 1;
1378 psz_text = realloc( psz_text, i_old + strlen( s ) + 1 );
1381 strcat( psz_text, s );
1382 strcat( psz_text, "\n" );
1383 if( txt->i_line == txt->i_line_count )
1387 p_subtitle->psz_text = psz_text;
1391 static int ParsePJS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1393 VLC_UNUSED( i_idx );
1395 demux_sys_t *p_sys = p_demux->p_sys;
1396 text_t *txt = &p_sys->txt;
1402 const char *s = TextGetLine( txt );
1406 return VLC_EGENERIC;
1408 psz_text = malloc( strlen(s) + 1 );
1413 if( sscanf (s, "%d,%d,\"%[^\n\r]", &t1, &t2, psz_text ) == 3 )
1415 /* 1/10th of second ? Frame based ? FIXME */
1416 p_subtitle->i_start = 10 * t1;
1417 p_subtitle->i_stop = 10 * t2;
1418 /* Remove latest " */
1419 psz_text[ strlen(psz_text) - 1 ] = '\0';
1426 /* replace | by \n */
1427 for( i = 0; psz_text[i] != '\0'; i++ )
1429 if( psz_text[i] == '|' )
1433 p_subtitle->psz_text = psz_text;
1434 msg_Dbg( p_demux, "%s", psz_text );
1438 static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1440 VLC_UNUSED( i_idx );
1442 demux_sys_t *p_sys = p_demux->p_sys;
1443 text_t *txt = &p_sys->txt;
1444 char *psz_text = strdup( "" );
1446 if( !p_sys->mpsub.b_inited )
1448 p_sys->mpsub.f_total = 0.0;
1449 p_sys->mpsub.f_factor = 0.0;
1451 p_sys->mpsub.b_inited = true;
1460 const char *s = TextGetLine( txt );
1462 return VLC_EGENERIC;
1464 if( strstr( s, "FORMAT" ) )
1466 if( sscanf (s, "FORMAT=TIM%c", &p_dummy ) == 1 && p_dummy == 'E')
1468 p_sys->mpsub.f_factor = 100.0;
1472 psz_temp = malloc( strlen(s) );
1476 if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
1479 f_fps = us_strtod( psz_temp, NULL );
1480 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
1481 var_SetFloat( p_demux, "sub-fps", f_fps );
1483 p_sys->mpsub.f_factor = 1.0;
1490 f1 = us_strtod( s, &psz_temp );
1493 f2 = us_strtod( psz_temp, NULL );
1494 p_sys->mpsub.f_total += f1 * p_sys->mpsub.f_factor;
1495 p_subtitle->i_start = (int64_t)(10000.0 * p_sys->mpsub.f_total);
1496 p_sys->mpsub.f_total += f2 * p_sys->mpsub.f_factor;
1497 p_subtitle->i_stop = (int64_t)(10000.0 * p_sys->mpsub.f_total);
1504 const char *s = TextGetLine( txt );
1507 return VLC_EGENERIC;
1509 int i_len = strlen( s );
1513 int i_old = strlen( psz_text );
1515 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1519 strcat( psz_text, s );
1520 strcat( psz_text, "\n" );
1523 p_subtitle->psz_text = psz_text;
1527 static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1529 VLC_UNUSED( i_idx );
1531 demux_sys_t *p_sys = p_demux->p_sys;
1532 text_t *txt = &p_sys->txt;
1533 char *psz_text, *psz_orig;
1534 char *psz_text2, *psz_orig2;
1535 int h1, h2, m1, m2, s1, s2, f1, f2;
1537 if( !p_sys->jss.b_inited )
1539 p_sys->jss.i_comment = 0;
1540 p_sys->jss.i_time_resolution = 30;
1541 p_sys->jss.i_time_shift = 0;
1543 p_sys->jss.b_inited = true;
1546 /* Parse the main lines */
1549 const char *s = TextGetLine( txt );
1551 return VLC_EGENERIC;
1553 psz_orig = malloc( strlen( s ) + 1 );
1556 psz_text = psz_orig;
1558 /* Complete time lines */
1559 if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]",
1560 &h1, &m1, &s1, &f1, &h2, &m2, &s2, &f2, psz_text ) == 9 )
1562 p_subtitle->i_start = ( (int64_t)( h1 *3600 + m1 * 60 + s1 ) +
1563 (int64_t)( ( f1 + p_sys->jss.i_time_shift ) / p_sys->jss.i_time_resolution ) )
1565 p_subtitle->i_stop = ( (int64_t)( h2 *3600 + m2 * 60 + s2 ) +
1566 (int64_t)( ( f2 + p_sys->jss.i_time_shift ) / p_sys->jss.i_time_resolution ) )
1570 /* Short time lines */
1571 else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 )
1573 p_subtitle->i_start = (int64_t)(
1574 ( f1 + p_sys->jss.i_time_shift ) / p_sys->jss.i_time_resolution * 1000000.0 );
1575 p_subtitle->i_stop = (int64_t)(
1576 ( f2 + p_sys->jss.i_time_shift ) / p_sys->jss.i_time_resolution * 1000000.0 );
1579 /* General Directive lines */
1580 /* Only TIME and SHIFT are supported so far */
1581 else if( s[0] == '#' )
1583 int h = 0, m =0, sec = 1, f = 1;
1587 strcpy( psz_text, s );
1589 switch( toupper( psz_text[1] ) )
1592 shift = isalpha( psz_text[2] ) ? 6 : 2 ;
1594 if( sscanf( &psz_text[shift], "%d", &h ) )
1596 /* Negative shifting */
1603 if( sscanf( &psz_text[shift], "%*d:%d", &m ) )
1605 if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) )
1607 sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f );
1612 sscanf( &psz_text[shift], "%d:%d.%d",
1620 sscanf( &psz_text[shift], "%d.%d", &sec, &f);
1623 p_sys->jss.i_time_shift = ( ( h * 3600 + m * 60 + sec )
1624 * p_sys->jss.i_time_resolution + f ) * inv;
1629 shift = isalpha( psz_text[2] ) ? 8 : 2 ;
1631 sscanf( &psz_text[shift], "%d", &p_sys->jss.i_time_resolution );
1638 /* Unkown type line, probably a comment */
1645 while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
1647 const char *s2 = TextGetLine( txt );
1650 return VLC_EGENERIC;
1652 int i_len = strlen( s2 );
1656 int i_old = strlen( psz_text );
1658 psz_text = realloc( psz_text, i_old + i_len + 1 );
1662 psz_orig = psz_text;
1663 strcat( psz_text, s2 );
1666 /* Skip the blanks */
1667 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1669 /* Parse the directives */
1670 if( isalpha( *psz_text ) || *psz_text == '[' )
1672 while( *psz_text != ' ' )
1675 /* Directives are NOT parsed yet */
1676 /* This has probably a better place in a decoder ? */
1677 /* directive = malloc( strlen( psz_text ) + 1 );
1678 if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/
1681 /* Skip the blanks after directives */
1682 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1684 /* Clean all the lines from inline comments and other stuffs */
1685 psz_orig2 = calloc( strlen( psz_text) + 1, 1 );
1686 psz_text2 = psz_orig2;
1688 for( ; *psz_text != '\0' && *psz_text != '\n' && *psz_text != '\r'; )
1693 p_sys->jss.i_comment++;
1696 if( p_sys->jss.i_comment )
1698 p_sys->jss.i_comment = 0;
1699 if( (*(psz_text + 1 ) ) == ' ' ) psz_text++;
1703 if( !p_sys->jss.i_comment )
1711 if( (*(psz_text + 1 ) ) == ' ' || (*(psz_text + 1 ) ) == '\t' )
1713 if( !p_sys->jss.i_comment )
1720 if( (*(psz_text + 1 ) ) == 'n' )
1727 if( ( toupper(*(psz_text + 1 ) ) == 'C' ) ||
1728 ( toupper(*(psz_text + 1 ) ) == 'F' ) )
1730 psz_text++; psz_text++;
1733 if( (*(psz_text + 1 ) ) == 'B' || (*(psz_text + 1 ) ) == 'b' ||
1734 (*(psz_text + 1 ) ) == 'I' || (*(psz_text + 1 ) ) == 'i' ||
1735 (*(psz_text + 1 ) ) == 'U' || (*(psz_text + 1 ) ) == 'u' ||
1736 (*(psz_text + 1 ) ) == 'D' || (*(psz_text + 1 ) ) == 'N' )
1741 if( (*(psz_text + 1 ) ) == '~' || (*(psz_text + 1 ) ) == '{' ||
1742 (*(psz_text + 1 ) ) == '\\' )
1744 else if( *(psz_text + 1 ) == '\r' || *(psz_text + 1 ) == '\n' ||
1745 *(psz_text + 1 ) == '\0' )
1751 if( !p_sys->jss.i_comment )
1753 *psz_text2 = *psz_text;
1760 p_subtitle->psz_text = psz_orig2;
1761 msg_Dbg( p_demux, "%s", p_subtitle->psz_text );
1766 static int ParsePSB( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1768 VLC_UNUSED( i_idx );
1770 demux_sys_t *p_sys = p_demux->p_sys;
1771 text_t *txt = &p_sys->txt;
1779 const char *s = TextGetLine( txt );
1782 return VLC_EGENERIC;
1784 psz_text = malloc( strlen( s ) + 1 );
1788 if( sscanf( s, "{%d:%d:%d}{%d:%d:%d}%[^\r\n]",
1789 &h1, &m1, &s1, &h2, &m2, &s2, psz_text ) == 7 )
1791 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1792 (int64_t)m1 * 60*1000 +
1793 (int64_t)s1 * 1000 ) * 1000;
1794 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1795 (int64_t)m2 * 60*1000 +
1796 (int64_t)s2 * 1000 ) * 1000;
1802 /* replace | by \n */
1803 for( i = 0; psz_text[i] != '\0'; i++ )
1805 if( psz_text[i] == '|' )
1808 p_subtitle->psz_text = psz_text;
1812 static int64_t ParseRealTime( char *psz, int *h, int *m, int *s, int *f )
1814 if( strlen( psz ) == 0 ) return 0;
1815 if( sscanf( psz, "%d:%d:%d.%d", h, m, s, f ) == 4 ||
1816 sscanf( psz, "%d:%d.%d", m, s, f ) == 3 ||
1817 sscanf( psz, "%d.%d", s, f ) == 2 ||
1818 sscanf( psz, "%d:%d", m, s ) == 2 ||
1819 sscanf( psz, "%d", s ) == 1 )
1821 return (int64_t)((( *h * 60 + *m ) * 60 ) + *s ) * 1000 * 1000
1822 + (int64_t)*f * 10 * 1000;
1824 else return VLC_EGENERIC;
1827 static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1829 VLC_UNUSED( i_idx );
1830 demux_sys_t *p_sys = p_demux->p_sys;
1831 text_t *txt = &p_sys->txt;
1833 char psz_end[12]= "", psz_begin[12] = "";
1837 int h1 = 0, m1 = 0, s1 = 0, f1 = 0;
1838 int h2 = 0, m2 = 0, s2 = 0, f2 = 0;
1839 const char *s = TextGetLine( txt );
1842 return VLC_EGENERIC;
1844 psz_text = malloc( strlen( s ) + 1 );
1848 /* Find the good begining. This removes extra spaces at the beginning
1850 char *psz_temp = strcasestr( s, "<time");
1851 if( psz_temp != NULL )
1853 /* Line has begin and end */
1854 if( ( sscanf( psz_temp,
1855 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\" %*[e|E]nd=\"%[^\"]%*[^>]%[^\n\r]",
1856 psz_begin, psz_end, psz_text) != 3 ) &&
1857 /* Line has begin and no end */
1859 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\"%*[^>]%[^\n\r]",
1860 psz_begin, psz_text ) != 2) )
1861 /* Line is not recognized */
1868 int64_t i_time = ParseRealTime( psz_begin, &h1, &m1, &s1, &f1 );
1871 p_subtitle->i_start = i_time;
1874 i_time = ParseRealTime( psz_end, &h2, &m2, &s2, &f2 );
1877 p_subtitle->i_stop = i_time;
1881 /* Line is not recognized */
1886 /* Get the following Lines */
1889 const char *s = TextGetLine( txt );
1892 return VLC_EGENERIC;
1894 int i_len = strlen( s );
1895 if( i_len == 0 ) break;
1897 if( strcasestr( s, "<time" ) ||
1898 strcasestr( s, "<clear/") )
1900 TextPreviousLine( txt );
1904 int i_old = strlen( psz_text );
1906 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1910 strcat( psz_text, s );
1911 strcat( psz_text, "\n" );
1914 /* Remove the starting ">" that remained after the sscanf */
1915 memmove( &psz_text[0], &psz_text[1], strlen( psz_text ) );
1917 p_subtitle->psz_text = psz_text;
1922 static int ParseDKS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1924 VLC_UNUSED( i_idx );
1926 demux_sys_t *p_sys = p_demux->p_sys;
1927 text_t *txt = &p_sys->txt;
1934 char *s = TextGetLine( txt );
1937 return VLC_EGENERIC;
1939 psz_text = malloc( strlen( s ) + 1 );
1943 if( sscanf( s, "[%d:%d:%d]%[^\r\n]",
1944 &h1, &m1, &s1, psz_text ) == 4 )
1946 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1947 (int64_t)m1 * 60*1000 +
1948 (int64_t)s1 * 1000 ) * 1000;
1950 char *s = TextGetLine( txt );
1952 return VLC_EGENERIC;
1954 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1955 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1956 (int64_t)m2 * 60*1000 +
1957 (int64_t)s2 * 1000 ) * 1000;
1963 /* replace [br] by \n */
1965 while( ( p = strstr( psz_text, "[br]" ) ) )
1968 memmove( p, &p[3], strlen(&p[3])+1 );
1971 p_subtitle->psz_text = psz_text;
1975 static int ParseSubViewer1( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1977 VLC_UNUSED( i_idx );
1979 demux_sys_t *p_sys = p_demux->p_sys;
1980 text_t *txt = &p_sys->txt;
1987 char *s = TextGetLine( txt );
1990 return VLC_EGENERIC;
1992 if( sscanf( s, "[%d:%d:%d]", &h1, &m1, &s1 ) == 3 )
1994 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1995 (int64_t)m1 * 60*1000 +
1996 (int64_t)s1 * 1000 ) * 1000;
1998 char *s = TextGetLine( txt );
2000 return VLC_EGENERIC;
2002 psz_text = strdup( s );
2006 s = TextGetLine( txt );
2008 return VLC_EGENERIC;
2010 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
2011 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
2012 (int64_t)m2 * 60*1000 +
2013 (int64_t)s2 * 1000 ) * 1000;
2018 p_subtitle->psz_text = psz_text;