]> git.sesse.net Git - vlc/blobdiff - include/vlc_common.h
Include assert.h when needed
[vlc] / include / vlc_common.h
index 923586de31f5fb937857b822abd46d09cb9e64c6..7719c0fe344eaec8283d5b4dfacedf33f7f73fe3 100644 (file)
  * This file is a collection of common definitions and types
  */
 
+#ifndef PACKAGE
+/* Temporary regression test */
+#error You probably forgot to include config.h!!
+#endif
+
 /*****************************************************************************
  * Required vlc headers
  *****************************************************************************/
-#if defined( __BORLANDC__ )
-#   undef PACKAGE
-#endif
-
-#include "config.h"
-
-#if defined(PACKAGE)
-#   undef PACKAGE_NAME
-#   define PACKAGE_NAME PACKAGE
-#endif
-#if defined(VERSION)
-#   undef PACKAGE_VERSION
-#   define PACKAGE_VERSION VERSION
-#endif
-
 #if defined( __BORLANDC__ )
 #   undef HAVE_VARIADIC_MACROS
 #   undef HAVE_STDINT_H
@@ -281,6 +271,7 @@ typedef struct access_sys_t access_sys_t;
 typedef struct stream_t     stream_t;
 typedef struct stream_sys_t stream_sys_t;
 typedef struct demux_t  demux_t;
+typedef struct demux_meta_t demux_meta_t;
 typedef struct demux_sys_t demux_sys_t;
 typedef struct es_out_t     es_out_t;
 typedef struct es_out_id_t  es_out_id_t;
@@ -311,7 +302,6 @@ typedef struct aout_filter_t aout_filter_t;
 /* Video */
 typedef struct vout_thread_t vout_thread_t;
 typedef struct vout_sys_t vout_sys_t;
-typedef struct vout_synchro_t vout_synchro_t;
 typedef struct chroma_sys_t chroma_sys_t;
 
 typedef video_format_t video_frame_format_t;
@@ -365,8 +355,9 @@ typedef struct sout_gui_descr_t sout_gui_descr_t;
 typedef struct profile_parser_t profile_parser_t;
 
 /* Decoders */
-typedef struct decoder_t      decoder_t;
-typedef struct decoder_sys_t  decoder_sys_t;
+typedef struct decoder_t         decoder_t;
+typedef struct decoder_sys_t     decoder_sys_t;
+typedef struct decoder_synchro_t decoder_synchro_t;
 
 /* Encoders */
 typedef struct encoder_t      encoder_t;
@@ -382,6 +373,7 @@ typedef struct virtual_socket_t v_socket_t;
 typedef struct sockaddr sockaddr;
 typedef struct addrinfo addrinfo;
 typedef struct vlc_acl_t vlc_acl_t;
+typedef struct vlc_url_t vlc_url_t;
 
 /* Misc */
 typedef struct iso639_lang_t iso639_lang_t;
@@ -606,27 +598,42 @@ struct gc_object_t
             VLC_GC_MEMBERS
 };
 
+#include <assert.h> /* FIXME: should not be included here */
+
 static inline void __vlc_gc_incref( gc_object_t * p_gc )
 {
+    assert( p_gc->i_gc_refcount > 0 );
+
     p_gc->i_gc_refcount ++;
 };
 
 static inline void __vlc_gc_decref( gc_object_t *p_gc )
 {
+    if( !p_gc ) return;
+
+    assert( p_gc->i_gc_refcount > 0 );
+
     p_gc->i_gc_refcount -- ;
 
     if( p_gc->i_gc_refcount == 0 )
     {
         p_gc->pf_destructor( p_gc );
         /* Do not use the p_gc pointer from now on ! */
-     }
+    }
+}
+
+static inline void
+__vlc_gc_init( gc_object_t * p_gc, void (*pf_destructor)( gc_object_t * ),
+               void * arg)
+{
+    p_gc->i_gc_refcount = 1;
+    p_gc->pf_destructor = pf_destructor;
+    p_gc->p_destructor_arg = arg;
 }
 
 #define vlc_gc_incref( a ) __vlc_gc_incref( (gc_object_t *)a )
 #define vlc_gc_decref( a ) __vlc_gc_decref( (gc_object_t *)a )
-#define vlc_gc_init( a,b,c ) {  ((gc_object_t *)a)->i_gc_refcount = 0; \
-                              ((gc_object_t *)a)->pf_destructor = b; \
-                              ((gc_object_t *)a)->p_destructor_arg = c; }
+#define vlc_gc_init( a,b,c ) __vlc_gc_init( (gc_object_t *)a,b,c )
 
 
 /*****************************************************************************
@@ -654,10 +661,15 @@ static inline void __vlc_gc_decref( gc_object_t *p_gc )
 #   define __MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
 #endif
 
-static int64_t GCD( int64_t a, int64_t b )
+static inline int64_t GCD( int64_t a, int64_t b )
 {
-    if( b ) return GCD( b, a % b );
-    else return a;
+    while( b )
+    {
+        int64_t c = a % b;
+        a = b;
+        b = c;
+    }
+    return a;
 }
 
 /* function imported from libavutil/common.h */
@@ -683,8 +695,7 @@ static inline uint8_t clip_uint8_vlc( int32_t a )
 #define DECMALLOC_NULL( var, type ) type* var = (type*)malloc( sizeof(type) );\
                                     if( !var ) return NULL;
 
-#define FREENULL(a) do { if( a ) { free( a ); a = NULL; } } while(0)
-#define FREE(a) do { if( a ) { free( a ); } } while(0)
+#define FREENULL(a) do { free( a ); a = NULL; } while(0)
 
 #define EMPTY_STR(str) (!str || !*str)
 
@@ -1027,12 +1038,12 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw )
 
 #if defined (WIN32)
 #   include <dirent.h>
-VLC_INTERNAL( void *, vlc_wopendir, ( const wchar_t * ) );
-VLC_INTERNAL( struct _wdirent *, vlc_wreaddir, ( void * ) );
-VLC_EXPORT( int, vlc_wclosedir, ( void * ) );
-VLC_INTERNAL( void, vlc_rewinddir, ( void * ) );
-VLC_INTERNAL( void, vlc_seekdir, ( void *, long ) );
-VLC_INTERNAL( long, vlc_telldir, ( void * ) );
+ VLC_INTERNAL( void *, vlc_wopendir, ( const wchar_t * ) );
+ VLC_INTERNAL( struct _wdirent *, vlc_wreaddir, ( void * ) );
+ VLC_EXPORT( int, vlc_wclosedir, ( void * ) );
+ VLC_INTERNAL( void, vlc_rewinddir, ( void * ) );
+ VLC_INTERNAL( void, vlc_seekdir, ( void *, long ) );
+ VLC_INTERNAL( long, vlc_telldir, ( void * ) );
 #   define opendir Use_utf8_opendir_or_vlc_wopendir_instead!
 #   define readdir Use_utf8_readdir_or_vlc_wreaddir_instead!
 #   define closedir vlc_wclosedir
@@ -1183,7 +1194,7 @@ VLC_EXPORT( unsigned, vlc_CPU, ( void ) );
  * I18n stuff
  *****************************************************************************/
 #ifdef WIN32
-VLC_EXPORT( char *, vlc_dgettext, ( const char *package, const char *msgid ) );
+    VLC_EXPORT( char *, vlc_dgettext, ( const char *package, const char *msgid ) );
 #endif
 
 #if defined( ENABLE_NLS ) && \