X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Flibvlc.c;h=1349eb67ae2bb599700ededeb90f481f2978c1c4;hb=cd0c2c45c0198ec38cce4af877b033529639ddaa;hp=9affe8cf374ac61a60a500dc0214ed6222a5706a;hpb=6197b056e6f9bd026012db6f1512bbd981e27442;p=vlc diff --git a/src/libvlc.c b/src/libvlc.c index 9affe8cf37..1349eb67ae 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -68,6 +68,8 @@ # include #endif + +#include #include #include @@ -78,6 +80,7 @@ #include #include #include +#include #include "libvlc.h" @@ -116,18 +119,7 @@ void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *)) assert (pf_destruct); p_gc->pf_destructor = pf_destruct; - p_gc->refs = 1; -#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) - __sync_synchronize (); -#elif defined (WIN32) && defined (__GNUC__) -#elif defined(__APPLE__) - OSMemoryBarrier (); -#else - /* Nobody else can possibly lock the spin - it's there as a barrier */ - vlc_spin_init (&p_gc->spin); - vlc_spin_lock (&p_gc->spin); - vlc_spin_unlock (&p_gc->spin); -#endif + vlc_atomic_set (&p_gc->refs, 1); return p_gc; } @@ -139,22 +131,9 @@ void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *)) void *vlc_hold (gc_object_t * p_gc) { uintptr_t refs; + assert( p_gc ); - assert ((((uintptr_t)&p_gc->refs) & (sizeof (void *) - 1)) == 0); /* alignment */ - -#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) - refs = __sync_add_and_fetch (&p_gc->refs, 1); -#elif defined (WIN64) - refs = InterlockedIncrement64 (&p_gc->refs); -#elif defined (WIN32) - refs = InterlockedIncrement (&p_gc->refs); -#elif defined(__APPLE__) - refs = OSAtomicIncrement32Barrier((int*)&p_gc->refs); -#else - vlc_spin_lock (&p_gc->spin); - refs = ++p_gc->refs; - vlc_spin_unlock (&p_gc->spin); -#endif + refs = vlc_atomic_inc (&p_gc->refs); assert (refs != 1); /* there had to be a reference already */ return p_gc; } @@ -168,33 +147,10 @@ void vlc_release (gc_object_t *p_gc) unsigned refs; assert( p_gc ); - assert ((((uintptr_t)&p_gc->refs) & (sizeof (void *) - 1)) == 0); /* alignment */ - -#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) - refs = __sync_sub_and_fetch (&p_gc->refs, 1); -#elif defined (WIN64) - refs = InterlockedDecrement64 (&p_gc->refs); -#elif defined (WIN32) - refs = InterlockedDecrement (&p_gc->refs); -#elif defined(__APPLE__) - refs = OSAtomicDecrement32Barrier((int*)&p_gc->refs); -#else - vlc_spin_lock (&p_gc->spin); - refs = --p_gc->refs; - vlc_spin_unlock (&p_gc->spin); -#endif - + refs = vlc_atomic_dec (&p_gc->refs); assert (refs != (uintptr_t)(-1)); /* reference underflow?! */ if (refs == 0) - { -#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) -#elif defined (WIN32) && defined (__GNUC__) -#elif defined(__APPLE__) -#else - vlc_spin_destroy (&p_gc->spin); -#endif p_gc->pf_destructor (p_gc); - } } /***************************************************************************** @@ -251,6 +207,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) priv = libvlc_priv (p_libvlc); priv->p_playlist = NULL; + priv->p_ml = NULL; priv->p_dialog_provider = NULL; priv->p_vlm = NULL; @@ -272,6 +229,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) #endif /* Initialize mutexes */ + vlc_mutex_init( &priv->ml_lock ); vlc_mutex_init( &priv->timer_lock ); vlc_ExitInit( &priv->exit ); @@ -803,6 +761,11 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING ); var_Create( p_libvlc, "record-file", VLC_VAR_STRING ); + /* some default internal settings */ + var_Create( p_libvlc, "window", VLC_VAR_STRING ); + var_Create( p_libvlc, "user-agent", VLC_VAR_STRING ); + var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" ); + /* Initialize playlist and get commandline files */ p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) ); if( !p_playlist ) @@ -819,6 +782,23 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, /* System specific configuration */ system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); +#if defined(MEDIA_LIBRARY) + /* Get the ML */ + if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) == true ) + { + priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL ); + if( !priv->p_ml ) + { + msg_Err( p_libvlc, "ML initialization failed" ); + return VLC_EGENERIC; + } + } + else + { + priv->p_ml = NULL; + } +#endif + /* Add service discovery modules */ psz_modules = var_InheritString( p_libvlc, "services-discovery" ); if( psz_modules ) @@ -948,6 +928,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, } #endif +#ifdef __APPLE__ var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER ); @@ -956,6 +937,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER ); +#endif #ifdef WIN32 var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_ADDRESS ); #endif @@ -1014,6 +996,16 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) /* Free playlist now, all threads are gone */ playlist_Destroy( p_playlist ); +#if defined(MEDIA_LIBRARY) + media_library_t* p_ml = priv->p_ml; + if( p_ml ) + { + ml_Destroy( VLC_OBJECT( p_ml ) ); + vlc_object_release( p_ml ); + libvlc_priv(p_playlist->p_libvlc)->p_ml = NULL; + } +#endif + stats_TimersDumpAll( p_libvlc ); stats_TimersCleanAll( p_libvlc ); @@ -1076,6 +1068,7 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc ) /* Destroy mutexes */ vlc_ExitDestroy( &priv->exit ); vlc_mutex_destroy( &priv->timer_lock ); + vlc_mutex_destroy( &priv->ml_lock ); #ifndef NDEBUG /* Hack to dump leaked objects tree */ if( vlc_internals( p_libvlc )->i_refcount > 1 ) @@ -1177,9 +1170,7 @@ static void GetFilenames( libvlc_int_t *p_vlc, unsigned n, } } - /* TODO: write an internal function of this one, to avoid - * unnecessary lookups. */ - char *mrl = make_URI( args[n] ); + char *mrl = make_URI( args[n], NULL ); if( !mrl ) continue; @@ -1967,15 +1958,3 @@ static int ConsoleWidth( void ) return i_width; } - -#include - -void vlc_avcodec_mutex (bool acquire) -{ - static vlc_mutex_t lock = VLC_STATIC_MUTEX; - - if (acquire) - vlc_mutex_lock (&lock); - else - vlc_mutex_unlock (&lock); -}