]> git.sesse.net Git - vlc/blobdiff - src/misc/objects.c
Fixed system clock phase when changing rate.
[vlc] / src / misc / objects.c
index f89133e22194f6c21bc5b4048c45fad114073abc..4e66695f4d6f4c0ec29f565bf3326bbe960599d6 100644 (file)
@@ -88,8 +88,6 @@ static void vlc_object_dump( vlc_object_t *p_this );
 /*****************************************************************************
  * Local structure lock
  *****************************************************************************/
-static vlc_mutex_t structure_lock;
-
 static void close_nocancel (int fd)
 {
     int canc = vlc_savecancel ();
@@ -97,6 +95,16 @@ static void close_nocancel (int fd)
     vlc_restorecancel (canc);
 }
 
+static void libvlc_lock (libvlc_int_t *p_libvlc)
+{
+    vlc_mutex_lock (&(libvlc_priv (p_libvlc)->structure_lock));
+}
+
+static void libvlc_unlock (libvlc_int_t *p_libvlc)
+{
+    vlc_mutex_unlock (&(libvlc_priv (p_libvlc)->structure_lock));
+}
+
 void *__vlc_custom_create( vlc_object_t *p_this, size_t i_size,
                            int i_type, const char *psz_type )
 {
@@ -143,14 +151,9 @@ void *__vlc_custom_create( vlc_object_t *p_this, size_t i_size,
 
     if( p_this == NULL )
     {
-        if( i_type == VLC_OBJECT_LIBVLC )
-            p_new->p_libvlc = (libvlc_int_t*)p_new;
-        else
-        {
-            p_new->p_libvlc = NULL;
-            vlc_mutex_init( &structure_lock );
-        }
-
+        libvlc_int_t *self = (libvlc_int_t*)p_new;
+        p_new->p_libvlc = self;
+        vlc_mutex_init (&(libvlc_priv (self)->structure_lock));
         p_this = p_priv->next = p_priv->prev = p_new;
     }
     else
@@ -174,14 +177,14 @@ void *__vlc_custom_create( vlc_object_t *p_this, size_t i_size,
     p_priv->pipes[0] = p_priv->pipes[1] = -1;
 
     p_priv->next = p_this;
-    vlc_mutex_lock( &structure_lock );
+    libvlc_lock (p_new->p_libvlc);
     p_priv->prev = vlc_internals (p_this)->prev;
     vlc_internals (p_this)->prev = p_new;
     vlc_internals (p_priv->prev)->next = p_new;
-    vlc_mutex_unlock( &structure_lock );
+    libvlc_unlock (p_new->p_libvlc);
 
-    if( i_type == VLC_OBJECT_LIBVLC )
-    {
+    if (p_new == VLC_OBJECT(p_new->p_libvlc))
+    {   /* TODO: should be in src/libvlc.c */
         int canc = vlc_savecancel ();
         var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
         var_AddCallback( p_new, "list", DumpCommand, NULL );
@@ -231,10 +234,6 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
             i_size = sizeof(aout_instance_t);
             psz_type = "audio output";
             break;
-        case VLC_OBJECT_OPENGL:
-            i_size = sizeof( vout_thread_t );
-            psz_type = "opengl";
-            break;
         default:
             assert( i_type > 0 ); /* unknown type?! */
             i_size = i_type;
@@ -301,10 +300,6 @@ static void vlc_object_destroy( vlc_object_t *p_this )
 
     free( p_this->psz_header );
 
-    if( p_this->p_libvlc == NULL )
-        /* We are the global object ... no need to lock. */
-        vlc_mutex_destroy( &structure_lock );
-
     FREENULL( p_this->psz_object_name );
 
     vlc_spin_destroy( &p_priv->ref_spin );
@@ -315,6 +310,8 @@ static void vlc_object_destroy( vlc_object_t *p_this )
         close( p_priv->pipes[1] );
     if( p_priv->pipes[0] != -1 )
         close( p_priv->pipes[0] );
+    if( VLC_OBJECT(p_this->p_libvlc) == p_this )
+        vlc_mutex_destroy (&(libvlc_priv ((libvlc_int_t *)p_this)->structure_lock));
 
     free( p_priv );
 }
@@ -398,7 +395,7 @@ error:
  * @param obj object that would be "killed"
  * @return a readable pipe descriptor, or -1 on error.
  */
-int __vlc_object_waitpipe( vlc_object_t *obj )
+int vlc_object_waitpipe( vlc_object_t *obj )
 {
     int pfd[2] = { -1, -1 };
     vlc_object_internals_t *internals = vlc_internals( obj );
@@ -525,7 +522,7 @@ void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
     /* If we are of the requested type ourselves, don't look further */
     if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
     {
-        vlc_object_yield( p_this );
+        vlc_object_hold( p_this );
         return p_this;
     }
 
@@ -535,15 +532,15 @@ void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
 #ifndef NDEBUG
         if (i_type == VLC_OBJECT_PLAYLIST)
            msg_Err (p_this, "using vlc_object_find(VLC_OBJECT_PLAYLIST) "
-                     "instead of pl_Yield()");
+                     "instead of pl_Hold()");
 #endif
         return vlc_object_find (p_this->p_libvlc, i_type,
                                 (i_mode & ~0x000f)|FIND_CHILD);
     }
 
-    vlc_mutex_lock( &structure_lock );
+    libvlc_lock (p_this->p_libvlc);
     p_found = FindObject( p_this, i_type, i_mode );
-    vlc_mutex_unlock( &structure_lock );
+    libvlc_unlock (p_this->p_libvlc);
     return p_found;
 }
 
@@ -574,11 +571,11 @@ vlc_object_t *vlc_object_find_name( vlc_object_t *p_this,
         && p_this->psz_object_name
         && !strcmp( p_this->psz_object_name, psz_name ) )
     {
-        vlc_object_yield( p_this );
+        vlc_object_hold( p_this );
         return p_this;
     }
 
-    vlc_mutex_lock( &structure_lock );
+    libvlc_lock (p_this->p_libvlc);
 
     /* Otherwise, recursively look for the object */
     if( (i_mode & 0x000f) == FIND_ANYWHERE )
@@ -605,15 +602,14 @@ vlc_object_t *vlc_object_find_name( vlc_object_t *p_this,
         p_found = FindObjectName( p_this, psz_name, i_mode );
     }
 
-    vlc_mutex_unlock( &structure_lock );
-
+    libvlc_unlock (p_this->p_libvlc);
     return p_found;
 }
 
 /**
  * Increment an object reference counter.
  */
-void * __vlc_object_yield( vlc_object_t *p_this )
+void * __vlc_object_hold( vlc_object_t *p_this )
 {
     vlc_object_internals_t *internals = vlc_internals( p_this );
 
@@ -651,8 +647,8 @@ void __vlc_object_release( vlc_object_t *p_this )
 
     /* Slow path */
     /* Remember that we cannot hold the spin while waiting on the mutex */
-    vlc_mutex_lock( &structure_lock );
-    /* Take the spin again. Note that another thread may have yielded the
+    libvlc_lock (p_this->p_libvlc);
+    /* Take the spin again. Note that another thread may have held the
      * object in the (very short) mean time. */
     vlc_spin_lock( &internals->ref_spin );
     b_should_destroy = --internals->i_refcount == 0;
@@ -696,7 +692,7 @@ void __vlc_object_release( vlc_object_t *p_this )
             /* Detach from parent to protect against FIND_CHILDREN */
             vlc_object_detach_unlocked (p_this);
     }
-    vlc_mutex_unlock( &structure_lock );
+    libvlc_unlock (p_this->p_libvlc);
 
     if( b_should_destroy )
     {
@@ -721,8 +717,8 @@ void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
 {
     if( !p_this ) return;
 
-    vlc_object_yield (p_parent);
-    vlc_mutex_lock( &structure_lock );
+    vlc_object_hold (p_parent);
+    libvlc_lock (p_this->p_libvlc);
 
     /* Attach the parent to its child */
     assert (!p_this->p_parent);
@@ -732,15 +728,12 @@ void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
     vlc_object_internals_t *priv = vlc_internals( p_parent );
     INSERT_ELEM( priv->pp_children, priv->i_children, priv->i_children,
                  p_this );
-
-    vlc_mutex_unlock( &structure_lock );
+    libvlc_unlock (p_this->p_libvlc);
 }
 
 
 static void vlc_object_detach_unlocked (vlc_object_t *p_this)
 {
-    vlc_assert_locked (&structure_lock);
-
     if (p_this->p_parent == NULL)
         return;
 
@@ -790,11 +783,11 @@ void __vlc_object_detach( vlc_object_t *p_this )
     vlc_object_t *p_parent;
     if( !p_this ) return;
 
-    vlc_mutex_lock( &structure_lock );
+    libvlc_lock (p_this->p_libvlc);
     p_parent = p_this->p_parent;
     if (p_parent)
         vlc_object_detach_unlocked( p_this );
-    vlc_mutex_unlock( &structure_lock );
+    libvlc_unlock (p_this->p_libvlc);
 
     if (p_parent)
         vlc_object_release (p_parent);
@@ -817,31 +810,24 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
     switch( i_mode & 0x000f )
     {
     case FIND_ANYWHERE:
-        /* Modules should probably not be object, and the module should perhaps
-         * not be shared across LibVLC instances. In the mean time, this ugly
-         * hack is brought to you by Courmisch. */
-        if (i_type == VLC_OBJECT_MODULE)
-            return vlc_list_find ((vlc_object_t *)p_module_bank,
-                                  i_type, FIND_CHILD);
         return vlc_list_find (p_this->p_libvlc, i_type, FIND_CHILD);
 
     case FIND_CHILD:
-        vlc_mutex_lock( &structure_lock );
+        libvlc_lock (p_this->p_libvlc);
         i_count = CountChildren( p_this, i_type );
         p_list = NewList( i_count );
 
         /* Check allocation was successful */
         if( p_list->i_count != i_count )
         {
-            vlc_mutex_unlock( &structure_lock );
-            msg_Err( p_this, "list allocation failed!" );
+            libvlc_unlock (p_this->p_libvlc);
             p_list->i_count = 0;
             break;
         }
 
         p_list->i_count = 0;
         ListChildren( p_list, p_this, i_type );
-        vlc_mutex_unlock( &structure_lock );
+        libvlc_unlock (p_this->p_libvlc);
         break;
 
     default:
@@ -863,14 +849,14 @@ vlc_list_t *__vlc_list_children( vlc_object_t *obj )
     vlc_list_t *l;
     vlc_object_internals_t *priv = vlc_internals( obj );
 
-    vlc_mutex_lock( &structure_lock );
+    libvlc_lock (obj->p_libvlc);
     l = NewList( priv->i_children );
     for (int i = 0; i < l->i_count; i++)
     {
-        vlc_object_yield( priv->pp_children[i] );
+        vlc_object_hold( priv->pp_children[i] );
         l->p_values[i].p_object = priv->pp_children[i];
     }
-    vlc_mutex_unlock( &structure_lock );
+    libvlc_unlock (obj->p_libvlc);
     return l;
 }
 
@@ -891,14 +877,14 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
     {
         vlc_object_t *cur = VLC_OBJECT (p_libvlc);
 
-        vlc_mutex_lock( &structure_lock );
+        libvlc_lock (p_this->p_libvlc);
         do
         {
             PrintObject (cur, "");
             cur = vlc_internals (cur)->next;
         }
         while (cur != VLC_OBJECT(p_libvlc));
-        vlc_mutex_unlock( &structure_lock );
+        libvlc_unlock (p_this->p_libvlc);
     }
     else
     {
@@ -906,8 +892,6 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
 
         if( *newval.psz_string )
         {
-            char *end;
-            int i_id = strtol( newval.psz_string, &end, 0 );
             /* try using the object's name to find it */
             p_object = vlc_object_find_name( p_this, newval.psz_string,
                                              FIND_ANYWHERE );
@@ -917,8 +901,7 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
             }
         }
 
-        vlc_mutex_lock( &structure_lock );
-
+        libvlc_lock (p_this->p_libvlc);
         if( *psz_cmd == 't' )
         {
             char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
@@ -1009,8 +992,7 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
                 printf( "\n" );
             }
         }
-
-        vlc_mutex_unlock( &structure_lock );
+        libvlc_unlock (p_this->p_libvlc);
 
         if( *newval.psz_string )
         {
@@ -1048,7 +1030,6 @@ static void vlc_object_dump( vlc_object_t *p_this )
     char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
     psz_foo[0] = '|';
 
-    vlc_assert_locked( &structure_lock );
     DumpStructure( p_this, 0, psz_foo );
 }
 
@@ -1067,7 +1048,7 @@ static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
         {
             if( p_tmp->i_object_type == i_type )
             {
-                vlc_object_yield( p_tmp );
+                vlc_object_hold( p_tmp );
                 return p_tmp;
             }
             else
@@ -1083,7 +1064,7 @@ static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
             p_tmp = vlc_internals( p_this )->pp_children[i];
             if( p_tmp->i_object_type == i_type )
             {
-                vlc_object_yield( p_tmp );
+                vlc_object_hold( p_tmp );
                 return p_tmp;
             }
             else if( vlc_internals( p_tmp )->i_children )
@@ -1121,7 +1102,7 @@ static vlc_object_t * FindObjectName( vlc_object_t *p_this,
             if( p_tmp->psz_object_name
                 && !strcmp( p_tmp->psz_object_name, psz_name ) )
             {
-                vlc_object_yield( p_tmp );
+                vlc_object_hold( p_tmp );
                 return p_tmp;
             }
             else
@@ -1138,7 +1119,7 @@ static vlc_object_t * FindObjectName( vlc_object_t *p_this,
             if( p_tmp->psz_object_name
                 && !strcmp( p_tmp->psz_object_name, psz_name ) )
             {
-                vlc_object_yield( p_tmp );
+                vlc_object_hold( p_tmp );
                 return p_tmp;
             }
             else if( vlc_internals( p_tmp )->i_children )
@@ -1289,7 +1270,7 @@ static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
         return;
     }
 
-    vlc_object_yield( p_object );
+    vlc_object_hold( p_object );
 
     p_list->p_values[i_index].p_object = p_object;
 
@@ -1311,7 +1292,7 @@ static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
         return;
     }
 
-    vlc_object_yield( p_object );
+    vlc_object_hold( p_object );
 
     p_list->p_values[p_list->i_count].p_object = p_object;
     p_list->i_count++;