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 submitted via vlc_preparser_Push(),
50 * vlc_preparser_GenerateThumbnail(), or vlc_preparser_GenerateThumbnailToFiles().
51 * It can be passed to vlc_preparser_Cancel() to cancel that request.
52 *
53 * @note
54 * - Validity starts when a submit function returns a non-NULL handle and ends
55 * with vlc_preparser_req_Release().
56 *
57 * - The user must ensure that callbacks and their context remain valid
58 * until request termination.
59 */
62#define VLC_PREPARSER_TYPE_PARSE 0x01
63#define VLC_PREPARSER_TYPE_FETCHMETA_LOCAL 0x02
64#define VLC_PREPARSER_TYPE_FETCHMETA_NET 0x04
65#define VLC_PREPARSER_TYPE_THUMBNAIL 0x08
66#define VLC_PREPARSER_TYPE_THUMBNAIL_TO_FILES 0x10
67#define VLC_PREPARSER_TYPE_FETCHMETA_ALL \
68 (VLC_PREPARSER_TYPE_FETCHMETA_LOCAL|VLC_PREPARSER_TYPE_FETCHMETA_NET)
69
70#define VLC_PREPARSER_OPTION_INTERACT 0x1000
71#define VLC_PREPARSER_OPTION_SUBITEMS 0x2000
75 /**
76 * Event received when the parser ends
77 *
78 * @note This callback is mandatory.
79 *
80 * @param req request handle returned by vlc_preparser_Push()
81 * @param status VLC_SUCCESS in case of success, VLC_ETIMEOUT in case of
82 * timeout, -EINTR if cancelled, an error otherwise
83 * @param data opaque pointer passed by vlc_preparser_Push()
84 */
85 void (*on_ended)(vlc_preparser_req *req, int status, void *data);
87 /**
88 * Event received when a new subtree is added
89 *
90 * @note This callback is optional.
91 *
92 * @param req request handle returned by vlc_preparser_Push()
93 * @param subtree sub items of the current item (the listener gets the ownership)
94 * @param data opaque pointer passed by vlc_preparser_Push()
95 */
97 void *data);
98
99 /**
100 * Event received when new attachments are added
101 *
102 * @note This callback is optional. It can be called several times for one
103 * parse request. The array contains only new elements after a second call.
104 *
105 * @param req request handle returned by vlc_preparser_Push()
106 * @param array valid array containing new elements, should only be used
107 * within the callback. One and all elements can be held and stored on a
108 * new variable or new array.
109 * @param count number of elements in the array
110 * @param data opaque pointer passed by vlc_preparser_Push()
111 */
113 input_attachment_t *const *array,
114 size_t count, void *data);
115};
116
117/**
118 * Preparser thumbnailer callbacks
119 *
120 * Used by vlc_preparser_GenerateThumbnail()
121 */
124 /**
125 * Event received on thumbnailing completion or error
126 *
127 * This callback will always be called, provided
128 * vlc_preparser_GenerateThumbnail() returned a valid request, and provided
129 * the request is not cancelled before its completion.
130 *
131 * @note This callback is mandatory if calling
132 * vlc_preparser_GenerateThumbnail()
133 *
134 * In case of failure, timeout or cancellation, p_thumbnail will be NULL.
135 * The picture, if any, is owned by the thumbnailer, and must be acquired
136 * by using \link picture_Hold \endlink to use it pass the callback's
137 * scope.
138 *
139 * @param req request handle returned by vlc_preparser_GenerateThumbnail()
140 * @param status VLC_SUCCESS in case of success, VLC_ETIMEOUT in case of
141 * timeout, -EINTR if cancelled, an error otherwise
142 * @param thumbnail The generated thumbnail, or NULL in case of failure or
143 * timeout
144 * @param data opaque pointer passed by
145 * vlc_preparser_GenerateThumbnail()
146 *
147 */
148 void (*on_ended)(vlc_preparser_req *req, int status, picture_t* thumbnail, void *data);
150
151/**
152 * Preparser thumbnailer to file callbacks
153 *
154 * Used by vlc_preparser_GenerateThumbnailToFiles()
155 */
158 /**
159 * Event received on thumbnailing completion or error
160 *
161 * This callback will always be called, provided
162 *
163 * vlc_preparser_GenerateThumbnailToFiles() returned a valid request, and
164 * provided the request is not cancelled before its completion.
165 *
166 * @note This callback is mandatory if calling
167 * vlc_preparser_GenerateThumbnailToFiles()
168 *
169 * @param req request handle returned by vlc_preparser_GenerateThumbnailToFiles()
170 * @param status VLC_SUCCESS in case of success, VLC_ETIMEOUT in case of
171 * timeout, -EINTR if cancelled, an error otherwise. A success mean that an
172 * image was generated but it is still possible that the export failed,
173 * check result_array to assure export were successful.
174 * @param array of results, if result_array[i] is true, the outputs[i] from
175 * vlc_preparser_GenerateThumbnailToFiles() succeeded.
176 * @param result_count size of the array, same than the output_count arg
177 * from vlc_preparser_GenerateThumbnailToFiles()
178 * @param data opaque pointer passed by
179 * vlc_preparser_GenerateThumbnailToFiles()
180 */
181 void (*on_ended)(vlc_preparser_req *req, int status,
182 const bool *result_array, size_t result_count, void *data);
183};
184
185/**
186 * Thumbnailer argument
187 *
188 * Used by vlc_preparser_GenerateThumbnail() and
189 * vlc_preparser_GenerateThumbnailToFiles()
190 */
193 /** Seek argument */
194 struct seek
196 enum
197 {
198 /** Don't seek (default) */
200 /** Seek by time */
202 /** Seek by position */
205 union
206 {
207 /** Seek time if type == VLC_THUMBNAILER_SEEK_TIME */
209 /** Seek position if type == VLC_THUMBNAILER_SEEK_POS */
210 double pos;
211 };
212 enum
213 {
214 /** Precise, but potentially slow */
216 /** Fast, but potentially imprecise */
221 /** True to enable hardware decoder (false by default) */
222 bool hw_dec;
224
225/**
226 * Thumbnailer output format
227 */
237/**
238 * Thumbnailer output argument
239 *
240 * Used by vlc_preparser_GenerateThumbnailToFiles()
241 */
244 /**
245 * Thumbnailer output format
246 */
249 /**
250 * Requested width of the thumbnail
251 *
252 * cf. picture_Export() documentation.
253 */
254 int width;
256 /**
257 * Requested Height of the thumbnail
258 *
259 * cf. picture_Export() documentation.
260 */
261 int height;
263 /**
264 * True if the thumbnail should be cropped
265 *
266 * cf. picture_Export() documentation.
267 */
268 bool crop;
270 /** File output path of the thumbnail */
271 const char *file_path;
272 /** File mode bits (cf. "mode_t mode" in `man 2 open`) */
273 unsigned int creat_mode;
275
276/**
277 * Preparser creation configuration
278 */
281 /**
282 * A combination of VLC_PREPARSER_TYPE_* flags, it is used to
283 * setup the executors for each domain. Its possible to select more than
284 * one type
285 */
286 int types;
288 /**
289 * The maximum number of threads used by the parser, 0 for default
290 * (1 thread)
291 */
292 unsigned max_parser_threads;
294 /**
295 * The maximum number of threads used by the thumbnailer, 0 for default
296 * (1 thread)
297 */
300 /**
301 * Timeout of the preparser and/or thumbnailer, 0 for no limits.
302 */
305 /**
306 * Indicate if the preparser will use external process or not.
307 */
308 bool external_process;
310
311/**
312 * This function creates the preparser object and thread.
313 *
314 * @param obj the parent object
315 * @param cfg a pointer to a valid confiuration struct
316 * @return a valid preparser object or NULL in case of error
317 */
319 const struct vlc_preparser_cfg *cfg );
320
321/**
322 * This function enqueues the provided item to be preparsed or fetched.
323 *
324 * The input item is retained until the preparsing is done or until the
325 * preparser object is deleted.
326 *
327 * @param preparser the preparser object
328 * @param item a valid item to preparse
329 * @param type_option a combination of VLC_PREPARSER_TYPE_* and
330 * VLC_PREPARSER_OPTION_* flags. The type must be in the set specified in
331 * vlc_preparser_New() (it is possible to select less types).
332 * @param cbs callback to listen to events (can't be NULL)
333 * @param cbs_userdata opaque pointer used by the callbacks
334 * @return NULL in case of error, or a valid request handle if the
335 * item was scheduled for preparsing. If this returns an
336 * error, the on_preparse_ended will *not* be invoked
337 */
339vlc_preparser_Push( vlc_preparser_t *preparser, input_item_t *item, int type_option,
340 const struct vlc_preparser_cbs *cbs, void *cbs_userdata );
341
342/**
343 * This function enqueues the provided item for generating a thumbnail
344 *
345 * @param preparser the preparser object
346 * @param item a valid item to generate the thumbnail for
347 * @param arg pointer to the arg struct, NULL for default options
348 * @param cbs callback to listen to events (can't be NULL)
349 * @param cbs_userdata opaque pointer used by the callbacks
350 * @return NULL in case of error, or a valid request handle if the
351 * item was scheduled for thumbnailing. If this returns an
352 * error, the thumbnailer.on_ended callback will *not* be invoked
353 *
354 * The provided input_item will be held by the thumbnailer and can safely be
355 * released safely after calling this function.
356 */
359 const struct vlc_thumbnailer_arg *arg,
360 const struct vlc_thumbnailer_cbs *cbs,
361 void *cbs_userdata );
362
363/**
364 * Get the best possible format
365 *
366 * @param[out] format pointer to the best format
367 * @param[out] out_ext pointer to the extension of the format
368 * @return 0 if a format was found, VLC_ENOENT otherwise (in case there are no
369 * "image encoder" modules)
370 */
371VLC_API int
373 const char **out_ext);
374
375/**
376 * Check if the format is handled by VLC
377 *
378 * @param format format to check
379 * @return 0 if the format was found, VLC_ENOENT otherwise (in case there are
380 * no "image encoder" modules)
381 */
382VLC_API int
384
385/**
386 * This function generates a thumbnail to one or several files
387 *
388 * @param preparser the preparser object
389 * @param item a valid item to generate the thumbnail for
390 * @param arg pointer to the arg struct, NULL for default options
391 * @param outputs array of outputs, one file will be generated per output for a
392 * single thumbnail
393 * @param output_count outputs array size, must be > 1
394 * @param cbs callback to listen to events (can't be NULL)
395 * @param cbs_userdata opaque pointer used by the callbacks
396 * @return NULL in case of error, or a valid request handle if the
397 * item was scheduled for thumbnailing. If this returns an
398 * error, the thumbnailer.on_ended callback will *not* be invoked
399 *
400 * The provided input_item will be held by the thumbnailer and can safely be
401 * released safely after calling this function.
402 */
405 const struct vlc_thumbnailer_arg *arg,
406 const struct vlc_thumbnailer_output *outputs,
407 size_t output_count,
408 const struct vlc_thumbnailer_to_files_cbs *cbs,
409 void *cbs_userdata );
410
411/**
412 * This function cancels ongoing or queued preparsing/thumbnail generation
413 * for a given request handle.
414 *
415 * @param preparser the preparser object
416 * @param req request handle returned by vlc_preparser_Push(),
417 * vlc_preparser_GenerateThumbnail(), or vlc_preparser_GenerateThumbnailToFiles().
418 * Pass NULL to cancel all pending and running tasks.
419 * @return number of tasks cancelled
420 *
421 * @note
422 * - When a request is cancelled, the `on_ended` callback will be triggered
423 * with -EINTR status.
424 *
425 * - If the request is already in a terminated state (finished, cancelled, or error),
426 * the call is a no-op and no callback will be invoked.
427 */
429 vlc_preparser_req *req );
430
431/**
432 * Fetch the input item associated with the request.
433 *
434 * @param req request handle returned by vlc_preparser_Push(),
435 * vlc_preparser_GenerateThumbnail(), or vlc_preparser_GenerateThumbnailToFiles().
436 * @return input_item_t associated with the request
437 *
438 * @note The returned input item is held by the request, it must not be
439 * released by the caller.
440 */
442
443/**
444 * Release a preparser request handle.
445 *
446 * @param req the preparser request handle
447 *
448 * @note
449 * - The request handle is retained when returned by a submit function.
450 *
451 * - Mandatory to call to avoid memory leaks.
452 *
453 * - It is safe to call this API from within the on_ended callback.
454 *
455 * - The request handle should not be used after calling this function.
456 *
457 * - If called on an active request, it doesn't cancel the preparsing request,
458 * use vlc_preparser_Cancel() for that.
459 */
461
462/**
463 * This function destroys the preparser object and thread.
464 *
465 * @param preparser the preparser object
466 * All pending input items will be released.
467 */
469
470/**
471 * Do not use, libVLC only fonction, will be removed soon
472 */
474 vlc_tick_t timeout ) VLC_DEPRECATED;
475
476/** @} vlc_preparser */
477
478#endif
size_t count
Definition core.c:403
#define VLC_API
Definition fourcc_gen.c:31
#define VLC_DEPRECATED
Definition vlc_common.h:158
vlc_thumbnailer_format
Thumbnailer output format.
Definition vlc_preparser.h:230
vlc_preparser_req * vlc_preparser_GenerateThumbnailToFiles(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)
This function generates a thumbnail to one or several files.
Definition preparser.c:95
input_item_t * vlc_preparser_req_GetItem(vlc_preparser_req *req)
Fetch the input item associated with the request.
Definition preparser.c:138
void vlc_preparser_SetTimeout(vlc_preparser_t *preparser, vlc_tick_t timeout)
Do not use, libVLC only fonction, will be removed soon.
Definition preparser.c:130
struct vlc_preparser_req vlc_preparser_req
Preparser request opaque handle.
Definition vlc_preparser.h:61
vlc_preparser_req * vlc_preparser_GenerateThumbnail(vlc_preparser_t *preparser, input_item_t *item, const struct vlc_thumbnailer_arg *arg, const struct vlc_thumbnailer_cbs *cbs, void *cbs_userdata)
This function enqueues the provided item for generating a thumbnail.
Definition preparser.c:81
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:769
void vlc_preparser_req_Release(vlc_preparser_req *req)
Release a preparser request handle.
Definition preparser.c:146
int vlc_preparser_GetBestThumbnailerFormat(enum vlc_thumbnailer_format *format, const char **out_ext)
Get the best possible format.
Definition internal.c:762
vlc_preparser_req * vlc_preparser_Push(vlc_preparser_t *preparser, input_item_t *item, int type_option, const struct vlc_preparser_cbs *cbs, void *cbs_userdata)
This function enqueues the provided item to be preparsed or fetched.
Definition preparser.c:69
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:112
void vlc_preparser_Delete(vlc_preparser_t *preparser)
This function destroys the preparser object and thread.
Definition preparser.c:121
@ VLC_THUMBNAILER_FORMAT_WEBP
Definition vlc_preparser.h:232
@ VLC_THUMBNAILER_FORMAT_RGBA
Definition vlc_preparser.h:234
@ VLC_THUMBNAILER_FORMAT_PNG
Definition vlc_preparser.h:231
@ VLC_THUMBNAILER_FORMAT_JPEG
Definition vlc_preparser.h:233
@ VLC_THUMBNAILER_FORMAT_ARGB
Definition vlc_preparser.h:235
void * arg
Definition sort.c:32
Definition vlc_input.h:168
Definition vlc_input_item.h:204
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:75
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:113
void(* on_ended)(vlc_preparser_req *req, int status, void *data)
Event received when the parser ends.
Definition vlc_preparser.h:86
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:97
Preparser creation configuration.
Definition vlc_preparser.h:281
vlc_tick_t timeout
Timeout of the preparser and/or thumbnailer, 0 for no limits.
Definition vlc_preparser.h:304
int types
A combination of VLC_PREPARSER_TYPE_* flags, it is used to setup the executors for each domain.
Definition vlc_preparser.h:287
unsigned max_parser_threads
The maximum number of threads used by the parser, 0 for default (1 thread).
Definition vlc_preparser.h:293
bool external_process
Indicate if the preparser will use external process or not.
Definition vlc_preparser.h:309
unsigned max_thumbnailer_threads
The maximum number of threads used by the thumbnailer, 0 for default (1 thread).
Definition vlc_preparser.h:299
Definition preparser.h:75
Definition preparser.h:53
Seek argument.
Definition vlc_preparser.h:196
enum vlc_thumbnailer_arg::seek::@332237124070327025112071122156207037227312020171 type
@ VLC_THUMBNAILER_SEEK_FAST
Fast, but potentially imprecise.
Definition vlc_preparser.h:218
@ VLC_THUMBNAILER_SEEK_PRECISE
Precise, but potentially slow.
Definition vlc_preparser.h:216
enum vlc_thumbnailer_arg::seek::@176015036064103074174004227006001063107374250322 speed
vlc_tick_t time
Seek time if type == VLC_THUMBNAILER_SEEK_TIME.
Definition vlc_preparser.h:209
double pos
Seek position if type == VLC_THUMBNAILER_SEEK_POS.
Definition vlc_preparser.h:211
@ VLC_THUMBNAILER_SEEK_POS
Seek by position.
Definition vlc_preparser.h:204
@ VLC_THUMBNAILER_SEEK_TIME
Seek by time.
Definition vlc_preparser.h:202
@ VLC_THUMBNAILER_SEEK_NONE
Don't seek (default).
Definition vlc_preparser.h:200
Thumbnailer argument.
Definition vlc_preparser.h:193
bool hw_dec
True to enable hardware decoder (false by default).
Definition vlc_preparser.h:223
struct vlc_thumbnailer_arg::seek seek
Preparser thumbnailer callbacks.
Definition vlc_preparser.h:124
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:149
Thumbnailer output argument.
Definition vlc_preparser.h:244
int height
Requested Height of the thumbnail.
Definition vlc_preparser.h:262
unsigned int creat_mode
File mode bits (cf.
Definition vlc_preparser.h:274
const char * file_path
File output path of the thumbnail.
Definition vlc_preparser.h:272
int width
Requested width of the thumbnail.
Definition vlc_preparser.h:255
enum vlc_thumbnailer_format format
Thumbnailer output format.
Definition vlc_preparser.h:248
bool crop
True if the thumbnail should be cropped.
Definition vlc_preparser.h:269
Preparser thumbnailer to file callbacks.
Definition vlc_preparser.h:158
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:182
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