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 */
235/**
236 * Thumbnailer output argument
237 *
238 * Used by vlc_preparser_GenerateThumbnailToFiles()
239 */
242 /**
243 * Thumbnailer output format
244 */
247 /**
248 * Requested width of the thumbnail
249 *
250 * cf. picture_Export() documentation.
251 */
252 int width;
254 /**
255 * Requested Height of the thumbnail
256 *
257 * cf. picture_Export() documentation.
258 */
259 int height;
261 /**
262 * True if the thumbnail should be cropped
263 *
264 * cf. picture_Export() documentation.
265 */
266 bool crop;
268 /** File output path of the thumbnail */
269 const char *file_path;
270 /** File mode bits (cf. "mode_t mode" in `man 2 open`) */
271 unsigned int creat_mode;
273
274/**
275 * Preparser creation configuration
276 */
279 /**
280 * A combination of VLC_PREPARSER_TYPE_* flags, it is used to
281 * setup the executors for each domain. Its possible to select more than
282 * one type
283 */
284 int types;
286 /**
287 * The maximum number of threads used by the parser, 0 for default
288 * (1 thread)
289 */
290 unsigned max_parser_threads;
292 /**
293 * The maximum number of threads used by the thumbnailer, 0 for default
294 * (1 thread)
295 */
298 /**
299 * Timeout of the preparser and/or thumbnailer, 0 for no limits.
300 */
303 /**
304 * Indicate if the preparser will use external process or not.
305 */
306 bool external_process;
308
309/**
310 * This function creates the preparser object and thread.
311 *
312 * @param obj the parent object
313 * @param cfg a pointer to a valid confiuration struct
314 * @return a valid preparser object or NULL in case of error
315 */
317 const struct vlc_preparser_cfg *cfg );
318
319/**
320 * This function enqueues the provided item to be preparsed or fetched.
321 *
322 * The input item is retained until the preparsing is done or until the
323 * preparser object is deleted.
324 *
325 * @param preparser the preparser object
326 * @param item a valid item to preparse
327 * @param type_option a combination of VLC_PREPARSER_TYPE_* and
328 * VLC_PREPARSER_OPTION_* flags. The type must be in the set specified in
329 * vlc_preparser_New() (it is possible to select less types).
330 * @param cbs callback to listen to events (can't be NULL)
331 * @param cbs_userdata opaque pointer used by the callbacks
332 * @return NULL in case of error, or a valid request handle if the
333 * item was scheduled for preparsing. If this returns an
334 * error, the on_preparse_ended will *not* be invoked
335 */
337vlc_preparser_Push( vlc_preparser_t *preparser, input_item_t *item, int type_option,
338 const struct vlc_preparser_cbs *cbs, void *cbs_userdata );
339
340/**
341 * This function enqueues the provided item for generating a thumbnail
342 *
343 * @param preparser the preparser object
344 * @param item a valid item to generate the thumbnail for
345 * @param arg pointer to the arg struct, NULL for default options
346 * @param cbs callback to listen to events (can't be NULL)
347 * @param cbs_userdata opaque pointer used by the callbacks
348 * @return NULL in case of error, or a valid request handle if the
349 * item was scheduled for thumbnailing. If this returns an
350 * error, the thumbnailer.on_ended callback will *not* be invoked
351 *
352 * The provided input_item will be held by the thumbnailer and can safely be
353 * released safely after calling this function.
354 */
357 const struct vlc_thumbnailer_arg *arg,
358 const struct vlc_thumbnailer_cbs *cbs,
359 void *cbs_userdata );
360
361/**
362 * Get the best possible format
363 *
364 * @param[out] format pointer to the best format
365 * @param[out] out_ext pointer to the extension of the format
366 * @return 0 if a format was found, VLC_ENOENT otherwise (in case there are no
367 * "image encoder" modules)
368 */
369VLC_API int
371 const char **out_ext);
372
373/**
374 * Check if the format is handled by VLC
375 *
376 * @param format format to check
377 * @return 0 if the format was found, VLC_ENOENT otherwise (in case there are
378 * no "image encoder" modules)
379 */
380VLC_API int
382
383/**
384 * This function generates a thumbnail to one or several files
385 *
386 * @param preparser the preparser object
387 * @param item a valid item to generate the thumbnail for
388 * @param arg pointer to the arg struct, NULL for default options
389 * @param outputs array of outputs, one file will be generated per output for a
390 * single thumbnail
391 * @param output_count outputs array size, must be > 1
392 * @param cbs callback to listen to events (can't be NULL)
393 * @param cbs_userdata opaque pointer used by the callbacks
394 * @return NULL in case of error, or a valid request handle if the
395 * item was scheduled for thumbnailing. If this returns an
396 * error, the thumbnailer.on_ended callback will *not* be invoked
397 *
398 * The provided input_item will be held by the thumbnailer and can safely be
399 * released safely after calling this function.
400 */
403 const struct vlc_thumbnailer_arg *arg,
404 const struct vlc_thumbnailer_output *outputs,
405 size_t output_count,
406 const struct vlc_thumbnailer_to_files_cbs *cbs,
407 void *cbs_userdata );
408
409/**
410 * This function cancels ongoing or queued preparsing/thumbnail generation
411 * for a given request handle.
412 *
413 * @param preparser the preparser object
414 * @param req request handle returned by vlc_preparser_Push(),
415 * vlc_preparser_GenerateThumbnail(), or vlc_preparser_GenerateThumbnailToFiles().
416 * Pass NULL to cancel all pending and running tasks.
417 * @return number of tasks cancelled
418 *
419 * @note
420 * - When a request is cancelled, the `on_ended` callback will be triggered
421 * with -EINTR status.
422 *
423 * - If the request is already in a terminated state (finished, cancelled, or error),
424 * the call is a no-op and no callback will be invoked.
425 */
427 vlc_preparser_req *req );
428
429/**
430 * Fetch the input item associated with the request.
431 *
432 * @param req request handle returned by vlc_preparser_Push(),
433 * vlc_preparser_GenerateThumbnail(), or vlc_preparser_GenerateThumbnailToFiles().
434 * @return input_item_t associated with the request
435 *
436 * @note The returned input item is held by the request, it must not be
437 * released by the caller.
438 */
440
441/**
442 * Release a preparser request handle.
443 *
444 * @param req the preparser request handle
445 *
446 * @note
447 * - The request handle is retained when returned by a submit function.
448 *
449 * - Mandatory to call to avoid memory leaks.
450 *
451 * - It is safe to call this API from within the on_ended callback.
452 *
453 * - The request handle should not be used after calling this function.
454 *
455 * - If called on an active request, it doesn't cancel the preparsing request,
456 * use vlc_preparser_Cancel() for that.
457 */
459
460/**
461 * This function destroys the preparser object and thread.
462 *
463 * @param preparser the preparser object
464 * All pending input items will be released.
465 */
467
468/**
469 * Do not use, libVLC only fonction, will be removed soon
470 */
472 vlc_tick_t timeout ) VLC_DEPRECATED;
473
474/** @} vlc_preparser */
475
476#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:82
input_item_t * vlc_preparser_req_GetItem(vlc_preparser_req *req)
Fetch the input item associated with the request.
Definition preparser.c:125
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:117
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:68
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:761
void vlc_preparser_req_Release(vlc_preparser_req *req)
Release a preparser request handle.
Definition preparser.c:133
int vlc_preparser_GetBestThumbnailerFormat(enum vlc_thumbnailer_format *format, const char **out_ext)
Get the best possible format.
Definition internal.c:754
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:56
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:99
void vlc_preparser_Delete(vlc_preparser_t *preparser)
This function destroys the preparser object and thread.
Definition preparser.c:108
@ VLC_THUMBNAILER_FORMAT_WEBP
Definition vlc_preparser.h:232
@ VLC_THUMBNAILER_FORMAT_PNG
Definition vlc_preparser.h:231
@ VLC_THUMBNAILER_FORMAT_JPEG
Definition vlc_preparser.h:233
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:279
vlc_tick_t timeout
Timeout of the preparser and/or thumbnailer, 0 for no limits.
Definition vlc_preparser.h:302
int types
A combination of VLC_PREPARSER_TYPE_* flags, it is used to setup the executors for each domain.
Definition vlc_preparser.h:285
unsigned max_parser_threads
The maximum number of threads used by the parser, 0 for default (1 thread)
Definition vlc_preparser.h:291
bool external_process
Indicate if the preparser will use external process or not.
Definition vlc_preparser.h:307
unsigned max_thumbnailer_threads
The maximum number of threads used by the thumbnailer, 0 for default (1 thread)
Definition vlc_preparser.h:297
Definition preparser.h:75
Definition preparser.h:53
Seek argument.
Definition vlc_preparser.h:196
enum vlc_thumbnailer_arg::seek::@284 type
vlc_tick_t time
Seek time if type == VLC_THUMBNAILER_SEEK_TIME.
Definition vlc_preparser.h:209
@ 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
@ 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
double pos
Seek position if type == VLC_THUMBNAILER_SEEK_POS.
Definition vlc_preparser.h:211
enum vlc_thumbnailer_arg::seek::@287 speed
Thumbnailer argument.
Definition vlc_preparser.h:193
bool hw_dec
True to enable hardware decoder (false by default)
Definition vlc_preparser.h:223
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:242
int height
Requested Height of the thumbnail.
Definition vlc_preparser.h:260
unsigned int creat_mode
File mode bits (cf.
Definition vlc_preparser.h:272
const char * file_path
File output path of the thumbnail.
Definition vlc_preparser.h:270
int width
Requested width of the thumbnail.
Definition vlc_preparser.h:253
enum vlc_thumbnailer_format format
Thumbnailer output format.
Definition vlc_preparser.h:246
bool crop
True if the thumbnail should be cropped.
Definition vlc_preparser.h:267
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