]> git.sesse.net Git - vlc/commitdiff
src/control: a bit of cleanup here and there
authorClément Stenac <zorglub@videolan.org>
Tue, 1 Aug 2006 09:22:35 +0000 (09:22 +0000)
committerClément Stenac <zorglub@videolan.org>
Tue, 1 Aug 2006 09:22:35 +0000 (09:22 +0000)
include/libvlc_internal.h
include/vlc/libvlc.h
src/control/audio.c
src/control/core.c
src/control/input.c
src/control/playlist.c

index e3f3c4520094c416bfc75eb05d81d404cc160f3c..6cbc8184ce83b5bead917ab0dadc0a3bb58c1bb4 100644 (file)
@@ -50,6 +50,9 @@ struct libvlc_input_t
     struct libvlc_instance_t *p_instance; ///< Parent instance
 };
 
+#define RAISENULL( psz ) { libvlc_exception_raise( p_e, psz ); return NULL; }
+#define RAISEVOID( psz ) { libvlc_exception_raise( p_e, psz ); return; }
+#define RAISEZERO( psz ) { libvlc_exception_raise( p_e, psz ); return 0; }
 
 # ifdef __cplusplus
 }
index b0e0a312110d2041ec344703b08462956c630cee..28f73c17e3eff899853cfa6b6b6b3815bb144938 100644 (file)
@@ -114,8 +114,10 @@ typedef struct libvlc_instance_t libvlc_instance_t;
 libvlc_instance_t * libvlc_new( int , char **, libvlc_exception_t *);
 
 /**
- * returns a libvlc instance identifier for legacy APIs
- * \param p_instance the instance to destroy
+ * Returns a libvlc instance identifier for legacy APIs. Use of this
+ * function is discouraged, you should convert your program to use the
+ * new API.
+ * \param p_instance the instance
  */
 int libvlc_get_vlc_id( libvlc_instance_t *p_instance );
 
@@ -200,20 +202,6 @@ void libvlc_playlist_prev( libvlc_instance_t *, libvlc_exception_t * );
  */
 void libvlc_playlist_clear( libvlc_instance_t *, libvlc_exception_t * );
 
-/**
- * Go to next playlist item
- * \param p_instance the instance
- * \param p_exception an initialized exception
- */
-void libvlc_playlist_next( libvlc_instance_t *, libvlc_exception_t * );
-
-/**
- * Go to Previous playlist item
- * \param p_instance the instance
- * \param p_exception an initialized exception
- */
-void libvlc_playlist_prev( libvlc_instance_t *, libvlc_exception_t * );
-
 /**
  * Add an item at the end of the playlist
  * If you need more advanced options, \see libvlc_playlist_add_extended
@@ -232,13 +220,20 @@ int libvlc_playlist_add( libvlc_instance_t *, const char *, const char *,
  * \param psz_name a name that you might want to give or NULL
  * \param i_options the number of options to add
  * \param ppsz_options strings representing the options to add
+ * \param p_exception an initialized exception
  * \return the identifier of the new item
  */
 int libvlc_playlist_add_extended( libvlc_instance_t *, const char *,
                                   const char *, int, const char **,
                                   libvlc_exception_t * );
 
-
+/** 
+ * Delete the playlist item with the given ID.
+ * \param p_instance the instance
+ * \param i_id the id to remove
+ * \param p_exception an initialized exception
+ * \return
+ */
 int libvlc_playlist_delete_item( libvlc_instance_t *, int,
                                  libvlc_exception_t * );
     
@@ -252,8 +247,6 @@ typedef struct libvlc_input_t libvlc_input_t;
 libvlc_input_t *libvlc_playlist_get_input( libvlc_instance_t *,
                                            libvlc_exception_t * );
 
-
-
 /** @}*/
 
 /*****************************************************************************
@@ -277,8 +270,6 @@ void        libvlc_input_set_time       ( libvlc_input_t *, vlc_int64_t, libvlc_
 float       libvlc_input_get_position   ( libvlc_input_t *, libvlc_exception_t *);
 void        libvlc_input_set_position   ( libvlc_input_t *, float, libvlc_exception_t *);
 vlc_bool_t  libvlc_input_will_play      ( libvlc_input_t *, libvlc_exception_t *);
-vlc_bool_t  libvlc_input_has_vout       ( libvlc_input_t *, libvlc_exception_t *);
-float       libvlc_input_get_fps        ( libvlc_input_t *, libvlc_exception_t *);
         
 /** @} */
 
