]> git.sesse.net Git - vlc/blobdiff - src/playlist/item.c
Don't fail with no-debug
[vlc] / src / playlist / item.c
index 9e5a5cd522590e9c446d00974c8c04fef55508a3..6f4eb9409187792f3079174654da864e3b1433e0 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * item.c : Playlist item functions
  *****************************************************************************
- * Copyright (C) 1999-2004 VideoLAN
+ * Copyright (C) 1999-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 #include <stdlib.h>                                      /* free(), strtol() */
 #include <stdio.h>                                              /* sprintf() */
@@ -27,6 +27,7 @@
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 
+#include "vlc_input.h"
 #include "vlc_playlist.h"
 
 static void GuessType( input_item_t *p_item);
@@ -39,9 +40,19 @@ static void GuessType( input_item_t *p_item);
  * \param psz_name a text giving a name or description of the item
  * \return the new item or NULL on failure
  */
+
 playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
                                       const char *psz_uri,
                                       const char *psz_name )
+{
+    return playlist_ItemNewWithType( p_obj, psz_uri,
+                                     psz_name, ITEM_TYPE_UNKNOWN );
+}
+
+playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
+                                            const char *psz_uri,
+                                            const char *psz_name,
+                                            int i_type )
 {
     playlist_item_t * p_item;
 
@@ -52,11 +63,16 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
 
     memset( p_item, 0, sizeof( playlist_item_t ) );
 
+    vlc_input_item_Init( p_obj, &p_item->input );
+    p_item->input.b_fixed_name = VLC_FALSE;
+
     p_item->input.psz_uri = strdup( psz_uri );
 
     if( psz_name != NULL ) p_item->input.psz_name = strdup( psz_name );
     else p_item->input.psz_name = strdup ( psz_uri );
 
+    p_item->input.i_type = i_type;
+
     p_item->b_enabled = VLC_TRUE;
     p_item->i_nb_played = 0;
 
@@ -65,6 +81,7 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
 
     p_item->i_flags = 0;
     p_item->i_flags |= PLAYLIST_SKIP_FLAG;
+    p_item->i_flags |= PLAYLIST_SAVE_FLAG;
 
     p_item->input.i_duration = -1;
     p_item->input.ppsz_options = NULL;
@@ -72,13 +89,98 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
 
     vlc_mutex_init( p_obj, &p_item->input.lock );
 
-    GuessType( &p_item->input );
-
-    playlist_ItemCreateCategory( p_item, _("General") );
+    if( p_item->input.i_type == ITEM_TYPE_UNKNOWN )
+        GuessType( &p_item->input );
 
     return p_item;
 }
 
