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

Generated on Fri Nov 20 08:04:56 2009 for VLC by  doxygen 1.5.6