@@ -288,6 +279,14 @@ float       libvlc_input_get_fps        ( libvlc_input_t *, libvlc_exception_t *
  * @{
  */
 
+/**
+ * Does this input have a video output ?
+ * \param p_input the input
+ * \param p_exception an initialized exception
+ */
+vlc_bool_t  libvlc_input_has_vout       ( libvlc_input_t *, libvlc_exception_t *);
+float       libvlc_input_get_fps        ( libvlc_input_t *, libvlc_exception_t *);
+
 /**
  * Toggle fullscreen status on video output
  * \param p_input the input
@@ -474,8 +473,6 @@ void libvlc_vlm_set_output( libvlc_instance_t *, char *, char*,
 void libvlc_vlm_set_input( libvlc_instance_t *, char *, char*,
                            libvlc_exception_t *);
 
-
-
 /**
  * Set output for a media
  * \param p_instance the instance
index 1713ba686b52bb0531a7529820441e9e02365579..c28b70b448fde7e2dc9e1baad91dbbccd3bb7fc4 100644 (file)
  * libvlc_audio_get_mute : Get the volume state, true if muted
  *****************************************************************************/
 void libvlc_audio_toggle_mute( libvlc_instance_t *p_instance,
-                               libvlc_exception_t *p_exception )
+                               libvlc_exception_t *p_e )
 {
     aout_VolumeMute( p_instance->p_vlc, NULL );
 }
 
 vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance,
-                                  libvlc_exception_t *p_exception )
+                                  libvlc_exception_t *p_e )
 {
     /*
      * If the volume level is 0, then the channel is muted
      */
     audio_volume_t i_volume;
 
-    i_volume = libvlc_audio_get_volume(p_instance, p_exception);
+    i_volume = libvlc_audio_get_volume(p_instance, p_e);
     if ( i_volume == 0 )
         return VLC_TRUE;
-
     return VLC_FALSE;
 }
 
 void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t status,
-                            libvlc_exception_t *p_exception )
+                            libvlc_exception_t *p_e )
 {
     if ( status )
     {
-        /*
-         * Check if the volume is already muted
-         */
-        if (! libvlc_audio_get_volume( p_instance, p_exception ) )
+        /* Check if the volume is already muted */
+        if (! libvlc_audio_get_volume( p_instance, p_e ) )
         {
             return;
         }
-        
         aout_VolumeMute( p_instance->p_vlc, NULL );
-        return;
-        
     }
     else
     {
-        /*
-         * the aout_VolumeMute is a toggle function, so this is enough.
-         */
+        /* the aout_VolumeMute is a toggle function, so this is enough. */
         aout_VolumeMute( p_instance->p_vlc, NULL );
-        return;
     }
 }
 
-
 /*****************************************************************************
  * libvlc_audio_get_volume : Get the current volume (range 0-200 %)
  *****************************************************************************/
 int libvlc_audio_get_volume( libvlc_instance_t *p_instance,
-                             libvlc_exception_t *p_exception )
+                             libvlc_exception_t *p_e )
 {
     audio_volume_t i_volume;
 
@@ -97,7 +87,7 @@ int libvlc_audio_get_volume( libvlc_instance_t *p_instance,
  * libvlc_audio_set_volume : Set the current volume
  *****************************************************************************/
 void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
-                              libvlc_exception_t *p_exception )
+                              libvlc_exception_t *p_e )
 {
     if( i_volume >= 0 && i_volume <= 200 )
     {
@@ -106,7 +96,7 @@ void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
     }
     else
     {
-        libvlc_exception_raise( p_exception, "Volume out of range" );
+        libvlc_exception_raise( p_e, "Volume out of range" );
     }
 }
 
