]> git.sesse.net Git - vlc/blob - modules/demux/util/sub.h
* src/input/subtitles.c: made the autodetection fuzziness a config option.
[vlc] / modules / demux / util / sub.h
1 /*****************************************************************************
2  * sub.h
3  *****************************************************************************
4  * Copyright (C) 2001-2003 VideoLAN
5  * $Id: sub.h,v 1.8 2003/10/11 22:40:05 hartman Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  * 
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
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
31
32 typedef struct subtitle_s
33 {
34     mtime_t i_start;
35     mtime_t i_stop;
36
37     char    *psz_text;
38 } subtitle_t;
39
40
41 typedef struct subtitle_demux_s
42 {
43     VLC_COMMON_MEMBERS
44     
45     module_t        *p_module;
46     
47     int     (*pf_open) ( struct subtitle_demux_s *p_sub, 
48                          input_thread_t*p_input, 
49                          char *psz_name,
50                          mtime_t i_microsecperframe,
51                          int i_track_id );
52     int     (*pf_demux)( struct subtitle_demux_s *p_sub, mtime_t i_maxdate );
53     int     (*pf_seek) ( struct subtitle_demux_s *p_sub, mtime_t i_date );
54     void    (*pf_close)( struct subtitle_demux_s *p_sub );
55     
56
57     /* *** private *** */
58     input_thread_t  *p_input;
59     int             i_sub_type;
60     
61     int             i_previously_selected; // to make pf_seek
62     es_descriptor_t *p_es;
63     
64     int             i_subtitle;
65     int             i_subtitles;
66     subtitle_t      *subtitle;
67
68 } subtitle_demux_t;
69
70 /*****************************************************************************
71  *
72  * I made somes wrappers : So use them !
73  *  I think you shouldn't need access to subtitle_demux_t members else said
74  *  it to me.
75  *
76  *****************************************************************************/
77
78
79 /*****************************************************************************
80  * subtitle_New: Start a new subtitle demux instance (but subtitle ES isn't 
81  *               selected by default.
82  *****************************************************************************
83  * Return: NULL if failed, else a pointer on a new subtitle_demux_t.
84  *
85  * XXX: - if psz_name is NULL then --sub-file is read
86  *      - i_microsecperframe is used only for microdvd file. (overriden
87  *        by --sub-fps )
88  *      - it's at this point that --sub-delay is applied
89  *
90  *****************************************************************************/
91 static inline subtitle_demux_t *subtitle_New( input_thread_t *p_input,
92                                               char *psz_name,
93                                               mtime_t i_microsecperframe,
94                                               int i_track_id );
95 /*****************************************************************************
96  * subtitle_Select: Select the related subtitle ES.
97  *****************************************************************************/
98 static inline void subtitle_Select( subtitle_demux_t *p_sub );
99
100 /*****************************************************************************
101  * subtitle_Unselect: Unselect the related subtitle ES.
102  *****************************************************************************/
103 static inline void subtitle_Unselect( subtitle_demux_t *p_sub );
104
105 /*****************************************************************************
106  * subtitle_Demux: send subtitle to decoder from last date to i_max
107  *****************************************************************************/
108 static inline int  subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max );
109
110 /*****************************************************************************
111  * subtitle_Seek: Seek to i_date
112  *****************************************************************************/
113 static inline int  subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date );
114
115 /*****************************************************************************
116  * subtitle_Close: Stop ES decoder and free all memory included p_sub.
117  *****************************************************************************/
118 static inline void subtitle_Close( subtitle_demux_t *p_sub );
119
120
121
122
123
124 /*****************************************************************************/
125 /*****************************************************************************/
126 /*****************************************************************************/
127
128
129 static inline 
130     subtitle_demux_t *subtitle_New( input_thread_t *p_input,
131                                     char *psz_name,
132                                     mtime_t i_microsecperframe,
133                                     int i_track_id )
134 {
135     subtitle_demux_t *p_sub;
136
137     p_sub = vlc_object_create( p_input, sizeof( subtitle_demux_t ) );
138     p_sub->psz_object_name = "subtitle demux";
139     vlc_object_attach( p_sub, p_input );
140     p_sub->p_module = module_Need( p_sub, "subtitle demux", "" );
141
142     if( p_sub->p_module &&
143         p_sub->pf_open( p_sub,
144                         p_input,
145                         psz_name,
146                         i_microsecperframe,
147                         i_track_id ) >=0 )
148     {
149         msg_Info( p_input, "subtitle started" );
150
151     }
152     else
153     {
154         msg_Warn( p_input, "failed to start subtitle demux" );
155         vlc_object_detach( p_sub );
156         if( p_sub->p_module )
157         {
158             module_Unneed( p_sub, p_sub->p_module );
159         }
160         vlc_object_destroy( p_sub );
161         p_sub = NULL;
162     }
163
164     return( p_sub );
165 }
166
167 static inline void subtitle_Select( subtitle_demux_t *p_sub )
168 {
169     if( p_sub && p_sub->p_es )
170     {
171         vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
172         input_SelectES( p_sub->p_input, p_sub->p_es );
173         vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
174         p_sub->i_previously_selected = 0;
175     }
176 }
177 static inline void subtitle_Unselect( subtitle_demux_t *p_sub )
178 {
179     if( p_sub && p_sub->p_es )
180     {
181         vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
182         input_UnselectES( p_sub->p_input, p_sub->p_es );
183         vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
184         p_sub->i_previously_selected = 0;
185     }
186 }
187
188 static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max )
189 {
190     return( p_sub->pf_demux( p_sub, i_max ) );
191 }
192
193 static inline int subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date )
194 {
195     return( p_sub->pf_demux( p_sub, i_date ) );
196 }
197
198 static inline void subtitle_Close( subtitle_demux_t *p_sub )
199 {
200     msg_Info( p_sub, "subtitle stopped" );
201     if( p_sub )
202     {
203         vlc_object_detach( p_sub );
204         if( p_sub->p_module )
205         {
206             module_Unneed( p_sub, p_sub->p_module );
207         }
208         vlc_object_destroy( p_sub );
209     }
210 }