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"
34 This allows for the direct addition of subitems in the playback options test.
35 This would not be necessary if there were an add subitems function.
37 #include "../../src/control/media_internal.h"
39 struct check_items_order_data {
46 static inline void check_data_init(struct check_items_order_data *check)
50 check->done_playing = false;
53 static inline void queue_expected_item(struct check_items_order_data *check, void *item)
55 assert(check->count < 16);
56 check->items[check->count] = item;
60 static inline void wait_queued_items(struct check_items_order_data *check)
62 // Wait dummily for check_items_order_callback() to flag 'done_playing':
63 while (!check->done_playing)
67 static void check_items_order_callback(const libvlc_event_t * p_event, void * user_data)
69 struct check_items_order_data *checks = user_data;
70 libvlc_media_t *md = p_event->u.media_list_player_next_item_set.item;
71 assert(checks->index < checks->count);
72 if (checks->items[checks->index] != md)
74 char *title = libvlc_media_get_meta(md, libvlc_meta_Title);
75 log ("Got items %s\n", title);
78 assert(checks->items[checks->index] == md);
80 char *title = libvlc_media_get_meta(md, libvlc_meta_Title);
81 log ("Item %d '%s' was correctly queued\n", checks->index, title);
84 if (checks->index == (checks->count - 1))
86 log ("Done playing with success\n");
87 checks->done_playing = true;
92 static void test_media_list_player_items_queue(const char** argv, int argc)
94 libvlc_instance_t *vlc;
96 libvlc_media_list_t *ml;
97 libvlc_media_list_player_t *mlp;
99 const char * file = test_default_sample;
101 log ("Testing media player item queue-ing\n");
103 vlc = libvlc_new (argc, argv);
104 assert (vlc != NULL);
106 md = libvlc_media_new_path (vlc, file);
109 ml = libvlc_media_list_new (vlc);
112 mlp = libvlc_media_list_player_new (vlc);
115 libvlc_media_list_add_media (ml, md);
117 static struct check_items_order_data check;
118 check_data_init(&check);
119 queue_expected_item(&check, md);
121 // Add three more media
122 queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
123 queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
124 queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
127 libvlc_media_t *node = libvlc_media_new_as_node(vlc, "node");
129 libvlc_media_list_add_media(ml, node);
130 queue_expected_item(&check, node);
132 // Add items to that node
133 libvlc_media_list_t *subitems = libvlc_media_subitems(node);
134 queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
135 queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
136 queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
137 libvlc_media_list_release(subitems);
139 libvlc_media_list_player_set_media_list (mlp, ml);
141 libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
142 int val = libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet,
143 check_items_order_callback, &check);
146 libvlc_media_list_player_play(mlp);
148 // Wait until all item are read
149 wait_queued_items(&check);
151 libvlc_media_list_player_stop (mlp);
152 while (libvlc_media_list_player_is_playing (mlp))
155 libvlc_media_list_player_release (mlp);
156 libvlc_release (vlc);
159 static void test_media_list_player_previous(const char** argv, int argc)
161 libvlc_instance_t *vlc;
163 libvlc_media_list_t *ml;
164 libvlc_media_list_player_t *mlp;
166 const char * file = test_default_sample;
168 log ("Testing media player previous()\n");
170 vlc = libvlc_new (argc, argv);
171 assert (vlc != NULL);
173 md = libvlc_media_new_path (vlc, file);
176 ml = libvlc_media_list_new (vlc);
179 mlp = libvlc_media_list_player_new (vlc);
182 libvlc_media_list_add_media (ml, md);
185 media_list_add_file_path (vlc, ml, file);
186 media_list_add_file_path (vlc, ml, file);
187 media_list_add_file_path (vlc, ml, file);
189 libvlc_media_list_player_set_media_list (mlp, ml);
191 libvlc_media_list_player_play_item (mlp, md);
193 while (!libvlc_media_list_player_is_playing (mlp))
196 libvlc_media_release (md);
198 libvlc_media_list_player_previous (mlp);
200 while (!libvlc_media_list_player_is_playing (mlp))
203 libvlc_media_list_player_pause (mlp);
204 libvlc_media_list_player_previous (mlp);
206 while (!libvlc_media_list_player_is_playing (mlp))
209 libvlc_media_list_player_stop (mlp);
211 while (libvlc_media_list_player_is_playing (mlp))
214 libvlc_media_list_player_previous (mlp);
216 while (!libvlc_media_list_player_is_playing (mlp))
219 libvlc_media_list_player_stop (mlp);
221 while (libvlc_media_list_player_is_playing (mlp))
224 libvlc_media_list_player_release (mlp);
225 libvlc_release (vlc);
228 static void test_media_list_player_next(const char** argv, int argc)
230 libvlc_instance_t *vlc;
232 libvlc_media_list_t *ml;
233 libvlc_media_list_player_t *mlp;
235 const char * file = test_default_sample;
237 log ("Testing media player next()\n");
239 vlc = libvlc_new (argc, argv);
240 assert (vlc != NULL);
242 md = libvlc_media_new_path (vlc, file);
245 ml = libvlc_media_list_new (vlc);
248 mlp = libvlc_media_list_player_new (vlc);
251 libvlc_media_list_add_media (ml, md);
254 media_list_add_file_path (vlc, ml, file);
255 media_list_add_file_path (vlc, ml, file);
256 media_list_add_file_path (vlc, ml, file);
258 libvlc_media_list_player_set_media_list (mlp, ml);
260 libvlc_media_list_player_play_item (mlp, md);
262 libvlc_media_release (md);
264 while (!libvlc_media_list_player_is_playing (mlp))
267 libvlc_media_list_player_next (mlp);
269 while (!libvlc_media_list_player_is_playing (mlp))
272 libvlc_media_list_player_pause (mlp);
273 libvlc_media_list_player_next (mlp);
275 while (!libvlc_media_list_player_is_playing (mlp))
278 libvlc_media_list_player_stop (mlp);
280 while (libvlc_media_list_player_is_playing (mlp))
283 libvlc_media_list_player_next (mlp);
285 while (!libvlc_media_list_player_is_playing (mlp))
288 libvlc_media_list_player_stop (mlp);
289 while (libvlc_media_list_player_is_playing (mlp))
292 libvlc_media_list_player_release (mlp);
293 libvlc_release (vlc);
296 static void test_media_list_player_pause_stop(const char** argv, int argc)
298 libvlc_instance_t *vlc;
300 libvlc_media_list_t *ml;
301 libvlc_media_list_player_t *mlp;
303 const char * file = test_default_sample;
305 log ("Testing play and pause of %s using the media list.\n", file);
307 vlc = libvlc_new (argc, argv);
308 assert (vlc != NULL);
310 md = libvlc_media_new_path (vlc, file);
313 ml = libvlc_media_list_new (vlc);
316 mlp = libvlc_media_list_player_new (vlc);
319 libvlc_media_list_add_media( ml, md);
321 libvlc_media_list_player_set_media_list( mlp, ml );
323 libvlc_media_list_player_play_item( mlp, md );
325 while (!libvlc_media_list_player_is_playing (mlp))
328 libvlc_media_list_player_pause (mlp);
329 libvlc_media_list_player_stop (mlp);
331 while (libvlc_media_list_player_is_playing (mlp))
334 libvlc_media_release (md);
335 libvlc_media_list_player_release (mlp);
336 libvlc_release (vlc);
339 static void test_media_list_player_play_item_at_index(const char** argv, int argc)
341 libvlc_instance_t *vlc;
343 libvlc_media_list_t *ml;
344 libvlc_media_list_player_t *mlp;
346 const char * file = test_default_sample;
348 log ("Testing play_item_at_index of %s using the media list.\n", file);
350 vlc = libvlc_new (argc, argv);
351 assert (vlc != NULL);
353 md = libvlc_media_new_path (vlc, file);
356 ml = libvlc_media_list_new (vlc);
359 mlp = libvlc_media_list_player_new (vlc);
362 for (unsigned i = 0; i < 5; i++)
364 libvlc_media_list_add_media( ml, md );
367 libvlc_media_list_player_set_media_list( mlp, ml );
368 libvlc_media_list_player_play_item_at_index( mlp, 0 );
370 while (!libvlc_media_list_player_is_playing (mlp))
373 libvlc_media_list_player_stop (mlp);
375 while (libvlc_media_list_player_is_playing (mlp))
378 libvlc_media_release (md);
379 libvlc_media_list_player_release (mlp);
380 libvlc_release (vlc);
383 static void test_media_list_player_playback_options (const char** argv, int argc)
385 libvlc_instance_t *vlc;
391 libvlc_media_list_t *ml;
392 libvlc_media_list_t *ml2;
393 libvlc_media_list_t *ml3;
394 libvlc_media_list_t *ml4;
395 libvlc_media_list_t *ml5;
396 libvlc_media_list_t *ml6;
397 libvlc_media_list_player_t *mlp;
399 const char * file = test_default_sample;
401 log ("Testing media player playback options()\n");
403 vlc = libvlc_new (argc, argv);
404 assert (vlc != NULL);
407 * Create the following media tree:
409 * ml1: 0 ---- 1 ---- 2
411 * ml2&4: 0 -- 1 | 0 -- 1 -- 2
413 * ml3: 0 -- 1 -- 2 -- 3 -- 4 -- 5 -- 6
418 md = libvlc_media_new_path (vlc, file);
421 md2 = libvlc_media_new_path (vlc, file);
424 md3 = libvlc_media_new_path (vlc, file);
427 md4 = libvlc_media_new_path (vlc, file);
430 md5 = libvlc_media_new_path (vlc, file);
433 ml = libvlc_media_list_new (vlc);
436 ml2 = libvlc_media_list_new (vlc);
437 assert (ml2 != NULL);
439 ml3 = libvlc_media_list_new (vlc);
440 assert (ml3 != NULL);
442 ml4 = libvlc_media_list_new (vlc);
443 assert (ml4 != NULL);
445 ml5 = libvlc_media_list_new (vlc);
446 assert (ml5 != NULL);
448 ml6 = libvlc_media_list_new (vlc);
449 assert (ml6 != NULL);
451 media_list_add_file_path (vlc, ml2, file);
452 media_list_add_file_path (vlc, ml2, file);
454 media_list_add_file_path (vlc, ml3, file);
455 media_list_add_file_path (vlc, ml3, file);
456 libvlc_media_list_add_media (ml3, md4);
457 media_list_add_file_path (vlc, ml3, file);
458 media_list_add_file_path (vlc, ml3, file);
459 media_list_add_file_path (vlc, ml3, file);
460 libvlc_media_list_add_media (ml3, md5);
462 media_list_add_file_path (vlc, ml4, file);
463 media_list_add_file_path (vlc, ml4, file);
464 media_list_add_file_path (vlc, ml4, file);
466 media_list_add_file_path (vlc, ml5, file);
468 media_list_add_file_path (vlc, ml6, file);
469 media_list_add_file_path (vlc, ml6, file);
471 md->p_subitems = ml2;
472 md2->p_subitems = ml3;
473 md3->p_subitems = ml4;
474 md4->p_subitems = ml5;
475 md5->p_subitems = ml6;
477 libvlc_media_list_add_media (ml, md);
478 libvlc_media_list_add_media (ml, md2);
479 libvlc_media_list_add_media (ml, md3);
481 mlp = libvlc_media_list_player_new (vlc);
484 libvlc_media_list_player_set_media_list (mlp, ml);
486 // Test default playback mode
487 libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_default);
489 libvlc_media_list_player_play_item (mlp, md);
491 while (!libvlc_media_list_player_is_playing (mlp))
494 libvlc_media_release (md);
495 libvlc_media_release (md2);
496 libvlc_media_release (md3);
497 libvlc_media_release (md4);
498 libvlc_media_release (md5);
500 libvlc_media_list_player_stop (mlp);
502 while (libvlc_media_list_player_is_playing (mlp))
505 // Test looping playback mode
506 log ("Testing media player playback option - Loop\n");
507 libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_loop);
509 libvlc_media_list_player_play_item (mlp, md);
511 while (!libvlc_media_list_player_is_playing (mlp))
514 libvlc_media_list_player_stop (mlp);
516 while (libvlc_media_list_player_is_playing (mlp))
519 // Test repeat playback mode
520 log ("Testing media player playback option - Repeat\n");
521 libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_repeat);
523 libvlc_media_list_player_play_item (mlp, md);
525 while (!libvlc_media_list_player_is_playing (mlp))
528 libvlc_media_list_player_stop (mlp);
530 while (libvlc_media_list_player_is_playing (mlp))
533 libvlc_media_list_player_release (mlp);
534 libvlc_release (vlc);
542 test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
543 test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
544 test_media_list_player_previous (test_defaults_args, test_defaults_nargs);
545 test_media_list_player_next (test_defaults_args, test_defaults_nargs);
546 test_media_list_player_items_queue (test_defaults_args, test_defaults_nargs);
547 test_media_list_player_playback_options (test_defaults_args, test_defaults_nargs);