[vlc-devel] commit: media_list_player: Make sure we'll correctly play next item, instead of setting the item but not playing it. (Pierre d'Herbemont )
git version control
git at videolan.org
Thu Aug 20 01:27:28 CEST 2009
vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Thu Aug 20 01:02:56 2009 +0200| [141eb5a663b05b41afc5664ccf43cc73e601894c] | committer: Pierre d'Herbemont
media_list_player: Make sure we'll correctly play next item, instead of setting the item but not playing it.
Add a test for correct item queuing as well.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=141eb5a663b05b41afc5664ccf43cc73e601894c
---
include/vlc/libvlc_events.h | 6 ++
include/vlc/libvlc_media_list_player.h | 8 +++
src/control/media_list_player.c | 17 ++++++-
src/libvlc.sym | 1 +
test/libvlc/media_list_player.c | 79 +++++++++++++++++++++++++++++++-
5 files changed, 108 insertions(+), 3 deletions(-)
diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index f1fc40f..649fffa 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -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
{
diff --git a/include/vlc/libvlc_media_list_player.h b/include/vlc/libvlc_media_list_player.h
index d2f2151..020ba79 100644
--- a/include/vlc/libvlc_media_list_player.h
+++ b/include/vlc/libvlc_media_list_player.h
@@ -65,6 +65,14 @@ 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.
*
* \param p_mlp media list player instance
diff --git a/src/control/media_list_player.c b/src/control/media_list_player.c
index 808d1cb..1c91799 100644
--- a/src/control/media_list_player.c
+++ b/src/control/media_list_player.c
@@ -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 */
}
@@ -390,6 +393,15 @@ void libvlc_media_list_player_release(libvlc_media_list_player_t * 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)
**************************************************************************/
void libvlc_media_list_player_set_media_player(libvlc_media_list_player_t * p_mlp, libvlc_media_player_t * p_mi, libvlc_exception_t * p_e)
@@ -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);
}
/**************************************************************************
diff --git a/src/libvlc.sym b/src/libvlc.sym
index a44b158..e27b65a 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -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
diff --git a/test/libvlc/media_list_player.c b/test/libvlc/media_list_player.c
index 56fbb43..e3701a6 100644
--- a/test/libvlc/media_list_player.c
+++ b/test/libvlc/media_list_player.c
@@ -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;
}
More information about the vlc-devel
mailing list