]> git.sesse.net Git - vlc/blob - include/common.h
8f5446a2e7d6902ef990a1ee2dc7512934e4c5fb
[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.24 2001/01/13 12:57:19 sam 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 #else
43 typedef int                 boolean_t;
44 #endif
45 #ifdef SYS_GNU
46 #   define _MACH_I386_BOOLEAN_H_
47 #endif
48
49 /* ptrdiff_t definition */
50 #ifdef HAVE_STDDEF_H
51 #   include <stddef.h>
52 #else
53 #   include <malloc.h>
54 #   ifndef _PTRDIFF_T
55 #       define _PTRDIFF_T
56 /* Not portable in a 64-bit environment. */
57 typedef int                 ptrdiff_t;
58 #   endif
59 #endif
60
61 /* Counter for statistics and profiling */
62 typedef unsigned long       count_t;
63
64 /* DCT elements types */
65 #ifndef VDEC_DFT
66 typedef short dctelem_t;
67 #else
68 typedef int dctelem_t;
69 #endif
70
71 /*****************************************************************************
72  * Classes declaration
73  *****************************************************************************/
74
75 /* Plugins */
76 struct plugin_bank_s;
77 struct plugin_info_s;
78
79 typedef struct plugin_bank_s *          p_plugin_bank_t;
80 typedef struct plugin_info_s *          p_plugin_info_t;
81
82 /* Playlist */
83 struct playlist_s;
84
85 typedef struct playlist_s *             p_playlist_t;
86
87 /* Interface */
88 struct intf_thread_s;
89 struct intf_sys_s;
90 struct intf_console_s;
91 struct intf_msg_s;
92 struct intf_channel_s;
93
94 typedef struct intf_thread_s *          p_intf_thread_t;
95 typedef struct intf_sys_s *             p_intf_sys_t;
96 typedef struct intf_console_s *         p_intf_console_t;
97 typedef struct intf_msg_s *             p_intf_msg_t;
98 typedef struct intf_channel_s *         p_intf_channel_t;
99
100 /* Input */
101 struct input_thread_s;
102 struct input_vlan_s;
103 struct input_cfg_s;
104
105 typedef struct input_thread_s *         p_input_thread_t;
106 typedef struct input_vlan_s *           p_input_vlan_t;
107 typedef struct input_cfg_s *            p_input_cfg_t;
108
109 /* Audio */
110 struct aout_thread_s;
111 struct aout_sys_s;
112
113 typedef struct aout_thread_s *          p_aout_thread_t;
114 typedef struct aout_sys_s *             p_aout_sys_t;
115
116 /* Video */
117 struct vout_thread_s;
118 struct vout_font_s;
119 struct vout_sys_s;
120 struct vdec_thread_s;
121 struct vpar_thread_s;
122 struct video_parser_s;
123
124 typedef struct vout_thread_s *          p_vout_thread_t;
125 typedef struct vout_font_s *            p_vout_font_t;
126 typedef struct vout_sys_s *             p_vout_sys_t;
127 typedef struct vdec_thread_s *          p_vdec_thread_t;
128 typedef struct vpar_thread_s *          p_vpar_thread_t;
129 typedef struct video_parser_s *         p_video_parser_t;
130
131 /*****************************************************************************
132  * Macros and inline functions
133  *****************************************************************************/
134
135 #ifdef NTOHL_IN_SYS_PARAM_H
136 #   include <sys/param.h>
137 #else
138 #   include <netinet/in.h>
139 #endif
140
141 /* CEIL: division with round to nearest greater integer */
142 #define CEIL(n, d)  ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
143
144 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
145 #define PAD(n, d)   ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
146
147 /* MAX and MIN: self explanatory */
148 #ifndef MAX
149 #define MAX(a, b)   ( ((a) > (b)) ? (a) : (b) )
150 #endif
151 #ifndef MIN
152 #define MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
153 #endif
154
155 /*
156  * This is stolen from the livid source who stole it from the kernel
157  */
158
159 #if defined(SYS_BEOS)
160 #   define swab32(x) B_BENDIAN_TO_HOST_INT32(x)
161 #else
162 #   ifdef WORDS_BIG_ENDIAN
163 #       define swab32(x) (x)
164 #   else
165 #       if defined (HAVE_X86_BSWAP)
166 static __inline__ const u32 __i386_swab32( u32 x )
167 {
168     __asm__("bswap %0" : "=r" (x) : "0" (x));
169     return x;
170 }
171 #           define swab32(x) __i386_swab32(x)
172 #       else
173 #           define swab32(x)                                                 \
174             ( ( (u32)(((u8*)&x)[0]) << 24 ) | ( (u32)(((u8*)&x)[1]) << 16 ) |\
175               ( (u32)(((u8*)&x)[2]) << 8 )  | ( (u32)(((u8*)&x)[3])) )
176 #       endif
177 #   endif
178 #endif
179
180 /* MSB (big endian)/LSB (little endian) conversions - network order is always
181  * MSB, and should be used for both network communications and files. Note that
182  * byte orders other than little and big endians are not supported, but only
183  * the VAX seems to have such exotic properties - note that these 'functions'
184  * needs <netinet/in.h> or the local equivalent. */
185 /* FIXME: hton64 should be declared as an extern inline function to avoid
186  * border effects (see byteorder.h) */
187 #if WORDS_BIGENDIAN
188 #define hton16      htons
189 #define hton32      htonl
190 #define hton64(i)   ( i )
191 #define ntoh16      ntohs
192 #define ntoh32      ntohl
193 #define ntoh64(i)   ( i )
194 #else
195 #define hton16      htons
196 #define hton32      htonl
197 #define hton64(i)   ( ((u64)(htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 32) & 0xffffffff ) )
198 #define ntoh16      ntohs
199 #define ntoh32      ntohl
200 #define ntoh64      hton64
201 #endif
202
203 /* Macros with automatic casts */
204 #define U32_AT(p)   ( swab32 ( *( (u32 *)(p) ) ) )
205 #define U16_AT(p)   ( ntohs ( *( (u16 *)(p) ) ) )
206