1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 1999-2003 VideoLAN
5 * $Id: sub.c,v 1.31 2003/10/31 22:46:19 hartman Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
29 #include <sys/types.h>
33 #include <vlc/input.h>
34 #include "vlc_video.h"
38 #if (!defined( WIN32 ) || defined(__MINGW32__))
42 static int Open ( vlc_object_t *p_this );
44 static int sub_open ( subtitle_demux_t *p_sub,
45 input_thread_t *p_input,
47 mtime_t i_microsecperframe,
49 static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate );
50 static int sub_seek ( subtitle_demux_t *p_sub, mtime_t i_date );
51 static void sub_close( subtitle_demux_t *p_sub );
53 static void sub_fix( subtitle_demux_t *p_sub );
55 static char *ppsz_sub_type[] = { "auto", "microdvd", "subrip", "ssa1", "ssa2-4",
56 "vplayer", "sami", "vobsub", NULL };
59 /*****************************************************************************
61 *****************************************************************************/
62 #define SUB_DELAY_LONGTEXT \
63 "Delay subtitles (in 1/10s)"
64 #define SUB_FPS_LONGTEXT \
65 "Override frames per second. " \
66 "It will only work with MicroDVD subtitles."
67 #define SUB_TYPE_LONGTEXT \
68 "One from \"microdvd\", \"subrip\", \"ssa1\", \"ssa2-4\", \"vplayer\" " \
69 "\"sami\" (auto for autodetection, it should always work)."
72 set_description( _("Text subtitles demux") );
73 set_capability( "subtitle demux", 12 );
74 add_category_hint( "Subtitles", NULL, VLC_TRUE );
75 add_float( "sub-fps", 0.0, NULL,
77 SUB_FPS_LONGTEXT, VLC_TRUE );
78 add_integer( "sub-delay", 0, NULL,
79 "Delay subtitles (in 1/10s)",
80 SUB_DELAY_LONGTEXT, VLC_TRUE );
81 add_string_from_list( "sub-type", "auto", ppsz_sub_type, NULL,
83 SUB_TYPE_LONGTEXT, VLC_TRUE );
84 set_callbacks( Open, NULL );
87 /*****************************************************************************
89 *****************************************************************************/
90 static int Open ( vlc_object_t *p_this )
92 subtitle_demux_t *p_sub = (subtitle_demux_t*)p_this;
94 p_sub->pf_open = sub_open;
95 p_sub->pf_demux = sub_demux;
96 p_sub->pf_seek = sub_seek;
97 p_sub->pf_close = sub_close;
99 /* Initialize the variables */
100 var_Create( p_this, "sub-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
101 var_Create( p_this, "sub-delay", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
102 var_Create( p_this, "sub-type", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
107 #define MAX_LINE 2048
109 #define FREE( p ) if( p ) { free( p); (p) = NULL; }
118 static int text_load( text_t *txt, char *psz_name )
125 txt->i_line_count = 0;
127 txt->line = calloc( i_line_max, sizeof( char * ) );
130 if( !( f = fopen( psz_name, "rb" ) ) )
135 /* load the complete file */
141 if( fgets( buffer, 8096, f ) <= 0)
145 while( ( p = strchr( buffer, '\r' ) ) )
149 while( ( p = strchr( buffer, '\n' ) ) )
154 txt->line[txt->i_line_count++] = strdup( buffer );
156 if( txt->i_line_count >= i_line_max )
159 txt->line = realloc( txt->line, i_line_max * sizeof( char*) );
165 if( txt->i_line_count <= 0 )
168 return( VLC_EGENERIC );
171 return( VLC_SUCCESS );
173 static void text_unload( text_t *txt )
177 for( i = 0; i < txt->i_line_count; i++ )
179 FREE( txt->line[i] );
183 txt->i_line_count = 0;
186 static char *text_get_line( text_t *txt )
188 if( txt->i_line >= txt->i_line_count )
193 return( txt->line[txt->i_line++] );
195 static void text_previous_line( text_t *txt )
197 if( txt->i_line > 0 )
202 static void text_rewind( text_t *txt )
207 static int sub_MicroDvdRead( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe );
208 static int sub_SubRipRead ( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe );
209 static int sub_SSA1Read ( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe );
210 static int sub_SSA2_4Read ( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe );
211 static int sub_Vplayer ( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe );
212 static int sub_Sami ( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe );
213 static int sub_VobSub ( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe );
220 int (*pf_read_subtitle) ( text_t *, subtitle_t*, mtime_t );
221 } sub_read_subtitle_function [] =
223 { "microdvd", SUB_TYPE_MICRODVD, "MicroDVD", sub_MicroDvdRead },
224 { "subrip", SUB_TYPE_SUBRIP, "SubRIP", sub_SubRipRead },
225 { "ssa1", SUB_TYPE_SSA1, "SSA-1", sub_SSA1Read },
226 { "ssa2-4", SUB_TYPE_SSA2_4, "SSA-2/3/4",sub_SSA2_4Read },
227 { "vplayer", SUB_TYPE_VPLAYER, "VPlayer", sub_Vplayer },
228 { "sami", SUB_TYPE_SAMI, "SAMI", sub_Sami },
229 { "vobsub", SUB_TYPE_VOBSUB, "VobSub", sub_VobSub },
230 { NULL, SUB_TYPE_UNKNOWN, "Unknown", NULL }
233 static char * local_stristr( char *psz_big, char *psz_little)
235 char *p_pos = psz_big;
237 if (!psz_big || !psz_little || !*psz_little) return psz_big;
241 if (toupper(*p_pos) == toupper(*psz_little))
243 char * psz_cur1 = p_pos + 1;
244 char * psz_cur2 = psz_little + 1;
245 while (*psz_cur1 && *psz_cur2 && toupper(*psz_cur1) == toupper(*psz_cur2))
250 if (!*psz_cur2) return p_pos;
257 /*****************************************************************************
258 * sub_open: Open a subtitle file and add subtitle ES
259 *****************************************************************************/
260 static int sub_open ( subtitle_demux_t *p_sub,
261 input_thread_t *p_input,
263 mtime_t i_microsecperframe,
272 int (*pf_read_subtitle)( text_t *, subtitle_t *, mtime_t ) = NULL;
274 p_sub->i_sub_type = SUB_TYPE_UNKNOWN;
276 p_sub->i_subtitles = 0;
277 p_sub->subtitle = NULL;
278 p_sub->p_input = p_input;
280 if( !psz_name || !*psz_name )
282 msg_Err( p_sub, "no subtitle file specified" );
283 if( psz_name ) free( psz_name );
287 /* *** load the file *** */
288 if( text_load( &txt, psz_name ) )
290 msg_Err( p_sub, "cannot open `%s' subtitle file", psz_name );
294 msg_Dbg( p_sub, "opened `%s'", psz_name );
297 var_Get( p_sub, "sub-fps", &val );
298 if( val.i_int >= 1.0 )
300 var_Get( p_sub, "sub-fps", &val );
301 i_microsecperframe = (mtime_t)( (float)1000000 / val.f_float );
303 else if( i_microsecperframe <= 0 )
305 i_microsecperframe = 40000; /* default: 25fps */
308 var_Get( p_sub, "sub-type", &val);
309 if( val.psz_string && *val.psz_string )
315 if( sub_read_subtitle_function[i].psz_type_name == NULL )
317 i_sub_type = SUB_TYPE_UNKNOWN;
320 if( !strcmp( sub_read_subtitle_function[i].psz_type_name,
323 i_sub_type = sub_read_subtitle_function[i].i_type;
330 i_sub_type = SUB_TYPE_UNKNOWN;
332 FREE( val.psz_string );
334 /* *** Now try to autodetect subtitle format *** */
335 if( i_sub_type == SUB_TYPE_UNKNOWN )
340 msg_Dbg( p_input, "trying to autodetect file format" );
341 for( i_try = 0; i_try < MAX_TRY; i_try++ )
345 if( ( s = text_get_line( &txt ) ) == NULL )
350 if( local_stristr( s, "<SAMI>" ) )
352 i_sub_type = SUB_TYPE_SAMI;
355 else if( sscanf( s, "{%d}{%d}", &i_dummy, &i_dummy ) == 2 ||
356 sscanf( s, "{%d}{}", &i_dummy ) == 1)
358 i_sub_type = SUB_TYPE_MICRODVD;
362 "%d:%d:%d,%d --> %d:%d:%d,%d",
363 &i_dummy,&i_dummy,&i_dummy,&i_dummy,
364 &i_dummy,&i_dummy,&i_dummy,&i_dummy ) == 8 )
366 i_sub_type = SUB_TYPE_SUBRIP;
370 "!: This is a Sub Station Alpha v%d.x script.",
375 i_sub_type = SUB_TYPE_SSA1;
379 i_sub_type = SUB_TYPE_SSA2_4; /* I hope this will work */
383 else if( local_stristr( s, "This is a Sub Station Alpha v4 script" ) )
385 i_sub_type = SUB_TYPE_SSA2_4; /* I hope this will work */
388 else if( !strncasecmp( s, "Dialogue: Marked", 16 ) )
390 i_sub_type = SUB_TYPE_SSA2_4; /* could be wrong */
393 else if( sscanf( s, "%d:%d:%d:", &i_dummy, &i_dummy, &i_dummy ) == 3 ||
394 sscanf( s, "%d:%d:%d ", &i_dummy, &i_dummy, &i_dummy ) == 3 )
396 i_sub_type = SUB_TYPE_VPLAYER;
399 else if( local_stristr( s, "# VobSub index file" ) )
401 i_sub_type = SUB_TYPE_VOBSUB;
409 /* *** Load this file in memory *** */
412 if( sub_read_subtitle_function[i].i_type == SUB_TYPE_UNKNOWN )
414 msg_Dbg( p_input, "unknown subtitle file" );
419 if( sub_read_subtitle_function[i].i_type == i_sub_type )
421 msg_Dbg( p_input, "detected %s format",
422 sub_read_subtitle_function[i].psz_name );
423 p_sub->i_sub_type = i_sub_type;
424 pf_read_subtitle = sub_read_subtitle_function[i].pf_read_subtitle;
431 if( p_sub->i_subtitles >= i_max )
434 if( p_sub->subtitle )
436 p_sub->subtitle = realloc( p_sub->subtitle,
437 sizeof( subtitle_t ) * i_max );
441 p_sub->subtitle = malloc( sizeof( subtitle_t ) * i_max );
444 if( pf_read_subtitle( &txt,
445 p_sub->subtitle + p_sub->i_subtitles,
446 i_microsecperframe ) < 0 )
450 p_sub->i_subtitles++;
452 msg_Dbg( p_sub, "loaded %d subtitles", p_sub->i_subtitles );
454 /* *** Close the file *** */
457 /* *** fix subtitle (order and time) *** */
458 p_sub->i_subtitle = 0; /* will be modified by sub_fix */
461 /* *** add subtitle ES *** */
462 vlc_mutex_lock( &p_input->stream.stream_lock );
463 p_sub->p_es = input_AddES( p_input, p_input->stream.p_selected_program,
464 0xff - i_track_id, /* FIXME */
466 vlc_mutex_unlock( &p_input->stream.stream_lock );
468 p_sub->p_es->i_stream_id = 0xff - i_track_id; /* FIXME */
470 if( p_sub->i_sub_type != SUB_TYPE_VOBSUB )
472 p_sub->p_es->i_fourcc = VLC_FOURCC( 's','u','b','t' );
476 p_sub->p_es->i_fourcc = VLC_FOURCC( 's','p','u',' ' );
477 /* open vobsub file */
480 p_sub->i_previously_selected = 0;
484 /*****************************************************************************
485 * sub_demux: Send subtitle to decoder until i_maxdate
486 *****************************************************************************/
487 static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
489 if( p_sub->p_es->p_decoder_fifo && !p_sub->i_previously_selected )
491 p_sub->i_previously_selected = 1;
492 p_sub->pf_seek( p_sub, i_maxdate );
495 else if( !p_sub->p_es->p_decoder_fifo && p_sub->i_previously_selected )
497 p_sub->i_previously_selected = 0;
501 while( p_sub->i_subtitle < p_sub->i_subtitles &&
502 p_sub->subtitle[p_sub->i_subtitle].i_start < i_maxdate )
505 data_packet_t *p_data;
509 i_len = strlen( p_sub->subtitle[p_sub->i_subtitle].psz_text ) + 1;
517 if( !( p_pes = input_NewPES( p_sub->p_input->p_method_data ) ) )
523 if( !( p_data = input_NewPacket( p_sub->p_input->p_method_data,
526 input_DeletePES( p_sub->p_input->p_method_data, p_pes );
530 p_data->p_payload_end = p_data->p_payload_start + i_len;
533 input_ClockGetTS( p_sub->p_input,
534 p_sub->p_input->stream.p_selected_program,
535 p_sub->subtitle[p_sub->i_subtitle].i_start*9/100);
536 if( p_sub->subtitle[p_sub->i_subtitle].i_stop > 0 )
539 * i_dts means end of display...
542 input_ClockGetTS( p_sub->p_input,
543 p_sub->p_input->stream.p_selected_program,
544 p_sub->subtitle[p_sub->i_subtitle].i_stop *9/100);
551 p_pes->i_nb_data = 1;
553 p_pes->p_last = p_data;
554 p_pes->i_pes_size = i_len;
556 memcpy( p_data->p_payload_start,
557 p_sub->subtitle[p_sub->i_subtitle].psz_text,
559 if( p_sub->p_es->p_decoder_fifo && p_pes->i_pts > 0 )
562 input_DecodePES( p_sub->p_es->p_decoder_fifo, p_pes );
566 input_DeletePES( p_sub->p_input->p_method_data, p_pes );
574 /*****************************************************************************
575 * sub_seek: Seek to i_date
576 *****************************************************************************/
577 static int sub_seek ( subtitle_demux_t *p_sub, mtime_t i_date )
579 /* should be fast enough... */
580 p_sub->i_subtitle = 0;
581 while( p_sub->i_subtitle < p_sub->i_subtitles &&
582 p_sub->subtitle[p_sub->i_subtitle].i_start < i_date )
590 /*****************************************************************************
591 * sub_close: Close subtitle demux
592 *****************************************************************************/
593 static void sub_close( subtitle_demux_t *p_sub )
595 if( p_sub->subtitle )
598 for( i = 0; i < p_sub->i_subtitles; i++ )
600 if( p_sub->subtitle[i].psz_text )
602 free( p_sub->subtitle[i].psz_text );
605 free( p_sub->subtitle );
608 /*****************************************************************************
610 * sub_fix: fix time stamp and order of subtitle
611 *****************************************************************************/
612 static void sub_fix( subtitle_demux_t *p_sub )
620 /* *** fix order (to be sure...) *** */
621 /* We suppose that there are near in order and this durty bubble sort
622 * wont take too much time
627 for( i_index = 1; i_index < p_sub->i_subtitles; i_index++ )
629 if( p_sub->subtitle[i_index].i_start <
630 p_sub->subtitle[i_index - 1].i_start )
634 p_sub->subtitle + i_index - 1,
635 sizeof( subtitle_t ) );
636 memcpy( p_sub->subtitle + i_index - 1,
637 p_sub->subtitle + i_index,
638 sizeof( subtitle_t ) );
639 memcpy( p_sub->subtitle + i_index,
641 sizeof( subtitle_t ) );
647 /* *** and at the end add delay *** */
648 var_Get( p_sub, "sub-delay", &val );
649 i_delay = (mtime_t) val.i_int * 100000;
652 for( i = 0; i < p_sub->i_subtitles; i++ )
654 p_sub->subtitle[i].i_start += i_delay;
655 p_sub->subtitle[i].i_stop += i_delay;
656 if( p_sub->subtitle[i].i_start < 0 )
658 p_sub->i_subtitle = i + 1;
666 /*****************************************************************************
667 * Specific Subtitle function
668 *****************************************************************************/
669 static int sub_MicroDvdRead( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe)
673 * {n1}{n2}Line1|Line2|Line3....
674 * where n1 and n2 are the video frame number...
679 char buffer_text[MAX_LINE + 1];
686 if( ( s = text_get_line( txt ) ) == NULL )
688 return( VLC_EGENERIC );
693 memset( buffer_text, '\0', MAX_LINE );
694 if( sscanf( s, "{%d}{}%[^\r\n]", &i_start, buffer_text ) == 2 ||
695 sscanf( s, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, buffer_text ) == 3)
700 /* replace | by \n */
701 for( i = 0; i < strlen( buffer_text ); i++ )
703 if( buffer_text[i] == '|' )
705 buffer_text[i] = '\n';
708 p_subtitle->i_start = (mtime_t)i_start * (mtime_t)i_microsecperframe;
709 p_subtitle->i_stop = (mtime_t)i_stop * (mtime_t)i_microsecperframe;
710 p_subtitle->psz_text = strndup( buffer_text, MAX_LINE );
714 static int sub_SubRipRead( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe )
718 * h1:m1:s1,d1 --> h2:m2:s2,d2
726 char buffer_text[ 10 * MAX_LINE];
733 int h1, m1, s1, d1, h2, m2, s2, d2;
734 if( ( s = text_get_line( txt ) ) == NULL )
736 return( VLC_EGENERIC );
739 "%d:%d:%d,%d --> %d:%d:%d,%d",
741 &h2, &m2, &s2, &d2 ) == 8 )
743 i_start = ( (mtime_t)h1 * 3600*1000 +
744 (mtime_t)m1 * 60*1000 +
746 (mtime_t)d1 ) * 1000;
748 i_stop = ( (mtime_t)h2 * 3600*1000 +
749 (mtime_t)m2 * 60*1000 +
751 (mtime_t)d2 ) * 1000;
753 /* Now read text until an empty line */
754 for( i_buffer_text = 0;; )
757 if( ( s = text_get_line( txt ) ) == NULL )
759 return( VLC_EGENERIC );
765 // empty line -> end of this subtitle
766 buffer_text[__MAX( i_buffer_text - 1, 0 )] = '\0';
767 p_subtitle->i_start = i_start;
768 p_subtitle->i_stop = i_stop;
769 p_subtitle->psz_text = strdup( buffer_text );
774 if( i_buffer_text + i_len + 1 < 10 * MAX_LINE )
776 memcpy( buffer_text + i_buffer_text,
779 i_buffer_text += i_len;
781 buffer_text[i_buffer_text] = '\n';
791 static int sub_SSARead( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe, int i_comma_count )
793 char buffer_text[ 10 * MAX_LINE];
803 int h1, m1, s1, c1, h2, m2, s2, c2;
806 if( ( s = text_get_line( txt ) ) == NULL )
808 return( VLC_EGENERIC );
811 "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d,%[^\r\n]",
815 buffer_text ) == 10 )
817 i_start = ( (mtime_t)h1 * 3600*1000 +
818 (mtime_t)m1 * 60*1000 +
820 (mtime_t)c1 * 10 ) * 1000;
822 i_stop = ( (mtime_t)h2 * 3600*1000 +
823 (mtime_t)m2 * 60*1000 +
825 (mtime_t)c2 * 10 ) * 1000;
827 p_buffer_text = buffer_text;
829 while( i_comma < i_comma_count &&
830 *p_buffer_text != '\0' )
832 if( *p_buffer_text == ',' )
838 p_subtitle->psz_text = malloc( strlen( p_buffer_text ) + 1);
840 while( *p_buffer_text )
842 if( *p_buffer_text == '\\' && ( *p_buffer_text =='n' || *p_buffer_text =='N' ) )
844 p_subtitle->psz_text[i_text] = '\n';
848 else if( *p_buffer_text == '{' && *p_buffer_text == '\\')
850 while( *p_buffer_text && *p_buffer_text != '}' )
857 p_subtitle->psz_text[i_text] = *p_buffer_text;
862 p_subtitle->psz_text[i_text] = '\0';
863 p_subtitle->i_start = i_start;
864 p_subtitle->i_stop = i_stop;
870 static int sub_SSA1Read( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe )
872 return( sub_SSARead( txt, p_subtitle, i_microsecperframe, 8 ) );
874 static int sub_SSA2_4Read( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe )
876 return( sub_SSARead( txt, p_subtitle, i_microsecperframe, 9 ) );
879 static int sub_Vplayer( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe)
883 * h:m:s:Line1|Line2|Line3....
885 * h:m:s Line1|Line2|Line3....
886 * where n1 and n2 are the video frame number...
890 char buffer_text[MAX_LINE + 1];
899 if( ( p = text_get_line( txt ) ) == NULL )
901 return( VLC_EGENERIC );
906 memset( buffer_text, '\0', MAX_LINE );
907 if( sscanf( p, "%d:%d:%d%[ :]%[^\r\n]", &h, &m, &s, &c, buffer_text ) == 5 )
909 i_start = ( (mtime_t)h * 3600*1000 +
910 (mtime_t)m * 60*1000 +
911 (mtime_t)s * 1000 ) * 1000;
916 /* replace | by \n */
917 for( i = 0; i < strlen( buffer_text ); i++ )
919 if( buffer_text[i] == '|' )
921 buffer_text[i] = '\n';
924 p_subtitle->i_start = i_start;
926 p_subtitle->i_stop = 0;
927 p_subtitle->psz_text = strndup( buffer_text, MAX_LINE );
931 static char *sub_SamiSearch( text_t *txt, char *psz_start, char *psz_str )
935 if( local_stristr( psz_start, psz_str ) )
937 char *s = local_stristr( psz_start, psz_str );
939 s += strlen( psz_str );
947 if( ( p = text_get_line( txt ) ) == NULL )
951 if( local_stristr( p, psz_str ) )
953 char *s = local_stristr( p, psz_str );
955 s += strlen( psz_str );
962 static int sub_Sami( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe )
968 char buffer_text[10*MAX_LINE + 1];
970 if( i_text < 10*MAX_LINE ) \
972 buffer_text[i_text++] = c; \
973 buffer_text[i_text] = '\0'; \
976 /* search "Start=" */
977 if( !( p = sub_SamiSearch( txt, NULL, "Start=" ) ) )
982 /* get start value */
983 i_start = strtol( p, &p, 0 );
986 if( !( p = sub_SamiSearch( txt, p, "<P" ) ) )
991 if( !( p = sub_SamiSearch( txt, p, ">" ) ) )
997 buffer_text[0] = '\0';
998 /* now get all txt until a "Start=" line */
1005 if( !strncasecmp( p, "<br", 3 ) )
1009 else if( local_stristr( p, "Start=" ) )
1011 text_previous_line( txt );
1014 p = sub_SamiSearch( txt, p, ">" );
1016 else if( !strncmp( p, " ", 6 ) )
1021 else if( *p == '\t' )
1034 p = text_get_line( txt );
1043 p_subtitle->i_start = i_start * 1000;
1044 p_subtitle->i_stop = 0;
1045 p_subtitle->psz_text = strndup( buffer_text, 10*MAX_LINE );
1047 return( VLC_SUCCESS );
1051 static int sub_VobSub( text_t *txt, subtitle_t *p_subtitle, mtime_t i_microsecperframe)
1054 * Parse the idx file. Each line:
1055 * timestamp: hh:mm:ss:mss, filepos: loc
1056 * hexint is the hex location of the vobsub in the .sub file
1061 char buffer_text[MAX_LINE + 1];
1062 uint32_t i_start, i_location;
1066 if( ( p = text_get_line( txt ) ) == NULL )
1068 return( VLC_EGENERIC );
1071 unsigned int h, m, s, ms, loc;
1073 memset( buffer_text, '\0', MAX_LINE );
1074 if( sscanf( p, "timestamp: %d:%d:%d:%d, filepos: %x%[^\r\n]",
1075 &h, &m, &s, &ms, &loc, buffer_text ) == 5 )
1077 i_start = ( (mtime_t)h * 3600*1000 +
1078 (mtime_t)m * 60*1000 +
1080 (mtime_t)ms ) * 1000;
1085 p_subtitle->i_start = (mtime_t)i_start;
1086 p_subtitle->i_stop = 0;
1087 p_subtitle->i_vobsub_location = i_location;
1088 fprintf( stderr, "time: %x, location: %x\n", i_start, i_location );