* Start cleaning up libvlc playlist API (Refs:#457)
authorClément Stenac <zorglub@videolan.org>
Tue, 20 Feb 2007 07:29:54 +0000 (07:29 +0000)
committerClément Stenac <zorglub@videolan.org>
Tue, 20 Feb 2007 07:29:54 +0000 (07:29 +0000)
  - Return correct item ids
  - Structures for navigating the playlist
  - Consistent locking
* Add a b_locked parameter to the remaining playlist API calls

44 files changed:
include/vlc/libvlc.h
include/vlc_playlist.h
modules/access/cdda.c
modules/access/directory.c
modules/access/mms/mmsh.c
modules/codec/cmml/intf.c
modules/control/http/macro.c
modules/control/http/rpn.c
modules/control/rc.c
modules/demux/mp4/mp4.c
modules/demux/playlist/asx.c
modules/demux/playlist/b4s.c
modules/demux/playlist/dvb.c
modules/demux/playlist/gvp.c
modules/demux/playlist/m3u.c
modules/demux/playlist/pls.c
modules/demux/playlist/podcast.c
modules/demux/playlist/qtl.c
modules/demux/playlist/sgimb.c
modules/demux/playlist/shoutcast.c
modules/demux/playlist/xspf.c
modules/gui/macosx/applescript.m
modules/gui/macosx/playlist.m
modules/gui/macosx/wizard.m
modules/gui/qt4/dialogs/open.cpp
modules/gui/qt4/dialogs/playlist.cpp
modules/gui/qt4/dialogs_provider.cpp
modules/gui/qt4/main_interface.cpp
modules/gui/wxwidgets/dialogs.cpp
modules/gui/wxwidgets/dialogs/open.cpp
modules/gui/wxwidgets/dialogs/wizard.cpp
modules/gui/wxwidgets/interface.cpp
modules/services_discovery/bonjour.c
modules/services_discovery/hal.c
modules/services_discovery/podcast.c
modules/services_discovery/sap.c
modules/services_discovery/shout.c
modules/services_discovery/upnp_cc.cpp
modules/services_discovery/upnp_intel.cpp
src/control/libvlc_internal.h
src/control/playlist.c
src/libvlc.c
src/misc/win32_specific.c
src/playlist/item.c

index 1850175..0ddc1a5 100644 (file)
@@ -48,13 +48,12 @@ extern "C" {
  * @{
  */
 
-struct libvlc_exception_t
+typedef struct
 {
     int b_raised;
     int i_code;
     char *psz_message;
-};
-typedef struct libvlc_exception_t libvlc_exception_t;
+} libvlc_exception_t;
 
 /**
  * Initialize an exception structure. This can be called several times to reuse
@@ -140,6 +139,13 @@ VLC_PUBLIC_API void libvlc_destroy( libvlc_instance_t *, libvlc_exception_t * );
  * @{
  */
 
+typedef struct {
+    int i_id;
+    char * psz_uri;
+    char * psz_name
+
+} libvlc_playlist_item_t;
+
 /**
  * Set loop variable
  */
index c139ccb..032288c 100644 (file)
@@ -368,11 +368,11 @@ VLC_EXPORT( int,  playlist_DeleteFromInput, ( playlist_t *, int, vlc_bool_t ) );
 VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *, const char * ) );
 
 /******************** Item addition ********************/
-VLC_EXPORT( int,  playlist_Add,    ( playlist_t *, const char *, const char *, int, int, vlc_bool_t ) );
-VLC_EXPORT( int,  playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char *const *,int, vlc_bool_t ) );
-VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *,int , int, vlc_bool_t ) );
-VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
-VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int, int*, int* ) );
+VLC_EXPORT( int,  playlist_Add,    ( playlist_t *, const char *, const char *, int, int, vlc_bool_t, vlc_bool_t ) );
+VLC_EXPORT( int,  playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char *const *,int, vlc_bool_t, vlc_bool_t ) );
+VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *, int, int, vlc_bool_t, vlc_bool_t ) );
+VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int, vlc_bool_t ) );
+VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int, int*, int*, vlc_bool_t ) );
 
 /********************** Misc item operations **********************/
 VLC_EXPORT( playlist_item_t*, playlist_ItemToNode, (playlist_t *,playlist_item_t *, vlc_bool_t) );
@@ -415,7 +415,7 @@ static inline int playlist_Import( playlist_t *p_playlist, const char *psz_file)
     snprintf( psz_uri, 256+9, "file/://%s", psz_file );
     p_input = input_ItemNewExt( p_playlist, psz_uri, psz_file, 0, NULL, -1 );
     playlist_AddInput( p_playlist, p_input, PLAYLIST_APPEND, PLAYLIST_END,
-                       VLC_TRUE );
+                       VLC_TRUE, VLC_FALSE );
     input_Read( p_playlist, p_input, VLC_TRUE );
     return VLC_SUCCESS;
 }
