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;
45typedef size_t vlc_preparser_req_id;
47#define VLC_PREPARSER_REQ_ID_INVALID 0
49#define VLC_PREPARSER_TYPE_PARSE 0x01
50#define VLC_PREPARSER_TYPE_FETCHMETA_LOCAL 0x02
51#define VLC_PREPARSER_TYPE_FETCHMETA_NET 0x04
52#define VLC_PREPARSER_TYPE_THUMBNAIL 0x08
53#define VLC_PREPARSER_TYPE_THUMBNAIL_TO_FILES 0x10
54#define VLC_PREPARSER_TYPE_FETCHMETA_ALL \
55 (VLC_PREPARSER_TYPE_FETCHMETA_LOCAL|VLC_PREPARSER_TYPE_FETCHMETA_NET)
56
57#define VLC_PREPARSER_OPTION_INTERACT 0x1000
58#define VLC_PREPARSER_OPTION_SUBITEMS 0x2000
60/**
61 * Preparser thumbnailer callbacks
62 *
63 * Used by vlc_preparser_GenerateThumbnail()
64 */
67 /**
68 * Event received on thumbnailing completion or error
69 *
70 * This callback will always be called, provided
71 * vlc_preparser_GenerateThumbnail() returned a valid request, and provided
72 * the request is not cancelled before its completion.
73 *
74 * @note This callback is mandatory if calling
75 * vlc_preparser_GenerateThumbnail()
76 *
77 * In case of failure, timeout or cancellation, p_thumbnail will be NULL.
78 * The picture, if any, is owned by the thumbnailer, and must be acquired
79 * by using \link picture_Hold \endlink to use it pass the callback's
80 * scope.
81 *
82 * @param item item used for the thumbnailer
83 * @param status VLC_SUCCESS in case of success, VLC_ETIMEOUT in case of
84 * timeout, -EINTR if cancelled, an error otherwise
85 * @param thumbnail The generated thumbnail, or NULL in case of failure or
86 * timeout
87 * @param data opaque pointer passed by
88 * vlc_preparser_GenerateThumbnail()
89 *
90 */
91 void (*on_ended)(input_item_t *item, int status, picture_t* thumbnail,
92 void *data);
93};
94
95/**
96 * Preparser thumbnailer to file callbacks
97 *
98 * Used by vlc_preparser_GenerateThumbnailToFiles()
99 */
102 /**
103 * Event received on thumbnailing completion or error
104 *
105 * This callback will always be called, provided
106 *
107 * vlc_preparser_GenerateThumbnailToFiles() returned a valid request, and
108 * provided the request is not cancelled before its completion.
109 *
110 * @note This callback is mandatory if calling
111 * vlc_preparser_GenerateThumbnailToFiles()
112 *
113 * @param item item used for the thumbnailer
114 * @param status VLC_SUCCESS in case of success, VLC_ETIMEOUT in case of
115 * timeout, -EINTR if cancelled, an error otherwise. A success mean that an
116 * image was generated but it is still possible that the export failed,
117 * check result_array to assure export were successful.
118 * @param array of results, if result_array[i] is true, the outputs[i] from
119 * vlc_preparser_GenerateThumbnailToFiles() succeeded.
120 * @param result_count size of the array, same than the output_count arg
121 * from vlc_preparser_GenerateThumbnailToFiles()
122 * @param data opaque pointer passed by
123 * vlc_preparser_GenerateThumbnailToFiles()
124 */
125 void (*on_ended)(input_item_t *item, int status,
126 const bool *result_array, size_t result_count, void *data);
127};
128
129/**
130 * Thumbnailer argument
131 *
132 * Used by vlc_preparser_GenerateThumbnail() and
133 * vlc_preparser_GenerateThumbnailToFiles()
134 */
137 /** Seek argument */
138 struct seek
140 enum
141 {
142 /** Don't seek (default) */
144 /** Seek by time */
146 /** Seek by position */
149 union
150 {
151 /** Seek time if type == VLC_THUMBNAILER_SEEK_TIME */
153 /** Seek position if type == VLC_THUMBNAILER_SEEK_POS */
154 double pos;
155 };
156 enum
157 {
158 /** Precise, but potentially slow */
160 /** Fast, but potentially imprecise */
165 /** True to enable hardware decoder (false by default) */
166 bool hw_dec;
168
169/**
170 * Thumbnailer output format
171 */
179/**
180 * Thumbnailer output argument
181 *
182 * Used by vlc_preparser_GenerateThumbnailToFiles()
183 */
186 /**
187 * Thumbnailer output format
188 */
191 /**
192 * Requested width of the thumbnail
193 *
194 * cf. picture_Export() documentation.
195 */
196 int width;
198 /**
199 * Requested Height of the thumbnail
200 *
201 * cf. picture_Export() documentation.
202 */
203 int height;
205 /**
206 * True if the thumbnail should be cropped
207 *
208 * cf. picture_Export() documentation.
209 */
210 bool crop;
212 /** File output path of the thumbnail */
213 const char *file_path;
214 /** File mode bits (cf. "mode_t mode" in `man 2 open`) */
215 unsigned int creat_mode;
217
218/**
219 * Preparser creation configuration
220 */
223 /**
224 * A combination of VLC_PREPARSER_TYPE_* flags, it is used to
225 * setup the executors for each domain. Its possible to select more than
226 * one type
227 */
228 int types;
230 /**
231 * The maximum number of threads used by the parser, 0 for default
232 * (1 thread)
233 */
234 unsigned max_parser_threads;
236 /**
237 * The maximum number of threads used by the thumbnailer, 0 for default
238 * (1 thread)
239 */
242 /**
243 * Timeout of the preparser and/or thumbnailer, 0 for no limits.
244 */
247
248/**
249 * This function creates the preparser object and thread.
250 *
251 * @param obj the parent object
252 * @param cfg a pointer to a valid confiuration struct
253 * @return a valid preparser object or NULL in case of error
254 */
256 const struct vlc_preparser_cfg *cfg );
257
258/**
259 * This function enqueues the provided item to be preparsed or fetched.
260 *
261 * The input item is retained until the preparsing is done or until the
262 * preparser object is deleted.
263 *
264 * @param preparser the preparser object
265 * @param item a valid item to preparse
266 * @param type_option a combination of VLC_PREPARSER_TYPE_* and
267 * VLC_PREPARSER_OPTION_* flags. The type must be in the set specified in
268 * vlc_preparser_New() (it is possible to select less types).
269 * @param cbs callback to listen to events (can't be NULL)
270 * @param cbs_userdata opaque pointer used by the callbacks
271 * @param id unique id provided by the caller. This is can be used to cancel
272 * the request with vlc_preparser_Cancel()
273 * @return VLC_PREPARSER_REQ_ID_INVALID in case of error, or a valid id if the
274 * item was scheduled for preparsing. If this returns an
275 * error, the on_preparse_ended will *not* be invoked
276 */
278vlc_preparser_Push( vlc_preparser_t *preparser, input_item_t *item, int type_option,
279 const input_item_parser_cbs_t *cbs, void *cbs_userdata );
280
281/**
282 * This function enqueues the provided item for generating a thumbnail
283 *
284 * @param preparser the preparser object
285 * @param item a valid item to generate the thumbnail for
286 * @param arg pointer to the arg struct, NULL for default options
287 * @param cbs callback to listen to events (can't be NULL)
288 * @param cbs_userdata opaque pointer used by the callbacks
289 * @return VLC_PREPARSER_REQ_ID_INVALID in case of error, or a valid id if the
290 * item was scheduled for thumbnailing. If this returns an
291 * error, the thumbnailer.on_ended callback will *not* be invoked
292 *
293 * The provided input_item will be held by the thumbnailer and can safely be
294 * released safely after calling this function.
295 */
298 const struct vlc_thumbnailer_arg *arg,
299 const struct vlc_thumbnailer_cbs *cbs,
300 void *cbs_userdata );
301
302/**
303 * Get the best possible format
304 *
305 * @param[out] format pointer to the best format
306 * @param[out] out_ext pointer to the extension of the format
307 * @return 0 if a format was found, VLC_ENOENT otherwise (in case there are no
308 * "image encoder" modules)
309 */
310VLC_API int
312 const char **out_ext);
313
314/**
315 * Check if the format is handled by VLC
316 *
317 * @param format format to check
318 * @return 0 if the format was found, VLC_ENOENT otherwise (in case there are
319 * no "image encoder" modules)
320 */
321VLC_API int
323
324/**
325 * This function generates a thumbnail to one or several files
326 *
327 * @param preparser the preparser object
328 * @param item a valid item to generate the thumbnail for
329 * @param arg pointer to the arg struct, NULL for default options
330 * @param outputs array of outputs, one file will be generated per output for a
331 * single thumbnail
332 * @param output_count outputs array size, must be > 1
333 * @param cbs callback to listen to events (can't be NULL)
334 * @param cbs_userdata opaque pointer used by the callbacks
335 * @return VLC_PREPARSER_REQ_ID_INVALID in case of error, or a valid id if the
336 * item was scheduled for thumbnailing. If this returns an
337 * error, the thumbnailer.on_ended callback will *not* be invoked
338 *
339 * The provided input_item will be held by the thumbnailer and can safely be
340 * released safely after calling this function.
341 */
344 const struct vlc_thumbnailer_arg *arg,
345 const struct vlc_thumbnailer_output *outputs,
346 size_t output_count,
347 const struct vlc_thumbnailer_to_files_cbs *cbs,
348 void *cbs_userdata );
349
350/**
351 * This function cancel all preparsing requests for a given id
352 *
353 * @param preparser the preparser object
354 * @param id unique id returned by vlc_preparser_Push(),
355 * VLC_PREPARSER_REQ_ID_INVALID to cancels all tasks
356 * @return number of tasks cancelled
357 */
360
361/**
362 * This function destroys the preparser object and thread.
363 *
364 * @param preparser the preparser object
365 * All pending input items will be released.
366 */
368
369/**
370 * Do not use, libVLC only fonction, will be removed soon
371 */
373 vlc_tick_t timeout ) VLC_DEPRECATED;
374
375/** @} vlc_preparser */
376
377#endif
378
#define VLC_API
Definition fourcc_gen.c:31
#define VLC_DEPRECATED
Definition vlc_common.h:158
size_t vlc_preparser_Cancel(vlc_preparser_t *preparser, vlc_preparser_req_id id)
This function cancel all preparsing requests for a given id.
Definition preparser.c:858
vlc_thumbnailer_format
Thumbnailer output format.
Definition vlc_preparser.h:174
vlc_preparser_req_id 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:787
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:940
vlc_preparser_req_id vlc_preparser_Push(vlc_preparser_t *preparser, input_item_t *item, int type_option, const input_item_parser_cbs_t *cbs, void *cbs_userdata)
This function enqueues the provided item to be preparsed or fetched.
Definition preparser.c:652
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:571
int vlc_preparser_CheckThumbnailerFormat(enum vlc_thumbnailer_format format)
Check if the format is handled by VLC.
Definition preparser.c:781
int vlc_preparser_GetBestThumbnailerFormat(enum vlc_thumbnailer_format *format, const char **out_ext)
Get the best possible format.
Definition preparser.c:774
size_t vlc_preparser_req_id
Definition vlc_preparser.h:46
void vlc_preparser_Delete(vlc_preparser_t *preparser)
This function destroys the preparser object and thread.
Definition preparser.c:946
vlc_preparser_req_id 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:699
@ VLC_THUMBNAILER_FORMAT_WEBP
Definition vlc_preparser.h:176
@ VLC_THUMBNAILER_FORMAT_PNG
Definition vlc_preparser.h:175
@ VLC_THUMBNAILER_FORMAT_JPEG
Definition vlc_preparser.h:177
void * arg
Definition sort.c:32
input item parser callbacks
Definition vlc_input_item.h:431
Describes an input and is used to spawn input_thread_t objects.
Definition vlc_input_item.h:98
Video picture.
Definition vlc_picture.h:130
VLC object common members.
Definition vlc_objects.h:53
Preparser creation configuration.
Definition vlc_preparser.h:223
vlc_tick_t timeout
Timeout of the preparser and/or thumbnailer, 0 for no limits.
Definition vlc_preparser.h:246
int types
A combination of VLC_PREPARSER_TYPE_* flags, it is used to setup the executors for each domain.
Definition vlc_preparser.h:229
unsigned max_parser_threads
The maximum number of threads used by the parser, 0 for default (1 thread)
Definition vlc_preparser.h:235
unsigned max_thumbnailer_threads
The maximum number of threads used by the thumbnailer, 0 for default (1 thread)
Definition vlc_preparser.h:241
Definition preparser.c:47
Seek argument.
Definition vlc_preparser.h:140
enum vlc_thumbnailer_arg::seek::@276 type
enum vlc_thumbnailer_arg::seek::@279 speed
vlc_tick_t time
Seek time if type == VLC_THUMBNAILER_SEEK_TIME.
Definition vlc_preparser.h:153
@ VLC_THUMBNAILER_SEEK_POS
Seek by position.
Definition vlc_preparser.h:148
@ VLC_THUMBNAILER_SEEK_TIME
Seek by time.
Definition vlc_preparser.h:146
@ VLC_THUMBNAILER_SEEK_NONE
Don't seek (default)
Definition vlc_preparser.h:144
double pos
Seek position if type == VLC_THUMBNAILER_SEEK_POS.
Definition vlc_preparser.h:155
@ VLC_THUMBNAILER_SEEK_FAST
Fast, but potentially imprecise.
Definition vlc_preparser.h:162
@ VLC_THUMBNAILER_SEEK_PRECISE
Precise, but potentially slow.
Definition vlc_preparser.h:160
Thumbnailer argument.
Definition vlc_preparser.h:137
bool hw_dec
True to enable hardware decoder (false by default)
Definition vlc_preparser.h:167
Preparser thumbnailer callbacks.
Definition vlc_preparser.h:67
void(* on_ended)(input_item_t *item, int status, picture_t *thumbnail, void *data)
Event received on thumbnailing completion or error.
Definition vlc_preparser.h:92
Thumbnailer output argument.
Definition vlc_preparser.h:186
int height
Requested Height of the thumbnail.
Definition vlc_preparser.h:204
unsigned int creat_mode
File mode bits (cf.
Definition vlc_preparser.h:216
const char * file_path
File output path of the thumbnail.
Definition vlc_preparser.h:214
int width
Requested width of the thumbnail.
Definition vlc_preparser.h:197
enum vlc_thumbnailer_format format
Thumbnailer output format.
Definition vlc_preparser.h:190
bool crop
True if the thumbnail should be cropped.
Definition vlc_preparser.h:211
Preparser thumbnailer to file callbacks.
Definition vlc_preparser.h:102
void(* on_ended)(input_item_t *item, int status, const bool *result_array, size_t result_count, void *data)
Event received on thumbnailing completion or error.
Definition vlc_preparser.h:126
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