[vlc-devel] [PATCH] intf: use new playlist
Rémi Denis-Courmont
remi at remlab.net
Thu Nov 29 14:56:34 CET 2018
Why do you change the parenting here?
Le 28 novembre 2018 16:09:07 GMT+02:00, Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com> a écrit :
>---
> include/vlc_interface.h | 2 +-
> src/interface/interface.c | 129 +++++++++++++-------------------------
> src/libvlc.c | 2 +-
> src/libvlc.h | 2 +-
> 4 files changed, 45 insertions(+), 90 deletions(-)
>
>diff --git a/include/vlc_interface.h b/include/vlc_interface.h
>index 632759060b..75c2060096 100644
>--- a/include/vlc_interface.h
>+++ b/include/vlc_interface.h
>@@ -88,7 +88,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 0f47e06fd8..f3901672a5 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;
>@@ -110,9 +103,10 @@ int intf_Create( playlist_t *playlist, const char
>*chain )
> goto error;
> }
>
>+ libvlc_priv_t *libvlc_p = libvlc_priv(libvlc);
> vlc_mutex_lock( &lock );
>- p_intf->p_next = pl_priv( playlist )->interface;
>- pl_priv( playlist )->interface = p_intf;
>+ p_intf->p_next = libvlc_p->interface;
>+ libvlc_p->interface = p_intf;
> vlc_mutex_unlock( &lock );
>
> return VLC_SUCCESS;
>@@ -125,27 +119,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)
> {
>@@ -155,9 +128,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().
>@@ -165,36 +138,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);
> }
>
> /**
>@@ -202,14 +171,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");
>@@ -221,49 +186,39 @@ 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);
>- playlist = libvlc_priv(libvlc)->playlist;
>- if (playlist != NULL)
>+ intf_thread_t **p_intf = &libvlc_p->interface;
>+ while (*p_intf != NULL)
> {
>- intf_thread_t *intf, **pp = &(pl_priv(playlist)->interface);
>-
>- while ((intf = *pp) != NULL)
>- {
>- *pp = intf->p_next;
>- 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);
>- }
>-
>- libvlc_priv(libvlc)->playlist = NULL;
>+ intf = *p_intf;
>+ *p_intf = intf->p_next;
>+ 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);
> }
>+ libvlc_p->interface = NULL;
> 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 cf35bcfed3..b82b5bac53 100644
>--- a/src/libvlc.c
>+++ b/src/libvlc.c
>@@ -96,8 +96,8 @@ libvlc_int_t * libvlc_InternalCreate( void )
> return NULL;
>
> priv = libvlc_priv (p_libvlc);
>- priv->playlist = NULL;
> priv->main_playlist = NULL;
>+ priv->interface = NULL;
> priv->p_vlm = NULL;
> priv->media_source_provider = NULL;
>
>diff --git a/src/libvlc.h b/src/libvlc.h
>index a0adeeb26a..736c7fe85b 100644
>--- a/src/libvlc.h
>+++ b/src/libvlc.h
>@@ -195,8 +195,8 @@ typedef struct libvlc_priv_t
> vlm_t *p_vlm; ///< the VLM singleton (or NULL)
> vlc_dialog_provider *p_dialog_provider; ///< dialog provider
> vlc_keystore *p_memory_keystore; ///< memory keystore
>- struct playlist_t *playlist; ///< Playlist for interfaces
> vlc_playlist_t *main_playlist;
>+ struct intf_thread_t *interface; ///< Linked list of interfaces
> struct input_preparser_t *parser; ///< Input item meta data handler
> vlc_media_source_provider_t *media_source_provider;
> vlc_actions_t *actions; ///< Hotkeys handler
>--
>2.19.1
>
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel
--
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20181129/e2ce2520/attachment.html>
More information about the vlc-devel
mailing list