index 4cddad0..589e0d7 100644 (file)
@@ -503,7 +503,8 @@ static int GetTracks( access_t *p_access,
         }
 #endif
         playlist_BothAddInput( p_playlist, p_input_item, p_item_in_category,
-                               PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL );
+                               PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL,
+                               VLC_FALSE );
         free( psz_uri ); free( psz_opt ); free( psz_name );
         free( psz_first ); free( psz_last );
     }
index 49c56cc..832cb6c 100644 (file)
@@ -516,7 +516,8 @@ static int ReadDir( playlist_t *p_playlist, const char *psz_name,
                                            p_parent_category,
                                            PLAYLIST_APPEND|PLAYLIST_PREPARSE|
                                            PLAYLIST_NO_REBUILD,
-                                           PLAYLIST_END, NULL, NULL );
+                                           PLAYLIST_END, NULL, NULL,
+                                           VLC_FALSE );
                 }
             }
         }
index c3011e6..2758549 100644 (file)
@@ -112,7 +112,8 @@ int E_(MMSHOpen)( access_t *p_access )
 
         /** \bug we do not autodelete here */
         playlist_Add( p_playlist, psz_location, psz_location,
-                      PLAYLIST_INSERT | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE );
+                      PLAYLIST_INSERT | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE,
+                      VLC_FALSE );
         vlc_object_release( p_playlist );
 
         free( psz_location );
