]> git.sesse.net Git - vlc/blobdiff - src/libvlc-common.c
Add long overdue private libvlc object pointer...
[vlc] / src / libvlc-common.c
index ee4dfe7fce222f062cc36e5daf6734a696041e4a..2e648d4ace09c64a0408a4d3ca6d4c1c6d350de3 100644 (file)
 #include <vlc_vlm.h>
 
 /*****************************************************************************
- * The evil global variable. We handle it with care, don't worry.
+ * The evil global variables. We handle them with care, don't worry.
  *****************************************************************************/
-static libvlc_global_data_t   libvlc_global;
-static libvlc_global_data_t *p_libvlc_global = &libvlc_global;
 static libvlc_int_t *    p_static_vlc = NULL;
 static volatile unsigned int i_instances = 0;
 
+static bool b_daemon = false;
+
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -128,11 +128,6 @@ static int  VerboseCallback( vlc_object_t *, char const *,
 
 static void InitDeviceValues( libvlc_int_t * );
 
-libvlc_global_data_t *vlc_global( void )
-{
-    return p_libvlc_global;
-}
-
 /*****************************************************************************
  * vlc_current_object: return the current object.
  *****************************************************************************
@@ -151,43 +146,43 @@ libvlc_int_t * vlc_current_object( int i_object )
  */
 libvlc_int_t * libvlc_InternalCreate( void )
 {
-    int i_ret;
-    libvlc_int_t * p_libvlc = NULL;
+    libvlc_int_t *p_libvlc;
+    libvlc_priv_t *priv;
     char *psz_env = NULL;
 
     /* vlc_threads_init *must* be the first internal call! No other call is
      * allowed before the thread system has been initialized. */
-    i_ret = vlc_threads_init( p_libvlc_global );
-    if( i_ret < 0 ) return NULL;
+    if (vlc_threads_init ())
+        return NULL;
 
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
     /* Now that the thread system is initialized, we don't have much, but
      * at least we have variables */
     vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
-
-    i_instances++;
-
-    if( !p_libvlc_global->b_ready )
+    if( i_instances == 0 )
     {
         /* Guess what CPU we have */
         cpu_flags = CPUCapabilities();
        /* The module bank will be initialized later */
         p_libvlc_global->p_module_bank = NULL;
-
-        p_libvlc_global->b_ready = true;
     }
-    vlc_mutex_unlock( lock );
 
     /* Allocate a libvlc instance object */
-    p_libvlc = vlc_object_create( p_libvlc_global, VLC_OBJECT_LIBVLC );
+    p_libvlc = vlc_custom_create( VLC_OBJECT(p_libvlc_global),
+                                  sizeof (*p_libvlc) + sizeof (libvlc_priv_t),
+                                  VLC_OBJECT_LIBVLC, "libvlc" );
+    if( p_libvlc != NULL )
+        i_instances++;
+    vlc_mutex_unlock( lock );
+
     if( p_libvlc == NULL )
-    {
-        i_instances--;
         return NULL;
-    }
+
     p_libvlc->p_playlist = NULL;
     p_libvlc->p_interaction = NULL;
     p_libvlc->p_vlm = NULL;
     p_libvlc->psz_object_name = strdup( "libvlc" );
+    priv = libvlc_priv (p_libvlc);
 
     /* Initialize message queue */
     msg_Create( p_libvlc );
@@ -209,10 +204,9 @@ libvlc_int_t * libvlc_InternalCreate( void )
     msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
 
     /* Initialize mutexes */
-    vlc_mutex_init( p_libvlc, &p_libvlc->timer_lock );
-    vlc_mutex_init( p_libvlc, &p_libvlc->config_lock );
+    vlc_mutex_init( &priv->timer_lock );
+    vlc_mutex_init( &priv->config_lock );
 #ifdef __APPLE__
-    vlc_mutex_init( p_libvlc, &p_libvlc->quicktime_lock );
     vlc_thread_set_priority( p_libvlc, VLC_THREAD_PRIORITY_LOW );
 #endif
     /* Store data for the non-reentrant API */
@@ -232,6 +226,8 @@ libvlc_int_t * libvlc_InternalCreate( void )
 int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
                          const char *ppsz_argv[] )
 {
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
+    libvlc_priv_t *priv = libvlc_priv (p_libvlc);
     char         p_capabilities[200];
     char *       p_tmp = NULL;
     char *       psz_modules = NULL;
@@ -331,7 +327,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
             msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
             b_exit = true;
         }
-        p_libvlc_global->b_daemon = true;
+        b_daemon = true;
 
         /* lets check if we need to write the pidfile */
         psz_pidfile = config_GetPsz( p_libvlc, "pidfile" );
@@ -378,7 +374,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
             close( STDOUT_FILENO );
             close( STDERR_FILENO );
 
-            p_libvlc_global->b_daemon = true;
+            b_daemon = true;
         }
 #endif
     }
@@ -714,19 +710,9 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
      */
     p_libvlc->p_memcpy_module = module_Need( p_libvlc, "memcpy", "$memcpy", 0 );
 
