]> git.sesse.net Git - vlc/blob - include/common.h
All decoders (audio, video, subtitles) are now modules.
[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.48 2001/11/13 12:09:17 henri 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  * Classes declaration
76  *****************************************************************************/
77
78 /* Plugins */
79 struct plugin_bank_s;
80 struct plugin_info_s;
81
82 typedef struct plugin_bank_s *          p_plugin_bank_t;
83 typedef struct plugin_info_s *          p_plugin_info_t;
84
85 /* Plugins */
86 struct playlist_s;
87 struct playlist_item_s;
88 struct module_s;
89
90 typedef struct playlist_s *             p_playlist_t;
91 typedef struct playlist_item_s *        p_playlist_item_t;
92
93 /* Interface */
94 struct intf_thread_s;
95 struct intf_sys_s;
96 struct intf_console_s;
97 struct intf_msg_s;
98 struct intf_channel_s;
99
100 typedef struct intf_thread_s *          p_intf_thread_t;
101 typedef struct intf_sys_s *             p_intf_sys_t;
102 typedef struct intf_console_s *         p_intf_console_t;
103 typedef struct intf_msg_s *             p_intf_msg_t;
104 typedef struct intf_channel_s *         p_intf_channel_t;
105
106 /* Input */
107 struct input_thread_s;
108 struct input_channel_s;
109 struct input_cfg_s;
110
111 typedef struct input_thread_s *         p_input_thread_t;
112 typedef struct input_channel_s *        p_input_channel_t;
113 typedef struct input_cfg_s *            p_input_cfg_t;
114
115 /* Audio */
116 struct aout_thread_s;
117 struct aout_sys_s;
118
119 typedef struct aout_thread_s *          p_aout_thread_t;
120 typedef struct aout_sys_s *             p_aout_sys_t;
121
122 /* Video */
123 struct vout_thread_s;
124 struct vout_font_s;
125 struct vout_sys_s;
126 struct vdec_thread_s;
127 struct vpar_thread_s;
128 struct video_parser_s;
129 struct picture_t;
130
131 typedef struct vout_thread_s *          p_vout_thread_t;
132 typedef struct vout_font_s *            p_vout_font_t;
133 typedef struct vout_sys_s *             p_vout_sys_t;
134 typedef struct vdec_thread_s *          p_vdec_thread_t;
135 typedef struct vpar_thread_s *          p_vpar_thread_t;
136 typedef struct video_parser_s *         p_video_parser_t;
137
138 /* Misc */
139 struct macroblock_s;
140 struct data_packet_s;
141 struct es_descriptor_s;
142 struct pgrm_descriptor_s;
143 struct pes_packet_s;
144 struct input_area_s;
145 struct bit_stream_s;
146
147 /* Decoders */
148 struct decoder_config_s;
149 struct decoder_fifo_s;
150
151 /*****************************************************************************
152  * Macros and inline functions
153  *****************************************************************************/
154 #ifdef NTOHL_IN_SYS_PARAM_H
155 #   include <sys/param.h>
156 #elif defined(WIN32)
157 #   include <winsock.h>
158 #else
159 #   include <netinet/in.h>
160 #endif
161
162 /* CEIL: division with round to nearest greater integer */
163 #define CEIL(n, d)  ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
164
165 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
166 #define PAD(n, d)   ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
167
168 /* MAX and MIN: self explanatory */
169 #ifndef MAX
170 #   define MAX(a, b)   ( ((a) > (b)) ? (a) : (b) )
171 #endif
172 #ifndef MIN
173 #   define MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
174 #endif
175
176 /* MSB (big endian)/LSB (little endian) conversions - network order is always
177  * MSB, and should be used for both network communications and files. Note that
178  * byte orders other than little and big endians are not supported, but only
179  * the VAX seems to have such exotic properties - note that these 'functions'
180  * needs <netinet/in.h> or the local equivalent. */
181 /* FIXME: hton64 should be declared as an extern inline function to avoid
182  * border effects (see byteorder.h) */
183 #if WORDS_BIGENDIAN
184 #   define hton16      htons
185 #   define hton32      htonl
186 #   define hton64(i)   ( i )
187 #   define ntoh16      ntohs
188 #   define ntoh32      ntohl
189 #   define ntoh64(i)   ( i )
190 #else
191 #   define hton16      htons
192 #   define hton32      htonl
193 #   define hton64(i)   ( ((u64)(htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 32) & 0xffffffff ) )
194 #   define ntoh16      ntohs
195 #   define ntoh32      ntohl
196 #   define ntoh64      hton64
197 #endif
198
199 /* Macros with automatic casts */
200 #define U64_AT(p)   ( ntoh64 ( *( (u64 *)(p) ) ) )
201 #define U32_AT(p)   ( ntoh32 ( *( (u32 *)(p) ) ) )
202 #define U16_AT(p)   ( ntoh16 ( *( (u16 *)(p) ) ) )
203
204 /* Alignment of critical static data structures */
205 #ifdef ATTRIBUTE_ALIGNED_MAX
206 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
207 #else
208 #   define ATTR_ALIGN(align)
209 #endif
210
211 /* Alignment of critical dynamic data structure */
212 #ifdef HAVE_MEMALIGN
213     /* Some systems have memalign() but no declaration for it */
214     void * memalign( size_t align, size_t size );
215 #else
216 #   ifdef HAVE_VALLOC
217         /* That's like using a hammer to kill a fly, but eh... */
218 #       include <unistd.h>
219 #       define memalign(align,size) valloc(size)
220 #   else
221         /* Assume malloc alignment is sufficient */
222 #       define memalign(align,size) malloc(size)
223 #   endif
224
225     
226 #endif
227
228 /* win32, cl and icl support */
229 #if defined( _MSC_VER )
230 #   define __attribute__(x)
231 #   define __inline__      __inline
232 #   define strncasecmp     strnicmp
233 #   define strcasecmp      stricmp
234 #   define S_ISBLK(m)      (0)
235 #   define S_ISCHR(m)      (0)
236 #   define S_ISFIFO(m)     (((m)&_S_IFMT) == _S_IFIFO)
237 #   define S_ISREG(m)      (((m)&_S_IFMT) == _S_IFREG)
238 #   define I64C(x)         x##i64
239 #else
240 #   define I64C(x)         x##LL
241 #endif
242
243 #if defined( WIN32 )
244 #   if defined( __MINGW32__ )
245 #       if !defined( _OFF_T_ )
246 typedef long long _off_t;
247 typedef _off_t off_t;
248 #           define _OFF_T_
249 #       else
250 #           define off_t long long
251 #       endif
252 #   elif defined( _MSC_VER )
253 #       if !defined( _OFF_T_DEFINED )
254 typedef __int64 off_t;
255 #           define _OFF_T_DEFINED
256 #       else
257 #           define off_t __int64
258 #       endif
259 #   endif
260 #   define stat _stati64
261 #   ifndef snprintf
262 #       define snprintf _snprintf  /* snprintf not defined in mingw32 (bug?) */
263 #   endif
264 #endif