]> git.sesse.net Git - vlc/commitdiff
Options as infos were bad in several ways: it broke PLAYLIST_GO, used
authorClément Stenac <zorglub@videolan.org>
Thu, 29 Jan 2004 17:51:08 +0000 (17:51 +0000)
committerClément Stenac <zorglub@videolan.org>
Thu, 29 Jan 2004 17:51:08 +0000 (17:51 +0000)
much memory, and was inconsistent, especially with input_CreateThread
taking an array of options

* Revert to using array of options

* To add an item with options:
    - either use playlist_ItemNew, ItemAddOption, and then AddItem
      (useful if you don't have all your options in an array)
    - either use playlist_AddExt (use this if all your options are
      already in an array)

* To add an item without options: use playlist_Add

You can still add options after an item has been added by using either
playlist_AddOption or playlist_ItemAddOption

* Attempt to improve API and solve thread safety issues.
  - playlist_Item* functions allow to touch items only.
    p_item->lock must be used when needed
    (playlist_ItemNew, playlist_ItemDelete, playlist_Item*Info,
     playlist_ItemSet* )

  - playlist_ItemGetById and ItemGetByPos give you playlist_items
    for GetByPos, you should have the playlist lock

At the moment, the playlist_Set* and playlist_*Info functions are kept (they work with position) but should be avoided.

22 files changed:
include/vlc_playlist.h
modules/access/cdda/access.c
modules/access/vcdx/access.c
modules/codec/speex.c
modules/codec/theora.c
modules/codec/vorbis.c
modules/control/http.c
modules/demux/util/id3tag.c
modules/gui/pda/pda_callbacks.c
modules/gui/wxwindows/iteminfo.cpp
modules/gui/wxwindows/open.cpp
modules/gui/wxwindows/playlist.cpp
modules/gui/wxwindows/streamwizard.cpp
modules/misc/sap.c
src/input/input.c
src/libvlc.c
src/misc/win32_specific.c
src/playlist/info.c
src/playlist/item-ext.c
src/playlist/item.c
src/playlist/loadsave.c
src/playlist/playlist.c

index 0c6c9bad32d78ea164ec00b682e86eb073b8e771..bf7593fd50c6949bfdac6b9c1035cd6a57f74bd3 100644 (file)
@@ -2,7 +2,7 @@
  * vlc_playlist.h : Playlist functions
  *****************************************************************************
  * Copyright (C) 1999-2004 VideoLAN
- * $Id: vlc_playlist.h,v 1.26 2004/01/25 18:17:08 zorglub Exp $
+ * $Id: vlc_playlist.h,v 1.27 2004/01/29 17:51:07 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -75,10 +75,11 @@ struct playlist_item_t
     char *     psz_uri;        /**< mrl of this item */
     mtime_t    i_duration;     /**< A hint about the duration of this
                                 * item, in milliseconds*/
-    int i_categories;          /**< Number of info categories */
-    item_info_category_t **pp_categories;
-                               /**< Pointer to the first info category */
-    int        i_status;       /**< unused yet */
+    int        i_categories;   /**< Number of info categories */
+    item_info_category_t **
+               pp_categories;  /**< Pointer to the first info category */
+    int        i_options;      /**< Number of options */
+    char **    ppsz_options;   /**< Array of options */
     int        i_nb_played;    /**< How many times was this item played ? */
     vlc_bool_t b_autodeletion; /**< Indicates whther this item is to
                                 * be deleted after playback. True mean
@@ -86,8 +87,9 @@ struct playlist_item_t
                                 * after playback, false otherwise */
     vlc_bool_t b_enabled;      /**< Indicates whether this item is to be
                                 * played or skipped */
-    int        i_group;         /**< Which group does this item belongs to ? */
+    int        i_group;        /**< Which group does this item belongs to ? */
     int        i_id;           /**< Unique id to track this item */
+    vlc_mutex_t lock;          /**< Item cannot be changed without this lock */
 };
 
 /**
@@ -165,11 +167,18 @@ void           playlist_Destroy  ( playlist_t * );
 VLC_EXPORT( void, playlist_Command, ( playlist_t *, playlist_command_t, int ) );
 
 
-/* Item functions */
+/* Item management functions */
+#define playlist_AddItem(p,pi,i1,i2) playlist_ItemAdd(p,pi,i1,i2)
+#define playlist_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
+VLC_EXPORT( playlist_item_t* , __playlist_ItemNew, ( vlc_object_t *,const char *,const char * ) );
+VLC_EXPORT( void, playlist_ItemDelete, ( playlist_item_t * ) );
+VLC_EXPORT( int,  playlist_ItemAdd, ( playlist_t *, playlist_item_t *, int, int ) );
+
+/* Simple add/remove funcctions */
 VLC_EXPORT( int,  playlist_Add,    ( playlist_t *, const char *, const char *, int, int ) );
-VLC_EXPORT( int,  playlist_AddWDuration, ( playlist_t *, const char *, const char *, int, int, mtime_t ) );
-/* For internal use. Do not use this one anymore */
-VLC_EXPORT( int,  playlist_AddItem, ( playlist_t *, playlist_item_t *, int, int ) );
+VLC_EXPORT( int,  playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char **,int ) );
+
+
 VLC_EXPORT( int,  playlist_Clear, ( playlist_t * ) );
 VLC_EXPORT( int,  playlist_Delete, ( playlist_t *, int ) );
 VLC_EXPORT( int,  playlist_Disable, ( playlist_t *, int ) );
@@ -178,13 +187,18 @@ VLC_EXPORT( int,  playlist_DisableGroup, ( playlist_t *, int ) );
 VLC_EXPORT( int,  playlist_EnableGroup, ( playlist_t *, int ) );
 
 /* Basic item informations accessors */
-VLC_EXPORT( int, playlist_SetGroup, (playlist_t *, int, int ) );
-VLC_EXPORT( int, playlist_SetName, (playlist_t *, int, char * ) );
-VLC_EXPORT( int, playlist_SetDuration, (playlist_t *, int, mtime_t ) );
+VLC_EXPORT( int, playlist_ItemSetGroup, (playlist_item_t *, int ) );
+VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *,  char * ) );
+VLC_EXPORT( int, playlist_ItemSetDuration, (playlist_item_t *, mtime_t ) );
+
+VLC_EXPORT( int, playlist_SetGroup, (playlist_t * , int , int ) );
+VLC_EXPORT( int, playlist_SetName, (playlist_t *, int ,  char * ) );
+VLC_EXPORT( int, playlist_SetDuration, (playlist_t *, int , mtime_t ) );
 
 /* Item search functions */
 VLC_EXPORT( int, playlist_GetPositionById, (playlist_t *, int) );
-VLC_EXPORT( playlist_item_t *, playlist_GetItemById, (playlist_t *, int) );
+VLC_EXPORT( playlist_item_t *, playlist_ItemGetById, (playlist_t *, int) );
+VLC_EXPORT( playlist_item_t *, playlist_ItemGetByPos, (playlist_t *, int) );
 
 
 /* Group management functions */
@@ -195,20 +209,20 @@ VLC_EXPORT( int, playlist_GroupToId, (playlist_t *, char * ) );
 
 /* Info functions */
 VLC_EXPORT( char * , playlist_GetInfo, ( playlist_t * , int, const char *, const char *) );
-VLC_EXPORT( char * , playlist_GetItemInfo, ( playlist_item_t * , const char *, const char *) );
+VLC_EXPORT( char * , playlist_ItemGetInfo, ( playlist_item_t * , const char *, const char *) );
 
 VLC_EXPORT( item_info_category_t*, playlist_GetCategory, ( playlist_t *, int, const char *) );
-VLC_EXPORT( item_info_category_t*, playlist_GetItemCategory, ( playlist_item_t *, const char *) );
+VLC_EXPORT( item_info_category_t*, playlist_ItemGetCategory, ( playlist_item_t *, const char *) );
 
 VLC_EXPORT( item_info_category_t*, playlist_CreateCategory, ( playlist_t *, int, const char *) );
-VLC_EXPORT( item_info_category_t*, playlist_CreateItemCategory, ( playlist_item_t *, const char *) );
+VLC_EXPORT( item_info_category_t*, playlist_ItemCreateCategory, ( playlist_item_t *, const char *) );
 
 VLC_EXPORT( int, playlist_AddInfo, (playlist_t *, int, const char * , const char *, const char *, ...) );
-VLC_EXPORT( int, playlist_AddItemInfo, (playlist_item_t *, const char * , const char *, const char *, ...) );
+VLC_EXPORT( int, playlist_ItemAddInfo, (playlist_item_t *, const char * , const char *, const char *, ...) );
 
 /* Option functions */
-VLC_EXPORT( int, playlist_AddOption, (playlist_t *, int, const char *, ...) );
-VLC_EXPORT( int, playlist_AddItemOption, (playlist_item_t *, const char *, ...) );
+VLC_EXPORT( int, playlist_AddOption, (playlist_t *, int, const char *) );
+VLC_EXPORT( int, playlist_ItemAddOption, (playlist_item_t *, const char *) );
 
 /* Playlist sorting */
 #define playlist_SortID(p, i) playlist_Sort( p, SORT_ID, i)
index d36d7bd382801fd0a8d28c719ad82fc9a65bfa76..092abb962bfaa55c6d8de4bd76f372244db0661b 100644 (file)
@@ -2,7 +2,7 @@
  * cddax.c : CD digital audio input module for vlc using libcdio
  *****************************************************************************
  * Copyright (C) 2000,2003 VideoLAN
- * $Id: access.c,v 1.22 2004/01/07 07:21:31 rocky Exp $
+ * $Id: access.c,v 1.23 2004/01/29 17:51:07 zorglub Exp $
  *
  * Authors: Rocky Bernstein <rocky@panix.com>
  *          Laurent Aimar <fenrir@via.ecp.fr>
