]> git.sesse.net Git - vlc/blobdiff - src/playlist/engine.c
avcodec: map LCL MSZH and ZLIB
[vlc] / src / playlist / engine.c
index e22a1b25df7e01562a8d40a212b462f8d45bf970..d9af6f0b71db3cb7fd671c0e41cb4e69c1635d5c 100644 (file)
 
 #include <stddef.h>
 #include <assert.h>
+
 #include <vlc_common.h>
 #include <vlc_sout.h>
 #include <vlc_playlist.h>
 #include <vlc_interface.h>
 #include "playlist_internal.h"
-#include "stream_output/stream_output.h" /* sout_DeleteInstance */
-#include <math.h> /* for fabs() */
+#include "input/resource.h"
 
 /*****************************************************************************
  * Local prototypes
@@ -45,16 +45,61 @@ static int RandomCallback( vlc_object_t *p_this, char const *psz_cmd,
 {
     (void)psz_cmd; (void)oldval; (void)newval; (void)a;
     playlist_t *p_playlist = (playlist_t*)p_this;
+    bool random = newval.b_bool;
 
     PL_LOCK;
 
-    pl_priv(p_playlist)->b_reset_currently_playing = true;
-    vlc_cond_signal( &pl_priv(p_playlist)->signal );
+    if( !random ) {
+        pl_priv(p_playlist)->b_reset_currently_playing = true;
+        vlc_cond_signal( &pl_priv(p_playlist)->signal );
+    } else {
+        /* Shuffle and sync the playlist on activation of random mode.
+         * This preserves the current playing item, so that the user
+         * can return to it if needed. (See #4472)
+         */
+        playlist_private_t *p_sys = pl_priv(p_playlist);
+        playlist_item_t *p_new = p_sys->status.p_item;
+        ResetCurrentlyPlaying( p_playlist, NULL );
+        if( p_new )
+            ResyncCurrentIndex( p_playlist, p_new );
+    }
 
     PL_UNLOCK;
     return VLC_SUCCESS;
 }
 
+/**
+ * When there are one or more pending corks, playback should be paused.
+ * This is used for audio policy.
+ * \warning Always add and remove a cork with var_IncInteger() and var_DecInteger().
+ * var_Get() and var_Set() are prone to race conditions.
+ */
+static int CorksCallback( vlc_object_t *obj, char const *var,
+                          vlc_value_t old, vlc_value_t cur, void *dummy )
+{
+    playlist_t *pl = (playlist_t *)obj;
+
+    msg_Dbg( obj, "corks count: %"PRId64" -> %"PRId64, old.i_int, cur.i_int );
+    if( !old.i_int == !cur.i_int )
+        return VLC_SUCCESS; /* nothing to do */
+
+    if( cur.i_int )
+    {
+        if( var_InheritBool( obj, "playlist-cork" ) )
+        {
+            msg_Dbg( obj, "corked" );
+            playlist_Pause( pl );
+        }
+        else
+            msg_Dbg( obj, "not corked" );
+    }
+    else
+        msg_Dbg( obj, "uncorked" );
+
+    (void) var; (void) dummy;
+    return VLC_SUCCESS;
+}
+
 static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval, void *p )
 {
@@ -150,7 +195,7 @@ static int VideoSplitterCallback( vlc_object_t *p_this, char const *psz_cmd,
  * \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
  */
-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;
@@ -164,8 +209,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     p_playlist = &p->public_data;
     TAB_INIT( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds );
 
-    libvlc_priv(p_parent->p_libvlc)->p_playlist = p_playlist;
-
     VariablesInit( p_playlist );
     vlc_mutex_init( &p->lock );
     vlc_cond_init( &p->signal );
@@ -182,7 +225,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
 
     p_playlist->i_current_index = 0;
     pl_priv(p_playlist)->b_reset_currently_playing = true;
-    pl_priv(p_playlist)->last_rebuild_date = 0;
 
     pl_priv(p_playlist)->b_tree = var_InheritBool( p_parent, "playlist-tree" );
 
@@ -191,19 +233,10 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     pl_priv(p_playlist)->b_auto_preparse =
         var_InheritBool( p_parent, "auto-preparse" );
 
-    /* Fetcher */
-    p->p_fetcher = playlist_fetcher_New( p_playlist );
-    if( unlikely(p->p_fetcher == NULL) )
-    {
-        msg_Err( p_playlist, "cannot create fetcher" );
-        p->p_preparser = NULL;
-    }
-    else
-    {   /* Preparse */
-        p->p_preparser = playlist_preparser_New( p_playlist, p->p_fetcher );
-        if( unlikely(p->p_preparser == NULL) )
-            msg_Err( p_playlist, "cannot create preparser" );
-    }
+   /* Preparser (and meta retriever) */
+   p->p_preparser = playlist_preparser_New( VLC_OBJECT(p_playlist) );
+   if( unlikely(p->p_preparser == NULL) )
+       msg_Err( p_playlist, "cannot create preparser" );
 
     /* Create the root node */
     PL_LOCK;
@@ -231,8 +264,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
             p_playlist, _( "Media Library" ), p_playlist->p_root,
             PLAYLIST_END, PLAYLIST_RO_FLAG, NULL );
         PL_UNLOCK;
-
-        if(!p_playlist->p_media_library ) return NULL;
     }
     else
     {
@@ -260,6 +291,29 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
         pl_priv(p_playlist)->b_auto_preparse = b_auto_preparse;
     }
 