-    if( p_libvlc->pf_memcpy == NULL )
-    {
-        p_libvlc->pf_memcpy = memcpy;
-    }
-
-    if( p_libvlc->pf_memset == NULL )
-    {
-        p_libvlc->pf_memset = memset;
-    }
-
-    p_libvlc->b_stats = config_GetInt( p_libvlc, "stats" ) > 0;
-    p_libvlc->i_timers = 0;
-    p_libvlc->pp_timers = NULL;
+    priv->b_stats = config_GetInt( p_libvlc, "stats" ) > 0;
+    priv->i_timers = 0;
+    priv->pp_timers = NULL;
 
     /* Init stats */
     p_libvlc->p_stats = (global_stats_t *)malloc( sizeof( global_stats_t ) );
@@ -735,7 +721,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         vlc_object_release( p_libvlc );
         return VLC_ENOMEM;
     }
-    vlc_mutex_init( p_libvlc, &p_libvlc->p_stats->lock );
+    vlc_mutex_init( &p_libvlc->p_stats->lock );
     p_libvlc->p_stats_computer = NULL;
 
     /* Init the array that holds every input item */
@@ -778,6 +764,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     }
     free( psz_modules );
 
+#ifdef ENABLE_SOUT
     /* Initialize VLM if vlm-conf is specified */
     psz_parser = config_GetPsz( p_libvlc, "vlm-conf" );
     if( psz_parser && *psz_parser )
@@ -787,6 +774,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
             msg_Err( p_libvlc, "VLM initialization failed" );
     }
     free( psz_parser );
+#endif
 
     /*
      * Load background interfaces
@@ -839,7 +827,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     if( config_GetInt( p_libvlc, "one-instance" ) > 0 )
         VLC_AddIntf( 0, "dbus,none", false, false );
 
-    /* Prevents the power management daemon to suspend the computer
+    /* Prevents the power management daemon from suspending the system
      * when VLC is active */
     if( config_GetInt( p_libvlc, "inhibit" ) > 0 )
         VLC_AddIntf( 0, "inhibit,none", false, false );
@@ -944,8 +932,6 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     intf_thread_t      * p_intf = NULL;
     vout_thread_t      * p_vout = NULL;
     aout_instance_t    * p_aout = NULL;
-    announce_handler_t * p_announce = NULL;
-    sout_instance_t    * p_sout = NULL;
 
     /* Ask the interfaces to stop and destroy them */
     msg_Dbg( p_libvlc, "removing all interfaces" );
@@ -980,6 +966,9 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
         aout_Delete( p_aout );
     }
 
+#ifdef ENABLE_SOUT
+    sout_instance_t    * p_sout;
+
     p_sout = vlc_object_find( p_libvlc, VLC_OBJECT_SOUT, FIND_CHILD );
     if( p_sout )
     {
@@ -994,6 +983,7 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     {
         vlm_Delete( p_libvlc->p_vlm );
     }
+#endif
 
     /* Free interaction */
     msg_Dbg( p_libvlc, "removing interaction" );
@@ -1002,6 +992,9 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     stats_TimersDumpAll( p_libvlc );
     stats_TimersCleanAll( p_libvlc );
 
+#ifdef ENABLE_SOUT
+    announce_handler_t * p_announce;
+
     /* Free announce handler(s?) */
     while( (p_announce = vlc_object_find( p_libvlc, VLC_OBJECT_ANNOUNCE,
                                                  FIND_CHILD ) ) )
@@ -1011,6 +1004,7 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
         vlc_object_release( p_announce );
         announce_HandlerDestroy( p_announce );
     }
+#endif
 
     bool b_clean = true;
     FOREACH_ARRAY( input_item_t *p_del, p_libvlc->input_items )
@@ -1041,6 +1035,8 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release )
     if( !p_libvlc )
         return VLC_EGENERIC;
 
+    libvlc_priv_t *priv = libvlc_priv (p_libvlc);
+
 #ifndef WIN32
     char* psz_pidfile = NULL;
 
@@ -1092,8 +1088,8 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release )
     msg_Destroy( p_libvlc );
 
     /* Destroy mutexes */
-    vlc_mutex_destroy( &p_libvlc->config_lock );
-    vlc_mutex_destroy( &p_libvlc->timer_lock );
+    vlc_mutex_destroy( &priv->config_lock );
+    vlc_mutex_destroy( &priv->timer_lock );
 
     if( b_release ) vlc_object_release( p_libvlc );
     vlc_object_release( p_libvlc );
@@ -1102,7 +1098,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release )
     /* Stop thread system: last one out please shut the door!
      * The number of initializations of the thread system is counted, we
      * can call this each time */
-    vlc_threads_end( p_libvlc_global );
+    vlc_threads_end ();
 
     return VLC_SUCCESS;
 }
@@ -1130,7 +1126,7 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc,
     }
 
 #ifndef WIN32
-    if( p_libvlc_global->b_daemon && b_block && !psz_module )
+    if( b_daemon && b_block && !psz_module )
     {
         /* Daemon mode hack.
          * We prefer the dummy interface if none is specified. */
@@ -1222,7 +1218,7 @@ static inline int LoadMessages (void)
 #else
     char psz_path[1024];
     if (snprintf (psz_path, sizeof (psz_path), "%s/%s",
-                  p_libvlc_global->psz_vlcpath, "locale")
+                  vlc_global()->psz_vlcpath, "locale")
                      >= (int)sizeof (psz_path))
         return -1;