/*****************************************************************************
* subtitle.c: Demux for subtitle text files.
*****************************************************************************
- * Copyright (C) 1999-2004 the VideoLAN team
+ * Copyright (C) 1999-2007 the VideoLAN team
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
#define SUB_TYPE_LONGTEXT \
N_("Force the subtiles format. Valid values are : \"microdvd\", " \
"\"subrip\", \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\" " \
- "\"sami\", \"dvdsubtitle\" and \"auto\" (meaning autodetection, this " \
+ "\"sami\", \"dvdsubtitle\", \"mpl2\" and \"auto\" (meaning autodetection, this " \
"should always work).")
static const char *ppsz_sub_type[] =
{
"auto", "microdvd", "subrip", "subviewer", "ssa1",
- "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle"
+ "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2"
};
vlc_module_begin();
SUB_TYPE_VPLAYER,
SUB_TYPE_SAMI,
SUB_TYPE_SUBVIEWER,
- SUB_TYPE_DVDSUBTITLE
+ SUB_TYPE_DVDSUBTITLE,
+ SUB_TYPE_MPL2
};
typedef struct
static int ParseVplayer ( demux_t *, subtitle_t * );
static int ParseSami ( demux_t *, subtitle_t * );
static int ParseDVDSubtitle( demux_t *, subtitle_t * );
+static int ParseMPL2 ( demux_t *, subtitle_t * );
static struct
{
{ "vplayer", SUB_TYPE_VPLAYER, "VPlayer", ParseVplayer },
{ "sami", SUB_TYPE_SAMI, "SAMI", ParseSami },
{ "dvdsubtitle",SUB_TYPE_DVDSUBTITLE, "DVDSubtitle", ParseDVDSubtitle },
+ { "mpl2", SUB_TYPE_MPL2, "MPL2", ParseMPL2 },
{ NULL, SUB_TYPE_UNKNOWN, "Unknown", NULL }
};
p_sys->i_subtitle = 0;
p_sys->i_subtitles = 0;
p_sys->subtitle = NULL;
- p_sys->i_microsecperframe = 0;
+ p_sys->i_microsecperframe = 40000;
/* Get the FPS */
- f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
- if( f_fps >= 1.0 )
- {
- p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
- msg_Dbg( p_demux, "Override subtitle fps %f", f_fps );
- }
-
p_input = (input_thread_t *)vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT );
if( p_input )
{
if( f_fps >= 1.0 )
{
p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
+ msg_Dbg( p_demux, "Override subtitle fps %f", f_fps );
}
/* Get or probe the type */
p_sys->i_type = SUB_TYPE_DVDSUBTITLE;
break;
}
+ else if( sscanf( s, "[%d][%d]", &i_dummy, &i_dummy ) == 2 ||
+ sscanf( s, "[%d][]", &i_dummy ) == 1)
+ {
+ p_sys->i_type = SUB_TYPE_MPL2;
+ break;
+ }
free( s );
s = NULL;
int i_stop;
unsigned int i;
- /* Try sub-fps value if set, movie rate if know, else 25fps (40000) */
- int i_microsecperframe = p_sys->i_original_mspf > 0 ? p_sys->i_original_mspf : 40000;
- if( p_sys->i_microsecperframe > 0 )
- i_microsecperframe = p_sys->i_microsecperframe;
-
p_subtitle->i_start = 0;
p_subtitle->i_stop = 0;
p_subtitle->psz_text = NULL;
}
}
+static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ text_t *txt = &p_sys->txt;
+ /*
+ * each line:
+ * [n1][n2]Line1|Line2|Line3....
+ * where n1 and n2 are the video frame number...
+ * [n2] can also be []
+ */
+ char *s;
+
+ char buffer_text[MAX_LINE + 1];
+ int i_start;
+ int i_stop;
+ unsigned int i;
+
+ p_subtitle->i_start = 0;
+ p_subtitle->i_stop = 0;
+ p_subtitle->psz_text = NULL;
+
+ for( ;; )
+ {
+ if( ( s = TextGetLine( txt ) ) == NULL )
+ {
+ return( VLC_EGENERIC );
+ }
+ i_start = 0;
+ i_stop = 0;
+
+ memset( buffer_text, '\0', MAX_LINE );
+ if( sscanf( s, "[%d][]%[^\r\n]", &i_start, buffer_text ) == 2 ||
+ sscanf( s, "[%d][%d]%[^\r\n]", &i_start, &i_stop, buffer_text ) == 3)
+ {
+ break;
+ }
+ }
+
+ /* replace | by \n */
+ for( i = 0; i < strlen( buffer_text ); i++ )
+ {
+ if( buffer_text[i] == '|' )
+ {
+ buffer_text[i] = '\n';
+ }
+ }
+ p_subtitle->i_start = (int64_t)i_start * 100000;
+ p_subtitle->i_stop = (int64_t)i_stop * 100000;
+ p_subtitle->psz_text = strndup( buffer_text, MAX_LINE );
+ return( 0 );
+}