[vlc-devel] [PATCH 6/6] intf: use new playlist

Victorien Le Couviour--Tuffet victorien.lecouviour.tuffet at gmail.com
Tue Nov 27 13:28:58 CET 2018


---
 include/vlc_interface.h   |   2 +-
 src/interface/interface.c | 120 ++++++++++++--------------------------
 src/libvlc.c              |   1 -
 src/libvlc.h              |   1 -
 4 files changed, 37 insertions(+), 87 deletions(-)

diff --git a/include/vlc_interface.h b/include/vlc_interface.h
index 558ac1099d..ca5c8bba04 100644
--- a/include/vlc_interface.h
+++ b/include/vlc_interface.h
@@ -86,7 +86,7 @@ struct intf_dialog_args_t
     struct interaction_dialog_t *p_dialog;
 };
 
-VLC_API int intf_Create( playlist_t *, const char * );
+VLC_API int intf_Create(libvlc_int_t *, char const *);
 
 VLC_API void libvlc_Quit( libvlc_int_t * );
 
diff --git a/src/interface/interface.c b/src/interface/interface.c
index 7e0fed8412..cecb08ac84 100644
--- a/src/interface/interface.c
+++ b/src/interface/interface.c
@@ -42,36 +42,29 @@
 #include <vlc_common.h>
 #include <vlc_modules.h>
 #include <vlc_interface.h>
-#include <vlc_playlist_legacy.h>
+#include <vlc_playlist.h>
 #include "libvlc.h"
-#include "playlist_legacy/playlist_internal.h"
 #include "../lib/libvlc_internal.h"
 
 static int AddIntfCallback( vlc_object_t *, char const *,
                             vlc_value_t , vlc_value_t , void * );
 
-/* This lock ensures that the playlist is created only once (per instance). It
- * also protects the list of running interfaces against concurrent access,
+/* This lock protects the list of running interfaces against concurrent access,
  * either to add or remove an interface.
- *
- * However, it does NOT protect from destruction of the playlist by
- * intf_DestroyAll(). Instead, care must be taken that intf_Create() and any
- * other function that depends on the playlist is only called BEFORE
- * intf_DestroyAll() has the possibility to destroy all interfaces.
  */
 static vlc_mutex_t lock = VLC_STATIC_MUTEX;
 
 /**
  * Create and start an interface.
  *
- * @param playlist playlist and parent object for the interface
+ * @param libvlc libvlc and parent object for the interface
  * @param chain configuration chain string
  * @return VLC_SUCCESS or an error code
  */
-int intf_Create( playlist_t *playlist, const char *chain )
+int intf_Create(libvlc_int_t *libvlc, char const *chain)
 {
     /* Allocate structure */
-    intf_thread_t *p_intf = vlc_custom_create( playlist, sizeof( *p_intf ),
+    intf_thread_t *p_intf = vlc_custom_create( libvlc, sizeof( *p_intf ),
                                                "interface" );
     if( unlikely(p_intf == NULL) )
         return VLC_ENOMEM;
@@ -95,7 +88,7 @@ int intf_Create( playlist_t *playlist, const char *chain )
     var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, val,
                 _("Mouse Gestures") );
 
-    var_AddCallback( p_intf, "intf-add", AddIntfCallback, playlist );
+    var_AddCallback(p_intf, "intf-add", AddIntfCallback, NULL);
 
     /* Choose the best module */
     char *module;
@@ -124,27 +117,6 @@ error:
     return VLC_EGENERIC;
 }
 
