[vlc-devel] commit: media_instance: Don' t rely on vlc_object_find now that input refcounting is fixed. (Pierre d' Herbemont )

git version control git at videolan.org
Wed Mar 19 02:32:21 CET 2008


vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Wed Mar 19 02:32:28 2008 +0100| [c365acef1712b09f8c07a10e8014f135081df441]

media_instance: Don't rely on vlc_object_find now that input refcounting is fixed.

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

 src/control/libvlc_internal.h |    3 +-
 src/control/media_instance.c  |   57 ++++++++++++++++-------------------------
 src/control/video.c           |    5 +--
 3 files changed, 25 insertions(+), 40 deletions(-)

diff --git a/src/control/libvlc_internal.h b/src/control/libvlc_internal.h
index eaf1b0e..891aee1 100644
--- a/src/control/libvlc_internal.h
+++ b/src/control/libvlc_internal.h
@@ -183,8 +183,7 @@ struct libvlc_media_instance_t
 {
     int                i_refcount;
     vlc_mutex_t        object_lock;
-    int i_input_id;  /* Input object id. We don't use a pointer to
-                        avoid any crash */
+    input_thread_t *   p_input_thread;
     struct libvlc_instance_t *  p_libvlc_instance; /* Parent instance */
     libvlc_media_descriptor_t * p_md; /* current media descriptor */
     libvlc_event_manager_t *    p_event_manager;
diff --git a/src/control/media_instance.c b/src/control/media_instance.c
index 3150c6c..110d29e 100644
--- a/src/control/media_instance.c
+++ b/src/control/media_instance.c
@@ -74,18 +74,12 @@ static inline libvlc_state_t vlc_to_libvlc_state( int vlc_state )
  */
 static void release_input_thread( libvlc_media_instance_t *p_mi )
 {
-    input_thread_t *p_input_thread;
+    input_thread_t * p_input_thread;
 
-    if( !p_mi || p_mi->i_input_id == -1 )
+    if( !p_mi || !p_mi->p_input_thread )
         return;
 
-    p_input_thread = (input_thread_t*)vlc_object_get( p_mi->i_input_id );
-
-    p_mi->i_input_id = -1;
-
-    if( !p_input_thread )
-        return;
- 
+    p_input_thread = p_mi->p_input_thread;
 
     /* No one is tracking this input_thread appart us. Destroy it */
     if( p_mi->b_own_its_input_thread )
@@ -101,13 +95,10 @@ static void release_input_thread( libvlc_media_instance_t *p_mi )
 
         var_Destroy( p_input_thread, "drawable" );
     }
-    else
-    {
-        vlc_object_release( p_input_thread );
-    }
 
-    /* release for previous vlc_object_get */
     vlc_object_release( p_input_thread );
+
+    p_mi->p_input_thread = NULL;
 }
 
 /*
@@ -121,27 +112,21 @@ input_thread_t *libvlc_get_input_thread( libvlc_media_instance_t *p_mi,
 {
     input_thread_t *p_input_thread;
 
-    if ( !p_mi )
-    {
-        RAISENULL( "Input is NULL" );
-    }
-
+    if( !p_mi ) RAISENULL( "Media Instance is NULL" );
+    
     vlc_mutex_lock( &p_mi->object_lock );
 
-    if( !p_mi || p_mi->i_input_id == -1 )
+    if( !p_mi->p_input_thread )
     {
         vlc_mutex_unlock( &p_mi->object_lock );
         RAISENULL( "Input is NULL" );
     }
 
-    p_input_thread = (input_thread_t*)vlc_object_get( p_mi->i_input_id );
-    if( !p_input_thread )
-    {
-        vlc_mutex_unlock( &p_mi->object_lock );
-        RAISENULL( "Input does not exist" );
-    }
+    p_input_thread = p_mi->p_input_thread;
+    vlc_object_yield( p_input_thread );
 
     vlc_mutex_unlock( &p_mi->object_lock );
+
     return p_input_thread;
 }
 
@@ -308,7 +293,7 @@ libvlc_media_instance_new( libvlc_instance_t * p_libvlc_instance,
     p_mi->p_md = NULL;
     p_mi->drawable = 0;
     p_mi->p_libvlc_instance = p_libvlc_instance;
-    p_mi->i_input_id = -1;
+    p_mi->p_input_thread = NULL;
     /* refcount strategy:
      * - All items created by _new start with a refcount set to 1
      * - Accessor _release decrease the refcount by 1, if after that
@@ -401,12 +386,12 @@ libvlc_media_instance_t * libvlc_media_instance_new_from_input_thread(
         return NULL;
     }
 
-    p_mi->i_input_id = p_input->i_object_id;
-    p_mi->b_own_its_input_thread = VLC_FALSE;
-
     /* will be released in media_instance_release() */
     vlc_object_yield( p_input );
 
+    p_mi->p_input_thread = p_input;
+    p_mi->b_own_its_input_thread = VLC_FALSE;
+
     return p_mi;
 }
 
@@ -580,17 +565,20 @@ void libvlc_media_instance_play( libvlc_media_instance_t *p_mi,
         return;
     }
 
-    p_mi->i_input_id = input_Read( p_mi->p_libvlc_instance->p_libvlc_int,
-                                   p_mi->p_md->p_input_item, VLC_FALSE );
+    int i_input_id = input_Read( p_mi->p_libvlc_instance->p_libvlc_int,
+                      p_mi->p_md->p_input_item, VLC_FALSE );
 
-    p_input_thread = (input_thread_t*)vlc_object_get( p_mi->i_input_id );
+    /* Released in input_release */
+    p_mi->p_input_thread = (input_thread_t*)vlc_object_get( i_input_id );
 
-    if( !p_input_thread )
+    if( !p_mi->p_input_thread )
     {
         return;
         vlc_mutex_unlock( &p_mi->object_lock );
     }
 
+    p_input_thread = p_mi->p_input_thread;
+
     if( p_mi->drawable )
     {
         vlc_value_t val;
@@ -604,7 +592,6 @@ void libvlc_media_instance_play( libvlc_media_instance_t *p_mi,
     var_AddCallback( p_input_thread, "intf-change", input_position_changed, p_mi );
     var_AddCallback( p_input_thread, "intf-change", input_time_changed, p_mi );
 
-    vlc_object_release( p_input_thread );
     vlc_mutex_unlock( &p_mi->object_lock );
 }
 
diff --git a/src/control/video.c b/src/control/video.c
index 4ebb4e6..d9e95cf 100644
--- a/src/control/video.c
+++ b/src/control/video.c
@@ -147,8 +147,8 @@ libvlc_video_take_snapshot( libvlc_media_instance_t *p_mi, char *psz_filepath,
     var_SetInteger( p_vout, "snapshot-width", i_width );
     var_SetInteger( p_vout, "snapshot-height", i_height );
 
-    p_input_thread = (input_thread_t*)vlc_object_get( p_mi->i_input_id );
-    if( !p_input_thread )
+    p_input_thread = p_mi->p_input_thread;
+    if( !p_mi->p_input_thread )
     {
         libvlc_exception_raise( p_e, "Input does not exist" );
         return;
@@ -159,7 +159,6 @@ libvlc_video_take_snapshot( libvlc_media_instance_t *p_mi, char *psz_filepath,
 
     vout_Control( p_vout, VOUT_SNAPSHOT );
     vlc_object_release( p_vout );
-    vlc_object_release( p_input_thread );
 }
 
 int libvlc_video_get_height( libvlc_media_instance_t *p_mi,




More information about the vlc-devel mailing list