Commit aafd5b0d authored by Laurent Aimar's avatar Laurent Aimar

* modules/demux/util : add a text subtitle demuxer. (Module called by demux).

MicroDVD, SubRIP, SSA subtitle format should work...
 Options: --sub-file <subtitle file> [--sub-fps, --sub-delay --sub-format].

 * modules/demux/avi : make use of subtitle parser.
 * modules/demux/asf : display movie length. (It will not work with live
streams of course).

 modules/codec/spudec : use i_dts to send end of display time for subtitle.
(Yes it's ugly, but it works :)
parent d2d2e4f9
......@@ -585,7 +585,7 @@ PLUGINS="${PLUGINS} aout_file"
#PLUGINS="${PLUGINS} scope"
PLUGINS="${PLUGINS} i420_rgb i420_yuy2 i422_yuy2 i420_ymga"
PLUGINS="${PLUGINS} id3 m3u"
PLUGINS="${PLUGINS} wav araw demuxdump"
PLUGINS="${PLUGINS} wav araw demuxdump demuxsub"
dnl
dnl Network modules
......
......@@ -2,7 +2,7 @@
* text.c: text subtitles parser
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
* $Id: text.c,v 1.1 2002/11/06 21:48:24 gbazin Exp $
* $Id: text.c,v 1.2 2002/11/15 18:10:26 fenrir Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
......@@ -43,10 +43,11 @@
void E_(ParseText)( spudec_thread_t *p_spudec, subtitler_font_t *p_font )
{
char * psz_subtitle;
mtime_t i_pts;
mtime_t i_pts, i_dts;
/* We cannot display a subpicture with no date */
i_pts = p_spudec->bit_stream.p_pes->i_pts;
i_dts = p_spudec->bit_stream.p_pes->i_dts;
if( i_pts == 0 )
{
/* Dump the packet */
......@@ -75,7 +76,7 @@ void E_(ParseText)( spudec_thread_t *p_spudec, subtitler_font_t *p_font )
subtitler_PlotSubtitle( p_spudec->p_vout,
psz_subtitle, p_font,
i_pts,
0 );
i_dts );
}
/* Prepare for next time. No need to check that
......
......@@ -2,7 +2,7 @@
* asf.c : ASFv01 file input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: asf.c,v 1.5 2002/11/14 16:17:47 fenrir Exp $
* $Id: asf.c,v 1.6 2002/11/15 18:10:26 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
......@@ -292,9 +292,6 @@ static int Activate( vlc_object_t * p_this )
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.p_selected_program->b_is_ok = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock );
p_demux->i_data_begin = p_demux->root.p_data->i_object_pos + 50;
if( p_demux->root.p_data->i_object_size != 0 )
......@@ -310,6 +307,46 @@ static int Activate( vlc_object_t * p_this )
// go to first packet
ASF_SeekAbsolute( p_input, p_demux->i_data_begin );
vlc_mutex_lock( &p_input->stream.stream_lock );
/* try to calculate movie time */
if( p_demux->p_fp->i_data_packets_count > 0 )
{
int64_t i_count;
mtime_t i_length;
/* real number of packets */
i_count = ( p_input->stream.p_selected_area->i_size -
p_demux->i_data_begin ) /
p_demux->p_fp->i_min_data_packet_size;
/* calculate the time duration in s */
i_length = (mtime_t)p_demux->p_fp->i_play_duration / 10 *
(mtime_t)i_count /
(mtime_t)p_demux->p_fp->i_data_packets_count /
(mtime_t)1000000;
if( i_length > 0 )
{
p_input->stream.i_mux_rate =
p_input->stream.p_selected_area->i_size / 50 / i_length;
}
else
{
p_input->stream.i_mux_rate = 0;
}
}
else
{
/* cannot known */
p_input->stream.i_mux_rate = 0;
}
p_input->stream.p_selected_program->b_is_ok = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock );
return( 0 );
}
......
......@@ -2,7 +2,7 @@
* avi.c : AVI file Stream input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: avi.c,v 1.11 2002/11/08 10:26:53 gbazin Exp $
* $Id: avi.c,v 1.12 2002/11/15 18:10:26 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
......@@ -34,6 +34,12 @@
#include "video.h"
#include "libavi.h"
#define __AVI_SUBTITLE__ 1
#ifdef __AVI_SUBTITLE__
# include "../util/sub.h"
#endif
#include "avi.h"
/*****************************************************************************
......@@ -744,6 +750,13 @@ static void __AVIEnd ( vlc_object_t * p_this )
}
free( p_avi->pp_info );
}
#ifdef __AVI_SUBTITLE__
if( p_avi->p_sub )
{
subtitle_Close( p_avi->p_sub );
p_avi->p_sub = NULL;
}
#endif
AVI_ChunkFreeRoot( p_input, &p_avi->ck_root );
}
......@@ -764,7 +777,10 @@ static int AVIInit( vlc_object_t * p_this )
demux_sys_t *p_avi;
es_descriptor_t *p_es = NULL; /* avoid warning */
int i;
#ifdef __AVI_SUBTITLE__
mtime_t i_microsecperframe = 0; // for some subtitle format
#endif
vlc_bool_t b_stream_audio, b_stream_video;
p_input->pf_demux = AVIDemux_Seekable;
......@@ -954,6 +970,14 @@ static int AVIInit( vlc_object_t * p_this )
p_avi_strf_vids->p_bih->biBitCount,
(float)p_info->i_rate /
(float)p_info->i_scale );
#ifdef __AVI_SUBTITLE__
if( i_microsecperframe == 0 )
{
i_microsecperframe = (mtime_t)1000000 *
(mtime_t)p_info->i_scale /
(mtime_t)p_info->i_rate;
}
#endif
break;
default:
msg_Err( p_input, "stream[%d] unknown type", i );
......@@ -983,6 +1007,14 @@ static int AVIInit( vlc_object_t * p_this )
}
#undef p_info
}
#ifdef __AVI_SUBTITLE__
if( ( p_avi->p_sub = subtitle_New( p_input, NULL, i_microsecperframe ) ) )
{
subtitle_Select( p_avi->p_sub );
}
#endif
if( config_GetInt( p_input, "avi-index" ) )
{
if( p_avi->b_seekable )
......@@ -1593,6 +1625,13 @@ static int AVIDemux_Seekable( input_thread_t *p_input )
// input_ClockInit( p_input->stream.p_selected_program );
AVISeek( p_input, i_date, i_percent);
#ifdef __AVI_SUBTITLE__
if( p_avi->p_sub )
{
subtitle_Seek( p_avi->p_sub, p_avi->i_time );
}
#endif
}
......@@ -1607,6 +1646,12 @@ static int AVIDemux_Seekable( input_thread_t *p_input )
p_avi->i_time += 100*1000; /* read 100ms */
#ifdef __AVI_SUBTITLE__
if( p_avi->p_sub )
{
subtitle_Demux( p_avi->p_sub, p_avi->i_time );
}
#endif
/* init toread */
for( i_stream = 0; i_stream < p_avi->i_streams; i_stream++ )
{
......
......@@ -2,7 +2,7 @@
* avi.h : AVI file Stream input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: avi.h,v 1.6 2002/11/06 14:44:30 sam Exp $
* $Id: avi.h,v 1.7 2002/11/15 18:10:26 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
......@@ -20,7 +20,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
typedef struct avi_packet_s
{
vlc_fourcc_t i_fourcc;
......@@ -84,5 +83,9 @@ struct demux_sys_t
int i_streams;
avi_stream_t **pp_info;
#ifdef __AVI_SUBTITLE__
subtitle_demux_t *p_sub;
#endif
};
SOURCES_id3 = modules/demux/util/id3.c
SOURCES_id3tag = modules/demux/util/id3tag.c
SOURCES_demuxsub = modules/demux/util/sub.c
noinst_HEADERS += \
modules/demux/util/sub.h
This diff is collapsed.
/*****************************************************************************
* sub.h
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: sub.h,v 1.1 2002/11/15 18:10:26 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*****************************************************************************/
#define SUB_TYPE_MICRODVD 0x00
#define SUB_TYPE_SUBRIP 0x01
#define SUB_TYPE_SSA1 0x02
#define SUB_TYPE_SSA2_4 0x03
#define SUB_TYPE_UNKNOWN 0xffff
typedef struct subtitle_s
{
mtime_t i_start;
mtime_t i_stop;
char *psz_text;
} subtitle_t;
typedef struct subtitle_demux_s
{
VLC_COMMON_MEMBERS
module_t *p_module;
int (*pf_open) ( struct subtitle_demux_s *p_sub,
input_thread_t*p_input,
char *psz_name,
mtime_t i_microsecperframe );
int (*pf_demux)( struct subtitle_demux_s *p_sub, mtime_t i_maxdate );
int (*pf_seek) ( struct subtitle_demux_s *p_sub, mtime_t i_date );
void (*pf_close)( struct subtitle_demux_s *p_sub );
/* *** private *** */
input_thread_t *p_input;
int i_sub_type;
int i_previously_selected; // to make pf_seek
es_descriptor_t *p_es;
int i_subtitle;
int i_subtitles;
subtitle_t *subtitle;
} subtitle_demux_t;
/*****************************************************************************
*
* I made somes wrappers : So use them !
* I think you shouldn't need access to subtitle_demux_t members else said
* it to me.
*
*****************************************************************************/
/*****************************************************************************
* subtitle_New: Start a new subtitle demux instance (but subtitle ES isn't
* selected by default.
*****************************************************************************
* Return: NULL if failed, else a pointer on a new subtitle_demux_t.
*
* XXX: - if psz_name is NULL then --sub-file is read
* - i_microsecperframe is used only for microdvd file. (overriden
* by --sub-fps )
* - it's at this point that --sub-delay is applied
*
*****************************************************************************/
static inline subtitle_demux_t *subtitle_New( input_thread_t *p_input,
char *psz_name,
mtime_t i_microsecperframe );
/*****************************************************************************
* subtitle_Select: Select the related subtitle ES.
*****************************************************************************/
static inline void subtitle_Select( subtitle_demux_t *p_sub );
/*****************************************************************************
* subtitle_Unselect: Unselect the related subtitle ES.
*****************************************************************************/
static inline void subtitle_Unselect( subtitle_demux_t *p_sub );
/*****************************************************************************
* subtitle_Demux: send subtitle to decoder from last date to i_max
*****************************************************************************/
static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max );
/*****************************************************************************
* subtitle_Seek: Seek to i_date
*****************************************************************************/
static inline int subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date );
/*****************************************************************************
* subtitle_Close: Stop ES decoder and free all memory included p_sub.
*****************************************************************************/
static inline void subtitle_Close( subtitle_demux_t *p_sub );
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
static inline
subtitle_demux_t *subtitle_New( input_thread_t *p_input,
char *psz_name,
mtime_t i_microsecperframe )
{
subtitle_demux_t *p_sub;
p_sub = vlc_object_create( p_input, sizeof( subtitle_demux_t ) );
p_sub->psz_object_name = "subtitle demux";
p_sub->p_module = module_Need( p_sub, "subtitle demux", "" );
if( p_sub->p_module &&
p_sub->pf_open( p_sub,
p_input,
psz_name,
i_microsecperframe ) >=0 )
{
msg_Info( p_input, "subtitle started" );
}
else
{
msg_Err( p_input, "failed to start subtitle demux" );
if( p_sub->p_module )
{
module_Unneed( p_sub, p_sub->p_module );
}
vlc_object_destroy( p_sub );
p_sub = NULL;
}
return( p_sub );
}
static inline void subtitle_Select( subtitle_demux_t *p_sub )
{
if( p_sub && p_sub->p_es )
{
vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
input_SelectES( p_sub->p_input, p_sub->p_es );
vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
p_sub->i_previously_selected = 0;
}
}
static inline void subtitle_Unselect( subtitle_demux_t *p_sub )
{
if( p_sub && p_sub->p_es )
{
vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
input_UnselectES( p_sub->p_input, p_sub->p_es );
vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
p_sub->i_previously_selected = 0;
}
}
static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max )
{
return( p_sub->pf_demux( p_sub, i_max ) );
}
static inline int subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date )
{
return( p_sub->pf_demux( p_sub, i_date ) );
}
static inline void subtitle_Close( subtitle_demux_t *p_sub )
{
msg_Info( p_sub, "subtitle stopped" );
if( p_sub->p_module )
{
module_Unneed( p_sub, p_sub->p_module );
}
if( p_sub )
{
vlc_object_destroy( p_sub );
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment