]> git.sesse.net Git - vlc/blob - include/common.h
5064b4d183d82ddfb5aa8b5cb04d800ca1810270
[vlc] / include / common.h
1 /*****************************************************************************
2  * common.h: common definitions
3  * Collection of useful common types and macros definitions
4  *****************************************************************************
5  * Copyright (C) 1998, 1999, 2000 VideoLAN
6  * $Id: common.h,v 1.51 2001/11/28 15:08:04 massiot Exp $
7  *
8  * Authors: Samuel Hocevar <sam@via.ecp.fr>
9  *          Vincent Seguin <seguin@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * required headers:
28  *  config.h
29  *****************************************************************************/
30
31 /*****************************************************************************
32  * Basic types definitions
33  *****************************************************************************/
34
35 #include "int_types.h"
36
37 typedef u8                  byte_t;
38
39 /* Boolean type */
40 #ifdef BOOLEAN_T_IN_SYS_TYPES_H
41 #   include <sys/types.h>
42 #elif defined(BOOLEAN_T_IN_PTHREAD_H)
43 #   include <pthread.h>
44 #elif defined(BOOLEAN_T_IN_CTHREADS_H)
45 #   include <cthreads.h>
46 #else
47 typedef int                 boolean_t;
48 #endif
49 #ifdef SYS_GNU
50 #   define _MACH_I386_BOOLEAN_H_
51 #endif
52
53 /* ptrdiff_t definition */
54 #ifdef HAVE_STDDEF_H
55 #   include <stddef.h>
56 #else
57 #   include <malloc.h>
58 #   ifndef _PTRDIFF_T
59 #       define _PTRDIFF_T
60 /* Not portable in a 64-bit environment. */
61 typedef int                 ptrdiff_t;
62 #   endif
63 #endif
64
65 /* Counter for statistics and profiling */
66 typedef unsigned long       count_t;
67
68 /* DCT elements types */
69 typedef s16                 dctelem_t;
70
71 /* Video buffer types */
72 typedef u8                  yuv_data_t;
73
74 /*****************************************************************************
75  * mtime_t: high precision date or time interval
76  *****************************************************************************
77  * Store an high precision date or time interval. The maximum precision is the
78  * micro-second, and a 64 bits integer is used to avoid any overflow (maximum
79  * time interval is then 292271 years, which should be length enough for any
80  * video). Date are stored as a time interval since a common date.
81  * Note that date and time intervals can be manipulated using regular arithmetic
82  * operators, and that no special functions are required.
83  *****************************************************************************/
84 typedef s64 mtime_t;
85
86 /*****************************************************************************
87  * Classes declaration
88  *****************************************************************************/
89
90 /* Plugins */
91 struct plugin_bank_s;
92 struct plugin_info_s;
93
94 typedef struct plugin_bank_s *          p_plugin_bank_t;
95 typedef struct plugin_info_s *          p_plugin_info_t;
96
97 /* Plugins */
98 struct playlist_s;
99 struct playlist_item_s;
100 struct module_s;
101
102 typedef struct playlist_s *             p_playlist_t;
103 typedef struct playlist_item_s *        p_playlist_item_t;
104
105 /* Interface */
106 struct intf_thread_s;
107 struct intf_sys_s;
108 struct intf_console_s;
109 struct intf_msg_s;
110 struct intf_channel_s;
111
112 typedef struct intf_thread_s *          p_intf_thread_t;
113 typedef struct intf_sys_s *             p_intf_sys_t;
114 typedef struct intf_console_s *         p_intf_console_t;
115 typedef struct intf_msg_s *             p_intf_msg_t;
116 typedef struct intf_channel_s *         p_intf_channel_t;
117
118 /* Input */
119 struct input_thread_s;
120 struct input_channel_s;
121 struct input_cfg_s;
122
123 typedef struct input_thread_s *         p_input_thread_t;
124 typedef struct input_channel_s *        p_input_channel_t;
125 typedef struct input_cfg_s *            p_input_cfg_t;
126
127 /* Audio */
128 struct aout_thread_s;
129 struct aout_sys_s;
130
131 typedef struct aout_thread_s *          p_aout_thread_t;
132 typedef struct aout_sys_s *             p_aout_sys_t;
133
134 /* Video */
135 struct vout_thread_s;
136 struct vout_font_s;
137 struct vout_sys_s;
138 struct vdec_thread_s;
139 struct vpar_thread_s;
140 struct video_parser_s;
141
142 typedef struct vout_thread_s *          p_vout_thread_t;
143 typedef struct vout_font_s *            p_vout_font_t;
144 typedef struct vout_sys_s *             p_vout_sys_t;
145 typedef struct vdec_thread_s *          p_vdec_thread_t;
146 typedef struct vpar_thread_s *          p_vpar_thread_t;
147 typedef struct video_parser_s *         p_video_parser_t;
148
149 /* Misc */
150 struct macroblock_s;
151 struct data_packet_s;
152 struct es_descriptor_s;
153 struct pgrm_descriptor_s;
154 struct pes_packet_s;
155 struct input_area_s;
156 struct bit_stream_s;
157
158 /* Decoders */
159 struct decoder_config_s;
160 struct decoder_fifo_s;
161
162 /*****************************************************************************
163  * Macros and inline functions
164  *****************************************************************************/
165 #ifdef NTOHL_IN_SYS_PARAM_H
166 #   include <sys/param.h>
167 #elif defined(WIN32)
168 #   include "bytes_swap.h"
169 #else
170 #   include <netinet/in.h>
171 #endif
172
173 /* CEIL: division with round to nearest greater integer */
174 #define CEIL(n, d)  ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
175
176 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
177 #define PAD(n, d)   ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
178
179 /* MAX and MIN: self explanatory */
180 #ifndef MAX
181 #   define MAX(a, b)   ( ((a) > (b)) ? (a) : (b) )
182 #endif
183 #ifndef MIN
184 #   define MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
185 #endif
186
187 /* MSB (big endian)/LSB (little endian) conversions - network order is always
188  * MSB, and should be used for both network communications and files. Note that
189  * byte orders other than little and big endians are not supported, but only
190  * the VAX seems to have such exotic properties - note that these 'functions'
191  * needs <netinet/in.h> or the local equivalent. */
192 /* FIXME: hton64 should be declared as an extern inline function to avoid
193  * border effects (see byteorder.h) */
194 #if WORDS_BIGENDIAN
195 #   define hton16      htons
196 #   define hton32      htonl
197 #   define hton64(i)   ( i )
198 #   define ntoh16      ntohs
199 #   define ntoh32      ntohl
200 #   define ntoh64(i)   ( i )
201 #else
202 #   define hton16      htons
203 #   define hton32      htonl
204 #   define hton64(i)   ( ((u64)(htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 32) & 0xffffffff ) )
205 #   define ntoh16      ntohs
206 #   define ntoh32      ntohl
207 #   define ntoh64      hton64
208 #endif
209
210 /* Macros with automatic casts */
211 #define U64_AT(p)   ( ntoh64 ( *( (u64 *)(p) ) ) )
212 #define U32_AT(p)   ( ntoh32 ( *( (u32 *)(p) ) ) )
213 #define U16_AT(p)   ( ntoh16 ( *( (u16 *)(p) ) ) )
214
215 /* Alignment of critical static data structures */
216 #ifdef ATTRIBUTE_ALIGNED_MAX
217 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
218 #else
219 #   define ATTR_ALIGN(align)
220 #endif
221
222 /* Alignment of critical dynamic data structure */
223 #ifdef HAVE_MEMALIGN
224     /* Some systems have memalign() but no declaration for it */
225     void * memalign( size_t align, size_t size );
226 #else
227 #   ifdef HAVE_VALLOC
228         /* That's like using a hammer to kill a fly, but eh... */
229 #       include <unistd.h>
230 #       define memalign(align,size) valloc(size)
231 #   else
232         /* Assume malloc alignment is sufficient */
233 #       define memalign(align,size) malloc(size)
234 #   endif    
235 #endif
236
237
238 #define I64C(x)         x##LL
239
240
241 /* The win32 specific stuff was getting really big so it has been moved */
242 #if defined( WIN32 )
243 #   include "common_win32.h"
244 #endif
245
246 /*****************************************************************************
247  * Plug-in stuff
248  *****************************************************************************/
249 typedef struct module_symbols_s
250 {
251     struct main_s* p_main;
252     struct aout_bank_s* p_aout_bank;
253     struct vout_bank_s* p_vout_bank;
254
255     int    ( * main_GetIntVariable ) ( char *, int );
256     char * ( * main_GetPszVariable ) ( char *, char * );
257     void   ( * main_PutIntVariable ) ( char *, int );
258     void   ( * main_PutPszVariable ) ( char *, char * );
259
260     int  ( * TestProgram )  ( char * );
261     int  ( * TestMethod )   ( char *, char * );
262     int  ( * TestCPU )      ( int );
263
264     int  ( * intf_ProcessKey ) ( struct intf_thread_s *, int );
265     void ( * intf_AssignKey )  ( struct intf_thread_s *, int, int, int );
266
267     void ( * intf_Msg )        ( char *, ... );
268     void ( * intf_ErrMsg )     ( char *, ... );
269     void ( * intf_StatMsg )    ( char *, ... );
270     void ( * intf_WarnMsg )    ( int, char *, ... );
271     void ( * intf_WarnMsgImm ) ( int, char *, ... );
272 #ifdef TRACE
273     void ( * intf_DbgMsg )     ( char *, char *, int, char *, ... );
274     void ( * intf_DbgMsgImm )  ( char *, char *, int, char *, ... );
275 #endif
276
277     int  ( * intf_PlaylistAdd )     ( struct playlist_s *, int, const char* );
278     int  ( * intf_PlaylistDelete )  ( struct playlist_s *, int );
279     void ( * intf_PlaylistNext )    ( struct playlist_s * );
280     void ( * intf_PlaylistPrev )    ( struct playlist_s * );
281     void ( * intf_PlaylistDestroy ) ( struct playlist_s * );
282     void ( * intf_PlaylistJumpto )  ( struct playlist_s *, int );
283     void ( * intf_UrlDecode )       ( char * );
284
285     void    ( * msleep )         ( mtime_t );
286     mtime_t ( * mdate )          ( void );
287
288     int  ( * network_ChannelCreate )( void );
289     int  ( * network_ChannelJoin )  ( int );
290
291     void ( * input_SetStatus )      ( struct input_thread_s *, int );
292     void ( * input_Seek )           ( struct input_thread_s *, off_t );
293     void ( * input_DumpStream )     ( struct input_thread_s * );
294     char * ( * input_OffsetToTime ) ( struct input_thread_s *, char *, off_t );
295     int  ( * input_ChangeES )       ( struct input_thread_s *,
296                                       struct es_descriptor_s *, u8 );
297     int  ( * input_ToggleES )       ( struct input_thread_s *,
298                                       struct es_descriptor_s *, boolean_t );
299     int  ( * input_ChangeArea )     ( struct input_thread_s *,
300                                       struct input_area_s * );
301     struct es_descriptor_s * ( * input_FindES ) ( struct input_thread_s *,
302                                                   u16 );
303     struct es_descriptor_s * ( * input_AddES ) ( struct input_thread_s *,
304                                       struct pgrm_descriptor_s *, u16, size_t );
305     void ( * input_DelES )          ( struct input_thread_s *,
306                                       struct es_descriptor_s * );
307     int  ( * input_SelectES )       ( struct input_thread_s *,
308                                       struct es_descriptor_s * );
309     int  ( * input_UnselectES )     ( struct input_thread_s *,
310                                       struct es_descriptor_s * );
311     struct pgrm_descriptor_s* ( * input_AddProgram ) ( struct input_thread_s *,
312                                                        u16, size_t );
313     void ( * input_DelProgram )     ( struct input_thread_s *,
314                                       struct pgrm_descriptor_s * );
315     struct input_area_s * ( * input_AddArea ) ( struct input_thread_s * );
316     void ( * input_DelArea )        ( struct input_thread_s *,
317                                       struct input_area_s * );
318
319     void ( * InitBitstream )        ( struct bit_stream_s *,
320                                       struct decoder_fifo_s *,
321                                       void ( * ) ( struct bit_stream_s *,
322                                                    boolean_t ),
323                                       void * );
324     int  ( * input_InitStream )     ( struct input_thread_s *, size_t );
325     void ( * input_EndStream )      ( struct input_thread_s * );
326
327     void ( * input_ParsePES )       ( struct input_thread_s *,
328                                       struct es_descriptor_s * );
329     void ( * input_GatherPES )      ( struct input_thread_s *,
330                                       struct data_packet_s *,
331                                       struct es_descriptor_s *,
332                                       boolean_t, boolean_t );
333     void ( * input_DecodePES )      ( struct decoder_fifo_s *,
334                                       struct pes_packet_s * );
335     struct es_descriptor_s * ( * input_ParsePS ) ( struct input_thread_s *,
336                                                    struct data_packet_s * );
337     void ( * input_DemuxPS )        ( struct input_thread_s *,
338                                       struct data_packet_s * );
339     void ( * input_DemuxTS )        ( struct input_thread_s *,
340                                       struct data_packet_s * );
341     void ( * input_DemuxPSI )       ( struct input_thread_s *,
342                                       struct data_packet_s *,
343                                       struct es_descriptor_s *, 
344                                       boolean_t, boolean_t );
345
346     int ( * input_ClockManageControl )   ( struct input_thread_s *,
347                                            struct pgrm_descriptor_s *,
348                                            mtime_t );
349
350     int ( * input_NetlistInit )          ( struct input_thread_s *,
351                                            int, int, int, size_t, int );
352     struct iovec * ( * input_NetlistGetiovec ) ( void * p_method_data );
353     void ( * input_NetlistMviovec )      ( void * , int,
354                                            struct data_packet_s **);
355     struct data_packet_s * ( * input_NetlistNewPacket ) ( void *, size_t );
356     struct data_packet_s * ( * input_NetlistNewPtr ) ( void * );
357     struct pes_packet_s * ( * input_NetlistNewPES ) ( void * );
358     void ( * input_NetlistDeletePacket ) ( void *, struct data_packet_s * );
359     void ( * input_NetlistDeletePES )    ( void *, struct pes_packet_s * );
360     void ( * input_NetlistEnd )          ( struct input_thread_s * );
361
362     struct aout_fifo_s * ( * aout_CreateFifo ) 
363                                        ( int, int, long, long, long, void * );
364     void ( * aout_DestroyFifo )     ( struct aout_fifo_s * );
365
366     struct vout_thread_s * (* vout_CreateThread) ( int *, int, int );
367     struct subpicture_s * (* vout_CreateSubPicture) ( struct vout_thread_s *, 
368                                                       int, int );
369     struct picture_s * ( * vout_CreatePicture ) ( struct vout_thread_s *, 
370                                                   int, int, int );
371
372     void  ( * vout_DestroySubPicture )  ( struct vout_thread_s *, 
373                                           struct subpicture_s * );
374     void  ( * vout_DisplaySubPicture )  ( struct vout_thread_s *, 
375                                           struct subpicture_s * );
376     void  ( * vout_DisplayPicture ) ( struct vout_thread_s *, 
377                                       struct picture_s * );
378     void  ( * vout_DestroyPicture ) ( struct vout_thread_s *,
379                                       struct picture_s * );
380     void  ( * vout_LinkPicture )    ( struct vout_thread_s *,
381                                       struct picture_s * );
382     void  ( * vout_UnlinkPicture )    ( struct vout_thread_s *,
383                                       struct picture_s * );
384     void  ( * vout_DatePicture )    ( struct vout_thread_s *p_vout, 
385                                       struct picture_s *p_pic, mtime_t );
386     
387     u32  ( * UnalignedShowBits )    ( struct bit_stream_s *, unsigned int );
388     void ( * UnalignedRemoveBits )  ( struct bit_stream_s * );
389     u32  ( * UnalignedGetBits )     ( struct bit_stream_s *, unsigned int );
390
391     char * ( * DecodeLanguage ) ( u16 );
392
393     struct module_s * ( * module_Need )    ( int, void * );
394     void ( * module_Unneed )        ( struct module_s * );
395 } module_symbols_t;
396
397 #ifdef PLUGIN
398 extern module_symbols_t* p_symbols;
399 #endif