index b193ea8..114ccc8 100644 (file)
@@ -796,7 +796,8 @@ static void ReplacePlaylistItem( playlist_t *p_playlist, char *psz_uri )
 {
     playlist_Stop( p_playlist );
     (void) playlist_Add( p_playlist, psz_uri, psz_uri,
-                         PLAYLIST_INSERT /* FIXME: used to be PLAYLIST_REPLACE */, PLAYLIST_END|PLAYLIST_GO, VLC_TRUE /* FIXME: p_playlist->status.i_index */ );
+                         PLAYLIST_INSERT /* FIXME: used to be PLAYLIST_REPLACE */, PLAYLIST_END|PLAYLIST_GO, VLC_TRUE /* FIXME: p_playlist->status.i_index */,
+                         VLC_FALSE);
 }
 
 /****************************************************************************
index bc97060..ee09716 100644 (file)
@@ -343,7 +343,8 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                     else
                     {
                         playlist_AddInput( p_sys->p_playlist, p_input,
-                                     PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
+                                     PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
+                                     VLC_FALSE);
                         msg_Dbg( p_intf, "requested mrl add: %s", mrl );
                     }
 
index c280f31..6027a15 100644 (file)
@@ -851,7 +851,8 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
             else
             {
                 i_id = playlist_AddInput( p_sys->p_playlist, p_input,
-                                   PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
+                                   PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
+                                   VLC_FALSE);
                 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
             }
             E_(SSPushN)( st, i_id );
index 3428849..b574806 100644 (file)
@@ -1367,7 +1367,8 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
         {
             msg_rc( "Trying to add %s to playlist.", newval.psz_string );
             playlist_AddInput( p_playlist, p_item,
-                     PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
+                     PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
+                     VLC_FALSE );
         }
     }
     else if( !strcmp( psz_cmd, "enqueue" ) &&
@@ -1379,7 +1380,8 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
         {
             msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
             playlist_AddInput( p_playlist, p_item,
-                               PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
+                               PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
+                               VLC_FALSE);
         }
     }
     else if( !strcmp( psz_cmd, "playlist" ) )
index cc90eb6..c333672 100644 (file)
@@ -419,7 +419,7 @@ static int Open( vlc_object_t * p_this )
                         playlist_BothAddInput( p_playlist, p_input,
                                                p_item_in_category,
                                                PLAYLIST_APPEND, PLAYLIST_END,
-                                               NULL, NULL);
+                                               NULL, NULL, VLC_FALSE );
                     }
                 }
                 else
index cdb0902..714a201 100644 (file)
@@ -371,7 +371,8 @@ static int Demux( demux_t *p_demux )
                             playlist_BothAddInput( p_playlist, p_input,
                                                    p_item_in_category,
                                             PLAYLIST_APPEND|PLAYLIST_SPREPARSE,
-                                            PLAYLIST_END, NULL, NULL );
+                                            PLAYLIST_END, NULL, NULL,
+                                            VLC_FALSE);
                             free( psz_string );
                         }
                         else continue;
@@ -451,7 +452,8 @@ static int Demux( demux_t *p_demux )
                             playlist_BothAddInput( p_playlist, p_entry,
                                                  p_item_in_category,
                                                  PLAYLIST_APPEND | PLAYLIST_SPREPARSE
-                                                 , PLAYLIST_END, NULL, NULL);
+                                                 , PLAYLIST_END, NULL, NULL,
+                                                 VLC_FALSE );
                             free( psz_string );
                         }
                         else continue;
index 1ce444f..99a9129 100644 (file)
@@ -270,7 +270,7 @@ static int Demux( demux_t *p_demux )
                     playlist_BothAddInput( p_playlist, p_input,
                                            p_item_in_category,
                                            PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                                           PLAYLIST_END, NULL, NULL );
+                                           PLAYLIST_END, NULL, NULL, VLC_FALSE );
                     FREENULL( psz_name );
                     FREENULL( psz_mrl );
                     FREENULL( psz_genre );
index c020f55..2fe46ab 100644 (file)
@@ -120,7 +120,7 @@ static int Demux( demux_t *p_demux )
         }
         playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
                                PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                               PLAYLIST_END, NULL, NULL );
+                               PLAYLIST_END, NULL, NULL, VLC_FALSE );
 
         while( i_options-- ) free( ppsz_options[i_options] );
         if( ppsz_options ) free( ppsz_options );
index 369ff3a..a4869d4 100644 (file)
@@ -215,7 +215,7 @@ static int Demux( demux_t *p_demux )
         playlist_BothAddInput( p_sys->p_playlist, p_input,
                                p_sys->p_item_in_category,
                                PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                               PLAYLIST_END, NULL, NULL );
+                               PLAYLIST_END, NULL, NULL, VLC_FALSE );
     }
 
     HANDLE_PLAY_AND_RELEASE;
index 40c7eba..39696a6 100644 (file)
@@ -187,7 +187,7 @@ static int Demux( demux_t *p_demux )
                                         _(VLC_META_ARTIST), "%s", psz_artist );
             playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
                                    PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                                   PLAYLIST_END, NULL, NULL );
+                                   PLAYLIST_END, NULL, NULL, VLC_FALSE );
             free( psz_mrl );
             // XXX Not to be a scare monger, but I suspect options are leaked
         }
index e723f6f..b3df8e2 100644 (file)
@@ -163,7 +163,7 @@ static int Demux( demux_t *p_demux )
                 input_ItemCopyOptions( p_current->p_input, p_input );
                 playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
                                        PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                                       PLAYLIST_END, NULL, NULL );
+                                       PLAYLIST_END, NULL, NULL, VLC_FALSE );
             }
             else
             {
@@ -220,7 +220,7 @@ static int Demux( demux_t *p_demux )
         input_ItemCopyOptions( p_current->p_input, p_input );
         playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
                                PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                               PLAYLIST_END, NULL, NULL );
+                               PLAYLIST_END, NULL, NULL, VLC_FALSE );
         free( psz_mrl_orig );
         psz_mrl = NULL;
     }
index 50cc010..ca19bf8 100644 (file)
@@ -293,7 +293,7 @@ static int Demux( demux_t *p_demux )
                     playlist_BothAddInput( p_playlist, p_input,
                                            p_item_in_category,
                                            PLAYLIST_APPEND | PLAYLIST_SPREPARSE
-                                           , PLAYLIST_END, NULL, NULL );
+                                           , PLAYLIST_END, NULL, NULL, VLC_FALSE );
                     FREENULL( psz_item_name );
                     FREENULL( psz_item_mrl );
                     FREENULL( psz_item_size );
index 08ee00f..eac3157 100644 (file)
@@ -362,7 +362,7 @@ static int Demux( demux_t *p_demux )
         playlist_BothAddInput( p_sys->p_playlist, p_input,
                                p_sys->p_item_in_category,
                                PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                               PLAYLIST_END, NULL, NULL );
+                               PLAYLIST_END, NULL, NULL, VLC_FALSE );
         if( psz_qtnext )
         {
             p_input = input_ItemNewExt( p_sys->p_playlist,
@@ -370,7 +370,7 @@ static int Demux( demux_t *p_demux )
             playlist_BothAddInput( p_sys->p_playlist, p_input,
                                    p_sys->p_item_in_category,
                                    PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                                   PLAYLIST_END, NULL, NULL );
+                                   PLAYLIST_END, NULL, NULL, VLC_FALSE );
         }
     }
 
index 59a9f51..358a599 100644 (file)
@@ -408,7 +408,7 @@ static int Demux ( demux_t *p_demux )
 
     playlist_BothAddInput( p_playlist, p_child, p_item_in_category,
                            PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
-                           NULL, NULL);
+                           NULL, NULL, VLC_FALSE );
     HANDLE_PLAY_AND_RELEASE
     return -1; /* Needed for correct operation of go back */
 }
index 5487f1d..518c6cc 100644 (file)
@@ -242,7 +242,7 @@ static int DemuxGenre( demux_t *p_demux )
                     playlist_BothAddInput( p_sys->p_playlist, p_input,
                                            p_sys->p_item_in_category,
                                            PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                                           PLAYLIST_END, NULL, NULL );
+                                           PLAYLIST_END, NULL, NULL, VLC_FALSE );
                     FREENULL( psz_name );
                 }
                 FREENULL( psz_eltname );
@@ -434,7 +434,7 @@ static int DemuxStation( demux_t *p_demux )
                     playlist_BothAddInput( p_sys->p_playlist, p_input,
                                            p_sys->p_item_in_category,
                                            PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                                           PLAYLIST_END, NULL, NULL );
+                                           PLAYLIST_END, NULL, NULL, VLC_FALSE );
 
                     FREENULL( psz_name );
                     FREENULL( psz_mt )
