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 $
8 * Authors: Samuel Hocevar <sam@via.ecp.fr>
9 * Vincent Seguin <seguin@via.ecp.fr>
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.
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.
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 *****************************************************************************/
26 /*****************************************************************************
29 *****************************************************************************/
31 /*****************************************************************************
32 * Basic types definitions
33 *****************************************************************************/
35 #include "int_types.h"
40 #ifdef BOOLEAN_T_IN_SYS_TYPES_H
41 # include <sys/types.h>
42 #elif defined(BOOLEAN_T_IN_PTHREAD_H)
44 #elif defined(BOOLEAN_T_IN_CTHREADS_H)
45 # include <cthreads.h>
47 typedef int boolean_t;
50 # define _MACH_I386_BOOLEAN_H_
53 /* ptrdiff_t definition */
60 /* Not portable in a 64-bit environment. */
61 typedef int ptrdiff_t;
65 /* Counter for statistics and profiling */
66 typedef unsigned long count_t;
68 /* DCT elements types */
69 typedef s16 dctelem_t;
71 /* Video buffer types */
72 typedef u8 yuv_data_t;
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 *****************************************************************************/
86 /*****************************************************************************
88 *****************************************************************************/
94 typedef struct plugin_bank_s * p_plugin_bank_t;
95 typedef struct plugin_info_s * p_plugin_info_t;
99 struct playlist_item_s;
102 typedef struct playlist_s * p_playlist_t;
103 typedef struct playlist_item_s * p_playlist_item_t;
106 struct intf_thread_s;
108 struct intf_console_s;
110 struct intf_channel_s;
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;
119 struct input_thread_s;
120 struct input_channel_s;
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;
128 struct aout_thread_s;
131 typedef struct aout_thread_s * p_aout_thread_t;
132 typedef struct aout_sys_s * p_aout_sys_t;
135 struct vout_thread_s;
138 struct vdec_thread_s;
139 struct vpar_thread_s;
140 struct video_parser_s;
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;
151 struct data_packet_s;
152 struct es_descriptor_s;
153 struct pgrm_descriptor_s;
159 struct decoder_config_s;
160 struct decoder_fifo_s;
162 /*****************************************************************************
163 * Macros and inline functions
164 *****************************************************************************/
165 #ifdef NTOHL_IN_SYS_PARAM_H
166 # include <sys/param.h>
168 # include "bytes_swap.h"
170 # include <netinet/in.h>
173 /* CEIL: division with round to nearest greater integer */
174 #define CEIL(n, d) ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
176 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
177 #define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
179 /* MAX and MIN: self explanatory */
181 # define MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
184 # define MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
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) */
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 )
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
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) ) ) )
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)))
219 # define ATTR_ALIGN(align)
222 /* Alignment of critical dynamic data structure */
224 /* Some systems have memalign() but no declaration for it */
225 void * memalign( size_t align, size_t size );
228 /* That's like using a hammer to kill a fly, but eh... */
230 # define memalign(align,size) valloc(size)
232 /* Assume malloc alignment is sufficient */
233 # define memalign(align,size) malloc(size)
238 #define I64C(x) x##LL
241 /* The win32 specific stuff was getting really big so it has been moved */
243 # include "common_win32.h"
246 /*****************************************************************************
248 *****************************************************************************/
249 typedef struct module_symbols_s
251 struct main_s* p_main;
252 struct aout_bank_s* p_aout_bank;
253 struct vout_bank_s* p_vout_bank;
255 int ( * main_GetIntVariable ) ( char *, int );
256 char * ( * main_GetPszVariable ) ( char *, char * );
257 void ( * main_PutIntVariable ) ( char *, int );
258 void ( * main_PutPszVariable ) ( char *, char * );
260 int ( * TestProgram ) ( char * );
261 int ( * TestMethod ) ( char *, char * );
262 int ( * TestCPU ) ( int );
264 int ( * intf_ProcessKey ) ( struct intf_thread_s *, int );
265 void ( * intf_AssignKey ) ( struct intf_thread_s *, int, int, int );
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 *, ... );
273 void ( * intf_DbgMsg ) ( char *, char *, int, char *, ... );
274 void ( * intf_DbgMsgImm ) ( char *, char *, int, char *, ... );
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 * );
285 void ( * msleep ) ( mtime_t );
286 mtime_t ( * mdate ) ( void );
288 int ( * network_ChannelCreate )( void );
289 int ( * network_ChannelJoin ) ( int );
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 *,
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 *,
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 * );
319 void ( * InitBitstream ) ( struct bit_stream_s *,
320 struct decoder_fifo_s *,
321 void ( * ) ( struct bit_stream_s *,
324 int ( * input_InitStream ) ( struct input_thread_s *, size_t );
325 void ( * input_EndStream ) ( struct input_thread_s * );
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 );
346 int ( * input_ClockManageControl ) ( struct input_thread_s *,
347 struct pgrm_descriptor_s *,
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 * );
362 struct aout_fifo_s * ( * aout_CreateFifo )
363 ( int, int, long, long, long, void * );
364 void ( * aout_DestroyFifo ) ( struct aout_fifo_s * );
366 struct vout_thread_s * (* vout_CreateThread) ( int *, int, int );
367 struct subpicture_s * (* vout_CreateSubPicture) ( struct vout_thread_s *,
369 struct picture_s * ( * vout_CreatePicture ) ( struct vout_thread_s *,
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 );
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 );
391 char * ( * DecodeLanguage ) ( u16 );
393 struct module_s * ( * module_Need ) ( int, void * );
394 void ( * module_Unneed ) ( struct module_s * );
398 extern module_symbols_t* p_symbols;