index 2934e09ee2c9f3d774b0e7b9884441f568cda3f6..e7d22653ced54cc873aba0160a91b8adfae67702 100644 (file)
@@ -63,14 +63,13 @@ inline void libvlc_exception_raise( libvlc_exception_t *p_exception,
     va_list args;
 
     /* does caller care about exceptions ? */
-    if( p_exception == NULL )
-       return;
+    if( p_exception == NULL ) return;
 
     /* remove previous exception if it wasn't cleared */
     if( p_exception->b_raised && p_exception->psz_message )
     {
-       free(p_exception->psz_message);
-       p_exception->psz_message = NULL;
+        free(p_exception->psz_message);
+        p_exception->psz_message = NULL;
     }
 
     va_start( args, psz_format );
@@ -81,7 +80,7 @@ inline void libvlc_exception_raise( libvlc_exception_t *p_exception,
 }
 
 libvlc_instance_t * libvlc_new( int argc, char **argv,
-                                libvlc_exception_t *p_exception )
+                                libvlc_exception_t *p_e )
 {
     int i_vlc_id;
     libvlc_instance_t *p_new;
@@ -90,21 +89,14 @@ libvlc_instance_t * libvlc_new( int argc, char **argv,
     i_vlc_id = VLC_Create();
     p_vlc = (vlc_t* ) vlc_current_object( i_vlc_id );
 
-    if( !p_vlc )
-    {
-        libvlc_exception_raise( p_exception, "VLC initialization failed" );
-        return NULL;
-    }
+    if( !p_vlc ) RAISENULL( "VLC initialization failed" );
+
     p_new = (libvlc_instance_t *)malloc( sizeof( libvlc_instance_t ) );
+    if( !p_new ) RAISENULL( "Out of memory" );
 
     /** \todo Look for interface settings. If we don't have any, add -I dummy */
     /* Because we probably don't want a GUI by default */
 
-    if( !p_new )
-    {
-        libvlc_exception_raise( p_exception, "Out of memory" );
-        return NULL;
-    }
 
     VLC_Init( i_vlc_id, argc, argv );
 
@@ -113,13 +105,9 @@ libvlc_instance_t * libvlc_new( int argc, char **argv,
                                 VLC_OBJECT_PLAYLIST, FIND_CHILD );
     p_new->p_vlm = NULL;
 
-    if( !p_new->p_playlist )
-    {
-        libvlc_exception_raise( p_exception, "Playlist creation failed" );
-        return NULL;
-    }
+    if( !p_new->p_playlist ) RAISENULL( "Playlist creation failed" );
+    
     p_new->i_vlc_id = i_vlc_id;
-
     return p_new;
 }
 
@@ -136,4 +124,3 @@ int libvlc_get_vlc_id( libvlc_instance_t *p_instance )
 {
     return p_instance->i_vlc_id;
 }
-
index bb48e8581e9c706caec662bfc13ef01da3ead07e..2b248a5506befecf4b48c6071a0a738df5b37a29 100644 (file)
@@ -29,8 +29,7 @@
 
 void libvlc_input_free( libvlc_input_t *p_input )
 {
-    if( p_input )
-        free( p_input );
+    if( p_input ) free( p_input );
 }
 
 /*
@@ -42,20 +41,12 @@ input_thread_t *libvlc_get_input_thread( libvlc_input_t *p_input,
 {
     input_thread_t *p_input_thread;
 
-    if( !p_input )
-    {
-        libvlc_exception_raise( p_e, "Input is NULL" );
-        return NULL;
-    }
+    if( !p_input ) RAISENULL( "Input is NULL" );
 
     p_input_thread = (input_thread_t*)vlc_object_get(
-                                 p_input->p_instance->p_vlc,
-                                 p_input->i_input_id );
-    if( !p_input_thread )
-    {
-        libvlc_exception_raise( p_e, "Input does not exist" );
-        return NULL;
-    }
+                                                    p_input->p_instance->p_vlc,
+                                                    p_input->i_input_id );
+    if( !p_input_thread ) RAISENULL( "Input does not exist" );
 
     return p_input_thread;
 }
@@ -66,15 +57,13 @@ input_thread_t *libvlc_get_input_thread( libvlc_input_t *p_input,
  * Getters for stream information
  **************************************************************************/
 vlc_int64_t libvlc_input_get_length( libvlc_input_t *p_input,
-                             libvlc_exception_t *p_exception )
+                             libvlc_exception_t *p_e )
 {
     input_thread_t *p_input_thread;
     vlc_value_t val;
 
-    p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
-
-    if ( libvlc_exception_raised( p_exception ) )
-        return -1.0;
+    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, "length", &val );
     vlc_object_release( p_input_thread );
@@ -83,72 +72,55 @@ vlc_int64_t libvlc_input_get_length( libvlc_input_t *p_input,
 }
 
 vlc_int64_t libvlc_input_get_time( libvlc_input_t *p_input,
-                           libvlc_exception_t *p_exception )
+                                   libvlc_exception_t *p_e )
 {
     input_thread_t *p_input_thread;
     vlc_value_t val;
 
-
-    p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
-
-    if ( libvlc_exception_raised( p_exception ) )
-        return -1.0;
+    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 , "time", &val );
     vlc_object_release( p_input_thread );