index d19c692..ceea35e 100644 (file)
@@ -481,7 +481,7 @@ static vlc_bool_t parse_track_node COMPLEX_INTERFACE
                     playlist_BothAddInput( p_playlist, p_new_input,
                                            p_demux->p_sys->p_item_in_category,
                                            PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                                           PLAYLIST_END, NULL, NULL );
+                                           PLAYLIST_END, NULL, NULL, VLC_FALSE );
                     if( p_demux->p_sys->i_identifier <
                         p_demux->p_sys->i_tracklist_entries )
                     {
index adf3188..97ff247 100644 (file)
@@ -58,7 +58,7 @@
                                     [[[NSFileManager defaultManager]
                                     displayNameAtPath: o_urlString] UTF8String] );
             playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
-                               PLAYLIST_END, VLC_TRUE );
+                               PLAYLIST_END, VLC_TRUE, VLC_FALSE );
 
 
             o_url = [NSURL fileURLWithPath: o_urlString];
     [o_controls toogleFullscreen: self];
 }
 
-@end
\ No newline at end of file
+@end
index 517d288..c21d79d 100644 (file)
@@ -1011,7 +1011,8 @@ NSLog( @"expandable" );
 
         /* Add the item */
         playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
-             i_position == -1 ? PLAYLIST_END : i_position + i_item, VLC_TRUE );
+             i_position == -1 ? PLAYLIST_END : i_position + i_item, VLC_TRUE,
+            VLC_FALSE );
 
         if( i_item == 0 && !b_enqueue )
         {
index c2f3845..90e668f 100644 (file)
@@ -1314,7 +1314,7 @@ static VLCWizard *_o_sharedInstance = nil;
                 UTF8String] );
 
             playlist_AddInput( p_playlist, p_input, PLAYLIST_STOP, 
-                       PLAYLIST_END, VLC_TRUE );
+                       PLAYLIST_END, VLC_TRUE, VLC_FALSE );
 
             if( x == 0 )
             {
index bf572dc..c56b1ba 100644 (file)
@@ -121,7 +121,7 @@ void OpenDialog::ok()
              playlist_Add( THEPL, psz_utf8, NULL,
                            PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
                            ( i ? PLAYLIST_PREPARSE : 0 ),
-                           PLAYLIST_END, VLC_TRUE );
+                           PLAYLIST_END, VLC_TRUE, VLC_FALSE );
          }
 
     }
index fbb9450..52e174b 100644 (file)
@@ -85,7 +85,7 @@ void PlaylistDialog::dropEvent(QDropEvent *event)
         QString s = url.toString();
         if( s.length() > 0 ) {
             playlist_Add( THEPL, qtu(s), NULL,
-                          PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
+                          PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE, VLC_FALSE );
         }
      }
      event->acceptProposedAction();
index 09a0581..a71fd9a 100644 (file)
@@ -239,7 +239,7 @@ void DialogsProvider::addFromSimple( bool pl, bool go)
                                                ( i ? PLAYLIST_PREPARSE : 0 ) )
                          : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
                       PLAYLIST_END,
-                      pl ? VLC_TRUE : VLC_FALSE );
+                      pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
         i++;
     }
 }
@@ -319,7 +319,7 @@ static void openDirectory( intf_thread_t* p_intf, bool pl, bool go )
                                                0, NULL, -1 );
     playlist_AddInput( THEPL, p_input,
                        go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
-                       PLAYLIST_END, pl);
+                       PLAYLIST_END, pl, VLC_FALSE );
     input_Read( THEPL, p_input, VLC_FALSE );
 }
 
@@ -354,7 +354,7 @@ void DialogsProvider::streamingDialog()
 
             playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
                              PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
-                             -1, &psz_option, 1, VLC_TRUE );
+                             -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
         }
         delete s;
     }
index 6ecb381..6b0a77a 100644 (file)
@@ -521,7 +521,7 @@ void MainInterface::dropEvent(QDropEvent *event)
         if( s.length() > 0 ) {
             playlist_Add( THEPL, qtu(s), NULL,
                           PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
-                          PLAYLIST_END, VLC_TRUE );
+                          PLAYLIST_END, VLC_TRUE, VLC_FALSE );
             first = false;
         }
      }
index 793a19a..3abe162 100644 (file)
@@ -453,10 +453,10 @@ void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
                 playlist_Add( p_playlist, psz_utf8, NULL,
                               PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
                               (i ? PLAYLIST_PREPARSE : 0 ),
-                              PLAYLIST_END, VLC_TRUE );
+                              PLAYLIST_END, VLC_TRUE, VLC_FALSE );
             else
                 playlist_Add( p_playlist, psz_utf8, NULL,
-                              PLAYLIST_APPEND | PLAYLIST_PREPARSE , PLAYLIST_END , VLC_TRUE);
+                              PLAYLIST_APPEND | PLAYLIST_PREPARSE , PLAYLIST_END , VLC_TRUE, VLC_FALSE );
             wxLocaleFree( psz_utf8 );
         }
     }
