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