-
     return val.i_time / 1000;
 }
 
-void libvlc_input_set_time( libvlc_input_t *p_input, vlc_int64_t time, libvlc_exception_t *p_exception )
+void libvlc_input_set_time( libvlc_input_t *p_input, vlc_int64_t time,
+                            libvlc_exception_t *p_e )
 {
     input_thread_t *p_input_thread;
     vlc_value_t value;
 
-    p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
-
-    if ( libvlc_exception_raised( p_exception ) )
-        return;
+    p_input_thread = libvlc_get_input_thread ( p_input, p_e );
+    if( libvlc_exception_raised( p_e ) )  return;
     
     value.i_time = time;
     var_Set( p_input_thread, "time", value );
     vlc_object_release( p_input_thread );
-
-    return;
-    
 }
 
-void libvlc_input_set_position( libvlc_input_t *p_input, float position, libvlc_exception_t *p_exception ) 
+void libvlc_input_set_position( libvlc_input_t *p_input, float position,
+                                libvlc_exception_t *p_e ) 
 {
     input_thread_t *p_input_thread;
     vlc_value_t val;
-
     val.f_float = position;
     
-    p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
-
-    if ( libvlc_exception_raised( p_exception ) )
-        return;
+    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 );
     vlc_object_release( p_input_thread );
-
-    return;
-
 }
 
-
-
 float libvlc_input_get_position( libvlc_input_t *p_input,
-                                 libvlc_exception_t *p_exception )
+                                 libvlc_exception_t *p_e )
 {
     input_thread_t *p_input_thread;
     vlc_value_t val;
 
-    p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
-
-    if ( libvlc_exception_raised( p_exception ) )
-        return -1.0;
+    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 );
     vlc_object_release( p_input_thread );
@@ -157,17 +129,19 @@ float libvlc_input_get_position( libvlc_input_t *p_input,
 }
 
 float libvlc_input_get_fps( libvlc_input_t *p_input,
-                            libvlc_exception_t *p_exception
+                            libvlc_exception_t *p_e) 
 {
     double f_fps;
     input_thread_t *p_input_thread;
 
-    p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
+    p_input_thread = libvlc_get_input_thread ( p_input, p_e );
+    if ( libvlc_exception_raised( p_e ) )  return 0.0;
 
-    if( demux2_Control( p_input_thread->input.p_demux, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 ) 
+    if( demux2_Control( p_input_thread->input.p_demux, DEMUX_GET_FPS, &f_fps )
+        || f_fps < 0.1 ) 
     {
         vlc_object_release( p_input_thread );
-        return 0;
+        return 0.0;
     }
     else
     {
@@ -177,21 +151,17 @@ 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_exception
+                                   libvlc_exception_t *p_e) 
 {
-    input_thread_t *p_input_thread;
-
-    p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
-
-    if ( libvlc_exception_raised( p_exception ) )
-        return VLC_FALSE;
+    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 ) 
     {
         vlc_object_release( p_input_thread );
         return VLC_TRUE;
     }
-    
     vlc_object_release( p_input_thread );
     return VLC_FALSE;
 }
index 89d35c151dbd6601135bce61e5c5ca50b34abe83..fb3bc8b80ecee97437a819802392a91c60a151d5 100644 (file)
 
 void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
                            int i_options, char **ppsz_options,
-                           libvlc_exception_t *p_exception )
+                           libvlc_exception_t *p_e )
 {
+    assert( p_instance->p_playlist );
     ///\todo Handle additionnal options
 
-    if( p_instance->p_playlist->i_size == 0 )
-    {
-        libvlc_exception_raise( p_exception, "Empty playlist" );
-        return;
-    }
+    if( p_instance->p_playlist->i_size == 0 ) RAISEVOID( "Empty playlist" );
     if( i_id > 0 )
     {
-        playlist_item_t *p_item = playlist_ItemGetById( p_instance->p_playlist, i_id );
+        playlist_item_t *p_item = playlist_ItemGetById( p_instance->p_playlist,
+                                                        i_id );
+        if( !p_item ) RAISEVOID( "Unable to find item" );
 
-        if( !p_item )
-        {
-            libvlc_exception_raise( p_exception, "Unable to find item " );
-            return;
-        }
         playlist_LockControl( p_instance->p_playlist, PLAYLIST_VIEWPLAY,
                           p_instance->p_playlist->status.p_node, p_item );
     }
@@ -56,103 +50,94 @@ void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
 }
 
 void libvlc_playlist_pause( libvlc_instance_t *p_instance,
-                           libvlc_exception_t *p_exception )
+                           libvlc_exception_t *p_e )
 {
+    assert( p_instance->p_playlist );
     if( playlist_Pause( p_instance->p_playlist ) != VLC_SUCCESS )
-    {
-        libvlc_exception_raise( p_exception, "Empty playlist" );
-    }
+        RAISEVOID( "Empty playlist" );
 }
 
 
 void libvlc_playlist_stop( libvlc_instance_t *p_instance,
-                           libvlc_exception_t *p_exception )
+                           libvlc_exception_t *p_e )
 {
+    assert( p_instance->p_playlist );
     if( playlist_Stop( p_instance->p_playlist ) != VLC_SUCCESS )
-    {
-        libvlc_exception_raise( p_exception, "Empty playlist" );
-    }
+        RAISEVOID( "Empty playlist" );
 }
 
 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