+    /* Input resources */
+    p->p_input_resource = input_resource_New( VLC_OBJECT( p_playlist ) );
+    if( unlikely(p->p_input_resource == NULL) )
+        abort();
+
+    /* Audio output (needed for volume and device controls). */
+    audio_output_t *aout = input_resource_GetAout( p->p_input_resource );
+    if( aout != NULL )
+        input_resource_PutAout( p->p_input_resource, aout );
+
+    /* Thread */
+    playlist_Activate (p_playlist);
+
+    /* Add service discovery modules */
+    char *mods = var_InheritString( p_playlist, "services-discovery" );
+    if( mods != NULL )
+    {
+        char *p = mods, *m;
+        while( (m = strsep( &p, " :," )) != NULL )
+            playlist_ServicesDiscoveryAdd( p_playlist, m );
+        free( mods );
+    }
+
     return p_playlist;
 }
 
@@ -274,15 +328,28 @@ void playlist_Destroy( playlist_t *p_playlist )
 {
     playlist_private_t *p_sys = pl_priv(p_playlist);
 
+    /* Remove all services discovery */
+    playlist_ServicesDiscoveryKillAll( p_playlist );
+
     msg_Dbg( p_playlist, "destroying" );
+
+    playlist_Deactivate( p_playlist );
     if( p_sys->p_preparser )
         playlist_preparser_Delete( p_sys->p_preparser );
-    if( p_sys->p_fetcher )
-        playlist_fetcher_Delete( p_sys->p_fetcher );
 
-    /* Already cleared when deactivating (if activated anyway) */
-    assert( !p_sys->p_input );
-    assert( !p_sys->p_input_resource );
+    /* Release input resources */
+    assert( p_sys->p_input == NULL );
+    input_resource_Release( p_sys->p_input_resource );
+
+    if( p_playlist->p_media_library != NULL )
+        playlist_MLDump( p_playlist );
+
+    PL_LOCK;
+    /* Release the current node */
+    set_current_status_node( p_playlist, NULL );
+    /* Release the current item */
+    set_current_status_item( p_playlist, NULL );
+    PL_UNLOCK;
 
     vlc_cond_destroy( &p_sys->signal );
     vlc_mutex_destroy( &p_sys->lock );
@@ -369,12 +436,6 @@ void set_current_status_node( playlist_t * p_playlist,
     pl_priv(p_playlist)->status.p_node = p_node;
 }
 
-static input_thread_t *playlist_FindInput( vlc_object_t *object )
-{
-    assert( object == VLC_OBJECT(pl_Get(object)) );
-    return playlist_CurrentInput( (playlist_t *)object );
-}
-
 static void VariablesInit( playlist_t *p_playlist )
 {
     /* These variables control updates */
@@ -389,45 +450,41 @@ static void VariablesInit( playlist_t *p_playlist )
 
     var_Create( p_playlist, "playlist-item-append", VLC_VAR_ADDRESS );
 
-    var_Create( p_playlist, "item-current", VLC_VAR_ADDRESS );
     var_Create( p_playlist, "input-current", VLC_VAR_ADDRESS );
 
-    var_Create( p_playlist, "activity", VLC_VAR_INTEGER );
-    var_SetInteger( p_playlist, "activity", 0 );
+    var_Create( p_playlist, "activity", VLC_VAR_VOID );
 
     /* Variables to control playback */
     var_Create( p_playlist, "playlist-autostart", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    var_Create( p_playlist, "play-and-stop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    var_Create( p_playlist, "play-and-exit", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_playlist, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    var_AddCallback( p_playlist, "random", RandomCallback, NULL );
     var_Create( p_playlist, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_playlist, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    var_Create( p_playlist, "corks", VLC_VAR_INTEGER );
+    var_AddCallback( p_playlist, "corks", CorksCallback, NULL );
 
     var_Create( p_playlist, "rate", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
-    var_Create( p_playlist, "rate-slower", VLC_VAR_VOID );
-    var_Create( p_playlist, "rate-faster", VLC_VAR_VOID );
     var_AddCallback( p_playlist, "rate", RateCallback, NULL );
+    var_Create( p_playlist, "rate-slower", VLC_VAR_VOID );
     var_AddCallback( p_playlist, "rate-slower", RateOffsetCallback, NULL );
+    var_Create( p_playlist, "rate-faster", VLC_VAR_VOID );
     var_AddCallback( p_playlist, "rate-faster", RateOffsetCallback, NULL );
 
     var_Create( p_playlist, "video-splitter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_AddCallback( p_playlist, "video-splitter", VideoSplitterCallback, NULL );
 
-    var_AddCallback( p_playlist, "random", RandomCallback, NULL );
-
     /* */
     var_Create( p_playlist, "album-art", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
 
     /* Variables to preserve video output parameters */
     var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    var_Create( p_playlist, "video-wallpaper", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
 
     /* Audio output parameters */
     var_Create( p_playlist, "mute", VLC_VAR_BOOL );
-    var_Create( p_playlist, "volume", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
-    /* FIXME: horrible hack for audio output interface code */
-    var_Create( p_playlist, "find-input-callback", VLC_VAR_ADDRESS );
-    var_SetAddress( p_playlist, "find-input-callback", playlist_FindInput );
+    var_Create( p_playlist, "volume", VLC_VAR_FLOAT );
+    var_SetFloat( p_playlist, "volume", -1.f );
 }
 
 playlist_item_t * playlist_CurrentPlayingItem( playlist_t * p_playlist )