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, &ex);
144 libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
145 libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet, check_items_order_callback, &check, &ex);
148 libvlc_media_list_player_play(mlp, &ex);
151 // Wait until all item are read
152 wait_queued_items(&check);
154 libvlc_media_list_player_stop (mlp, &ex);
157 libvlc_media_list_player_release (mlp);
160 libvlc_release (vlc);
164 static void test_media_list_player_previous(const char** argv, int argc)
166 libvlc_instance_t *vlc;
168 libvlc_media_list_t *ml;
169 libvlc_media_list_player_t *mlp;
171 const char * file = test_default_sample;
173 log ("Testing media player previous()\n");
175 libvlc_exception_init (&ex);
176 vlc = libvlc_new (argc, argv, &ex);
179 md = libvlc_media_new (vlc, file, &ex);
182 ml = libvlc_media_list_new (vlc, &ex);
185 mlp = libvlc_media_list_player_new (vlc, &ex);
188 libvlc_media_list_add_media (ml, md, &ex);
192 media_list_add_file_path (vlc, ml, file);
193 media_list_add_file_path (vlc, ml, file);
194 media_list_add_file_path (vlc, ml, file);
196 libvlc_media_list_player_set_media_list (mlp, ml, &ex);
198 libvlc_media_list_player_play_item (mlp, md, &ex);
201 libvlc_media_release (md);
205 libvlc_media_list_player_previous (mlp, &ex);
208 libvlc_media_list_player_pause (mlp, &ex);
213 libvlc_media_list_player_previous (mlp, &ex);
216 libvlc_media_list_player_stop (mlp, &ex);
221 libvlc_media_list_player_previous (mlp, &ex);
224 libvlc_media_list_player_stop (mlp, &ex);
227 libvlc_media_list_player_release (mlp);
230 libvlc_release (vlc);
234 static void test_media_list_player_next(const char** argv, int argc)
236 libvlc_instance_t *vlc;
238 libvlc_media_list_t *ml;
239 libvlc_media_list_player_t *mlp;
241 const char * file = test_default_sample;
243 log ("Testing media player next()\n");
245 libvlc_exception_init (&ex);
246 vlc = libvlc_new (argc, argv, &ex);
249 md = libvlc_media_new (vlc, file, &ex);
252 ml = libvlc_media_list_new (vlc, &ex);
255 mlp = libvlc_media_list_player_new (vlc, &ex);
258 libvlc_media_list_add_media (ml, md, &ex);
262 media_list_add_file_path (vlc, ml, file);
263 media_list_add_file_path (vlc, ml, file);
264 media_list_add_file_path (vlc, ml, file);
266 libvlc_media_list_player_set_media_list (mlp, ml, &ex);
268 libvlc_media_list_player_play_item (mlp, md, &ex);
271 libvlc_media_release (md);
275 libvlc_media_list_player_next (mlp, &ex);
278 libvlc_media_list_player_pause (mlp, &ex);
283 libvlc_media_list_player_next (mlp, &ex);
286 libvlc_media_list_player_stop (mlp, &ex);
291 libvlc_media_list_player_next (mlp, &ex);
294 libvlc_media_list_player_stop (mlp, &ex);
297 libvlc_media_list_player_release (mlp);
300 libvlc_release (vlc);
304 static void test_media_list_player_pause_stop(const char** argv, int argc)
306 libvlc_instance_t *vlc;
308 libvlc_media_list_t *ml;
309 libvlc_media_list_player_t *mlp;
311 const char * file = test_default_sample;
313 log ("Testing play and pause of %s using the media list.\n", file);
315 libvlc_exception_init (&ex);
316 vlc = libvlc_new (argc, argv, &ex);
319 md = libvlc_media_new (vlc, file, &ex);
322 ml = libvlc_media_list_new (vlc, &ex);
325 mlp = libvlc_media_list_player_new (vlc, &ex);
327 libvlc_media_list_add_media( ml, md, &ex );
330 libvlc_media_list_player_set_media_list( mlp, ml, &ex );
332 libvlc_media_list_player_play_item( mlp, md, &ex );
335 libvlc_media_list_player_pause (mlp, &ex);
338 libvlc_media_list_player_stop (mlp, &ex);
341 libvlc_media_release (md);
343 libvlc_media_list_player_release (mlp);
346 libvlc_release (vlc);
350 static void test_media_list_player_play_item_at_index(const char** argv, int argc)
352 libvlc_instance_t *vlc;
354 libvlc_media_list_t *ml;
355 libvlc_media_list_player_t *mlp;
357 const char * file = test_default_sample;
359 log ("Testing play_item_at_index of %s using the media list.\n", file);
361 libvlc_exception_init (&ex);
362 vlc = libvlc_new (argc, argv, &ex);
365 md = libvlc_media_new (vlc, file, &ex);
368 ml = libvlc_media_list_new (vlc, &ex);
371 mlp = libvlc_media_list_player_new (vlc, &ex);
373 for (unsigned i = 0; i < 5; i++)
375 libvlc_media_list_add_media( ml, md, &ex );
379 libvlc_media_list_player_set_media_list( mlp, ml, &ex );
381 libvlc_media_list_player_play_item_at_index( mlp, 0, &ex );
384 libvlc_media_list_player_stop (mlp, &ex);
387 libvlc_media_release (md);
390 libvlc_media_list_player_release (mlp);
393 libvlc_release (vlc);
397 static void test_media_list_player_playback_options (const char** argv, int argc)
399 libvlc_instance_t *vlc;
405 libvlc_media_list_t *ml;
406 libvlc_media_list_t *ml2;
407 libvlc_media_list_t *ml3;
408 libvlc_media_list_t *ml4;
409 libvlc_media_list_t *ml5;
410 libvlc_media_list_t *ml6;
411 libvlc_media_list_player_t *mlp;
413 const char * file = test_default_sample;
415 log ("Testing media player playback options()\n");
417 libvlc_exception_init (&ex);
418 vlc = libvlc_new (argc, argv, &ex);
422 * Create the following media tree:
424 * ml1: 0 ---- 1 ---- 2
426 * ml2&4: 0 -- 1 | 0 -- 1 -- 2
428 * ml3: 0 -- 1 -- 2 -- 3 -- 4 -- 5 -- 6
433 md = libvlc_media_new (vlc, file, &ex);
436 md2 = libvlc_media_new (vlc, file, &ex);
439 md3 = libvlc_media_new (vlc, file, &ex);
442 md4 = libvlc_media_new (vlc, file, &ex);
445 md5 = libvlc_media_new (vlc, file, &ex);
448 ml = libvlc_media_list_new (vlc, &ex);
451 ml2 = libvlc_media_list_new (vlc, &ex);
454 ml3 = libvlc_media_list_new (vlc, &ex);
457 ml4 = libvlc_media_list_new (vlc, &ex);
460 ml5 = libvlc_media_list_new (vlc, &ex);
463 ml6 = libvlc_media_list_new (vlc, &ex);
466 media_list_add_file_path (vlc, ml2, file);
467 media_list_add_file_path (vlc, ml2, file);
469 media_list_add_file_path (vlc, ml3, file);
470 media_list_add_file_path (vlc, ml3, file);
471 libvlc_media_list_add_media (ml3, md4, &ex);
473 media_list_add_file_path (vlc, ml3, file);
474 media_list_add_file_path (vlc, ml3, file);
475 media_list_add_file_path (vlc, ml3, file);
476 libvlc_media_list_add_media (ml3, md5, &ex);
479 media_list_add_file_path (vlc, ml4, file);
480 media_list_add_file_path (vlc, ml4, file);
481 media_list_add_file_path (vlc, ml4, file);
483 media_list_add_file_path (vlc, ml5, file);
485 media_list_add_file_path (vlc, ml6, file);
486 media_list_add_file_path (vlc, ml6, file);
488 md->p_subitems = ml2;
489 md2->p_subitems = ml3;
490 md3->p_subitems = ml4;
491 md4->p_subitems = ml5;
492 md5->p_subitems = ml6;
494 libvlc_media_list_add_media (ml, md, &ex);
497 libvlc_media_list_add_media (ml, md2, &ex);
500 libvlc_media_list_add_media (ml, md3, &ex);
503 mlp = libvlc_media_list_player_new (vlc, &ex);
506 libvlc_media_list_player_set_media_list (mlp, ml, &ex);
509 // Test default playback mode
510 libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_default, &ex);
513 libvlc_media_list_player_play_item (mlp, md, &ex);
516 libvlc_media_release (md);
518 libvlc_media_release (md2);
520 libvlc_media_release (md3);
522 libvlc_media_release (md4);
524 libvlc_media_release (md5);
529 libvlc_media_list_player_stop (mlp, &ex);
532 // Test looping playback mode
533 log ("Testing media player playback option - Loop\n");
534 libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_loop, &ex);
537 libvlc_media_list_player_play_item (mlp, md, &ex);
542 libvlc_media_list_player_stop (mlp, &ex);
545 // Test repeat playback mode
546 log ("Testing media player playback option - Repeat\n");
547 libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_repeat, &ex);
550 libvlc_media_list_player_play_item (mlp, md, &ex);
555 libvlc_media_list_player_stop (mlp, &ex);
558 libvlc_media_list_player_release (mlp);
561 libvlc_release (vlc);
570 test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
571 test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
572 test_media_list_player_previous (test_defaults_args, test_defaults_nargs);
573 test_media_list_player_next (test_defaults_args, test_defaults_nargs);
574 test_media_list_player_items_queue (test_defaults_args, test_defaults_nargs);
575 test_media_list_player_playback_options (test_defaults_args, test_defaults_nargs);