@@ -314,8 +314,13 @@ static void CDDASeek( input_thread_t * p_input, off_t i_off )
   if ( str ) {                                                 \
     dbg_print( INPUT_DBG_META, "field %s: %s\n", title, str);  \
     input_AddInfo( p_cat, _(title), "%s", str );               \
-    playlist_AddInfo( p_playlist, -1, p_cat->psz_name,         \
+    vlc_mutex_lock( &p_playlist->object_lock );                \
+    p_item = playlist_ItemGetByPos( p_playlist, -1 );          \
+    vlc_mutex_unlock( &p_playlist->object_lock );              \
+    vlc_mutex_lock( &p_item->lock );                           \
+    playlist_ItemAddInfo( p_item, p_cat->psz_name,             \
                       _(title), "%s" , str );                  \
+    vlc_mutex_unlock( &p_item->lock );                         \
   }
 
 
@@ -325,9 +330,10 @@ static void InformationCreate( input_thread_t *p_input  )
   playlist_t *p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
                                             FIND_PARENT );
   input_info_category_t *p_cat;
+  playlist_item_t *p_item;
 
   p_cat = input_InfoCategory( p_input, "General" );
-  
+
 
 #ifdef HAVE_LIBCDDB
   if (p_cdda->i_cddb_enabled) {
@@ -669,6 +675,7 @@ CDDACreatePlayListItem(const input_thread_t *p_input, cdda_data_t *p_cdda,
   char *p_author;
   char *p_title;
   char *config_varname = MODULE_STRING "-title-format";
+  playlist_item_t *p_item;
 
 #ifdef HAVE_LIBCDDB
   if (p_cdda->i_cddb_enabled) {
@@ -685,54 +692,63 @@ CDDACreatePlayListItem(const input_thread_t *p_input, cdda_data_t *p_cdda,
 
   dbg_print( INPUT_DBG_META, "mrl: %s, title: %s, duration, %ld, pos %d",
              psz_mrl, p_title, (long int) i_duration / 1000000 , i_pos );
-  playlist_AddWDuration( p_playlist, psz_mrl, p_title, playlist_operation, 
-                        i_pos, i_duration );
+  playlist_AddExt( p_playlist, psz_mrl, p_title, playlist_operation,
+                         i_pos, i_duration , NULL, 0);
 
   if( i_pos == PLAYLIST_END ) i_pos = p_playlist->i_size - 1;
 
+  vlc_mutex_lock( &p_playlist->object_lock );
+  p_item = playlist_ItemGetByPos( p_playlist, i_pos );
+  vlc_mutex_unlock( &p_playlist->object_lock );
+  if( !p_item )
+      return;
+
+  vlc_mutex_lock( &p_item->lock );
+
   p_author =
     CDDAFormatStr( p_input, p_cdda,
                    config_GetPsz( p_input, MODULE_STRING "-author-format" ),
                    psz_mrl, i_track );
 
-  playlist_AddInfo( p_playlist, i_pos, _("General"),_("Author"), p_author);
+  playlist_ItemAddInfo( p_item ,  _("General"),_("Author"), p_author);
 
 #ifdef HAVE_LIBCDDB
   if (p_cdda->i_cddb_enabled) {
     const char *psz_general_cat = _("General");
 
-    playlist_AddInfo( p_playlist, i_pos, psz_general_cat, _("Album"),
-                     "%s", p_cdda->cddb.disc->title);
-    playlist_AddInfo( p_playlist, i_pos, psz_general_cat, _("Disc Artist(s)"),
-                     "%s", p_cdda->cddb.disc->artist);
-    playlist_AddInfo( p_playlist, i_pos, psz_general_cat,
-                     _("CDDB Disc Category"),
-                     "%s", CDDB_CATEGORY[p_cdda->cddb.disc->category]);
-    playlist_AddInfo( p_playlist, i_pos, psz_general_cat, _("Genre"),
-                     "%s", p_cdda->cddb.disc->genre);
+    playlist_ItemAddInfo( p_item, psz_general_cat, _("Album"),
+                      "%s", p_cdda->cddb.disc->title);
+    playlist_ItemAddInfo( p_item, psz_general_cat, _("Disc Artist(s)"),
+                      "%s", p_cdda->cddb.disc->artist);
+    playlist_ItemAddInfo( p_item, psz_general_cat,
+                        _("CDDB Disc Category"),
+                      "%s", CDDB_CATEGORY[p_cdda->cddb.disc->category]);
+    playlist_ItemAddInfo( p_item, psz_general_cat, _("Genre"),
+                      "%s", p_cdda->cddb.disc->genre);
     if ( p_cdda->cddb.disc->discid ) {
-      playlist_AddInfo( p_playlist, i_pos, psz_general_cat, _("CDDB Disc ID"),
-                       "%x", p_cdda->cddb.disc->discid );
+      playlist_ItemAddInfo( p_item, psz_general_cat, _("CDDB Disc ID"),
+                        "%x", p_cdda->cddb.disc->discid );
     }
     if (p_cdda->cddb.disc->year != 0) {
-      playlist_AddInfo( p_playlist, i_pos, psz_general_cat,
-                       _("Year"), "%5d", p_cdda->cddb.disc->year );
+      playlist_ItemAddInfo( p_item, psz_general_cat,
+                        _("Year"), "%5d", p_cdda->cddb.disc->year );
     }
 
     if (p_cdda->i_cddb_enabled) {
       cddb_track_t *t=cddb_disc_get_track(p_cdda->cddb.disc,
-                                         i_track-1);
+                                          i_track-1);
       if (t != NULL && t->artist != NULL) {
-       playlist_AddInfo( p_playlist, i_pos, psz_general_cat,
-                         _("Track Artist"), "%s", t->artist );
-       playlist_AddInfo( p_playlist, i_pos, psz_general_cat,
-                         _("Track Title"), "%s",  t->title );
+        playlist_ItemAddInfo( p_item, psz_general_cat,
+                          _("Track Artist"), "%s", t->artist );
+        playlist_ItemAddInfo( p_item , psz_general_cat,
+                          _("Track Title"), "%s",  t->title );
       }
     }
 
   }
 #endif /*HAVE_LIBCDDB*/
 
+  vlc_mutex_unlock( &p_item->lock );
 }
 
 static int
index 89e2f3a877b30eadb6319cf9546522faebb1125b..5aaf7095cae20160de4c1f82d471c2b4aeecf40b 100644 (file)
@@ -4,7 +4,7 @@
  *         to go here.
  *****************************************************************************
  * Copyright (C) 2000, 2003, 2004 VideoLAN
- * $Id: access.c,v 1.17 2004/01/25 04:53:16 rocky Exp $
+ * $Id: access.c,v 1.18 2004/01/29 17:51:07 zorglub Exp $
  *
  * Authors: Rocky Bernstein <rocky@panix.com>
  *          Johan Bilien <jobi@via.ecp.fr>
@@ -1003,37 +1003,53 @@ VCDUpdateVar( input_thread_t *p_input, int i_num, int i_action,
 
 
 static inline void
-MetaInfoAddStr(input_thread_t *p_input, input_info_category_t *p_cat, 
-                 playlist_t *p_playlist, char *title, 
-                 const char *str)
+MetaInfoAddStr(input_thread_t *p_input, input_info_category_t *p_cat,
+               playlist_t *p_playlist, char *title,
+               const char *str)
 {
   thread_vcd_data_t *p_vcd = (thread_vcd_data_t *) p_input->p_access_data;
-  if ( str ) {                                                                
+  playlist_item_t *p_item;
+  if ( str ) {
     dbg_print( INPUT_DBG_META, "field: %s: %s\n", title, str);
-    input_AddInfo( p_cat, title, "%s", str );              
-    playlist_AddInfo( p_playlist, -1, p_cat->psz_name, title,
-                      "%s",str );                                             
+    input_AddInfo( p_cat, title, "%s", str );
+
+    vlc_mutex_lock( &p_playlist->object_lock );
+    p_item = playlist_ItemGetByPos( p_playlist, -1 );
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
+    vlc_mutex_lock( &p_item->lock );
+    playlist_ItemAddInfo( p_item, p_cat->psz_name, title,
+                          "%s",str );
+    vlc_mutex_unlock( &p_item->lock );
   }
 }
 
 
 static inline void
-MetaInfoAddNum(input_thread_t *p_input, input_info_category_t *p_cat, 
-              playlist_t *p_playlist, char *title, int num)
+MetaInfoAddNum(input_thread_t *p_input, input_info_category_t *p_cat,
+               playlist_t *p_playlist, char *title, int num)
 {
   thread_vcd_data_t *p_vcd = (thread_vcd_data_t *) p_input->p_access_data;
+  playlist_item_t *p_item;
+
+  vlc_mutex_lock( &p_playlist->object_lock );
+  p_item = playlist_ItemGetByPos( p_playlist, -1 );
+  vlc_mutex_unlock( &p_playlist->object_lock );
+
   dbg_print( INPUT_DBG_META, "field %s: %d\n", title, num);
   input_AddInfo( p_cat, title, "%d", num );
-  playlist_AddInfo( p_playlist, -1, p_cat->psz_name, title,
-                    "%d",num );
+
+  vlc_mutex_lock( &p_item->lock );
+  playlist_ItemAddInfo( p_item ,  p_cat->psz_name, title, "%d",num );
+  vlc_mutex_unlock( &p_item->lock );
 }
-  
+
 #define addstr(title, str) \
   MetaInfoAddStr( p_input, p_cat, p_playlist, title, str );
 
 #define addnum(title, num) \
   MetaInfoAddNum( p_input, p_cat, p_playlist, title, num );
-  
+
 static void InformationCreate( input_thread_t *p_input  )
 {
   thread_vcd_data_t *p_vcd = (thread_vcd_data_t *) p_input->p_access_data;
index f227431ce587d3f127f5a941911bdbb0674279cf..fdb0a8d5e74c374e40e72169784f3074f924e242 100755 (executable)
@@ -2,7 +2,7 @@
  * speex.c: speex decoder/packetizer/encoder module making use of libspeex.
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: speex.c,v 1.10 2004/01/25 18:20:12 bigben Exp $
+ * $Id: speex.c,v 1.11 2004/01/29 17:51:07 zorglub Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -471,8 +471,19 @@ static void ParseSpeexComments( decoder_t *p_dec, ogg_packet *p_oggpacket )
 
     p_mode = speex_mode_list[p_sys->p_header->mode];
     input_AddInfo( p_cat, _("Mode"), "%s%s",
-                   p_mode->modeName, p_sys->p_header->vbr ? " VBR" : "" );
-    playlist_AddInfo( p_playlist, -1, _("Speex comment") , _("Mode"), "%s%s",
+                  p_mode->modeName, p_sys->p_header->vbr ? " VBR" : "" );
+
+    vlc_mutex_lock( &p_playlist->object_lock );
+    p_item = playlist_ItemGetByPos( p_playlist, -1 );
+    vlc_mutex_unlock( &p_playlist->object_lock );
+    if( !p_item)
+    {
+        msg_Err(p_dec, "unable to find item" );
+        return;
+    }
+    vlc_mutex_lock( &p_item->lock );
+
+    playlist_ItemAddInfo( p_item, _("Speex comment") , _("Mode"),"%s%s",
                     p_mode->modeName, p_sys->p_header->vbr ? " VBR" : "" );
 
     if( p_oggpacket->bytes < 8 )
@@ -489,7 +500,9 @@ static void ParseSpeexComments( decoder_t *p_dec, ogg_packet *p_oggpacket )
     }
 
     input_AddInfo( p_cat, p_buf, "" );
-    playlist_AddInfo( p_playlist, -1, _("Speex comment") , p_buf , "" );
+    playlist_ItemAddInfo( p_item , _("Speex comment") , p_buf , "" );
+
+    vlc_mutex_unlock( &p_item->lock );
 
     if( p_playlist ) vlc_object_release( p_playlist );
 
index da4843c01a625586b6b52bd04b1b37f7e04056ff..ad633c96ceb5c1d999866eee3bacea9e87ef987d 100644 (file)
@@ -2,7 +2,7 @@
  * theora.c: theora decoder module making use of libtheora.
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: theora.c,v 1.23 2004/01/25 18:20:12 bigben Exp $
+ * $Id: theora.c,v 1.24 2004/01/29 17:51:07 zorglub Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -340,6 +340,7 @@ static void ParseTheoraComments( decoder_t *p_dec )
         input_InfoCategory( p_input, _("Theora comment") );
     playlist_t *p_playlist = vlc_object_find( p_dec, VLC_OBJECT_PLAYLIST,
                                               FIND_ANYWHERE );
+    playlist_item_t *p_item;
     int i = 0;
     char *psz_name, *psz_value, *psz_comment;
     while ( i < p_dec->p_sys->tc.comments )
@@ -357,8 +358,18 @@ static void ParseTheoraComments( decoder_t *p_dec )
             *psz_value = '\0';
             psz_value++;
             input_AddInfo( p_cat, psz_name, psz_value );
-            playlist_AddInfo( p_playlist, -1, _("Theora comment") ,
-                              psz_name, psz_value );
+            vlc_mutex_lock( &p_playlist->object_lock );
+            p_item = playlist_ItemGetByPos( p_playlist, -1 );
+            vlc_mutex_unlock( &p_playlist->object_lock );
+            if( !p_item)
+            {
+                msg_Err(p_dec, "unable to find item" );
+                return;
+            }
+            vlc_mutex_lock( &p_item->lock );
+            playlist_ItemAddInfo( p_item, _("Theora comment") ,
+                                  psz_name, psz_value );
+            vlc_mutex_unlock( &p_item->lock );
         }
         free( psz_comment );
         i++;
index b5b1c6c3ff0d4e4881e4e5867be9ca0733168855..534ea387dadaa7a0e84ec4996fc00e06ee626c2a 100644 (file)
@@ -2,7 +2,7 @@
  * vorbis.c: vorbis decoder/encoder/packetizer module making use of libvorbis.
  *****************************************************************************
  * Copyright (C) 2001-2003 VideoLAN
- * $Id: vorbis.c,v 1.30 2004/01/25 18:20:12 bigben Exp $
+ * $Id: vorbis.c,v 1.31 2004/01/29 17:51:07 zorglub Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -456,6 +456,7 @@ static void ParseVorbisComments( decoder_t *p_dec )
         input_InfoCategory( p_input, _("Vorbis comment") );
     playlist_t *p_playlist = vlc_object_find( p_dec, VLC_OBJECT_PLAYLIST,
                                               FIND_ANYWHERE );
+    playlist_item_t *p_item;
     int i = 0;
     char *psz_name, *psz_value, *psz_comment;
     while ( i < p_dec->p_sys->vc.comments )
@@ -473,8 +474,18 @@ static void ParseVorbisComments( decoder_t *p_dec )
             *psz_value = '\0';
             psz_value++;
             input_AddInfo( p_cat, psz_name, psz_value );
-            playlist_AddInfo( p_playlist, -1, _("Vorbis comment") ,
-                              psz_name, psz_value );
+            vlc_mutex_lock( &p_playlist->object_lock );
+            p_item = playlist_ItemGetByPos( p_playlist, -1 );
+            vlc_mutex_unlock( &p_playlist->object_lock );
+            if( !p_item)
+            {
+                    msg_Err(p_dec, "unable to find item" );
+                    return;
+            }
+            vlc_mutex_lock( &p_item->lock );
+            playlist_ItemAddInfo( p_item, _("Vorbis comment") ,
+                            psz_name, psz_value );
+            vlc_mutex_unlock( &p_item->lock );
         }
         free( psz_comment );
         i++;
index dca627d26b8e610ffe5d23fdcb719528abc61f6b..24c8869a14926886157291bbce9f1f90267df585 100644 (file)
@@ -2,7 +2,7 @@
  * http.c :  http mini-server ;)
  *****************************************************************************
  * Copyright (C) 2001-2004 VideoLAN
- * $Id: http.c,v 1.50 2004/01/25 16:17:03 anil Exp $
+ * $Id: http.c,v 1.51 2004/01/29 17:51:07 zorglub Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *          Laurent Aimar <fenrir@via.ecp.fr>
@@ -125,7 +125,7 @@ static void uri_decode_url_encoded( char *psz );
 
 static char *Find_end_MRL( char *psz );
 
-static playlist_item_t * parse_MRL( char *psz );
+static playlist_item_t * parse_MRL( intf_thread_t * , char *psz );
 
 /*****************************************************************************
  *
@@ -1764,7 +1764,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
 
                     uri_extract_value( p_request, "mrl", mrl, 512 );
                     uri_decode_url_encoded( mrl );
-                    p_item = parse_MRL( mrl );
+                    p_item = parse_MRL( p_intf, mrl );
 
                     if( !p_item || !p_item->psz_uri || !*p_item->psz_uri )
                     {
@@ -2870,7 +2870,7 @@ static char *Find_end_MRL( char *psz )
  * create an item with all informations in it, and return the item.
  * return NULL if there is an error.
  **********************************************************************/
-playlist_item_t * parse_MRL( char *psz )
+playlist_item_t * parse_MRL( intf_thread_t *p_intf, char *psz )
 {
     char **ppsz_options = NULL;
     char *mrl;
@@ -2967,17 +2967,10 @@ playlist_item_t * parse_MRL( char *psz )
     else
     {
         /* now create an item */
-        p_item = malloc( sizeof( playlist_item_t ) );
-        memset( p_item, 0, sizeof( playlist_item_t ) );
-        p_item->psz_name   = mrl;
-        p_item->psz_uri    = strdup( mrl );
-        p_item->i_duration = -1;
-        p_item->b_enabled = VLC_TRUE;
-        p_item->i_group = PLAYLIST_TYPE_MANUAL;
-
+        p_item = playlist_ItemNew( p_intf, mrl, mrl);
         for( i = 0 ; i< i_options ; i++ )
         {
-            playlist_AddItemOption( p_item, ppsz_options[i] );
+            playlist_ItemAddOption( p_item, ppsz_options[i] );
         }
     }
 
index 018509538731775f27b9470611f32b4b6accc986..7a80282fc8fe0bada8f3bf61d62e7025407de430 100644 (file)
@@ -2,7 +2,7 @@
  * id3tag.c: id3 tag parser/skipper based on libid3tag
  *****************************************************************************
  * Copyright (C) 2002-2004 VideoLAN
- * $Id: id3tag.c,v 1.19 2004/01/25 20:05:29 hartman Exp $
+ * $Id: id3tag.c,v 1.20 2004/01/29 17:51:07 zorglub Exp $
  *
  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
  *
@@ -85,7 +85,14 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
 
     while ( ( p_frame = id3_tag_findframe( p_id3_tag , "T", i ) ) )
     {
-        playlist_item_t *p_item = p_playlist ? p_playlist->pp_items[p_playlist->i_index] : NULL;
+        playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, -1 );
+        if( !p_item )
+        {
+            msg_Err( p_input, "Unable to get item" );
+            return;
+        }
+
+        vlc_mutex_lock( &p_item->lock );
 
         int i_strings = id3_field_getnstrings( &p_frame->fields[1] );
 
@@ -101,7 +108,7 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
                 {
                     input_AddInfo( p_category, (char *)p_frame->description,
                                    ppsz_genres[atoi(psz_temp)]);
-                    playlist_AddItemInfo( p_item, "ID3",
+                    playlist_ItemAddInfo( p_item, "ID3",
                                     (char *)p_frame->description,
                                     ppsz_genres[atoi(psz_temp)]);
                 }
@@ -109,7 +116,7 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
                 {
                     input_AddInfo( p_category, (char *)p_frame->description,
                                                 psz_temp );
-                    playlist_AddItemInfo( p_item, "ID3",
+                    playlist_ItemAddInfo( p_item, "ID3",
                                     (char *)p_frame->description,
                                     psz_temp);
                 }
@@ -128,7 +135,7 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
                 }
                 input_AddInfo( p_category, (char *)p_frame->description,
                                             psz_temp );
-                playlist_AddItemInfo( p_item, "ID3",
+                playlist_ItemAddInfo( p_item, "ID3",
                                         (char *)p_frame->description,
                                     psz_temp);
             }
@@ -136,13 +143,13 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
             {
                 if( p_item )
                 {
-                    playlist_AddItemInfo( p_item,
+                    playlist_ItemAddInfo( p_item,
                                           _("General"), _("Author"), psz_temp);
                     val.b_bool = VLC_TRUE;
                 }
                 input_AddInfo( p_category, (char *)p_frame->description,
                                             psz_temp );
-                playlist_AddItemInfo( p_item, "ID3",
+                playlist_ItemAddInfo( p_item, "ID3",
                                            (char *)p_frame->description,
                                            psz_temp);
             }
@@ -150,13 +157,14 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
             {
                 input_AddInfo( p_category, (char *)p_frame->description,
                                             psz_temp );
-                playlist_AddItemInfo( p_item, "ID3",
+                playlist_ItemAddInfo( p_item, "ID3",
                                            (char *)p_frame->description,
                                            psz_temp);
             }
             free( psz_temp );
         }
         i++;
+        vlc_mutex_unlock( &p_item->lock );
     }
     id3_tag_delete( p_id3_tag );
     if(val.b_bool == VLC_TRUE )
index 15b43a9796fc23abd5fadc904ede28c9f690620c..33df88658bff6d670e6f3a864965df9503bdd757 100644 (file)
@@ -2,7 +2,7 @@
  * pda_callbacks.c : Callbacks for the pda Linux Gtk+ plugin.
  *****************************************************************************
  * Copyright (C) 2000, 2001 VideoLAN
- * $Id: pda_callbacks.c,v 1.25 2004/01/25 14:15:21 kuehne Exp $
+ * $Id: pda_callbacks.c,v 1.26 2004/01/29 17:51:07 zorglub Exp $
  *
  * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
  *
@@ -133,16 +133,10 @@ void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_
             else
 #endif
             {
-                i_id = playlist_Add( p_playlist, (const char*)name,
-                                (const char*)name,
-                              PLAYLIST_APPEND, PLAYLIST_END );
-
-                i_pos = playlist_GetPositionById( p_playlist, i_id );
-
-                for( i = 0 ; i< i_size ; i++ )
-                {
-                    playlist_AddOption( p_playlist, i_pos , ppsz_options[i] );
-                }
+                i_id = playlist_AddExt( p_playlist, (const char*)name,
+                              (const char*)name,
+                              PLAYLIST_APPEND, PLAYLIST_END,
+                              ppsz_options, i_pos );
             }
 
             /* Cleanup memory */
index 8dd78ba1adae8a2d64ccd5a462e832450ffb77fa..7230bafb1f1ef06833ce187dd5ff0753450aa6a2 100644 (file)
@@ -2,7 +2,7 @@
  * iteminfo.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2004 VideoLAN
- * $Id: iteminfo.cpp,v 1.7 2004/01/25 03:29:01 hartman Exp $
+ * $Id: iteminfo.cpp,v 1.8 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Clément Stenac <zorglub@videolan.org>
  *
@@ -178,7 +178,7 @@ wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
 
     author_text =
                    new wxTextCtrl( info_panel, Uri_Event,
-                                   wxU( playlist_GetItemInfo( p_item,
+                                   wxU( playlist_ItemGetInfo( p_item,
                                           _("General"), _("Author") ) ),
                                    wxDefaultPosition, wxSize( 300, -1 ),
                                    wxTE_PROCESS_ENTER);
@@ -305,9 +305,10 @@ void ItemInfoDialog::UpdateInfo()
  *****************************************************************************/
 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
 {
+    vlc_mutex_lock( &p_item->lock );
     p_item->psz_name = strdup( name_text->GetLineText(0).mb_str() );
     p_item->psz_uri = strdup( uri_text->GetLineText(0).mb_str() );
-    playlist_AddItemInfo( p_item,"General","Author",
+    playlist_ItemAddInfo( p_item,"General","Author",
                             author_text->GetLineText(0).mb_str() );
     vlc_bool_t b_old_enabled = p_item->b_enabled;
 
@@ -335,6 +336,7 @@ void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
     }
 
     p_item->b_enabled = enabled_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE ;
+    vlc_mutex_unlock( &p_item->lock );
     EndModal( wxID_OK );
 }
 
index 7bc0f9c09bcd3460e803e2c61dff936ab58a6302..4aade5b9dd558c7ad8b9d56590404f023e7d8815 100644 (file)
@@ -2,7 +2,7 @@
  * open.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2004 VideoLAN
- * $Id: open.cpp,v 1.66 2004/01/26 22:10:20 gbazin Exp $
+ * $Id: open.cpp,v 1.67 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -890,11 +890,10 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
     for( int i = 0; i < (int)mrl.GetCount(); i++ )
     {
         int i_options = 0;
-
-        int i_id = playlist_Add( p_playlist, (const char *)mrl[i].mb_str(),
-                      (const char *)mrl[i].mb_str(),
-                      PLAYLIST_APPEND, PLAYLIST_END );
-        playlist_item_t *p_item = playlist_GetItemById( p_playlist , i_id );
+        playlist_item_t *p_item =
+                  playlist_ItemNew( p_intf,
+                                    (const char*)mrl[i].mb_str(),
+                                    (const char *)mrl[i].mb_str() );
 
         /* Count the input options */
         while( i + i_options + 1 < (int)mrl.GetCount() &&
@@ -906,7 +905,7 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
         /* Insert options */
         for( int j = 0; j < i_options; j++ )
         {
-            playlist_AddItemOption( p_item, mrl[i + j  + 1].mb_str() );
+            playlist_ItemAddOption( p_item, mrl[i + j  + 1].mb_str() );
         }
 
         /* Get the options from the subtitles dialog */
@@ -914,7 +913,7 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
         {
             for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
             {
-                playlist_AddItemOption( p_item, subsfile_mrl[j].mb_str() );
+                playlist_ItemAddOption( p_item, subsfile_mrl[j].mb_str() );
             }
         }
 
@@ -923,10 +922,13 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
         {
             for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
             {
-                playlist_AddItemOption( p_item, sout_mrl[j].mb_str() );
+                playlist_ItemAddOption( p_item, sout_mrl[j].mb_str() );
             }
         }
 
+       int i_id = playlist_AddItem( p_playlist, p_item,
+                      PLAYLIST_APPEND, PLAYLIST_END );
+
         if( !i && i_open_arg )
         {
             int i_pos = playlist_GetPositionById( p_playlist , i_id );
index 12a626680dcc05763547a53cd1e94a1099eaeb18..5966383fe9d7458389ea9b0dba412e25f0091240 100644 (file)
@@ -2,7 +2,7 @@
  * playlist.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2004 VideoLAN
- * $Id: playlist.cpp,v 1.39 2004/01/25 03:29:01 hartman Exp $
+ * $Id: playlist.cpp,v 1.40 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *
@@ -405,24 +405,29 @@ void Playlist::UpdateItem( int i )
     playlist_t *p_playlist =
         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                        FIND_ANYWHERE );
+
     if( p_playlist == NULL )
     {
         return;
     }
-    if( i < 0 || i >= p_playlist->i_size || !p_playlist->pp_items[i] )
+
+    playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
+
+    if( !p_item )
     {
         vlc_object_release(p_playlist);
         return;
     }
-    listview->SetItem( i, 0, wxL2U(p_playlist->pp_items[i]->psz_name) );
-    listview->SetItem( i, 1, wxU( playlist_GetInfo( p_playlist, i,
+
+    listview->SetItem( i, 0, wxL2U(p_item->psz_name) );
+    listview->SetItem( i, 1, wxU( playlist_ItemGetInfo( p_item,
                                        _("General") , _("Author") ) ) );
     char *psz_group = playlist_FindGroup(p_playlist,
-                                         p_playlist->pp_items[i]->i_group);
+                                         p_item->i_group);
     listview->SetItem( i, 2,
              wxL2U( psz_group ? psz_group : _("Normal") ) );
 
-    if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
+    if( p_item->b_enabled == VLC_FALSE )
     {
         wxListItem listitem;
         listitem.m_itemId = i;
@@ -431,7 +436,7 @@ void Playlist::UpdateItem( int i )
     }
 
     char psz_duration[MSTRTIME_MAX_SIZE];
-    mtime_t dur = p_playlist->pp_items[i]->i_duration;
+    mtime_t dur = p_item->i_duration;
     if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
     else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
     listview->SetItem( i, 3, wxU(psz_duration) );
@@ -611,9 +616,9 @@ void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
                                  formats[dialog.GetFilterIndex()].psz_module );
             }
         }
-        
+
         vlc_object_release( p_playlist );
-        
+
     }
 }
 
@@ -900,6 +905,7 @@ void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) )
     {
         if( listview->IsSelected( item ) )
         {
+            /*XXX*/
             playlist_Enable( p_playlist, item );
             UpdateItem( item );
         }
@@ -921,6 +927,7 @@ void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) )
     {
         if( listview->IsSelected( item ) )
         {
+            /*XXX*/
             playlist_Disable( p_playlist, item );
             UpdateItem( item );
         }
@@ -1021,10 +1028,14 @@ void Playlist::ShowInfos( int i_item )
     }
     if( iteminfo_dialog == NULL )
     {
-        if( i_item >= 0 && i_item < p_playlist->i_size )
+        vlc_mutex_lock( &p_playlist->object_lock);
+        playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
+        vlc_mutex_unlock( &p_playlist->object_lock );
+
+        if( p_item )
         {
             iteminfo_dialog = new ItemInfoDialog(
-                              p_intf, p_playlist->pp_items[i_item], this );
+                              p_intf, p_item , this );
             if( iteminfo_dialog->ShowModal()  == wxID_OK )
                 UpdateItem( i_item );
             delete iteminfo_dialog;
@@ -1060,6 +1071,7 @@ void Playlist::OnEnDis( wxCommandEvent& event )
        switch( event.GetId() )
        {
            case EnableGroup_Event:
+               /*XXX*/
                playlist_EnableGroup( p_playlist ,
                                   p_playlist->pp_items[i_item]->i_group );
                break;
@@ -1168,6 +1180,7 @@ int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
                  vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
     Playlist *p_playlist_dialog = (Playlist *)param;
+    fprintf(stderr,"Update item: %i\n",new_val.i_int);
     p_playlist_dialog->UpdateItem( new_val.i_int );
     return 0;
 }
index 7a40fb17279507513513015412717f4735413f68..450154da11688576deb21f2f0e5a6e4a9b270c20 100644 (file)
@@ -2,7 +2,7 @@
  * stream.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2004 VideoLAN
- * $Id: streamwizard.cpp,v 1.5 2004/01/25 03:29:01 hartman Exp $
+ * $Id: streamwizard.cpp,v 1.6 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Clément Stenac <zorglub@videolan.org>
  *
@@ -204,11 +204,9 @@ void StreamDialog::OnStart( wxCommandEvent& event )
 
     for( int i = 0; i < (int)p_open_dialog->mrl.GetCount(); i++ )
     {
-        int i_id = playlist_Add( p_playlist,
+        playlist_item_t *p_item = playlist_ItemNew( p_intf,
                       (const char *)p_open_dialog->mrl[i].mb_str(),
-                      (const char *)p_open_dialog->mrl[i].mb_str(),
-                      PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
-        int i_pos = playlist_GetPositionById( p_playlist, i_id );
+                      (const char *)p_open_dialog->mrl[i].mb_str() );
         int i_options = 0;
 
         /* Count the input options */
@@ -222,7 +220,7 @@ void StreamDialog::OnStart( wxCommandEvent& event )
         /* Insert options */
         for( int j = 0; j < i_options; j++ )
         {
-            playlist_AddOption( p_playlist, i_pos,
+            playlist_ItemAddOption( p_item ,
                                 p_open_dialog->mrl[i + j  + 1].mb_str() );
         }
 
@@ -231,18 +229,21 @@ void StreamDialog::OnStart( wxCommandEvent& event )
         {
             for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
             {
-                playlist_AddOption( p_playlist, i_pos ,
-                                    sout_mrl[j].mb_str() );
+                playlist_ItemAddOption( p_item , sout_mrl[j].mb_str() );
             }
         }
+
+         playlist_AddItem( p_playlist, p_item,
+                      PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
+
         msg_Dbg(p_intf,"playings %s",
                  (const char *)p_open_dialog->mrl[i].mb_str());
 
         i += i_options;
-   }
- vlc_object_release( p_playlist );
+    }
   vlc_object_release( p_playlist );
 
-  Hide();
+    Hide();
 }
 
 
index 6b72ef7588dccf018534960cec1a76dbc04e5cc6..f51503417d83572f3dd918e9bc3f3a9fa6751b50 100644 (file)
@@ -2,7 +2,7 @@
  * sap.c :  SAP interface module
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: sap.c,v 1.51 2004/01/25 18:53:07 gbazin Exp $
+ * $Id: sap.c,v 1.52 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Arnaud Schauly <gitan@via.ecp.fr>
  *          Clément Stenac <zorglub@via.ecp.fr>
@@ -647,6 +647,7 @@ static void sess_toitem( intf_thread_t * p_intf, sess_descr_t * p_sd )
     vlc_bool_t b_http = VLC_FALSE;
     char *psz_http_path = NULL;
     playlist_t *p_playlist = NULL;
+    playlist_item_t *p_item;
 
     psz_uri_default = NULL;
     if( p_sd->i_media > 1 )
@@ -670,8 +671,8 @@ static void sess_toitem( intf_thread_t * p_intf, sess_descr_t * p_sd )
                       PLAYLIST_CHECK_INSERT, PLAYLIST_END );
         if( i_id != -1 )
         {
-            i_pos = playlist_GetPositionById( p_playlist, i_id );
-            playlist_SetGroup( p_playlist, i_pos, p_intf->p_sys->i_group );
+            playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
+            playlist_ItemSetGroup( p_item, p_intf->p_sys->i_group );
         }
 
         /* Remember it */
@@ -838,7 +839,7 @@ static void sess_toitem( intf_thread_t * p_intf, sess_descr_t * p_sd )
                             p_sd->psz_sessionname,
                             psz_item_uri );
 
-                    p_item = playlist_GetItemById( p_playlist,
+                    p_item = playlist_ItemGetById( p_playlist,
                                     p_intf->p_sys->pp_announces[i]->i_id );
 
                     /* Change the name in the item */
@@ -864,8 +865,13 @@ static void sess_toitem( intf_thread_t * p_intf, sess_descr_t * p_sd )
         i_id = playlist_Add ( p_playlist, psz_item_uri ,
                                p_sd->psz_sessionname,
                                PLAYLIST_CHECK_INSERT, PLAYLIST_END );
-        i_pos = playlist_GetPositionById( p_playlist, i_id );
-        playlist_SetGroup( p_playlist, i_pos, i_group );
+        p_item = playlist_ItemGetById( p_playlist, i_id );
+        if( p_item )
+        {
+            vlc_mutex_lock( &p_item->lock );
+            playlist_ItemSetGroup( p_item, i_group );
+            vlc_mutex_unlock( &p_item->lock );
+        }
 
         /* Then remember it */
         p_announce = (struct sap_announce_t *)malloc(
index 0dc0c429c2d9006c4469c5e825d5d1ccf06a9cf8..6c3f827b640c2aa6c0444d7cc19f7d55f722bd21 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998-2004 VideoLAN
- * $Id: input.c,v 1.283 2004/01/26 23:37:05 hartman Exp $
+ * $Id: input.c,v 1.284 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -787,7 +787,7 @@ static int InitThread( input_thread_t * p_input )
         if( p_playlist )
         {
             playlist_SetDuration( p_playlist, -1 , i_length );
-            val.b_bool = VLC_TRUE;
+            val.b_bool = p_playlist->i_index;
             var_Set( p_playlist, "item-change", val );
             vlc_object_release( p_playlist );
         }
@@ -808,7 +808,7 @@ static int InitThread( input_thread_t * p_input )
     var_Get( p_input, "sub-file", &val );
     if( val.psz_string && *val.psz_string )
     {
-       msg_Dbg( p_input, "force subtitle: %s", val.psz_string );
+        msg_Dbg( p_input, "force subtitle: %s", val.psz_string );
         subtitle_demux_t *p_sub;
         if( ( p_sub = subtitle_New( p_input, strdup(val.psz_string),
                                     i_microsecondperframe ) ) )
index 95b84a64b106cf10f0321c2a82f8be9ebe25aeaf..e06d88c043b15fd8e0222830c1cc6a4e4602c741 100644 (file)
@@ -2,7 +2,7 @@
  * libvlc.c: main libvlc source
  *****************************************************************************
  * Copyright (C) 1998-2004 VideoLAN
- * $Id: libvlc.c,v 1.114 2004/01/29 14:39:08 sigmunau Exp $
+ * $Id: libvlc.c,v 1.115 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -801,7 +801,6 @@ int VLC_AddTarget( int i_object, char const *psz_target,
                    char const **ppsz_options, int i_options,
                    int i_mode, int i_pos )
 {
-    int i;
     int i_err;
     playlist_t *p_playlist;
     vlc_t *p_vlc = vlc_current_object( i_object );
@@ -827,13 +826,8 @@ int VLC_AddTarget( int i_object, char const *psz_target,
         vlc_object_yield( p_playlist );
     }
 
-    i_err = playlist_Add( p_playlist, psz_target, psz_target,
-                          i_mode, i_pos );
-
-    for( i = 0 ; i< i_options ; i++ )
-    {
-        playlist_AddOption( p_playlist, i_err , ppsz_options[i] );
-    }
+    i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
+                             i_mode, i_pos, -1, ppsz_options, i_options);
 
     vlc_object_release( p_playlist );
 
index e956f13697c12e015da75d08499f6c4db6536cc8..bcbf17a769e0d0c91d5f0116b1f4e26938be75db 100644 (file)
@@ -2,7 +2,7 @@
  * win32_specific.c: Win32 specific features
  *****************************************************************************
  * Copyright (C) 2001-2004 VideoLAN
- * $Id: win32_specific.c,v 1.32 2004/01/25 17:16:06 zorglub Exp $
+ * $Id: win32_specific.c,v 1.33 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Gildas Bazin <gbazin@netcourrier.com>
@@ -324,13 +324,8 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
                 i_id = playlist_Add( p_playlist, ppsz_argv[ i_opt ],
                               ppsz_argv[ i_opt ],
                               PLAYLIST_APPEND | (i_opt? 0 : PLAYLIST_GO),
-                              PLAYLIST_END );
-                i_pos = playlist_GetPositionById( p_playlist, i_id );
-                for( j = 0 ; j < i_options ; j++ )
-                {
-                    playlist_AddOption( p_playlist, i_pos ,
-                                        ppsz_argv[i_opt+1+j] );
-                }
+                              PLAYLIST_END, -1,
+                              ppsz_argv[i_opt+1], i_options );
                 i_opt += i_options;
             }
 
index d7023c15237e6ab85e524b45e434d1db18e17fea..2dd79357feb2eb002870a02b35243c654f0e5acc 100644 (file)
@@ -2,7 +2,7 @@
  * info.c : Playlist info management
  *****************************************************************************
  * Copyright (C) 1999-2004 VideoLAN
- * $Id: info.c,v 1.7 2004/01/25 17:16:06 zorglub Exp $
+ * $Id: info.c,v 1.8 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Clément Stenac <zorglub@videolan.org>
  *
@@ -32,6 +32,7 @@
 
 /**
  * Get one special info
+ * Must be entered with playlist lock
  *
  * \param p_playlist the playlist to get the info from
  * \param i_item position of the item on
  * \param psz_name the name of the info
  * \return the info value if any, an empty string else
 */
-char * playlist_GetInfo( playlist_t *p_playlist, int i_item,
+char * playlist_GetInfo( playlist_t *p_playlist, int i_pos,
                          const char * psz_cat, const char *psz_name )
 {
+    playlist_item_t *p_item;
+    char *psz_buffer;
     /* Check the existence of the playlist */
     if( p_playlist == NULL)
     {
         return strdup("");
     }
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
-    {
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        i_item = p_playlist->i_index;
-    }
-    else
+    p_item = playlist_ItemGetByPos( p_playlist, i_pos );
+    if( !p_item )
     {
         return strdup("");
     }
-    return playlist_GetItemInfo( p_playlist->pp_items[i_item] , psz_cat,
-                                 psz_name );
+    vlc_mutex_lock( &p_item->lock );
+    psz_buffer = playlist_ItemGetInfo( p_item ,
+                                       psz_cat, psz_name );
+    vlc_mutex_unlock( &p_item->lock );
+
+    return psz_buffer;
 }
 
 /**
@@ -72,7 +72,7 @@ char * playlist_GetInfo( playlist_t *p_playlist, int i_item,
  * \param psz_name the name of the info
  * \return the info value if any, an empty string else
 */
-char * playlist_GetItemInfo( playlist_item_t *p_item,
+char * playlist_ItemGetInfo( playlist_item_t *p_item,
                       const char * psz_cat, const char *psz_name )
 {
      int i,j ;
@@ -104,29 +104,21 @@ char * playlist_GetItemInfo( playlist_item_t *p_item,
  * \return the info category.
  */
 item_info_category_t *
-playlist_GetCategory( playlist_t *p_playlist, int i_item,
+playlist_GetCategory( playlist_t *p_playlist, int i_pos,
                       const char * psz_cat )
 {
+    playlist_item_t *p_item;
     /* Check the existence of the playlist */
     if( p_playlist == NULL)
     {
         return NULL;
     }
-
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
-    {
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        i_item = p_playlist->i_index;
-    }
-    else
+    p_item=  playlist_ItemGetByPos( p_playlist , i_pos );
+    if( !p_item )
     {
         return NULL;
     }
-
-    return playlist_GetItemCategory( p_playlist->pp_items[i_item] , psz_cat );
+    return playlist_ItemGetCategory( p_item , psz_cat );
 }
 
 /**
@@ -136,7 +128,7 @@ playlist_GetCategory( playlist_t *p_playlist, int i_item,
  * \param psz_cat the category we want
  * \return the info category.
  */
-item_info_category_t *playlist_GetItemCategory( playlist_item_t *p_item,
+item_info_category_t *playlist_ItemGetCategory( playlist_item_t *p_item,
                                                 const char *psz_cat )
 {
     int i;
@@ -151,7 +143,7 @@ item_info_category_t *playlist_GetItemCategory( playlist_item_t *p_item,
     }
 
     /* We did not find the category, create it */
-    return playlist_CreateItemCategory( p_item, psz_cat );
+    return playlist_ItemCreateCategory( p_item, psz_cat );
 }
 
 
@@ -165,7 +157,7 @@ item_info_category_t *playlist_GetItemCategory( playlist_item_t *p_item,
  * \return the info category.
  */
 item_info_category_t *
-playlist_CreateCategory( playlist_t *p_playlist, int i_item,
+playlist_CreateCategory( playlist_t *p_playlist, int i_pos,
                          const char * psz_cat )
 {
     playlist_item_t *p_item = NULL;
@@ -175,22 +167,13 @@ playlist_CreateCategory( playlist_t *p_playlist, int i_item,
     {
         return NULL;
     }
-
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
-    {
-        p_item = p_playlist->pp_items[i_item];
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        p_item = p_playlist->pp_items[p_playlist->i_index];
-    }
-    else
+    p_item = playlist_ItemGetByPos( p_playlist , i_pos );
+    if( !p_item )
     {
         return NULL;
     }
 
-    return playlist_CreateItemCategory( p_item, psz_cat );
+    return playlist_ItemCreateCategory( p_item, psz_cat );
 }
 
 /**
@@ -202,7 +185,7 @@ playlist_CreateCategory( playlist_t *p_playlist, int i_item,
  * \return the info category.
  */
 item_info_category_t *
-playlist_CreateItemCategory( playlist_item_t *p_item, const char *psz_cat )
+playlist_ItemCreateCategory( playlist_item_t *p_item, const char *psz_cat )
 {
     item_info_category_t *p_cat;
     int i;
@@ -257,25 +240,19 @@ int playlist_AddInfo( playlist_t *p_playlist, int i_item,
         return VLC_EGENERIC;
     }
 
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
-    {
-        p_item = p_playlist->pp_items[i_item];
-    }
-    else if( p_playlist->i_size > 0 )
+    p_item = playlist_ItemGetByPos( p_playlist, i_item );
+    if( !p_item )
     {
-        p_item = p_playlist->pp_items[p_playlist->i_index];
-    }
-    else
-    {
-        return VLC_EGENERIC;
+            return VLC_ENOOBJ;
     }
 
     va_start( args, psz_format );
     vasprintf( &psz_value, psz_format, args );
     va_end( args );
 
-    i_ret = playlist_AddItemInfo( p_item , psz_cat , psz_name , psz_value );
+    vlc_mutex_lock( &p_item->lock );
+    i_ret = playlist_ItemAddInfo( p_item , psz_cat , psz_name , psz_value );
+    vlc_mutex_unlock( &p_item->lock );
 
     free( psz_value );
     return i_ret;
@@ -291,7 +268,7 @@ int playlist_AddInfo( playlist_t *p_playlist, int i_item,
  * \param psz_format printf-style info
  * \return VLC_SUCCESS on success
 */
-int playlist_AddItemInfo( playlist_item_t *p_item,
+int playlist_ItemAddInfo( playlist_item_t *p_item,
                       const char *psz_cat, const char *psz_name,
                       const char *psz_format, ... )
 {
@@ -302,7 +279,7 @@ int playlist_AddItemInfo( playlist_item_t *p_item,
     item_info_category_t *p_cat;
 
     /* Find or create the category */
-    p_cat = playlist_GetItemCategory( p_item, psz_cat );
+    p_cat = playlist_ItemGetCategory( p_item, psz_cat );
     if( p_cat == NULL)
     {
         return VLC_EGENERIC;
@@ -358,12 +335,10 @@ int playlist_AddItemInfo( playlist_item_t *p_item,
  * \param psz_value the option to add
  * \return the info category.
  */
-int playlist_AddOption( playlist_t *p_playlist, int i_item,
-                        const char * psz_format, ...)
+int playlist_AddOption( playlist_t *p_playlist, int i_pos,
+                        const char *psz_option)
 {
-    va_list args;
-    item_info_t *p_info = NULL;
-    item_info_category_t *p_cat;
+    playlist_item_t *p_item;
 
     /* Check the existence of the playlist */
     if( p_playlist == NULL)
@@ -371,39 +346,18 @@ int playlist_AddOption( playlist_t *p_playlist, int i_item,
         return VLC_EGENERIC;
     }
 
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
-    {
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        i_item = p_playlist->i_index;
-    }
-    else
-    {
-        return VLC_EGENERIC;
-    }
-
-    p_cat = playlist_GetCategory( p_playlist, i_item , _("Options") );
-
-    if( p_cat == NULL)
-    {
-        return VLC_EGENERIC;
-    }
-
-    if( ( p_info = malloc( sizeof( item_info_t) ) ) == NULL )
+    p_item = playlist_ItemGetByPos( p_playlist , i_pos );
+    if( !p_item )
     {
-        msg_Err( p_playlist, "out of memory" );
-        return VLC_EGENERIC;
+            return VLC_ENOOBJ;
     }
 
-    p_info->psz_name = strdup( "option" );
-
-    va_start( args, psz_format );
-    vasprintf( &p_info->psz_value, psz_format, args );
-    va_end( args );
-
-    INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
+    vlc_mutex_lock( &p_item->lock );
+    INSERT_ELEM( p_item->ppsz_options,
+                 p_item->i_options,
+                 p_item->i_options,
+                 (char *)psz_option );
+    vlc_mutex_unlock( &p_item->lock );
 
     return VLC_SUCCESS;
 }
@@ -415,31 +369,13 @@ int playlist_AddOption( playlist_t *p_playlist, int i_item,
  * \param psz_format the option
  * \return 0 on success
 */
-int playlist_AddItemOption( playlist_item_t *p_item,
-                            const char *psz_format, ... )
+int playlist_ItemAddOption( playlist_item_t *p_item,
+                            const char *psz_option )
 {
-    va_list args;
-    item_info_t *p_info = NULL;
-    item_info_category_t *p_cat;
-
-    p_cat = playlist_GetItemCategory( p_item, _("Options") );
-    if( p_cat == NULL)
-    {
-        return VLC_EGENERIC;
-    }
-
-    if( ( p_info = malloc( sizeof( item_info_t) ) ) == NULL )
-    {
-        return VLC_EGENERIC;
-    }
-
-    p_info->psz_name = strdup( "option" );
-
-    va_start( args, psz_format );
-    vasprintf( &p_info->psz_value, psz_format, args );
-    va_end( args );
-
-    INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
+    INSERT_ELEM( p_item->ppsz_options,
+                 p_item->i_options,
+                 p_item->i_options,
+                 (char *)psz_option);
 
     return VLC_SUCCESS;
 }
index 19e6b2bab47bc16a26b8f9ede23a41a4813e3d19..a6c4d3560bc7887c947008a70511f117f71af809 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * item-ext.c : Exported playlist item functions
+ * item-ext.c : Playlist item management functions
  *****************************************************************************
  * Copyright (C) 1999-2004 VideoLAN
- * $Id: item-ext.c,v 1.12 2004/01/25 17:16:06 zorglub Exp $
+ * $Id: item-ext.c,v 1.13 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Clément Stenac <zorglub@videolan.org>
 
 #include "vlc_playlist.h"
 
+/***************************************************************************
+ * Item creation/addition functions
+ ***************************************************************************/
+
 /**
- * Add a MRL into the playlist, duration given.
+ * Add a MRL into the playlist, duration and options given
  *
  * \param p_playlist the playlist to add into
  * \param psz_uri the mrl to add to the playlist
  *        PLAYLIST_END the item will be added at the end of the playlist
  *        regardless of it's size
  * \param i_duration length of the item in milliseconds.
+ * \param ppsz_options an array of options
+ * \param i_options the number of options
  * \return The id of the playlist item
 */
-int playlist_AddWDuration( playlist_t *p_playlist, const char * psz_uri,
-                           const char *psz_name, int i_mode, int i_pos,
-                           mtime_t i_duration )
+int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
+                     const char *psz_name, int i_mode, int i_pos,
+                     mtime_t i_duration, const char **ppsz_options,
+                     int i_options )
+{
+    playlist_item_t * p_item = playlist_ItemNew( p_playlist , psz_uri, psz_name );
+
+    if( p_item == NULL )
+    {
+        msg_Err( p_playlist, "unable to add item to playlist" );
+        return -1;
+    }
+
+    p_item->i_duration = i_duration;
+    p_item->ppsz_options = (char **)ppsz_options;
+    p_item->i_options  = i_options;
+
+    return playlist_AddItem( p_playlist, p_item, i_mode, i_pos );
+}
+
+/**
+ * Add a MRL into the playlist.
+ *
+ * \param p_playlist the playlist to add into
+ * \param psz_uri the mrl to add to the playlist
+ * \param psz_name a text giving a name or description of this item
+ * \param i_mode the mode used when adding
+ * \param i_pos the position in the playlist where to add. If this is
+ *        PLAYLIST_END the item will be added at the end of the playlist
+ *        regardless of it's size
+ * \return The id of the playlist item
+*/
+int playlist_Add( playlist_t *p_playlist, const char * psz_uri,
+                     const char *psz_name, int i_mode, int i_pos )
+{
+    return playlist_AddExt ( p_playlist, psz_uri, psz_name, i_mode, i_pos,
+                            -1, NULL, 0 );
+}
+
+/**
+ * Create a new item, without adding it to the playlist
+ *
+ * \param psz_uri the mrl of the 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 )
 {
     playlist_item_t * p_item;
 
     p_item = malloc( sizeof( playlist_item_t ) );
     if( p_item == NULL )
     {
-        msg_Err( p_playlist, "out of memory" );
+        return NULL;
     }
     if( psz_uri == NULL)
     {
-        msg_Err( p_playlist, "Not adding NULL item");
-        return -1;
+        return NULL;
     }
     memset( p_item, 0, sizeof( playlist_item_t ) );
     p_item->psz_uri    = strdup( psz_uri );
@@ -72,34 +123,82 @@ int playlist_AddWDuration( playlist_t *p_playlist, const char * psz_uri,
     }
     p_item->b_enabled = VLC_TRUE;
     p_item->i_group = PLAYLIST_TYPE_MANUAL;
-    p_item->i_duration = i_duration;
 
-    playlist_CreateItemCategory( p_item, _("General") );
-    playlist_CreateItemCategory( p_item, _("Options") );
-    return playlist_AddItem( p_playlist, p_item, i_mode, i_pos );
+    p_item->i_duration = -1;
+    p_item->ppsz_options = NULL;
+    p_item->i_options = 0;
+
+    vlc_mutex_init( p_obj->p_vlc , &p_item->lock );
+
+    playlist_ItemCreateCategory( p_item, _("General") );
+    return p_item;
 }
 
 /**
- * Add a MRL into the playlist.
+ * Deletes a playlist item
  *
- * \param p_playlist the playlist to add into
- * \param psz_uri the mrl to add to the playlist
- * \param psz_name a text giving a name or description of this item
- * \param i_mode the mode used when adding
- * \param i_pos the position in the playlist where to add. If this is
- *        PLAYLIST_END the item will be added at the end of the playlist
- *        regardless of it's size
- * \return The id of the playlist item
-*/
-int playlist_Add( playlist_t *p_playlist, const char * psz_uri,
-                     const char *psz_name, int i_mode, int i_pos )
+ * \param p_item the item to delete
+ * \return nothing
+ */
+void playlist_ItemDelete( playlist_item_t *p_item)
 {
-  return playlist_AddWDuration ( p_playlist, psz_uri, psz_name, i_mode, i_pos,
-                                 -1 );
+    int i,j;
+
+    vlc_mutex_lock( &p_item->lock );
+
+    if( p_item->psz_name )
+    {
+        free( p_item->psz_name );
+    }
+    if( p_item->psz_uri )
+    {
+        free( p_item->psz_uri );
+    }
+
+    /* Free the info categories. Welcome to the segfault factory */
+    if( p_item->i_categories > 0 )
+    {
+        for( i = 0; i < p_item->i_categories; i++ )
+        {
+            for( j= 0 ; j < p_item->pp_categories[i]->i_infos; j++)
+            {
+                if( p_item->pp_categories[i]->pp_infos[j]->psz_name)
+                {
+                    free( p_item->pp_categories[i]->
+                                  pp_infos[j]->psz_name);
+                }
+                if( p_item->pp_categories[i]->pp_infos[j]->psz_value)
+                {
+                    free( p_item->pp_categories[i]->
+                                  pp_infos[j]->psz_value);
+                }
+                free( p_item->pp_categories[i]->pp_infos[j] );
+            }
+            if( p_item->pp_categories[i]->i_infos )
+                free( p_item->pp_categories[i]->pp_infos );
+            if( p_item->pp_categories[i]->psz_name)
+            {
+                free( p_item->pp_categories[i]->psz_name );
+            }
+            free( p_item->pp_categories[i] );
+       }
+       free( p_item->pp_categories );
+   }
+
+    vlc_mutex_unlock( &p_item->lock );
+    vlc_mutex_destroy( &p_item->lock );
+
+    free( p_item );
 }
 
+/***************************************************************************
+ * Item search functions
+ ***************************************************************************/
+
 /**
  * Search the position of an item by its id
+ * This function must be entered with the playlist lock
+ *
  * \param p_playlist the playlist
  * \param i_id the id to find
  * \return the position, or VLC_EGENERIC on failure
@@ -120,11 +219,12 @@ int playlist_GetPositionById( playlist_t * p_playlist , int i_id )
 
 /**
  * Search an item by its id
+ *
  * \param p_playlist the playlist
  * \param i_id the id to find
  * \return the item, or NULL on failure
  */
-playlist_item_t * playlist_GetItemById( playlist_t * p_playlist , int i_id )
+playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id )
 {
     int i;
     for( i =  0 ; i < p_playlist->i_size ; i++ )
@@ -137,6 +237,30 @@ playlist_item_t * playlist_GetItemById( playlist_t * p_playlist , int i_id )
     return NULL;
 }
 
+/**
+ * Search an item by its position
+ * This function must be entered with the playlist lock
+ *
+ * \param p_playlist the playlist
+ * \param i_id the id to find
+ * \return the item, or NULL on failure
+ */
+playlist_item_t * playlist_ItemGetByPos( playlist_t * p_playlist , int i_pos )
+{
+    if( i_pos >= 0 && i_pos < p_playlist->i_size)
+    {
+        return p_playlist->pp_items[i_pos];
+    }
+    else if( p_playlist->i_size > 0)
+    {
+        return p_playlist->pp_items[p_playlist->i_index];
+    }
+    else
+    {
+        return NULL;
+    }
+}
+
 /**********************************************************************
  * playlist_item_t structure accessors
  * These functions give access to the fields of the playlist_item_t
@@ -146,6 +270,20 @@ playlist_item_t * playlist_GetItemById( playlist_t * p_playlist , int i_id )
 /**
  * Set the group of a playlist item
  *
+ * \param p_item the item
+ * \return VLC_SUCCESS on success
+ */
+int playlist_ItemSetGroup( playlist_item_t *p_item, int i_group)
+{
+    p_item->i_group = i_group;
+    return VLC_SUCCESS;
+}
+
+/**
+ * Set the group of a playlist item (by position)
+ * This function must be entered with the playlist lock
+ * Legacy function due to disappear (locks the whole playlist)
+ *
  * \param p_playlist the playlist
  * \param i_pos the postition of the item of which we change the group
  * \param i_group the new group
@@ -153,36 +291,24 @@ playlist_item_t * playlist_GetItemById( playlist_t * p_playlist , int i_id )
  */
 int playlist_SetGroup( playlist_t *p_playlist, int i_pos, int i_group )
 {
-    char *psz_group;
     vlc_value_t val;
-    /* Check the existence of the playlist */
-    if( p_playlist == NULL)
+    playlist_item_t *p_item;
+    if( !p_playlist )
     {
-        return VLC_EGENERIC;
+        return VLC_ENOOBJ;
     }
 
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    /* Get a correct item */
-    if( i_pos >= 0 && i_pos < p_playlist->i_size )
+    p_item = playlist_ItemGetByPos( p_playlist , i_pos );
+    if( !p_item )
     {
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        i_pos = p_playlist->i_index;
-    }
-    else
-    {
-        return VLC_EGENERIC;
+        return VLC_ENOOBJ;
     }
 
-    psz_group = playlist_FindGroup( p_playlist , i_group );
-    if( psz_group != NULL)
-    {
-        p_playlist->pp_items[i_pos]->i_group = i_group ;
-    }
-    vlc_mutex_unlock( &p_playlist->object_lock );
-    val.b_bool = i_pos;
+    vlc_mutex_lock( &p_item->lock );
+    playlist_ItemSetGroup( p_item , i_group );
+    vlc_mutex_unlock( &p_item->lock );
+
+    val.b_bool = (i_pos >= 0 && i_pos < p_playlist->i_size ) ? i_pos : -1;
     var_Set( p_playlist, "item-change", val );
 
     return VLC_SUCCESS;
@@ -191,6 +317,25 @@ int playlist_SetGroup( playlist_t *p_playlist, int i_pos, int i_group )
 /**
  * Set the name of a playlist item
  *
+ * \param p_item the item
+ * \param psz_name the new name
+ * \return VLC_SUCCESS on success, VLC_EGENERIC on failure
+ */
+int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name )
+{
+    if( psz_name && p_item )
+    {
+        p_item->psz_name = strdup( psz_name );
+        return VLC_SUCCESS;
+    }
+    return VLC_EGENERIC;
+}
+
+/**
+ * Set the name of a playlist item (by position)
+ * This function must be entered with the playlist lock
+ * Legacy function due to disappear (locks the whole playlist)
+ *
  * \param p_playlist the playlist
  * \param i_pos the position of the item of which we change the name
  * \param psz_name the new name
@@ -199,43 +344,62 @@ int playlist_SetGroup( playlist_t *p_playlist, int i_pos, int i_group )
 int playlist_SetName( playlist_t *p_playlist, int i_pos, char *psz_name )
 {
     vlc_value_t val;
-
-    /* Check the existence of the playlist */
-    if( p_playlist == NULL)
+    playlist_item_t *p_item;
+    if( !p_playlist )
     {
-        return VLC_EGENERIC;
+        return VLC_ENOOBJ;
     }
 
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    /* Get a correct item */
-    if( i_pos >= 0 && i_pos < p_playlist->i_size )
+    p_item = playlist_ItemGetByPos( p_playlist , i_pos );
+    if( !p_item )
     {
+        return VLC_ENOOBJ;
     }
-    else if( p_playlist->i_size > 0 )
-    {
-        i_pos = p_playlist->i_index;
-    }
-    else
-    {
-        return VLC_EGENERIC;
-    }
-
-    if( p_playlist->pp_items[i_pos]->psz_name)
-        free( p_playlist->pp_items[i_pos]->psz_name );
 
-    if( psz_name )
-        p_playlist->pp_items[i_pos]->psz_name = strdup( psz_name );
-
-    vlc_mutex_unlock( &p_playlist->object_lock );
+    vlc_mutex_lock( &p_item->lock );
+    playlist_ItemSetName( p_item , psz_name );
+    vlc_mutex_unlock( &p_item->lock );
 
-    val.b_bool = i_pos;
+    val.b_bool = (i_pos >= 0 && i_pos < p_playlist->i_size ) ? i_pos : -1;
     var_Set( p_playlist, "item-change", val );
+
     return VLC_SUCCESS;
 }
 
 /**
  * Set the duration of a playlist item
+ * This function must be entered with the item lock
+ *
+ * \param p_item the item
+ * \param psz_name the new name
+ * \return VLC_SUCCESS on success, VLC_EGENERIC on failure
+ */
+int playlist_ItemSetDuration( playlist_item_t *p_item, mtime_t i_duration )
+{
+    char psz_buffer[MSTRTIME_MAX_SIZE];
+    if( p_item )
+    {
+        p_item->i_duration = i_duration;
+        if( i_duration != -1 )
+        {
+            secstotimestr( psz_buffer, i_duration/1000000 );
+        }
+        else
+        {
+            memcpy( psz_buffer, "--:--:--", sizeof("--:--:--") );
+        }
+        playlist_ItemAddInfo( p_item, _("General") , _("Duration"),
+                      "%s", psz_buffer );
+
+        return VLC_SUCCESS;
+    }
+    return VLC_EGENERIC;
+}
+
+/**
+ * Set the duration of a playlist item
+ * This function must be entered with the playlist lock
+ * Legacy function due to disappear (locks the whole playlist)
  *
  * \param p_playlist the playlist
  * \param i_pos the position of the item of which we change the duration
@@ -244,46 +408,26 @@ int playlist_SetName( playlist_t *p_playlist, int i_pos, char *psz_name )
  */
 int playlist_SetDuration( playlist_t *p_playlist, int i_pos, mtime_t i_duration )
 {
-    char psz_buffer[MSTRTIME_MAX_SIZE];
     vlc_value_t val;
-
-    /* Check the existence of the playlist */
-    if( p_playlist == NULL)
-    {
-        return VLC_EGENERIC;
-    }
-
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    /* Get a correct item */
-    if( i_pos >= 0 && i_pos < p_playlist->i_size )
-    {
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        i_pos = p_playlist->i_index;
-    }
-    else
+    playlist_item_t *p_item;
+    if( !p_playlist )
     {
-        return VLC_EGENERIC;
+        return VLC_ENOOBJ;
     }
 
-    p_playlist->pp_items[i_pos]->i_duration = i_duration;
-    if( i_duration != -1 )
-    {
-        secstotimestr( psz_buffer, i_duration/1000000 );
-    }
-    else
+    p_item = playlist_ItemGetByPos( p_playlist , i_pos );
+    if( !p_item )
     {
-        memcpy( psz_buffer, "--:--:--", sizeof("--:--:--") );
+        return VLC_ENOOBJ;
     }
-    playlist_AddInfo( p_playlist, i_pos, _("General") , _("Duration"),
-                      "%s", psz_buffer );
 
-    vlc_mutex_unlock( &p_playlist->object_lock );
+    vlc_mutex_lock( &p_item->lock );
+    playlist_ItemSetDuration( p_item , i_duration );
+    vlc_mutex_unlock( &p_item->lock );
 
-    val.b_bool = i_pos;
+    val.b_bool = (i_pos >= 0 && i_pos < p_playlist->i_size ) ? i_pos : -1;
     var_Set( p_playlist, "item-change", val );
+
     return VLC_SUCCESS;
 }
 
@@ -303,9 +447,11 @@ int playlist_Delete( playlist_t * p_playlist, int i_pos )
 {
     vlc_value_t     val;
     int i,j;
+    int i_delay=0;
 
     /* if i_pos is the current played item, playlist should stop playing it */
-    if( ( p_playlist->i_status == PLAYLIST_RUNNING) && (p_playlist->i_index == i_pos) )
+    if( ( p_playlist->i_status == PLAYLIST_RUNNING) &&
+                    (p_playlist->i_index == i_pos) )
     {
         playlist_Command( p_playlist, PLAYLIST_STOP, 0 );
     }
@@ -317,6 +463,8 @@ int playlist_Delete( playlist_t * p_playlist, int i_pos )
 
         msg_Dbg( p_playlist, "deleting playlist item « %s »",
                  p_item->psz_name );
+#if 0
+        vlc_mutex_lock( &p_item->lock );
 
         if( p_item->psz_name )
         {
@@ -359,8 +507,11 @@ int playlist_Delete( playlist_t * p_playlist, int i_pos )
         }
 
         /* XXX: what if the item is still in use? */
+#endif
+        playlist_ItemDelete( p_item );
+#if 0
         free( p_item );
-
+#endif
         if( i_pos <= p_playlist->i_index )
         {
             p_playlist->i_index--;
@@ -382,8 +533,6 @@ int playlist_Delete( playlist_t * p_playlist, int i_pos )
     return 0;
 }
 
-
-
 /**
  * Clear all playlist items
  *
index f49bde3c8603f5918b5eb9502049f13ab358186e..1ede7578aab809cb08866d02a0b05490aedbc9f1 100644 (file)
@@ -2,7 +2,7 @@
  * item.c : Playlist item functions
  *****************************************************************************
  * Copyright (C) 1999-2004 VideoLAN
- * $Id: item.c,v 1.12 2004/01/17 14:08:37 sigmunau Exp $
+ * $Id: item.c,v 1.13 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
 
 #include "vlc_playlist.h"
 
+
+
+
+
 /**
  * Add a playlist item into a playlist
  *
index 630bd4badac9b8f6e92966413b9b6fcb53ef93f6..d85defcd654141be581685bd80c320f88765ee12 100644 (file)
@@ -2,7 +2,7 @@
  * loadsave.c : Playlist loading / saving functions
  *****************************************************************************
  * Copyright (C) 1999-2004 VideoLAN
- * $Id: loadsave.c,v 1.9 2004/01/25 17:16:06 zorglub Exp $
+ * $Id: loadsave.c,v 1.10 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -64,7 +64,7 @@ int playlist_Import( playlist_t * p_playlist, const char *psz_filename )
     i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
                   PLAYLIST_INSERT | PLAYLIST_GO , PLAYLIST_END);
 
-    p_item = playlist_GetItemById( p_playlist, i_id );
+    p_item = playlist_ItemGetById( p_playlist, i_id );
     p_item->b_autodeletion = VLC_TRUE;
 
     vlc_mutex_unlock( &p_playlist->object_lock );
index 29bdb7403dd89c8c83341c44f3679cbe4ec43980..e559d22926a3e4c8518bc2084e6ec96ddbfeec9e 100644 (file)
@@ -2,7 +2,7 @@
  * playlist.c : Playlist management functions
  *****************************************************************************
  * Copyright (C) 1999-2004 VideoLAN
- * $Id: playlist.c,v 1.78 2004/01/26 23:30:18 fenrir Exp $
+ * $Id: playlist.c,v 1.79 2004/01/29 17:51:08 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -567,8 +567,6 @@ static void SkipItem( playlist_t *p_playlist, int i_arg )
 static void PlayItem( playlist_t *p_playlist )
 {
     playlist_item_t *p_item;
-    char            **ppsz_options;
-    int             i_options;
     int             i, j;
     vlc_value_t val;
     if( p_playlist->i_index == -1 )
@@ -587,37 +585,12 @@ static void PlayItem( playlist_t *p_playlist )
     msg_Dbg( p_playlist, "creating new input thread" );
     p_item = p_playlist->pp_items[p_playlist->i_index];
 
-    i_options    = 0;
-    ppsz_options = NULL;
-
-    /* Beurk, who the hell have done that ???????, why moving options
-     * to playlist in a such *bad* way ? --fenrir_is_asking ...*/
-    /* Parse input options */
-    for( i = 0 ; i < p_item->i_categories ; i++ )
-    {
-        if( !strcmp( p_item->pp_categories[i]->psz_name, _("Options") ) )
-        {
-            msg_Dbg( p_playlist, "Parsing %i options for item", p_item->pp_categories[i]->i_infos );
-            for( j = 0; j< p_item->pp_categories[i]->i_infos ; j++ )
-            {
-                msg_Dbg( p_playlist, "Option : %s",
-                         p_item->pp_categories[i]->pp_infos[j]->psz_value );
-                TAB_APPEND( i_options, ppsz_options,
-                            p_item->pp_categories[i]->pp_infos[j]->psz_value );
-            }
-            break;
-        }
-    }
+    p_item->i_nb_played++;
 
     p_playlist->p_input = input_CreateThread( p_playlist, p_item->psz_uri,
-                                              ppsz_options, i_options );
-
-    if( ppsz_options )
-    {
-        free( ppsz_options );
-    }
+                                              p_item->ppsz_options,
+                                              p_item->i_options );
 
     val.i_int = p_playlist->i_index;
     var_Set( p_playlist, "playlist-current", val);
 }
-