Coverage Report

Created: 2026-02-26 08:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/include/vlc_playlist.h
Line
Count
Source
1
/*****************************************************************************
2
 * vlc_playlist.h
3
 *****************************************************************************
4
 * Copyright (C) 2018 VLC authors and VideoLAN
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19
 *****************************************************************************/
20
21
#ifndef VLC_PLAYLIST_NEW_H
22
#define VLC_PLAYLIST_NEW_H
23
24
#include <vlc_common.h>
25
#include <vlc_preparser.h>
26
27
# ifdef __cplusplus
28
extern "C" {
29
# endif
30
31
/**
32
 * \defgroup playlist VLC playlist
33
 * \ingroup interface
34
 *
35
 * A VLC playlist contains a list of "playlist items".
36
 *
37
 * Each playlist item contains exactly one media (input item). In the future,
38
 * it might contain associated data.
39
 *
40
 * The API is intended to be simple, UI-friendly and allow for an
41
 * implementation both correct (no race conditions) and performant for common
42
 * use cases.
43
 *
44
 * UI frameworks typically use "list models" to provide a list of items to a
45
 * list view component. A list model requires to implement functions to:
46
 *  - return the total number of items,
47
 *  - return the item at a given index.
48
 *
49
 * In addition, it must notify the view when changes occur when:
50
 *  - items are inserted (providing index and count),
51
 *  - items are removed (providing index and count),
52
 *  - items are moved (providing index, count, and target index),
53
 *  - items are updated (providing index and count),
54
 *  - the model is reset (the whole content should be considered changed).
55
 *
56
 * The API directly exposes what list models require.
57
 *
58
 * The core playlist may be modified from any thread, so it may not be used as
59
 * a direct data source for a list model. In other words, the functions of a
60
 * list model must not delegate the calls to the playlist. This would require
61
 * locking the playlist individually for each call to get the count and
62
 * retrieve each item (which is, in itself, not a good idea for UI
63
 * responsiveness), and would not be sufficient to guarantee correctness: the
64
 * playlist content could change between view calls so that a request to
65
 * retrieve an item at a specific index could be invalid (which would break the
66
 * list model expected behavior).
67
 *
68
 * As a consequence, the UI playlist should be considered as a remote
69
 * out-of-sync view of the core playlist. This implies that the UI needs to
70
 * keep a copy of the playlist content.
71
 *
72
 * Note that the copy must not be limited to the list of playlist items
73
 * (pointers) themselves, but also to the item's content which is displayed and
74
 * susceptible to change asynchronously (e.g. media metadata, like title or
75
 * duration). The UI should never lock a media (input item) for rendering a
76
 * playlist item; otherwise, the content could be changed (and exposed) before
77
 * the list model notified the view of this change (which, again, would break
78
 * the list model expected behavior).
79
 *
80
 * It is very important that the copy held by the UI is only modified through
81
 * the core playlist callbacks, to guarantee that the indexes notified are
82
 * valid in the context of the list model. In other words, from the client, the
83
 * playlist copy is a read-only "desynchronized" view of the core playlist.
84
 *
85
 * Moreover, the events triggered by the playlist must be kept in order until
86
 * they are handled. The callbacks may be called from any thread, with lock
87
 * held (in practice, the thread from which a change is requested). A UI will
88
 * typically need to handle the events in the UI thread, so it will usually
89
 * post the events in an event loop, to handle them from the UI thread. In that
90
 * case, be careful to always post the events in the event loop, even if the
91
 * current thread is already the UI thread, not to break the order of events.
92
 *
93
 * The playlist also handles the playback order and the repeat mode. It also
94
 * manages a cursor to the "current" item, and exposes whether previous and
95
 * next items (which depend on the playback order and repeat mode) are
96
 * available.
97
 *
98
 * When a user requests to insert, move or remove items, or to set the current
99
 * item, before the core playlist lock is successfully acquired, another client
100
 * may have changed the list. Therefore, vlc_playlist_Request*() functions are
101
 * exposed to resolve potential conflicts and apply the changes. The actual
102
 * changes applied are notified through the callbacks.
103
 *
104
 * @{
105
 */
106
107
/* forward declarations */
108
typedef struct input_item_t input_item_t;
109
typedef struct vlc_player_t vlc_player_t;
110
111
/* opaque types */
112
typedef struct vlc_playlist vlc_playlist_t;
113
typedef struct vlc_playlist_item vlc_playlist_item_t;
114
typedef struct vlc_playlist_listener_id vlc_playlist_listener_id;
115
116
enum vlc_playlist_playback_repeat
117
{
118
    VLC_PLAYLIST_PLAYBACK_REPEAT_NONE,
119
    VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT,
120
    VLC_PLAYLIST_PLAYBACK_REPEAT_ALL,
121
};
122
123
enum vlc_playlist_playback_order
124
{
125
    VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL,
126
    VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM,
127
};
128
129
enum vlc_playlist_sort_key
130
{
131
    VLC_PLAYLIST_SORT_KEY_TITLE,
132
    VLC_PLAYLIST_SORT_KEY_DURATION,
133
    VLC_PLAYLIST_SORT_KEY_ARTIST,
134
    VLC_PLAYLIST_SORT_KEY_ALBUM,
135
    VLC_PLAYLIST_SORT_KEY_ALBUM_ARTIST,
136
    VLC_PLAYLIST_SORT_KEY_GENRE,
137
    VLC_PLAYLIST_SORT_KEY_DATE,
138
    VLC_PLAYLIST_SORT_KEY_TRACK_NUMBER,
139
    VLC_PLAYLIST_SORT_KEY_DISC_NUMBER,
140
    VLC_PLAYLIST_SORT_KEY_URL,
141
    VLC_PLAYLIST_SORT_KEY_RATING,
142
    VLC_PLAYLIST_SORT_KEY_FILE_SIZE,
143
    VLC_PLAYLIST_SORT_KEY_FILE_MODIFIED
144
};
145
146
enum vlc_playlist_sort_order
147
{
148
    VLC_PLAYLIST_SORT_ORDER_ASCENDING,
149
    VLC_PLAYLIST_SORT_ORDER_DESCENDING,
150
};
151
152
struct vlc_playlist_sort_criterion
153
{
154
    enum vlc_playlist_sort_key key;
155
    enum vlc_playlist_sort_order order;
156
};
157
158
/** Preparsing depth */
159
enum vlc_playlist_preparsing
160
{
161
    /** Don't parse anything */
162
    VLC_PLAYLIST_PREPARSING_DISABLED,
163
    /** Auto parse items but don't auto-parse sub items */
164
    VLC_PLAYLIST_PREPARSING_ENABLED,
165
    /** Auto parse sub items of items (1 level depth) */
166
    VLC_PLAYLIST_PREPARSING_COLLAPSE,
167
    /** Auto parse all sub items recursively */
168
    VLC_PLAYLIST_PREPARSING_RECURSIVE,
169
};
170
171
/**
172
 * Action when a media is stopped
173
 *
174
 * @see vlc_playlist_SetMediaStoppedAction()
175
 */
176
enum vlc_playlist_media_stopped_action {
177
    /** Continue (or stop if there is no next media), default behavior */
178
    VLC_PLAYLIST_MEDIA_STOPPED_CONTINUE,
179
    /** Stop, even if there is a next media to play */
180
    VLC_PLAYLIST_MEDIA_STOPPED_STOP,
181
    /** Exit VLC */
182
    VLC_PLAYLIST_MEDIA_STOPPED_EXIT,
183
};
184
185
/**
186
 * Playlist callbacks.
187
 *
188
 * A client may register a listener using vlc_playlist_AddListener() to listen
189
 * playlist events.
190
 *
191
 * All callbacks are called with the playlist locked (see vlc_playlist_Lock()).
192
 */
193
struct vlc_playlist_callbacks
194
{
195
    /**
196
     * Called when the whole content has changed (e.g. when the playlist has
197
     * been cleared, shuffled or sorted).
198
     *
199
     * \param playlist the playlist
200
     * \param items    the whole new content of the playlist
201
     * \param count    the number of items
202
     * \param userdata userdata provided to AddListener()
203
     */
204
    void
205
    (*on_items_reset)(vlc_playlist_t *, vlc_playlist_item_t *const items[],
206
                      size_t count, void *userdata);
207
208
    /**
209
     * Called when items have been added to the playlist.
210
     *
211
     * \param playlist the playlist
212
     * \param index    the index of the insertion
213
     * \param items    the array of added items
214
     * \param count    the number of items added
215
     * \param userdata userdata provided to AddListener()
216
     */
217
    void
218
    (*on_items_added)(vlc_playlist_t *playlist, size_t index,
219
                      vlc_playlist_item_t *const items[], size_t count,
220
                      void *userdata);
221
222
    /**
223
     * Called when a slice of items have been moved.
224
     *
225
     * \param playlist the playlist
226
     * \param index    the index of the first moved item
227
     * \param count    the number of items moved
228
     * \param target   the new index of the moved slice
229
     * \param userdata userdata provided to AddListener()
230
     */
231
    void
232
    (*on_items_moved)(vlc_playlist_t *playlist, size_t index, size_t count,
233
                      size_t target, void *userdata);
234
    /**
235
     * Called when a slice of items have been removed from the playlist.
236
     *
237
     * \param playlist the playlist
238
     * \param index    the index of the first removed item
239
     * \param count    the number of items removed
240
     * \param userdata userdata provided to AddListener()
241
     */
242
    void
243
    (*on_items_removed)(vlc_playlist_t *playlist, size_t index, size_t count,
244
                        void *userdata);
245
246
    /**
247
     * Called when an item has been updated via (pre-)parsing.
248
     *
249
     * \param playlist the playlist
250
     * \param index    the index of the first updated item
251
     * \param items    the array of updated items
252
     * \param count    the number of items updated
253
     * \param userdata userdata provided to AddListener()
254
     */
255
    void
256
    (*on_items_updated)(vlc_playlist_t *playlist, size_t index,
257
                        vlc_playlist_item_t *const items[], size_t count,
258
                        void *userdata);
259
260
    /**
261
     * Called when the playback repeat mode has been changed.
262
     *
263
     * \param playlist the playlist
264
     * \param repeat   the new playback "repeat" mode
265
     * \param userdata userdata provided to AddListener()
266
     */
267
    void
268
    (*on_playback_repeat_changed)(vlc_playlist_t *playlist,
269
                                  enum vlc_playlist_playback_repeat repeat,
270
                                  void *userdata);
271
272
    /**
273
     * Called when the playback order mode has been changed.
274
     *
275
     * \param playlist the playlist
276
     * \param rorder   the new playback order
277
     * \param userdata userdata provided to AddListener()
278
     */
279
    void
280
    (*on_playback_order_changed)(vlc_playlist_t *playlist,
281
                                 enum vlc_playlist_playback_order order,
282
                                 void *userdata);
283
284
    /**
285
     * Called when the current item index has changed.
286
     *
287
     * Note that the current item index may have changed while the current item
288
     * is still the same: it may have been moved.
289
     *
290
     * \param playlist the playlist
291
     * \param index    the new current index (-1 if there is no current item)
292
     * \param userdata userdata provided to AddListener()
293
     */
294
    void
295
    (*on_current_index_changed)(vlc_playlist_t *playlist, ssize_t index,
296
                                void *userdata);
297
298
    /**
299
     * Called when the "has previous item" property has changed.
300
     *
301
     * This is typically useful to update any "previous" button in the UI.
302
     *
303
     * \param playlist the playlist
304
     * \param has_prev true if there is a previous item, false otherwise
305
     * \param userdata userdata provided to AddListener()
306
     */
307
    void
308
    (*on_has_prev_changed)(vlc_playlist_t *playlist, bool has_prev,
309
                           void *userdata);
310
311
    /**
312
     * Called when the "has next item" property has changed.
313
     *
314
     * This is typically useful to update any "next" button in the UI.
315
     *
316
     * \param playlist the playlist
317
     * \param has_next true if there is a next item, false otherwise
318
     * \param userdata userdata provided to AddListener()
319
     */
320
    void
321
    (*on_has_next_changed)(vlc_playlist_t *playlist,
322
                           bool has_next, void *userdata);
323
324
    /**
325
     * Called when the stopped action has changed
326
     *
327
     * @see vlc_playlist_SetMediaStoppedAction()
328
     *
329
     * \param playlist the playlist
330
     * @param new_action action to execute when a media is stopped
331
     * \param userdata userdata provided to AddListener()
332
     */
333
    void (*on_media_stopped_action_changed)(vlc_playlist_t *playlist,
334
                                            enum vlc_playlist_media_stopped_action new_action,
335
                                            void *userdata);
336
};
337
338
/* Playlist items */
339
340
/**
341
 * Hold a playlist item.
342
 *
343
 * Increment the refcount of the playlist item.
344
 */
345
VLC_API void
346
vlc_playlist_item_Hold(vlc_playlist_item_t *);
347
348
/**
349
 * Release a playlist item.
350
 *
351
 * Decrement the refcount of the playlist item, and destroy it if necessary.
352
 */
353
VLC_API void
354
vlc_playlist_item_Release(vlc_playlist_item_t *);
355
356
/**
357
 * Return the media associated to the playlist item.
358
 */
359
VLC_API input_item_t *
360
vlc_playlist_item_GetMedia(vlc_playlist_item_t *);
361
362
/**
363
 * Return a unique id for the playlist item instance.
364
 */
365
VLC_API uint64_t
366
vlc_playlist_item_GetId(vlc_playlist_item_t *);
367
368
/* Playlist */
369
370
/**
371
 * Create a new playlist.
372
 *
373
 * \param parent   a VLC object
374
 * \param rec preparsing depth
375
 * \param preparse_max_threads the maximum number of threads used to parse, must be >= 1
376
 * \param preparse_timeout default timeout of the preparser, 0 for no limits.
377
 * \return a pointer to a valid playlist instance, or NULL if an error occurred
378
 */
379
VLC_API VLC_USED vlc_playlist_t *
380
vlc_playlist_New(vlc_object_t *parent, enum vlc_playlist_preparsing rec,
381
                 unsigned preparse_max_threads, vlc_tick_t preparse_timeout);
382
383
/**
384
 * Delete a playlist.
385
 *
386
 * All playlist items are released, and listeners are removed and destroyed.
387
 */
388
VLC_API void
389
vlc_playlist_Delete(vlc_playlist_t *);
390
391
/**
392
 * Lock the playlist/player.
393
 *
394
 * The playlist and its player share the same lock, to avoid lock-order
395
 * inversion issues.
396
 *
397
 * \warning Do not forget that the playlist and player lock are the same (or
398
 * you could lock twice the same and deadlock).
399
 *
400
 * Almost all playlist functions must be called with lock held (check their
401
 * description).
402
 *
403
 * The lock is not recursive.
404
 */
405
VLC_API void
406
vlc_playlist_Lock(vlc_playlist_t *);
407
408
/**
409
 * Unlock the playlist/player.
410
 */
411
VLC_API void
412
vlc_playlist_Unlock(vlc_playlist_t *);
413
414
/**
415
 * Add a playlist listener.
416
 *
417
 * Return an opaque listener identifier, to be passed to
418
 * vlc_player_RemoveListener().
419
 *
420
 * If notify_current_state is true, the callbacks are called once with the
421
 * current state of the playlist. This is useful because when a client
422
 * registers to the playlist, it may already contain items. Calling callbacks
423
 * is a convenient way to initialize the client automatically.
424
 *
425
 * \param playlist             the playlist, locked
426
 * \param cbs                  the callbacks (must be valid until the listener
427
 *                             is removed)
428
 * \param userdata             userdata provided as a parameter in callbacks
429
 * \param notify_current_state true to notify the current state immediately via
430
 *                             callbacks
431
 * \return a listener identifier, or NULL if an error occurred
432
 */
433
VLC_API VLC_USED vlc_playlist_listener_id *
434
vlc_playlist_AddListener(vlc_playlist_t *playlist,
435
                         const struct vlc_playlist_callbacks *cbs,
436
                         void *userdata, bool notify_current_state);
437
438
/**
439
 * Remove a player listener.
440
 *
441
 * \param playlist the playlist, locked
442
 * \param id       the listener identifier returned by
443
 *                 vlc_playlist_AddListener()
444
 */
445
VLC_API void
446
vlc_playlist_RemoveListener(vlc_playlist_t *playlist,
447
                            vlc_playlist_listener_id *id);
448
449
/**
450
 * Setup an action when a media is stopped
451
 *
452
 * @param playlist the playlist, locked
453
 * @param action action to do when a media is stopped
454
 */
455
VLC_API void
456
vlc_playlist_SetMediaStoppedAction(vlc_playlist_t *playlist,
457
                              enum vlc_playlist_media_stopped_action action);
458
459
/**
460
 * Return the number of items.
461
 *
462
 * \param playlist the playlist, locked
463
 */
464
VLC_API size_t
465
vlc_playlist_Count(vlc_playlist_t *playlist);
466
467
/**
468
 * Return the item at a given index.
469
 *
470
 * The index must be in range (less than vlc_playlist_Count()).
471
 *
472
 * \param playlist the playlist, locked
473
 * \param index    the index
474
 * \return the playlist item
475
 */
476
VLC_API vlc_playlist_item_t *
477
vlc_playlist_Get(vlc_playlist_t *playlist, size_t index);
478
479
/**
480
 * Clear the playlist.
481
 *
482
 * \param playlist the playlist, locked
483
 */
484
VLC_API void
485
vlc_playlist_Clear(vlc_playlist_t *playlist);
486
487
/**
488
 * Insert a list of media at a given index.
489
 *
490
 * The index must be in range (less than or equal to vlc_playlist_Count()).
491
 *
492
 * \param playlist the playlist, locked
493
 * \param index    the index where the media are to be inserted
494
 * \param media    the array of media to insert
495
 * \param count    the number of media to insert
496
 * \return VLC_SUCCESS on success, another value on error
497
 */
498
VLC_API int
499
vlc_playlist_Insert(vlc_playlist_t *playlist, size_t index,
500
                    input_item_t *const media[], size_t count);
501
502
/**
503
 * Insert a media at a given index.
504
 *
505
 * The index must be in range (less than or equal to vlc_playlist_Count()).
506
 *
507
 * \param playlist the playlist, locked
508
 * \param index    the index where the media is to be inserted
509
 * \param media    the media to insert
510
 * \return VLC_SUCCESS on success, another value on error
511
 */
512
static inline int
513
vlc_playlist_InsertOne(vlc_playlist_t *playlist, size_t index,
514
                       input_item_t *media)
515
0
{
516
0
    return vlc_playlist_Insert(playlist, index, &media, 1);
517
0
}
Unexecuted instantiation: libvlc.c:vlc_playlist_InsertOne
Unexecuted instantiation: media_source.c:vlc_playlist_InsertOne
Unexecuted instantiation: interface.c:vlc_playlist_InsertOne
Unexecuted instantiation: content.c:vlc_playlist_InsertOne
Unexecuted instantiation: control.c:vlc_playlist_InsertOne
Unexecuted instantiation: item.c:vlc_playlist_InsertOne
Unexecuted instantiation: notify.c:vlc_playlist_InsertOne
Unexecuted instantiation: player.c:vlc_playlist_InsertOne
Unexecuted instantiation: playlist.c:vlc_playlist_InsertOne
Unexecuted instantiation: preparse.c:vlc_playlist_InsertOne
518
519
/**
520
 * Add a list of media at the end of the playlist.
521
 *
522
 * \param playlist the playlist, locked
523
 * \param media    the array of media to append
524
 * \param count    the number of media to append
525
 * \return VLC_SUCCESS on success, another value on error
526
 */
527
static inline int
528
vlc_playlist_Append(vlc_playlist_t *playlist, input_item_t *const media[],
529
                    size_t count)
530
0
{
531
0
    size_t size = vlc_playlist_Count(playlist);
532
0
    return vlc_playlist_Insert(playlist, size, media, count);
533
0
}
Unexecuted instantiation: libvlc.c:vlc_playlist_Append
Unexecuted instantiation: media_source.c:vlc_playlist_Append
Unexecuted instantiation: interface.c:vlc_playlist_Append
Unexecuted instantiation: content.c:vlc_playlist_Append
Unexecuted instantiation: control.c:vlc_playlist_Append
Unexecuted instantiation: item.c:vlc_playlist_Append
Unexecuted instantiation: notify.c:vlc_playlist_Append
Unexecuted instantiation: player.c:vlc_playlist_Append
Unexecuted instantiation: playlist.c:vlc_playlist_Append
Unexecuted instantiation: preparse.c:vlc_playlist_Append
534
535
/**
536
 * Add a media at the end of the playlist.
537
 *
538
 * \param playlist the playlist, locked
539
 * \param media    the media to append
540
 * \return VLC_SUCCESS on success, another value on error
541
 */
542
static inline int
543
vlc_playlist_AppendOne(vlc_playlist_t *playlist, input_item_t *media)
544
0
{
545
0
    return vlc_playlist_Append(playlist, &media, 1);
546
0
}
Unexecuted instantiation: libvlc.c:vlc_playlist_AppendOne
Unexecuted instantiation: media_source.c:vlc_playlist_AppendOne
Unexecuted instantiation: interface.c:vlc_playlist_AppendOne
Unexecuted instantiation: content.c:vlc_playlist_AppendOne
Unexecuted instantiation: control.c:vlc_playlist_AppendOne
Unexecuted instantiation: item.c:vlc_playlist_AppendOne
Unexecuted instantiation: notify.c:vlc_playlist_AppendOne
Unexecuted instantiation: player.c:vlc_playlist_AppendOne
Unexecuted instantiation: playlist.c:vlc_playlist_AppendOne
Unexecuted instantiation: preparse.c:vlc_playlist_AppendOne
547
548
/**
549
 * Move a slice of items to a given target index.
550
 *
551
 * The slice and the target must be in range (both index+count and target+count
552
 * less than or equal to vlc_playlist_Count()).
553
 *
554
 * \param playlist the playlist, locked
555
 * \param index    the index of the first item to move
556
 * \param count    the number of items to move
557
 * \param target   the new index of the moved slice
558
 */
559
VLC_API void
560
vlc_playlist_Move(vlc_playlist_t *playlist, size_t index, size_t count,
561
                  size_t target);
562
563
/**
564
 * Move an item to a given target index.
565
 *
566
 * The index and the target must be in range (index less than, and target less
567
 * than or equal to, vlc_playlist_Count()).
568
 *
569
 * \param playlist the playlist, locked
570
 * \param index    the index of the item to move
571
 * \param target   the new index of the moved item
572
 */
573
static inline void
574
vlc_playlist_MoveOne(vlc_playlist_t *playlist, size_t index, size_t target)
575
0
{
576
0
    vlc_playlist_Move(playlist, index, 1, target);
577
0
}
Unexecuted instantiation: libvlc.c:vlc_playlist_MoveOne
Unexecuted instantiation: media_source.c:vlc_playlist_MoveOne
Unexecuted instantiation: interface.c:vlc_playlist_MoveOne
Unexecuted instantiation: content.c:vlc_playlist_MoveOne
Unexecuted instantiation: control.c:vlc_playlist_MoveOne
Unexecuted instantiation: item.c:vlc_playlist_MoveOne
Unexecuted instantiation: notify.c:vlc_playlist_MoveOne
Unexecuted instantiation: player.c:vlc_playlist_MoveOne
Unexecuted instantiation: playlist.c:vlc_playlist_MoveOne
Unexecuted instantiation: preparse.c:vlc_playlist_MoveOne
578
579
/**
580
 * Remove a slice of items at a given index.
581
 *
582
 * The slice must be in range (index+count less than or equal to
583
 * vlc_playlist_Count()).
584
 *
585
 * \param playlist the playlist, locked
586
 * \param index    the index of the first item to remove
587
 * \param count    the number of items to remove
588
 */
589
VLC_API void
590
vlc_playlist_Remove(vlc_playlist_t *playlist, size_t index, size_t count);
591
592
/**
593
 * Remove an item at a given index.
594
 *
595
 * The index must be in range (less than vlc_playlist_Count()).
596
 *
597
 * \param playlist the playlist, locked
598
 * \param index    the index of the item to remove
599
 */
600
static inline void
601
vlc_playlist_RemoveOne(vlc_playlist_t *playlist, size_t index)
602
0
{
603
0
    vlc_playlist_Remove(playlist, index, 1);
604
0
}
Unexecuted instantiation: libvlc.c:vlc_playlist_RemoveOne
Unexecuted instantiation: media_source.c:vlc_playlist_RemoveOne
Unexecuted instantiation: interface.c:vlc_playlist_RemoveOne
Unexecuted instantiation: content.c:vlc_playlist_RemoveOne
Unexecuted instantiation: control.c:vlc_playlist_RemoveOne
Unexecuted instantiation: item.c:vlc_playlist_RemoveOne
Unexecuted instantiation: notify.c:vlc_playlist_RemoveOne
Unexecuted instantiation: player.c:vlc_playlist_RemoveOne
Unexecuted instantiation: playlist.c:vlc_playlist_RemoveOne
Unexecuted instantiation: preparse.c:vlc_playlist_RemoveOne
605
606
/**
607
 * Insert a list of media at a given index (if in range), or append.
608
 *
609
 * Contrary to vlc_playlist_Insert(), the index need not be in range: if it is
610
 * out of bounds, items will be appended.
611
 *
612
 * This is an helper to apply a desynchronized insert request, i.e. the
613
 * playlist content may have changed since the request had been submitted.
614
 * This is typically the case for user requests (e.g. from UI), because the
615
 * playlist lock has to be acquired *after* the user requested the
616
 * change.
617
 *
618
 * \param playlist the playlist, locked
619
 * \param index    the index where the media are to be inserted
620
 * \param media    the array of media to insert
621
 * \param count    the number of media to insert
622
 * \return VLC_SUCCESS on success, another value on error
623
 */
624
VLC_API int
625
vlc_playlist_RequestInsert(vlc_playlist_t *playlist, size_t index,
626
                           input_item_t *const media[], size_t count);
627
628
/**
629
 * Move a slice of items by value.
630
 *
631
 * If the indices are known, use vlc_playlist_Move() instead.
632
 *
633
 * This is an helper to apply a desynchronized move request, i.e. the playlist
634
 * content may have changed since the request had been submitted. This is
635
 * typically the case for user requests (e.g. from UI), because the playlist
636
 * lock has to be acquired *after* the user requested the change.
637
 *
638
 * For optimization purpose, it is possible to pass an `index_hint`, which is
639
 * the expected index of the first item of the slice (as known by the client).
640
 * Hopefully, the index should often match, since conflicts are expected to be
641
 * rare. Pass -1 not to pass any hint.
642
 *
643
 * \param playlist   the playlist, locked
644
 * \param items      the array of items to move
645
 * \param count      the number of items to move
646
 * \param target     the new index of the moved slice
647
 * \param index_hint the expected index of the first item (-1 for none)
648
 * \return VLC_SUCCESS on success, another value on error
649
 */
650
VLC_API int
651
vlc_playlist_RequestMove(vlc_playlist_t *playlist,
652
                         vlc_playlist_item_t *const items[], size_t count,
653
                         size_t target, ssize_t index_hint);
654
655
/**
656
 * Remove a slice of items by value.
657
 *
658
 * If the indices are known, use vlc_playlist_Remove() instead.
659
 *
660
 * This is an helper to apply a desynchronized remove request, i.e. the
661
 * playlist content may have changed since the request had been submitted.
662
 * This is typically the case for user requests (e.g. from UI), because the
663
 * playlist lock has to be acquired *after* the user requested the change.
664
 *
665
 * For optimization purpose, it is possible to pass an `index_hint`, which is
666
 * the expected index of the first item of the slice (as known by the client).
667
 * Hopefully, the index should often match, since conflicts are expected to be
668
 * rare. Pass -1 not to pass any hint.
669
 *
670
 * \param playlist   the playlist, locked
671
 * \param items      the array of items to remove
672
 * \param count      the number of items to remove
673
 * \param index_hint the expected index of the first item (-1 for none)
674
 * \return VLC_SUCCESS on success, another value on error
675
 */
676
VLC_API int
677
vlc_playlist_RequestRemove(vlc_playlist_t *playlist,
678
                           vlc_playlist_item_t *const items[], size_t count,
679
                           ssize_t index_hint);
680
681
/**
682
 * Shuffle the playlist.
683
 *
684
 * \param playlist the playlist, locked
685
 */
686
VLC_API void
687
vlc_playlist_Shuffle(vlc_playlist_t *playlist);
688
689
/**
690
 * Sort the playlist by a list of criteria.
691
 *
692
 * \param playlist the playlist, locked
693
 * \param criteria the sort criteria (in order)
694
 * \param count    the number of criteria
695
 * \return VLC_SUCCESS on success, another value on error
696
 */
697
VLC_API int
698
vlc_playlist_Sort(vlc_playlist_t *playlist,
699
                  const struct vlc_playlist_sort_criterion criteria[],
700
                  size_t count);
701
702
/**
703
 * Return the index of a given item.
704
 *
705
 * \param playlist the playlist, locked
706
 * \param item     the item to locate
707
 * \return the index of the item (-1 if not found)
708
 */
709
VLC_API ssize_t
710
vlc_playlist_IndexOf(vlc_playlist_t *playlist, const vlc_playlist_item_t *item);
711
712
/**
713
 * Return the index of a given media.
714
 *
715
 * \param playlist the playlist, locked
716
 * \param media    the media to locate
717
 * \return the index of the playlist item containing the media (-1 if not found)
718
 */
719
VLC_API ssize_t
720
vlc_playlist_IndexOfMedia(vlc_playlist_t *playlist, const input_item_t *media);
721
722
/**
723
 * Return the index of a given item id.
724
 *
725
 * \param playlist the playlist, locked
726
 * \param id       the id to locate
727
 * \return the index of the playlist item having the id (-1 if not found)
728
 */
729
VLC_API ssize_t
730
vlc_playlist_IndexOfId(vlc_playlist_t *playlist, uint64_t id);
731
732
/**
733
 * Return the playback "repeat" mode.
734
 *
735
 * \param playlist the playlist, locked
736
 * \return the playback "repeat" mode
737
 */
738
VLC_API enum vlc_playlist_playback_repeat
739
vlc_playlist_GetPlaybackRepeat(vlc_playlist_t *playlist);
740
741
/**
742
 * Return the playback order.
743
 *
744
 * \param playlist the playlist, locked
745
 * \return the playback order
746
 */
747
VLC_API enum vlc_playlist_playback_order
748
vlc_playlist_GetPlaybackOrder(vlc_playlist_t *playlist);
749
750
/**
751
 * Change the playback "repeat" mode.
752
 *
753
 * \param playlist the playlist, locked
754
 * \param repeat the new playback "repeat" mode
755
 */
756
VLC_API void
757
vlc_playlist_SetPlaybackRepeat(vlc_playlist_t *playlist,
758
                               enum vlc_playlist_playback_repeat repeat);
759
760
/**
761
 * Change the playback order
762
 *
763
 * \param playlist the playlist, locked
764
 * \param order the new playback order
765
 */
766
VLC_API void
767
vlc_playlist_SetPlaybackOrder(vlc_playlist_t *playlist,
768
                              enum vlc_playlist_playback_order order);
769
770
/**
771
 * Return the index of the current item.
772
 *
773
 * \param playlist the playlist, locked
774
 * \return the index of the current item, -1 if none.
775
 */
776
VLC_API ssize_t
777
vlc_playlist_GetCurrentIndex(vlc_playlist_t *playlist);
778
779
/**
780
 * Indicate whether a previous item is available.
781
 *
782
 * \param playlist the playlist, locked
783
 * \retval true if a previous item is available
784
 * \retval false if no previous item is available
785
 */
786
VLC_API bool
787
vlc_playlist_HasPrev(vlc_playlist_t *playlist);
788
789
/**
790
 * Indicate whether a next item is available.
791
 *
792
 * \param playlist the playlist, locked
793
 * \retval true if a next item is available
794
 * \retval false if no next item is available
795
 */
796
VLC_API bool
797
vlc_playlist_HasNext(vlc_playlist_t *playlist);
798
799
/**
800
 * Go to the previous item.
801
 *
802
 * Return VLC_EGENERIC if vlc_playlist_HasPrev() returns false.
803
 *
804
 * \param playlist the playlist, locked
805
 * \return VLC_SUCCESS on success, another value on error
806
 */
807
VLC_API int
808
vlc_playlist_Prev(vlc_playlist_t *playlist);
809
810
/**
811
 * Go to the next item.
812
 *
813
 * Return VLC_EGENERIC if vlc_playlist_HasNext() returns false.
814
 *
815
 * \param playlist the playlist, locked
816
 * \return VLC_SUCCESS on success, another value on error
817
 */
818
VLC_API int
819
vlc_playlist_Next(vlc_playlist_t *playlist);
820
821
/**
822
 * Go to a given index.
823
 *
824
 * the index must be -1 or in range (less than vlc_playlist_Count()).
825
 *
826
 * \param playlist the playlist, locked
827
 * \param index    the index to go to (-1 to none)
828
 * \return VLC_SUCCESS on success, another value on error
829
 */
830
VLC_API int
831
vlc_playlist_GoTo(vlc_playlist_t *playlist, ssize_t index);
832
833
/**
834
 * Go to a given item.
835
 *
836
 * If the index is known, use vlc_playlist_GoTo() instead.
837
 *
838
 * This is a helper to apply a desynchronized "go to" request, i.e. the
839
 * playlist content may have changed since the request had been submitted.
840
 * This is typically the case for user requests (e.g. from UI), because the
841
 * playlist lock has to be acquired *after* the user requested the change.
842
 *
843
 * For optimization purpose, it is possible to pass an `index_hint`, which is
844
 * the expected index of the first item of the slice (as known by the client).
845
 * Hopefully, the index should often match, since conflicts are expected to be
846
 * rare. Pass -1 not to pass any hint.
847
 *
848
 * \param playlist   the playlist, locked
849
 * \param item       the item to go to (NULL for none)
850
 * \param index_hint the expected index of the item (-1 for none)
851
 * \return VLC_SUCCESS on success, another value on error
852
 */
853
VLC_API int
854
vlc_playlist_RequestGoTo(vlc_playlist_t *playlist, vlc_playlist_item_t *item,
855
                         ssize_t index_hint);
856
857
/**
858
 * Return the player owned by the playlist.
859
 *
860
 * \param playlist the playlist (not necessarily locked)
861
 * \return the player
862
 */
863
VLC_API vlc_player_t *
864
vlc_playlist_GetPlayer(vlc_playlist_t *playlist);
865
866
/**
867
 * Start the player.
868
 *
869
 * \param playlist the playlist, locked
870
 * \return VLC_SUCCESS on success, another value on error
871
 */
872
VLC_API int
873
vlc_playlist_Start(vlc_playlist_t *playlist);
874
875
/**
876
 * Stop the player.
877
 *
878
 * \param playlist the playlist, locked
879
 */
880
VLC_API void
881
vlc_playlist_Stop(vlc_playlist_t *playlist);
882
883
/**
884
 * Pause the player.
885
 *
886
 * \param playlist the playlist, locked
887
 */
888
VLC_API void
889
vlc_playlist_Pause(vlc_playlist_t *playlist);
890
891
/**
892
 * Resume the player.
893
 *
894
 * \param playlist the playlist, locked
895
 */
896
VLC_API void
897
vlc_playlist_Resume(vlc_playlist_t *playlist);
898
899
/**
900
 * Go to the given index and plays the corresponding item.
901
 *
902
 * \param playlist the playlist, locked
903
 * \param index    the index to play at
904
 * \return VLC_SUCCESS on success, another value on error
905
 */
906
static inline int
907
vlc_playlist_PlayAt(vlc_playlist_t *playlist, size_t index)
908
0
{
909
0
    int ret = vlc_playlist_GoTo(playlist, index);
910
0
    if (ret != VLC_SUCCESS)
911
0
        return ret;
912
0
    return vlc_playlist_Start(playlist);
913
0
}
Unexecuted instantiation: libvlc.c:vlc_playlist_PlayAt
Unexecuted instantiation: media_source.c:vlc_playlist_PlayAt
Unexecuted instantiation: interface.c:vlc_playlist_PlayAt
Unexecuted instantiation: content.c:vlc_playlist_PlayAt
Unexecuted instantiation: control.c:vlc_playlist_PlayAt
Unexecuted instantiation: item.c:vlc_playlist_PlayAt
Unexecuted instantiation: notify.c:vlc_playlist_PlayAt
Unexecuted instantiation: player.c:vlc_playlist_PlayAt
Unexecuted instantiation: playlist.c:vlc_playlist_PlayAt
Unexecuted instantiation: preparse.c:vlc_playlist_PlayAt
914
915
/**
916
 * Export the playlist to a file.
917
 *
918
 * \param playlist a playlist instance
919
 * \param filename the location where the exported file will be saved
920
 * \param type the type of the playlist file to create (m3u, m3u8, xspf, ...)
921
 * \return VLC_SUCCESS on success, another value on error
922
 */
923
// XXX use vlc_memstream instead of filename?
924
VLC_API int
925
vlc_playlist_Export(vlc_playlist_t *playlist, const char *filename,
926
                    const char *type);
927
928
/** @} */
929
# ifdef __cplusplus
930
}
931
# endif
932
933
#endif