VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_process.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*****************************************************************************
3 * vlc_process.h: vlc_process functions
4 *****************************************************************************
5 * Copyright © 2025 Videolabs, VideoLAN and VLC authors
6 *
7 * Authors: Gabriel Lafond Thenaille <gabriel@videolabs.io>
8 *****************************************************************************/
9
10#ifndef VLC_PROCESS_H
11#define VLC_PROCESS_H
12
13#include <vlc_common.h>
14#include <vlc_tick.h>
15
16/**
17 * @ingroup misc
18 * @file
19 * VLC_PROCESS API
20 * @defgroup process Process API
21 * @{
22 */
23
24/**
25 * Spawn a new process with input and output redirection.
26 *
27 * Creates and starts a new vlc_process for the specified executable path with
28 * the given arguments. Sets up pipes to allow reading from the process's
29 * standard output and writing to its standard input.
30 *
31 * @param [in] path Path to the executable to run. Must not be NULL.
32 * @param [in] argc Number of arguments passed to the process (must be
33 * greater than 0).
34 * @param [in] argv Array of argument strings (argv[0] must not be NULL).
35 *
36 * @return A pointer to the newly created vlc_process structure on
37 * success, or NULL on failure.
38 */
39VLC_API struct vlc_process *
40vlc_process_Spawn(const char *path, int argc, const char *const *argv);
41
42/**
43 * Stop a vlc_process and wait for its termination.
44 *
45 * Closes its file descriptors, and waits for it to exit. Optionally sends a
46 * termination signal to the process,
47 *
48 * @param [in] process Pointer to the vlc_process instance. Must not
49 * be NULL.
50 * @param [in] kill_process Whether to forcibly terminate the process
51 * before waiting.
52 *
53 * @return The exit status of the process, or -1 on error.
54 */
55VLC_API int
56vlc_process_Terminate(struct vlc_process *process, bool kill_process);
57
58/**
59 * Read data from the process's standard output with a timeout.
60 *
61 * Attempts to read up to @p size bytes from the process's standard output
62 * into the provided buffer, waiting up to @p timeout_ms milliseconds for data
63 * to become available.
64 *
65 * On POSIX systems, this uses poll to wait for readability. On Windows,
66 * a platform-specific implementation is used due to limitations with poll on
67 * non-socket handles.
68 *
69 * @param [in] process Pointer to the vlc_process instance.
70 * @param [out] buf Buffer where the read data will be stored.
71 * @param [in] size Maximum number of bytes to read.
72 * @param [in] timeout_ms Timeout in milliseconds to wait for data.
73 *
74 * @return The number of bytes read on success,
75 * -1 on error, and errno is set to indicate the error.
76 */
77VLC_API ssize_t
78vlc_process_fd_Read(struct vlc_process *process, uint8_t *buf, size_t size,
79 vlc_tick_t timeout_ms);
80
81/**
82 * Write data to the process's standard input with a timeout.
83 *
84 * Attempts to write up to @p size bytes from the provided buffer to the
85 * process's standard input, waiting up to @p timeout_ms milliseconds for the
86 * pipe to become writable.
87 *
88 * On POSIX systems, this uses poll to wait for writability. On Windows,
89 * a platform-specific implementation is used due to limitations with poll on
90 * non-socket handles.
91 *
92 * @param [in] process Pointer to the vlc_process instance.
93 * @param [in] buf Buffer containing the data to write.
94 * @param [in] size Number of bytes to write.
95 * @param [in] timeout_ms Timeout in milliseconds to wait for the pipe to be
96 * writable.
97 *
98 * @return The number of bytes read on success,
99 * -1 on error, and errno is set to indicate the error.
100 */
101VLC_API ssize_t
102vlc_process_fd_Write(struct vlc_process *process, const uint8_t *buf, size_t size,
103 vlc_tick_t timeout_ms);
104
105/**
106 * @} process
107 */
108
109#endif /* VLC_PROCESS_H */
#define VLC_API
Definition fourcc_gen.c:31
struct vlc_process * vlc_process_Spawn(const char *path, int argc, const char *const *argv)
Spawn a new process with input and output redirection.
Definition missing.c:185
ssize_t vlc_process_fd_Write(struct vlc_process *process, const uint8_t *buf, size_t size, vlc_tick_t timeout_ms)
Write data to the process's standard input with a timeout.
Definition missing.c:215
int vlc_process_Terminate(struct vlc_process *process, bool kill_process)
Stop a vlc_process and wait for its termination.
Definition missing.c:194
ssize_t vlc_process_fd_Read(struct vlc_process *process, uint8_t *buf, size_t size, vlc_tick_t timeout_ms)
Read data from the process's standard output with a timeout.
Definition missing.c:203
Definition process.c:32
This file is a collection of common definitions and types.
int64_t vlc_tick_t
High precision date or time interval.
Definition vlc_tick.h:48