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: 7e16c13d6978d3292c5f54429741aaeef04f1e63 $
00007  *
00008  * Authors: Samuel Hocevar <sam@via.ecp.fr>
00009  *          Vincent Seguin <seguin@via.ecp.fr>
00010  *          Gildas Bazin <gbazin@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00025  *****************************************************************************/
00026 
00027 /**
00028  * \file
00029  * This file is a collection of common definitions and types
00030  */
00031 
00032 #ifndef VLC_COMMON_H
00033 # define VLC_COMMON_H 1
00034 
00035 /*****************************************************************************
00036  * Required vlc headers
00037  *****************************************************************************/
00038 #if defined( _MSC_VER )
00039 #   pragma warning( disable : 4244 )
00040 #endif
00041 
00042 #include "vlc_config.h"
00043 
00044 /*****************************************************************************
00045  * Required system headers
00046  *****************************************************************************/
00047 #include <stdlib.h>
00048 #include <stdarg.h>
00049 
00050 #include <string.h>
00051 #include <stdio.h>
00052 #include <inttypes.h>
00053 #include <stddef.h>
00054 
00055 #ifndef __cplusplus
00056 # include <stdbool.h>
00057 #endif
00058 
00059 /* Try to fix format strings for all versions of mingw and mingw64 */
00060 #if defined( _WIN32 ) && defined( __USE_MINGW_ANSI_STDIO )
00061  #undef PRId64
00062  #define PRId64 "lld"
00063  #undef PRIi64
00064  #define PRIi64 "lli"
00065  #undef PRIu64
00066  #define PRIu64 "llu"
00067  #undef PRIo64
00068  #define PRIo64 "llo"
00069  #undef PRIx64
00070  #define PRIx64 "llx"
00071  #define snprintf        __mingw_snprintf
00072  #define vsnprintf       __mingw_vsnprintf
00073 #endif
00074 
00075 /* Format string sanity checks */
00076 #ifdef __GNUC__
00077 #   if defined( _WIN32 ) && (__GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) )
00078 #     define LIBVLC_FORMAT(x,y) __attribute__ ((format(gnu_printf,x,y)))
00079 #   else
00080 #     define LIBVLC_FORMAT(x,y) __attribute__ ((format(printf,x,y)))
00081 #   endif
00082 #   define LIBVLC_FORMAT_ARG(x) __attribute__ ((format_arg(x)))
00083 #   if __GNUC__ > 3 || (__GNUC__ == 3 && (__GNUC_MINOR__ >= 4))
00084 #     define LIBVLC_USED __attribute__ ((warn_unused_result))
00085 #   else
00086 #     define LIBVLC_USED
00087 #   endif
00088 #   define LIBVLC_MALLOC __attribute__ ((malloc))
00089 #else
00090 #   define LIBVLC_FORMAT(x,y)
00091 #   define LIBVLC_FORMAT_ARG(x)
00092 #   define LIBVLC_USED
00093 #   define LIBVLC_MALLOC
00094 #endif
00095 
00096 /* Branch prediction */
00097 #ifdef __GNUC__
00098 #   define likely(p)   __builtin_expect(!!(p), 1)
00099 #   define unlikely(p) __builtin_expect(!!(p), 0)
00100 #else
00101 #   define likely(p)   (!!(p))
00102 #   define unlikely(p) (!!(p))
00103 #endif
00104 
00105 /*****************************************************************************
00106  * Basic types definitions
00107  *****************************************************************************/
00108 #if defined( WIN32 ) || defined( UNDER_CE )
00109 #   include <malloc.h>
00110 #   ifndef PATH_MAX
00111 #       define PATH_MAX MAX_PATH
00112 #   endif
00113 #endif
00114 
00115 /* Counter for statistics and profiling */
00116 typedef unsigned long       count_t;
00117 
00118 /* Audio volume */
00119 typedef uint16_t            audio_volume_t;
00120 
00121 /**
00122  * High precision date or time interval
00123  *
00124  * Store a high precision date or time interval. The maximum precision is the
00125  * microsecond, and a 64 bits integer is used to avoid overflows (maximum
00126  * time interval is then 292271 years, which should be long enough for any
00127  * video). Dates are stored as microseconds since a common date (usually the
00128  * epoch). Note that date and time intervals can be manipulated using regular
00129  * arithmetic operators, and that no special functions are required.
00130  */
00131 typedef int64_t mtime_t;
00132 
00133 /**
00134  * The vlc_fourcc_t type.
00135  *
00136  * See http://www.webartz.com/fourcc/ for a very detailed list.
00137  */
00138 typedef uint32_t vlc_fourcc_t;
00139 
00140 #ifdef WORDS_BIGENDIAN
00141 #   define VLC_FOURCC( a, b, c, d ) \
00142         ( ((uint32_t)d) | ( ((uint32_t)c) << 8 ) \
00143            | ( ((uint32_t)b) << 16 ) | ( ((uint32_t)a) << 24 ) )
00144 #   define VLC_TWOCC( a, b ) \
00145         ( (uint16_t)(b) | ( (uint16_t)(a) << 8 ) )
00146 
00147 #else
00148 #   define VLC_FOURCC( a, b, c, d ) \
00149         ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
00150            | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
00151 #   define VLC_TWOCC( a, b ) \
00152         ( (uint16_t)(a) | ( (uint16_t)(b) << 8 ) )
00153 
00154 #endif
00155 
00156 /**
00157  * Translate a vlc_fourcc into its string representation. This function
00158  * assumes there is enough room in psz_fourcc to store 4 characters in.
00159  *
00160  * \param fcc a vlc_fourcc_t
00161  * \param psz_fourcc string to store string representation of vlc_fourcc in
00162  */
00163 static inline void vlc_fourcc_to_char( vlc_fourcc_t fcc, char *psz_fourcc )
00164 {
00165     memcpy( psz_fourcc, &fcc, 4 );
00166 }
00167 
00168 #define vlc_fourcc_to_char( a, b ) \
00169         vlc_fourcc_to_char( (vlc_fourcc_t)(a), (char *)(b) )
00170 
00171 /*****************************************************************************
00172  * Classes declaration
00173  *****************************************************************************/
00174 
00175 /* Internal types */
00176 typedef struct vlc_list_t vlc_list_t;
00177 typedef struct vlc_object_t vlc_object_t;
00178 typedef struct libvlc_int_t libvlc_int_t;
00179 typedef struct date_t date_t;
00180 typedef struct dict_entry_t dict_entry_t;
00181 typedef struct dict_t dict_t;
00182 
00183 /* Playlist */
00184 
00185 /* FIXME */
00186 /**
00187  * Playlist commands
00188  */
00189 typedef enum {
00190     PLAYLIST_PLAY,      /**< No arg.                            res=can fail*/
00191     PLAYLIST_VIEWPLAY,  /**< arg1= playlist_item_t*,*/
00192                         /**  arg2 = playlist_item_t*          , res=can fail */
00193     PLAYLIST_PAUSE,     /**< No arg                             res=can fail*/
00194     PLAYLIST_STOP,      /**< No arg                             res=can fail*/
00195     PLAYLIST_SKIP,      /**< arg1=int,                          res=can fail*/
00196 } playlist_command_t;
00197 
00198 
00199 typedef struct playlist_t playlist_t;
00200 typedef struct playlist_item_t playlist_item_t;
00201 typedef struct playlist_view_t playlist_view_t;
00202 typedef struct services_discovery_t services_discovery_t;
00203 typedef struct services_discovery_sys_t services_discovery_sys_t;
00204 typedef struct playlist_add_t playlist_add_t;
00205 
00206 /* Modules */
00207 typedef struct module_bank_t module_bank_t;
00208 typedef struct module_t module_t;
00209 typedef struct module_config_t module_config_t;
00210 typedef struct module_symbols_t module_symbols_t;
00211 typedef struct module_cache_t module_cache_t;
00212 
00213 typedef struct config_category_t config_category_t;
00214 
00215 /* Input */
00216 typedef struct input_thread_t input_thread_t;
00217 typedef struct input_thread_sys_t input_thread_sys_t;
00218 typedef struct input_item_t input_item_t;
00219 typedef struct input_item_node_t input_item_node_t;
00220 typedef struct access_t access_t;
00221 typedef struct access_sys_t access_sys_t;
00222 typedef struct stream_t     stream_t;
00223 typedef struct stream_sys_t stream_sys_t;
00224 typedef struct demux_t  demux_t;
00225 typedef struct demux_sys_t demux_sys_t;
00226 typedef struct es_out_t     es_out_t;
00227 typedef struct es_out_id_t  es_out_id_t;
00228 typedef struct es_out_sys_t es_out_sys_t;
00229 typedef struct es_descriptor_t es_descriptor_t;
00230 typedef struct seekpoint_t seekpoint_t;
00231 typedef struct info_t info_t;
00232 typedef struct info_category_t info_category_t;
00233 typedef struct input_attachment_t input_attachment_t;
00234 
00235 /* Format */
00236 typedef struct audio_format_t audio_format_t;
00237 typedef struct video_format_t video_format_t;
00238 typedef struct subs_format_t subs_format_t;
00239 typedef struct es_format_t es_format_t;
00240 typedef struct video_palette_t video_palette_t;
00241 
00242 /* Audio */
00243 typedef struct aout_instance_t aout_instance_t;
00244 typedef struct aout_sys_t aout_sys_t;
00245 typedef struct aout_fifo_t aout_fifo_t;
00246 typedef struct aout_input_t aout_input_t;
00247 typedef struct block_t aout_buffer_t;
00248 typedef audio_format_t audio_sample_format_t;
00249 typedef struct audio_date_t audio_date_t;
00250 typedef struct aout_filter_t aout_filter_t;
00251 
00252 /* Video */
00253 typedef struct vout_thread_t vout_thread_t;
00254 
00255 typedef video_format_t video_frame_format_t;
00256 typedef struct picture_t picture_t;
00257 typedef struct picture_sys_t picture_sys_t;
00258 
00259 /* Subpictures */
00260 typedef struct spu_t spu_t;
00261 typedef struct subpicture_t subpicture_t;
00262 typedef struct subpicture_sys_t subpicture_sys_t;
00263 typedef struct subpicture_region_t subpicture_region_t;
00264 
00265 typedef struct image_handler_t image_handler_t;
00266 
00267 /* Stream output */
00268 typedef struct sout_instance_t sout_instance_t;
00269 typedef struct sout_instance_sys_t sout_instance_sys_t;
00270 
00271 typedef struct sout_input_t sout_input_t;
00272 typedef struct sout_packetizer_input_t sout_packetizer_input_t;
00273 
00274 typedef struct sout_access_out_t sout_access_out_t;
00275 typedef struct sout_access_out_sys_t   sout_access_out_sys_t;
00276 
00277 typedef struct sout_mux_t sout_mux_t;
00278 typedef struct sout_mux_sys_t sout_mux_sys_t;
00279 
00280 typedef struct sout_stream_t    sout_stream_t;
00281 typedef struct sout_stream_sys_t sout_stream_sys_t;
00282 
00283 typedef struct config_chain_t       config_chain_t;
00284 typedef struct session_descriptor_t session_descriptor_t;
00285 typedef struct announce_method_t announce_method_t;
00286 
00287 typedef struct sout_param_t sout_param_t;
00288 typedef struct sout_pcat_t sout_pcat_t;
00289 typedef struct sout_std_t sout_std_t;
00290 typedef struct sout_display_t sout_display_t;
00291 typedef struct sout_duplicate_t sout_duplicate_t;
00292 typedef struct sout_transcode_t sout_transcode_t;
00293 typedef struct sout_chain_t sout_chain_t;
00294 typedef struct streaming_profile_t streaming_profile_t;
00295 typedef struct sout_module_t sout_module_t;
00296 typedef struct sout_gui_descr_t sout_gui_descr_t;
00297 typedef struct profile_parser_t profile_parser_t;
00298 
00299 /* Decoders */
00300 typedef struct decoder_t         decoder_t;
00301 typedef struct decoder_sys_t     decoder_sys_t;
00302 typedef struct decoder_synchro_t decoder_synchro_t;
00303 
00304 /* Encoders */
00305 typedef struct encoder_t      encoder_t;
00306 typedef struct encoder_sys_t  encoder_sys_t;
00307 
00308 /* Filters */
00309 typedef struct filter_t filter_t;
00310 typedef struct filter_sys_t filter_sys_t;
00311 
00312 /* Network */
00313 typedef struct network_socket_t network_socket_t;
00314 typedef struct virtual_socket_t v_socket_t;
00315 typedef struct sockaddr sockaddr;
00316 typedef struct addrinfo addrinfo;
00317 typedef struct vlc_acl_t vlc_acl_t;
00318 typedef struct vlc_url_t vlc_url_t;
00319 
00320 /* Misc */
00321 typedef struct iso639_lang_t iso639_lang_t;
00322 typedef struct device_t device_t;
00323 typedef struct device_probe_t device_probe_t;
00324 typedef struct probe_sys_t probe_sys_t;
00325 
00326 /* block */
00327 typedef struct block_t      block_t;
00328 typedef struct block_fifo_t block_fifo_t;
00329 
00330 /* httpd */
00331 typedef struct httpd_t          httpd_t;
00332 typedef struct httpd_host_t     httpd_host_t;
00333 typedef struct httpd_url_t      httpd_url_t;
00334 typedef struct httpd_client_t   httpd_client_t;
00335 typedef struct httpd_callback_sys_t httpd_callback_sys_t;
00336 typedef struct httpd_message_t  httpd_message_t;
00337 typedef int    (*httpd_callback_t)( httpd_callback_sys_t *, httpd_client_t *, httpd_message_t *answer, const httpd_message_t *query );
00338 typedef struct httpd_file_t     httpd_file_t;
00339 typedef struct httpd_file_sys_t httpd_file_sys_t;
00340 typedef int (*httpd_file_callback_t)( httpd_file_sys_t *, httpd_file_t *, uint8_t *psz_request, uint8_t **pp_data, int *pi_data );
00341 typedef struct httpd_handler_t  httpd_handler_t;
00342 typedef struct httpd_handler_sys_t httpd_handler_sys_t;
00343 typedef int (*httpd_handler_callback_t)( httpd_handler_sys_t *, httpd_handler_t *, char *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 );
00344 typedef struct httpd_redirect_t httpd_redirect_t;
00345 typedef struct httpd_stream_t httpd_stream_t;
00346 
00347 /* TLS support */
00348 typedef struct tls_server_t tls_server_t;
00349 typedef struct tls_session_t tls_session_t;
00350 
00351 /* Hashing */
00352 typedef struct md5_s md5_t;
00353 
00354 /* XML */
00355 typedef struct xml_t xml_t;
00356 typedef struct xml_sys_t xml_sys_t;
00357 typedef struct xml_reader_t xml_reader_t;
00358 typedef struct xml_reader_sys_t xml_reader_sys_t;
00359 
00360 /* vod server */
00361 typedef struct vod_t     vod_t;
00362 typedef struct vod_sys_t vod_sys_t;
00363 typedef struct vod_media_t vod_media_t;
00364 
00365 /* opengl */
00366 typedef struct opengl_t     opengl_t;
00367 typedef struct opengl_sys_t opengl_sys_t;
00368 
00369 /* osdmenu */
00370 typedef struct osd_menu_t   osd_menu_t;
00371 typedef struct osd_state_t  osd_state_t;
00372 typedef struct osd_event_t  osd_event_t;
00373 typedef struct osd_button_t osd_button_t;
00374 typedef struct osd_menu_state_t osd_menu_state_t;
00375 
00376 /* VLM */
00377 typedef struct vlm_t         vlm_t;
00378 typedef struct vlm_message_t vlm_message_t;
00379 
00380 /* misc */
00381 typedef struct vlc_meta_t    vlc_meta_t;
00382 
00383 /* Stats */
00384 typedef struct counter_t     counter_t;
00385 typedef struct counter_sample_t counter_sample_t;
00386 typedef struct stats_handler_t stats_handler_t;
00387 typedef struct input_stats_t input_stats_t;
00388 
00389 /* Update */
00390 typedef struct update_t update_t;
00391 typedef struct update_iterator_t update_iterator_t;
00392 
00393 /* Meta engine */
00394 typedef struct meta_engine_t meta_engine_t;
00395 
00396 /* stat/lstat/fstat */
00397 #ifdef WIN32
00398 #include <sys/stat.h>
00399 
00400 # ifndef UNDER_CE
00401 struct _stati64;
00402 #define stat _stati64
00403 #define fstat _fstati64
00404 #endif
00405 
00406 /* You should otherwise use vlc_stat and vlc_lstat. */
00407 #else
00408 struct stat;
00409 #endif
00410 
00411 /**
00412  * VLC value structure
00413  */
00414 typedef union
00415 {
00416     int64_t         i_int;
00417     bool            b_bool;
00418     float           f_float;
00419     char *          psz_string;
00420     void *          p_address;
00421     vlc_object_t *  p_object;
00422     vlc_list_t *    p_list;
00423     mtime_t         i_time;
00424     struct { int32_t x; int32_t y; } coords;
00425 
00426 } vlc_value_t;
00427 
00428 /**
00429  * VLC list structure
00430  */
00431 struct vlc_list_t
00432 {
00433     int             i_count;
00434     vlc_value_t *   p_values;
00435     int *           pi_types;
00436 
00437 };
00438 
00439 /**
00440  * \defgroup var_type Variable types
00441  * These are the different types a vlc variable can have.
00442  * @{
00443  */
00444 #define VLC_VAR_VOID      0x0010
00445 #define VLC_VAR_BOOL      0x0020
00446 #define VLC_VAR_INTEGER   0x0030
00447 #define VLC_VAR_HOTKEY    0x0031
00448 #define VLC_VAR_STRING    0x0040
00449 #define VLC_VAR_MODULE    0x0041
00450 #define VLC_VAR_FILE      0x0042
00451 #define VLC_VAR_DIRECTORY 0x0043
00452 #define VLC_VAR_VARIABLE  0x0044
00453 #define VLC_VAR_FLOAT     0x0050
00454 #define VLC_VAR_TIME      0x0060
00455 #define VLC_VAR_ADDRESS   0x0070
00456 #define VLC_VAR_MUTEX     0x0080
00457 #define VLC_VAR_COORDS    0x00A0
00458 /**@}*/
00459 
00460 /*****************************************************************************
00461  * Error values (shouldn't be exposed)
00462  *****************************************************************************/
00463 #define VLC_SUCCESS         -0                                   /* No error */
00464 #define VLC_ENOMEM          -1                          /* Not enough memory */
00465 #define VLC_ETIMEOUT        -3                                    /* Timeout */
00466 
00467 #define VLC_ENOMOD         -10                           /* Module not found */
00468 
00469 #define VLC_ENOOBJ         -20                           /* Object not found */
00470 
00471 #define VLC_ENOVAR         -30                         /* Variable not found */
00472 #define VLC_EBADVAR        -31                         /* Bad variable value */
00473 
00474 #define VLC_ENOITEM        -40                           /**< Item not found */
00475 
00476 #define VLC_EEXIT         -255                             /* Program exited */
00477 #define VLC_EEXITSUCCESS  -999                /* Program exited successfully */
00478 #define VLC_EGENERIC      -666                              /* Generic error */
00479 
00480 /*****************************************************************************
00481  * Variable callbacks
00482  *****************************************************************************/
00483 typedef int ( * vlc_callback_t ) ( vlc_object_t *,      /* variable's object */
00484                                    char const *,            /* variable name */
00485                                    vlc_value_t,                 /* old value */
00486                                    vlc_value_t,                 /* new value */
00487                                    void * );                /* callback data */
00488 
00489 /*****************************************************************************
00490  * Plug-in stuff
00491  *****************************************************************************/
00492 
00493 #ifdef __cplusplus
00494 # define LIBVLC_EXTERN extern "C"
00495 #else
00496 # define LIBVLC_EXTERN extern
00497 #endif
00498 #if defined (WIN32) && defined (DLL_EXPORT)
00499 #if defined (UNDER_CE)
00500 # include <windef.h>
00501 #endif
00502 # define LIBVLC_EXPORT __declspec(dllexport)
00503 #else
00504 # define LIBVLC_EXPORT
00505 #endif
00506 #define VLC_EXPORT( type, name, args ) \
00507                         LIBVLC_EXTERN LIBVLC_EXPORT type name args
00508 
00509 /*****************************************************************************
00510  * OS-specific headers and thread types
00511  *****************************************************************************/
00512 #if defined( WIN32 ) || defined( UNDER_CE )
00513 #   define WIN32_LEAN_AND_MEAN
00514 #   include <windows.h>
00515 #endif
00516 
00517 #include "vlc_mtime.h"
00518 #include "vlc_threads.h"
00519 
00520 /**
00521  * Memory storage space for an atom. Never access it directly.
00522  */
00523 typedef union
00524 {
00525     volatile uintptr_t u;
00526     volatile intptr_t  s;
00527 } vlc_atomic_t;
00528 
00529 /*****************************************************************************
00530  * Common structure members
00531  *****************************************************************************/
00532 
00533 /* VLC_COMMON_MEMBERS : members common to all basic vlc objects */
00534 #define VLC_COMMON_MEMBERS                                                  \
00535 /** \name VLC_COMMON_MEMBERS                                                \
00536  * these members are common for all vlc objects                             \
00537  */                                                                         \
00538 /**@{*/                                                                     \
00539     const char *psz_object_type;                                            \
00540                                                                             \
00541     /* Messages header */                                                   \
00542     char *psz_header;                                                       \
00543     int  i_flags;                                                           \
00544                                                                             \
00545     /* Object properties */                                                 \
00546     volatile bool b_die;                   /**< set by the outside */ \
00547     bool b_force;      /**< set by the outside (eg. module_need()) */ \
00548                                                                             \
00549     /* Stuff related to the libvlc structure */                             \
00550     libvlc_int_t *p_libvlc;                  /**< (root of all evil) - 1 */ \
00551                                                                             \
00552     vlc_object_t *  p_parent;                            /**< our parent */ \
00553                                                                             \
00554 /**@}*/                                                                     \
00555 
00556 /* VLC_OBJECT: attempt at doing a clever cast */
00557 #if defined( __GNUC__ ) && __GNUC__ > 3
00558 # ifndef __cplusplus
00559 #  define VLC_OBJECT( x ) \
00560     __builtin_choose_expr(__builtin_offsetof(__typeof__(*x), psz_object_type), \
00561                           (void)0 /* screw you */, (vlc_object_t *)(x))
00562 # else
00563 #  define VLC_OBJECT( x ) \
00564     ((vlc_object_t *)(x) \
00565       + 0 * __builtin_offsetof(__typeof__(*x), psz_object_type))
00566 # endif
00567 #else
00568 # define VLC_OBJECT( x ) ((vlc_object_t *)(x))
00569 #endif
00570 
00571 typedef struct gc_object_t
00572 {
00573     vlc_atomic_t    refs;
00574     void          (*pf_destructor) (struct gc_object_t *);
00575 } gc_object_t;
00576 
00577 /**
00578  * These members are common to all objects that wish to be garbage-collected.
00579  */
00580 #define VLC_GC_MEMBERS gc_object_t vlc_gc_data;
00581 
00582 VLC_EXPORT(void *, vlc_gc_init, (gc_object_t *, void (*)(gc_object_t *)));
00583 VLC_EXPORT(void *, vlc_hold, (gc_object_t *));
00584 VLC_EXPORT(void, vlc_release, (gc_object_t *));
00585 
00586 #define vlc_gc_init( a,b ) vlc_gc_init( &(a)->vlc_gc_data, (b) )
00587 #define vlc_gc_incref( a ) vlc_hold( &(a)->vlc_gc_data )
00588 #define vlc_gc_decref( a ) vlc_release( &(a)->vlc_gc_data )
00589 #define vlc_priv( gc, t ) ((t *)(((char *)(gc)) - offsetof(t, vlc_gc_data)))
00590 
00591 /*****************************************************************************
00592  * Macros and inline functions
00593  *****************************************************************************/
00594 
00595 /* CEIL: division with round to nearest greater integer */
00596 #define CEIL(n, d)  ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
00597 
00598 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
00599 #define PAD(n, d)   ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
00600 
00601 /* __MAX and __MIN: self explanatory */
00602 #ifndef __MAX
00603 #   define __MAX(a, b)   ( ((a) > (b)) ? (a) : (b) )
00604 #endif
00605 #ifndef __MIN
00606 #   define __MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
00607 #endif
00608 
00609 LIBVLC_USED
00610 static inline int64_t GCD ( int64_t a, int64_t b )
00611 {
00612     while( b )
00613     {
00614         int64_t c = a % b;
00615         a = b;
00616         b = c;
00617     }
00618     return a;
00619 }
00620 
00621 /* function imported from libavutil/common.h */
00622 LIBVLC_USED
00623 static inline uint8_t clip_uint8_vlc( int32_t a )
00624 {
00625     if( a&(~255) ) return (-a)>>31;
00626     else           return a;
00627 }
00628 
00629 /* Count leading zeroes */
00630 LIBVLC_USED
00631 static inline unsigned clz (unsigned x)
00632 {
00633 #ifdef __GNUC_
00634     return __builtin_clz (x);
00635 #else
00636     unsigned i = sizeof (x) * 8;
00637 
00638     while (x)
00639     {
00640         x = x >> 1;
00641         i--;
00642     }
00643     return i;
00644 #endif
00645 }
00646 
00647 #define clz8( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint8_t)) * 8))
00648 #define clz16( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint16_t)) * 8))
00649 /* XXX: this assumes that int is 32-bits or more */
00650 #define clz32( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint32_t)) * 8))
00651 
00652 /* Free and set set the variable to NULL */
00653 #define FREENULL(a) do { free( a ); a = NULL; } while(0)
00654 
00655 #define EMPTY_STR(str) (!str || !*str)
00656 
00657 VLC_EXPORT( char const *, vlc_error, ( int ) LIBVLC_USED );
00658 
00659 #include <vlc_arrays.h>
00660 
00661 /* MSB (big endian)/LSB (little endian) conversions - network order is always
00662  * MSB, and should be used for both network communications and files. */
00663 LIBVLC_USED
00664 static inline uint16_t U16_AT( const void * _p )
00665 {
00666     const uint8_t * p = (const uint8_t *)_p;
00667     return ( ((uint16_t)p[0] << 8) | p[1] );
00668 }
00669 
00670 LIBVLC_USED
00671 static inline uint32_t U32_AT( const void * _p )
00672 {
00673     const uint8_t * p = (const uint8_t *)_p;
00674     return ( ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16)
00675               | ((uint32_t)p[2] << 8) | p[3] );
00676 }
00677 
00678 LIBVLC_USED
00679 static inline uint64_t U64_AT( const void * _p )
00680 {
00681     const uint8_t * p = (const uint8_t *)_p;
00682     return ( ((uint64_t)p[0] << 56) | ((uint64_t)p[1] << 48)
00683               | ((uint64_t)p[2] << 40) | ((uint64_t)p[3] << 32)
00684               | ((uint64_t)p[4] << 24) | ((uint64_t)p[5] << 16)
00685               | ((uint64_t)p[6] << 8) | p[7] );
00686 }
00687 
00688 LIBVLC_USED
00689 static inline uint16_t GetWLE( const void * _p )
00690 {
00691     const uint8_t * p = (const uint8_t *)_p;
00692     return ( ((uint16_t)p[1] << 8) | p[0] );
00693 }
00694 
00695 LIBVLC_USED
00696 static inline uint32_t GetDWLE( const void * _p )
00697 {
00698     const uint8_t * p = (const uint8_t *)_p;
00699     return ( ((uint32_t)p[3] << 24) | ((uint32_t)p[2] << 16)
00700               | ((uint32_t)p[1] << 8) | p[0] );
00701 }
00702 
00703 LIBVLC_USED
00704 static inline uint64_t GetQWLE( const void * _p )
00705 {
00706     const uint8_t * p = (const uint8_t *)_p;
00707     return ( ((uint64_t)p[7] << 56) | ((uint64_t)p[6] << 48)
00708               | ((uint64_t)p[5] << 40) | ((uint64_t)p[4] << 32)
00709               | ((uint64_t)p[3] << 24) | ((uint64_t)p[2] << 16)
00710               | ((uint64_t)p[1] << 8) | p[0] );
00711 }
00712 
00713 #define GetWBE( p )     U16_AT( p )
00714 #define GetDWBE( p )    U32_AT( p )
00715 #define GetQWBE( p )    U64_AT( p )
00716 
00717 /* Helper writer functions */
00718 #define SetWLE( p, v ) _SetWLE( (uint8_t*)(p), v)
00719 static inline void _SetWLE( uint8_t *p, uint16_t i_dw )
00720 {
00721     p[1] = ( i_dw >>  8 )&0xff;
00722     p[0] = ( i_dw       )&0xff;
00723 }
00724 
00725 #define SetDWLE( p, v ) _SetDWLE( (uint8_t*)(p), v)
00726 static inline void _SetDWLE( uint8_t *p, uint32_t i_dw )
00727 {
00728     p[3] = ( i_dw >> 24 )&0xff;
00729     p[2] = ( i_dw >> 16 )&0xff;
00730     p[1] = ( i_dw >>  8 )&0xff;
00731     p[0] = ( i_dw       )&0xff;
00732 }
00733 #define SetQWLE( p, v ) _SetQWLE( (uint8_t*)(p), v)
00734 static inline void _SetQWLE( uint8_t *p, uint64_t i_qw )
00735 {
00736     SetDWLE( p,   i_qw&0xffffffff );
00737     SetDWLE( p+4, ( i_qw >> 32)&0xffffffff );
00738 }
00739 #define SetWBE( p, v ) _SetWBE( (uint8_t*)(p), v)
00740 static inline void _SetWBE( uint8_t *p, uint16_t i_dw )
00741 {
00742     p[0] = ( i_dw >>  8 )&0xff;
00743     p[1] = ( i_dw       )&0xff;
00744 }
00745 
00746 #define SetDWBE( p, v ) _SetDWBE( (uint8_t*)(p), v)
00747 static inline void _SetDWBE( uint8_t *p, uint32_t i_dw )
00748 {
00749     p[0] = ( i_dw >> 24 )&0xff;
00750     p[1] = ( i_dw >> 16 )&0xff;
00751     p[2] = ( i_dw >>  8 )&0xff;
00752     p[3] = ( i_dw       )&0xff;
00753 }
00754 #define SetQWBE( p, v ) _SetQWBE( (uint8_t*)(p), v)
00755 static inline void _SetQWBE( uint8_t *p, uint64_t i_qw )
00756 {
00757     SetDWBE( p+4,   i_qw&0xffffffff );
00758     SetDWBE( p, ( i_qw >> 32)&0xffffffff );
00759 }
00760 
00761 #define hton16(i) htons(i)
00762 #define hton32(i) htonl(i)
00763 #define ntoh16(i) ntohs(i)
00764 #define ntoh32(i) ntohl(i)
00765 
00766 LIBVLC_USED
00767 static inline uint64_t ntoh64 (uint64_t ll)
00768 {
00769     union { uint64_t qw; uint8_t b[16]; } v = { ll };
00770     return ((uint64_t)v.b[0] << 56)
00771          | ((uint64_t)v.b[1] << 48)
00772          | ((uint64_t)v.b[2] << 40)
00773          | ((uint64_t)v.b[3] << 32)
00774          | ((uint64_t)v.b[4] << 24)
00775          | ((uint64_t)v.b[5] << 16)
00776          | ((uint64_t)v.b[6] <<  8)
00777          | ((uint64_t)v.b[7] <<  0);
00778 }
00779 #define hton64(i) ntoh64(i)
00780 
00781 /* */
00782 #define VLC_UNUSED(x) (void)(x)
00783 
00784 /* Stuff defined in src/extras/libc.c */
00785 
00786 #if defined(WIN32) || defined(UNDER_CE)
00787 /* win32, cl and icl support */
00788 #   if defined( _MSC_VER ) || !defined( __MINGW32__ )
00789 #       define __attribute__(x)
00790 #       define __inline__      __inline
00791 #       define S_IFBLK         0x3000  /* Block */
00792 #       define S_ISBLK(m)      (0)
00793 #       define S_ISCHR(m)      (0)
00794 #       define S_ISFIFO(m)     (((m)&_S_IFMT) == _S_IFIFO)
00795 #       define S_ISREG(m)      (((m)&_S_IFMT) == _S_IFREG)
00796 #   endif
00797 
00798 /* several type definitions */
00799 #   if defined( __MINGW32__ )
00800 #       if !defined( _OFF_T_ )
00801             typedef long long _off_t;
00802             typedef _off_t off_t;
00803 #           define _OFF_T_
00804 #       else
00805 #           ifdef off_t
00806 #               undef off_t
00807 #           endif
00808 #           define off_t long long
00809 #       endif
00810 #   endif
00811 
00812 #   if defined( _MSC_VER ) && !defined( __WXMSW__ )
00813 #       if !defined( _OFF_T_DEFINED )
00814             typedef __int64 off_t;
00815 #           define _OFF_T_DEFINED
00816 #       else
00817             /* for wx compatibility typedef long off_t; */
00818 #           define off_t __int64
00819 #       endif
00820 #   endif
00821 
00822 #   if defined( __BORLANDC__ )
00823 #       undef off_t
00824 #       define off_t unsigned __int64
00825 #   endif
00826 
00827 #   ifndef O_NONBLOCK
00828 #       define O_NONBLOCK 0
00829 #   endif
00830 
00831 #   ifndef alloca
00832 #       define alloca _alloca
00833 #   endif
00834 
00835 #   include <tchar.h>
00836 #endif
00837 
00838 VLC_EXPORT( bool, vlc_ureduce, ( unsigned *, unsigned *, uint64_t, uint64_t, uint64_t ) );
00839 
00840 VLC_EXPORT( void *, vlc_memalign, ( void **base, size_t alignment, size_t size ) LIBVLC_USED );
00841 
00842 /* iconv wrappers (defined in src/extras/libc.c) */
00843 typedef void *vlc_iconv_t;
00844 VLC_EXPORT( vlc_iconv_t, vlc_iconv_open, ( const char *, const char * ) LIBVLC_USED );
00845 VLC_EXPORT( size_t, vlc_iconv, ( vlc_iconv_t, const char **, size_t *, char **, size_t * ) LIBVLC_USED );
00846 VLC_EXPORT( int, vlc_iconv_close, ( vlc_iconv_t ) );
00847 
00848 /* execve wrapper (defined in src/extras/libc.c) */
00849 VLC_EXPORT( int, vlc_execve, ( vlc_object_t *p_object, int i_argc, char *const *pp_argv, char *const *pp_env, const char *psz_cwd, const char *p_in, size_t i_in, char **pp_data, size_t *pi_data ) LIBVLC_USED );
00850 #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)
00851 
00852 VLC_EXPORT( void, vlc_tdestroy, ( void *, void (*)(void *) ) );
00853 
00854 /* Fast large memory copy and memory set */
00855 VLC_EXPORT( void *, vlc_memcpy, ( void *, const void *, size_t ) );
00856 VLC_EXPORT( void *, vlc_memset, ( void *, int, size_t ) );
00857 
00858 /*****************************************************************************
00859  * I18n stuff
00860  *****************************************************************************/
00861 VLC_EXPORT( char *, vlc_gettext, ( const char *msgid ) LIBVLC_FORMAT_ARG(1) );
00862 
00863 #define vlc_pgettext( ctx, id ) \
00864         vlc_pgettext_aux( ctx "\004" id, id )
00865 
00866 LIBVLC_FORMAT_ARG(2)
00867 static inline const char *vlc_pgettext_aux( const char *ctx, const char *id )
00868 {
00869     const char *tr = vlc_gettext( ctx );
00870     return (tr == ctx) ? id : tr;
00871 }
00872 
00873 /*****************************************************************************
00874  * Loosy memory allocation functions. Do not use in new code.
00875  *****************************************************************************/
00876 static inline void *xmalloc (size_t len)
00877 {
00878     void *ptr = malloc (len);
00879     if (unlikely (ptr == NULL))
00880         abort ();
00881     return ptr;
00882 }
00883 
00884 static inline void *xrealloc (void *ptr, size_t len)
00885 {
00886     void *nptr = realloc (ptr, len);
00887     if (unlikely (nptr == NULL))
00888         abort ();
00889     return nptr;
00890 }
00891 
00892 /*****************************************************************************
00893  * libvlc features
00894  *****************************************************************************/
00895 VLC_EXPORT( const char *, VLC_Version, ( void ) LIBVLC_USED );
00896 VLC_EXPORT( const char *, VLC_CompileBy, ( void ) LIBVLC_USED );
00897 VLC_EXPORT( const char *, VLC_CompileHost, ( void ) LIBVLC_USED );
00898 VLC_EXPORT( const char *, VLC_Compiler, ( void ) LIBVLC_USED );
00899 
00900 /*****************************************************************************
00901  * Additional vlc stuff
00902  *****************************************************************************/
00903 #include "vlc_messages.h"
00904 #include "vlc_objects.h"
00905 #include "vlc_variables.h"
00906 #include "vlc_main.h"
00907 #include "vlc_configuration.h"
00908 
00909 #if defined( WIN32 ) || defined( UNDER_CE )
00910 #   define DIR_SEP_CHAR '\\'
00911 #   define DIR_SEP "\\"
00912 #   define PATH_SEP_CHAR ';'
00913 #   define PATH_SEP ";"
00914 #else
00915 #   define DIR_SEP_CHAR '/'
00916 #   define DIR_SEP "/"
00917 #   define PATH_SEP_CHAR ':'
00918 #   define PATH_SEP ":"
00919 #endif
00920 
00921 #define LICENSE_MSG \
00922   _("This program comes with NO WARRANTY, to the extent permitted by " \
00923     "law.\nYou may redistribute it under the terms of the GNU General " \
00924     "Public License;\nsee the file named COPYING for details.\n" \
00925     "Written by the VideoLAN team; see the AUTHORS file.\n")
00926 
00927 #endif /* !VLC_COMMON_H */

Generated on Mon Nov 22 07:55:19 2010 for VLC by  doxygen 1.5.6