]> git.sesse.net Git - vlc/blobdiff - src/control/media_list_player.c
Revert "Remove enums from public APIs"
[vlc] / src / control / media_list_player.c
index d5865d99c2e6ceb833f1f9938ebdaf2e01baa360..4a0618bd4fb7fd4ae7d77eaaa3ecd664609fbffd 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-#include "libvlc_internal.h"
+
 #include <vlc/libvlc.h>
+#include <vlc/libvlc_media.h>
+#include <vlc/libvlc_media_list.h>
+#include <vlc/libvlc_media_player.h>
+#include <vlc/libvlc_media_list_player.h>
+#include <vlc/libvlc_events.h>
+
+#include "libvlc_internal.h"
+
+#include "media_internal.h" // Abuse, could and should be removed
 #include "media_list_path.h"
 
+//#define DEBUG_MEDIA_LIST_PLAYER
+
+struct libvlc_media_list_player_t
+{
+    libvlc_event_manager_t *    p_event_manager;
+    libvlc_instance_t *         p_libvlc_instance;
+    int                         i_refcount;
+    vlc_mutex_t                 object_lock;
+    libvlc_media_list_path_t    current_playing_item_path;
+    libvlc_media_t *            p_current_playing_item;
+    libvlc_media_list_t *       p_mlist;
+    libvlc_media_player_t *     p_mi;
+};
+
 /*
  * Private functions
  */
@@ -70,6 +93,9 @@ get_next_path( libvlc_media_list_player_t * p_mlp )
 
     ret = libvlc_media_list_path_copy( p_mlp->current_playing_item_path );
 
+    ret[depth-1]++; // Play next element
+
+    /* If this goes beyong the end of the list */
     while( ret[depth-1] >= libvlc_media_list_count( p_parent_of_playing_item, NULL ) )
     {
         depth--;
@@ -115,7 +141,10 @@ media_player_reached_end( const libvlc_event_t * p_event,
     }
     libvlc_media_release( p_md );
     libvlc_media_release( p_current_md );
-    libvlc_media_list_player_next( p_mlp, NULL );
+    libvlc_exception_t e;
+    libvlc_exception_init(&e);
+    libvlc_media_list_player_next(p_mlp, &e);
+    libvlc_exception_clear(&e); // Don't worry if there was an error
 }
 
 /**************************************************************************
@@ -171,7 +200,7 @@ uninstall_playlist_observer( libvlc_media_list_player_t * p_mlp )
 static void
 install_media_player_observer( libvlc_media_list_player_t * p_mlp )
 {
-    libvlc_event_attach( libvlc_media_player_event_manager( p_mlp->p_mi, NULL ),
+    libvlc_event_attach_async( libvlc_media_player_event_manager( p_mlp->p_mi, NULL ),
                          libvlc_MediaPlayerEndReached,
                           media_player_reached_end, p_mlp, NULL );
 }
@@ -184,9 +213,7 @@ static void
 uninstall_media_player_observer( libvlc_media_list_player_t * p_mlp )
 {
     if ( !p_mlp->p_mi )
-    {
         return;
-    }
 
     libvlc_event_detach( libvlc_media_player_event_manager( p_mlp->p_mi, NULL ),
                          libvlc_MediaPlayerEndReached,
@@ -264,10 +291,13 @@ libvlc_media_list_player_new( libvlc_instance_t * p_instance,
     if( !p_mlp )
         return NULL;
 
+    libvlc_retain( p_instance );
+    p_mlp->p_libvlc_instance = p_instance;
+    p_mlp->i_refcount = 0;
+    vlc_mutex_init( &p_mlp->object_lock );
     p_mlp->current_playing_item_path = NULL;
-    p_mlp->p_mi = NULL;
     p_mlp->p_mlist = NULL;
-    vlc_mutex_init( &p_mlp->object_lock );
+    p_mlp->p_mi = NULL;
     p_mlp->p_event_manager = libvlc_event_manager_new( p_mlp,
                                                        p_instance,
                                                        p_e );
@@ -306,6 +336,7 @@ void libvlc_media_list_player_release( libvlc_media_list_player_t * p_mlp )
     }
 
     free( p_mlp->current_playing_item_path );
+    libvlc_release( p_mlp->p_libvlc_instance );
     free( p_mlp );
 }
 
@@ -344,6 +375,13 @@ void libvlc_media_list_player_set_media_list(
 {
     vlc_mutex_lock( &p_mlp->object_lock );
 
+    if(!p_mlist)
+    {
+        libvlc_exception_raise( p_e, "No media list provided");
+        vlc_mutex_unlock( &p_mlp->object_lock );
+        return;
+    }
+
     if( libvlc_media_list_player_is_playing( p_mlp, p_e ) )
     {
         libvlc_media_player_stop( p_mlp->p_mi, p_e );
@@ -464,6 +502,8 @@ void libvlc_media_list_player_play_item(
 void libvlc_media_list_player_stop( libvlc_media_list_player_t * p_mlp,
                                     libvlc_exception_t * p_e )
 {
+    vlc_mutex_lock( &p_mlp->object_lock );
+
     if ( p_mlp->p_mi )
     {
         /* We are not interested in getting media stop event now */
@@ -472,7 +512,6 @@ void libvlc_media_list_player_stop( libvlc_media_list_player_t * p_mlp,
         install_media_player_observer( p_mlp );
     }
 
-    vlc_mutex_lock( &p_mlp->object_lock );
     free( p_mlp->current_playing_item_path );
     p_mlp->current_playing_item_path = NULL;
     vlc_mutex_unlock( &p_mlp->object_lock );
@@ -488,7 +527,7 @@ void libvlc_media_list_player_next( libvlc_media_list_player_t * p_mlp,
 
     if (! p_mlp->p_mlist )
     {
-        libvlc_exception_raise( p_e, "No more element to play" );
+        libvlc_exception_raise( p_e, "No media list" );
         return;
     }
 
@@ -496,6 +535,11 @@ void libvlc_media_list_player_next( libvlc_media_list_player_t * p_mlp,
 
     path = get_next_path( p_mlp );
 
+#ifdef DEBUG_MEDIA_LIST_PLAYER
+    printf("Playing:");
+    libvlc_media_list_path_dump(path);
+#endif
+    
     if( !path )
     {
         libvlc_media_list_unlock( p_mlp->p_mlist );