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