/*****************************************************************************
- * subtitle.c: Demux for text and vobsub files.
+ * subtitle.c: Demux for subtitle text files.
*****************************************************************************
- * Copyright (C) 1999-2004 VideoLAN
+ * Copyright (C) 1999-2007 the VideoLAN team
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <stdlib.h>
-
-#include <errno.h>
-#include <sys/types.h>
-#include <ctype.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
#include <vlc/vlc.h>
-#include <vlc/input.h>
-#include "vlc_video.h"
+#include <vlc_input.h>
-#include "ps.h"
-#if (!defined( WIN32 ) || defined(__MINGW32__))
-# include <dirent.h>
+#include <errno.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
#endif
+#include <ctype.h>
+
+#include <vlc_demux.h>
+#include <vlc_charset.h>
/*****************************************************************************
* Module descriptor
static void Close( vlc_object_t *p_this );
#define SUB_DELAY_LONGTEXT \
- "Delay subtitles (in 1/10s)"
+ N_("Apply a delay to all subtitles (in 1/10s, eg 100 means 10s).")
#define SUB_FPS_LONGTEXT \
- "Override frames per second. " \
- "It will only work with MicroDVD subtitles."
+ N_("Override the normal frames per second settings. " \
+ "This will only work with MicroDVD and SubRIP (SRT) subtitles.")
#define SUB_TYPE_LONGTEXT \
- "One from \"microdvd\", \"subrip\", \"ssa1\", \"ssa2-4\", \"vplayer\" " \
- "\"sami\" (auto for autodetection, it should always work)."
-static char *ppsz_sub_type[] =
+ N_("Force the subtiles format. Valid values are : \"microdvd\", " \
+ "\"subrip\", \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\" " \
+ "\"sami\", \"dvdsubtitle\", \"mpl2\" and \"auto\" (meaning autodetection, this " \
+ "should always work).")
+static const char *ppsz_sub_type[] =
{
"auto", "microdvd", "subrip", "subviewer", "ssa1",
- "ssa2-4", "vplayer", "sami", "vobsub"
+ "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2"
};
vlc_module_begin();
- set_description( _("Text subtitles demux") );
+ set_shortname( _("Subtitles"));
+ set_description( _("Text subtitles parser") );
set_capability( "demux2", 0 );
+ set_category( CAT_INPUT );
+ set_subcategory( SUBCAT_INPUT_DEMUX );
add_float( "sub-fps", 0.0, NULL,
N_("Frames per second"),
SUB_FPS_LONGTEXT, VLC_TRUE );
- add_string( "sub-type", "auto", NULL, "Subtitles fileformat",
+ add_integer( "sub-delay", 0, NULL,
+ N_("Subtitles delay"),
+ SUB_DELAY_LONGTEXT, VLC_TRUE );
+ add_string( "sub-type", "auto", NULL, N_("Subtitles format"),
SUB_TYPE_LONGTEXT, VLC_TRUE );
- change_string_list( ppsz_sub_type, 0, 0 );
+ change_string_list( ppsz_sub_type, NULL, NULL );
set_callbacks( Open, Close );
add_shortcut( "subtitle" );
- add_shortcut( "vobsub" );
vlc_module_end();
/*****************************************************************************
SUB_TYPE_SUBRIP,
SUB_TYPE_SSA1,
SUB_TYPE_SSA2_4,
+ SUB_TYPE_ASS,
SUB_TYPE_VPLAYER,
SUB_TYPE_SAMI,
SUB_TYPE_SUBVIEWER,
- SUB_TYPE_VOBSUB,
+ SUB_TYPE_DVDSUBTITLE,
+ SUB_TYPE_MPL2
};
typedef struct
typedef struct
{
- mtime_t i_start;
- mtime_t i_stop;
+ int64_t i_start;
+ int64_t i_stop;
char *psz_text;
- int i_vobsub_location;
} subtitle_t;
es_out_id_t *es;
int64_t i_next_demux_date;
-
int64_t i_microsecperframe;
char *psz_header;
int i_subtitle;
int i_subtitles;
subtitle_t *subtitle;
- FILE *p_vobsub_file;
- mtime_t i_original_mspf;
int64_t i_length;
};
-static int ParseMicroDvd ( demux_t *, subtitle_t * );
-static int ParseSubRip ( demux_t *, subtitle_t * );
-static int ParseSubViewer( demux_t *, subtitle_t * );
-static int ParseSSA ( demux_t *, subtitle_t * );
-static int ParseVplayer ( demux_t *, subtitle_t * );
-static int ParseSami ( demux_t *, subtitle_t * );
-static int ParseVobSubIDX( demux_t *, subtitle_t * );
-
-static int DemuxVobSub( demux_t *, block_t * );
+static int ParseMicroDvd ( demux_t *, subtitle_t * );
+static int ParseSubRip ( demux_t *, subtitle_t * );
+static int ParseSubViewer ( demux_t *, subtitle_t * );
+static int ParseSSA ( demux_t *, subtitle_t * );
+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
{
- char *psz_type_name;
+ const char *psz_type_name;
int i_type;
- char *psz_name;
+ const char *psz_name;
int (*pf_read)( demux_t *, subtitle_t* );
} sub_read_subtitle_function [] =
{
- { "microdvd", SUB_TYPE_MICRODVD, "MicroDVD", ParseMicroDvd },
- { "subrip", SUB_TYPE_SUBRIP, "SubRIP", ParseSubRip },
- { "subviewer", SUB_TYPE_SUBVIEWER, "SubViewer",ParseSubViewer },
- { "ssa1", SUB_TYPE_SSA1, "SSA-1", ParseSSA },
- { "ssa2-4", SUB_TYPE_SSA2_4, "SSA-2/3/4",ParseSSA },
- { "vplayer", SUB_TYPE_VPLAYER, "VPlayer", ParseVplayer },
- { "sami", SUB_TYPE_SAMI, "SAMI", ParseSami },
- { "vobsub", SUB_TYPE_VOBSUB, "VobSub", ParseVobSubIDX },
- { NULL, SUB_TYPE_UNKNOWN, "Unknown", NULL }
+ { "microdvd", SUB_TYPE_MICRODVD, "MicroDVD", ParseMicroDvd },
+ { "subrip", SUB_TYPE_SUBRIP, "SubRIP", ParseSubRip },
+ { "subviewer", SUB_TYPE_SUBVIEWER, "SubViewer", ParseSubViewer },
+ { "ssa1", SUB_TYPE_SSA1, "SSA-1", ParseSSA },
+ { "ssa2-4", SUB_TYPE_SSA2_4, "SSA-2/3/4", ParseSSA },
+ { "ass", SUB_TYPE_ASS, "SSA/ASS", ParseSSA },
+ { "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 }
};
static int Demux( demux_t * );
static int Control( demux_t *, int, va_list );
-static void Fix( demux_t * );
-
-#define DVD_VIDEO_LB_LEN 2048
+/*static void Fix( demux_t * );*/
/*****************************************************************************
* Module initializer
*****************************************************************************/
static int Open ( vlc_object_t *p_this )
{
- demux_t *p_demux = (demux_t*)p_this;
- demux_sys_t *p_sys;
- es_format_t fmt;
- float f_fps;
- char *psz_type;
+ demux_t *p_demux = (demux_t*)p_this;
+ demux_sys_t *p_sys;
+ es_format_t fmt;
+ float f_fps;
+ char *psz_type;
int (*pf_read)( demux_t *, subtitle_t* );
- int i, i_max;
+ int i, i_max;
- if( strcmp( p_demux->psz_demux, "subtitle" ) &&
- strcmp( p_demux->psz_demux, "vobsub" ) )
+ if( !p_demux->b_force )
{
msg_Dbg( p_demux, "subtitle demux discarded" );
return VLC_EGENERIC;
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
- p_sys->psz_header = NULL;
- p_sys->i_subtitle = 0;
- p_sys->i_subtitles= 0;
- p_sys->subtitle = NULL;
- p_sys->p_vobsub_file = NULL;
- p_sys->i_original_mspf = 0;
-
+ p_sys->psz_header = NULL;
+ p_sys->i_subtitle = 0;
+ p_sys->i_subtitles = 0;
+ p_sys->subtitle = NULL;
+ p_sys->i_microsecperframe = 40000;
/* Get the FPS */
- p_sys->i_microsecperframe = 40000; /* default to 25 fps */
+ f_fps = var_CreateGetFloat( p_demux, "sub-original-fps" );
+ if( f_fps >= 1.0 )
+ p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
+
+ msg_Dbg( p_demux, "Movie fps: %f", f_fps );
+
+ /* Check for override of the fps */
f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
if( f_fps >= 1.0 )
{
- p_sys->i_microsecperframe = (mtime_t)( (float)1000000 / f_fps );
+ 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_SUBRIP;
break;
}
- else if( sscanf( s,
- "!: This is a Sub Station Alpha v%d.x script.",
- &i_dummy ) == 1)
+ else if( !strncasecmp( s, "!: This is a Sub Station Alpha v1", 33 ) )
{
- if( i_dummy <= 1 )
- {
- p_sys->i_type = SUB_TYPE_SSA1;
- }
- else
- {
- p_sys->i_type = SUB_TYPE_SSA2_4; /* I hope this will work */
- }
+ p_sys->i_type = SUB_TYPE_SSA1;
break;
}
- else if( strcasestr( s, "This is a Sub Station Alpha v4 script" ) )
+ else if( !strncasecmp( s, "ScriptType: v4.00+", 18 ) )
{
- p_sys->i_type = SUB_TYPE_SSA2_4; /* I hope this will work */
+ p_sys->i_type = SUB_TYPE_ASS;
+ break;
+ }
+ else if( !strncasecmp( s, "ScriptType: v4.00", 17 ) )
+ {
+ p_sys->i_type = SUB_TYPE_SSA2_4;
break;
}
else if( !strncasecmp( s, "Dialogue: Marked", 16 ) )
{
- p_sys->i_type = SUB_TYPE_SSA2_4; /* could be wrong */
+ p_sys->i_type = SUB_TYPE_SSA2_4;
+ break;
+ }
+ else if( !strncasecmp( s, "Dialogue:", 9 ) )
+ {
+ p_sys->i_type = SUB_TYPE_ASS;
break;
}
else if( strcasestr( s, "[INFORMATION]" ) )
p_sys->i_type = SUB_TYPE_VPLAYER;
break;
}
- else if( strcasestr( s, "# VobSub index file" ) )
+ else if( sscanf( s, "{T %d:%d:%d:%d", &i_dummy, &i_dummy,
+ &i_dummy, &i_dummy ) == 4 )
{
- p_sys->i_type = SUB_TYPE_VOBSUB;
+ 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;
}
if( s ) free( s );
/* It will nearly always work even for non seekable stream thanks the
- * caching system, and if it fails we loose just a few sub */
+ * caching system, and if it fails we lose just a few sub */
if( stream_Seek( p_demux->s, 0 ) )
{
msg_Warn( p_demux, "failed to rewind" );
if( p_sys->i_type == SUB_TYPE_UNKNOWN )
{
msg_Err( p_demux, "failed to recognize subtitle type" );
+ free( p_sys );
return VLC_EGENERIC;
}
sizeof(subtitle_t) * i_max ) ) )
{
msg_Err( p_demux, "out of memory");
+ if( p_sys->subtitle != NULL )
+ free( p_sys->subtitle );
+ TextUnload( &p_sys->txt );
+ free( p_sys );
return VLC_ENOMEM;
}
}
/* Fix subtitle (order and time) *** */
p_sys->i_subtitle = 0;
- if( p_sys->i_type != SUB_TYPE_VOBSUB )
- {
- Fix( p_demux );
- }
p_sys->i_length = 0;
if( p_sys->i_subtitles > 0 )
{
}
/* *** add subtitle ES *** */
- if( p_sys->i_type == SUB_TYPE_VOBSUB )
- {
- int i_len = strlen( p_demux->psz_path );
- char *psz_vobname = strdup( p_demux->psz_path );
-
- strcpy( psz_vobname + i_len - 4, ".sub" );
-
- /* open file */
- if( !( p_sys->p_vobsub_file = fopen( psz_vobname, "rb" ) ) )
- {
- msg_Err( p_demux, "couldn't open .sub Vobsub file: %s",
- psz_vobname );
- }
- free( psz_vobname );
-
- es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) );
- }
- else if( p_sys->i_type == SUB_TYPE_SSA1 ||
- p_sys->i_type == SUB_TYPE_SSA2_4 )
+ if( p_sys->i_type == SUB_TYPE_SSA1 ||
+ p_sys->i_type == SUB_TYPE_SSA2_4 ||
+ p_sys->i_type == SUB_TYPE_ASS )
{
es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','s','a',' ' ) );
}
if( p_sys->subtitle )
free( p_sys->subtitle );
- if( p_sys->p_vobsub_file )
- fclose( p_sys->p_vobsub_file );
-
free( p_sys );
}
case DEMUX_GET_FPS:
case DEMUX_GET_META:
+ case DEMUX_GET_ATTACHMENTS:
case DEMUX_GET_TITLE_INFO:
+ case DEMUX_HAS_UNSUPPORTED_META:
return VLC_EGENERIC;
default:
- msg_Err( p_demux, "unknown query in subtitle control" );
+ msg_Err( p_demux, "unknown query %d in subtitle control", i_query );
return VLC_EGENERIC;
}
}
if( p_sys->i_subtitle >= p_sys->i_subtitles )
return 0;
- i_maxdate = p_sys->i_next_demux_date;
+ i_maxdate = p_sys->i_next_demux_date - var_GetTime( p_demux->p_parent, "spu-delay" );;
if( i_maxdate <= 0 && p_sys->i_subtitle < p_sys->i_subtitles )
{
/* Should not happen */
i_maxdate = p_sys->subtitle[p_sys->i_subtitle].i_start + 1;
}
- if( p_sys->i_type != SUB_TYPE_VOBSUB )
+ while( p_sys->i_subtitle < p_sys->i_subtitles &&
+ p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
{
- while( p_sys->i_subtitle < p_sys->i_subtitles &&
- p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
- {
- block_t *p_block;
- int i_len = strlen( p_sys->subtitle[p_sys->i_subtitle].psz_text ) + 1;
-
- if( i_len <= 1 )
- {
- /* empty subtitle */
- p_sys->i_subtitle++;
- continue;
- }
-
- if( ( p_block = block_New( p_demux, i_len ) ) == NULL )
- {
- p_sys->i_subtitle++;
- continue;
- }
+ block_t *p_block;
+ int i_len = strlen( p_sys->subtitle[p_sys->i_subtitle].psz_text ) + 1;
- if( p_sys->subtitle[p_sys->i_subtitle].i_start < 0 )
- {
- p_sys->i_subtitle++;
- continue;
- }
-
- p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
- p_block->i_dts = p_block->i_pts;
- if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )
- {
- p_block->i_length =
- p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;
- }
-
- memcpy( p_block->p_buffer,
- p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );
- if( p_block->i_pts > 0 )
- {
- es_out_Send( p_demux->out, p_sys->es, p_block );
- }
- else
- {
- block_Release( p_block );
- }
+ if( i_len <= 1 )
+ {
+ /* empty subtitle */
p_sys->i_subtitle++;
+ continue;
}
- }
- else
- {
- while( p_sys->i_subtitle < p_sys->i_subtitles &&
- p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
- {
- int i_pos = p_sys->subtitle[p_sys->i_subtitle].i_vobsub_location;
- block_t *p_block;
- int i_size = 0;
-
- /* first compute SPU size */
- if( p_sys->i_subtitle + 1 < p_sys->i_subtitles )
- {
- i_size = p_sys->subtitle[p_sys->i_subtitle+1].i_vobsub_location - i_pos;
- }
- if( i_size <= 0 ) i_size = 65535; /* Invalid or EOF */
-
- /* Seek at the right place */
- if( fseek( p_sys->p_vobsub_file, i_pos, SEEK_SET ) )
- {
- msg_Warn( p_demux,
- "cannot seek at right vobsub location %d", i_pos );
- p_sys->i_subtitle++;
- continue;
- }
- /* allocate a packet */
- if( ( p_block = block_New( p_demux, i_size ) ) == NULL )
- {
- p_sys->i_subtitle++;
- continue;
- }
-
- /* read data */
- p_block->i_buffer = fread( p_block->p_buffer, 1, i_size,
- p_sys->p_vobsub_file );
- if( p_block->i_buffer <= 6 )
- {
- block_Release( p_block );
- p_sys->i_subtitle++;
- continue;
- }
+ if( ( p_block = block_New( p_demux, i_len ) ) == NULL )
+ {
+ p_sys->i_subtitle++;
+ continue;
+ }
- /* pts */
- p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
+ if( p_sys->subtitle[p_sys->i_subtitle].i_start < 0 )
+ {
+ p_sys->i_subtitle++;
+ continue;
+ }
- /* demux this block */
- DemuxVobSub( p_demux, p_block );
+ p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
+ p_block->i_dts = p_block->i_pts;
+ if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )
+ {
+ p_block->i_length =
+ p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;
+ }
- p_sys->i_subtitle++;
+ memcpy( p_block->p_buffer,
+ p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );
+ if( p_block->i_pts > 0 )
+ {
+ es_out_Send( p_demux->out, p_sys->es, p_block );
+ }
+ else
+ {
+ block_Release( p_block );
}
+ p_sys->i_subtitle++;
}
/* */
/*****************************************************************************
* Fix: fix time stamp and order of subtitle
*****************************************************************************/
+#ifdef USE_THIS_UNUSED_PIECE_OF_CODE
static void Fix( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
}
} while( !b_done );
}
+#endif
static int TextLoad( text_t *txt, stream_t *s )
{
if( txt->i_line_count >= i_line_max )
{
i_line_max += 100;
- txt->line = realloc( txt->line, i_line_max * sizeof( char*) );
+ txt->line = realloc( txt->line, i_line_max * sizeof( char * ) );
}
}
/*****************************************************************************
* Specific Subtitle function
*****************************************************************************/
-#define MAX_LINE 8192
+/* ParseMicroDvd:
+ * Format:
+ * {n1}{n2}Line1|Line2|Line3....
+ * where n1 and n2 are the video frame number (n2 can be empty)
+ */
static int ParseMicroDvd( 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...
- *
- */
- char *s;
-
- char buffer_text[MAX_LINE + 1];
- unsigned int i_start;
- unsigned int i_stop;
- unsigned int i;
-
- p_subtitle->i_start = 0;
- p_subtitle->i_stop = 0;
- p_subtitle->i_vobsub_location = 0;
- p_subtitle->psz_text = NULL;
+ char *psz_text;
+ int i_start;
+ int i_stop;
+ int i;
for( ;; )
{
- if( ( s = TextGetLine( txt ) ) == NULL )
- {
- return( VLC_EGENERIC );
- }
+ const char *s = TextGetLine( txt );
+ if( !s )
+ return VLC_EGENERIC;
+
+ psz_text = malloc( strlen(s) + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
+
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)
+ if( sscanf( s, "{%d}{}%[^\r\n]", &i_start, psz_text ) == 2 ||
+ sscanf( s, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
{
- break;
+ float f_fps;
+ if( i_start != 1 || i_stop != 1 )
+ break;
+
+ /* We found a possible setting of the framerate "{1}{1}23.976" */
+ /* Check if it's usable, and if the sub-fps is not set */
+ f_fps = us_strtod( psz_text, NULL );
+ if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
+ p_sys->i_microsecperframe = (int64_t)((float)1000000 / f_fps);
}
+ free( psz_text );
}
+
/* replace | by \n */
- for( i = 0; i < strlen( buffer_text ); i++ )
+ for( i = 0; psz_text[i] != '\0'; i++ )
{
- if( buffer_text[i] == '|' )
- {
- buffer_text[i] = '\n';
- }
+ if( psz_text[i] == '|' )
+ psz_text[i] = '\n';
}
- p_subtitle->i_start = (mtime_t)i_start * p_sys->i_microsecperframe;
- p_subtitle->i_stop = (mtime_t)i_stop * p_sys->i_microsecperframe;
- p_subtitle->psz_text = strndup( buffer_text, MAX_LINE );
- return( 0 );
+ /* */
+ p_subtitle->i_start = i_start * p_sys->i_microsecperframe;
+ p_subtitle->i_stop = i_stop * p_sys->i_microsecperframe;
+ p_subtitle->psz_text = psz_text;
+ return VLC_SUCCESS;
}
-static int ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle )
+/* ParseSubRipSubViewer
+ * Format SubRip
+ * n
+ * h1:m1:s1,d1 --> h2:m2:s2,d2
+ * Line1
+ * Line2
+ * ....
+ * [Empty line]
+ * Format SubViewer v1/v2
+ * h1:m1:s1.d1,h2:m2:s2.d2
+ * Line1[br]Line2
+ * Line3
+ * ...
+ * [empty line]
+ * We ignore line number for SubRip
+ */
+static int ParseSubRipSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
+ const char *psz_fmt,
+ vlc_bool_t b_replace_br )
{
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
-
- /*
- * n
- * h1:m1:s1,d1 --> h2:m2:s2,d2
- * Line1
- * Line2
- * ...
- * [empty line]
- *
- */
- char *s;
- char buffer_text[ 10 * MAX_LINE];
- int i_buffer_text;
- mtime_t i_start;
- mtime_t i_stop;
-
- p_subtitle->i_start = 0;
- p_subtitle->i_stop = 0;
- p_subtitle->i_vobsub_location = 0;
- p_subtitle->psz_text = NULL;
+ char *psz_text;
for( ;; )
{
+ const char *s = TextGetLine( txt );
int h1, m1, s1, d1, h2, m2, s2, d2;
- if( ( s = TextGetLine( txt ) ) == NULL )
- {
- return( VLC_EGENERIC );
- }
- if( sscanf( s,
- "%d:%d:%d,%d --> %d:%d:%d,%d",
+
+ if( !s )
+ return VLC_EGENERIC;
+
+ if( sscanf( s, psz_fmt,
&h1, &m1, &s1, &d1,
&h2, &m2, &s2, &d2 ) == 8 )
{
- i_start = ( (mtime_t)h1 * 3600*1000 +
- (mtime_t)m1 * 60*1000 +
- (mtime_t)s1 * 1000 +
- (mtime_t)d1 ) * 1000;
-
- i_stop = ( (mtime_t)h2 * 3600*1000 +
- (mtime_t)m2 * 60*1000 +
- (mtime_t)s2 * 1000 +
- (mtime_t)d2 ) * 1000;
-
- /* Now read text until an empty line */
- for( i_buffer_text = 0;; )
- {
- int i_len;
- if( ( s = TextGetLine( txt ) ) == NULL )
- {
- return( VLC_EGENERIC );
- }
-
- i_len = strlen( s );
- if( i_len <= 0 )
- {
- /* empty line -> end of this subtitle */
- buffer_text[__MAX( i_buffer_text - 1, 0 )] = '\0';
- p_subtitle->i_start = i_start;
- p_subtitle->i_stop = i_stop;
- p_subtitle->psz_text = strdup( buffer_text );
- /* If framerate is available, use sub-fps */
- if( p_sys->i_microsecperframe != 0 &&
- p_sys->i_original_mspf != 0)
- {
- p_subtitle->i_start = (mtime_t)i_start *
- p_sys->i_original_mspf /
- p_sys->i_microsecperframe;
- p_subtitle->i_stop = (mtime_t)i_stop *
- p_sys->i_original_mspf /
- p_sys->i_microsecperframe;
- }
- return 0;
- }
- else
- {
- if( i_buffer_text + i_len + 1 < 10 * MAX_LINE )
- {
- memcpy( buffer_text + i_buffer_text,
- s,
- i_len );
- i_buffer_text += i_len;
-
- buffer_text[i_buffer_text] = '\n';
- i_buffer_text++;
- }
- }
- }
+ p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
+ (int64_t)m1 * 60*1000 +
+ (int64_t)s1 * 1000 +
+ (int64_t)d1 ) * 1000;
+
+ p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
+ (int64_t)m2 * 60*1000 +
+ (int64_t)s2 * 1000 +
+ (int64_t)d2 ) * 1000;
+ break;
}
}
-}
-
-static int ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle )
-{
- demux_sys_t *p_sys = p_demux->p_sys;
- text_t *txt = &p_sys->txt;
-
- /*
- * h1:m1:s1.d1,h2:m2:s2.d2
- * Line1[br]Line2
- * Line3
- * ...
- * [empty line]
- * ( works with subviewer and subviewer v2 )
- */
- char *s;
- char buffer_text[ 10 * MAX_LINE];
- int i_buffer_text;
- mtime_t i_start;
- mtime_t i_stop;
-
- p_subtitle->i_start = 0;
- p_subtitle->i_stop = 0;
- p_subtitle->i_vobsub_location = 0;
- p_subtitle->psz_text = NULL;
+ /* Now read text until an empty line */
+ psz_text = strdup("");
+ if( !psz_text )
+ return VLC_ENOMEM;
for( ;; )
{
- int h1, m1, s1, d1, h2, m2, s2, d2;
- if( ( s = TextGetLine( txt ) ) == NULL )
+ const char *s = TextGetLine( txt );
+ int i_len;
+ int i_old;
+
+ if( !s )
{
- return( VLC_EGENERIC );
+ free( psz_text );
+ return VLC_EGENERIC;
}
- if( sscanf( s,
- "%d:%d:%d.%d,%d:%d:%d.%d",
- &h1, &m1, &s1, &d1,
- &h2, &m2, &s2, &d2 ) == 8 )
+
+ i_len = strlen( s );
+ if( i_len <= 0 )
{
- i_start = ( (mtime_t)h1 * 3600*1000 +
- (mtime_t)m1 * 60*1000 +
- (mtime_t)s1 * 1000 +
- (mtime_t)d1 ) * 1000;
-
- i_stop = ( (mtime_t)h2 * 3600*1000 +
- (mtime_t)m2 * 60*1000 +
- (mtime_t)s2 * 1000 +
- (mtime_t)d2 ) * 1000;
-
- /* Now read text until an empty line */
- for( i_buffer_text = 0;; )
+ p_subtitle->psz_text = psz_text;
+ return VLC_SUCCESS;
+ }
+
+ i_old = strlen( psz_text );
+ psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
+ strcat( psz_text, s );
+ strcat( psz_text, "\n" );
+
+ /* replace [br] by \n */
+ if( b_replace_br )
+ {
+ char *p;
+
+ while( ( p = strstr( psz_text, "[br]" ) ) )
{
- int i_len, i;
- if( ( s = TextGetLine( txt ) ) == NULL )
- {
- return( VLC_EGENERIC );
- }
-
- i_len = strlen( s );
- if( i_len <= 0 )
- {
- /* empty line -> end of this subtitle */
- buffer_text[__MAX( i_buffer_text - 1, 0 )] = '\0';
- p_subtitle->i_start = i_start;
- p_subtitle->i_stop = i_stop;
-
- /* replace [br] by \n */
- for( i = 0; i < i_buffer_text - 3; i++ )
- {
- if( buffer_text[i] == '[' && buffer_text[i+1] == 'b' &&
- buffer_text[i+2] == 'r' && buffer_text[i+3] == ']' )
- {
- char *temp = buffer_text + i + 1;
- buffer_text[i] = '\n';
- memmove( temp, temp+3, strlen( temp ) -3 );
- temp[strlen( temp )-3] = '\0';
- }
- }
- p_subtitle->psz_text = strdup( buffer_text );
- return( 0 );
- }
- else
- {
- if( i_buffer_text + i_len + 1 < 10 * MAX_LINE )
- {
- memcpy( buffer_text + i_buffer_text,
- s,
- i_len );
- i_buffer_text += i_len;
-
- buffer_text[i_buffer_text] = '\n';
- i_buffer_text++;
- }
- }
+ *p++ = '\n';
+ memmove( p, &p[3], strlen(&p[3])+1 );
}
}
}
}
+/* ParseSubRip
+ */
+static int ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle )
+{
+ return ParseSubRipSubViewer( p_demux, p_subtitle,
+ "%d:%d:%d,%d --> %d:%d:%d,%d",
+ VLC_FALSE );
+}
+/* ParseSubViewer
+ */
+static int ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle )
+{
+ return ParseSubRipSubViewer( p_demux, p_subtitle,
+ "%d:%d:%d.%d,%d:%d:%d.%d",
+ VLC_TRUE );
+}
-
+/* ParseSSA
+ */
static int ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle )
{
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
- char buffer_text[ 10 * MAX_LINE];
- char *s;
- mtime_t i_start;
- mtime_t i_stop;
-
- p_subtitle->i_start = 0;
- p_subtitle->i_stop = 0;
- p_subtitle->i_vobsub_location = 0;
- p_subtitle->psz_text = NULL;
-
for( ;; )
{
+ const char *s = TextGetLine( txt );
int h1, m1, s1, c1, h2, m2, s2, c2;
- int i_dummy;
+ char *psz_text;
- if( ( s = TextGetLine( txt ) ) == NULL )
- {
- return( VLC_EGENERIC );
- }
- p_subtitle->psz_text = malloc( strlen( s ) );
+ if( !s )
+ return VLC_EGENERIC;
+
+ /* We expect (SSA2-4):
+ * Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
+ * Dialogue: Marked=0,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
+ *
+ * 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.
+ */
+
+ /* For ASS:
+ * Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
+ * Dialogue: Layer#,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
+ */
+ psz_text = malloc( 2 + strlen( s ) + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
if( sscanf( s,
- "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d%[^\r\n]",
- &i_dummy,
+ "Dialogue: %*[^,],%d:%d:%d.%d,%d:%d:%d.%d,%[^\r\n]",
&h1, &m1, &s1, &c1,
&h2, &m2, &s2, &c2,
- buffer_text ) == 10 )
+ psz_text ) == 9 )
{
- i_start = ( (mtime_t)h1 * 3600*1000 +
- (mtime_t)m1 * 60*1000 +
- (mtime_t)s1 * 1000 +
- (mtime_t)c1 * 10 ) * 1000;
-
- i_stop = ( (mtime_t)h2 * 3600*1000 +
- (mtime_t)m2 * 60*1000 +
- (mtime_t)s2 * 1000 +
- (mtime_t)c2 * 10 ) * 1000;
-
/* The dec expects: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */
+ /* (Layer comes from ASS specs ... it's empty for SSA.) */
if( p_sys->i_type == SUB_TYPE_SSA1 )
{
- sprintf( p_subtitle->psz_text,
- ",%d%s", i_dummy, strdup( buffer_text) );
- }
- else
- {
- sprintf( p_subtitle->psz_text,
- ",%d,%s", i_dummy, strdup( buffer_text) );
- }
- p_subtitle->i_start = i_start;
- p_subtitle->i_stop = i_stop;
- return 0;
- }
- else
- {
- /* All the other stuff we add to the header field */
- if( p_sys->psz_header != NULL )
- {
- if( !( p_sys->psz_header = realloc( p_sys->psz_header,
- strlen( p_sys->psz_header ) + strlen( s ) + 2 ) ) )
- {
- msg_Err( p_demux, "out of memory");
- return VLC_ENOMEM;
- }
- p_sys->psz_header = strcat( p_sys->psz_header, strdup( s ) );
- p_sys->psz_header = strcat( p_sys->psz_header, "\n" );
+ /* SSA1 has only 8 commas before the text starts, not 9 */
+ memmove( &psz_text[1], psz_text, strlen(psz_text)+1 );
+ psz_text[0] = ',';
}
else
{
- if( !( p_sys->psz_header = malloc( strlen( s ) + 2 ) ) )
- {
- msg_Err( p_demux, "out of memory");
- return VLC_ENOMEM;
- }
- p_sys->psz_header = strdup( s );
- p_sys->psz_header = strcat( p_sys->psz_header, "\n" );
+ /* ReadOrder, Layer, %s(rest of fields) */
+ memmove( &psz_text[2], psz_text, strlen(psz_text)+1 );
+ psz_text[0] = ',';
+ psz_text[1] = ',';
}
+
+ p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
+ (int64_t)m1 * 60*1000 +
+ (int64_t)s1 * 1000 +
+ (int64_t)c1 * 10 ) * 1000;
+ p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
+ (int64_t)m2 * 60*1000 +
+ (int64_t)s2 * 1000 +
+ (int64_t)c2 * 10 ) * 1000;
+ p_subtitle->psz_text = psz_text;
+ return VLC_SUCCESS;
}
+ free( psz_text );
+
+ /* All the other stuff we add to the header field */
+ if( !p_sys->psz_header )
+ p_sys->psz_header = strdup( "" );
+ if( !p_sys->psz_header )
+ return VLC_ENOMEM;
+
+ p_sys->psz_header =
+ realloc( p_sys->psz_header,
+ strlen( p_sys->psz_header ) + strlen( s ) + 2 );
+ strcat( p_sys->psz_header, s );
+ strcat( p_sys->psz_header, "\n" );
}
}
+/* ParseVplayer
+ * Format
+ * h:m:s:Line1|Line2|Line3....
+ * or
+ * h:m:s Line1|Line2|Line3....
+ */
static int ParseVplayer( 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:
- * h:m:s:Line1|Line2|Line3....
- * or
- * h:m:s Line1|Line2|Line3....
- *
- */
- char *p;
- char buffer_text[MAX_LINE + 1];
- mtime_t i_start;
- unsigned int i;
-
- p_subtitle->i_start = 0;
- p_subtitle->i_stop = 0;
- p_subtitle->i_vobsub_location = 0;
- p_subtitle->psz_text = NULL;
+ char *psz_text;
+ int i;
for( ;; )
{
- int h, m, s;
- char c;
+ const char *s = TextGetLine( txt );
+ int h1, m1, s1;
- if( ( p = TextGetLine( txt ) ) == NULL )
- {
- return( VLC_EGENERIC );
- }
+ if( !s )
+ return VLC_EGENERIC;
- i_start = 0;
+ psz_text = malloc( strlen( s ) + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
- memset( buffer_text, '\0', MAX_LINE );
- if( sscanf( p, "%d:%d:%d%[ :]%[^\r\n]", &h, &m, &s, &c, buffer_text ) == 5 )
+ if( sscanf( s, "%d:%d:%d%*c%[^\r\n]",
+ &h1, &m1, &s1, psz_text ) == 4 )
{
- i_start = ( (mtime_t)h * 3600*1000 +
- (mtime_t)m * 60*1000 +
- (mtime_t)s * 1000 ) * 1000;
+ p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
+ (int64_t)m1 * 60*1000 +
+ (int64_t)s1 * 1000 ) * 1000;
+ p_subtitle->i_stop = 0;
break;
}
+ free( psz_text );
}
/* replace | by \n */
- for( i = 0; i < strlen( buffer_text ); i++ )
+ for( i = 0; psz_text[i] != '\0'; i++ )
{
- if( buffer_text[i] == '|' )
- {
- buffer_text[i] = '\n';
- }
+ if( psz_text[i] == '|' )
+ psz_text[i] = '\n';
}
- p_subtitle->i_start = i_start;
-
- p_subtitle->i_stop = 0;
- p_subtitle->psz_text = strndup( buffer_text, MAX_LINE );
- return( 0 );
+ p_subtitle->psz_text = psz_text;
+ return VLC_SUCCESS;
}
-static char *ParseSamiSearch( text_t *txt, char *psz_start, char *psz_str )
+/* ParseSami
+ */
+static char *ParseSamiSearch( text_t *txt,
+ char *psz_start, const char *psz_str )
{
- if( psz_start )
+ if( psz_start && strcasestr( psz_start, psz_str ) )
{
- if( strcasestr( psz_start, psz_str ) )
- {
- char *s = strcasestr( psz_start, psz_str );
-
- s += strlen( psz_str );
-
- return( s );
- }
+ char *s = strcasestr( psz_start, psz_str );
+ return &s[strlen( psz_str )];
}
+
for( ;; )
{
- char *p;
- if( ( p = TextGetLine( txt ) ) == NULL )
- {
+ char *p = TextGetLine( txt );
+ if( !p )
return NULL;
- }
+
if( strcasestr( p, psz_str ) )
{
char *s = strcasestr( p, psz_str );
-
- s += strlen( psz_str );
-
- return( s);
+ return &s[strlen( psz_str )];
}
}
}
-
static int ParseSami( demux_t *p_demux, subtitle_t *p_subtitle )
{
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
- char *p;
- int i_start;
-
- int i_text;
- char buffer_text[10*MAX_LINE + 1];
+ char *s;
+ int64_t i_start;
- p_subtitle->i_start = 0;
- p_subtitle->i_stop = 0;
- p_subtitle->i_vobsub_location = 0;
- p_subtitle->psz_text = NULL;
-
-#define ADDC( c ) \
- if( i_text < 10*MAX_LINE ) \
- { \
- buffer_text[i_text++] = c; \
- buffer_text[i_text] = '\0'; \
- }
+ unsigned int i_text;
+ char text[8192]; /* Arbitrary but should be long enough */
/* search "Start=" */
- if( !( p = ParseSamiSearch( txt, NULL, "Start=" ) ) )
- {
+ if( !( s = ParseSamiSearch( txt, NULL, "Start=" ) ) )
return VLC_EGENERIC;
- }
/* get start value */
- i_start = strtol( p, &p, 0 );
+ i_start = strtol( s, &s, 0 );
/* search <P */
- if( !( p = ParseSamiSearch( txt, p, "<P" ) ) )
- {
+ if( !( s = ParseSamiSearch( txt, s, "<P" ) ) )
return VLC_EGENERIC;
- }
+
/* search > */
- if( !( p = ParseSamiSearch( txt, p, ">" ) ) )
- {
+ if( !( s = ParseSamiSearch( txt, s, ">" ) ) )
return VLC_EGENERIC;
- }
i_text = 0;
- buffer_text[0] = '\0';
+ text[0] = '\0';
/* now get all txt until a "Start=" line */
for( ;; )
{
- if( *p )
+ char c = '\0';
+ /* Search non empty line */
+ while( s && *s == '\0' )
+ s = TextGetLine( txt );
+ if( !s )
+ break;
+
+ if( *s == '<' )
{
- if( *p == '<' )
- {
- if( !strncasecmp( p, "<br", 3 ) )
- {
- ADDC( '\n' );
- }
- else if( strcasestr( p, "Start=" ) )
- {
- TextPreviousLine( txt );
- break;
- }
- p = ParseSamiSearch( txt, p, ">" );
- }
- else if( !strncmp( p, " ", 6 ) )
- {
- ADDC( ' ' );
- p += 6;
- }
- else if( *p == '\t' )
+ if( !strncasecmp( s, "<br", 3 ) )
{
- ADDC( ' ' );
- p++;
+ c = '\n';
}
- else
+ else if( strcasestr( s, "Start=" ) )
{
- ADDC( *p );
- p++;
+ TextPreviousLine( txt );
+ break;
}
+ s = ParseSamiSearch( txt, s, ">" );
+ }
+ else if( !strncmp( s, " ", 6 ) )
+ {
+ c = ' ';
+ s += 6;
+ }
+ else if( *s == '\t' )
+ {
+ c = ' ';
+ s++;
}
else
{
- p = TextGetLine( txt );
+ c = *s;
+ s++;
}
-
- if( p == NULL )
+ if( c != '\0' && i_text+1 < sizeof(text) )
{
- break;
+ text[i_text++] = c;
+ text[i_text] = '\0';
}
}
p_subtitle->i_start = i_start * 1000;
p_subtitle->i_stop = 0;
- p_subtitle->psz_text = strndup( buffer_text, 10*MAX_LINE );
+ p_subtitle->psz_text = strdup( text );
- return( VLC_SUCCESS );
-#undef ADDC
+ return VLC_SUCCESS;
}
-static int ParseVobSubIDX( demux_t *p_demux, subtitle_t *p_subtitle )
+/* ParseDVDSubtitle
+ * Format
+ * {T h1:m1:s1:c1
+ * Line1
+ * Line2
+ * ...
+ * }
+ * TODO it can have a header
+ * { HEAD
+ * ...
+ * CODEPAGE=...
+ * FORMAT=...
+ * LANG=English
+ * }
+ * LANG support would be cool
+ * CODEPAGE is probably mandatory FIXME
+ */
+static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle )
{
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
+ char *psz_text;
- /*
- * Parse the idx file. Each line:
- * timestamp: hh:mm:ss:mss, filepos: loc
- * hexint is the hex location of the vobsub in the .sub file
- *
- */
- char *p;
- char buffer_text[MAX_LINE + 1];
- unsigned int i_start, i_location;
+ for( ;; )
+ {
+ const char *s = TextGetLine( txt );
+ int h1, m1, s1, c1;
- p_subtitle->i_start = 0;
- p_subtitle->i_stop = 0;
- p_subtitle->i_vobsub_location = 0;
- p_subtitle->psz_text = NULL;
+ if( !s )
+ return VLC_EGENERIC;
+
+ if( sscanf( s,
+ "{T %d:%d:%d:%d",
+ &h1, &m1, &s1, &c1 ) == 4 )
+ {
+ p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
+ (int64_t)m1 * 60*1000 +
+ (int64_t)s1 * 1000 +
+ (int64_t)c1 * 10) * 1000;
+ p_subtitle->i_stop = 0;
+ break;
+ }
+ }
+ /* Now read text until a line containing "}" */
+ psz_text = strdup("");
+ if( !psz_text )
+ return VLC_ENOMEM;
for( ;; )
{
- unsigned int h, m, s, ms, loc;
+ const char *s = TextGetLine( txt );
+ int i_len;
+ int i_old;
- if( ( p = TextGetLine( txt ) ) == NULL )
+ if( !s )
{
- return( VLC_EGENERIC );
+ free( psz_text );
+ return VLC_EGENERIC;
}
- i_start = 0;
- memset( buffer_text, '\0', MAX_LINE );
- if( sscanf( p, "timestamp: %d:%d:%d:%d, filepos: %x%[^\r\n]",
- &h, &m, &s, &ms, &loc, buffer_text ) == 5 )
+ i_len = strlen( s );
+ if( i_len == 1 && s[0] == '}')
{
- i_start = ( (mtime_t)h * 3600*1000 +
- (mtime_t)m * 60*1000 +
- (mtime_t)s * 1000 +
- (mtime_t)ms ) * 1000;
- i_location = loc;
- break;
+ p_subtitle->psz_text = psz_text;
+ return VLC_SUCCESS;
}
+
+ i_old = strlen( psz_text );
+ psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
+ strcat( psz_text, s );
+ strcat( psz_text, "\n" );
}
- p_subtitle->i_start = (mtime_t)i_start;
- p_subtitle->i_stop = 0;
- p_subtitle->psz_text = NULL;
- p_subtitle->i_vobsub_location = i_location;
- fprintf( stderr, "time: %x, location: %x\n", i_start, i_location );
- return( 0 );
}
-static int DemuxVobSub( demux_t *p_demux, block_t *p_bk )
+/* ParseMPL2
+ * Format
+ * [n1][n2]Line1|Line2|Line3...
+ * where n1 and n2 are the video frame number (n2 can be empty)
+ */
+static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle )
{
demux_sys_t *p_sys = p_demux->p_sys;
- uint8_t *p = p_bk->p_buffer;
- uint8_t *p_end = &p_bk->p_buffer[p_bk->i_buffer];
+ text_t *txt = &p_sys->txt;
+ char *psz_text;
+ int i;
- while( p < p_end )
+ for( ;; )
{
- int i_size = ps_pkt_size( p, p_end - p );
- block_t *p_pkt;
- int i_id;
- int i_spu;
+ const char *s = TextGetLine( txt );
+ int i_start;
+ int i_stop;
- if( i_size <= 0 )
- {
- break;
- }
- if( p[0] != 0 || p[1] != 0 || p[2] != 0x01 )
- {
- msg_Warn( p_demux, "invalid PES" );
- break;
- }
-
- if( p[3] != 0xbd )
- {
- msg_Dbg( p_demux, "we don't need these ps packets (id=0x1%2.2x)", p[3] );
- p += i_size;
- continue;
- }
+ if( !s )
+ return VLC_EGENERIC;
- /* Create a block */
- p_pkt = block_New( p_demux, i_size );
- memcpy( p_pkt->p_buffer, p, i_size);
- p += i_size;
+ psz_text = malloc( strlen(s) + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
- i_id = ps_pkt_id( p_pkt );
- if( (i_id&0xffe0) != 0xbd20 ||
- ps_pkt_parse_pes( p_pkt, 1 ) )
+ i_start = 0;
+ i_stop = 0;
+ if( sscanf( s, "[%d][] %[^\r\n]", &i_start, psz_text ) == 2 ||
+ sscanf( s, "[%d][%d] %[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
{
- block_Release( p_pkt );
- continue;
+ p_subtitle->i_start = (int64_t)i_start * 100000;
+ p_subtitle->i_stop = (int64_t)i_stop * 100000;
+ break;
}
- i_spu = i_id&0x1f;
- msg_Dbg( p_demux, "SPU track %d size %d", i_spu, i_size );
+ free( psz_text );
+ }
- /* FIXME i_spu == determines which of the spu tracks we will show. */
- if( p_sys->es && i_spu == 0 )
- {
- p_pkt->i_dts = p_pkt->i_pts = p_bk->i_pts;
- p_pkt->i_length = 0;
- es_out_Send( p_demux->out, p_sys->es, p_pkt );
+ /* replace | by \n */
+ for( i = 0; psz_text[i] != '\0'; )
+ {
+ if( psz_text[i] == '|' )
+ psz_text[i] = '\n';
- p_bk->i_pts = 0; /* only first packet has a pts */
- }
+ /* Remove italic */
+ if( psz_text[i] == '/' && ( i == 0 || psz_text[i-1] == '\n' ) )
+ memmove( &psz_text[i], &psz_text[i+1], strlen(&psz_text[i+1])+1 );
else
- {
- block_Release( p_pkt );
- continue;
- }
+ i++;
}
-
+ p_subtitle->psz_text = psz_text;
return VLC_SUCCESS;
}
+