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