[vlc-commits] commit: Added a ref count on input_resource_t. (Laurent Aimar )

git at videolan.org git at videolan.org
Thu Jun 17 23:57:17 CEST 2010


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Thu Jun 17 23:55:22 2010 +0200| [a8f019f23091a4b65790f74a39939b0c0749686f] | committer: Laurent Aimar 

Added a ref count on input_resource_t.

It should fix invalid accesses of input_resource_t using input_GetVout/Aout.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a8f019f23091a4b65790f74a39939b0c0749686f
---

 include/vlc_input.h        |    9 +++++++--
 src/control/media_player.c |    3 ++-
 src/input/input.c          |    8 +++++---
 src/input/resource.c       |   29 ++++++++++++++++++++++-------
 src/input/resource.h       |    5 +++++
 src/input/vlm.c            |    5 ++++-
 src/libvlccore.sym         |    3 ++-
 src/playlist/thread.c      |    5 ++++-
 8 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/include/vlc_input.h b/include/vlc_input.h
index 930f3eb..da57548 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -663,13 +663,18 @@ VLC_EXPORT( char *, input_CreateFilename, ( vlc_object_t *, const char *psz_path
 VLC_EXPORT( input_resource_t *, input_resource_New, ( vlc_object_t * ) );
 
 /**
- * It deletes an input resource.
+ * It releases an input resource.
  */
-VLC_EXPORT(void, input_resource_Delete, ( input_resource_t * ) );
+VLC_EXPORT(void, input_resource_Release, ( input_resource_t * ) );
 
 /**
  * Forcefully destroys the video output (e.g. when the playlist is stopped).
  */
 VLC_EXPORT(void, input_resource_TerminateVout, ( input_resource_t * ) );
 
+/**
+ * This function releases all resources (object).
+ */
+VLC_EXPORT( void, input_resource_Terminate, ( input_resource_t * ) );
+
 #endif
diff --git a/src/control/media_player.c b/src/control/media_player.c
index 6d8b540..5b33293 100644
--- a/src/control/media_player.c
+++ b/src/control/media_player.c
@@ -506,7 +506,8 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
         release_input_thread(p_mi, true);
     if( p_mi->input.p_resource )
     {
-        input_resource_Delete( p_mi->input.p_resource );
+        input_resource_Terminate( p_mi->input.p_resource );
+        input_resource_Release( p_mi->input.p_resource );
         p_mi->input.p_resource = NULL;
     }
     vlc_mutex_destroy( &p_mi->input.lock );
diff --git a/src/input/input.c b/src/input/input.c
index 9f3b7bb..f66c063 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -386,12 +386,12 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     if( p_resource )
     {
         p_input->p->p_resource_private = NULL;
-        p_input->p->p_resource = p_resource;
+        p_input->p->p_resource = input_resource_Hold( p_resource );
     }
     else
     {
         p_input->p->p_resource_private = input_resource_New( VLC_OBJECT( p_input ) );
-        p_input->p->p_resource = p_input->p->p_resource_private;
+        p_input->p->p_resource = input_resource_Hold( p_input->p->p_resource_private );
     }
     input_resource_SetInput( p_input->p->p_resource, p_input );
 
@@ -500,8 +500,10 @@ static void Destructor( input_thread_t * p_input )
     if( p_input->p->p_es_out_display )
         es_out_Delete( p_input->p->p_es_out_display );
 
+    if( p_input->p->p_resource )
+        input_resource_Release( p_input->p->p_resource );
     if( p_input->p->p_resource_private )
-        input_resource_Delete( p_input->p->p_resource_private );
+        input_resource_Release( p_input->p->p_resource_private );
 
     vlc_gc_decref( p_input->p->p_item );
 
diff --git a/src/input/resource.c b/src/input/resource.c
index 677b50e..f683e61 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -44,6 +44,8 @@
 
 struct input_resource_t
 {
+    VLC_GC_MEMBERS
+
     vlc_object_t   *p_parent;
 
     /* This lock is used to serialize request and protect
@@ -387,6 +389,18 @@ static void TerminateAout( input_resource_t *p_resource )
         vlc_object_release( p_aout );
 }
 
+static void Destructor( gc_object_t *p_gc )
+{
+    input_resource_t *p_resource = vlc_priv( p_gc, input_resource_t );
+
+    DestroySout( p_resource );
+    DestroyVout( p_resource );
+    DestroyAout( p_resource );
+
+    vlc_mutex_destroy( &p_resource->lock_hold );
+    vlc_mutex_destroy( &p_resource->lock );
+    free( p_resource );
+}
 
 /* */
 input_resource_t *input_resource_New( vlc_object_t *p_parent )
@@ -395,21 +409,22 @@ input_resource_t *input_resource_New( vlc_object_t *p_parent )
     if( !p_resource )
         return NULL;
 
+    vlc_gc_init( p_resource, Destructor );
     p_resource->p_parent = p_parent;
     vlc_mutex_init( &p_resource->lock );
     vlc_mutex_init( &p_resource->lock_hold );
     return p_resource;
 }
 
-void input_resource_Delete( input_resource_t *p_resource )
+void input_resource_Release( input_resource_t *p_resource )
 {
-    DestroySout( p_resource );
-    DestroyVout( p_resource );
-    DestroyAout( p_resource );
+    vlc_gc_decref( p_resource );
+}
 
-    vlc_mutex_destroy( &p_resource->lock_hold );
-    vlc_mutex_destroy( &p_resource->lock );
-    free( p_resource );
+input_resource_t *input_resource_Hold( input_resource_t *p_resource )
+{
+    vlc_gc_incref( p_resource );
+    return p_resource;
 }
 
 void input_resource_SetInput( input_resource_t *p_resource, input_thread_t *p_input )
diff --git a/src/input/resource.h b/src/input/resource.h
index d8b45f2..713fe8e 100644
--- a/src/input/resource.h
+++ b/src/input/resource.h
@@ -76,5 +76,10 @@ void input_resource_HoldVouts( input_resource_t *, vout_thread_t ***, size_t * )
  */
 void input_resource_Terminate( input_resource_t * );
 
+/**
+ * This function holds the input_resource_t itself
+ */
+input_resource_t *input_resource_Hold( input_resource_t * );
+
 #endif
 
diff --git a/src/input/vlm.c b/src/input/vlm.c
index c117d52..772ce7c 100644
--- a/src/input/vlm.c
+++ b/src/input/vlm.c
@@ -867,7 +867,10 @@ static void vlm_MediaInstanceDelete( vlm_t *p_vlm, int64_t id, vlm_media_instanc
         vlm_SendEventMediaInstanceStopped( p_vlm, id, p_media->cfg.psz_name );
     }
     if( p_instance->p_input_resource )
-        input_resource_Delete( p_instance->p_input_resource );
+    {
+        input_resource_Terminate( p_instance->p_input_resource );
+        input_resource_Release( p_instance->p_input_resource );
+    }
 
     TAB_REMOVE( p_media->i_instance, p_media->instance, p_instance );
     vlc_gc_decref( p_instance->p_item );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index eca2690..4994225 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -219,8 +219,9 @@ input_item_SetURI
 input_item_WriteMeta
 input_Read
 input_resource_New
-input_resource_Delete
+input_resource_Release
 input_resource_TerminateVout
+input_resource_Terminate
 input_SplitMRL
 input_Start
 input_Stop
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 0ed215e..1940996 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -84,7 +84,10 @@ void playlist_Deactivate( playlist_t *p_playlist )
 
     /* release input resources */
     if( p_sys->p_input_resource )
-        input_resource_Delete( p_sys->p_input_resource );
+    {
+        input_resource_Terminate( p_sys->p_input_resource );
+        input_resource_Release( p_sys->p_input_resource );
+    }
     p_sys->p_input_resource = NULL;
 
     if( var_InheritBool( p_playlist, "media-library" ) )



More information about the vlc-commits mailing list