#include <vlc_common.h>
#include <vlc_modules.h>
#include <vlc_interface.h>
+#include <vlc_playlist.h>
#include "libvlc.h"
-
-#ifdef __APPLE__
-#include "../lib/libvlc_internal.h"
-#endif
+#include "playlist/playlist_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,
+ * 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;
#undef intf_Create
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;
+}
+
+playlist_t *(pl_Get)(vlc_object_t *obj)
+{
+ playlist_t *pl = intf_GetPlaylist(obj->p_libvlc);
+ if (unlikely(pl == NULL))
+ abort();
+ return pl;
+}
/**
* Stops and destroys all interfaces
return NULL;
priv = libvlc_priv (p_libvlc);
- priv->p_playlist = NULL;
+ priv->playlist = NULL;
priv->p_dialog_provider = NULL;
priv->p_vlm = NULL;
#endif
/* Free playlist now, all threads are gone */
- playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
+ playlist_t *p_playlist = libvlc_priv (p_libvlc)->playlist;
if( p_playlist != NULL )
playlist_Destroy( p_playlist );
bool b_stats; ///< Whether to collect stats
/* Singleton objects */
- playlist_t *p_playlist; ///< the playlist singleton
vlm_t *p_vlm; ///< the VLM singleton (or NULL)
vlc_object_t *p_dialog_provider; ///< dialog provider
#ifdef ENABLE_SOUT
sap_handler_t *p_sap; ///< SAP SDP advertiser
#endif
+ struct playlist_t *playlist; ///< Playlist for interfaces
struct playlist_preparser_t *parser; ///< Input item meta data handler
struct vlc_actions *actions; ///< Hotkeys handler
* \param p_parent the vlc object that is to be the parent of this playlist
* \return a pointer to the created playlist, or NULL on error
*/
-static playlist_t *playlist_Create( vlc_object_t *p_parent )
+playlist_t *playlist_Create( vlc_object_t *p_parent )
{
playlist_t *p_playlist;
playlist_private_t *p;
vlc_object_release( p_playlist );
}
-#undef pl_Get
-playlist_t *pl_Get (vlc_object_t *obj)
-{
- static vlc_mutex_t lock = VLC_STATIC_MUTEX;
- libvlc_int_t *p_libvlc = obj->p_libvlc;
- playlist_t *pl;
-
- vlc_mutex_lock (&lock);
- pl = libvlc_priv (p_libvlc)->p_playlist;
- if (unlikely(pl == NULL))
- {
- pl = playlist_Create (VLC_OBJECT(p_libvlc));
- if (unlikely(pl == NULL))
- abort();
- libvlc_priv (p_libvlc)->p_playlist = pl;
- }
- vlc_mutex_unlock (&lock);
- return pl;
-}
-
/** Get current playing input.
*/
input_thread_t * playlist_CurrentInput( playlist_t * p_playlist )
*****************************************************************************/
/* Creation/Deletion */
+playlist_t *playlist_Create( vlc_object_t * );
void playlist_Destroy( playlist_t * );
void playlist_Activate( playlist_t * );