1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001-2003 VideoLAN
5 * $Id: sub.h,v 1.7 2003/08/23 19:20:29 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 #define SUB_TYPE_MICRODVD 0x00
25 #define SUB_TYPE_SUBRIP 0x01
26 #define SUB_TYPE_SSA1 0x02
27 #define SUB_TYPE_SSA2_4 0x03
28 #define SUB_TYPE_VPLAYER 0x04
29 #define SUB_TYPE_SAMI 0x05
30 #define SUB_TYPE_UNKNOWN 0xffff
32 typedef struct subtitle_s
41 typedef struct subtitle_demux_s
47 int (*pf_open) ( struct subtitle_demux_s *p_sub,
48 input_thread_t*p_input,
50 mtime_t i_microsecperframe );
51 int (*pf_demux)( struct subtitle_demux_s *p_sub, mtime_t i_maxdate );
52 int (*pf_seek) ( struct subtitle_demux_s *p_sub, mtime_t i_date );
53 void (*pf_close)( struct subtitle_demux_s *p_sub );
57 input_thread_t *p_input;
60 int i_previously_selected; // to make pf_seek
61 es_descriptor_t *p_es;
69 /*****************************************************************************
71 * I made somes wrappers : So use them !
72 * I think you shouldn't need access to subtitle_demux_t members else said
75 *****************************************************************************/
78 /*****************************************************************************
79 * subtitle_New: Start a new subtitle demux instance (but subtitle ES isn't
80 * selected by default.
81 *****************************************************************************
82 * Return: NULL if failed, else a pointer on a new subtitle_demux_t.
84 * XXX: - if psz_name is NULL then --sub-file is read
85 * - i_microsecperframe is used only for microdvd file. (overriden
87 * - it's at this point that --sub-delay is applied
89 *****************************************************************************/
90 static inline subtitle_demux_t *subtitle_New( input_thread_t *p_input,
92 mtime_t i_microsecperframe );
93 /*****************************************************************************
94 * subtitle_Select: Select the related subtitle ES.
95 *****************************************************************************/
96 static inline void subtitle_Select( subtitle_demux_t *p_sub );
98 /*****************************************************************************
99 * subtitle_Unselect: Unselect the related subtitle ES.
100 *****************************************************************************/
101 static inline void subtitle_Unselect( subtitle_demux_t *p_sub );
103 /*****************************************************************************
104 * subtitle_Demux: send subtitle to decoder from last date to i_max
105 *****************************************************************************/
106 static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max );
108 /*****************************************************************************
109 * subtitle_Seek: Seek to i_date
110 *****************************************************************************/
111 static inline int subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date );
113 /*****************************************************************************
114 * subtitle_Close: Stop ES decoder and free all memory included p_sub.
115 *****************************************************************************/
116 static inline void subtitle_Close( subtitle_demux_t *p_sub );
122 /*****************************************************************************/
123 /*****************************************************************************/
124 /*****************************************************************************/
128 subtitle_demux_t *subtitle_New( input_thread_t *p_input,
130 mtime_t i_microsecperframe )
132 subtitle_demux_t *p_sub;
134 p_sub = vlc_object_create( p_input, sizeof( subtitle_demux_t ) );
135 p_sub->psz_object_name = "subtitle demux";
136 vlc_object_attach( p_sub, p_input );
137 p_sub->p_module = module_Need( p_sub, "subtitle demux", "" );
139 if( p_sub->p_module &&
140 p_sub->pf_open( p_sub,
143 i_microsecperframe ) >=0 )
145 msg_Info( p_input, "subtitle started" );
150 msg_Warn( p_input, "failed to start subtitle demux" );
151 vlc_object_detach( p_sub );
152 if( p_sub->p_module )
154 module_Unneed( p_sub, p_sub->p_module );
156 vlc_object_destroy( p_sub );
163 static inline void subtitle_Select( subtitle_demux_t *p_sub )
165 if( p_sub && p_sub->p_es )
167 vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
168 input_SelectES( p_sub->p_input, p_sub->p_es );
169 vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
170 p_sub->i_previously_selected = 0;
173 static inline void subtitle_Unselect( subtitle_demux_t *p_sub )
175 if( p_sub && p_sub->p_es )
177 vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
178 input_UnselectES( p_sub->p_input, p_sub->p_es );
179 vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
180 p_sub->i_previously_selected = 0;
184 static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max )
186 return( p_sub->pf_demux( p_sub, i_max ) );
189 static inline int subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date )
191 return( p_sub->pf_demux( p_sub, i_date ) );
194 static inline void subtitle_Close( subtitle_demux_t *p_sub )
196 msg_Info( p_sub, "subtitle stopped" );
199 vlc_object_detach( p_sub );
200 if( p_sub->p_module )
202 module_Unneed( p_sub, p_sub->p_module );
204 vlc_object_destroy( p_sub );