]> git.sesse.net Git - vlc/blob - modules/demux/util/sub.h
676e5d2bf9a16e1c1579f318db8db737dd5108a9
[vlc] / modules / demux / util / sub.h
1 /*****************************************************************************
2  * sub.h
3  *****************************************************************************
4  * Copyright (C) 2001-2003 VideoLAN
5  * $Id: sub.h,v 1.12 2004/01/25 20:05:29 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 #if 0
44 typedef struct
45 {
46     int             i_track_id;
47     char            *psz_header;
48     int             i_subtitle;
49     int             i_subtitles;
50     subtitle_t      *subtitle;
51     char            *psz_language;
52
53     int             i_previously_selected; /* to make pf_seek */
54     es_descriptor_t *p_es;
55
56 } subtitle_track_t;
57 #endif
58
59 typedef struct subtitle_demux_s
60 {
61     VLC_COMMON_MEMBERS
62
63     module_t        *p_module;
64
65     int     (*pf_open) ( struct subtitle_demux_s *p_sub,
66                          input_thread_t*p_input,
67                          char *psz_name,
68                          mtime_t i_microsecperframe,
69                          int i_track_id );
70     int     (*pf_demux)( struct subtitle_demux_s *p_sub, mtime_t i_maxdate );
71     int     (*pf_seek) ( struct subtitle_demux_s *p_sub, mtime_t i_date );
72     void    (*pf_close)( struct subtitle_demux_s *p_sub );
73
74     /* *** private *** */
75     input_thread_t      *p_input;
76     int                 i_sub_type;
77
78     char                *psz_header;
79     int                 i_subtitle;
80     int                 i_subtitles;
81     subtitle_t          *subtitle;
82     es_out_id_t         *p_es;
83     int                 i_previously_selected; /* to make pf_seek */
84     FILE                *p_vobsub_file;
85
86     /*unsigned int i_tracks;
87     subtitle_track_t *p_tracks
88     */
89
90 } subtitle_demux_t;
91
92 /*****************************************************************************
93  * subtitle_New: Start a new subtitle demux instance (but subtitle ES isn't
94  *               selected by default.
95  *****************************************************************************
96  * Return: NULL if failed, else a pointer on a new subtitle_demux_t.
97  *
98  * XXX: - if psz_name is NULL then --sub-file is read
99  *      - i_microsecperframe is used only for microdvd file. (overriden
100  *        by --sub-fps )
101  *      - it's at this point that --sub-delay is applied
102  *
103  *****************************************************************************/
104 static inline subtitle_demux_t *subtitle_New( input_thread_t *p_input,
105                                               char *psz_name,
106                                               mtime_t i_microsecperframe,
107                                               int i_track_id )
108 {
109     subtitle_demux_t *p_sub;
110
111     p_sub = vlc_object_create( p_input, sizeof( subtitle_demux_t ) );
112     p_sub->psz_object_name = "subtitle demux";
113     vlc_object_attach( p_sub, p_input );
114     p_sub->p_module = module_Need( p_sub, "subtitle demux", "" );
115
116     if( p_sub->p_module &&
117         p_sub->pf_open( p_sub,
118                         p_input,
119                         psz_name,
120                         i_microsecperframe,
121                         i_track_id ) >=0 )
122     {
123         msg_Info( p_input, "subtitle started" );
124
125     }
126     else
127     {
128         msg_Warn( p_input, "failed to start subtitle demux" );
129         vlc_object_detach( p_sub );
130         if( p_sub->p_module )
131         {
132             module_Unneed( p_sub, p_sub->p_module );
133         }
134         vlc_object_destroy( p_sub );
135         p_sub = NULL;
136     }
137
138     return( p_sub );
139 }
140
141 /*****************************************************************************
142  * subtitle_Demux: send subtitle to decoder from last date to i_max
143  *****************************************************************************/
144 static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max )
145 {
146     return( p_sub->pf_demux( p_sub, i_max ) );
147 }
148
149 /*****************************************************************************
150  * subtitle_Seek: Seek to i_date
151  *****************************************************************************/
152 static inline int subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date )
153 {
154     return( p_sub->pf_seek( p_sub, i_date ) );
155 }
156
157 /*****************************************************************************
158  * subtitle_Close: Stop ES decoder and free all memory included p_sub.
159  *****************************************************************************/
160 static inline void subtitle_Close( subtitle_demux_t *p_sub )
161 {
162     msg_Info( p_sub, "subtitle stopped" );
163     if( p_sub )
164     {
165         vlc_object_detach( p_sub );
166         if( p_sub->p_module )
167         {
168             module_Unneed( p_sub, p_sub->p_module );
169         }
170         vlc_object_destroy( p_sub );
171     }
172 }
173