@@ -483,7 +483,7 @@ void DialogsProvider::OnOpenDirectory( wxCommandEvent& event )
         char *psz_utf8 = wxFromLocale( path );
         playlist_Add( p_playlist, psz_utf8, NULL,
                       PLAYLIST_APPEND | (event.GetInt() ? PLAYLIST_GO : 0),
-                      PLAYLIST_END, VLC_TRUE );
+                      PLAYLIST_END, VLC_TRUE, VLC_FALSE );
         wxLocaleFree( psz_utf8 );
     }
 
index 65115e7..c33f586 100644 (file)
@@ -1206,13 +1206,13 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
         {
             playlist_AddInput( p_playlist, p_input,
                                PLAYLIST_APPEND | PLAYLIST_GO,
-                               PLAYLIST_END, VLC_TRUE );
+                               PLAYLIST_END, VLC_TRUE, VLC_FALSE );
         }
         else
         {
             playlist_AddInput( p_playlist, p_input,
                                        PLAYLIST_APPEND|PLAYLIST_PREPARSE,
-                                       PLAYLIST_END, VLC_TRUE );
+                                       PLAYLIST_END, VLC_TRUE, VLC_FALSE );
         }
     }
 
index 03bba24..19504c0 100644 (file)
@@ -1640,7 +1640,7 @@ void WizardDialog::Run()
             input_ItemAddOption( p_input, psz_ttl );
 
             playlist_AddInput( p_playlist, p_input,
-                               PLAYLIST_GO, PLAYLIST_END, VLC_TRUE );
+                               PLAYLIST_GO, PLAYLIST_END, VLC_TRUE, VLC_FALSE );
             vlc_object_release(p_playlist);
         }
         else
index 64199b3..c2e3c4f 100644 (file)
@@ -1324,7 +1324,7 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
 
         playlist_Add( p_playlist, psz_utf8, NULL,
                       PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
-                      PLAYLIST_END, VLC_TRUE );
+                      PLAYLIST_END, VLC_TRUE, VLC_FALSE );
 
         wxDnDLocaleFree( psz_utf8 );
     }
index f3108d8..6f9a6ca 100644 (file)
@@ -184,12 +184,14 @@ static void resolve_callback(
             playlist_item_t *p_item;
             p_item = playlist_NodeAddInput( p_sys->p_playlist, p_input,
                                             p_sys->p_node_cat,
-                                            PLAYLIST_APPEND, PLAYLIST_END );
+                                            PLAYLIST_APPEND, PLAYLIST_END,
+                                            VLC_FALSE);
             p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
             p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
             p_item = playlist_NodeAddInput( p_sys->p_playlist, p_input,
                                             p_sys->p_node_one,
-                                            PLAYLIST_APPEND, PLAYLIST_END );
+                                            PLAYLIST_APPEND, PLAYLIST_END,
+                                            VLC_FALSE );
             p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
             p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
        }
index ac4f52e..6ff31ec 100644 (file)
@@ -226,10 +226,12 @@ static void AddItem( services_discovery_t *p_sd, input_item_t * p_input
         return;
     }
     p_item_cat = playlist_NodeAddInput( p_playlist,
-            p_input,p_sd->p_sys->p_node_cat, PLAYLIST_APPEND, PLAYLIST_END );
+            p_input,p_sd->p_sys->p_node_cat, PLAYLIST_APPEND, PLAYLIST_END,
+            VLC_FALSE );
     p_item_cat->i_flags &= ~PLAYLIST_SKIP_FLAG;
     p_item_one = playlist_NodeAddInput( p_playlist,
-            p_input,p_sd->p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END );
+            p_input,p_sd->p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END,
+            VLC_FALSE );
     p_item_one->i_flags &= ~PLAYLIST_SKIP_FLAG;
 
     vlc_object_release( p_playlist );
index 42f6574..ca3488d 100644 (file)
@@ -167,9 +167,11 @@ static int Open( vlc_object_t *p_this )
                                     p_sys->ppsz_urls[i], 0, NULL, -1 );
         input_ItemAddOption( p_input, "demux=podcast" );
         p_item = playlist_NodeAddInput( p_playlist, p_input, p_sys->p_node_cat,
-                                        PLAYLIST_APPEND, PLAYLIST_END );
+                                        PLAYLIST_APPEND, PLAYLIST_END,
+                                        VLC_FALSE );
         p_item = playlist_NodeAddInput( p_playlist, p_input, p_sys->p_node_one,
-                                        PLAYLIST_APPEND, PLAYLIST_END );
+                                        PLAYLIST_APPEND, PLAYLIST_END,
+                                        VLC_FALSE );
         free( psz_buf );
         p_sys->pp_input[i] = input_CreateThread( p_playlist, p_input );
     }
