VLC 4.0.0-dev
Loading...
Searching...
No Matches
libvlc_parser.h
Go to the documentation of this file.
1/*****************************************************************************
2 * libvlc_parser.h: libvlc parser API
3 *****************************************************************************
4 * Copyright (C) 2025 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_LIBVLC_PARSER_H
22#define VLC_LIBVLC_PARSER_H 1
23
24#include <vlc/libvlc.h>
25#include <vlc/libvlc_picture.h>
26
27# ifdef __cplusplus
28extern "C" {
29# endif
30
31/** \defgroup libvlc_parser LibVLC parser
32 * \ingroup libvlc
33 * \ref libvlc_parser_t is an abstract representation of a parser
34 * @{
35 * \file
36 * LibVLC parser API
37 */
39
44
45/**
46 * A parser request object
47 */
49
50/**
51 * A thumbnailer request object
52 */
54
55/**
56 * Opaque handle of a parsing/thumbnailing task.
57 *
58 * Identifies a task request submitted via libvlc_parser_queue()
59 * or libvlc_parser_queue_thumbnailing(). It can be passed to
60 * libvlc_parser_cancel_request() to cancel that request.
61 *
62 * \note Validity starts when a submit function returns a non-NULL handle
63 * and ends with libvlc_parser_task_release().
64 */
66
67/**
68 * Parse flags used by libvlc_parser_request_t
69 */
71{
72 /**
73 * Parse media
74 */
76 /**
77 * Fetch meta and cover art using local resources
78 */
80 /**
81 * Fetch meta and cover art using network resources
82 */
84 /**
85 * Interact with the user (via libvlc_dialog_cbs) when preparsing this item
86 * (and not its sub items). Set this flag in order to receive a callback
87 * when the input is asking for credentials.
88 */
91
92/**
93 * Outcome of a finished parse request, reported by
94 * \ref libvlc_parser_cbs.on_parsed
95 *
96 */
98{
99 /** The parsing failed */
101 /** The parsing timed out */
103 /** The parsing was cancelled */
105 /** The parsing completed successfully */
108
109/**
110 * Thumbnailer seek type
111 */
113{
114 /** Don't seek (default) */
116 /** Seek by time */
118 /** Seek by position */
121
122/**
123 * Thumbnailer seek speed
124 */
126{
127 /** Precise, but potentially slow */
129 /** Fast, but potentially imprecise */
132
133/**
134 * Thumbnailer seek value
135 *
136 * The active member is selected based on the associated
137 * \ref libvlc_thumbnailer_seek_type_t.
138 */
140{
141 /** Seek time, only use if type == libvlc_thumbnailer_seek_time */
143 /** Seek position, only use if type == libvlc_thumbnailer_seek_pos */
144 double pos;
146
147/**
148 * struct defining callbacks for libvlc_parser_queue
149 */
151{
152 /**
153 * Version of struct libvlc_parser_cbs
154 */
155 uint32_t version;
156
157 /**
158 * Callback prototype that notify when a parser request finishes
159 *
160 * \note Mandatory (can't be NULL),
161 * available since version 0
162 *
163 * \param opaque opaque pointer set by cbs_opaque
164 * \param task opaque handle returned by libvlc_parser_queue()
165 * \param status terminal parse outcome, \ref libvlc_parser_status_t
166 */
167 void (*on_parsed)(void *opaque,
170
171 /**
172 * Callback prototype that notify when the parser add new attachments to
173 * the media.
174 *
175 * Called before on_parsed, if there are valid attachments.
176 *
177 * \note Optional (can be NULL),
178 * available since version 0
179 *
180 * \param opaque opaque pointer set by cbs_opaque
181 * \param task opaque handle returned by libvlc_parser_queue()
182 * \param list list of pictures, the list is only valid from this
183 * callback, each pictures can be held separately with
184 * libvlc_picture_retain().
185 */
186 void (*on_attachments_added)(void *opaque,
189};
190
191/**
192 * struct defining a parse request
193 */
195{
196 /**
197 * Version of libvlc_parser_request_t
198 */
199 uint32_t version;
200
201 /**
202 * Media to parse
203 *
204 * \note Mandatory (can't be NULL),
205 * available since version 0
206 */
208
209 /**
210 * Parse flags, a combination of \ref libvlc_media_parse_flag_t
211 * (default to libvlc_media_parse if 0)
212 *
213 * \note Optional (can be 0),
214 * available since version 0
215 */
217};
218
219/**
220 * struct defining callbacks for libvlc_parser_queue_thumbnailing
221 */
223{
224 /**
225 * Version of struct libvlc_thumbnailer_cbs
226 */
227 uint32_t version;
228
229 /**
230 * Callback prototype that notify when a thumbnailer request finishes
231 *
232 * \note Mandatory (can't be NULL),
233 * available since version 0
234 *
235 * \param opaque opaque pointer set in cbs_opaque
236 * \param task opaque handle returned by libvlc_parser_queue_thumbnailing()
237 * \param picture generated thumbnail, the picture is only valid from this
238 * callback, it can be held separately with libvlc_picture_retain().
239 * NULL in case of an error, timeout or request was cancelled.
240 */
241 void (*on_ended)( void *opaque, libvlc_parser_task *task, libvlc_picture_t *picture );
242};
243
244/**
245 * struct defining a thumbnailer request
246 */
248{
249 /**
250 * Version of libvlc_thumbnailer_request_t
251 */
252 uint32_t version;
253
254 /**
255 * Media source of the thumbnail.
256 *
257 * \note Mandatory (can't be NULL),
258 * available since version 0
259 */
261
262 /**
263 * Thumbnail width (0 by default)
264 * \note The resulting thumbnail size can either be:
265 *
266 * - Hardcoded by providing both width & height. In which case, the image will
267 * be stretched to match the provided aspect ratio, or cropped if crop is true.
268 *
269 * - Derived from the media aspect ratio if only width or height is provided and
270 * the other one is set to 0.
271 *
272 * - Of the same size as the media if both width and height are set to 0.
273 *
274 * \note Optional (can be 0),
275 * available since version 0
276 */
277 unsigned int width;
278
279 /**
280 * Thumbnail height (0 by default)
281 * \note The resulting thumbnail size can either be:
282 *
283 * - Hardcoded by providing both width & height. In which case, the image will
284 * be stretched to match the provided aspect ratio, or cropped if crop is true.
285 *
286 * - Derived from the media aspect ratio if only width or height is provided and
287 * the other one is set to 0.
288 *
289 * - Of the same size as the media if both width and height are set to 0.
290 *
291 * \note Optional (can be 0),
292 * available since version 0
293 */
294 unsigned int height;
295
296 /**
297 * True to enable crop (false by default)
298 *
299 * \note Only meaningful when both width and height are non-zero
300 * (hardcoded thumbnail size); ignored otherwise.
301 *
302 * \note Optional (can be false),
303 * available since version 0
304 */
305 bool crop;
306
307 /**
308 * Picture type (libvlc_picture_Argb by default)
309 *
310 * \note Optional (can be 0),
311 * available since version 0
312 */
314
315 /**
316 * Seek parameters
317 *
318 * \note Optional (can be zero-initialized, in which case the members
319 * will be set to their default values),
320 * available since version 0
321 */
322 struct
323 {
324 /**
325 * by time or by position (libvlc_thumbnailer_seek_none by default)
326 */
328
329 /** Seek value, the active member is selected by type
330 *
331 * \note `time` by default, although it won't be used if type is libvlc_thumbnailer_seek_none
332 */
334
335 /** precise or fast mode (libvlc_media_thumbnail_seek_precise by default) */
338
339 /**
340 * True to enable hardware decoder (false by default)
341 *
342 * \note Optional (can be false),
343 * available since version 0
344 */
345 bool hw_dec;
346};
347
348/**
349 * struct defining parser configuration
350 */
352{
353 /**
354 * Version of struct libvlc_parser_cfg
355 */
356 uint32_t version;
357
358 /**
359 * The maximum number of threads used by the parser, 0 for default
360 * (1 thread)
361 *
362 * \note Optional (can be 0),
363 * available since version 0
364 */
366
367 /**
368 * The maximum number of threads used by the thumbnailer, 0 for default
369 * (1 thread)
370 *
371 * \note Optional (can be 0),
372 * available since version 0
373 */
375
376 /**
377 * Timeout of the parser in us, 0 for no limits, or -1 to inherit the value of preparse-timeout
378 *
379 * \note Optional (can be 0),
380 * available since version 0
381 */
383};
384
385/**
386 * Create a parser
387 *
388 * \param inst LibVLC instance to create parser with
389 * \param cfg a pointer to a valid configuration struct
390 * \return a new parser object, or NULL on error.
391 * It must be released by libvlc_parser_destroy().
392 * \version libvlc 4.0.0 or later
393 */
396 const struct libvlc_parser_cfg *cfg);
397
398/**
399 * Destroy a parser and free resources.
400 * All pending and running tasks are cancelled, and reported as cancelled
401 * via callback. This API waits for all worker threads to join.
402 *
403 * \note It is safe to call this API while tasks are still running or pending.
404 *
405 * \param parser the parser
406 * \version libvlc 4.0.0 or later
407 */
409
410/**
411 * Parse a media asynchronously
412 *
413 * This fetches (local or network) art, meta data and/or tracks information.
414 *
415 * \note It is possible to cancel the request with
416 * libvlc_parser_cancel_request()
417 *
418 * If the request is successfully queued, the \ref
419 * libvlc_parser_cbs.on_parsed callback is guaranteed to be called
420 *
421 * \note A media can be parsed multiple times, for instance to refresh network
422 * metadata; a previous successful, failed, timed out or cancelled parse does
423 * not prevent re-queueing.
424 *
425 * \param parser the parser
426 * \param req a pointer to a valid request struct
427 * \param cbs a pointer to a valid callbacks struct. The pointed struct
428 * must be kept alive (and not modified) by the caller until libvlc_parser_cbs.on_parsed
429 * is called for the returned task handle.
430 * \param cbs_opaque an opaque pointer to be passed to the callbacks
431 * \return NULL in case of error, or a valid handle if the item was scheduled
432 * for parsing. If this returns NULL, the \ref libvlc_parser_cbs.on_parsed
433 * callback will *not* be called.
434 * \version LibVLC 4.0.0 or later
435 */
438 const struct libvlc_parser_cbs *cbs, void *cbs_opaque);
439
440/**
441 * Generate a thumbnail asynchronously
442 *
443 * \note It is possible to cancel the request with
444 * libvlc_parser_cancel_request()
445 *
446 * If the request is successfully queued, the \ref
447 * libvlc_thumbnailer_cbs.on_ended callback is guaranteed to be called
448 *
449 * \param parser the parser
450 * \param req a pointer to a valid request struct
451 * \param cbs a pointer to a valid callbacks struct. The pointed struct
452 * must be kept alive (and not modified) by the caller until libvlc_thumbnailer_cbs.on_ended
453 * is called for the returned task handle.
454 * \param cbs_opaque an opaque pointer to be passed to the callbacks
455 * \return NULL in case of error, or a valid handle if the item was
456 * scheduled for thumbnailing. If this returns an error, the \ref
457 * libvlc_thumbnailer_cbs.on_ended callback will *not* be called.
458 * \version LibVLC 4.0.0 or later
459 */
463 const struct libvlc_thumbnailer_cbs *cbs,
464 void *cbs_opaque);
465
466/**
467 * Cancel a parser request
468 *
469 * \param parser the parser
470 * \param task A parser task returned by libvlc_parser_queue(), libvlc_parser_queue_thumbnailing()
471 * or NULL to cancel all requests.
472 * \return the number of requests cancelled
473 *
474 * \note
475 * - When a task is cancelled, the `on_parsed` callback will be triggered
476 * with libvlc_parser_status_cancelled status.
477 *
478 * - If the request is already in a terminated state (finished, cancelled, error, timeout),
479 * the call is a no-op and no callback will be invoked.
480 * \version libvlc 4.0.0 or later
481 */
484
485/**
486 * Fetch the media associated with the task handle.
487 *
488 * \param task A parser task returned by libvlc_parser_queue() or libvlc_parser_queue_thumbnailing()
489 * \return libvlc_media_t associated with the task
490 *
491 * \note The returned media is held by the task, it must not be
492 * released by the caller.
493 */
496
497/**
498 * Release a parser task handle.
499 *
500 * \param task the parser task handle
501 *
502 * \note
503 * - The task handle is retained when returned by a submit function.
504 *
505 * - Mandatory to call to avoid memory leaks.
506 *
507 * - It is safe to call this API from within the on_parsed/on_ended callback.
508 *
509 * - The task handle should not be used after calling this function.
510 *
511 * - If called on an active request, it doesn't cancel the task,
512 * use libvlc_parser_cancel_request() for that.
513 */
515
516/** @} */
517
518# ifdef __cplusplus
519}
520# endif
521
522#endif /* VLC_LIBVLC_PARSER_H */
struct vlc_param ** list
Definition core.c:402
struct libvlc_instance_t libvlc_instance_t
This structure is opaque.
Definition libvlc.h:76
int64_t libvlc_time_t
Represents a time value in microseconds.
Definition libvlc.h:79
struct libvlc_media_t libvlc_media_t
Definition libvlc_media.h:47
void libvlc_parser_task_release(libvlc_parser_task *task)
Release a parser task handle.
libvlc_media_t * libvlc_parser_task_get_media(libvlc_parser_task *task)
Fetch the media associated with the task handle.
libvlc_thumbnailer_seek_speed_t
Thumbnailer seek speed.
Definition libvlc_parser.h:126
enum libvlc_picture_type_t libvlc_picture_type_t
Definition libvlc_parser.h:43
libvlc_media_parse_flag_t
Parse flags used by libvlc_parser_request_t.
Definition libvlc_parser.h:71
void libvlc_parser_destroy(libvlc_parser_t *parser)
Destroy a parser and free resources.
struct libvlc_picture_t libvlc_picture_t
Definition libvlc_parser.h:42
struct libvlc_parser_task libvlc_parser_task
Opaque handle of a parsing/thumbnailing task.
Definition libvlc_parser.h:65
struct libvlc_picture_list_t libvlc_picture_list_t
Definition libvlc_media_player.h:47
libvlc_parser_t * libvlc_parser_new(libvlc_instance_t *inst, const struct libvlc_parser_cfg *cfg)
Create a parser.
size_t libvlc_parser_cancel_request(libvlc_parser_t *parser, libvlc_parser_task *task)
Cancel a parser request.
libvlc_parser_status_t
Outcome of a finished parse request, reported by libvlc_parser_cbs::on_parsed.
Definition libvlc_parser.h:98
libvlc_thumbnailer_seek_type_t
Thumbnailer seek type.
Definition libvlc_parser.h:113
struct libvlc_parser_t libvlc_parser_t
Definition libvlc_parser.h:38
libvlc_parser_task * libvlc_parser_queue_thumbnailing(libvlc_parser_t *parser, const libvlc_thumbnailer_request_t *req, const struct libvlc_thumbnailer_cbs *cbs, void *cbs_opaque)
Generate a thumbnail asynchronously.
libvlc_parser_task * libvlc_parser_queue(libvlc_parser_t *parser, const libvlc_parser_request_t *req, const struct libvlc_parser_cbs *cbs, void *cbs_opaque)
Parse a media asynchronously.
struct libvlc_media_t libvlc_media_t
Definition libvlc_parser.h:40
@ libvlc_media_thumbnail_seek_fast
Fast, but potentially imprecise.
Definition libvlc_parser.h:130
@ libvlc_media_thumbnail_seek_precise
Precise, but potentially slow.
Definition libvlc_parser.h:128
@ libvlc_media_fetch_local
Fetch meta and cover art using local resources.
Definition libvlc_parser.h:79
@ libvlc_media_do_interact
Interact with the user (via libvlc_dialog_cbs) when preparsing this item (and not its sub items).
Definition libvlc_parser.h:89
@ libvlc_media_parse
Parse media.
Definition libvlc_parser.h:75
@ libvlc_media_fetch_network
Fetch meta and cover art using network resources.
Definition libvlc_parser.h:83
@ libvlc_parser_status_timeout
The parsing timed out.
Definition libvlc_parser.h:102
@ libvlc_parser_status_cancelled
The parsing was cancelled.
Definition libvlc_parser.h:104
@ libvlc_parser_status_done
The parsing completed successfully.
Definition libvlc_parser.h:106
@ libvlc_parser_status_failed
The parsing failed.
Definition libvlc_parser.h:100
@ libvlc_thumbnailer_seek_time
Seek by time.
Definition libvlc_parser.h:117
@ libvlc_thumbnailer_seek_none
Don't seek (default).
Definition libvlc_parser.h:115
@ libvlc_thumbnailer_seek_pos
Seek by position.
Definition libvlc_parser.h:119
#define LIBVLC_API
Definition libvlc.h:42
LibVLC core external API.
libvlc_picture_type_t
Definition libvlc_picture.h:34
struct defining callbacks for libvlc_parser_queue
Definition libvlc_parser.h:151
void(* on_parsed)(void *opaque, libvlc_parser_task *task, libvlc_parser_status_t status)
Callback prototype that notify when a parser request finishes.
Definition libvlc_parser.h:167
void(* on_attachments_added)(void *opaque, libvlc_parser_task *task, libvlc_picture_list_t *list)
Callback prototype that notify when the parser add new attachments to the media.
Definition libvlc_parser.h:186
uint32_t version
Version of struct libvlc_parser_cbs.
Definition libvlc_parser.h:155
struct defining parser configuration
Definition libvlc_parser.h:352
uint32_t max_thumbnailer_threads
The maximum number of threads used by the thumbnailer, 0 for default (1 thread).
Definition libvlc_parser.h:374
uint32_t version
Version of struct libvlc_parser_cfg.
Definition libvlc_parser.h:356
uint32_t max_parser_threads
The maximum number of threads used by the parser, 0 for default (1 thread).
Definition libvlc_parser.h:365
libvlc_time_t timeout
Timeout of the parser in us, 0 for no limits, or -1 to inherit the value of preparse-timeout.
Definition libvlc_parser.h:382
struct defining a parse request
Definition libvlc_parser.h:195
libvlc_media_parse_flag_t parse_flags
Parse flags, a combination of libvlc_media_parse_flag_t (default to libvlc_media_parse if 0).
Definition libvlc_parser.h:216
uint32_t version
Version of libvlc_parser_request_t.
Definition libvlc_parser.h:199
libvlc_media_t * media
Media to parse.
Definition libvlc_parser.h:207
struct defining callbacks for libvlc_parser_queue_thumbnailing
Definition libvlc_parser.h:223
uint32_t version
Version of struct libvlc_thumbnailer_cbs.
Definition libvlc_parser.h:227
void(* on_ended)(void *opaque, libvlc_parser_task *task, libvlc_picture_t *picture)
Callback prototype that notify when a thumbnailer request finishes.
Definition libvlc_parser.h:241
struct defining a thumbnailer request
Definition libvlc_parser.h:248
unsigned int height
Thumbnail height (0 by default).
Definition libvlc_parser.h:294
libvlc_picture_type_t type
Picture type (libvlc_picture_Argb by default).
Definition libvlc_parser.h:313
libvlc_thumbnailer_seek_value_t value
Seek value, the active member is selected by type.
Definition libvlc_parser.h:333
libvlc_media_t * media
Media source of the thumbnail.
Definition libvlc_parser.h:260
struct libvlc_thumbnailer_request_t::@231034204301360324167054075174315102025101305127 seek
Seek parameters.
unsigned int width
Thumbnail width (0 by default).
Definition libvlc_parser.h:277
bool crop
True to enable crop (false by default).
Definition libvlc_parser.h:305
uint32_t version
Version of libvlc_thumbnailer_request_t.
Definition libvlc_parser.h:252
bool hw_dec
True to enable hardware decoder (false by default).
Definition libvlc_parser.h:345
libvlc_thumbnailer_seek_speed_t speed
precise or fast mode (libvlc_media_thumbnail_seek_precise by default)
Definition libvlc_parser.h:336
Definition fetcher.c:54
Thumbnailer seek value.
Definition libvlc_parser.h:140
double pos
Seek position, only use if type == libvlc_thumbnailer_seek_pos.
Definition libvlc_parser.h:144
libvlc_time_t time
Seek time, only use if type == libvlc_thumbnailer_seek_time.
Definition libvlc_parser.h:142