[vlc-devel] commit: libvlc: input access returns an exception when it' s being destroyed ( Rafaël Carré )

git version control git at videolan.org
Tue Aug 5 16:34:07 CEST 2008


vlc | branch: 0.8.6-bugfix | Rafaël Carré <rcarre at m2x.nl> | Tue Aug  5 16:30:26 2008 +0200| [771bab34089c01983bb1e5e7afee840656d84169] | committer: Rafaël Carré 

libvlc: input access returns an exception when it's being destroyed

var_{G,S}et() fails if a variable is not existant
If they fail, that means the input mandatory variables have been destroyed.

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

 src/control/input.c |   73 +++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 57 insertions(+), 16 deletions(-)

diff --git a/src/control/input.c b/src/control/input.c
index 670558d..52f015c 100644
--- a/src/control/input.c
+++ b/src/control/input.c
@@ -29,7 +29,7 @@
 
 void libvlc_input_free( libvlc_input_t *p_input )
 {
-    if( p_input ) free( p_input );
+    free( p_input );
 }
 
 /*
@@ -37,7 +37,7 @@ void libvlc_input_free( libvlc_input_t *p_input )
  * once you are done with it.
  */
 input_thread_t *libvlc_get_input_thread( libvlc_input_t *p_input,
-                                         libvlc_exception_t *p_e ) 
+                                         libvlc_exception_t *p_e )
 {
     input_thread_t *p_input_thread;
 
@@ -63,9 +63,15 @@ vlc_int64_t libvlc_input_get_length( libvlc_input_t *p_input,
     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
     if( libvlc_exception_raised( p_e ) )  return -1;
 
-    var_Get( p_input_thread, "length", &val );
+    int i_ret = var_Get( p_input_thread, "length", &val );
     vlc_object_release( p_input_thread );
 
+    if( i_ret != VLC_SUCCESS )
+    {
+        libvlc_exception_raise( p_e, "Input is destroyed" );
+        return -1;
+    }
+
     return (val.i_time+500LL)/1000LL;
 }
 
@@ -78,8 +84,15 @@ vlc_int64_t libvlc_input_get_time( libvlc_input_t *p_input,
     p_input_thread = libvlc_get_input_thread ( p_input, p_e );
     if( libvlc_exception_raised( p_e ) )  return -1;
 
-    var_Get( p_input_thread , "time", &val );
+    int i_ret = var_Get( p_input_thread , "time", &val );
     vlc_object_release( p_input_thread );
+
+    if( i_ret != VLC_SUCCESS )
+    {
+        libvlc_exception_raise( p_e, "Input is destroyed" );
+        return -1;
+    }
+
     return (val.i_time+500LL)/1000LL;
 }
 
@@ -93,12 +106,15 @@ void libvlc_input_set_time( libvlc_input_t *p_input, vlc_int64_t time,
     if( libvlc_exception_raised( p_e ) )  return;
 
     value.i_time = time*1000LL;
-    var_Set( p_input_thread, "time", value );
+    int i_ret = var_Set( p_input_thread, "time", value );
     vlc_object_release( p_input_thread );
+
+    if( i_ret != VLC_SUCCESS )
+        libvlc_exception_raise( p_e, "Input is destroyed" );
 }
 
 void libvlc_input_set_position( libvlc_input_t *p_input, float position,
-                                libvlc_exception_t *p_e ) 
+                                libvlc_exception_t *p_e )
 {
     input_thread_t *p_input_thread;
     vlc_value_t val;
@@ -107,8 +123,11 @@ void libvlc_input_set_position( libvlc_input_t *p_input, float position,
     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
     if ( libvlc_exception_raised( p_e ) ) return;
 
-    var_Set( p_input_thread, "position", val );
+    int i_ret = var_Set( p_input_thread, "position", val );
     vlc_object_release( p_input_thread );
+
+    if( i_ret != VLC_SUCCESS )
+        libvlc_exception_raise( p_e, "Input is destroyed" );
 }
 
 float libvlc_input_get_position( libvlc_input_t *p_input,
@@ -120,14 +139,20 @@ float libvlc_input_get_position( libvlc_input_t *p_input,
     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
     if ( libvlc_exception_raised( p_e ) )  return -1.0;
 
-    var_Get( p_input_thread, "position", &val );
+    int i_ret = var_Get( p_input_thread, "position", &val );
     vlc_object_release( p_input_thread );
 
+    if( i_ret != VLC_SUCCESS )
+    {
+        libvlc_exception_raise( p_e, "Input is destroyed" );
+        return 0.;
+    }
+
     return val.f_float;
 }
 
 float libvlc_input_get_fps( libvlc_input_t *p_input,
-                            libvlc_exception_t *p_e) 
+                            libvlc_exception_t *p_e)
 {
     double f_fps = 0.0;
     input_thread_t *p_input_thread;
@@ -138,7 +163,7 @@ float libvlc_input_get_fps( libvlc_input_t *p_input,
     if( p_input_thread->input.p_demux )
     {
         if( demux2_Control( p_input_thread->input.p_demux, DEMUX_GET_FPS, &f_fps )
-            || (f_fps < 0.1) ) 
+            || (f_fps < 0.1) )
         {
             vlc_object_release( p_input_thread );
             return 0.0;
@@ -149,13 +174,13 @@ float libvlc_input_get_fps( libvlc_input_t *p_input,
 }
 
 vlc_bool_t libvlc_input_will_play( libvlc_input_t *p_input,
-                                   libvlc_exception_t *p_e) 
+                                   libvlc_exception_t *p_e)
 {
     input_thread_t *p_input_thread =
                             libvlc_get_input_thread ( p_input, p_e);
     if ( libvlc_exception_raised( p_e ) ) return VLC_FALSE;
 
-    if ( !p_input_thread->b_die && !p_input_thread->b_dead ) 
+    if ( !p_input_thread->b_die && !p_input_thread->b_dead )
     {
         vlc_object_release( p_input_thread );
         return VLC_TRUE;
@@ -165,7 +190,7 @@ vlc_bool_t libvlc_input_will_play( libvlc_input_t *p_input,
 }
 
 void libvlc_input_set_rate( libvlc_input_t *p_input, float rate,
-                                libvlc_exception_t *p_e ) 
+                                libvlc_exception_t *p_e )
 {
     input_thread_t *p_input_thread;
     vlc_value_t val;
@@ -178,8 +203,11 @@ void libvlc_input_set_rate( libvlc_input_t *p_input, float rate,
     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
     if ( libvlc_exception_raised( p_e ) ) return;
 
-    var_Set( p_input_thread, "rate", val );
+    int i_ret = var_Set( p_input_thread, "rate", val );
     vlc_object_release( p_input_thread );
+
+    if( i_ret != VLC_SUCCESS )
+        libvlc_exception_raise( p_e, "Input is destroyed" );
 }
 
 float libvlc_input_get_rate( libvlc_input_t *p_input,
@@ -191,9 +219,15 @@ float libvlc_input_get_rate( libvlc_input_t *p_input,
     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
     if ( libvlc_exception_raised( p_e ) )  return -1.0;
 
-    var_Get( p_input_thread, "rate", &val );
+    int i_ret = var_Get( p_input_thread, "rate", &val );
     vlc_object_release( p_input_thread );
 
+    if( i_ret != VLC_SUCCESS )
+    {
+        libvlc_exception_raise( p_e, "Input is destroyed" );
+        return 0.;
+    }
+
     return (float)1000.0f/val.i_int;
 }
 
@@ -207,8 +241,15 @@ int libvlc_input_get_state( libvlc_input_t *p_input,
     if ( libvlc_exception_raised( p_e ) )
         return 0;
 
-    var_Get( p_input_thread, "state", &val );
+    int i_ret = var_Get( p_input_thread, "state", &val );
+
     vlc_object_release( p_input_thread );
 
+    if( i_ret != VLC_SUCCESS )
+    {
+        libvlc_exception_raise( p_e, "Input is destroyed" );
+        return 0;
+    }
+
     return val.i_int;
 }




More information about the vlc-devel mailing list