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/**
305 * This function creates the preparser object and thread.
306 *
307 * @param obj the parent object
308 * @param cfg a pointer to a valid confiuration struct
309 * @return a valid preparser object or NULL in case of error
310 */
312 const struct vlc_preparser_cfg *cfg );
313
314/**
315 * This function enqueues the provided item to be preparsed or fetched.
316 *
317 * The input item is retained until the preparsing is done or until the
318 * preparser object is deleted.
319 *
320 * @param preparser the preparser object
321 * @param item a valid item to preparse
322 * @param type_option a combination of VLC_PREPARSER_TYPE_* and
323 * VLC_PREPARSER_OPTION_* flags. The type must be in the set specified in
324 * vlc_preparser_New() (it is possible to select less types).
325 * @param cbs callback to listen to events (can't be NULL)
326 * @param cbs_userdata opaque pointer used by the callbacks
327 * @return NULL in case of error, or a valid request handle if the
328 * item was scheduled for preparsing. If this returns an
329 * error, the on_preparse_ended will *not* be invoked
330 */
332vlc_preparser_Push( vlc_preparser_t *preparser, input_item_t *item, int type_option,
333 const struct vlc_preparser_cbs *cbs, void *cbs_userdata );
334
335/**
336 * This function enqueues the provided item for generating a thumbnail
337 *
338 * @param preparser the preparser object
339 * @param item a valid item to generate the thumbnail for
340 * @param arg pointer to the arg struct, NULL for default options
341 * @param cbs callback to listen to events (can't be NULL)
342 * @param cbs_userdata opaque pointer used by the callbacks
343 * @return NULL in case of error, or a valid request handle if the
344 * item was scheduled for thumbnailing. If this returns an
345 * error, the thumbnailer.on_ended callback will *not* be invoked
346 *
347 * The provided input_item will be held by the thumbnailer and can safely be
348 * released safely after calling this function.
349 */
352 const struct vlc_thumbnailer_arg *arg,
353 const struct vlc_thumbnailer_cbs *cbs,
354 void *cbs_userdata );
355
356/**
357 * Get the best possible format
358 *
359 * @param[out] format pointer to the best format
360 * @param[out] out_ext pointer to the extension of the format
361 * @return 0 if a format was found, VLC_ENOENT otherwise (in case there are no
362 * "image encoder" modules)
363 */
364VLC_API int
366 const char **out_ext);
367
368/**
369 * Check if the format is handled by VLC
370 *
371 * @param format format to check
372 * @return 0 if the format was found, VLC_ENOENT otherwise (in case there are
373 * no "image encoder" modules)
374 */
375VLC_API int
377
378/**
379 * This function generates a thumbnail to one or several files
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 outputs array of outputs, one file will be generated per output for a
385 * single thumbnail
386 * @param output_count outputs array size, must be > 1
387 * @param cbs callback to listen to events (can't be NULL)
388 * @param cbs_userdata opaque pointer used by the callbacks
389 * @return NULL in case of error, or a valid request handle if the
390 * item was scheduled for thumbnailing. If this returns an
391 * error, the thumbnailer.on_ended callback will *not* be invoked
392 *
393 * The provided input_item will be held by the thumbnailer and can safely be
394 * released safely after calling this function.
395 */
398 const struct vlc_thumbnailer_arg *arg,
399 const struct vlc_thumbnailer_output *outputs,
400 size_t output_count,
401 const struct vlc_thumbnailer_to_files_cbs *cbs,
402 void *cbs_userdata );
403
404/**
405 * This function cancels ongoing or queued preparsing/thumbnail generation
406 * for a given request handle.
407 *
408 * @param preparser the preparser object
409 * @param req request handle returned by vlc_preparser_Push(),
410 * vlc_preparser_GenerateThumbnail(), or vlc_preparser_GenerateThumbnailToFiles().
411 * Pass NULL to cancel all pending and running tasks.
412 * @return number of tasks cancelled
413 *
414 * @note
415 * - When a request is cancelled, the `on_ended` callback will be triggered
416 * with -EINTR status.
417 *
418 * - If the request is already in a terminated state (finished, cancelled, or error),
419 * the call is a no-op and no callback will be invoked.
420 */
422 vlc_preparser_req *req );
423
424/**
425 * Fetch the input item associated with the request.
426 *
427 * @param req request handle returned by vlc_preparser_Push(),
428 * vlc_preparser_GenerateThumbnail(), or vlc_preparser_GenerateThumbnailToFiles().
429 * @return input_item_t associated with the request
430 *
431 * @note The returned input item is held by the request, it must not be
432 * released by the caller.
433 */
435
436/**
437 * Release a preparser request handle.
438 *
439 * @param req the preparser request handle
440 *
441 * @note
442 * - The request handle is retained when returned by a submit function.
443 *
444 * - Mandatory to call to avoid memory leaks.
445 *
446 * - It is safe to call this API from within the on_ended callback.
447 *
448 * - The request handle should not be used after calling this function.
449 *
450 * - If called on an active request, it doesn't cancel the preparsing request,
451 * use vlc_preparser_Cancel() for that.
452 */
454
455/**
456 * This function destroys the preparser object and thread.
457 *
458 * @param preparser the preparser object
459 * All pending input items will be released.
460 */
462
463/**
464 * Do not use, libVLC only fonction, will be removed soon
465 */
467 vlc_tick_t timeout ) VLC_DEPRECATED;
468
469/** @} vlc_preparser */
470
471#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:779
input_item_t * vlc_preparser_req_GetItem(vlc_preparser_req *req)
Fetch the input item associated with the request.
Definition preparser.c:932
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:938
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:691
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:568
int vlc_preparser_CheckThumbnailerFormat(enum vlc_thumbnailer_format format)
Check if the format is handled by VLC.
Definition preparser.c:773
void vlc_preparser_req_Release(vlc_preparser_req *req)
Release a preparser request handle.
Definition preparser.c:944
int vlc_preparser_GetBestThumbnailerFormat(enum vlc_thumbnailer_format *format, const char **out_ext)
Get the best possible format.
Definition preparser.c:766
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:650
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:850
void vlc_preparser_Delete(vlc_preparser_t *preparser)
This function destroys the preparser object and thread.
Definition preparser.c:953
@ 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
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.c:70
Definition preparser.c:47
Seek argument.
Definition vlc_preparser.h:196
@ 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_tick_t time
Seek time if type == VLC_THUMBNAILER_SEEK_TIME.
Definition vlc_preparser.h:209
enum vlc_thumbnailer_arg::seek::@281 speed
@ 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
enum vlc_thumbnailer_arg::seek::@278 type
double pos
Seek position if type == VLC_THUMBNAILER_SEEK_POS.
Definition vlc_preparser.h:211
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