-                           libvlc_exception_t *p_exception )
+                           libvlc_exception_t *p_e )
 {
+    assert( p_instance->p_playlist );
     playlist_Clear( p_instance->p_playlist );
 }
 
 void libvlc_playlist_next( libvlc_instance_t *p_instance,
-                           libvlc_exception_t *p_exception )
+                           libvlc_exception_t *p_e )
 {
+    assert( p_instance->p_playlist );
     if( playlist_Next( p_instance->p_playlist ) != VLC_SUCCESS )
-    {
-        libvlc_exception_raise( p_exception, "Empty playlist" );
-    }
+        RAISEVOID( "Empty playlist" );
 }
 
 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
-                           libvlc_exception_t *p_exception )
+                           libvlc_exception_t *p_e )
 {
     if( playlist_Prev( p_instance->p_playlist ) != VLC_SUCCESS )
-    {
-        libvlc_exception_raise( p_exception, "Empty playlist" );
-    }
+        RAISEVOID( "Empty playlist" );
 }
 
 int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
-                         const char *psz_name, libvlc_exception_t *p_exception )
+                         const char *psz_name, libvlc_exception_t *p_e )
 {
     return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
-                                         0, NULL, p_exception );
+                                         0, NULL, p_e );
 }
 
 int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
                                   const char *psz_uri, const char *psz_name,
                                   int i_options, const char **ppsz_options,
-                                  libvlc_exception_t *p_exception )
+                                  libvlc_exception_t *p_e )
 {
+    assert( p_instance->p_playlist );
     return playlist_PlaylistAddExt( p_instance->p_playlist, psz_uri, psz_name,
                             PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
                             i_options );
 }
 
 int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
-                                 libvlc_exception_t *p_exception )
+                                 libvlc_exception_t *p_e )
 {
+    assert( p_instance->p_playlist );
     return playlist_DeleteFromItemId( p_instance->p_playlist, i_id );
 }
 
 
 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
-                               libvlc_exception_t *p_exception )
+                               libvlc_exception_t *p_e )
 {
-    if( !p_instance->p_playlist )
-    {
-        libvlc_exception_raise( p_exception, "No playlist" );
-        return 0;
-    }
+    assert( p_instance->p_playlist );
     return playlist_IsPlaying( p_instance->p_playlist );
 }
 
 int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
-                                 libvlc_exception_t *p_exception )
+                                 libvlc_exception_t *p_e )
 {
-    if( !p_instance->p_playlist )
-    {
-        libvlc_exception_raise( p_exception, "No playlist" );
-        return 0;
-    }
+    assert( p_instance->p_playlist );
     return p_instance->p_playlist->i_size;
 }
 
 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
-                                            libvlc_exception_t *p_exception )
+                                            libvlc_exception_t *p_e )
 {
     libvlc_input_t *p_input;
+    assert( p_instance->p_playlist );
 
     vlc_mutex_lock( &p_instance->p_playlist->object_lock );
     if( p_instance->p_playlist->p_input == NULL )
     {
-        libvlc_exception_raise( p_exception, "No active input" );
+        libvlc_exception_raise( p_e, "No active input" );
         vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
         return NULL;
     }