-/**
- * Creates the playlist if necessary, and return a pointer to it.
- * @note The playlist is not reference-counted. So the pointer is only valid
- * until intf_DestroyAll() destroys interfaces.
- */
-static playlist_t *intf_GetPlaylist(libvlc_int_t *libvlc)
-{
-    playlist_t *playlist;
-
-    vlc_mutex_lock(&lock);
-    playlist = libvlc_priv(libvlc)->playlist;
-    if (playlist == NULL)
-    {
-        playlist = playlist_Create(VLC_OBJECT(libvlc));
-        libvlc_priv(libvlc)->playlist = playlist;
-    }
-    vlc_mutex_unlock(&lock);
-
-    return playlist;
-}
-
 vlc_playlist_t *
 vlc_intf_GetMainPlaylist(intf_thread_t *intf)
 {
@@ -154,9 +126,9 @@ vlc_intf_GetMainPlaylist(intf_thread_t *intf)
 /**
  * Inserts an item in the playlist.
  *
- * This function is used during initialization. Unlike playlist_Add() and
- * variants, it inserts an item to the beginning of the playlist. That is
- * meant to compensate for the reverse parsing order of the command line.
+ * This function is used during initialization. It inserts an item to the
+ * beginning of the playlist. That is meant to compensate for the reverse
+ * parsing order of the command line.
  *
  * @note This function may <b>not</b> be called at the same time as
  * intf_DestroyAll().
@@ -164,36 +136,32 @@ vlc_intf_GetMainPlaylist(intf_thread_t *intf)
 int intf_InsertItem(libvlc_int_t *libvlc, const char *mrl, unsigned optc,
                     const char *const *optv, unsigned flags)
 {
-    playlist_t *playlist = intf_GetPlaylist(libvlc);
-    input_item_t *item = input_item_New(mrl, NULL);
+    int ret = -1;
 
+    input_item_t *item = input_item_New(mrl, NULL);
     if (unlikely(item == NULL))
-        return -1;
-
-    int ret = -1;
+        goto end;
 
     if (input_item_AddOptions(item, optc, optv, flags) == VLC_SUCCESS)
     {
-        playlist_Lock(playlist);
-        if (playlist_NodeAddInput(playlist, item, playlist->p_playing,
-                                  0) != NULL)
+        vlc_playlist_t *playlist = libvlc_priv(libvlc)->main_playlist;
+        vlc_playlist_Lock(playlist);
+        if (vlc_playlist_InsertOne(playlist, 0, item) == VLC_SUCCESS)
             ret = 0;
-        playlist_Unlock(playlist);
+        vlc_playlist_Unlock(playlist);
     }
     input_item_Release(item);
+
+end:
     return ret;
 }
 
 void libvlc_InternalPlay(libvlc_int_t *libvlc)
 {
-    playlist_t *pl;
-
-    vlc_mutex_lock(&lock);
-    pl = libvlc_priv(libvlc)->playlist;
-    vlc_mutex_unlock(&lock);
-
-    if (pl != NULL && var_GetBool(pl, "playlist-autostart"))
-        playlist_Control(pl, PLAYLIST_PLAY, false);
+    vlc_playlist_t *playlist = libvlc_priv(libvlc)->main_playlist;
+    vlc_playlist_Lock(playlist);
+    vlc_playlist_Start(playlist);
+    vlc_playlist_Unlock(playlist);
 }
 
 /**
@@ -201,14 +169,10 @@ void libvlc_InternalPlay(libvlc_int_t *libvlc)
  */
 int libvlc_InternalAddIntf(libvlc_int_t *libvlc, const char *name)
 {
-    playlist_t *playlist = intf_GetPlaylist(libvlc);
     int ret;
 
-    if (unlikely(playlist == NULL))
-        ret = VLC_ENOMEM;
-    else
     if (name != NULL)
-        ret = intf_Create(playlist, name);
+        ret = intf_Create(libvlc, name);
     else
     {   /* Default interface */
         char *intf = var_InheritString(libvlc, "intf");
@@ -220,48 +184,36 @@ int libvlc_InternalAddIntf(libvlc_int_t *libvlc, const char *name)
                 msg_Info(libvlc, _("Running vlc with the default interface. "
                          "Use 'cvlc' to use vlc without interface."));
         }
-        ret = intf_Create(playlist, intf);
+        ret = intf_Create(libvlc, intf);
         free(intf);
         name = "default";
     }
+
     if (ret != VLC_SUCCESS)
         msg_Err(libvlc, "interface \"%s\" initialization failed", name);
     return ret;
 }
 
 /**
- * Stops and destroys all interfaces, then the playlist.
- * @warning FIXME
+ * Stops and destroys all interfaces
  * @param libvlc the LibVLC instance
  */
 void intf_DestroyAll(libvlc_int_t *libvlc)
 {
-    playlist_t *playlist;
-
+    libvlc_priv_t *libvlc_p = libvlc_priv(libvlc);
+    intf_thread_t *intf;
     vlc_mutex_lock(&lock);
-    libvlc_priv_t *libvlc_p = livlc_priv(libvlc);
-    playlist = libvlc_p->playlist;
-    if (playlist != NULL)
+    vlc_vector_foreach(intf, &libvlc_p->interfaces)
     {
-        intf_thread_t *intf;
-        vlc_vector_foreach(intf, &libvlc_p->interfaces)
-        {
-            vlc_mutex_unlock(&lock);
-
-            module_unneed(intf, intf->p_module);
-            config_ChainDestroy(intf->p_cfg);
-            var_DelCallback(intf, "intf-add", AddIntfCallback, playlist);
-            vlc_object_release(intf);
-
-            vlc_mutex_lock(&lock);
-        }
-        vlc_vector_clear(&libvlc_p->interfaces);
-        libvlc_p->playlist = NULL;
+        vlc_mutex_unlock(&lock);
+        module_unneed(intf, intf->p_module);
+        config_ChainDestroy(intf->p_cfg);
+        var_DelCallback(intf, "intf-add", AddIntfCallback, NULL);
+        vlc_object_release(intf);
+        vlc_mutex_lock(&lock);
     }
+    vlc_vector_clear(&libvlc_p->interfaces);
     vlc_mutex_unlock(&lock);
-
-    if (playlist != NULL)
-        playlist_Destroy(playlist);
 }
 
 /* Following functions are local */
diff --git a/src/libvlc.c b/src/libvlc.c
index 003a606373..5ccff0af20 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -97,7 +97,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
 
     priv = libvlc_priv (p_libvlc);
     vlc_vector_init(&priv->interfaces);
-    priv->playlist = NULL;
     priv->main_playlist = NULL;
     priv->p_vlm = NULL;
     priv->media_source_provider = NULL;
diff --git a/src/libvlc.h b/src/libvlc.h
index 8fb96017eb..d37144650a 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -199,7 +199,6 @@ typedef struct libvlc_priv_t
     vlc_dialog_provider *p_dialog_provider; ///< dialog provider
     vlc_keystore      *p_memory_keystore; ///< memory keystore
     intf_vector interfaces; ///< LibVLC interfaces book keeping
-    struct playlist_t *playlist;
     vlc_playlist_t *main_playlist;
     struct input_preparser_t *parser; ///< Input item meta data handler
     vlc_media_source_provider_t *media_source_provider;
-- 
2.19.1



More information about the vlc-devel mailing list