2 * media_list_player.c - libvlc smoke test
7 /**********************************************************************
8 * Copyright (C) 2007 RĂ©mi Denis-Courmont. *
9 * This program is free software; you can redistribute and/or modify *
10 * it under the terms of the GNU General Public License as published *
11 * by the Free Software Foundation; version 2 of the license, or (at *
12 * your option) any later version. *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
17 * See the GNU General Public License for more details. *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, you can get it from: *
21 * http://www.gnu.org/copyleft/gpl.html *
22 **********************************************************************/
27 #include <vlc_common.h>
28 #include <vlc_mtime.h>
30 #include "libvlc_additions.h"
32 struct check_items_order_data {
39 static inline void check_data_init(struct check_items_order_data *check)
43 check->done_playing = false;
46 static inline void queue_expected_item(struct check_items_order_data *check, void *item)
48 assert(check->count < 16);
49 check->items[check->count] = item;
53 static inline void wait_queued_items(struct check_items_order_data *check)
55 // Wait dummily for check_items_order_callback() to flag 'done_playing':
56 while (!check->done_playing)
60 static void check_items_order_callback(const libvlc_event_t * p_event, void * user_data)
62 struct check_items_order_data *checks = user_data;
63 libvlc_media_t *md = p_event->u.media_list_player_next_item_set.item;
64 assert(checks->index < checks->count);
65 if (checks->items[checks->index] != md)
67 char *title = libvlc_media_get_meta(md, libvlc_meta_Title, NULL);
68 log ("Got items %s\n", title);
71 assert(checks->items[checks->index] == md);
73 char *title = libvlc_media_get_meta(md, libvlc_meta_Title, NULL);
74 log ("Item %d '%s' was correctly queued\n", checks->index, title);
77 if (checks->index == (checks->count - 1))
79 log ("Done playing with success\n");
80 checks->done_playing = true;
85 static void test_media_list_player_items_queue(const char** argv, int argc)
87 libvlc_instance_t *vlc;
89 libvlc_media_list_t *ml;
90 libvlc_media_list_player_t *mlp;
92 const char * file = test_default_sample;
94 log ("Testing media player item queue-ing\n");
96 libvlc_exception_init (&ex);
97 vlc = libvlc_new (argc, argv, &ex);
100 md = libvlc_media_new (vlc, file, &ex);
103 ml = libvlc_media_list_new (vlc, &ex);
106 mlp = libvlc_media_list_player_new (vlc, &ex);
109 libvlc_media_list_add_media (ml, md, &ex);
112 static struct check_items_order_data check;
113 check_data_init(&check);
114 queue_expected_item(&check, md);
116 // Add three more media
117 queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
118 queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
119 queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
122 libvlc_media_t *node = libvlc_media_new_as_node(vlc, "node", &ex);
124 libvlc_media_list_add_media(ml, node, &ex);
126 queue_expected_item(&check, node);
128 // Add items to that node
129 libvlc_media_list_t *subitems = libvlc_media_subitems(node, &ex);
131 queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
132 queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
133 queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
134 libvlc_media_list_release(subitems);
136 libvlc_media_list_player_set_media_list (mlp, ml, &ex);
138 libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
139 libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet, check_items_order_callback, &check, &ex);
142 libvlc_media_list_player_play(mlp, &ex);
145 // Wait until all item are read
146 wait_queued_items(&check);
148 libvlc_media_list_player_stop (mlp, &ex);
151 libvlc_media_list_player_release (mlp);
154 libvlc_release (vlc);
158 static void test_media_list_player_next(const char** argv, int argc)
160 libvlc_instance_t *vlc;
162 libvlc_media_list_t *ml;
163 libvlc_media_list_player_t *mlp;
165 const char * file = test_default_sample;
167 log ("Testing media player next()\n");
169 libvlc_exception_init (&ex);
170 vlc = libvlc_new (argc, argv, &ex);
173 md = libvlc_media_new (vlc, file, &ex);
176 ml = libvlc_media_list_new (vlc, &ex);
179 mlp = libvlc_media_list_player_new (vlc, &ex);
182 libvlc_media_list_add_media (ml, md, &ex);
186 media_list_add_file_path (vlc, ml, file);
187 media_list_add_file_path (vlc, ml, file);
188 media_list_add_file_path (vlc, ml, file);
190 libvlc_media_list_player_set_media_list (mlp, ml, &ex);
192 libvlc_media_list_player_play_item (mlp, md, &ex);
195 libvlc_media_release (md);
199 libvlc_media_list_player_next (mlp, &ex);
202 libvlc_media_list_player_pause (mlp, &ex);
207 libvlc_media_list_player_next (mlp, &ex);
210 libvlc_media_list_player_stop (mlp, &ex);
215 libvlc_media_list_player_next (mlp, &ex);
218 libvlc_media_list_player_release (mlp);
221 libvlc_release (vlc);
225 static void test_media_list_player_pause_stop(const char** argv, int argc)
227 libvlc_instance_t *vlc;
229 libvlc_media_list_t *ml;
230 libvlc_media_list_player_t *mlp;
232 const char * file = test_default_sample;
234 log ("Testing play and pause of %s using the media list.\n", file);
236 libvlc_exception_init (&ex);
237 vlc = libvlc_new (argc, argv, &ex);
240 md = libvlc_media_new (vlc, file, &ex);
243 ml = libvlc_media_list_new (vlc, &ex);
246 mlp = libvlc_media_list_player_new (vlc, &ex);
248 libvlc_media_list_add_media( ml, md, &ex );
251 libvlc_media_list_player_set_media_list( mlp, ml, &ex );
253 libvlc_media_list_player_play_item( mlp, md, &ex );
256 libvlc_media_list_player_pause (mlp, &ex);
259 libvlc_media_list_player_stop (mlp, &ex);
262 libvlc_media_release (md);
264 libvlc_media_list_player_release (mlp);
267 libvlc_release (vlc);
271 static void test_media_list_player_play_item_at_index(const char** argv, int argc)
273 libvlc_instance_t *vlc;
275 libvlc_media_list_t *ml;
276 libvlc_media_list_player_t *mlp;
278 const char * file = test_default_sample;
280 log ("Testing play_item_at_index of %s using the media list.\n", file);
282 libvlc_exception_init (&ex);
283 vlc = libvlc_new (argc, argv, &ex);
286 md = libvlc_media_new (vlc, file, &ex);
289 ml = libvlc_media_list_new (vlc, &ex);
292 mlp = libvlc_media_list_player_new (vlc, &ex);
294 for (unsigned i = 0; i < 5; i++)
296 libvlc_media_list_add_media( ml, md, &ex );
300 libvlc_media_list_player_set_media_list( mlp, ml, &ex );
302 libvlc_media_list_player_play_item_at_index( mlp, 0, &ex );
305 libvlc_media_list_player_stop (mlp, &ex);
308 libvlc_media_release (md);
311 libvlc_media_list_player_release (mlp);
314 libvlc_release (vlc);
323 test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
324 test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
325 test_media_list_player_next (test_defaults_args, test_defaults_nargs);
326 test_media_list_player_items_queue (test_defaults_args, test_defaults_nargs);