index 732c9be..278d03f 100644 (file)
@@ -813,13 +813,14 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
     }
 
     p_item = playlist_NodeAddInput( pl_Get( p_sd ), p_input, p_child,
-                                    PLAYLIST_APPEND, PLAYLIST_END );
+                                    PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE );
     p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
     p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
     p_sap->i_item_id_cat = p_item->i_id;
 
     p_item = playlist_NodeAddInput( pl_Get( p_sd ), p_input,
-                        p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END );
+                        p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END,
+                        VLC_FALSE );
     p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
     p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
     p_sap->i_item_id_one = p_item->i_id;
index f219b6e..87f3520 100644 (file)
@@ -139,10 +139,10 @@ static int Open( vlc_object_t *p_this, int i_type )
     p_sys->p_input->b_prefers_tree = VLC_TRUE;
     p_sys->p_node_cat = playlist_NodeAddInput( p_playlist, p_sys->p_input,
                            p_playlist->p_root_category,
-                           PLAYLIST_APPEND, PLAYLIST_END );
+                           PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE );
     p_sys->p_node_one = playlist_NodeAddInput( p_playlist, p_sys->p_input,
                            p_playlist->p_root_onelevel,
-                           PLAYLIST_APPEND, PLAYLIST_END );
+                           PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE );
     p_sys->p_node_cat->i_flags |= PLAYLIST_RO_FLAG;
     p_sys->p_node_cat->i_flags |= PLAYLIST_SKIP_FLAG;
     p_sys->p_node_one->i_flags |= PLAYLIST_RO_FLAG;
index e05900b..8c49df8 100644 (file)
@@ -240,7 +240,8 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node )
         ItemNode *iNode = (ItemNode *)node;
         input_item_t *p_input = input_ItemNew( p_sd, iNode->getResource(), title );
         playlist_BothAddInput( p_sys->p_playlist, p_input, p_parent,
-                               PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL );
+                               PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL,
+                               VLC_FALSE );
     } else if ( node->isContainerNode() )
     {
         ContainerNode *conNode = (ContainerNode *)node;
index 40a0feb..28513d9 100644 (file)
@@ -871,7 +871,8 @@ void MediaServer::_buildPlaylist( Container* parent )
                                                item->getTitle() );
         int i_cat;
         playlist_BothAddInput( p_playlist, p_input, parentNode,
-                               PLAYLIST_APPEND, PLAYLIST_END, &i_cat, NULL );
+                               PLAYLIST_APPEND, PLAYLIST_END, &i_cat, NULL,
+                               VLC_FALSE );
         /* TODO: do this better by storing ids */
         playlist_item_t *p_node = playlist_ItemGetById( p_playlist, i_cat, VLC_FALSE );
         assert( p_node );
