Swedish translation update by Daniel Nylander
[vlc.git] / include / vlc_demux.h
blobb098fc36a8bd56b926d23621d8f99e71387f3aa7
1 /*****************************************************************************
2 * vlc_demux.h: Demuxer descriptor, queries and methods
3 *****************************************************************************
4 * Copyright (C) 1999-2005 the VideoLAN team
5 * $Id$
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 #if !defined( __LIBVLC__ )
25 #error You are not libvlc or one of its plugins. You cannot include this file
26 #endif
28 #ifndef _VLC_DEMUX_H
29 #define _VLC_DEMUX_H 1
31 #include <vlc_es.h>
32 #include <vlc_stream.h>
33 #include <vlc_es_out.h>
35 /**
36 * \defgroup demux Demux
37 * @{
40 struct demux_t
42 VLC_COMMON_MEMBERS
44 /* Module properties */
45 module_t *p_module;
47 /* eg informative but needed (we can have access+demux) */
48 char *psz_access;
49 char *psz_demux;
50 char *psz_path;
52 /* input stream */
53 stream_t *s; /* NULL in case of a access+demux in one */
55 /* es output */
56 es_out_t *out; /* our p_es_out */
58 /* set by demuxer */
59 int (*pf_demux) ( demux_t * ); /* demux one frame only */
60 int (*pf_control)( demux_t *, int i_query, va_list args);
62 /* Demux has to maintain them uptodate
63 * when it is responsible of seekpoint/title */
64 struct
66 unsigned int i_update; /* Demux sets them on change,
67 Input removes them once take into account*/
68 /* Seekpoint/Title at demux level */
69 int i_title; /* idem, start from 0 (could be menu) */
70 int i_seekpoint; /* idem, start from 0 */
71 } info;
72 demux_sys_t *p_sys;
76 /* demux_meta_t is returned by "meta reader" module to the demuxer */
77 struct demux_meta_t
79 vlc_meta_t *p_meta; /**< meta data */
81 int i_attachments; /**< number of attachments */
82 input_attachment_t **attachments; /**< array of attachments */
85 enum demux_query_e
87 /* I. Common queries to access_demux and demux */
88 /* POSITION double between 0.0 and 1.0 */
89 DEMUX_GET_POSITION, /* arg1= double * res= */
90 DEMUX_SET_POSITION, /* arg1= double res=can fail */
92 /* LENGTH/TIME in microsecond, 0 if unknown */
93 DEMUX_GET_LENGTH, /* arg1= int64_t * res= */
94 DEMUX_GET_TIME, /* arg1= int64_t * res= */
95 DEMUX_SET_TIME, /* arg1= int64_t res=can fail */
97 /* TITLE_INFO only if more than 1 title or 1 chapter */
98 DEMUX_GET_TITLE_INFO, /* arg1=input_title_t*** arg2=int*
99 arg3=int*pi_title_offset(0), arg4=int*pi_seekpoint_offset(0) can fail */
100 /* TITLE/SEEKPOINT, only when TITLE_INFO succeed */
101 DEMUX_SET_TITLE, /* arg1= int can fail */
102 DEMUX_SET_SEEKPOINT, /* arg1= int can fail */
104 /* DEMUX_SET_GROUP only a hit for demuxer (mainly DVB) to allow not
105 * reading everything (you should not use this to call es_out_Control)
106 * if you don't know what to do with it, just IGNORE it, it is safe(r)
107 * -1 means all group, 0 default group (first es added) */
108 DEMUX_SET_GROUP, /* arg1= int can fail */
110 /* Ask the demux to demux until the given date at the next pf_demux call
111 * but not more (and not less, at the precision avaiable of course).
112 * XXX: not mandatory (except for subtitle demux) but I will help a lot
113 * for multi-input
115 DEMUX_SET_NEXT_DEMUX_TIME, /* arg1= int64_t * can fail */
116 /* FPS for correct subtitles handling */
117 DEMUX_GET_FPS, /* arg1= double * res=can fail */
119 /* Meta data */
120 DEMUX_GET_META, /* arg1= vlc_meta_t ** res=can fail */
121 DEMUX_HAS_UNSUPPORTED_META, /* arg1= vlc_bool_t * res can fail */
123 /* Attachments */
124 DEMUX_GET_ATTACHMENTS, /* arg1=input_attachment_t***, int* res=can fail */
126 /* II. Specific access_demux queries */
127 DEMUX_CAN_PAUSE, /* arg1= vlc_bool_t* cannot fail */
128 DEMUX_CAN_CONTROL_PACE, /* arg1= vlc_bool_t* cannot fail */
129 DEMUX_GET_PTS_DELAY, /* arg1= int64_t* cannot fail */
130 DEMUX_SET_PAUSE_STATE /* arg1= vlc_bool_t can fail */
133 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 ) );
135 /*************************************************************************
136 * Miscellaneous helpers for demuxers
137 *************************************************************************/
139 static inline vlc_bool_t demux2_IsPathExtension( demux_t *p_demux, const char *psz_extension )
141 const char *psz_ext = strrchr ( p_demux->psz_path, '.' );
142 if( !psz_ext || strcasecmp( psz_ext, psz_extension ) )
143 return VLC_FALSE;
144 return VLC_TRUE;
147 static inline vlc_bool_t demux2_IsForced( demux_t *p_demux, const char *psz_name )
149 if( !p_demux->psz_demux || strcmp( p_demux->psz_demux, psz_name ) )
150 return VLC_FALSE;
151 return VLC_TRUE;
154 #define DEMUX_INIT_COMMON() do { \
155 p_demux->pf_control = Control; \
156 p_demux->pf_demux = Demux; \
157 MALLOC_ERR( p_demux->p_sys, demux_sys_t ); \
158 memset( p_demux->p_sys, 0, sizeof( demux_sys_t ) ); } while(0)
160 #define STANDARD_DEMUX_INIT_MSG( msg ) do { \
161 DEMUX_INIT_COMMON(); \
162 msg_Dbg( p_demux, msg ); } while(0)
164 #define DEMUX_BY_EXTENSION( ext ) \
165 demux_t *p_demux = (demux_t *)p_this; \
166 if( !demux2_IsPathExtension( p_demux, ext ) ) \
167 return VLC_EGENERIC; \
168 DEMUX_INIT_COMMON();
170 #define DEMUX_BY_EXTENSION_MSG( ext, msg ) \
171 demux_t *p_demux = (demux_t *)p_this; \
172 if( !demux2_IsPathExtension( p_demux, ext ) ) \
173 return VLC_EGENERIC; \
174 STANDARD_DEMUX_INIT_MSG( msg );
176 #define DEMUX_BY_EXTENSION_OR_FORCED( ext, module ) \
177 demux_t *p_demux = (demux_t *)p_this; \
178 if( !demux2_IsPathExtension( p_demux, ext ) && !demux2_IsForced( p_demux, module ) ) \
179 return VLC_EGENERIC; \
180 DEMUX_INIT_COMMON();
182 #define DEMUX_BY_EXTENSION_OR_FORCED_MSG( ext, module, msg ) \
183 demux_t *p_demux = (demux_t *)p_this; \
184 if( !demux2_IsPathExtension( p_demux, ext ) && !demux2_IsForced( p_demux, module ) ) \
185 return VLC_EGENERIC; \
186 STANDARD_DEMUX_INIT_MSG( msg );
188 #define CHECK_PEEK( zepeek, size ) \
189 if( stream_Peek( p_demux->s , &zepeek, size ) < size ){ \
190 msg_Dbg( p_demux, "not enough data" ); return VLC_EGENERIC; }
192 #define CHECK_PEEK_GOTO( zepeek, size ) \
193 if( stream_Peek( p_demux->s , &zepeek, size ) < size ) { \
194 msg_Dbg( p_demux, "not enough data" ); goto error; }
196 #define POKE( peek, stuff, size ) (strncasecmp( (const char *)peek, stuff, size )==0)
198 #define COMMON_INIT_PACKETIZER( location ) \
199 location = vlc_object_create( p_demux, VLC_OBJECT_PACKETIZER ); \
200 location->pf_decode_audio = 0; \
201 location->pf_decode_video = 0; \
202 location->pf_decode_sub = 0; \
203 location->pf_packetize = 0; \
205 #define INIT_APACKETIZER( location, a,b,c,d ) \
206 COMMON_INIT_PACKETIZER(location ); \
207 es_format_Init( &location->fmt_in, AUDIO_ES, \
208 VLC_FOURCC( a, b, c, d ) );
210 #define INIT_VPACKETIZER( location, a,b,c,d ) \
211 COMMON_INIT_PACKETIZER(location ); \
212 es_format_Init( &location->fmt_in, VIDEO_ES, \
213 VLC_FOURCC( a, b, c, d ) );
215 /* BEWARE ! This can lead to memory leaks ! */
216 #define LOAD_PACKETIZER_OR_FAIL( location, msg ) \
217 location->p_module = \
218 module_Need( location, "packetizer", NULL, 0 ); \
219 if( location->p_module == NULL ) \
221 vlc_object_destroy( location ); \
222 msg_Err( p_demux, "cannot find packetizer for " # msg ); \
223 free( p_sys ); \
224 return VLC_EGENERIC; \
227 #define DESTROY_PACKETIZER( location ) \
228 if( location->p_module ) module_Unneed( location, location->p_module ); \
229 vlc_object_destroy( location );
232 * @}
235 #endif