<html><head></head><body>Why do you change the parenting here?<br><br><div class="gmail_quote">Le 28 novembre 2018 16:09:07 GMT+02:00, Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet@gmail.com> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail"><hr> include/vlc_interface.h   |   2 +-<br> src/interface/interface.c | 129 +++++++++++++-------------------------<br> src/libvlc.c              |   2 +-<br> src/libvlc.h              |   2 +-<br> 4 files changed, 45 insertions(+), 90 deletions(-)<br><br>diff --git a/include/vlc_interface.h b/include/vlc_interface.h<br>index 632759060b..75c2060096 100644<br>--- a/include/vlc_interface.h<br>+++ b/include/vlc_interface.h<br>@@ -88,7 +88,7 @@ struct intf_dialog_args_t<br>     struct interaction_dialog_t *p_dialog;<br> };<br> <br>-VLC_API int intf_Create( playlist_t *, const char * );<br>+VLC_API int intf_Create(libvlc_int_t *, char const *);<br> <br> VLC_API void libvlc_Quit( libvlc_int_t * );<br> <br>diff --git a/src/interface/interface.c b/src/interface/interface.c<br>index 0f47e06fd8..f3901672a5 100644<br>--- a/src/interface/interface.c<br>+++ b/src/interface/interface.c<br>@@ -42,36 +42,29 @@<br> #include <vlc_common.h><br> #include <vlc_modules.h><br> #include <vlc_interface.h><br>-#include <vlc_playlist_legacy.h><br>+#include <vlc_playlist.h><br> #include "libvlc.h"<br>-#include "playlist_legacy/playlist_internal.h"<br> #include "../lib/libvlc_internal.h"<br> <br> static int AddIntfCallback( vlc_object_t *, char const *,<br>                             vlc_value_t , vlc_value_t , void * );<br> <br>-/* This lock ensures that the playlist is created only once (per instance). It<br>- * also protects the list of running interfaces against concurrent access,<br>+/* This lock protects the list of running interfaces against concurrent access,<br>  * either to add or remove an interface.<br>- *<br>- * However, it does NOT protect from destruction of the playlist by<br>- * intf_DestroyAll(). Instead, care must be taken that intf_Create() and any<br>- * other function that depends on the playlist is only called BEFORE<br>- * intf_DestroyAll() has the possibility to destroy all interfaces.<br>  */<br> static vlc_mutex_t lock = VLC_STATIC_MUTEX;<br> <br> /**<br>  * Create and start an interface.<br>  *<br>- * @param playlist playlist and parent object for the interface<br>+ * @param libvlc libvlc and parent object for the interface<br>  * @param chain configuration chain string<br>  * @return VLC_SUCCESS or an error code<br>  */<br>-int intf_Create( playlist_t *playlist, const char *chain )<br>+int intf_Create(libvlc_int_t *libvlc, char const *chain)<br> {<br>     /* Allocate structure */<br>-    intf_thread_t *p_intf = vlc_custom_create( playlist, sizeof( *p_intf ),<br>+    intf_thread_t *p_intf = vlc_custom_create( libvlc, sizeof( *p_intf ),<br>                                                "interface" );<br>     if( unlikely(p_intf == NULL) )<br>         return VLC_ENOMEM;<br>@@ -95,7 +88,7 @@ int intf_Create( playlist_t *playlist, const char *chain )<br>     var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, val,<br>                 _("Mouse Gestures") );<br> <br>-    var_AddCallback( p_intf, "intf-add", AddIntfCallback, playlist );<br>+    var_AddCallback(p_intf, "intf-add", AddIntfCallback, NULL);<br> <br>     /* Choose the best module */<br>     char *module;<br>@@ -110,9 +103,10 @@ int intf_Create( playlist_t *playlist, const char *chain )<br>         goto error;<br>     }<br> <br>+    libvlc_priv_t *libvlc_p = libvlc_priv(libvlc);<br>     vlc_mutex_lock( &lock );<br>-    p_intf->p_next = pl_priv( playlist )->interface;<br>-    pl_priv( playlist )->interface = p_intf;<br>+    p_intf->p_next = libvlc_p->interface;<br>+    libvlc_p->interface = p_intf;<br>     vlc_mutex_unlock( &lock );<br> <br>     return VLC_SUCCESS;<br>@@ -125,27 +119,6 @@ error:<br>     return VLC_EGENERIC;<br> }<br> <br>-/**<br>- * Creates the playlist if necessary, and return a pointer to it.<br>- * @note The playlist is not reference-counted. So the pointer is only valid<br>- * until intf_DestroyAll() destroys interfaces.<br>- */<br>-static playlist_t *intf_GetPlaylist(libvlc_int_t *libvlc)<br>-{<br>-    playlist_t *playlist;<br>-<br>-    vlc_mutex_lock(&lock);<br>-    playlist = libvlc_priv(libvlc)->playlist;<br>-    if (playlist == NULL)<br>-    {<br>-        playlist = playlist_Create(VLC_OBJECT(libvlc));<br>-        libvlc_priv(libvlc)->playlist = playlist;<br>-    }<br>-    vlc_mutex_unlock(&lock);<br>-<br>-    return playlist;<br>-}<br>-<br> vlc_playlist_t *<br> vlc_intf_GetMainPlaylist(intf_thread_t *intf)<br> {<br>@@ -155,9 +128,9 @@ vlc_intf_GetMainPlaylist(intf_thread_t *intf)<br> /**<br>  * Inserts an item in the playlist.<br>  *<br>- * This function is used during initialization. Unlike playlist_Add() and<br>- * variants, it inserts an item to the beginning of the playlist. That is<br>- * meant to compensate for the reverse parsing order of the command line.<br>+ * This function is used during initialization. It inserts an item to the<br>+ * beginning of the playlist. That is meant to compensate for the reverse<br>+ * parsing order of the command line.<br>  *<br>  * @note This function may <b>not</b> be called at the same time as<br>  * intf_DestroyAll().<br>@@ -165,36 +138,32 @@ vlc_intf_GetMainPlaylist(intf_thread_t *intf)<br> int intf_InsertItem(libvlc_int_t *libvlc, const char *mrl, unsigned optc,<br>                     const char *const *optv, unsigned flags)<br> {<br>-    playlist_t *playlist = intf_GetPlaylist(libvlc);<br>-    input_item_t *item = input_item_New(mrl, NULL);<br>+    int ret = -1;<br> <br>+    input_item_t *item = input_item_New(mrl, NULL);<br>     if (unlikely(item == NULL))<br>-        return -1;<br>-<br>-    int ret = -1;<br>+        goto end;<br> <br>     if (input_item_AddOptions(item, optc, optv, flags) == VLC_SUCCESS)<br>     {<br>-        playlist_Lock(playlist);<br>-        if (playlist_NodeAddInput(playlist, item, playlist->p_playing,<br>-                                  0) != NULL)<br>+        vlc_playlist_t *playlist = libvlc_priv(libvlc)->main_playlist;<br>+        vlc_playlist_Lock(playlist);<br>+        if (vlc_playlist_InsertOne(playlist, 0, item) == VLC_SUCCESS)<br>             ret = 0;<br>-        playlist_Unlock(playlist);<br>+        vlc_playlist_Unlock(playlist);<br>     }<br>     input_item_Release(item);<br>+<br>+end:<br>     return ret;<br> }<br> <br> void libvlc_InternalPlay(libvlc_int_t *libvlc)<br> {<br>-    playlist_t *pl;<br>-<br>-    vlc_mutex_lock(&lock);<br>-    pl = libvlc_priv(libvlc)->playlist;<br>-    vlc_mutex_unlock(&lock);<br>-<br>-    if (pl != NULL && var_GetBool(pl, "playlist-autostart"))<br>-        playlist_Control(pl, PLAYLIST_PLAY, false);<br>+    vlc_playlist_t *playlist = libvlc_priv(libvlc)->main_playlist;<br>+    vlc_playlist_Lock(playlist);<br>+    vlc_playlist_Start(playlist);<br>+    vlc_playlist_Unlock(playlist);<br> }<br> <br> /**<br>@@ -202,14 +171,10 @@ void libvlc_InternalPlay(libvlc_int_t *libvlc)<br>  */<br> int libvlc_InternalAddIntf(libvlc_int_t *libvlc, const char *name)<br> {<br>-    playlist_t *playlist = intf_GetPlaylist(libvlc);<br>     int ret;<br> <br>-    if (unlikely(playlist == NULL))<br>-        ret = VLC_ENOMEM;<br>-    else<br>     if (name != NULL)<br>-        ret = intf_Create(playlist, name);<br>+        ret = intf_Create(libvlc, name);<br>     else<br>     {   /* Default interface */<br>         char *intf = var_InheritString(libvlc, "intf");<br>@@ -221,49 +186,39 @@ int libvlc_InternalAddIntf(libvlc_int_t *libvlc, const char *name)<br>                 msg_Info(libvlc, _("Running vlc with the default interface. "<br>                          "Use 'cvlc' to use vlc without interface."));<br>         }<br>-        ret = intf_Create(playlist, intf);<br>+        ret = intf_Create(libvlc, intf);<br>         free(intf);<br>         name = "default";<br>     }<br>+<br>     if (ret != VLC_SUCCESS)<br>         msg_Err(libvlc, "interface \"%s\" initialization failed", name);<br>     return ret;<br> }<br> <br> /**<br>- * Stops and destroys all interfaces, then the playlist.<br>- * @warning FIXME<br>+ * Stops and destroys all interfaces<br>  * @param libvlc the LibVLC instance<br>  */<br> void intf_DestroyAll(libvlc_int_t *libvlc)<br> {<br>-    playlist_t *playlist;<br>-<br>+    libvlc_priv_t *libvlc_p = libvlc_priv(libvlc);<br>+    intf_thread_t *intf;<br>     vlc_mutex_lock(&lock);<br>-    playlist = libvlc_priv(libvlc)->playlist;<br>-    if (playlist != NULL)<br>+    intf_thread_t **p_intf = &libvlc_p->interface;<br>+    while (*p_intf != NULL)<br>     {<br>-        intf_thread_t *intf, **pp = &(pl_priv(playlist)->interface);<br>-<br>-        while ((intf = *pp) != NULL)<br>-        {<br>-            *pp = intf->p_next;<br>-            vlc_mutex_unlock(&lock);<br>-<br>-            module_unneed(intf, intf->p_module);<br>-            config_ChainDestroy(intf->p_cfg);<br>-            var_DelCallback(intf, "intf-add", AddIntfCallback, playlist);<br>-            vlc_object_release(intf);<br>-<br>-            vlc_mutex_lock(&lock);<br>-        }<br>-<br>-        libvlc_priv(libvlc)->playlist = NULL;<br>+        intf = *p_intf;<br>+        *p_intf = intf->p_next;<br>+        vlc_mutex_unlock(&lock);<br>+        module_unneed(intf, intf->p_module);<br>+        config_ChainDestroy(intf->p_cfg);<br>+        var_DelCallback(intf, "intf-add", AddIntfCallback, NULL);<br>+        vlc_object_release(intf);<br>+        vlc_mutex_lock(&lock);<br>     }<br>+    libvlc_p->interface = NULL;<br>     vlc_mutex_unlock(&lock);<br>-<br>-    if (playlist != NULL)<br>-        playlist_Destroy(playlist);<br> }<br> <br> /* Following functions are local */<br>diff --git a/src/libvlc.c b/src/libvlc.c<br>index cf35bcfed3..b82b5bac53 100644<br>--- a/src/libvlc.c<br>+++ b/src/libvlc.c<br>@@ -96,8 +96,8 @@ libvlc_int_t * libvlc_InternalCreate( void )<br>         return NULL;<br> <br>     priv = libvlc_priv (p_libvlc);<br>-    priv->playlist = NULL;<br>     priv->main_playlist = NULL;<br>+    priv->interface = NULL;<br>     priv->p_vlm = NULL;<br>     priv->media_source_provider = NULL;<br> <br>diff --git a/src/libvlc.h b/src/libvlc.h<br>index a0adeeb26a..736c7fe85b 100644<br>--- a/src/libvlc.h<br>+++ b/src/libvlc.h<br>@@ -195,8 +195,8 @@ typedef struct libvlc_priv_t<br>     vlm_t             *p_vlm;  ///< the VLM singleton (or NULL)<br>     vlc_dialog_provider *p_dialog_provider; ///< dialog provider<br>     vlc_keystore      *p_memory_keystore; ///< memory keystore<br>-    struct playlist_t *playlist; ///< Playlist for interfaces<br>     vlc_playlist_t *main_playlist;<br>+    struct intf_thread_t *interface; ///< Linked list of interfaces<br>     struct input_preparser_t *parser; ///< Input item meta data handler<br>     vlc_media_source_provider_t *media_source_provider;<br>     vlc_actions_t *actions; ///< Hotkeys handler</pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>