media_list_player: Make sure we'll correctly play next item, instead of setting the...
authorPierre d'Herbemont <pdherbemont@free.fr>
Wed, 19 Aug 2009 23:02:56 +0000 (01:02 +0200)
committerPierre d'Herbemont <pdherbemont@free.fr>
Wed, 19 Aug 2009 23:06:49 +0000 (01:06 +0200)
Add a test for correct item queuing as well.

include/vlc/libvlc_events.h
include/vlc/libvlc_media_list_player.h
src/control/media_list_player.c
src/libvlc.sym
test/libvlc/media_list_player.c

index f1fc40f..649fffa 100644 (file)
@@ -213,6 +213,12 @@ struct libvlc_event_t
             int index;
         } media_list_view_will_delete_item;
 
+        /* media list player */
+        struct
+        {
+            libvlc_media_t * item;
+        } media_list_player_next_item_set;
+        
         /* snapshot taken */
         struct
         {
index d2f2151..020ba79 100644 (file)
@@ -64,6 +64,14 @@ VLC_PUBLIC_API libvlc_media_list_player_t *
 VLC_PUBLIC_API void
     libvlc_media_list_player_release( libvlc_media_list_player_t * p_mlp );
 
+/**
+ * Return the event manager of this media_list_player.
+ *
+ * \param p_mlp media list player instance
+ */
+VLC_PUBLIC_API libvlc_event_manager_t *
+    libvlc_media_list_player_event_manager(libvlc_media_list_player_t * p_mlp);
+
 /**
  * Replace media player in media_list_player with this instance.
  *
index 808d1cb..1c91799 100644 (file)
@@ -278,7 +278,7 @@ uninstall_media_player_observer(libvlc_media_list_player_t * p_mlp)
 
     // Now, lock back the callback lock. No more callback will be present from this point.
     vlc_mutex_lock(&p_mlp->mp_callback_lock);
-    p_mlp->are_mp_callback_cancelled = true;
+    p_mlp->are_mp_callback_cancelled = false;
 
     // What is here is safe, because we garantee that we won't be able to anything concurently,
     // - except (cancelled) callbacks - thanks to the object_lock.
@@ -315,6 +315,9 @@ set_current_playing_item(libvlc_media_list_player_t * p_mlp, libvlc_media_list_p
     /* Create a new media_player if there is none */
     if (!p_mlp->p_mi)
         p_mlp->p_mi = libvlc_media_player_new_from_media(p_md, NULL);
+
+    libvlc_media_player_set_media(p_mlp->p_mi, p_md, NULL);
+
     install_media_player_observer(p_mlp);
     libvlc_media_release(p_md); /* for libvlc_media_list_item_at_index */
 }
@@ -389,6 +392,15 @@ void libvlc_media_list_player_release(libvlc_media_list_player_t * p_mlp)
     free(p_mlp);
 }
 
+/**************************************************************************
+ *        event_manager (Public)
+ **************************************************************************/
+libvlc_event_manager_t *
+libvlc_media_list_player_event_manager(libvlc_media_list_player_t * p_mlp)
+{
+    return p_mlp->p_event_manager;
+}
+
 /**************************************************************************
  *        set_media_player (Public)
  **************************************************************************/
@@ -586,7 +598,10 @@ static void next(libvlc_media_list_player_t * p_mlp, libvlc_exception_t * p_e)
     /* Send the next item event */
     libvlc_event_t event;
     event.type = libvlc_MediaListPlayerNextItemSet;
+    libvlc_media_t * p_md = libvlc_media_list_item_at_path(p_mlp->p_mlist, path);
+    event.u.media_list_player_next_item_set.item = p_md;
     libvlc_event_send(p_mlp->p_event_manager, &event);
+    libvlc_media_release(p_md);
 }
 
 /**************************************************************************
index a44b158..e27b65a 100644 (file)
@@ -86,6 +86,7 @@ libvlc_media_list_item_at_index
 libvlc_media_list_lock
 libvlc_media_list_media
 libvlc_media_list_new
+libvlc_media_list_player_event_manager
 libvlc_media_list_player_get_state
 libvlc_media_list_player_is_playing
 libvlc_media_list_player_new
index 56fbb43..e3701a6 100644 (file)
@@ -27,7 +27,7 @@
 #include <vlc_common.h>
 #include <vlc_mtime.h>
 
-static void media_list_add_file_path(libvlc_instance_t *vlc, libvlc_media_list_t *ml, const char * file_path)
+static void* media_list_add_file_path(libvlc_instance_t *vlc, libvlc_media_list_t *ml, const char * file_path)
 {
     libvlc_media_t *md = libvlc_media_new (vlc, file_path, &ex);
     catch ();
@@ -36,6 +36,81 @@ static void media_list_add_file_path(libvlc_instance_t *vlc, libvlc_media_list_t
     catch ();
 
     libvlc_media_release (md);
+    return md;
+}
+
+static bool done_playing = false;
+static const unsigned items_count = 4;
+static void * items[4];
+static unsigned current_index = 0;
+
+static void next_item_callback(const libvlc_event_t * p_event, void * user_data)
+{
+    (void)user_data;
+    libvlc_media_t *md = p_event->u.media_list_player_next_item_set.item;
+    current_index++;
+    assert(current_index < items_count);    
+    assert(items[current_index] == md);
+    log ("Item %d was correctly queued\n", current_index);
+    if (current_index == (items_count - 1))
+        done_playing = true;
+}
+
+static void test_media_list_player_items_queue(const char** argv, int argc)
+{
+    libvlc_instance_t *vlc;
+    libvlc_media_t *md;
+    libvlc_media_list_t *ml;
+    libvlc_media_list_player_t *mlp;
+    
+    const char * file = test_default_sample;
+    
+    log ("Testing media player item queue-ing\n");
+    
+    libvlc_exception_init (&ex);
+    vlc = libvlc_new (argc, argv, &ex);
+    catch ();
+    
+    md = libvlc_media_new (vlc, file, &ex);
+    catch ();
+    
+    ml = libvlc_media_list_new (vlc, &ex);
+    catch ();
+    
+    mlp = libvlc_media_list_player_new (vlc, &ex);
+    catch ();
+    
+    libvlc_media_list_add_media (ml, md, &ex);
+    catch ();
+    
+    items[0] = md;
+
+    // Add three more media
+    items[1] = media_list_add_file_path (vlc, ml, file);
+    items[2] = media_list_add_file_path (vlc, ml, file);
+    items[3] = media_list_add_file_path (vlc, ml, file);
+    
+    libvlc_media_list_player_set_media_list (mlp, ml, &ex);
+
+    libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
+    libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet, next_item_callback, NULL, &ex);
+    catch ();
+
+    libvlc_media_list_player_play_item (mlp, md, &ex);
+    catch ();
+
+    // Wait dummily for next_item_callback() to flag 'done_playing':
+    while (!done_playing)
+        msleep(100000);
+
+    libvlc_media_list_player_stop (mlp, &ex);
+    catch ();
+
+    libvlc_media_list_player_release (mlp);
+    catch ();
+    
+    libvlc_release (vlc);
+    catch ();
 }
 
 static void test_media_list_player_next(const char** argv, int argc)
@@ -206,6 +281,6 @@ int main (void)
     test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
     test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
     test_media_list_player_next (test_defaults_args, test_defaults_nargs);
-
+    test_media_list_player_items_queue (test_defaults_args, test_defaults_nargs);
     return 0;
 }