]> git.sesse.net Git - vlc/blob - include/vlc_demux.h
A bit of headers cleanup
[vlc] / include / vlc_demux.h
1 /*****************************************************************************
2  * vlc_demux.h: Demuxer descriptor, queries and methods
3  *****************************************************************************
4  * Copyright (C) 1999-2005 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef _VLC_DEMUX_H
25 #define _VLC_DEMUX_H 1
26
27 #include <vlc_es.h>
28 #include <vlc_stream.h>
29 #include <vlc_es_out.h>
30
31 /**
32  * \defgroup demux Demux
33  * @{
34  */
35
36 struct demux_t
37 {
38     VLC_COMMON_MEMBERS
39
40     /* Module properties */
41     module_t    *p_module;
42
43     /* eg informative but needed (we can have access+demux) */
44     char        *psz_access;
45     char        *psz_demux;
46     char        *psz_path;
47
48     /* input stream */
49     stream_t    *s;     /* NULL in case of a access+demux in one */
50
51     /* es output */
52     es_out_t    *out;   /* our p_es_out */
53
54     /* set by demuxer */
55     int (*pf_demux)  ( demux_t * );   /* demux one frame only */
56     int (*pf_control)( demux_t *, int i_query, va_list args);
57
58     /* Demux has to maintain them uptodate
59      * when it is responsible of seekpoint/title */
60     struct
61     {
62         unsigned int i_update;  /* Demux sets them on change,
63                                    Input removes them once take into account*/
64         /* Seekpoint/Title at demux level */
65         int          i_title;       /* idem, start from 0 (could be menu) */
66         int          i_seekpoint;   /* idem, start from 0 */
67     } info;
68     demux_sys_t *p_sys;
69 };
70
71 enum demux_query_e
72 {
73     /* I. Common queries to access_demux and demux */
74     /* POSITION double between 0.0 and 1.0 */
75     DEMUX_GET_POSITION,         /* arg1= double *       res=    */
76     DEMUX_SET_POSITION,         /* arg1= double         res=can fail    */
77
78     /* LENGTH/TIME in microsecond, 0 if unknown */
79     DEMUX_GET_LENGTH,           /* arg1= int64_t *      res=    */
80     DEMUX_GET_TIME,             /* arg1= int64_t *      res=    */
81     DEMUX_SET_TIME,             /* arg1= int64_t        res=can fail    */
82
83     /* TITLE_INFO only if more than 1 title or 1 chapter */
84     DEMUX_GET_TITLE_INFO,       /* arg1=input_title_t*** arg2=int* can fail */
85
86     /* TITLE/SEEKPOINT, only when TITLE_INFO succeed */
87     DEMUX_SET_TITLE,            /* arg1= int            can fail */
88     DEMUX_SET_SEEKPOINT,        /* arg1= int            can fail */
89
90     /* DEMUX_SET_GROUP only a hit for demuxer (mainly DVB) to allow not
91      * reading everything (you should not use this to call es_out_Control)
92      * if you don't know what to do with it, just IGNORE it, it is safe(r)
93      * -1 means all group, 0 default group (first es added) */
94     DEMUX_SET_GROUP,            /* arg1= int            can fail */
95
96     /* Ask the demux to demux until the given date at the next pf_demux call
97      * but not more (and not less, at the precision avaiable of course).
98      * XXX: not mandatory (except for subtitle demux) but I will help a lot
99      * for multi-input
100      */
101     DEMUX_SET_NEXT_DEMUX_TIME,  /* arg1= int64_t *      can fail */
102     /* FPS for correct subtitles handling */
103     DEMUX_GET_FPS,              /* arg1= float *        res=can fail    */
104     /* Meta data */
105     DEMUX_GET_META,             /* arg1= vlc_meta_t **  res=can fail    */
106
107
108     /* II. Specific access_demux queries */
109     DEMUX_CAN_PAUSE,            /* arg1= vlc_bool_t*    cannot fail */
110     DEMUX_CAN_CONTROL_PACE,     /* arg1= vlc_bool_t*    cannot fail */
111     DEMUX_GET_PTS_DELAY,        /* arg1= int64_t*       cannot fail */
112     DEMUX_SET_PAUSE_STATE       /* arg1= vlc_bool_t     can fail */
113 };
114
115 VLC_EXPORT( int,       demux2_vaControlHelper, ( stream_t *, int64_t i_start, int64_t i_end, int i_bitrate, int i_align, int i_query, va_list args ) );
116
117 /*************************************************************************
118  * Miscellaneous helpers for demuxers
119  *************************************************************************/
120
121 static inline vlc_bool_t isExtension( demux_t *p_demux, const char *psz_requested )
122 {
123     const char *psz_ext = strrchr ( p_demux->psz_path, '.' );
124     if( !psz_ext || strcmp( psz_ext, psz_requested ) )
125         return VLC_FALSE;
126     return VLC_TRUE;
127 }
128
129 static inline vlc_bool_t isDemux( demux_t *p_demux, const char *psz_requested )
130 {
131    if( !p_demux->psz_demux || strcmp( p_demux->psz_demux, psz_requested ) )
132         return VLC_FALSE;
133     return VLC_TRUE;
134 }
135
136 #define STANDARD_DEMUX_INIT \
137     p_demux->pf_control = Control; \
138     p_demux->pf_demux = Demux; \
139     MALLOC_ERR( p_demux->p_sys, demux_sys_t ); \
140     memset( p_demux->p_sys, 0, sizeof( demux_sys_t ) );
141
142 #define STANDARD_DEMUX_INIT_MSG( msg ) \
143     p_demux->pf_control = Control; \
144     p_demux->pf_demux = Demux; \
145     MALLOC_ERR( p_demux->p_sys, demux_sys_t ); \
146     memset( p_demux->p_sys, 0, sizeof( demux_sys_t ) ); \
147     msg_Dbg( p_demux, msg ); \
148
149 #define DEMUX_BY_EXTENSION( ext ) \
150     demux_t *p_demux = (demux_t *)p_this; \
151     if( !isExtension( p_demux, ext ) ) \
152         return VLC_EGENERIC; \
153     STANDARD_DEMUX_INIT;
154
155 #define DEMUX_BY_EXTENSION_MSG( ext, msg ) \
156     demux_t *p_demux = (demux_t *)p_this; \
157     if( !isExtension( p_demux, ext ) ) \
158         return VLC_EGENERIC; \
159     STANDARD_DEMUX_INIT_MSG( msg );
160
161 #define DEMUX_BY_EXTENSION_OR_FORCED( ext, module ) \
162     demux_t *p_demux = (demux_t *)p_this; \
163     if( !isExtension( p_demux, ext ) && !isDemux( p_demux, module ) ) \
164         return VLC_EGENERIC; \
165     STANDARD_DEMUX_INIT;
166
167 #define DEMUX_BY_EXTENSION_OR_FORCED_MSG( ext, module, msg ) \
168     demux_t *p_demux = (demux_t *)p_this; \
169     if( !isExtension( p_demux, ext ) && !isDemux( p_demux, module ) ) \
170         return VLC_EGENERIC; \
171     STANDARD_DEMUX_INIT_MSG( msg );
172
173 #define CHECK_PEEK( zepeek, size ) \
174     if( stream_Peek( p_demux->s , &zepeek, size ) < size ){ \
175         msg_Dbg( p_demux, "not enough data" ); return VLC_EGENERIC; }
176
177 #define CHECK_PEEK_GOTO( zepeek, size ) \
178     if( stream_Peek( p_demux->s , &zepeek, size ) < size ) { \
179         msg_Dbg( p_demux, "not enough data" ); goto error; }
180
181 #define CHECK_DISCARD_PEEK( size ) { uint8_t *p_peek; \
182     if( stream_Peek( p_demux->s , &p_peek, size ) < size ) return VLC_EGENERIC;}
183
184 #define POKE( peek, stuff, size ) (strncasecmp( (char *)peek, stuff, size )==0)
185
186 #define COMMON_INIT_PACKETIZER( location ) \
187     location = vlc_object_create( p_demux, VLC_OBJECT_DECODER ); \
188     location->pf_decode_audio = 0; \
189     location->pf_decode_video = 0; \
190     location->pf_decode_sub = 0; \
191     location->pf_packetize = 0; \
192
193 #define INIT_APACKETIZER( location, a,b,c,d ) \
194     COMMON_INIT_PACKETIZER(location ); \
195     es_format_Init( &location->fmt_in, AUDIO_ES, \
196                     VLC_FOURCC( a, b, c, d ) );
197
198 #define INIT_VPACKETIZER( location, a,b,c,d ) \
199     COMMON_INIT_PACKETIZER(location ); \
200     es_format_Init( &location->fmt_in, VIDEO_ES, \
201                     VLC_FOURCC( a, b, c, d ) );
202
203 /* BEWARE ! This can lead to memory leaks ! */
204 #define LOAD_PACKETIZER_OR_FAIL( location, msg ) \
205     location->p_module = \
206         module_Need( location, "packetizer", NULL, 0 ); \
207     if( location->p_module == NULL ) \
208     { \
209         vlc_object_destroy( location ); \
210         msg_Err( p_demux, "cannot find packetizer for " # msg ); \
211         free( p_sys ); \
212         return VLC_EGENERIC; \
213     }
214
215 #define DESTROY_PACKETIZER( location ) \
216     if( location->p_module ) module_Unneed( location, location->p_module ); \
217     vlc_object_destroy( location );
218
219 /**
220  * @}
221  */
222
223 #endif