forked from videolan/vlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia_list_player.c
531 lines (384 loc) · 14.1 KB
/
media_list_player.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
/*
* media_list_player.c - libvlc smoke test
*
* $Id$
*/
/**********************************************************************
* Copyright (C) 2007 Rémi Denis-Courmont. *
* This program is free software; you can redistribute and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation; version 2 of the license, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, you can get it from: *
* http://www.gnu.org/copyleft/gpl.html *
**********************************************************************/
#include "test.h"
// For msleep
#include <vlc_common.h>
#include <vlc_mtime.h>
#include "libvlc_additions.h"
/*
HACK - FIX ME
This allows for the direct addition of subitems in the playback options test.
This would not be necessary if there were an add subitems function.
*/
#include "../../lib/media_internal.h"
struct check_items_order_data {
bool done_playing;
unsigned count;
unsigned index;
void * items[16];
};
static inline void check_data_init(struct check_items_order_data *check)
{
check->index = 0;
check->count = 0;
check->done_playing = false;
}
static inline void queue_expected_item(struct check_items_order_data *check, void *item)
{
assert(check->count < 16);
check->items[check->count] = item;
check->count++;
}
static inline void wait_queued_items(struct check_items_order_data *check)
{
// Wait dummily for check_items_order_callback() to flag 'done_playing':
while (!check->done_playing)
sched_yield();
}
static inline void wait_playing(libvlc_media_list_player_t *mlp)
{
while (!libvlc_media_list_player_is_playing (mlp))
sched_yield();
}
static inline void wait_stopped(libvlc_media_list_player_t *mlp)
{
while (libvlc_media_list_player_is_playing (mlp))
sched_yield();
}
static inline void stop_and_wait(libvlc_media_list_player_t *mlp)
{
libvlc_media_list_player_stop (mlp);
wait_stopped (mlp);
}
static void check_items_order_callback(const libvlc_event_t * p_event, void * user_data)
{
struct check_items_order_data *checks = user_data;
libvlc_media_t *md = p_event->u.media_list_player_next_item_set.item;
assert(checks->index < checks->count);
if (checks->items[checks->index] != md)
{
char *title = libvlc_media_get_meta(md, libvlc_meta_Title);
log ("Got items %s\n", title);
free(title);
}
assert(checks->items[checks->index] == md);
char *title = libvlc_media_get_meta(md, libvlc_meta_Title);
log ("Item %d '%s' was correctly queued\n", checks->index, title);
free(title);
if (checks->index == (checks->count - 1))
{
log ("Done playing with success\n");
checks->done_playing = true;
}
checks->index++;
}
static void test_media_list_player_items_queue(const char** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md;
libvlc_media_list_t *ml;
libvlc_media_list_player_t *mlp;
const char * file = test_default_sample;
log ("Testing media player item queue-ing\n");
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new_path (vlc, file);
assert(md);
ml = libvlc_media_list_new (vlc);
assert (ml != NULL);
mlp = libvlc_media_list_player_new (vlc);
assert(mlp);
libvlc_media_list_add_media (ml, md);
static struct check_items_order_data check;
check_data_init(&check);
queue_expected_item(&check, md);
// Add three more media
queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
// Add a node
libvlc_media_t *node = libvlc_media_new_as_node(vlc, "node");
assert(node);
libvlc_media_list_add_media(ml, node);
queue_expected_item(&check, node);
// Add items to that node
libvlc_media_list_t *subitems = libvlc_media_subitems(node);
queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
libvlc_media_list_release(subitems);
libvlc_media_list_player_set_media_list (mlp, ml);
libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
int val = libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet,
check_items_order_callback, &check);
assert(val == 0);
libvlc_media_list_player_play(mlp);
// Wait until all item are read
wait_queued_items(&check);
stop_and_wait (mlp);
libvlc_media_list_player_release (mlp);
libvlc_release (vlc);
}
static void test_media_list_player_previous(const char** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md;
libvlc_media_list_t *ml;
libvlc_media_list_player_t *mlp;
const char * file = test_default_sample;
log ("Testing media player previous()\n");
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new_path (vlc, file);
assert(md);
ml = libvlc_media_list_new (vlc);
assert (ml != NULL);
mlp = libvlc_media_list_player_new (vlc);
assert(mlp);;
libvlc_media_list_add_media (ml, md);
// Add three media
media_list_add_file_path (vlc, ml, file);
media_list_add_file_path (vlc, ml, file);
media_list_add_file_path (vlc, ml, file);
libvlc_media_list_player_set_media_list (mlp, ml);
libvlc_media_list_player_play_item (mlp, md);
wait_playing (mlp);
libvlc_media_release (md);
libvlc_media_list_player_previous (mlp);
wait_playing (mlp);
libvlc_media_list_player_pause (mlp);
libvlc_media_list_player_previous (mlp);
wait_playing (mlp);
stop_and_wait (mlp);
libvlc_media_list_player_previous (mlp);
wait_playing (mlp);
stop_and_wait (mlp);
libvlc_media_list_player_release (mlp);
libvlc_release (vlc);
}
static void test_media_list_player_next(const char** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md;
libvlc_media_list_t *ml;
libvlc_media_list_player_t *mlp;
const char * file = test_default_sample;
log ("Testing media player next()\n");
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new_path (vlc, file);
assert(md);
ml = libvlc_media_list_new (vlc);
assert (ml != NULL);
mlp = libvlc_media_list_player_new (vlc);
assert(mlp);
libvlc_media_list_add_media (ml, md);
// Add three media
media_list_add_file_path (vlc, ml, file);
media_list_add_file_path (vlc, ml, file);
media_list_add_file_path (vlc, ml, file);
libvlc_media_list_player_set_media_list (mlp, ml);
libvlc_media_list_player_play_item (mlp, md);
libvlc_media_release (md);
wait_playing (mlp);
libvlc_media_list_player_next (mlp);
wait_playing (mlp);
libvlc_media_list_player_pause (mlp);
libvlc_media_list_player_next (mlp);
wait_playing (mlp);
stop_and_wait (mlp);
libvlc_media_list_player_next (mlp);
wait_playing (mlp);
stop_and_wait (mlp);
libvlc_media_list_player_release (mlp);
libvlc_release (vlc);
}
static void test_media_list_player_pause_stop(const char** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md;
libvlc_media_list_t *ml;
libvlc_media_list_player_t *mlp;
const char * file = test_default_sample;
log ("Testing play and pause of %s using the media list.\n", file);
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new_path (vlc, file);
assert(md);
ml = libvlc_media_list_new (vlc);
assert (ml != NULL);
mlp = libvlc_media_list_player_new (vlc);
assert(mlp);
libvlc_media_list_add_media( ml, md);
libvlc_media_list_player_set_media_list( mlp, ml );
libvlc_media_list_player_play_item( mlp, md );
wait_playing (mlp);
libvlc_media_list_player_pause (mlp);
stop_and_wait (mlp);
libvlc_media_release (md);
libvlc_media_list_player_release (mlp);
libvlc_release (vlc);
}
static void test_media_list_player_play_item_at_index(const char** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md;
libvlc_media_list_t *ml;
libvlc_media_list_player_t *mlp;
const char * file = test_default_sample;
log ("Testing play_item_at_index of %s using the media list.\n", file);
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new_path (vlc, file);
assert(md);
ml = libvlc_media_list_new (vlc);
assert (ml != NULL);
mlp = libvlc_media_list_player_new (vlc);
assert(mlp);
for (unsigned i = 0; i < 5; i++)
libvlc_media_list_add_media( ml, md );
libvlc_media_list_player_set_media_list( mlp, ml );
libvlc_media_list_player_play_item_at_index( mlp, 0 );
wait_playing (mlp);
stop_and_wait (mlp);
libvlc_media_release (md);
libvlc_media_list_player_release (mlp);
libvlc_release (vlc);
}
static void test_media_list_player_playback_options (const char** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md;
libvlc_media_t *md2;
libvlc_media_t *md3;
libvlc_media_t *md4;
libvlc_media_t *md5;
libvlc_media_list_t *ml;
libvlc_media_list_t *ml2;
libvlc_media_list_t *ml3;
libvlc_media_list_t *ml4;
libvlc_media_list_t *ml5;
libvlc_media_list_t *ml6;
libvlc_media_list_player_t *mlp;
const char * file = test_default_sample;
log ("Testing media player playback options()\n");
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
/*
* Create the following media tree:
*
* ml1: 0 ---- 1 ---- 2
* / | \
* ml2&4: 0 -- 1 | 0 -- 1 -- 2
* |
* ml3: 0 -- 1 -- 2 -- 3 -- 4 -- 5 -- 6
* | |
* ml5&6: 0 0 -- 1
*/
md = libvlc_media_new_path (vlc, file);
assert(md);
md2 = libvlc_media_new_path (vlc, file);
assert(md2);
md3 = libvlc_media_new_path (vlc, file);
assert(md3);
md4 = libvlc_media_new_path (vlc, file);
assert(md4);
md5 = libvlc_media_new_path (vlc, file);
assert(md5);
ml = libvlc_media_list_new (vlc);
assert (ml != NULL);
ml2 = libvlc_media_list_new (vlc);
assert (ml2 != NULL);
ml3 = libvlc_media_list_new (vlc);
assert (ml3 != NULL);
ml4 = libvlc_media_list_new (vlc);
assert (ml4 != NULL);
ml5 = libvlc_media_list_new (vlc);
assert (ml5 != NULL);
ml6 = libvlc_media_list_new (vlc);
assert (ml6 != NULL);
media_list_add_file_path (vlc, ml2, file);
media_list_add_file_path (vlc, ml2, file);
media_list_add_file_path (vlc, ml3, file);
media_list_add_file_path (vlc, ml3, file);
libvlc_media_list_add_media (ml3, md4);
media_list_add_file_path (vlc, ml3, file);
media_list_add_file_path (vlc, ml3, file);
media_list_add_file_path (vlc, ml3, file);
libvlc_media_list_add_media (ml3, md5);
media_list_add_file_path (vlc, ml4, file);
media_list_add_file_path (vlc, ml4, file);
media_list_add_file_path (vlc, ml4, file);
media_list_add_file_path (vlc, ml5, file);
media_list_add_file_path (vlc, ml6, file);
media_list_add_file_path (vlc, ml6, file);
md->p_subitems = ml2;
md2->p_subitems = ml3;
md3->p_subitems = ml4;
md4->p_subitems = ml5;
md5->p_subitems = ml6;
libvlc_media_list_add_media (ml, md);
libvlc_media_list_add_media (ml, md2);
libvlc_media_list_add_media (ml, md3);
mlp = libvlc_media_list_player_new (vlc);
assert(mlp);
libvlc_media_list_player_set_media_list (mlp, ml);
// Test default playback mode
libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_default);
libvlc_media_list_player_play_item (mlp, md);
wait_playing (mlp);
libvlc_media_release (md);
libvlc_media_release (md2);
libvlc_media_release (md3);
libvlc_media_release (md4);
libvlc_media_release (md5);
libvlc_media_list_player_stop (mlp);
while (libvlc_media_list_player_is_playing (mlp))
sched_yield();
// Test looping playback mode
log ("Testing media player playback option - Loop\n");
libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_loop);
libvlc_media_list_player_play_item (mlp, md);
wait_playing (mlp);
stop_and_wait (mlp);
// Test repeat playback mode
log ("Testing media player playback option - Repeat\n");
libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_repeat);
libvlc_media_list_player_play_item (mlp, md);
wait_playing (mlp);
stop_and_wait (mlp);
libvlc_media_list_player_release (mlp);
libvlc_release (vlc);
}
int main (void)
{
test_init();
// There are 6 tests. And they take some times.
alarm(6 * 5);
test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
test_media_list_player_previous (test_defaults_args, test_defaults_nargs);
test_media_list_player_next (test_defaults_args, test_defaults_nargs);
test_media_list_player_items_queue (test_defaults_args, test_defaults_nargs);
test_media_list_player_playback_options (test_defaults_args, test_defaults_nargs);
return 0;
}