index 6da3d63..2813682 100644 (file)
@@ -49,7 +49,9 @@ VLC_EXPORT (int, libvlc_InternalAddIntf, ( libvlc_int_t *, const char *, vlc_boo
 struct libvlc_instance_t
 {
     libvlc_int_t *p_libvlc_int;
-    vlm_t      *p_vlm;
+    vlm_t        *p_vlm;
+    int           b_playlist_locked;
+    vlc_mutex_t   instance_lock;
 };
 
 struct libvlc_input_t
index 22a75a6..9a17a83 100644 (file)
 
 #define PL p_instance->p_libvlc_int->p_playlist
 
+static inline int playlist_was_locked( libvlc_instance_t *p_instance )
+{
+    int was_locked;
+    vlc_mutex_lock( &p_instance->instance_lock );
+    was_locked = p_instance->b_playlist_locked;
+    vlc_mutex_unlock( &p_instance->instance_lock );
+    return was_locked;
+}
+
+static inline void playlist_mark_locked( libvlc_instance_t *p_instance,
+                                         int locked )
+{
+    vlc_mutex_lock( &p_instance->instance_lock );
+    p_instance->b_playlist_locked = locked;
+    vlc_mutex_unlock( &p_instance->instance_lock );
+}
+
 void libvlc_playlist_loop( libvlc_instance_t *p_instance, vlc_bool_t loop,
                            libvlc_exception_t *p_e)
 {
@@ -42,30 +59,54 @@ void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
                            int i_options, char **ppsz_options,
                            libvlc_exception_t *p_e )
 {
+    int did_lock = 0;
     assert( PL );
     ///\todo Handle additionnal options
 
     if( PL->items.i_size == 0 ) RAISEVOID( "Empty playlist" );
     if( i_id > 0 )
     {
-        playlist_item_t *p_item = playlist_ItemGetByInputId( PL, i_id,
-                                                           PL->status.p_node );
-        if( !p_item ) RAISEVOID( "Unable to find item" );
-
-        playlist_Control( PL, PLAYLIST_VIEWPLAY, VLC_FALSE,
+        playlist_item_t *p_item;
+        if (! playlist_was_locked( p_instance ) )
+        {
+            playlist_mark_locked( p_instance, 1 );
+            vlc_mutex_lock( &PL->object_lock );
+            did_lock = 1;
+        }
+
+        p_item = playlist_ItemGetByInputId( PL, i_id,
+                                            PL->status.p_node );
+        if( !p_item )
+        {
+            if( did_lock == 1 )
+            {
+                vlc_mutex_unlock( &PL->object_lock );
+                playlist_mark_locked( p_instance, 0 );
+            }
+            RAISEVOID( "Unable to find item" );
+        }
+
+        playlist_Control( PL, PLAYLIST_VIEWPLAY, VLC_TRUE,
                           PL->status.p_node, p_item );
+        if( did_lock == 1 )
+        {
+            vlc_mutex_unlock( &PL->object_lock );
+            playlist_mark_locked( p_instance, 0 );
+        }
     }
     else
     {
-        playlist_Play( PL );
+        playlist_Control( PL, PLAYLIST_PLAY,
+                          playlist_was_locked( p_instance ) );
     }
 }
 
 void libvlc_playlist_pause( libvlc_instance_t *p_instance,
-                           libvlc_exception_t *p_e )
+                            libvlc_exception_t *p_e )
 {
     assert( PL );
-    if( playlist_Pause( PL ) != VLC_SUCCESS )
+    if( playlist_Control( PL, PLAYLIST_PAUSE,
+                          playlist_was_locked( p_instance ) ) != VLC_SUCCESS )
         RAISEVOID( "Empty playlist" );
 }
 
@@ -74,29 +115,32 @@ void libvlc_playlist_stop( libvlc_instance_t *p_instance,
                            libvlc_exception_t *p_e )
 {
     assert( PL );
-    if( playlist_Stop( PL ) != VLC_SUCCESS )
+    if( playlist_Control( PL, PLAYLIST_STOP,
+                          playlist_was_locked( p_instance ) ) != VLC_SUCCESS )
         RAISEVOID( "Empty playlist" );
 }
 
 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
-                           libvlc_exception_t *p_e )
+                            libvlc_exception_t *p_e )
 {
     assert( PL );
-    playlist_Clear( PL, VLC_FALSE );
+    playlist_Clear( PL, playlist_was_locked( p_instance ) );
 }
 
 void libvlc_playlist_next( libvlc_instance_t *p_instance,
                            libvlc_exception_t *p_e )
 {
     assert( PL );
-    if( playlist_Next( PL ) != VLC_SUCCESS )
+    if( playlist_Control( PL, PLAYLIST_SKIP, playlist_was_locked( p_instance ),
+                          1 ) != VLC_SUCCESS )
         RAISEVOID( "Empty playlist" );
 }
 
 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
                            libvlc_exception_t *p_e )
 {
-    if( playlist_Prev( PL ) != VLC_SUCCESS )
+    if( playlist_Control( PL, PLAYLIST_SKIP, playlist_was_locked( p_instance ),
+                          -1  ) != VLC_SUCCESS )
         RAISEVOID( "Empty playlist" );
 }
 
@@ -113,19 +157,25 @@ int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
                                   libvlc_exception_t *p_e )
 {
     assert( PL );
+    if( playlist_was_locked( p_instance ) )
+    {
+        libvlc_exeption_raise( p_e, "You must unlock playlist before "
+                               "calling libvlc_playlist_add" );
+        return VLC_EGENERIC;
+    }
     return playlist_AddExt( PL, psz_uri, psz_name,
                             PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
-                            i_options, 1 );
+                            i_options, 1, VLC_FALSE );
 }
 
 
-
 int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
                                  libvlc_exception_t *p_e )
 {
     assert( PL );
 
-    if( playlist_DeleteFromInput( PL, i_id, VLC_FALSE ) )
+    if( playlist_DeleteFromInput( PL, i_id,
+                                  playlist_was_locked( p_instance ) ) )
     {
         libvlc_exception_raise( p_e, "deletion failed" );
         return VLC_ENOITEM;
@@ -144,9 +194,25 @@ int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
                                  libvlc_exception_t *p_e )
 {
     assert( PL );
-    return PL->items.i_size;
+    return playlist_CurrentSize( PL );
 }
 
+void libvlc_playlist_lock( libvlc_instance_t *p_instance )
+{
+    assert( PL );
+    vlc_mutex_lock( &PL->object_lock );
+    p_instance->b_playlist_locked = 1;
+}
+
+void libvlc_playlist_unlock( libvlc_instance_t *p_instance )
+{
+    assert( PL );
+    p_instance->b_playlist_locked = 0;
+    vlc_mutex_unlock( &PL->object_lock );
+}
+
+
+
 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
                                             libvlc_exception_t *p_e )
 {
index 277fae3..a8c72bf 100644 (file)
@@ -314,7 +314,7 @@ int VLC_AddTarget( int i_object, char const *psz_target,
     LIBVLC_PLAYLIST_FUNC;
     i_err = playlist_AddExt( p_libvlc->p_playlist, psz_target,
                              NULL,  i_mode, i_pos, -1,
-                             ppsz_options, i_options, VLC_TRUE );
+                             ppsz_options, i_options, VLC_TRUE, VLC_FALSE );
     LIBVLC_PLAYLIST_FUNC_END;
     return i_err;
 }
