X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Flibvlc.c;h=519efa1ede4360db70536374148931682500592b;hb=55c960749e8f91763e720ac610d5dd56f90fcde1;hp=235d000aebe40ba02170a0697f96ff84854314f4;hpb=1775b86891966052dcb46f123ddf77c849557cc6;p=vlc diff --git a/src/libvlc.c b/src/libvlc.c index 235d000aeb..519efa1ede 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -42,7 +42,6 @@ #include "modules/modules.h" #include "config/configuration.h" -#include "interface/interface.h" #include /* ENOMEM */ #include /* sprintf() */ @@ -67,6 +66,10 @@ # include #endif +#ifdef ENABLE_NLS +# include /* bindtextdomain */ +#endif + #ifdef HAVE_DBUS /* used for one-instance mode */ # include @@ -258,7 +261,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) priv = libvlc_priv (p_libvlc); priv->p_playlist = NULL; - priv->p_interaction = NULL; + priv->p_dialog_provider = NULL; priv->p_vlm = NULL; p_libvlc->psz_object_name = strdup( "libvlc" ); @@ -279,7 +282,6 @@ libvlc_int_t * libvlc_InternalCreate( void ) /* Initialize mutexes */ vlc_mutex_init( &priv->timer_lock ); - vlc_mutex_init( &priv->config_lock ); vlc_cond_init( &priv->exiting ); return p_libvlc; @@ -337,7 +339,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, /* Announce who we are - Do it only for first instance ? */ msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE ); msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE ); - /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */ + /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */ msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") ); /* Check for short help option */ @@ -355,9 +357,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, i_ret = VLC_EEXITSUCCESS; } - /* Set the config file stuff */ - priv->psz_configfile = config_GetCustomConfigFile( p_libvlc ); - /* Check for plugins cache options */ bool b_cache_delete = config_GetInt( p_libvlc, "reset-plugins-cache" ) > 0; @@ -428,7 +427,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, if( b_exit ) { - free( priv->psz_configfile ); module_EndBank( p_libvlc, false ); return i_ret; } @@ -540,7 +538,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, if( b_exit ) { - free( priv->psz_configfile ); module_EndBank( p_libvlc, true ); return i_ret; } @@ -568,7 +565,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, "that they are valid.\n" ); PauseConsole(); #endif - free( priv->psz_configfile ); module_EndBank( p_libvlc, true ); return VLC_EGENERIC; } @@ -798,14 +794,25 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, */ var_Create( p_libvlc, "key-pressed", VLC_VAR_INTEGER ); var_Create( p_libvlc, "key-action", VLC_VAR_INTEGER ); - p_libvlc->p_hotkeys = malloc( libvlc_hotkeys_size ); - /* Do a copy (we don't need to modify the strings) */ - memcpy( p_libvlc->p_hotkeys, libvlc_hotkeys, libvlc_hotkeys_size ); - var_AddCallback( p_libvlc, "key-pressed", vlc_key_to_action, - p_libvlc->p_hotkeys ); + { + struct hotkey *p_keys = + malloc( (libvlc_actions_count + 1) * sizeof (*p_keys) ); - /* Initialize interaction */ - priv->p_interaction = interaction_Init( p_libvlc ); + /* Initialize from configuration */ + for( size_t i = 0; i < libvlc_actions_count; i++ ) + { + p_keys[i].psz_action = libvlc_actions[i].name; + p_keys[i].i_key = config_GetInt( p_libvlc, + libvlc_actions[i].name ); + p_keys[i].i_action = libvlc_actions[i].value; + } + p_keys[libvlc_actions_count].psz_action = NULL; + p_keys[libvlc_actions_count].i_key = 0; + p_keys[libvlc_actions_count].i_action = 0; + p_libvlc->p_hotkeys = p_keys; + var_AddCallback( p_libvlc, "key-pressed", vlc_key_to_action, + p_keys ); + } /* Initialize playlist and get commandline files */ p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) ); @@ -817,7 +824,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, module_unneed( p_libvlc, priv->p_memcpy_module ); } module_EndBank( p_libvlc, true ); - free( priv->psz_configfile ); return VLC_EGENERIC; } playlist_Activate( p_playlist ); @@ -879,7 +885,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, } if( asprintf( &psz_temp, "%s,none", psz_module ) != -1) { - libvlc_InternalAddIntf( p_libvlc, psz_temp ); + intf_Create( p_libvlc, psz_temp ); free( psz_temp ); } } @@ -889,9 +895,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, /* * Always load the hotkeys interface if it exists */ - libvlc_InternalAddIntf( p_libvlc, "hotkeys,none" ); - if( module_exists( "globalhotkeys" ) ) - libvlc_InternalAddIntf( p_libvlc, "globalhotkeys,none" ); + intf_Create( p_libvlc, "hotkeys,none" ); #ifdef HAVE_DBUS /* loads dbus control interface if in one-instance mode @@ -899,12 +903,12 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, if( config_GetInt( p_libvlc, "one-instance" ) > 0 || ( config_GetInt( p_libvlc, "one-instance-when-started-from-file" ) && config_GetInt( p_libvlc, "started-from-file" ) ) ) - libvlc_InternalAddIntf( p_libvlc, "dbus,none" ); + intf_Create( p_libvlc, "dbus,none" ); /* Prevents the power management daemon from suspending the system * when VLC is active */ if( config_GetInt( p_libvlc, "inhibit" ) > 0 ) - libvlc_InternalAddIntf( p_libvlc, "inhibit,none" ); + intf_Create( p_libvlc, "inhibit,none" ); #endif /* @@ -914,21 +918,21 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, #ifdef HAVE_X11_XLIB_H if( config_GetInt( p_libvlc, "disable-screensaver" ) ) { - libvlc_InternalAddIntf( p_libvlc, "screensaver,none" ); + intf_Create( p_libvlc, "screensaver,none" ); } #endif if( (config_GetInt( p_libvlc, "file-logging" ) > 0) && !config_GetInt( p_libvlc, "syslog" ) ) { - libvlc_InternalAddIntf( p_libvlc, "logger,none" ); + intf_Create( p_libvlc, "logger,none" ); } #ifdef HAVE_SYSLOG_H if( config_GetInt( p_libvlc, "syslog" ) > 0 ) { char *logmode = var_CreateGetString( p_libvlc, "logmode" ); var_SetString( p_libvlc, "logmode", "syslog" ); - libvlc_InternalAddIntf( p_libvlc, "logger,none" ); + intf_Create( p_libvlc, "logger,none" ); if( logmode ) { @@ -942,12 +946,12 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, if( config_GetInt( p_libvlc, "show-intf" ) > 0 ) { - libvlc_InternalAddIntf( p_libvlc, "showintf,none" ); + intf_Create( p_libvlc, "showintf,none" ); } if( config_GetInt( p_libvlc, "network-synchronisation") > 0 ) { - libvlc_InternalAddIntf( p_libvlc, "netsync,none" ); + intf_Create( p_libvlc, "netsync,none" ); } #ifdef WIN32 @@ -969,14 +973,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, } #endif - /* - * FIXME: kludge to use a p_libvlc-local variable for the Mozilla plugin - */ - var_Create( p_libvlc, "drawable-xid", VLC_VAR_INTEGER ); - var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_ADDRESS ); -#ifdef __APPLE__ - var_Create( p_libvlc, "drawable", VLC_VAR_INTEGER ); -#endif 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 ); @@ -1036,14 +1032,8 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) /* Ask the interfaces to stop and destroy them */ msg_Dbg( p_libvlc, "removing all interfaces" ); - intf_thread_t *p_intf; - while( (p_intf = vlc_object_find( p_libvlc, VLC_OBJECT_INTF, FIND_CHILD )) ) - { - intf_StopThread( p_intf ); - vlc_object_detach( p_intf ); - vlc_object_release( p_intf ); /* for intf_Create() */ - vlc_object_release( p_intf ); /* for vlc_object_find() */ - } + libvlc_Quit( p_libvlc ); + intf_DestroyAll( p_libvlc ); #ifdef ENABLE_VLM /* Destroy VLM if created in libvlc_InternalInit */ @@ -1062,10 +1052,6 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) vlc_object_release( p_playlist ); - /* Free interaction */ - msg_Dbg( p_libvlc, "removing interaction" ); - interaction_Destroy( priv->p_interaction ); - stats_TimersDumpAll( p_libvlc ); stats_TimersCleanAll( p_libvlc ); @@ -1099,10 +1085,9 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) /* Free module bank. It is refcounted, so we call this each time */ module_EndBank( p_libvlc, true ); - FREENULL( priv->psz_configfile ); var_DelCallback( p_libvlc, "key-pressed", vlc_key_to_action, - p_libvlc->p_hotkeys ); - FREENULL( p_libvlc->p_hotkeys ); + (void *)p_libvlc->p_hotkeys ); + free( (void *)p_libvlc->p_hotkeys ); } /** @@ -1130,9 +1115,14 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc ) /* Destroy mutexes */ vlc_cond_destroy( &priv->exiting ); - vlc_mutex_destroy( &priv->config_lock ); vlc_mutex_destroy( &priv->timer_lock ); +#ifndef NDEBUG /* Hack to dump leaked objects tree */ + if( vlc_internals( p_libvlc )->i_refcount > 1 ) + while( vlc_internals( p_libvlc )->i_refcount > 0 ) + vlc_object_release( p_libvlc ); +#endif + assert( vlc_internals( p_libvlc )->i_refcount == 1 ); vlc_object_release( p_libvlc ); } @@ -1142,9 +1132,6 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc ) */ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module ) { - int i_err; - intf_thread_t *p_intf = NULL; - if( !p_libvlc ) return VLC_EGENERIC; @@ -1160,31 +1147,22 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module ) psz_module = "dummy"; else #endif - msg_Info( p_libvlc, _("Running vlc with the default interface. Use 'cvlc' to use vlc without interface.") ); + msg_Info( p_libvlc, "%s", + _("Running vlc with the default interface. " + "Use 'cvlc' to use vlc without interface.") ); } free( psz_interface ); } /* Try to create the interface */ - p_intf = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" ); - if( p_intf == NULL ) + if( intf_Create( p_libvlc, psz_module ? psz_module : "$intf" ) ) { msg_Err( p_libvlc, "interface \"%s\" initialization failed", psz_module ); return VLC_EGENERIC; } - - /* Try to run the interface */ - i_err = intf_RunThread( p_intf ); - if( i_err ) - { - vlc_object_detach( p_intf ); - vlc_object_release( p_intf ); - return i_err; - } - return VLC_SUCCESS; -}; +} static vlc_mutex_t exit_lock = VLC_STATIC_MUTEX; @@ -1976,7 +1954,7 @@ static void Version( void ) utf8_fprintf( stdout, _("Compiled by %s@%s.%s\n"), VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() ); utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() ); - utf8_fprintf( stdout, LICENSE_MSG ); + utf8_fprintf( stdout, "%s", LICENSE_MSG ); #ifdef WIN32 /* Pause the console because it's destroyed when we exit */ PauseConsole(); @@ -2132,3 +2110,15 @@ static void InitDeviceValues( libvlc_int_t *p_vlc ) (void)p_vlc; #endif /* HAVE_HAL */ } + +#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); +}