[vlc-devel] [RFC] Fix input variables

Pierre Ynard linkfanel at yahoo.fr
Tue Nov 23 18:52:06 CET 2010


This makes the input resources create a VLC object and copy each input's
variables to it. With hindsight, this is pretty similar to what fenrir
told me not to do, but... this issue is hindering development, so it
needs to be fixed.


diff --git a/include/vlc_variables.h b/include/vlc_variables.h
index e0f5f88..a4e94a8 100644
--- a/include/vlc_variables.h
+++ b/include/vlc_variables.h
@@ -159,6 +159,9 @@ VLC_EXPORT( int, var_Command, ( vlc_object_t *, const char *, const char *, cons
 
 VLC_EXPORT( void, var_FreeList, ( vlc_value_t *, vlc_value_t * ) );
 
+VLC_EXPORT( void, var_Copy, ( vlc_object_t *, vlc_object_t * ) );
+#define var_Copy(o, n) var_Copy(VLC_OBJECT(o), VLC_OBJECT(n))
+
 
 /*****************************************************************************
  * Variable callbacks
diff --git a/src/input/input.c b/src/input/input.c
index 8a0e070..100fcb7 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -210,6 +210,10 @@ int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
  */
 int input_Start( input_thread_t *p_input )
 {
+    /* We need this to copy variables that were set after creating the
+     * input object. */
+    input_resource_SetInput( p_input->p->p_resource, p_input );
+
     /* Create thread and wait for its readiness. */
     if( vlc_thread_create( p_input, "input", Run,
                            VLC_THREAD_PRIORITY_INPUT ) )
diff --git a/src/input/resource.c b/src/input/resource.c
index f683e61..5025cc9 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -399,6 +399,7 @@ static void Destructor( gc_object_t *p_gc )
 
     vlc_mutex_destroy( &p_resource->lock_hold );
     vlc_mutex_destroy( &p_resource->lock );
+    vlc_object_release( p_resource->p_parent );
     free( p_resource );
 }
 
@@ -410,7 +411,8 @@ input_resource_t *input_resource_New( vlc_object_t *p_parent )
         return NULL;
 
     vlc_gc_init( p_resource, Destructor );
-    p_resource->p_parent = p_parent;
+    p_resource->p_parent = vlc_object_create( p_parent, sizeof (vlc_object_t) );
+    vlc_object_attach( p_resource->p_parent, p_parent->p_libvlc );
     vlc_mutex_init( &p_resource->lock );
     vlc_mutex_init( &p_resource->lock_hold );
     return p_resource;
@@ -435,6 +437,8 @@ void input_resource_SetInput( input_resource_t *p_resource, input_thread_t *p_in
         assert( p_resource->i_vout == 0 );
 
     /* */
+    if (p_input != NULL)
+        var_Copy( p_resource->p_parent, p_input );
     p_resource->p_input = p_input;
 
     vlc_mutex_unlock( &p_resource->lock );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index aec8a36..c24e0e8 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -472,6 +472,7 @@ utf8_vfprintf
 var_AddCallback
 var_Change
 var_Command
+var_Copy
 var_Create
 var_DelCallback
 var_Destroy
diff --git a/src/misc/variables.c b/src/misc/variables.c
index c91cb41..795d861 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -1403,3 +1403,41 @@ void var_FreeList( vlc_value_t *p_val, vlc_value_t *p_val2 )
         free( p_val2->p_list );
     }
 }
+
+static struct
+{
+    vlc_object_t *p_dst;
+    vlc_mutex_t lock;
+} walk = { NULL, VLC_STATIC_MUTEX };
+
+static void CopyVar( const void *nodep, const VISIT which, const int depth )
+{
+    (void) depth;
+
+    if (which != postorder && which != leaf)
+        return;
+
+    const variable_t *p_var = *((variable_t **) nodep);
+
+    if (p_var->i_type == VLC_VAR_VOID)
+        return;
+
+    var_Create(walk.p_dst, p_var->psz_name, p_var->i_type);
+    var_Set(walk.p_dst, p_var->psz_name, p_var->val);
+}
+
+#undef var_Copy
+void var_Copy( vlc_object_t *p_dst, vlc_object_t *p_src )
+{
+    vlc_object_internals_t *p_priv = vlc_internals(p_src);
+
+    vlc_mutex_lock(&p_priv->var_lock);
+    vlc_mutex_lock(&walk.lock);
+
+    walk.p_dst = p_dst;
+    twalk(p_priv->var_root, CopyVar);
+
+    vlc_mutex_unlock(&walk.lock);
+    vlc_mutex_unlock(&p_priv->var_lock);
+}
+


Regards,

-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."



More information about the vlc-devel mailing list