index 0921bbb..c318c7d 100644 (file)
@@ -325,13 +325,13 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
                     NULL, PLAYLIST_APPEND ,
                     PLAYLIST_END, -1,
                     (char const **)( i_options ? &ppsz_argv[i_opt+1] : NULL ),
-                    i_options, VLC_TRUE );
+                    i_options, VLC_TRUE, VLC_FALSE );
                 } else {
                   playlist_AddExt( p_playlist, ppsz_argv[i_opt],
                     NULL, PLAYLIST_APPEND | PLAYLIST_GO,
                     PLAYLIST_END, -1,
                     (char const **)( i_options ? &ppsz_argv[i_opt+1] : NULL ),
-                    i_options, VLC_TRUE );
+                    i_options, VLC_TRUE, VLC_FALSE );
                 }
 
                 i_opt += i_options;
index cc47aa1..9c4f6b7 100644 (file)
@@ -136,7 +136,8 @@ void playlist_Clear( playlist_t * p_playlist, vlc_bool_t b_locked )
  * This function is to be used only by the playlist */
 int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
 {
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,  VLC_TRUE );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,
+                                                    VLC_TRUE );
     if( !p_item ) return VLC_EGENERIC;
     return DeleteInner( p_playlist, p_item, VLC_TRUE );
 }
@@ -157,10 +158,10 @@ int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
  */
 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
                   const char *psz_name, int i_mode, int i_pos,
-                  vlc_bool_t b_playlist )
+                  vlc_bool_t b_playlist, vlc_bool_t b_locked )
 {
     return playlist_AddExt( p_playlist, psz_uri, psz_name,
-                            i_mode, i_pos, -1, NULL, 0, b_playlist );
+                            i_mode, i_pos, -1, NULL, 0, b_playlist, b_locked );
 }
 
 /**
@@ -182,14 +183,15 @@ int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
 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 *const *ppsz_options,
-                     int i_options, vlc_bool_t b_playlist )
+                     int i_options, vlc_bool_t b_playlist, vlc_bool_t b_locked )
 {
     int i_ret;
     input_item_t *p_input = input_ItemNewExt( p_playlist, psz_uri, psz_name,
                                               i_options, ppsz_options,
                                               i_duration );
 
-    i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist );
+    i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist,
+                               b_locked );
     if( i_ret == VLC_SUCCESS )
         return p_input->i_id;
     return -1;
@@ -197,7 +199,8 @@ int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
 
 /** Add an input item to the playlist node */
 int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
-                      int i_mode, int i_pos, vlc_bool_t b_playlist )
+                       int i_mode, int i_pos, vlc_bool_t b_playlist,
+                       vlc_bool_t b_locked )
 {
     playlist_item_t *p_item_cat, *p_item_one;
 
@@ -205,7 +208,7 @@ int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
         PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
                                              p_input->psz_uri );
 
-    PL_LOCK;
+    if( !b_locked ) PL_LOCK;
 
     /* Add to ONELEVEL */
     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
@@ -223,7 +226,7 @@ int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
 
     GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
 
-    PL_UNLOCK;
+    if( !b_locked ) PL_UNLOCK;
     return VLC_SUCCESS;
 }
 
@@ -233,12 +236,12 @@ int playlist_BothAddInput( playlist_t *p_playlist,
                            input_item_t *p_input,
                            playlist_item_t *p_direct_parent,
                            int i_mode, int i_pos,
-                           int *i_cat, int *i_one )
+                           int *i_cat, int *i_one, vlc_bool_t b_locked )
 {
     playlist_item_t *p_item_cat, *p_item_one, *p_up;
     int i_top;
     assert( p_input );
-    vlc_mutex_lock( & p_playlist->object_lock );
+    if( !b_locked ) PL_LOCK;
 
     /* Add to category */
     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
@@ -271,7 +274,7 @@ int playlist_BothAddInput( playlist_t *p_playlist,
     if( i_cat ) *i_cat = p_item_cat->i_id;
     if( i_one ) *i_one = p_item_one->i_id;
 
-    vlc_mutex_unlock( &p_playlist->object_lock );
+    if( !b_locked ) PL_UNLOCK;
     return VLC_SUCCESS;
 }
 
@@ -279,19 +282,20 @@ int playlist_BothAddInput( playlist_t *p_playlist,
 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
                                          input_item_t *p_input,
                                          playlist_item_t *p_parent,
-                                         int i_mode, int i_pos )
+                                         int i_mode, int i_pos,
+                                         vlc_bool_t b_locked )
 {
     playlist_item_t *p_item;
     assert( p_input );
     assert( p_parent && p_parent->i_children != -1 );
 
-    vlc_mutex_lock( &p_playlist->object_lock );
+    if( !b_locked ) PL_LOCK;
 
     p_item = playlist_ItemNewFromInput( p_playlist, p_input );
     if( p_item == NULL ) return NULL;
     AddItem( p_playlist, p_item, p_parent, i_mode, i_pos );
 
-    vlc_mutex_unlock( &p_playlist->object_lock );
+    if( !b_locked ) PL_UNLOCK;
 
     return p_item;
 }