VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_preparser.h
Go to the documentation of this file.
1/*****************************************************************************
2 * preparser.h
3 *****************************************************************************
4 * Copyright (C) 1999-2023 VLC authors and VideoLAN
5 *
6 * Authors: Samuel Hocevar <sam@zoy.org>
7 * Clément Stenac <zorglub@videolan.org>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
13 *
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. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23
24#ifndef VLC_PREPARSER_H
25#define VLC_PREPARSER_H 1
26
27#include <vlc_input_item.h>
28
29/**
30 * @defgroup vlc_preparser Preparser
31 * @ingroup input
32 * @{
33 * @file
34 * VLC Preparser API
35 */
36
37/**
38 * Preparser opaque structure.
39 *
40 * The preparser object will retrieve the meta data of any given input item in
41 * an asynchronous way.
42 * It will also issue art fetching requests.
43 */
44typedef struct vlc_preparser_t vlc_preparser_t;
46/**
47 * Preparser request opaque handle.
48 *
49 * Identifies a request created by vlc_preparser_req_NewParse(),
50 * vlc_preparser_req_NewThumbnail() or vlc_preparser_req_NewThumbnailToFiles()
51 * and started with vlc_preparser_Submit().
52 * It can be passed to vlc_preparser_Cancel() to cancel that request.
53 *
54 * @note
55 * - Ownership of the handle is transferred to the caller by the
56 * vlc_preparser_req_New*() functions. The caller must release it with
57 * vlc_preparser_req_Release() once it is no longer needed, whether or not it
58 * was submitted.
59 *
60 * - The caller must ensure that the callbacks and their context remain valid
61 * until the request terminates.
62 */
65#define VLC_PREPARSER_TYPE_PARSE 0x01
66#define VLC_PREPARSER_TYPE_FETCHMETA_LOCAL 0x02
67#define VLC_PREPARSER_TYPE_FETCHMETA_NET 0x04
68#define VLC_PREPARSER_TYPE_THUMBNAIL 0x08
69#define VLC_PREPARSER_TYPE_THUMBNAIL_TO_FILES 0x10
70#define VLC_PREPARSER_TYPE_FETCHMETA_ALL \
71 (VLC_PREPARSER_TYPE_FETCHMETA_LOCAL|VLC_PREPARSER_TYPE_FETCHMETA_NET)
72
73#define VLC_PREPARSER_OPTION_INTERACT 0x1000
74#define VLC_PREPARSER_OPTION_SUBITEMS 0x2000
78 /**
79 * Event received when the parser ends
80 *
81 * @note This callback is mandatory.
82 *
83 * @param req request handle returned by vlc_preparser_req_NewParse()
84 * @param status VLC_SUCCESS in case of success, VLC_ETIMEOUT in case of
85 * timeout, -EINTR if cancelled, an error otherwise
86 * @param data opaque pointer passed by vlc_preparser_req_NewParse()
87 */
88 void (*on_ended)(vlc_preparser_req *req, int status, void *data);
90 /**
91 * Event received when a new subtree is added
92 *
93 * @note This callback is optional.
94 *
95 * @param req request handle returned by vlc_preparser_req_NewParse()
96 * @param subtree sub items of the current item (the listener gets the ownership)
97 * @param data opaque pointer passed by vlc_preparser_req_NewParse()
98 */
100 void *data);
101
102 /**
103 * Event received when new attachments are added
104 *
105 * @note This callback is optional. It can be called several times for one
106 * parse request. The array contains only new elements after a second call.
107 *
108 * @param req request handle returned by vlc_preparser_req_NewParse()
109 * @param array valid array containing new elements, should only be used
110 * within the callback. One and all elements can be held and stored on a
111 * new variable or new array.
112 * @param count number of elements in the array
113 * @param data opaque pointer passed by vlc_preparser_req_NewParse()
114 */
116 input_attachment_t *const *array,
117 size_t count, void *data);
118};
119
120/**
121 * Preparser thumbnailer callbacks
122 *
123 * Used by vlc_preparser_req_NewThumbnail()
124 */
127 /**
128 * Event received on thumbnailing completion or error
129 *
130 * This callback is invoked exactly once for each request successfully
131 * submitted with vlc_preparser_Submit().
132 *
133 * @note This callback is mandatory if calling
134 * vlc_preparser_req_NewThumbnail()
135 *
136 * In case of failure, timeout or cancellation, thumbnail will be NULL.
137 * The picture, if any, is owned by the thumbnailer, and must be acquired
138 * by using \link picture_Hold \endlink to use it pass the callback's
139 * scope.
140 *
141 * @param req request handle returned by vlc_preparser_req_NewThumbnail()
142 * @param status VLC_SUCCESS in case of success, VLC_ETIMEOUT in case of
143 * timeout, -EINTR if cancelled, an error otherwise
144 * @param thumbnail The generated thumbnail, or NULL in case of failure,
145 * timeout or cancellation
146 * @param data opaque pointer passed by
147 * vlc_preparser_req_NewThumbnail()
148 */
149 void (*on_ended)(vlc_preparser_req *req, int status, picture_t* thumbnail, void *data);
151
152/**
153 * Preparser thumbnailer to file callbacks
154 *
155 * Used by vlc_preparser_req_NewThumbnailToFiles()
156 */
159 /**
160 * Event received on thumbnailing completion or error
161 *
162 * This callback is invoked exactly once for each request successfully
163 * submitted with vlc_preparser_Submit().
164 *
165 * @note This callback is mandatory if calling
166 * vlc_preparser_req_NewThumbnailToFiles()
167 *
168 * In case of failure, timeout or cancellation, result_array will be NULL
169 * and result_count will be 0.
170 *
171 * @param req request handle returned by vlc_preparser_req_NewThumbnailToFiles()
172 * @param status VLC_SUCCESS in case of success, VLC_ETIMEOUT in case of
173 * timeout, -EINTR if cancelled, an error otherwise. A success mean that an
174 * image was generated but it is still possible that the export failed,
175 * check result_array to assure export were successful.
176 * @param result_array array of results, if result_array[i] is true, the
177 * outputs[i] from vlc_preparser_req_NewThumbnailToFiles() succeeded. NULL
178 * if the status is not VLC_SUCCESS.
179 * @param result_count size of the array, same than the output_count arg
180 * from vlc_preparser_req_NewThumbnailToFiles(), or 0 if the status is not
181 * VLC_SUCCESS
182 * @param data opaque pointer passed by
183 * vlc_preparser_req_NewThumbnailToFiles()
184 */
185 void (*on_ended)(vlc_preparser_req *req, int status,
186 const bool *result_array, size_t result_count, void *data);
187};
188
189/**
190 * Thumbnailer argument
191 *
192 * Used by vlc_preparser_req_NewThumbnail() and
193 * vlc_preparser_req_NewThumbnailToFiles()
194 */
197 /** Seek argument */
198 struct seek
200 enum
201 {
202 /** Don't seek (default) */
204 /** Seek by time */
206 /** Seek by position */
209 union
210 {
211 /** Seek time if type == VLC_THUMBNAILER_SEEK_TIME */
213 /** Seek position if type == VLC_THUMBNAILER_SEEK_POS */
214 double pos;
215 };
216 enum
217 {
218 /** Precise, but potentially slow */
220 /** Fast, but potentially imprecise */
225 /** True to enable hardware decoder (false by default) */
226 bool hw_dec;
228
229/**
230 * Thumbnailer output format
231 */
241/**
242 * Thumbnailer output argument
243 *
244 * Used by vlc_preparser_req_NewThumbnailToFiles()
245 */
248 /**
249 * Thumbnailer output format
250 */
253 /**
254 * Requested width of the thumbnail
255 *
256 * cf. picture_Export() documentation.
257 */
258 int width;
260 /**
261 * Requested Height of the thumbnail
262 *
263 * cf. picture_Export() documentation.
264 */
265 int height;
267 /**
268 * True if the thumbnail should be cropped
269 *
270 * cf. picture_Export() documentation.
271 */
272 bool crop;
274 /** File output path of the thumbnail */
275 const char *file_path;
276 /** File mode bits (cf. "mode_t mode" in `man 2 open`) */
277 unsigned int creat_mode;
279
280/**
281 * Preparser creation configuration
282 */
285 /**
286 * A combination of VLC_PREPARSER_TYPE_* flags, it is used to
287 * setup the executors for each domain. Its possible to select more than
288 * one type
289 */
290 int types;
292 /**
293 * The maximum number of threads used by the parser, 0 for default
294 * (1 thread)
295 */
296 unsigned max_parser_threads;
298 /**
299 * The maximum number of threads used by the thumbnailer, 0 for default
300 * (1 thread)
301 */
304 /**
305 * Timeout of the preparser and/or thumbnailer, 0 for no limits.
306 */
309 /**
310 * Indicate if the preparser will use external process or not.
311 */
312 bool external_process;
314
315/**
316 * This function creates the preparser object and thread.
317 *
318 * @param obj the parent object
319 * @param cfg a pointer to a valid confiuration struct
320 * @return a valid preparser object or NULL in case of error
321 */
323 const struct vlc_preparser_cfg *cfg );
324
325/**
326 * Get the best possible format
327 *
328 * @param[out] format pointer to the best format
329 * @param[out] out_ext pointer to the extension of the format
330 * @return 0 if a format was found, VLC_ENOENT otherwise (in case there are no
331 * "image encoder" modules)
332 */
333VLC_API int
335 const char **out_ext);
336
337/**
338 * Check if the format is handled by VLC
339 *
340 * @param format format to check
341 * @return 0 if the format was found, VLC_ENOENT otherwise (in case there are
342 * no "image encoder" modules)
343 */
344VLC_API int
346
347/**
348 * Create a parse/fetch request.
349 *
350 * The request is created idle, nothing runs and no callback can fire until it
351 * is handed to vlc_preparser_Submit(). The caller owns the returned handle
352 * from the moment this function returns.
353 *
354 * @param preparser the preparser object
355 * @param item a valid item to preparse
356 * @param type_option a combination of VLC_PREPARSER_TYPE_* and
357 * VLC_PREPARSER_OPTION_* flags. The type must be in the set specified in
358 * vlc_preparser_New() (it is possible to select less types).
359 * @param cbs callback to listen to events (can't be NULL)
360 * @param cbs_userdata opaque pointer used by the callbacks
361 * @return a request handle owned by the caller, or NULL in case of error. It
362 * must be released with vlc_preparser_req_Release(), whether or not it is
363 * submitted.
364 *
365 * @note The provided input_item will be held by the preparser and can safely be
366 * released after calling this function.
367 */
370 int type_option,
371 const struct vlc_preparser_cbs *cbs,
372 void *cbs_userdata );
373
374/**
375 * Create a thumbnail generation request.
376 *
377 * The request is created idle, nothing runs and no callback can fire until it
378 * is handed to vlc_preparser_Submit(). The caller owns the returned handle
379 * from the moment this function returns.
380 *
381 * @param preparser the preparser object
382 * @param item a valid item to generate the thumbnail for
383 * @param arg pointer to the arg struct, NULL for default options
384 * @param cbs callback to listen to events (can't be NULL)
385 * @param cbs_userdata opaque pointer used by the callbacks
386 * @return a request handle owned by the caller, or NULL in case of error. It
387 * must be released with vlc_preparser_req_Release(), whether or not it is
388 * submitted.
389 *
390 * @note The provided input_item will be held by the preparser and can safely be
391 * released after calling this function.
392 */
395 const struct vlc_thumbnailer_arg *arg,
396 const struct vlc_thumbnailer_cbs *cbs,
397 void *cbs_userdata );
398
399/**
400 * Create a request generating a thumbnail to one or several files.
401 *
402 * The request is created idle, nothing runs and no callback can fire until it
403 * is handed to vlc_preparser_Submit(). The caller owns the returned handle
404 * from the moment this function returns.
405 *
406 * @param preparser the preparser object
407 * @param item a valid item to generate the thumbnail for
408 * @param arg pointer to the arg struct, NULL for default options
409 * @param outputs array of outputs, one file will be generated per output for a
410 * single thumbnail
411 * @param output_count outputs array size, must be > 0
412 * @param cbs callback to listen to events (can't be NULL)
413 * @param cbs_userdata opaque pointer used by the callbacks
414 * @return a request handle owned by the caller, or NULL in case of error. It
415 * must be released with vlc_preparser_req_Release(), whether or not it is
416 * submitted.
417 *
418 * @note The provided input_item will be held by the preparser and can safely be
419 * released after calling this function.
420 */
423 input_item_t *item,
424 const struct vlc_thumbnailer_arg *arg,
425 const struct vlc_thumbnailer_output *outputs,
426 size_t output_count,
427 const struct vlc_thumbnailer_to_files_cbs *cbs,
428 void *cbs_userdata );
429
430/**
431 * Submit a request created by one of the vlc_preparser_req_New*() functions.
432 *
433 * @param preparser the preparser object the request was created from
434 * @param req a request handle that has never been submitted successfully
435 * @return VLC_SUCCESS if the request was queued, VLC_EGENERIC otherwise
436 *
437 * @note
438 * - On success the `on_ended` callback is guaranteed to be invoked exactly
439 * once. It may be invoked even before this function returns.
440 *
441 * - On failure the request was not queued and no callback will be invoked.
442 * The caller keeps its reference and may submit the request again.
443 *
444 * - A request may be submitted at most once, and may only be re-submitted if
445 * the previous attempt failed. Submitting a request that was already queued
446 * successfully is undefined behaviour.
447 *
448 * - Submitting the same request concurrently from several threads is
449 * undefined behaviour.
450 */
451VLC_API int
453
454/**
455 * This function cancels ongoing or queued preparsing/thumbnail generation
456 * for a given request handle.
457 *
458 * @param preparser the preparser object
459 * @param req request handle returned by a vlc_preparser_req_New*() function.
460 * Pass NULL to cancel all pending and running tasks.
461 * @return number of tasks cancelled
462 *
463 * @note
464 * - When a request is cancelled, the `on_ended` callback will be triggered
465 * with -EINTR status.
466 *
467 * - That callback may run synchronously, on the thread calling this function,
468 * if the request had not started yet. The caller must be careful not to hold
469 * any lock that the callback needs, or it will deadlock against itself.
470 *
471 * - If the request is already in a terminated state (finished, cancelled or
472 * error), or if it was never submitted, the call is a no-op and no callback
473 * will be invoked.
474 */
476 vlc_preparser_req *req );
477
478/**
479 * Fetch the input item associated with the request.
480 *
481 * @param req request handle returned by a vlc_preparser_req_New*() function.
482 * @return input_item_t associated with the request
483 *
484 * @note The returned input item is held by the request, it must not be
485 * released by the caller.
486 */
488
489/**
490 * Release a preparser request handle.
491 *
492 * @param req the preparser request handle
493 *
494 * @note
495 * - Mandatory to call to avoid memory leaks.
496 *
497 * - It is safe to call this API from within the on_ended callback.
498 *
499 * - The request handle should not be used after calling this function.
500 *
501 * - If called on an active request, it doesn't cancel the preparsing request,
502 * use vlc_preparser_Cancel() for that.
503 */
505
506/**
507 * This function destroys the preparser object and thread.
508 *
509 * @param preparser the preparser object
510 * All pending input items will be released.
511 */
513
514/** @} vlc_preparser */
515
516#endif
size_t count
Definition core.c:403
#define VLC_API
Definition fourcc_gen.c:31
vlc_thumbnailer_format
Thumbnailer output format.
Definition vlc_preparser.h:234
input_item_t * vlc_preparser_req_GetItem(vlc_preparser_req *req)
Fetch the input item associated with the request.
Definition preparser.c:148
struct vlc_preparser_req vlc_preparser_req
Preparser request opaque handle.
Definition vlc_preparser.h:64
vlc_preparser_req * vlc_preparser_req_NewThumbnailToFiles(vlc_preparser_t *preparser, input_item_t *item, const struct vlc_thumbnailer_arg *arg, const struct vlc_thumbnailer_output *outputs, size_t output_count, const struct vlc_thumbnailer_to_files_cbs *cbs, void *cbs_userdata)
Create a request generating a thumbnail to one or several files.
Definition preparser.c:95
int vlc_preparser_Submit(vlc_preparser_t *preparser, vlc_preparser_req *req)
Submit a request created by one of the vlc_preparser_req_New*() functions.
Definition preparser.c:113
vlc_preparser_req * vlc_preparser_req_NewParse(vlc_preparser_t *preparser, input_item_t *item, int type_option, const struct vlc_preparser_cbs *cbs, void *cbs_userdata)
Create a parse/fetch request.
Definition preparser.c:69
vlc_preparser_req * vlc_preparser_req_NewThumbnail(vlc_preparser_t *preparser, input_item_t *item, const struct vlc_thumbnailer_arg *arg, const struct vlc_thumbnailer_cbs *cbs, void *cbs_userdata)
Create a thumbnail generation request.
Definition preparser.c:82
vlc_preparser_t * vlc_preparser_New(vlc_object_t *obj, const struct vlc_preparser_cfg *cfg)
This function creates the preparser object and thread.
Definition preparser.c:33
int vlc_preparser_CheckThumbnailerFormat(enum vlc_thumbnailer_format format)
Check if the format is handled by VLC.
Definition internal.c:780
void vlc_preparser_req_Release(vlc_preparser_req *req)
Release a preparser request handle.
Definition preparser.c:156
int vlc_preparser_GetBestThumbnailerFormat(enum vlc_thumbnailer_format *format, const char **out_ext)
Get the best possible format.
Definition internal.c:773
size_t vlc_preparser_Cancel(vlc_preparser_t *preparser, vlc_preparser_req *req)
This function cancels ongoing or queued preparsing/thumbnail generation for a given request handle.
Definition preparser.c:130
void vlc_preparser_Delete(vlc_preparser_t *preparser)
This function destroys the preparser object and thread.
Definition preparser.c:139
@ VLC_THUMBNAILER_FORMAT_WEBP
Definition vlc_preparser.h:236
@ VLC_THUMBNAILER_FORMAT_RGBA
Definition vlc_preparser.h:238
@ VLC_THUMBNAILER_FORMAT_PNG
Definition vlc_preparser.h:235
@ VLC_THUMBNAILER_FORMAT_JPEG
Definition vlc_preparser.h:237
@ VLC_THUMBNAILER_FORMAT_ARGB
Definition vlc_preparser.h:239
void * arg
Definition sort.c:32
Definition vlc_input.h:168
Definition vlc_input_item.h:201
Describes an input and is used to spawn input_thread_t objects.
Definition vlc_input_item.h:98
Video picture.
Definition vlc_picture.h:128
VLC object common members.
Definition vlc_objects.h:53
Definition vlc_preparser.h:78
void(* on_attachments_added)(vlc_preparser_req *req, input_attachment_t *const *array, size_t count, void *data)
Event received when new attachments are added.
Definition vlc_preparser.h:116
void(* on_ended)(vlc_preparser_req *req, int status, void *data)
Event received when the parser ends.
Definition vlc_preparser.h:89
void(* on_subtree_added)(vlc_preparser_req *req, input_item_node_t *subtree, void *data)
Event received when a new subtree is added.
Definition vlc_preparser.h:100
Preparser creation configuration.
Definition vlc_preparser.h:285
vlc_tick_t timeout
Timeout of the preparser and/or thumbnailer, 0 for no limits.
Definition vlc_preparser.h:308
int types
A combination of VLC_PREPARSER_TYPE_* flags, it is used to setup the executors for each domain.
Definition vlc_preparser.h:291
unsigned max_parser_threads
The maximum number of threads used by the parser, 0 for default (1 thread).
Definition vlc_preparser.h:297
bool external_process
Indicate if the preparser will use external process or not.
Definition vlc_preparser.h:313
unsigned max_thumbnailer_threads
The maximum number of threads used by the thumbnailer, 0 for default (1 thread).
Definition vlc_preparser.h:303
Definition preparser.h:76
Definition preparser.h:54
Seek argument.
Definition vlc_preparser.h:200
enum vlc_thumbnailer_arg::seek::@332237124070327025112071122156207037227312020171 type
@ VLC_THUMBNAILER_SEEK_FAST
Fast, but potentially imprecise.
Definition vlc_preparser.h:222
@ VLC_THUMBNAILER_SEEK_PRECISE
Precise, but potentially slow.
Definition vlc_preparser.h:220
enum vlc_thumbnailer_arg::seek::@176015036064103074174004227006001063107374250322 speed
vlc_tick_t time
Seek time if type == VLC_THUMBNAILER_SEEK_TIME.
Definition vlc_preparser.h:213
double pos
Seek position if type == VLC_THUMBNAILER_SEEK_POS.
Definition vlc_preparser.h:215
@ VLC_THUMBNAILER_SEEK_POS
Seek by position.
Definition vlc_preparser.h:208
@ VLC_THUMBNAILER_SEEK_TIME
Seek by time.
Definition vlc_preparser.h:206
@ VLC_THUMBNAILER_SEEK_NONE
Don't seek (default).
Definition vlc_preparser.h:204
Thumbnailer argument.
Definition vlc_preparser.h:197
bool hw_dec
True to enable hardware decoder (false by default).
Definition vlc_preparser.h:227
struct vlc_thumbnailer_arg::seek seek
Preparser thumbnailer callbacks.
Definition vlc_preparser.h:127
void(* on_ended)(vlc_preparser_req *req, int status, picture_t *thumbnail, void *data)
Event received on thumbnailing completion or error.
Definition vlc_preparser.h:150
Thumbnailer output argument.
Definition vlc_preparser.h:248
int height
Requested Height of the thumbnail.
Definition vlc_preparser.h:266
unsigned int creat_mode
File mode bits (cf.
Definition vlc_preparser.h:278
const char * file_path
File output path of the thumbnail.
Definition vlc_preparser.h:276
int width
Requested width of the thumbnail.
Definition vlc_preparser.h:259
enum vlc_thumbnailer_format format
Thumbnailer output format.
Definition vlc_preparser.h:252
bool crop
True if the thumbnail should be cropped.
Definition vlc_preparser.h:273
Preparser thumbnailer to file callbacks.
Definition vlc_preparser.h:159
void(* on_ended)(vlc_preparser_req *req, int status, const bool *result_array, size_t result_count, void *data)
Event received on thumbnailing completion or error.
Definition vlc_preparser.h:186
This file is a collection of common definitions and types.
This file defines functions, structures and enums for input items in vlc.
int64_t vlc_tick_t
High precision date or time interval.
Definition vlc_tick.h:48