]> git.sesse.net Git - vlc/commitdiff
* include/vlc_input.h, src/playlist/item.c: added vlc_input_item_Init()/Clean() facility.
authorGildas Bazin <gbazin@videolan.org>
Sun, 19 Sep 2004 19:22:04 +0000 (19:22 +0000)
committerGildas Bazin <gbazin@videolan.org>
Sun, 19 Sep 2004 19:22:04 +0000 (19:22 +0000)
include/vlc/intf.h
include/vlc_input.h
src/playlist/item.c

index 5751594a7632d085b81abec3d65bf8d8898bbcb7..b441d27689dde7d36ec0f1797bb41cf068167999 100644 (file)
@@ -35,6 +35,7 @@ extern "C" {
  * Required internal headers
  *****************************************************************************/
 #include "vlc_interface.h"
+#include "vlc_es.h"
 #include "vlc_input.h"
 #include "intf_eject.h"
 #include "vlc_playlist.h"
index b9872ee6d193eb86f97532160206a640243ef6ac..ae4f99f9625cc4742e5b5673659e90b4d41c79e2 100644 (file)
@@ -62,6 +62,65 @@ struct input_item_t
     vlc_mutex_t lock;                /**< Item cannot be changed without this lock */
 };
 
+static inline void vlc_input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
+{
+    memset( p_i, 0, sizeof(input_item_t) );
+    p_i->psz_name = 0;
+    p_i->psz_uri = 0;
+    p_i->ppsz_options = 0;
+    p_i->pp_categories = 0;
+    p_i->es = 0;
+    vlc_mutex_init( p_o, &p_i->lock );
+}
+
+static inline void vlc_input_item_Clean( input_item_t *p_i )
+{
+    if( p_i->psz_name ) free( p_i->psz_name );
+    if( p_i->psz_uri ) free( p_i->psz_uri );
+    p_i->psz_name = 0;
+    p_i->psz_uri = 0;
+
+    while( p_i->i_options )
+    {
+        p_i->i_options--;
+        if( p_i->ppsz_options[p_i->i_options] )
+            free( p_i->ppsz_options[p_i->i_options] );
+        if( !p_i->i_options ) free( p_i->ppsz_options );
+    }
+
+    while( p_i->i_es )
+    {
+        p_i->i_es--;
+        es_format_Clean( p_i->es[p_i->i_es] );
+        if( !p_i->i_es ) free( p_i->es );
+    }
+
+    while( p_i->i_categories )
+    {
+        info_category_t *p_category =
+            p_i->pp_categories[--(p_i->i_categories)];
+
+        while( p_category->i_infos )
+        {
+            p_category->i_infos--;
+
+            if( p_category->pp_infos[p_category->i_infos]->psz_name )
+                free( p_category->pp_infos[p_category->i_infos]->psz_name);
+            if( p_category->pp_infos[p_category->i_infos]->psz_value )
+                free( p_category->pp_infos[p_category->i_infos]->psz_value );
+            free( p_category->pp_infos[p_category->i_infos] );
+
+            if( !p_category->i_infos ) free( p_category->pp_infos );
+        }
+
+        if( p_category->psz_name ) free( p_category->psz_name );
+        free( p_category );
+
+        if( !p_i->i_categories ) free( p_i->pp_categories );
+    }
+
+    vlc_mutex_destroy( &p_i->lock );
+}
 
 /*****************************************************************************
  * Seek point: (generalisation of chapters)
@@ -129,6 +188,7 @@ static inline input_title_t *vlc_input_title_New( )
 
     return t;
 }
+
 static inline void vlc_input_title_Delete( input_title_t *t )
 {
     int i;
@@ -169,7 +229,6 @@ static inline input_title_t *vlc_input_title_Duplicate( input_title_t *t )
     return dup;
 }
 
-
 /*****************************************************************************
  * input defines/constants.
  *****************************************************************************/
@@ -357,10 +416,8 @@ enum input_query_e
 VLC_EXPORT( int, input_vaControl,( input_thread_t *, int i_query, va_list  ) );
 VLC_EXPORT( int, input_Control,  ( input_thread_t *, int i_query, ...  ) );
 
-
 VLC_EXPORT( decoder_t *, input_DecoderNew, ( input_thread_t *, es_format_t *, vlc_bool_t b_force_decoder ) );
 VLC_EXPORT( void, input_DecoderDelete, ( decoder_t * ) );
 VLC_EXPORT( void, input_DecoderDecode,( decoder_t *, block_t * ) );
 
 #endif
-
index 984501e20c8b2cd38c891bc499096cf9fee44ac2..ec757f85ba3a01bf3f3a79c8c1d827d64685d49b 100644 (file)
@@ -47,8 +47,9 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
     if( p_item == NULL ) return NULL;
     if( psz_uri == NULL) return NULL;
 
-    memset( p_item, 0, sizeof( playlist_item_t ) );
+    vlc_input_item_Init( p_obj, p_item );
 
+    p_item->input.i_duration = -1;
     p_item->input.psz_uri = strdup( psz_uri );
 
     if( psz_name != NULL ) p_item->input.psz_name = strdup( psz_name );
@@ -58,12 +59,6 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
     p_item->i_group = PLAYLIST_TYPE_MANUAL;
     p_item->i_nb_played = 0;
 
-    p_item->input.i_duration = -1;
-    p_item->input.ppsz_options = NULL;
-    p_item->input.i_options = 0;
-
-    vlc_mutex_init( p_obj, &p_item->input.lock );
-
     playlist_ItemCreateCategory( p_item, _("General") );
     return p_item;
 }
@@ -76,50 +71,7 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
  */
 void playlist_ItemDelete( playlist_item_t *p_item )
 {
-    vlc_mutex_lock( &p_item->input.lock );
-
-    if( p_item->input.psz_name ) free( p_item->input.psz_name );
-    if( p_item->input.psz_uri ) free( p_item->input.psz_uri );
-
-    /* Free the info categories */
-    if( p_item->input.i_categories > 0 )
-    {
-        int i, j;
-
-        for( i = 0; i < p_item->input.i_categories; i++ )
-        {
-            info_category_t *p_category = p_item->input.pp_categories[i];
-
-            for( j = 0; j < p_category->i_infos; j++)
-            {
-                if( p_category->pp_infos[j]->psz_name )
-                {
-                    free( p_category->pp_infos[j]->psz_name);
-                }
-                if( p_category->pp_infos[j]->psz_value )
-                {
-                    free( p_category->pp_infos[j]->psz_value );
-                }
-                free( p_category->pp_infos[j] );
-            }
-
-            if( p_category->i_infos ) free( p_category->pp_infos );
-            if( p_category->psz_name ) free( p_category->psz_name );
-            free( p_category );
-        }
-
-        free( p_item->input.pp_categories );
-    }
-
-    for( ; p_item->input.i_options > 0; p_item->input.i_options-- )
-    {
-        free( p_item->input.ppsz_options[p_item->input.i_options - 1] );
-        if( p_item->input.i_options == 1 ) free( p_item->input.ppsz_options );
-    }
-
-    vlc_mutex_unlock( &p_item->input.lock );
-    vlc_mutex_destroy( &p_item->input.lock );
-
+    vlc_input_item_Clean( p_item );
     free( p_item );
 }