VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_preparser_ipc.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*****************************************************************************
3 * vlc_preparser_serializer.h: preparser serializer
4 *****************************************************************************
5 * Copyright © 2025 Videolabs, VideoLAN and VLC authors
6 *
7 * Authors: Gabriel Lafond Thenaille <gabriel@videolabs.io>
8 *****************************************************************************/
9
10#ifndef VLC_PREPARSER_IPC_H
11#define VLC_PREPARSER_IPC_H
12
13#include <vlc_common.h>
14#include <vlc_vector.h>
15#include <vlc_input.h>
16#include <vlc_input_item.h>
17#include <vlc_preparser.h>
18#include <vlc_interrupt.h>
19
20/**
21 * @defgroup preparser_ipc Preparser IPC
22 * @ingroup preparser
23 * @{
24 * @file
25 * VLC Preparser IPC API
26 *
27 * @defgroup preparser_msg preparser message api
28 * @ingroup preparser_ipc
29 * @{
30 */
31
32/**
33 * Request types
34 */
36 /**
37 * Type of the request emitted by a `vlc_preparser_Push` call.
38 */
40 /**
41 * Type of the request emitted by a `vlc_preparser_GenerateThumbnail`
42 * call.
43 */
45 /**
46 * Type of the request emitted by a
47 * `vlc_preparser_GenerateThumbnailToFiles` call.
48 */
50};
51
52/**
53 * Preparser request.
54 */
56 /**
57 * Type of the request.
58 */
61 /**
62 * Used only by request of type `VLC_PREPARSER_MSG_REQ_TYPE_PARSE`.
63 */
64 int options;
66 /**
67 * Used by both type `VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL` and
68 * `VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL_TO_FILES`.
69 */
72 /**
73 * Used only by request of type
74 * `VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL_TO_FILES`.
75 */
76 /* all `output_path` will be freed so they must be heap allocated or set to
77 * NULL before a `vlc_preparser_msg_Clean` call. */
78 struct VLC_VECTOR(char *) outputs_path;
81 /* `uri` will be freed so it must be heap allocated or set to
82 * NULL before a `vlc_preparser_msg_Clean` call. */
83 char *uri;
84};
85
86/**
87 * Preparser Response
88 */
90 /**
91 * Type of the response (As the response answering a request they share the
92 * same type).
93 */
96 /**
97 * Used only by request of type `VLC_PREPARSER_MSG_REQ_TYPE_PARSE`.
98 */
102 /**
103 * Used only by request of type `VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL`.
104 */
105 picture_t *pic;
107 /**
108 * Used only by request of type
109 * `VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL_TO_FILES`.
110 */
111 struct VLC_VECTOR(bool) result;
113 /**
114 * Used by all types of request.
115 */
116 int status;
119
120/**
121 * Preparser message.
122 */
123struct vlc_preparser_msg {
124 /**
125 * Type of the message can be a request or a response.
126 */
127 enum {
128 VLC_PREPARSER_MSG_TYPE_REQ,
129 VLC_PREPARSER_MSG_TYPE_RES,
130 } type;
132 /**
133 * Type of the underling request or response.
134 */
135 enum vlc_preparser_msg_req_type req_type;
136 union {
137 struct vlc_preparser_msg_req req;
139 };
140};
141
142/**
143 * Initialize a preparser message.
144 *
145 * @info All data specific to each request/response have to be initialized
146 * by hand.
147 *
148 * @param msg message to initialize.
149 * @param msg_type message type (request or response).
150 * @param req_type request/response type (see enum vlc_preparser_req_type
151 * for more information).
152 */
153VLC_API void
155 enum vlc_preparser_msg_req_type req_type);
156
157/**
158 * Clean all memory used by a message.
159 *
160 * @info This function don't free the `msg` pointer.
161 *
162 * @param msg message to release.
163 */
164VLC_API void
166
167/**
168 * @} preparser_msg
169 *
170 * @defgroup preparser_serdes preparser serializer api
171 * @ingroup preparser_ipc
172 *
173 * @{
174 */
175#define VLC_PREPARSER_MSG_SERDES_TYPE_DATA 0x1
176#define VLC_PREPARSER_MSG_SERDES_TYPE_ATTACHMENT 0x2
177#define VLC_PREPARSER_MSG_SERDES_TYPE_END_DATA 0x4
178#define VLC_PREPARSER_MSG_SERDES_TYPE_END_ATTACHMENT 0x8
181 /**
182 * Write callback.
183 *
184 * @param [in] data buffer to write.
185 * @param [in] size number of bytes to write.
186 * @param [in] userdata callback userdata.
187 *
188 * @return the number of bytes writen or an error code on failure.
189 */
190 ssize_t (*write)(const void *data, size_t size, void *userdata);
192 /**
193 * Read callback.
194 *
195 * @param [out] data buffer to read into.
196 * @param [in] size number of bytes to read.
197 * @param [in] userdata callback userdata.
198 *
199 * @return the number of bytes read or an error code on failure.
200 */
201 ssize_t (*read)(void *data, size_t size, void *userdata);
203
205
207 /**
208 * Serialize `msg` and call the write callback with serialized data.
209 *
210 * @param [in] serdes serializer internal structure.
211 * @param [in] msg message to serialize.
212 * @param [in] userdata context for the write callbacks
213 *
214 * @return VLC_SUCCESS or an error code on failure.
215 */
216 int (*serialize)(struct vlc_preparser_msg_serdes *serdes,
217 const struct vlc_preparser_msg *msg,
218 void *userdata);
219
220 /**
221 * Deserialize `msg` and call the read callback to get data to deserialize.
222 *
223 * @param [in] serdes serializer internal structure.
224 * @param [out] msg message to deserialize.
225 * @param [in] userdata context for the read callbacks
226 *
227 * @return VLC_SUCCESS or an error code on failure.
228 */
229 int (*deserialize)(struct vlc_preparser_msg_serdes *serdes,
230 struct vlc_preparser_msg *msg,
231 void *userdata);
232
233 /**
234 * Close the serializer/deserialier and release all used memory.
235 *
236 * @param [in] serdes preparser msg serdes internal struture.
237 */
238 void (*close)(struct vlc_preparser_msg_serdes *serdes);
240
241/**
242 * Internal structure used by serializer.
243 */
245 /** Operations */
246 const struct vlc_preparser_msg_serdes_operations *ops;
248 struct {
249 /** Callbacks */
250 const struct vlc_preparser_msg_serdes_cbs *cbs;
251 /** Used by the serializer module. */
252 void *sys;
253 } owner;
255
257 (struct vlc_preparser_msg_serdes *, bool);
258
259#define set_callback_preparser_msg_serdes(activate, priority) \
260 {\
261 vlc_preparser_msg_serdes_module open__ = activate;\
262 (void)open__;\
263 set_callback(activate)\
264 }\
265 set_capability("preparser msg serdes", priority)
266
267/**
268 * Call the serialize operation.
269 *
270 * @param [in] s
271 * @param [out] buf
272 * @param [in] msg
273 *
274 * @return size of the allocated buffer.
275 */
276static inline int
278 const struct vlc_preparser_msg *msg,
279 void *userdata)
280{
281 assert(serdes != NULL);
282
283 if (serdes->ops != NULL && serdes->ops->serialize != NULL) {
284 return serdes->ops->serialize(serdes, msg, userdata);
285 }
286 return VLC_EGENERIC;
287}
288
289/**
290 * Call the deserialize operation.
291 *
292 * @param [in] s
293 * @param [in] buf
294 * @param [in] size
295 *
296 * @return size of the allocated buffer.
297 */
298static inline int
300 struct vlc_preparser_msg *msg,
301 void *userdata)
302{
303 assert(serdes!= NULL);
304
305 if (serdes->ops != NULL && serdes->ops->deserialize != NULL) {
306 return serdes->ops->deserialize(serdes, msg, userdata);
307 }
308 return VLC_EGENERIC;
309}
310
311/**
312 * Free the msg_serdes struct.
313 *
314 * @param [in] msg_serdes
315 */
316static inline void
319 assert(serdes != NULL);
320
321 if (serdes->ops != NULL && serdes->ops->close != NULL) {
322 serdes->ops->close(serdes);
323 }
324 free(serdes);
325}
326
327/**
328 * Create a vlc_preparser_msg_serdes object and load a preparser msg_serdes
329 * module.
330 *
331 * @param [in] obj vlc object
332 * @param [in] c serializer's callbacks
333 * @param [in] bin_data describe if the serializer and deserializer use
334 * binary data (intput_attachment_t or plane_t)
335 *
336 * @return a vlc_preparser_msg_serdes object or NULL on failure.
337 */
340 const struct vlc_preparser_msg_serdes_cbs *c,
341 bool bin_data);
342
343/**
344 * @} preparser_serdes
345 * @} preparser_ipc
346 */
347
348#endif /* VLC_PREPARSER_IPC */
#define VLC_API
Definition fourcc_gen.c:31
#define VLC_EGENERIC
Unspecified error.
Definition vlc_common.h:482
void vlc_preparser_msg_Clean(struct vlc_preparser_msg *msg)
Clean all memory used by a message.
Definition ipc.c:104
void vlc_preparser_msg_Init(struct vlc_preparser_msg *msg, int msg_type, enum vlc_preparser_msg_req_type req_type)
Initialize a preparser message.
Definition ipc.c:72
vlc_preparser_msg_req_type
Request types.
Definition vlc_preparser_ipc.h:36
@ VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL_TO_FILES
Type of the request emitted by a vlc_preparser_GenerateThumbnailToFiles call.
Definition vlc_preparser_ipc.h:50
@ VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL
Type of the request emitted by a vlc_preparser_GenerateThumbnail call.
Definition vlc_preparser_ipc.h:45
@ VLC_PREPARSER_MSG_REQ_TYPE_PARSE
Type of the request emitted by a vlc_preparser_Push call.
Definition vlc_preparser_ipc.h:40
struct vlc_preparser_msg_serdes * vlc_preparser_msg_serdes_Create(vlc_object_t *obj, const struct vlc_preparser_msg_serdes_cbs *c, bool bin_data)
Create a vlc_preparser_msg_serdes object and load a preparser msg_serdes module.
Definition ipc.c:32
int(* vlc_preparser_msg_serdes_module)(struct vlc_preparser_msg_serdes *, bool)
Definition vlc_preparser_ipc.h:258
static void vlc_preparser_msg_serdes_Delete(struct vlc_preparser_msg_serdes *serdes)
Free the msg_serdes struct.
Definition vlc_preparser_ipc.h:318
static int vlc_preparser_msg_serdes_Deserialize(struct vlc_preparser_msg_serdes *serdes, struct vlc_preparser_msg *msg, void *userdata)
Call the deserialize operation.
Definition vlc_preparser_ipc.h:300
static int vlc_preparser_msg_serdes_Serialize(struct vlc_preparser_msg_serdes *serdes, const struct vlc_preparser_msg *msg, void *userdata)
Call the serialize operation.
Definition vlc_preparser_ipc.h:278
#define VLC_VECTOR(type)
Vector struct body.
Definition vlc_vector.h:66
static const struct @110 msg_type[]
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
Preparser request.
Definition vlc_preparser_ipc.h:56
struct vlc_preparser_msg_req::@288 outputs_path
Used only by request of type VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL_TO_FILES.
struct vlc_thumbnailer_arg arg
Used by both type VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL and VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL_TO_FI...
Definition vlc_preparser_ipc.h:71
char * uri
Definition vlc_preparser_ipc.h:84
int options
Used only by request of type VLC_PREPARSER_MSG_REQ_TYPE_PARSE.
Definition vlc_preparser_ipc.h:65
enum vlc_preparser_msg_req_type type
Type of the request.
Definition vlc_preparser_ipc.h:60
struct vlc_preparser_msg_req::@289 outputs
Preparser Response.
Definition vlc_preparser_ipc.h:90
struct vlc_preparser_msg_res::@290 attachments
Used only by request of type VLC_PREPARSER_MSG_REQ_TYPE_PARSE.
input_item_t * item
Definition vlc_preparser_ipc.h:118
enum vlc_preparser_msg_req_type type
Type of the response (As the response answering a request they share the same type).
Definition vlc_preparser_ipc.h:95
input_item_node_t * subtree
Definition vlc_preparser_ipc.h:101
int status
Used by all types of request.
Definition vlc_preparser_ipc.h:117
picture_t * pic
Used only by request of type VLC_PREPARSER_MSG_REQ_TYPE_THUMBNAIL.
Definition vlc_preparser_ipc.h:106
Definition vlc_preparser_ipc.h:181
Definition vlc_preparser_ipc.h:207
int(* deserialize)(struct vlc_preparser_msg_serdes *serdes, struct vlc_preparser_msg *msg, void *userdata)
Deserialize msg and call the read callback to get data to deserialize.
Definition vlc_preparser_ipc.h:230
int(* serialize)(struct vlc_preparser_msg_serdes *serdes, const struct vlc_preparser_msg *msg, void *userdata)
Serialize msg and call the write callback with serialized data.
Definition vlc_preparser_ipc.h:217
void(* close)(struct vlc_preparser_msg_serdes *serdes)
Close the serializer/deserialier and release all used memory.
Definition vlc_preparser_ipc.h:239
Internal structure used by serializer.
Definition vlc_preparser_ipc.h:245
void * sys
Used by the serializer module.
Definition vlc_preparser_ipc.h:253
const struct vlc_preparser_msg_serdes_operations * ops
Operations.
Definition vlc_preparser_ipc.h:247
const struct vlc_preparser_msg_serdes_cbs * cbs
Callbacks.
Definition vlc_preparser_ipc.h:251
Preparser message.
Definition vlc_preparser_ipc.h:124
enum vlc_preparser_msg_req_type req_type
Type of the underling request or response.
Definition vlc_preparser_ipc.h:136
@ VLC_PREPARSER_MSG_TYPE_RES
Definition vlc_preparser_ipc.h:130
@ VLC_PREPARSER_MSG_TYPE_REQ
Definition vlc_preparser_ipc.h:129
Thumbnailer argument.
Definition vlc_preparser.h:193
Thumbnailer output argument.
Definition vlc_preparser.h:242
This file is a collection of common definitions and types.
Input thread interface.
This file defines functions, structures and enums for input items in vlc.
This file declares interruptible sleep functions.
VLC Preparser API.
This provides convenience helpers for vectors.