]> git.sesse.net Git - vlc/blob - modules/demux/util/sub.h
c5a7ccb372f92486ab02073e2884978863061ea0
[vlc] / modules / demux / util / sub.h
1 /*****************************************************************************
2  * sub.h
3  *****************************************************************************
4  * Copyright (C) 2001-2004 VideoLAN
5  * $Id: sub.h,v 1.20 2004/03/03 20:39:52 gbazin 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 #include "../ps.h"
25
26 #define SUB_TYPE_MICRODVD   0x00
27 #define SUB_TYPE_SUBRIP     0x01
28 #define SUB_TYPE_SSA1       0x02
29 #define SUB_TYPE_SSA2_4     0x03
30 #define SUB_TYPE_VPLAYER    0x04
31 #define SUB_TYPE_SAMI       0x05
32 #define SUB_TYPE_VOBSUB     0x100
33 #define SUB_TYPE_UNKNOWN    0xffff
34
35 typedef struct subtitle_s
36 {
37     mtime_t i_start;
38     mtime_t i_stop;
39
40     char    *psz_text;
41     int     i_vobsub_location;
42
43 } subtitle_t;
44
45 typedef struct subtitle_demux_s
46 {
47     VLC_COMMON_MEMBERS
48
49     module_t        *p_module;
50
51     int     (*pf_open) ( struct subtitle_demux_s *p_sub,
52                          input_thread_t*p_input,
53                          char *psz_name,
54                          mtime_t i_microsecperframe );
55     int     (*pf_demux)( struct subtitle_demux_s *p_sub, mtime_t i_maxdate );
56     int     (*pf_seek) ( struct subtitle_demux_s *p_sub, mtime_t i_date );
57     void    (*pf_close)( struct subtitle_demux_s *p_sub );
58
59     /* *** private *** */
60     input_thread_t      *p_input;
61     int                 i_sub_type;
62
63     char                *psz_header;
64     int                 i_subtitle;
65     int                 i_subtitles;
66     subtitle_t          *subtitle;
67     es_out_id_t         *p_es;
68     int                 i_previously_selected; /* to make pf_seek */
69     FILE                *p_vobsub_file;
70
71 } subtitle_demux_t;
72
73 /*****************************************************************************
74  * subtitle_New: Start a new subtitle demux instance (but subtitle ES isn't
75  *               selected by default.
76  *****************************************************************************
77  * Return: NULL if failed, else a pointer on a new subtitle_demux_t.
78  *
79  * XXX: - if psz_name is NULL then --sub-file is read
80  *      - i_microsecperframe is used only for microdvd file. (overriden
81  *        by --sub-fps )
82  *      - it's at this point that --sub-delay is applied
83  *
84  *****************************************************************************/
85 static inline subtitle_demux_t *subtitle_New( input_thread_t *p_input,
86                                               char *psz_name,
87                                               mtime_t i_microsecperframe )
88 {
89     subtitle_demux_t *p_sub;
90
91     p_sub = vlc_object_create( p_input, sizeof( subtitle_demux_t ) );
92     p_sub->psz_object_name = "subtitle demux";
93     vlc_object_attach( p_sub, p_input );
94     p_sub->p_module = module_Need( p_sub, "subtitle demux", NULL, 0 );
95
96     if( p_sub->p_module &&
97         p_sub->pf_open( p_sub, p_input, psz_name, i_microsecperframe ) >=0 )
98     {
99         msg_Info( p_input, "subtitle started" );
100
101     }
102     else
103     {
104         msg_Warn( p_input, "failed to start subtitle demux" );
105         vlc_object_detach( p_sub );
106         if( p_sub->p_module )
107         {
108             module_Unneed( p_sub, p_sub->p_module );
109         }
110         vlc_object_destroy( p_sub );
111         p_sub = NULL;
112     }
113
114     return( p_sub );
115 }
116
117 /*****************************************************************************
118  * subtitle_Demux: send subtitle to decoder from last date to i_max
119  *****************************************************************************/
120 static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max )
121 {
122     return( p_sub->pf_demux( p_sub, i_max ) );
123 }
124
125 /*****************************************************************************
126  * subtitle_Seek: Seek to i_date
127  *****************************************************************************/
128 static inline int subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date )
129 {
130     return( p_sub->pf_seek( p_sub, i_date ) );
131 }
132
133 /*****************************************************************************
134  * subtitle_Close: Stop ES decoder and free all memory included p_sub.
135  *****************************************************************************/
136 static inline void subtitle_Close( subtitle_demux_t *p_sub )
137 {
138     msg_Info( p_sub, "subtitle stopped" );
139     if( p_sub )
140     {
141         p_sub->pf_close( p_sub );
142         vlc_object_detach( p_sub );
143         if( p_sub->p_module )
144         {
145             module_Unneed( p_sub, p_sub->p_module );
146         }
147         vlc_object_destroy( p_sub );
148     }
149 }
150