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 "../../lib/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 inline void wait_playing(libvlc_media_list_player_t
*mlp
)
69 while (!libvlc_media_list_player_is_playing (mlp
))
73 static inline void wait_stopped(libvlc_media_list_player_t
*mlp
)
75 while (libvlc_media_list_player_is_playing (mlp
))
79 static inline void stop_and_wait(libvlc_media_list_player_t
*mlp
)
81 libvlc_media_list_player_stop (mlp
);
85 static void check_items_order_callback(const libvlc_event_t
* p_event
, void * user_data
)
87 struct check_items_order_data
*checks
= user_data
;
88 libvlc_media_t
*md
= p_event
->u
.media_list_player_next_item_set
.item
;
89 assert(checks
->index
< checks
->count
);
90 if (checks
->items
[checks
->index
] != md
)
92 char *title
= libvlc_media_get_meta(md
, libvlc_meta_Title
);
93 log ("Got items %s\n", title
);
96 assert(checks
->items
[checks
->index
] == md
);
98 char *title
= libvlc_media_get_meta(md
, libvlc_meta_Title
);
99 log ("Item %d '%s' was correctly queued\n", checks
->index
, title
);
102 if (checks
->index
== (checks
->count
- 1))
104 log ("Done playing with success\n");
105 checks
->done_playing
= true;
110 static void test_media_list_player_items_queue(const char** argv
, int argc
)
112 libvlc_instance_t
*vlc
;
114 libvlc_media_list_t
*ml
;
115 libvlc_media_list_player_t
*mlp
;
117 const char * file
= test_default_sample
;
119 log ("Testing media player item queue-ing\n");
121 vlc
= libvlc_new (argc
, argv
);
122 assert (vlc
!= NULL
);
124 md
= libvlc_media_new_path (vlc
, file
);
127 ml
= libvlc_media_list_new (vlc
);
130 mlp
= libvlc_media_list_player_new (vlc
);
133 libvlc_media_list_add_media (ml
, md
);
135 static struct check_items_order_data check
;
136 check_data_init(&check
);
137 queue_expected_item(&check
, md
);
139 // Add three more media
140 queue_expected_item(&check
, media_list_add_file_path (vlc
, ml
, file
));
141 queue_expected_item(&check
, media_list_add_file_path (vlc
, ml
, file
));
142 queue_expected_item(&check
, media_list_add_file_path (vlc
, ml
, file
));
145 libvlc_media_t
*node
= libvlc_media_new_as_node(vlc
, "node");
147 libvlc_media_list_add_media(ml
, node
);
148 queue_expected_item(&check
, node
);
150 // Add items to that node
151 libvlc_media_list_t
*subitems
= libvlc_media_subitems(node
);
152 queue_expected_item(&check
, media_list_add_file_path(vlc
, subitems
, file
));
153 queue_expected_item(&check
, media_list_add_file_path(vlc
, subitems
, file
));
154 queue_expected_item(&check
, media_list_add_file_path(vlc
, subitems
, file
));
155 libvlc_media_list_release(subitems
);
157 libvlc_media_list_player_set_media_list (mlp
, ml
);
159 libvlc_event_manager_t
* em
= libvlc_media_list_player_event_manager(mlp
);
160 int val
= libvlc_event_attach(em
, libvlc_MediaListPlayerNextItemSet
,
161 check_items_order_callback
, &check
);
164 libvlc_media_list_player_play(mlp
);
166 // Wait until all item are read
167 wait_queued_items(&check
);
171 libvlc_media_list_player_release (mlp
);
172 libvlc_release (vlc
);
175 static void test_media_list_player_previous(const char** argv
, int argc
)
177 libvlc_instance_t
*vlc
;
179 libvlc_media_list_t
*ml
;
180 libvlc_media_list_player_t
*mlp
;
182 const char * file
= test_default_sample
;
184 log ("Testing media player previous()\n");
186 vlc
= libvlc_new (argc
, argv
);
187 assert (vlc
!= NULL
);
189 md
= libvlc_media_new_path (vlc
, file
);
192 ml
= libvlc_media_list_new (vlc
);
195 mlp
= libvlc_media_list_player_new (vlc
);
198 libvlc_media_list_add_media (ml
, md
);
201 media_list_add_file_path (vlc
, ml
, file
);
202 media_list_add_file_path (vlc
, ml
, file
);
203 media_list_add_file_path (vlc
, ml
, file
);
205 libvlc_media_list_player_set_media_list (mlp
, ml
);
207 libvlc_media_list_player_play_item (mlp
, md
);
211 libvlc_media_release (md
);
213 libvlc_media_list_player_previous (mlp
);
217 libvlc_media_list_player_pause (mlp
);
218 libvlc_media_list_player_previous (mlp
);
224 libvlc_media_list_player_previous (mlp
);
230 libvlc_media_list_player_release (mlp
);
231 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 vlc
= libvlc_new (argc
, argv
);
246 assert (vlc
!= NULL
);
248 md
= libvlc_media_new_path (vlc
, file
);
251 ml
= libvlc_media_list_new (vlc
);
254 mlp
= libvlc_media_list_player_new (vlc
);
257 libvlc_media_list_add_media (ml
, md
);
260 media_list_add_file_path (vlc
, ml
, file
);
261 media_list_add_file_path (vlc
, ml
, file
);
262 media_list_add_file_path (vlc
, ml
, file
);
264 libvlc_media_list_player_set_media_list (mlp
, ml
);
266 libvlc_media_list_player_play_item (mlp
, md
);
268 libvlc_media_release (md
);
272 libvlc_media_list_player_next (mlp
);
276 libvlc_media_list_player_pause (mlp
);
277 libvlc_media_list_player_next (mlp
);
283 libvlc_media_list_player_next (mlp
);
289 libvlc_media_list_player_release (mlp
);
290 libvlc_release (vlc
);
293 static void test_media_list_player_pause_stop(const char** argv
, int argc
)
295 libvlc_instance_t
*vlc
;
297 libvlc_media_list_t
*ml
;
298 libvlc_media_list_player_t
*mlp
;
300 const char * file
= test_default_sample
;
302 log ("Testing play and pause of %s using the media list.\n", file
);
304 vlc
= libvlc_new (argc
, argv
);
305 assert (vlc
!= NULL
);
307 md
= libvlc_media_new_path (vlc
, file
);
310 ml
= libvlc_media_list_new (vlc
);
313 mlp
= libvlc_media_list_player_new (vlc
);
316 libvlc_media_list_add_media( ml
, md
);
318 libvlc_media_list_player_set_media_list( mlp
, ml
);
320 libvlc_media_list_player_play_item( mlp
, md
);
324 libvlc_media_list_player_pause (mlp
);
328 libvlc_media_release (md
);
329 libvlc_media_list_player_release (mlp
);
330 libvlc_release (vlc
);
333 static void test_media_list_player_play_item_at_index(const char** argv
, int argc
)
335 libvlc_instance_t
*vlc
;
337 libvlc_media_list_t
*ml
;
338 libvlc_media_list_player_t
*mlp
;
340 const char * file
= test_default_sample
;
342 log ("Testing play_item_at_index of %s using the media list.\n", file
);
344 vlc
= libvlc_new (argc
, argv
);
345 assert (vlc
!= NULL
);
347 md
= libvlc_media_new_path (vlc
, file
);
350 ml
= libvlc_media_list_new (vlc
);
353 mlp
= libvlc_media_list_player_new (vlc
);
356 for (unsigned i
= 0; i
< 5; i
++)
357 libvlc_media_list_add_media( ml
, md
);
359 libvlc_media_list_player_set_media_list( mlp
, ml
);
360 libvlc_media_list_player_play_item_at_index( mlp
, 0 );
366 libvlc_media_release (md
);
367 libvlc_media_list_player_release (mlp
);
368 libvlc_release (vlc
);
371 static void test_media_list_player_playback_options (const char** argv
, int argc
)
373 libvlc_instance_t
*vlc
;
379 libvlc_media_list_t
*ml
;
380 libvlc_media_list_t
*ml2
;
381 libvlc_media_list_t
*ml3
;
382 libvlc_media_list_t
*ml4
;
383 libvlc_media_list_t
*ml5
;
384 libvlc_media_list_t
*ml6
;
385 libvlc_media_list_player_t
*mlp
;
387 const char * file
= test_default_sample
;
389 log ("Testing media player playback options()\n");
391 vlc
= libvlc_new (argc
, argv
);
392 assert (vlc
!= NULL
);
395 * Create the following media tree:
397 * ml1: 0 ---- 1 ---- 2
399 * ml2&4: 0 -- 1 | 0 -- 1 -- 2
401 * ml3: 0 -- 1 -- 2 -- 3 -- 4 -- 5 -- 6
406 md
= libvlc_media_new_path (vlc
, file
);
409 md2
= libvlc_media_new_path (vlc
, file
);
412 md3
= libvlc_media_new_path (vlc
, file
);
415 md4
= libvlc_media_new_path (vlc
, file
);
418 md5
= libvlc_media_new_path (vlc
, file
);
421 ml
= libvlc_media_list_new (vlc
);
424 ml2
= libvlc_media_list_new (vlc
);
425 assert (ml2
!= NULL
);
427 ml3
= libvlc_media_list_new (vlc
);
428 assert (ml3
!= NULL
);
430 ml4
= libvlc_media_list_new (vlc
);
431 assert (ml4
!= NULL
);
433 ml5
= libvlc_media_list_new (vlc
);
434 assert (ml5
!= NULL
);
436 ml6
= libvlc_media_list_new (vlc
);
437 assert (ml6
!= NULL
);
439 media_list_add_file_path (vlc
, ml2
, file
);
440 media_list_add_file_path (vlc
, ml2
, file
);
442 media_list_add_file_path (vlc
, ml3
, file
);
443 media_list_add_file_path (vlc
, ml3
, file
);
444 libvlc_media_list_add_media (ml3
, md4
);
445 media_list_add_file_path (vlc
, ml3
, file
);
446 media_list_add_file_path (vlc
, ml3
, file
);
447 media_list_add_file_path (vlc
, ml3
, file
);
448 libvlc_media_list_add_media (ml3
, md5
);
450 media_list_add_file_path (vlc
, ml4
, file
);
451 media_list_add_file_path (vlc
, ml4
, file
);
452 media_list_add_file_path (vlc
, ml4
, file
);
454 media_list_add_file_path (vlc
, ml5
, file
);
456 media_list_add_file_path (vlc
, ml6
, file
);
457 media_list_add_file_path (vlc
, ml6
, file
);
459 md
->p_subitems
= ml2
;
460 md2
->p_subitems
= ml3
;
461 md3
->p_subitems
= ml4
;
462 md4
->p_subitems
= ml5
;
463 md5
->p_subitems
= ml6
;
465 libvlc_media_list_add_media (ml
, md
);
466 libvlc_media_list_add_media (ml
, md2
);
467 libvlc_media_list_add_media (ml
, md3
);
469 mlp
= libvlc_media_list_player_new (vlc
);
472 libvlc_media_list_player_set_media_list (mlp
, ml
);
474 // Test default playback mode
475 libvlc_media_list_player_set_playback_mode(mlp
, libvlc_playback_mode_default
);
477 libvlc_media_list_player_play_item (mlp
, md
);
481 libvlc_media_release (md
);
482 libvlc_media_release (md2
);
483 libvlc_media_release (md3
);
484 libvlc_media_release (md4
);
485 libvlc_media_release (md5
);
487 libvlc_media_list_player_stop (mlp
);
489 while (libvlc_media_list_player_is_playing (mlp
))
492 // Test looping playback mode
493 log ("Testing media player playback option - Loop\n");
494 libvlc_media_list_player_set_playback_mode(mlp
, libvlc_playback_mode_loop
);
496 libvlc_media_list_player_play_item (mlp
, md
);
502 // Test repeat playback mode
503 log ("Testing media player playback option - Repeat\n");
504 libvlc_media_list_player_set_playback_mode(mlp
, libvlc_playback_mode_repeat
);
506 libvlc_media_list_player_play_item (mlp
, md
);
512 libvlc_media_list_player_release (mlp
);
513 libvlc_release (vlc
);
521 // There are 6 tests. And they take some times.
524 test_media_list_player_pause_stop (test_defaults_args
, test_defaults_nargs
);
525 test_media_list_player_play_item_at_index (test_defaults_args
, test_defaults_nargs
);
526 test_media_list_player_previous (test_defaults_args
, test_defaults_nargs
);
527 test_media_list_player_next (test_defaults_args
, test_defaults_nargs
);
528 test_media_list_player_items_queue (test_defaults_args
, test_defaults_nargs
);
529 test_media_list_player_playback_options (test_defaults_args
, test_defaults_nargs
);