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 libvlc_exception_init (&ex);
104 vlc = libvlc_new (argc, argv, &ex);
107 md = libvlc_media_new (vlc, file, &ex);
110 ml = libvlc_media_list_new (vlc, &ex);
113 mlp = libvlc_media_list_player_new (vlc, &ex);
116 libvlc_media_list_add_media (ml, md, &ex);
119 static struct check_items_order_data check;
120 check_data_init(&check);
121 queue_expected_item(&check, md);
123 // Add three more media
124 queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
125 queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
126 queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
129 libvlc_media_t *node = libvlc_media_new_as_node(vlc, "node", &ex);
131 libvlc_media_list_add_media(ml, node, &ex);
133 queue_expected_item(&check, node);
135 // Add items to that node
136 libvlc_media_list_t *subitems = libvlc_media_subitems(node);
137 queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
138 queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
139 queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
140 libvlc_media_list_release(subitems);
142 libvlc_media_list_player_set_media_list (mlp, ml);
144 libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
145 int val = libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet,
146 check_items_order_callback, &check);
149 libvlc_media_list_player_play(mlp, &ex);
152 // Wait until all item are read
153 wait_queued_items(&check);
155 libvlc_media_list_player_stop (mlp);
156 while (libvlc_media_list_player_is_playing (mlp))
159 libvlc_media_list_player_release (mlp);
160 libvlc_release (vlc);
163 static void test_media_list_player_previous(const char** argv, int argc)
165 libvlc_instance_t *vlc;
167 libvlc_media_list_t *ml;
168 libvlc_media_list_player_t *mlp;
170 const char * file = test_default_sample;
172 log ("Testing media player previous()\n");
174 libvlc_exception_init (&ex);
175 vlc = libvlc_new (argc, argv, &ex);
178 md = libvlc_media_new (vlc, file, &ex);
181 ml = libvlc_media_list_new (vlc, &ex);
184 mlp = libvlc_media_list_player_new (vlc, &ex);
187 libvlc_media_list_add_media (ml, md, &ex);
191 media_list_add_file_path (vlc, ml, file);
192 media_list_add_file_path (vlc, ml, file);
193 media_list_add_file_path (vlc, ml, file);
195 libvlc_media_list_player_set_media_list (mlp, ml);
197 libvlc_media_list_player_play_item (mlp, md, &ex);
200 while (!libvlc_media_list_player_is_playing (mlp))
203 libvlc_media_release (md);
205 libvlc_media_list_player_previous (mlp, &ex);
208 while (!libvlc_media_list_player_is_playing (mlp))
211 libvlc_media_list_player_pause (mlp, &ex);
214 libvlc_media_list_player_previous (mlp, &ex);
217 while (!libvlc_media_list_player_is_playing (mlp))
220 libvlc_media_list_player_stop (mlp);
222 while (libvlc_media_list_player_is_playing (mlp))
225 libvlc_media_list_player_previous (mlp, &ex);
228 while (!libvlc_media_list_player_is_playing (mlp))
231 libvlc_media_list_player_stop (mlp);
233 while (libvlc_media_list_player_is_playing (mlp))
236 libvlc_media_list_player_release (mlp);
237 libvlc_release (vlc);
240 static void test_media_list_player_next(const char** argv, int argc)
242 libvlc_instance_t *vlc;
244 libvlc_media_list_t *ml;
245 libvlc_media_list_player_t *mlp;
247 const char * file = test_default_sample;
249 log ("Testing media player next()\n");
251 libvlc_exception_init (&ex);
252 vlc = libvlc_new (argc, argv, &ex);
255 md = libvlc_media_new (vlc, file, &ex);
258 ml = libvlc_media_list_new (vlc, &ex);
261 mlp = libvlc_media_list_player_new (vlc, &ex);
264 libvlc_media_list_add_media (ml, md, &ex);
268 media_list_add_file_path (vlc, ml, file);
269 media_list_add_file_path (vlc, ml, file);
270 media_list_add_file_path (vlc, ml, file);
272 libvlc_media_list_player_set_media_list (mlp, ml);
274 libvlc_media_list_player_play_item (mlp, md, &ex);
277 libvlc_media_release (md);
279 while (!libvlc_media_list_player_is_playing (mlp))
282 libvlc_media_list_player_next (mlp, &ex);
285 while (!libvlc_media_list_player_is_playing (mlp))
288 libvlc_media_list_player_pause (mlp, &ex);
291 libvlc_media_list_player_next (mlp, &ex);
294 while (!libvlc_media_list_player_is_playing (mlp))
297 libvlc_media_list_player_stop (mlp);
299 while (libvlc_media_list_player_is_playing (mlp))
302 libvlc_media_list_player_next (mlp, &ex);
305 while (!libvlc_media_list_player_is_playing (mlp))
308 libvlc_media_list_player_stop (mlp);
309 while (libvlc_media_list_player_is_playing (mlp))
312 libvlc_media_list_player_release (mlp);
313 libvlc_release (vlc);
316 static void test_media_list_player_pause_stop(const char** argv, int argc)
318 libvlc_instance_t *vlc;
320 libvlc_media_list_t *ml;
321 libvlc_media_list_player_t *mlp;
323 const char * file = test_default_sample;
325 log ("Testing play and pause of %s using the media list.\n", file);
327 libvlc_exception_init (&ex);
328 vlc = libvlc_new (argc, argv, &ex);
331 md = libvlc_media_new (vlc, file, &ex);
334 ml = libvlc_media_list_new (vlc, &ex);
337 mlp = libvlc_media_list_player_new (vlc, &ex);
339 libvlc_media_list_add_media( ml, md, &ex );
342 libvlc_media_list_player_set_media_list( mlp, ml );
344 libvlc_media_list_player_play_item( mlp, md, &ex );
347 while (!libvlc_media_list_player_is_playing (mlp))
350 libvlc_media_list_player_pause (mlp, &ex);
353 libvlc_media_list_player_stop (mlp);
355 while (libvlc_media_list_player_is_playing (mlp))
358 libvlc_media_release (md);
359 libvlc_media_list_player_release (mlp);
360 libvlc_release (vlc);
363 static void test_media_list_player_play_item_at_index(const char** argv, int argc)
365 libvlc_instance_t *vlc;
367 libvlc_media_list_t *ml;
368 libvlc_media_list_player_t *mlp;
370 const char * file = test_default_sample;
372 log ("Testing play_item_at_index of %s using the media list.\n", file);
374 libvlc_exception_init (&ex);
375 vlc = libvlc_new (argc, argv, &ex);
378 md = libvlc_media_new (vlc, file, &ex);
381 ml = libvlc_media_list_new (vlc, &ex);
384 mlp = libvlc_media_list_player_new (vlc, &ex);
386 for (unsigned i = 0; i < 5; i++)
388 libvlc_media_list_add_media( ml, md, &ex );
392 libvlc_media_list_player_set_media_list( mlp, ml );
394 libvlc_media_list_player_play_item_at_index( mlp, 0, &ex );
397 while (!libvlc_media_list_player_is_playing (mlp))
400 libvlc_media_list_player_stop (mlp);
402 while (libvlc_media_list_player_is_playing (mlp))
405 libvlc_media_release (md);
406 libvlc_media_list_player_release (mlp);
407 libvlc_release (vlc);
410 static void test_media_list_player_playback_options (const char** argv, int argc)
412 libvlc_instance_t *vlc;
418 libvlc_media_list_t *ml;
419 libvlc_media_list_t *ml2;
420 libvlc_media_list_t *ml3;
421 libvlc_media_list_t *ml4;
422 libvlc_media_list_t *ml5;
423 libvlc_media_list_t *ml6;
424 libvlc_media_list_player_t *mlp;
426 const char * file = test_default_sample;
428 log ("Testing media player playback options()\n");
430 libvlc_exception_init (&ex);
431 vlc = libvlc_new (argc, argv, &ex);
435 * Create the following media tree:
437 * ml1: 0 ---- 1 ---- 2
439 * ml2&4: 0 -- 1 | 0 -- 1 -- 2
441 * ml3: 0 -- 1 -- 2 -- 3 -- 4 -- 5 -- 6
446 md = libvlc_media_new (vlc, file, &ex);
449 md2 = libvlc_media_new (vlc, file, &ex);
452 md3 = libvlc_media_new (vlc, file, &ex);
455 md4 = libvlc_media_new (vlc, file, &ex);
458 md5 = libvlc_media_new (vlc, file, &ex);
461 ml = libvlc_media_list_new (vlc, &ex);
464 ml2 = libvlc_media_list_new (vlc, &ex);
467 ml3 = libvlc_media_list_new (vlc, &ex);
470 ml4 = libvlc_media_list_new (vlc, &ex);
473 ml5 = libvlc_media_list_new (vlc, &ex);
476 ml6 = libvlc_media_list_new (vlc, &ex);
479 media_list_add_file_path (vlc, ml2, file);
480 media_list_add_file_path (vlc, ml2, file);
482 media_list_add_file_path (vlc, ml3, file);
483 media_list_add_file_path (vlc, ml3, file);
484 libvlc_media_list_add_media (ml3, md4, &ex);
486 media_list_add_file_path (vlc, ml3, file);
487 media_list_add_file_path (vlc, ml3, file);
488 media_list_add_file_path (vlc, ml3, file);
489 libvlc_media_list_add_media (ml3, md5, &ex);
492 media_list_add_file_path (vlc, ml4, file);
493 media_list_add_file_path (vlc, ml4, file);
494 media_list_add_file_path (vlc, ml4, file);
496 media_list_add_file_path (vlc, ml5, file);
498 media_list_add_file_path (vlc, ml6, file);
499 media_list_add_file_path (vlc, ml6, file);
501 md->p_subitems = ml2;
502 md2->p_subitems = ml3;
503 md3->p_subitems = ml4;
504 md4->p_subitems = ml5;
505 md5->p_subitems = ml6;
507 libvlc_media_list_add_media (ml, md, &ex);
510 libvlc_media_list_add_media (ml, md2, &ex);
513 libvlc_media_list_add_media (ml, md3, &ex);
516 mlp = libvlc_media_list_player_new (vlc, &ex);
519 libvlc_media_list_player_set_media_list (mlp, ml);
521 // Test default playback mode
522 libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_default);
524 libvlc_media_list_player_play_item (mlp, md, &ex);
527 while (!libvlc_media_list_player_is_playing (mlp))
530 libvlc_media_release (md);
531 libvlc_media_release (md2);
532 libvlc_media_release (md3);
533 libvlc_media_release (md4);
534 libvlc_media_release (md5);
536 libvlc_media_list_player_stop (mlp);
538 while (libvlc_media_list_player_is_playing (mlp))
541 // Test looping playback mode
542 log ("Testing media player playback option - Loop\n");
543 libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_loop);
545 libvlc_media_list_player_play_item (mlp, md, &ex);
548 while (!libvlc_media_list_player_is_playing (mlp))
551 libvlc_media_list_player_stop (mlp);
553 while (libvlc_media_list_player_is_playing (mlp))
556 // Test repeat playback mode
557 log ("Testing media player playback option - Repeat\n");
558 libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_repeat);
560 libvlc_media_list_player_play_item (mlp, md, &ex);
563 while (!libvlc_media_list_player_is_playing (mlp))
566 libvlc_media_list_player_stop (mlp);
568 while (libvlc_media_list_player_is_playing (mlp))
571 libvlc_media_list_player_release (mlp);
572 libvlc_release (vlc);
580 test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
581 test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
582 test_media_list_player_previous (test_defaults_args, test_defaults_nargs);
583 test_media_list_player_next (test_defaults_args, test_defaults_nargs);
584 test_media_list_player_items_queue (test_defaults_args, test_defaults_nargs);
585 test_media_list_player_playback_options (test_defaults_args, test_defaults_nargs);