+/**
+ * Copy a playlist item
+ *
+ * Creates a new item with name, mrl and meta infor like the
+ * source. Does not copy children for node type items.
+ * \param p_obj any vlc object, needed for mutex init
+ * \param p_item the item to copy
+ * \return pointer to the new item, or NULL on error
+ * \note function takes the lock on p_item
+ */
+playlist_item_t *__playlist_ItemCopy( vlc_object_t *p_obj,
+                                      playlist_item_t *p_item )
+{
+    playlist_item_t *p_res;
+    int i;
+    vlc_mutex_lock( &p_item->input.lock );
+
+    p_res = malloc( sizeof( playlist_item_t ) );
+    if( p_res == NULL )
+    {
+        vlc_mutex_unlock( &p_item->input.lock );
+        return NULL;
+    }
+
+    *p_res = *p_item;
+    vlc_mutex_init( p_obj, &p_res->input.lock );
+
+    if( p_item->input.i_options )
+        p_res->input.ppsz_options =
+            malloc( p_item->input.i_options * sizeof(char*) );
+    for( i = 0; i < p_item->input.i_options; i++ )
+    {
+        p_res->input.ppsz_options[i] = strdup( p_item->input.ppsz_options[i] );
+    }
+
+    if( p_item->i_children != -1 )
+    {
+        msg_Warn( p_obj, "not copying playlist items children" );
+        p_res->i_children = -1;
+        p_res->pp_children = NULL;
+    }
+    p_res->i_parents = 0;
+    p_res->pp_parents = NULL;
+    
+    if( p_item->input.psz_name )
+        p_res->input.psz_name = strdup( p_item->input.psz_name );
+    if( p_item->input.psz_uri )
+        p_res->input.psz_uri = strdup( p_item->input.psz_uri );
+    
+    if( p_item->input.i_es )
+    {
+        p_res->input.es =
+            (es_format_t**)malloc( p_item->input.i_es * sizeof(es_format_t*));
+        for( i = 0; i < p_item->input.i_es; i++ )
+        {
+            p_res->input.es[ i ] = (es_format_t*)malloc(sizeof(es_format_t*));
+            es_format_Copy( p_res->input.es[ i ],
+                         p_item->input.es[ i ] );
+        }
+    }
+    if( p_item->input.i_categories )
+    {
+        p_res->input.pp_categories = NULL;
+        p_res->input.i_categories = 0;
+        for( i = 0; i < p_item->input.i_categories; i++ )
+        {
+            info_category_t *p_incat;
+            p_incat = p_item->input.pp_categories[i];
+            if( p_incat->i_infos )
+            {
+                int j;
+                for( j = 0; j < p_incat->i_infos; j++ )
+                {
+                    vlc_input_item_AddInfo( &p_res->input, p_incat->psz_name,
+                                            p_incat->pp_infos[j]->psz_name,
+                                            "%s", /* to be safe */
+                                            p_incat->pp_infos[j]->psz_value );
+                }
+            }
+        }
+    }
+
+    vlc_mutex_unlock( &p_item->input.lock );
+    return p_res;
+}
+
 /**
  * Deletes a playlist item
  *
@@ -235,6 +337,7 @@ int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name )
 {
     if( psz_name && p_item )
     {
+        if( p_item->input.psz_name ) free( p_item->input.psz_name );
         p_item->input.psz_name = strdup( psz_name );
         return VLC_SUCCESS;
     }
@@ -263,8 +366,8 @@ int playlist_ItemSetDuration( playlist_item_t *p_item, mtime_t i_duration )
         {
             memcpy( psz_buffer, "--:--:--", sizeof("--:--:--") );
         }
-        playlist_ItemAddInfo( p_item, _("General") , _("Duration"),
-                              "%s", psz_buffer );
+        vlc_input_item_AddInfo( &p_item->input, _("General") , _("Duration"),
+                                "%s", psz_buffer );
 
         return VLC_SUCCESS;
     }
@@ -280,7 +383,7 @@ static void GuessType( input_item_t *p_item)
     {
         { "http", ITEM_TYPE_NET },
         { "dvd", ITEM_TYPE_DISC },
-        { "cdda", ITEM_TYPE_DISC },
+        { "cdda", ITEM_TYPE_CDDA },
         { "mms", ITEM_TYPE_NET },
         { "rtsp", ITEM_TYPE_NET },
         { "udp", ITEM_TYPE_NET },
@@ -295,6 +398,14 @@ static void GuessType( input_item_t *p_item)
         { NULL, 0 }
     };
 
+#if 0 /* Unused */
+    static struct { char *psz_search; int i_type; } exts_array[] =
+    {
+        { "mp3", ITEM_TYPE_AFILE },
+        { NULL, 0 }
+    };
+#endif
+
     for( i = 0; types_array[i].psz_search != NULL; i++ )
     {
         if( !strncmp( p_item->psz_uri, types_array[i].psz_search,
@@ -304,5 +415,5 @@ static void GuessType( input_item_t *p_item)
             return;
         }
     }
-    p_item->i_type = ITEM_TYPE_UNKNOWN;
+    p_item->i_type = ITEM_TYPE_VFILE;
 }