Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vlc_common.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * common.h: common definitions
00003  * Collection of useful common types and macros definitions
00004  *****************************************************************************
00005  * Copyright (C) 1998-2005 the VideoLAN team
00006  * $Id: vlc_common.h 12649 2005-09-22 20:14:20Z gbazin $
00007  *
00008  * Authors: Samuel Hocevar <[email protected]>
00009  *          Vincent Seguin <[email protected]>
00010  *          Gildas Bazin <[email protected]>
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00025  *****************************************************************************/
00026 
00032 /*****************************************************************************
00033  * Required vlc headers
00034  *****************************************************************************/
00035 #if defined( __BORLANDC__ )
00036 #   undef PACKAGE
00037 #endif
00038 
00039 #include "config.h"
00040 
00041 #if defined(PACKAGE)
00042 #   undef PACKAGE_NAME
00043 #   define PACKAGE_NAME PACKAGE
00044 #endif
00045 #if defined(VERSION)
00046 #   undef PACKAGE_VERSION
00047 #   define PACKAGE_VERSION VERSION
00048 #endif
00049 
00050 #if defined( __BORLANDC__ )
00051 #   undef HAVE_VARIADIC_MACROS
00052 #   undef HAVE_STDINT_H
00053 #   undef HAVE_INTTYPES_H
00054 #   undef off_t
00055 #elif defined( _MSC_VER )
00056 #   pragma warning( disable : 4244 )
00057 #endif
00058 
00059 #include "vlc_config.h"
00060 #include "modules_inner.h"
00061 
00062 /*****************************************************************************
00063  * Required system headers
00064  *****************************************************************************/
00065 #include <stdlib.h>
00066 #include <stdarg.h>
00067 
00068 #ifdef HAVE_STRING_H
00069 #   include <string.h>                                         /* strerror() */
00070 #endif
00071 
00072 #ifdef HAVE_SYS_TYPES_H
00073 #   include <sys/types.h>
00074 #endif
00075 
00076 /*****************************************************************************
00077  * Basic types definitions
00078  *****************************************************************************/
00079 #if defined( HAVE_STDINT_H )
00080 #   include <stdint.h>
00081 #elif defined( HAVE_INTTYPES_H )
00082 #   include <inttypes.h>
00083 #elif defined( SYS_CYGWIN )
00084 #   include <sys/types.h>
00085     /* Cygwin only defines half of these... */
00086     typedef u_int8_t            uint8_t;
00087     typedef u_int16_t           uint16_t;
00088     typedef u_int32_t           uint32_t;
00089     typedef u_int64_t           uint64_t;
00090 #else
00091     /* Fallback types (very x86-centric, sorry) */
00092     typedef unsigned char       uint8_t;
00093     typedef signed char         int8_t;
00094     typedef unsigned short      uint16_t;
00095     typedef signed short        int16_t;
00096     typedef unsigned int        uint32_t;
00097     typedef signed int          int32_t;
00098 #   if defined( _MSC_VER ) \
00099       || defined( UNDER_CE ) \
00100       || ( defined( WIN32 ) && !defined( __MINGW32__ ) )
00101     typedef unsigned __int64    uint64_t;
00102     typedef signed __int64      int64_t;
00103 #   else
00104     typedef unsigned long long  uint64_t;
00105     typedef signed long long    int64_t;
00106 #   endif
00107     typedef uint32_t            uintptr_t;
00108     typedef int32_t             intptr_t;
00109 #endif
00110 
00111 typedef uint8_t                 byte_t;
00112 
00113 /* Systems that don't have stdint.h may not define INT64_MIN and
00114    INT64_MAX */
00115 #ifndef INT64_MIN
00116 #define INT64_MIN (-9223372036854775807LL-1)
00117 #endif
00118 #ifndef INT64_MAX
00119 #define INT64_MAX (9223372036854775807LL)
00120 #endif
00121 
00122 /* ptrdiff_t definition */
00123 #ifdef HAVE_STDDEF_H
00124 #   include <stddef.h>
00125 #else
00126 #   include <malloc.h>
00127 #   ifndef _PTRDIFF_T
00128 #       define _PTRDIFF_T
00129 /* Not portable in a 64-bit environment. */
00130 typedef int                 ptrdiff_t;
00131 #   endif
00132 #endif
00133 
00134 #if defined( WIN32 ) || defined( UNDER_CE )
00135 #   include <malloc.h>
00136 #   ifndef PATH_MAX
00137 #       define PATH_MAX MAX_PATH
00138 #   endif
00139 #endif
00140 
00141 #if (defined( WIN32 ) || defined( UNDER_CE )) && !defined( _SSIZE_T_ )
00142 typedef int                 ssize_t;
00143 #endif
00144 
00145 /* Counter for statistics and profiling */
00146 typedef unsigned long       count_t;
00147 
00148 /* DCT elements types */
00149 typedef int16_t             dctelem_t;
00150 
00151 /* Video buffer types */
00152 typedef uint8_t             yuv_data_t;
00153 
00154 /* Audio volume */
00155 typedef uint16_t            audio_volume_t;
00156 
00157 #ifndef HAVE_SOCKLEN_T
00158 typedef int                 socklen_t;
00159 #endif
00160 
00171 typedef int64_t mtime_t;
00172 
00178 typedef uint32_t vlc_fourcc_t;
00179 
00180 #ifdef WORDS_BIGENDIAN
00181 #   define VLC_FOURCC( a, b, c, d ) \
00182         ( ((uint32_t)d) | ( ((uint32_t)c) << 8 ) \
00183            | ( ((uint32_t)b) << 16 ) | ( ((uint32_t)a) << 24 ) )
00184 #   define VLC_TWOCC( a, b ) \
00185         ( (uint16_t)(b) | ( (uint16_t)(a) << 8 ) )
00186 
00187 #else
00188 #   define VLC_FOURCC( a, b, c, d ) \
00189         ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
00190            | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
00191 #   define VLC_TWOCC( a, b ) \
00192         ( (uint16_t)(a) | ( (uint16_t)(b) << 8 ) )
00193 
00194 #endif
00195 
00196 /*****************************************************************************
00197  * Classes declaration
00198  *****************************************************************************/
00199 
00200 /* Internal types */
00201 typedef struct libvlc_t libvlc_t;
00202 typedef struct vlc_t vlc_t;
00203 typedef struct variable_t variable_t;
00204 typedef struct date_t date_t;
00205 
00206 /* Messages */
00207 typedef struct msg_bank_t msg_bank_t;
00208 typedef struct msg_subscription_t msg_subscription_t;
00209 
00210 /* Playlist */
00211 
00212 /* FIXME */
00216 typedef enum {
00217     PLAYLIST_PLAY,      
00218     PLAYLIST_AUTOPLAY,  
00219     PLAYLIST_VIEWPLAY,  
00221     PLAYLIST_ITEMPLAY,  
00222     PLAYLIST_PAUSE,     
00223     PLAYLIST_STOP,      
00224     PLAYLIST_SKIP,      
00225     PLAYLIST_GOTO,      
00226     PLAYLIST_VIEWGOTO,      
00227 } playlist_command_t;
00228 
00229 
00230 typedef struct playlist_t playlist_t;
00231 typedef struct playlist_item_t playlist_item_t;
00232 typedef struct playlist_view_t playlist_view_t;
00233 typedef struct playlist_export_t playlist_export_t;
00234 typedef struct services_discovery_t services_discovery_t;
00235 typedef struct services_discovery_sys_t services_discovery_sys_t;
00236 typedef struct playlist_add_t playlist_add_t;
00237 typedef struct playlist_preparse_t playlist_preparse_t;
00238 
00239 /* Modules */
00240 typedef struct module_bank_t module_bank_t;
00241 typedef struct module_t module_t;
00242 typedef struct module_config_t module_config_t;
00243 typedef struct module_symbols_t module_symbols_t;
00244 typedef struct module_cache_t module_cache_t;
00245 
00246 typedef struct config_category_t config_category_t;
00247 
00248 /* Interface */
00249 typedef struct intf_thread_t intf_thread_t;
00250 typedef struct intf_sys_t intf_sys_t;
00251 typedef struct intf_console_t intf_console_t;
00252 typedef struct intf_msg_t intf_msg_t;
00253 typedef struct intf_channel_t intf_channel_t;
00254 
00255 /* Input */
00256 typedef struct input_thread_t input_thread_t;
00257 typedef struct input_thread_sys_t input_thread_sys_t;
00258 typedef struct input_item_t input_item_t;
00259 typedef struct input_area_t input_area_t;
00260 typedef struct input_buffers_t input_buffers_t;
00261 typedef struct input_socket_t input_socket_t;
00262 typedef struct access_sys_t access_sys_t;
00263 typedef struct demux_sys_t demux_sys_t;
00264 typedef struct es_descriptor_t es_descriptor_t;
00265 typedef struct es_sys_t es_sys_t;
00266 typedef struct pgrm_descriptor_t pgrm_descriptor_t;
00267 typedef struct pgrm_sys_t pgrm_sys_t;
00268 typedef struct stream_descriptor_t stream_descriptor_t;
00269 typedef struct seekpoint_t seekpoint_t;
00270 typedef struct info_t info_t;
00271 typedef struct info_category_t info_category_t;
00272 
00273 /* Format */
00274 typedef struct audio_format_t audio_format_t;
00275 typedef struct video_format_t video_format_t;
00276 typedef struct subs_format_t subs_format_t;
00277 typedef struct es_format_t es_format_t;
00278 typedef struct video_palette_t video_palette_t;
00279 
00280 /* NInput */
00281 typedef struct stream_sys_t stream_sys_t;
00282 typedef struct stream_t     stream_t;
00283 typedef struct es_out_t     es_out_t;
00284 typedef struct es_out_id_t  es_out_id_t;
00285 typedef struct es_out_sys_t es_out_sys_t;
00286 typedef struct demux_t  demux_t;
00287 typedef struct access_t access_t;
00288 
00289 /* Audio */
00290 typedef struct aout_instance_t aout_instance_t;
00291 typedef struct aout_sys_t aout_sys_t;
00292 typedef struct aout_fifo_t aout_fifo_t;
00293 typedef struct aout_input_t aout_input_t;
00294 typedef struct aout_buffer_t aout_buffer_t;
00295 typedef audio_format_t audio_sample_format_t;
00296 typedef struct audio_date_t audio_date_t;
00297 typedef struct aout_filter_t aout_filter_t;
00298 
00299 /* Video */
00300 typedef struct vout_thread_t vout_thread_t;
00301 typedef struct vout_sys_t vout_sys_t;
00302 typedef struct vout_synchro_t vout_synchro_t;
00303 typedef struct chroma_sys_t chroma_sys_t;
00304 
00305 typedef video_format_t video_frame_format_t;
00306 typedef struct picture_t picture_t;
00307 typedef struct picture_sys_t picture_sys_t;
00308 typedef struct picture_heap_t picture_heap_t;
00309 
00310 typedef struct spu_t spu_t;
00311 typedef struct subpicture_t subpicture_t;
00312 typedef struct subpicture_sys_t subpicture_sys_t;
00313 typedef struct subpicture_region_t subpicture_region_t;
00314 typedef struct text_style_t text_style_t;
00315 
00316 typedef struct image_handler_t image_handler_t;
00317 
00318 /* Stream output */
00319 typedef struct sout_instance_t sout_instance_t;
00320 typedef struct sout_instance_sys_t sout_instance_sys_t;
00321 
00322 typedef struct sout_input_t sout_input_t;
00323 typedef struct sout_packetizer_input_t sout_packetizer_input_t;
00324 
00325 typedef struct sout_access_out_t sout_access_out_t;
00326 typedef struct sout_access_out_sys_t   sout_access_out_sys_t;
00327 
00328 typedef struct sout_mux_t sout_mux_t;
00329 typedef struct sout_mux_sys_t sout_mux_sys_t;
00330 
00331 typedef struct sout_stream_t    sout_stream_t;
00332 typedef struct sout_stream_sys_t sout_stream_sys_t;
00333 
00334 typedef struct sout_cfg_t       sout_cfg_t;
00335 typedef struct sap_session_t    sap_session_t;
00336 typedef struct sap_address_t sap_address_t;
00337 typedef struct session_descriptor_t session_descriptor_t;
00338 typedef struct announce_method_t announce_method_t;
00339 typedef struct announce_handler_t announce_handler_t;
00340 typedef struct sap_handler_t sap_handler_t;
00341 //typedef struct slp_session_t    slp_session_t;
00342 
00343 /* Decoders */
00344 typedef struct decoder_t      decoder_t;
00345 typedef struct decoder_sys_t  decoder_sys_t;
00346 
00347 /* Encoders */
00348 typedef struct encoder_t      encoder_t;
00349 typedef struct encoder_sys_t  encoder_sys_t;
00350 
00351 /* Filters */
00352 typedef struct filter_t filter_t;
00353 typedef struct filter_sys_t filter_sys_t;
00354 
00355 /* Misc */
00356 typedef struct data_packet_t data_packet_t;
00357 typedef struct data_buffer_t data_buffer_t;
00358 typedef struct stream_ctrl_t stream_ctrl_t;
00359 typedef struct pes_packet_t pes_packet_t;
00360 typedef struct network_socket_t network_socket_t;
00361 typedef struct virtual_socket_t v_socket_t;
00362 typedef struct iso639_lang_t iso639_lang_t;
00363 typedef struct sockaddr sockaddr;
00364 typedef struct addrinfo addrinfo;
00365 typedef struct vlc_acl_t vlc_acl_t;
00366 
00367 /* block */
00368 typedef struct block_t      block_t;
00369 typedef struct block_fifo_t block_fifo_t;
00370 
00371 /* httpd */
00372 typedef struct httpd_t          httpd_t;
00373 typedef struct httpd_host_t     httpd_host_t;
00374 typedef struct httpd_url_t      httpd_url_t;
00375 typedef struct httpd_client_t   httpd_client_t;
00376 typedef struct httpd_callback_sys_t httpd_callback_sys_t;
00377 typedef struct httpd_message_t  httpd_message_t;
00378 typedef int    (*httpd_callback_t)( httpd_callback_sys_t *, httpd_client_t *, httpd_message_t *answer, httpd_message_t *query );
00379 typedef struct httpd_file_t     httpd_file_t;
00380 typedef struct httpd_file_sys_t httpd_file_sys_t;
00381 typedef int (*httpd_file_callback_t)( httpd_file_sys_t *, httpd_file_t *, uint8_t *psz_request, uint8_t **pp_data, int *pi_data );
00382 typedef struct httpd_handler_t  httpd_handler_t;
00383 typedef struct httpd_handler_sys_t httpd_handler_sys_t;
00384 typedef int (*httpd_handler_callback_t)( httpd_handler_sys_t *, httpd_handler_t *, uint8_t *psz_url, uint8_t *psz_request, int i_type, uint8_t *p_in, int i_in, char *psz_remote_addr, char *psz_remote_host, uint8_t **pp_data, int *pi_data );
00385 typedef struct httpd_redirect_t httpd_redirect_t;
00386 typedef struct httpd_stream_t httpd_stream_t;
00387 
00388 /* TLS support */
00389 typedef struct tls_t tls_t;
00390 typedef struct tls_server_t tls_server_t;
00391 typedef struct tls_session_t tls_session_t;
00392 
00393 /* Hashing */
00394 typedef struct md5_s md5_t;
00395 
00396 /* XML */
00397 typedef struct xml_t xml_t;
00398 typedef struct xml_sys_t xml_sys_t;
00399 typedef struct xml_reader_t xml_reader_t;
00400 typedef struct xml_reader_sys_t xml_reader_sys_t;
00401 
00402 /* vod server */
00403 typedef struct vod_t     vod_t;
00404 typedef struct vod_sys_t vod_sys_t;
00405 typedef struct vod_media_t vod_media_t;
00406 
00407 /* opengl */
00408 typedef struct opengl_t     opengl_t;
00409 typedef struct opengl_sys_t opengl_sys_t;
00410 
00411 /* osdmenu */
00412 typedef struct osd_menu_t   osd_menu_t;
00413 typedef struct osd_state_t  osd_state_t;
00414 typedef struct osd_event_t  osd_event_t;
00415 typedef struct osd_button_t osd_button_t;
00416 typedef struct osd_menu_state_t osd_menu_state_t;
00417 
00418 /* VLM */
00419 typedef struct vlm_t         vlm_t;
00420 typedef struct vlm_message_t vlm_message_t;
00421 typedef struct vlm_media_t   vlm_media_t;
00422 typedef struct vlm_schedule_t vlm_schedule_t;
00423 
00424 /* divers */
00425 typedef struct vlc_meta_t    vlc_meta_t;
00426 
00427 
00428 /*****************************************************************************
00429  * Variable callbacks
00430  *****************************************************************************/
00431 typedef int ( * vlc_callback_t ) ( vlc_object_t *,      /* variable's object */
00432                                    char const *,            /* variable name */
00433                                    vlc_value_t,                 /* old value */
00434                                    vlc_value_t,                 /* new value */
00435                                    void * );                /* callback data */
00436 
00437 /*****************************************************************************
00438  * Plug-in stuff
00439  *****************************************************************************/
00440 #ifndef __PLUGIN__
00441 #   define VLC_EXPORT( type, name, args ) type name args
00442 #else
00443 #   define VLC_EXPORT( type, name, args ) struct _u_n_u_s_e_d_
00444     extern module_symbols_t* p_symbols;
00445 #endif
00446 
00447 /*****************************************************************************
00448  * OS-specific headers and thread types
00449  *****************************************************************************/
00450 #if defined( WIN32 ) || defined( UNDER_CE )
00451 #   define WIN32_LEAN_AND_MEAN
00452 #   include <windows.h>
00453 #   if defined( UNDER_CE )
00454 #      define IS_WINNT 0
00455 #   else
00456 #      define IS_WINNT ( GetVersion() < 0x80000000 )
00457 #   endif
00458 #endif
00459 
00460 #include "vlc_threads.h"
00461 
00462 /*****************************************************************************
00463  * Common structure members
00464  *****************************************************************************/
00465 
00466 /* VLC_COMMON_MEMBERS : members common to all basic vlc objects */
00467 #define VLC_COMMON_MEMBERS                                                  \
00468                                                                          \
00471                                                                      \
00472     int   i_object_id;                                                      \
00473     int   i_object_type;                                                    \
00474     char *psz_object_type;                                                  \
00475     char *psz_object_name;                                                  \
00476                                                                             \
00477     /* Thread properties, if any */                                         \
00478     vlc_bool_t   b_thread;                                                  \
00479     vlc_thread_t thread_id;                                                 \
00480                                                                             \
00481     /* Object access lock */                                                \
00482     vlc_mutex_t  object_lock;                                               \
00483     vlc_cond_t   object_wait;                                               \
00484                                                                             \
00485     /* Object properties */                                                 \
00486     volatile vlc_bool_t b_error;                   \
00487     volatile vlc_bool_t b_die;                    \
00488     volatile vlc_bool_t b_dead;                    \
00489     volatile vlc_bool_t b_attached;                \
00490     vlc_bool_t b_force;       \
00491                                                                             \
00492     /* Object variables */                                                  \
00493     vlc_mutex_t     var_lock;                                               \
00494     int             i_vars;                                                 \
00495     variable_t *    p_vars;                                                 \
00496                                                                             \
00497     /* Stuff related to the libvlc structure */                             \
00498     libvlc_t *      p_libvlc;                       \
00499     vlc_t *         p_vlc;                    \
00500                                                                             \
00501     volatile int    i_refcount;                          \
00502     vlc_object_t *  p_parent;                             \
00503     vlc_object_t ** pp_children;                        \
00504     volatile int    i_children;                                             \
00505                                                                             \
00506     /* Private data */                                                      \
00507     void *          p_private;                                              \
00508                                                                             \
00509                 \
00510     int be_sure_to_add_VLC_COMMON_MEMBERS_to_struct;                        \
00511                                                                      \
00512 
00513 /* VLC_OBJECT: attempt at doing a clever cast */
00514 #define VLC_OBJECT( x ) \
00515     ((vlc_object_t *)(x))+0*(x)->be_sure_to_add_VLC_COMMON_MEMBERS_to_struct
00516 
00517 /*****************************************************************************
00518  * Macros and inline functions
00519  *****************************************************************************/
00520 #ifdef NTOHL_IN_SYS_PARAM_H
00521 #   include <sys/param.h>
00522 
00523 #elif !defined(WIN32) && !defined( UNDER_CE )
00524 #   include <netinet/in.h>
00525 
00526 #endif /* NTOHL_IN_SYS_PARAM_H || WIN32 */
00527 
00528 /* CEIL: division with round to nearest greater integer */
00529 #define CEIL(n, d)  ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
00530 
00531 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
00532 #define PAD(n, d)   ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
00533 
00534 /* __MAX and __MIN: self explanatory */
00535 #ifndef __MAX
00536 #   define __MAX(a, b)   ( ((a) > (b)) ? (a) : (b) )
00537 #endif
00538 #ifndef __MIN
00539 #   define __MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
00540 #endif
00541 
00542 static int64_t GCD( int64_t a, int64_t b )
00543 {
00544     if( b ) return GCD( b, a % b );
00545     else return a;
00546 }
00547 
00548 /* Dynamic array handling: realloc array, move data, increment position */
00549 #if defined( _MSC_VER ) && _MSC_VER < 1300 && !defined( UNDER_CE )
00550 #   define VLCCVP (void**) /* Work-around for broken compiler */
00551 #else
00552 #   define VLCCVP
00553 #endif
00554 #define INSERT_ELEM( p_ar, i_oldsize, i_pos, elem )                           \
00555     do                                                                        \
00556     {                                                                         \
00557         if( !i_oldsize ) (p_ar) = NULL;                                       \
00558         (p_ar) = VLCCVP realloc( p_ar, ((i_oldsize) + 1) * sizeof(*(p_ar)) ); \
00559         if( (i_oldsize) - (i_pos) )                                           \
00560         {                                                                     \
00561             memmove( (p_ar) + (i_pos) + 1, (p_ar) + (i_pos),                  \
00562                      ((i_oldsize) - (i_pos)) * sizeof( *(p_ar) ) );           \
00563         }                                                                     \
00564         (p_ar)[i_pos] = elem;                                                 \
00565         (i_oldsize)++;                                                        \
00566     }                                                                         \
00567     while( 0 )
00568 
00569 #define REMOVE_ELEM( p_ar, i_oldsize, i_pos )                                 \
00570     do                                                                        \
00571     {                                                                         \
00572         if( (i_oldsize) - (i_pos) - 1 )                                       \
00573         {                                                                     \
00574             memmove( (p_ar) + (i_pos),                                        \
00575                      (p_ar) + (i_pos) + 1,                                    \
00576                      ((i_oldsize) - (i_pos) - 1) * sizeof( *(p_ar) ) );       \
00577         }                                                                     \
00578         if( i_oldsize > 1 )                                                   \
00579         {                                                                     \
00580             (p_ar) = realloc( p_ar, ((i_oldsize) - 1) * sizeof( *(p_ar) ) );  \
00581         }                                                                     \
00582         else                                                                  \
00583         {                                                                     \
00584             free( p_ar );                                                     \
00585             (p_ar) = NULL;                                                    \
00586         }                                                                     \
00587         (i_oldsize)--;                                                        \
00588     }                                                                         \
00589     while( 0 )
00590 
00591 
00592 #define TAB_APPEND( count, tab, p )             \
00593     if( (count) > 0 )                           \
00594     {                                           \
00595         (tab) = realloc( tab, sizeof( void ** ) * ( (count) + 1 ) ); \
00596     }                                           \
00597     else                                        \
00598     {                                           \
00599         (tab) = malloc( sizeof( void ** ) );    \
00600     }                                           \
00601     (tab)[count] = (p);        \
00602     (count)++
00603 
00604 #define TAB_FIND( count, tab, p, index )        \
00605     {                                           \
00606         int _i_;                                \
00607         (index) = -1;                           \
00608         for( _i_ = 0; _i_ < (count); _i_++ )    \
00609         {                                       \
00610             if( (tab)[_i_] == (p) )  \
00611             {                                   \
00612                 (index) = _i_;                  \
00613                 break;                          \
00614             }                                   \
00615         }                                       \
00616     }
00617 
00618 #define TAB_REMOVE( count, tab, p )             \
00619     {                                           \
00620         int _i_index_;                          \
00621         TAB_FIND( count, tab, p, _i_index_ );   \
00622         if( _i_index_ >= 0 )                    \
00623         {                                       \
00624             if( (count) > 1 )                     \
00625             {                                   \
00626                 memmove( ((void**)(tab) + _i_index_),    \
00627                          ((void**)(tab) + _i_index_+1),  \
00628                          ( (count) - _i_index_ - 1 ) * sizeof( void* ) );\
00629             }                                   \
00630             (count)--;                          \
00631             if( (count) == 0 )                  \
00632             {                                   \
00633                 free( tab );                    \
00634                 (tab) = NULL;                   \
00635             }                                   \
00636         }                                       \
00637     }
00638 
00639 /* MSB (big endian)/LSB (little endian) conversions - network order is always
00640  * MSB, and should be used for both network communications and files. Note that
00641  * byte orders other than little and big endians are not supported, but only
00642  * the VAX seems to have such exotic properties. */
00643 static inline uint16_t U16_AT( void const * _p )
00644 {
00645     uint8_t * p = (uint8_t *)_p;
00646     return ( ((uint16_t)p[0] << 8) | p[1] );
00647 }
00648 static inline uint32_t U32_AT( void const * _p )
00649 {
00650     uint8_t * p = (uint8_t *)_p;
00651     return ( ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16)
00652               | ((uint32_t)p[2] << 8) | p[3] );
00653 }
00654 static inline uint64_t U64_AT( void const * _p )
00655 {
00656     uint8_t * p = (uint8_t *)_p;
00657     return ( ((uint64_t)p[0] << 56) | ((uint64_t)p[1] << 48)
00658               | ((uint64_t)p[2] << 40) | ((uint64_t)p[3] << 32)
00659               | ((uint64_t)p[4] << 24) | ((uint64_t)p[5] << 16)
00660               | ((uint64_t)p[6] << 8) | p[7] );
00661 }
00662 
00663 static inline uint16_t GetWLE( void const * _p )
00664 {
00665     uint8_t * p = (uint8_t *)_p;
00666     return ( ((uint16_t)p[1] << 8) | p[0] );
00667 }
00668 static inline uint32_t GetDWLE( void const * _p )
00669 {
00670     uint8_t * p = (uint8_t *)_p;
00671     return ( ((uint32_t)p[3] << 24) | ((uint32_t)p[2] << 16)
00672               | ((uint32_t)p[1] << 8) | p[0] );
00673 }
00674 static inline uint64_t GetQWLE( void const * _p )
00675 {
00676     uint8_t * p = (uint8_t *)_p;
00677     return ( ((uint64_t)p[7] << 56) | ((uint64_t)p[6] << 48)
00678               | ((uint64_t)p[5] << 40) | ((uint64_t)p[4] << 32)
00679               | ((uint64_t)p[3] << 24) | ((uint64_t)p[2] << 16)
00680               | ((uint64_t)p[1] << 8) | p[0] );
00681 }
00682 
00683 #define GetWBE( p )     U16_AT( p )
00684 #define GetDWBE( p )    U32_AT( p )
00685 #define GetQWBE( p )    U64_AT( p )
00686 
00687 /* Helper writer functions */
00688 #define SetWLE( p, v ) _SetWLE( (uint8_t*)p, v)
00689 static inline void _SetWLE( uint8_t *p, uint16_t i_dw )
00690 {
00691     p[1] = ( i_dw >>  8 )&0xff;
00692     p[0] = ( i_dw       )&0xff;
00693 }
00694 
00695 #define SetDWLE( p, v ) _SetDWLE( (uint8_t*)p, v)
00696 static inline void _SetDWLE( uint8_t *p, uint32_t i_dw )
00697 {
00698     p[3] = ( i_dw >> 24 )&0xff;
00699     p[2] = ( i_dw >> 16 )&0xff;
00700     p[1] = ( i_dw >>  8 )&0xff;
00701     p[0] = ( i_dw       )&0xff;
00702 }
00703 #define SetQWLE( p, v ) _SetQWLE( (uint8_t*)p, v)
00704 static inline void _SetQWLE( uint8_t *p, uint64_t i_qw )
00705 {
00706     SetDWLE( p,   i_qw&0xffffffff );
00707     SetDWLE( p+4, ( i_qw >> 32)&0xffffffff );
00708 }
00709 #define SetWBE( p, v ) _SetWBE( (uint8_t*)p, v)
00710 static inline void _SetWBE( uint8_t *p, uint16_t i_dw )
00711 {
00712     p[0] = ( i_dw >>  8 )&0xff;
00713     p[1] = ( i_dw       )&0xff;
00714 }
00715 
00716 #define SetDWBE( p, v ) _SetDWBE( (uint8_t*)p, v)
00717 static inline void _SetDWBE( uint8_t *p, uint32_t i_dw )
00718 {
00719     p[0] = ( i_dw >> 24 )&0xff;
00720     p[1] = ( i_dw >> 16 )&0xff;
00721     p[2] = ( i_dw >>  8 )&0xff;
00722     p[3] = ( i_dw       )&0xff;
00723 }
00724 #define SetQWBE( p, v ) _SetQWBE( (uint8_t*)p, v)
00725 static inline void _SetQWBE( uint8_t *p, uint64_t i_qw )
00726 {
00727     SetDWBE( p+4,   i_qw&0xffffffff );
00728     SetDWBE( p, ( i_qw >> 32)&0xffffffff );
00729 }
00730 
00731 #if WORDS_BIGENDIAN
00732 #   define hton16(i)   ( i )
00733 #   define hton32(i)   ( i )
00734 #   define hton64(i)   ( i )
00735 #   define ntoh16(i)   ( i )
00736 #   define ntoh32(i)   ( i )
00737 #   define ntoh64(i)   ( i )
00738 #else
00739 #   define hton16(i)   U16_AT(&i)
00740 #   define hton32(i)   U32_AT(&i)
00741 #   define hton64(i)   U64_AT(&i)
00742 #   define ntoh16(i)   U16_AT(&i)
00743 #   define ntoh32(i)   U32_AT(&i)
00744 #   define ntoh64(i)   U64_AT(&i)
00745 #endif
00746 
00747 /* Format string sanity checks */
00748 #ifdef HAVE_ATTRIBUTE_FORMAT
00749 #   define ATTRIBUTE_FORMAT(x,y) __attribute__ ((format(printf,x,y)))
00750 #else
00751 #   define ATTRIBUTE_FORMAT(x,y)
00752 #endif
00753 
00754 /* Alignment of critical static data structures */
00755 #ifdef ATTRIBUTE_ALIGNED_MAX
00756 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
00757 #else
00758 #   define ATTR_ALIGN(align)
00759 #endif
00760 
00761 /* Alignment of critical dynamic data structure
00762  *
00763  * Not all platforms support memalign so we provide a vlc_memalign wrapper
00764  * void *vlc_memalign( size_t align, size_t size, void **pp_orig )
00765  * *pp_orig is the pointer that has to be freed afterwards.
00766  */
00767 #if 0
00768 #ifdef HAVE_POSIX_MEMALIGN
00769 #   define vlc_memalign(align,size,pp_orig) \
00770     ( !posix_memalign( pp_orig, align, size ) ? *(pp_orig) : NULL )
00771 #endif
00772 #endif
00773 #ifdef HAVE_MEMALIGN
00774     /* Some systems have memalign() but no declaration for it */
00775     void * memalign( size_t align, size_t size );
00776 
00777 #   define vlc_memalign(pp_orig,align,size) \
00778     ( *(pp_orig) = memalign( align, size ) )
00779 
00780 #else /* We don't have any choice but to align manually */
00781 #   define vlc_memalign(pp_orig,align,size) \
00782     (( *(pp_orig) = malloc( size + align - 1 )) \
00783         ? (void *)( (((unsigned long)*(pp_orig)) + (unsigned long)(align-1) ) \
00784                        & (~(unsigned long)(align-1)) ) \
00785         : NULL )
00786 
00787 #endif
00788 
00789 /* Stuff defined in src/extras/libc.c */
00790 #ifndef HAVE_STRDUP
00791 #   define strdup vlc_strdup
00792     VLC_EXPORT( char *, vlc_strdup, ( const char *s ) );
00793 #elif !defined(__PLUGIN__)
00794 #   define vlc_strdup NULL
00795 #endif
00796 
00797 #if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
00798 #   define vasprintf vlc_vasprintf
00799     VLC_EXPORT( int, vlc_vasprintf, (char **, const char *, va_list ) );
00800 #elif !defined(__PLUGIN__)
00801 #   define vlc_vasprintf NULL
00802 #endif
00803 
00804 #if !defined(HAVE_ASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
00805 #   define asprintf vlc_asprintf
00806     VLC_EXPORT( int, vlc_asprintf, (char **, const char *, ... ) );
00807 #elif !defined(__PLUGIN__)
00808 #   define vlc_asprintf NULL
00809 #endif
00810 
00811 #ifndef HAVE_STRNDUP
00812 #   if defined(STRNDUP_IN_GNOME_H) && \
00813         (defined(MODULE_NAME_IS_gnome)||defined(MODULE_NAME_IS_gnome_main)||\
00814          defined(MODULE_NAME_IS_gnome2)||defined(MODULE_NAME_IS_gnome2_main))
00815         /* Do nothing: gnome.h defines strndup for us */
00816 #   else
00817 #       define strndup vlc_strndup
00818         VLC_EXPORT( char *, vlc_strndup, ( const char *s, size_t n ) );
00819 #   endif
00820 #elif !defined(__PLUGIN__)
00821 #   define vlc_strndup NULL
00822 #endif
00823 
00824 #ifndef HAVE_ATOF
00825 #   define atof vlc_atof
00826     VLC_EXPORT( double, vlc_atof, ( const char *nptr ) );
00827 #elif !defined(__PLUGIN__)
00828 #   define vlc_atof NULL
00829 #endif
00830 
00831 #ifndef HAVE_STRTOF
00832 #   ifdef HAVE_STRTOD
00833 #       define strtof strtod
00834 #   endif
00835 #endif
00836 
00837 #ifndef HAVE_ATOLL
00838 #   define atoll vlc_atoll
00839     VLC_EXPORT( int64_t, vlc_atoll, ( const char *nptr ) );
00840 #elif !defined(__PLUGIN__)
00841 #   define vlc_atoll NULL
00842 #endif
00843 
00844 #ifndef HAVE_STRTOLL
00845 #   define strtoll vlc_strtoll
00846     VLC_EXPORT( int64_t, vlc_strtoll, ( const char *nptr, char **endptr, int base ) );
00847 #elif !defined(__PLUGIN__)
00848 #   define vlc_strtoll NULL
00849 #endif
00850 
00851 #ifndef HAVE_SCANDIR
00852 #   define scandir vlc_scandir
00853 #   define alphasort vlc_alphasort
00854     struct dirent;
00855     VLC_EXPORT( int, vlc_scandir, ( const char *name, struct dirent ***namelist, int (*filter) ( const struct dirent * ), int (*compar) ( const struct dirent **, const struct dirent ** ) ) );
00856     VLC_EXPORT( int, vlc_alphasort, ( const struct dirent **a, const struct dirent **b ) );
00857 #elif !defined(__PLUGIN__)
00858 #   define vlc_scandir NULL
00859 #   define vlc_alphasort NULL
00860 #endif
00861 
00862 #ifndef HAVE_GETENV
00863 #   define getenv vlc_getenv
00864     VLC_EXPORT( char *, vlc_getenv, ( const char *name ) );
00865 #elif !defined(__PLUGIN__)
00866 #   define vlc_getenv NULL
00867 #endif
00868 
00869 #ifndef HAVE_STRCASECMP
00870 #   ifndef HAVE_STRICMP
00871 #       define strcasecmp vlc_strcasecmp
00872         VLC_EXPORT( int, vlc_strcasecmp, ( const char *s1, const char *s2 ) );
00873 #   else
00874 #       define strcasecmp stricmp
00875 #       if !defined(__PLUGIN__)
00876 #           define vlc_strcasecmp NULL
00877 #       endif
00878 #   endif
00879 #elif !defined(__PLUGIN__)
00880 #   define vlc_strcasecmp NULL
00881 #endif
00882 
00883 #ifndef HAVE_STRNCASECMP
00884 #   ifndef HAVE_STRNICMP
00885 #       define strncasecmp vlc_strncasecmp
00886         VLC_EXPORT( int, vlc_strncasecmp, ( const char *s1, const char *s2, size_t n ) );
00887 #   else
00888 #       define strncasecmp strnicmp
00889 #       if !defined(__PLUGIN__)
00890 #           define vlc_strncasecmp NULL
00891 #       endif
00892 #   endif
00893 #elif !defined(__PLUGIN__)
00894 #   define vlc_strncasecmp NULL
00895 #endif
00896 
00897 #ifndef HAVE_STRCASESTR
00898 #   ifndef HAVE_STRISTR
00899 #       define strcasestr vlc_strcasestr
00900         VLC_EXPORT( char *, vlc_strcasestr, ( const char *s1, const char *s2 ) );
00901 #   else
00902 #       define strcasestr stristr
00903 #       if !defined(__PLUGIN__)
00904 #           define vlc_strcasestr NULL
00905 #       endif
00906 #   endif
00907 #elif !defined(__PLUGIN__)
00908 #   define vlc_strcasestr NULL
00909 #endif
00910 
00911 #ifndef HAVE_DIRENT_H
00912     typedef void DIR;
00913 #   ifndef FILENAME_MAX
00914 #       define FILENAME_MAX (260)
00915 #   endif
00916     struct dirent
00917     {
00918         long            d_ino;          /* Always zero. */
00919         unsigned short  d_reclen;       /* Always zero. */
00920         unsigned short  d_namlen;       /* Length of name in d_name. */
00921         char            d_name[FILENAME_MAX]; /* File name. */
00922     };
00923 #   define opendir vlc_opendir
00924 #   define readdir vlc_readdir
00925 #   define closedir vlc_closedir
00926     VLC_EXPORT( void *, vlc_opendir, ( const char * ) );
00927     VLC_EXPORT( void *, vlc_readdir, ( void * ) );
00928     VLC_EXPORT( int, vlc_closedir, ( void * ) );
00929 #else
00930     struct dirent;  /* forward declaration for vlc_symbols.h */
00931 #   if !defined(__PLUGIN__)
00932 #       define vlc_opendir  NULL
00933 #       define vlc_readdir  NULL
00934 #       define vlc_closedir NULL
00935 #   endif
00936 #endif
00937 
00938     VLC_EXPORT( void *, vlc_opendir_wrapper, ( const char * ) );
00939     VLC_EXPORT( struct dirent *, vlc_readdir_wrapper, ( void * ) );
00940     VLC_EXPORT( int, vlc_closedir_wrapper, ( void * ) );
00941 
00942 /* Format type specifiers for 64 bits numbers */
00943 #if defined(__CYGWIN32__) || (!defined(WIN32) && !defined(UNDER_CE))
00944 #   if defined(__WORDSIZE) && __WORDSIZE == 64
00945 #       define I64Fd "%ld"
00946 #       define I64Fi "%li"
00947 #       define I64Fo "%lo"
00948 #       define I64Fu "%lu"
00949 #       define I64Fx "%lx"
00950 #       define I64FX "%lX"
00951 #   else
00952 #       define I64Fd "%lld"
00953 #       define I64Fi "%lli"
00954 #       define I64Fo "%llo"
00955 #       define I64Fu "%llu"
00956 #       define I64Fx "%llx"
00957 #       define I64FX "%llX"
00958 #   endif
00959 #else
00960 #   define I64Fd "%I64d"
00961 #   define I64Fi "%I64i"
00962 #   define I64Fo "%I64o"
00963 #   define I64Fu "%I64u"
00964 #   define I64Fx "%I64x"
00965 #   define I64FX "%I64X"
00966 #endif /* defined(WIN32)||defined(UNDER_CE) */
00967 
00968 /* 64 bits integer constant suffix */
00969 #if defined( __MINGW32__ ) || (!defined(WIN32) && !defined(UNDER_CE))
00970 #   if defined(__WORDSIZE) && __WORDSIZE == 64
00971 #       define I64C(x)         x##L
00972 #       define UI64C(x)        x##UL
00973 #   else
00974 #       define I64C(x)         x##LL
00975 #       define UI64C(x)        x##ULL
00976 #   endif
00977 #else
00978 #   define I64C(x)         x##i64
00979 #   define UI64C(x)        x##ui64
00980 #endif /* defined(WIN32)||defined(UNDER_CE) */
00981 
00982 #if defined(WIN32) || defined(UNDER_CE)
00983 /* win32, cl and icl support */
00984 #   if defined( _MSC_VER ) || !defined( __MINGW32__ )
00985 #       define __attribute__(x)
00986 #       define __inline__      __inline
00987 #       define S_IFBLK         0x3000  /* Block */
00988 #       define S_ISBLK(m)      (0)
00989 #       define S_ISCHR(m)      (0)
00990 #       define S_ISFIFO(m)     (((m)&_S_IFMT) == _S_IFIFO)
00991 #       define S_ISREG(m)      (((m)&_S_IFMT) == _S_IFREG)
00992 #   endif
00993 
00994 /* several type definitions */
00995 #   if defined( __MINGW32__ )
00996 #       if !defined( _OFF_T_ )
00997             typedef long long _off_t;
00998             typedef _off_t off_t;
00999 #           define _OFF_T_
01000 #       else
01001 #           ifdef off_t
01002 #               undef off_t
01003 #           endif
01004 #           define off_t long long
01005 #       endif
01006 #   endif
01007 
01008 #   if defined( _MSC_VER ) && !defined( __WXMSW__ )
01009 #       if !defined( _OFF_T_DEFINED )
01010             typedef __int64 off_t;
01011 #           define _OFF_T_DEFINED
01012 #       else
01013             /* for wx compatibility typedef long off_t; */
01014 #           define off_t __int64
01015 #       endif
01016 #   endif
01017 
01018 #   if defined( __BORLANDC__ )
01019 #       undef off_t
01020 #       define off_t unsigned __int64
01021 #   endif
01022 
01023 #   ifndef O_NONBLOCK
01024 #       define O_NONBLOCK 0
01025 #   endif
01026 
01027 #   ifndef alloca
01028 #       define alloca _alloca
01029 #   endif
01030 
01031     /* These two are not defined in mingw32 (bug?) */
01032 #   ifndef snprintf
01033 #       define snprintf _snprintf
01034 #   endif
01035 #   ifndef vsnprintf
01036 #       define vsnprintf _vsnprintf
01037 #   endif
01038 
01039 #   include <tchar.h>
01040 #endif
01041 
01042 VLC_EXPORT( vlc_bool_t, vlc_ureduce, ( unsigned *, unsigned *, uint64_t, uint64_t, uint64_t ) );
01043 VLC_EXPORT( char **, vlc_parse_cmdline, ( const char *, int * ) );
01044 
01045 /* vlc_wraptext (defined in src/extras/libc.c) */
01046 #define wraptext vlc_wraptext
01047 VLC_EXPORT( char *, vlc_wraptext, ( const char *, int, vlc_bool_t ) );
01048 
01049 /* iconv wrappers (defined in src/extras/libc.c) */
01050 typedef void *vlc_iconv_t;
01051 VLC_EXPORT( vlc_iconv_t, vlc_iconv_open, ( const char *, const char * ) );
01052 VLC_EXPORT( size_t, vlc_iconv, ( vlc_iconv_t, char **, size_t *, char **, size_t * ) );
01053 VLC_EXPORT( int, vlc_iconv_close, ( vlc_iconv_t ) );
01054 
01055 /* execve wrapper (defined in src/extras/libc.c) */
01056 VLC_EXPORT( int, __vlc_execve, ( vlc_object_t *p_object, int i_argc, char **pp_argv, char **pp_env, char *psz_cwd, char *p_in, int i_in, char **pp_data, int *pi_data ) );
01057 #define vlc_execve(a,b,c,d,e,f,g,h,i) __vlc_execve(VLC_OBJECT(a),b,c,d,e,f,g,h,i)
01058 
01059 /*****************************************************************************
01060  * CPU capabilities
01061  *****************************************************************************/
01062 #define CPU_CAPABILITY_NONE    0
01063 #define CPU_CAPABILITY_486     (1<<0)
01064 #define CPU_CAPABILITY_586     (1<<1)
01065 #define CPU_CAPABILITY_PPRO    (1<<2)
01066 #define CPU_CAPABILITY_MMX     (1<<3)
01067 #define CPU_CAPABILITY_3DNOW   (1<<4)
01068 #define CPU_CAPABILITY_MMXEXT  (1<<5)
01069 #define CPU_CAPABILITY_SSE     (1<<6)
01070 #define CPU_CAPABILITY_SSE2    (1<<7)
01071 #define CPU_CAPABILITY_ALTIVEC (1<<16)
01072 #define CPU_CAPABILITY_FPU     (1<<31)
01073 
01074 /*****************************************************************************
01075  * I18n stuff
01076  *****************************************************************************/
01077 VLC_EXPORT( char *, vlc_dgettext, ( const char *package, const char *msgid ) );
01078 
01079 #if defined( ENABLE_NLS ) && \
01080      (defined(MODULE_NAME_IS_gnome)||defined(MODULE_NAME_IS_gnome_main)||\
01081       defined(MODULE_NAME_IS_gnome2)||defined(MODULE_NAME_IS_gnome2_main)||\
01082       defined(MODULE_NAME_IS_pda))
01083     /* Declare nothing: gnome.h will do it for us */
01084 #elif defined( ENABLE_NLS )
01085 #   if defined( HAVE_INCLUDED_GETTEXT )
01086 #       include "libintl.h"
01087 #   else
01088 #       include <libintl.h>
01089 #   endif
01090 #   undef _
01091 #   define _(String) vlc_dgettext (PACKAGE_NAME, String)
01092 #   define N_(String) ((char*)(String))
01093 #else
01094 #   define _(String) ((char*)(String))
01095 #   define N_(String) ((char*)(String))
01096 #endif
01097 
01098 /*****************************************************************************
01099  * libvlc features
01100  *****************************************************************************/
01101 VLC_EXPORT( const char *, VLC_Version, ( void ) );
01102 VLC_EXPORT( const char *, VLC_CompileBy, ( void ) );
01103 VLC_EXPORT( const char *, VLC_CompileHost, ( void ) );
01104 VLC_EXPORT( const char *, VLC_CompileDomain, ( void ) );
01105 VLC_EXPORT( const char *, VLC_Compiler, ( void ) );
01106 VLC_EXPORT( const char *, VLC_Changeset, ( void ) );
01107 VLC_EXPORT( const char *, VLC_Error, ( int ) );
01108 
01109 /*****************************************************************************
01110  * Additional vlc stuff
01111  *****************************************************************************/
01112 #include "vlc_symbols.h"
01113 #include "os_specific.h"
01114 #include "vlc_messages.h"
01115 #include "variables.h"
01116 #include "vlc_objects.h"
01117 #include "vlc_threads_funcs.h"
01118 #include "mtime.h"
01119 #include "modules.h"
01120 #include "main.h"
01121 #include "configuration.h"
01122 
01123 #if defined( __BORLANDC__ )
01124 #   undef PACKAGE
01125 #   define PACKAGE
01126 #endif
01127 

Generated on Tue Dec 20 10:14:19 2005 for vlc-0.8.4a by  doxygen 1.4.2