]> git.sesse.net Git - vlc/blobdiff - src/libvlc-common.c
Remove pf_memcpy and pf_memset from libvlc
[vlc] / src / libvlc-common.c
index a3bb83b8d428cd7305562a0c2bc3da803664b2db..89a5cde7efbcfd7a7a109da8721a3bdf63183840 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,15 +146,15 @@ libvlc_int_t * vlc_current_object( int i_object )
  */
 libvlc_int_t * libvlc_InternalCreate( void )
 {
-    int i_ret;
     libvlc_int_t * p_libvlc = NULL;
     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" );
@@ -187,7 +182,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
     p_libvlc->p_playlist = NULL;
     p_libvlc->p_interaction = NULL;
     p_libvlc->p_vlm = NULL;
-    p_libvlc->psz_object_name = "libvlc";
+    p_libvlc->psz_object_name = strdup( "libvlc" );
 
     /* Initialize message queue */
     msg_Create( p_libvlc );
@@ -212,7 +207,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
     vlc_mutex_init( p_libvlc, &p_libvlc->timer_lock );
     vlc_mutex_init( p_libvlc, &p_libvlc->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,7 @@ 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();
     char         p_capabilities[200];
     char *       p_tmp = NULL;
     char *       psz_modules = NULL;
@@ -254,16 +249,18 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     /* Get the executable name (similar to the basename command) */
     if( i_argc > 0 )
     {
-        const char *exe = p_libvlc->psz_object_name = ppsz_argv[0];
+        const char *exe = strdup( ppsz_argv[0] );
+        const char *tmp = exe;
         while( *exe )
         {
             if( *exe++ == '/' )
-                p_libvlc->psz_object_name = exe;
+                tmp = exe;
         }
+        p_libvlc->psz_object_name = strdup( tmp );
     }
     else
     {
-        p_libvlc->psz_object_name = "vlc";
+        p_libvlc->psz_object_name = strdup( "vlc" );
     }
 
     /*
@@ -329,7 +326,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" );
@@ -376,7 +373,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
     }
@@ -712,16 +709,6 @@ 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;
@@ -776,6 +763,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 )
@@ -785,6 +773,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
@@ -942,7 +931,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;
 
     /* Ask the interfaces to stop and destroy them */
     msg_Dbg( p_libvlc, "removing all interfaces" );
@@ -977,11 +965,24 @@ 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 )
+    {
+        msg_Dbg( p_sout, "removing kept stream output" );
+        vlc_object_detach( (vlc_object_t*)p_sout );
+        vlc_object_release( (vlc_object_t*)p_sout );
+        sout_DeleteInstance( p_sout );
+    }
+
     /* Destroy VLM if created in libvlc_InternalInit */
     if( p_libvlc->p_vlm )
     {
         vlm_Delete( p_libvlc->p_vlm );
     }
+#endif
 
     /* Free interaction */
     msg_Dbg( p_libvlc, "removing interaction" );
@@ -990,6 +991,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 ) ) )
@@ -999,6 +1003,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 )
@@ -1090,7 +1095,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;
 }
@@ -1118,7 +1123,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. */