sub.h 7.87 KB
Newer Older
1
2
3
/*****************************************************************************
 * sub.h
 *****************************************************************************
4
 * Copyright (C) 2001-2003 VideoLAN
5
 * $Id: sub.h,v 1.10 2003/11/05 00:17:50 hartman Exp $
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#define SUB_TYPE_MICRODVD   0x00
#define SUB_TYPE_SUBRIP     0x01
#define SUB_TYPE_SSA1       0x02
#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
32
33
34
35
36
37
38
#define SUB_TYPE_UNKNOWN    0xffff

typedef struct subtitle_s
{
    mtime_t i_start;
    mtime_t i_stop;

    char    *psz_text;
39
40
    int     i_vobsub_location;

41
42
} subtitle_t;

43
44
45
typedef struct subtitle_track_s
{
    int             i_track_id;
46
    char            *psz_header;
47
48
49
50
51
52
53
54
55
    int             i_subtitle;
    int             i_subtitles;
    subtitle_t      *subtitle;
    char            *psz_language;

    int             i_previously_selected; /* to make pf_seek */
    es_descriptor_t *p_es;
    
} subtitle_track_t;
56
57
58
59
60
61
62
63
64
65

typedef struct subtitle_demux_s
{
    VLC_COMMON_MEMBERS
    
    module_t        *p_module;
    
    int     (*pf_open) ( struct subtitle_demux_s *p_sub, 
                         input_thread_t*p_input, 
                         char *psz_name,
66
67
                         mtime_t i_microsecperframe,
                         int i_track_id );
68
69
70
71
72
73
    int     (*pf_demux)( struct subtitle_demux_s *p_sub, mtime_t i_maxdate );
    int     (*pf_seek) ( struct subtitle_demux_s *p_sub, mtime_t i_date );
    void    (*pf_close)( struct subtitle_demux_s *p_sub );
    

    /* *** private *** */
74
75
76
    input_thread_t      *p_input;
    int                 i_sub_type;

77
    char                *psz_header;
78
79
80
81
    int                 i_subtitle;
    int                 i_subtitles;
    subtitle_t          *subtitle;
    es_descriptor_t     *p_es;
82
83
    int                 i_previously_selected; /* to make pf_seek */

84
85
86
    /*unsigned int	i_tracks;
    subtitle_track_t	*p_tracks
    */
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    

} subtitle_demux_t;

/*****************************************************************************
 *
 * I made somes wrappers : So use them !
 *  I think you shouldn't need access to subtitle_demux_t members else said
 *  it to me.
 *
 *****************************************************************************/


/*****************************************************************************
 * subtitle_New: Start a new subtitle demux instance (but subtitle ES isn't 
 *               selected by default.
 *****************************************************************************
 * Return: NULL if failed, else a pointer on a new subtitle_demux_t.
 *
 * XXX: - if psz_name is NULL then --sub-file is read
 *      - i_microsecperframe is used only for microdvd file. (overriden
 *        by --sub-fps )
 *      - it's at this point that --sub-delay is applied
 *
 *****************************************************************************/
static inline subtitle_demux_t *subtitle_New( input_thread_t *p_input,
                                              char *psz_name,
114
115
                                              mtime_t i_microsecperframe,
                                              int i_track_id );
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*****************************************************************************
 * subtitle_Select: Select the related subtitle ES.
 *****************************************************************************/
static inline void subtitle_Select( subtitle_demux_t *p_sub );

/*****************************************************************************
 * subtitle_Unselect: Unselect the related subtitle ES.
 *****************************************************************************/
static inline void subtitle_Unselect( subtitle_demux_t *p_sub );

/*****************************************************************************
 * subtitle_Demux: send subtitle to decoder from last date to i_max
 *****************************************************************************/
static inline int  subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max );

/*****************************************************************************
 * subtitle_Seek: Seek to i_date
 *****************************************************************************/
static inline int  subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date );

/*****************************************************************************
 * subtitle_Close: Stop ES decoder and free all memory included p_sub.
 *****************************************************************************/
static inline void subtitle_Close( subtitle_demux_t *p_sub );





/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/


static inline 
    subtitle_demux_t *subtitle_New( input_thread_t *p_input,
                                    char *psz_name,
153
154
                                    mtime_t i_microsecperframe,
                                    int i_track_id )
155
156
157
158
159
{
    subtitle_demux_t *p_sub;

    p_sub = vlc_object_create( p_input, sizeof( subtitle_demux_t ) );
    p_sub->psz_object_name = "subtitle demux";
gbazin's avatar
   
gbazin committed
160
    vlc_object_attach( p_sub, p_input );
161
162
163
164
165
166
    p_sub->p_module = module_Need( p_sub, "subtitle demux", "" );

    if( p_sub->p_module &&
        p_sub->pf_open( p_sub,
                        p_input,
                        psz_name,
167
168
                        i_microsecperframe,
                        i_track_id ) >=0 )
169
170
171
172
173
174
    {
        msg_Info( p_input, "subtitle started" );

    }
    else
    {
Christophe Massiot's avatar
Christophe Massiot committed
175
        msg_Warn( p_input, "failed to start subtitle demux" );
gbazin's avatar
   
gbazin committed
176
        vlc_object_detach( p_sub );
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
        if( p_sub->p_module )
        {
            module_Unneed( p_sub, p_sub->p_module );
        }
        vlc_object_destroy( p_sub );
        p_sub = NULL;
    }

    return( p_sub );
}

static inline void subtitle_Select( subtitle_demux_t *p_sub )
{
    if( p_sub && p_sub->p_es )
    {
        vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
        input_SelectES( p_sub->p_input, p_sub->p_es );
        vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
        p_sub->i_previously_selected = 0;
    }
}
static inline void subtitle_Unselect( subtitle_demux_t *p_sub )
{
    if( p_sub && p_sub->p_es )
    {
        vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
        input_UnselectES( p_sub->p_input, p_sub->p_es );
        vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
        p_sub->i_previously_selected = 0;
    }
}

static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max )
{
    return( p_sub->pf_demux( p_sub, i_max ) );
}

static inline int subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date )
{
    return( p_sub->pf_demux( p_sub, i_date ) );
}

static inline void subtitle_Close( subtitle_demux_t *p_sub )
{
    msg_Info( p_sub, "subtitle stopped" );
    if( p_sub )
    {
gbazin's avatar
   
gbazin committed
224
225
226
227
228
        vlc_object_detach( p_sub );
        if( p_sub->p_module )
        {
            module_Unneed( p_sub, p_sub->p_module );
        }
229
230
231
        vlc_object_destroy( p_sub );
    }
}