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 or equal to 0).
34 * @param [in] argv Array of argument strings. May be NULL if argc is 0;
35 * otherwise argv[0] must not be NULL.
36 *
37 * @return A pointer to the newly created vlc_process structure on
38 * success, or NULL on failure.
39 */
40VLC_API struct vlc_process *
41vlc_process_Spawn(const char *path, int argc, const char *const *argv);
42
43/**
44 * Stop a vlc_process and wait for its termination.
45 *
46 * Closes its file descriptors, and waits for it to exit. Optionally sends a
47 * termination signal to the process,
48 *
49 * @param [in] process Pointer to the vlc_process instance. Must not
50 * be NULL.
51 * @param [in] kill_process Whether to forcibly terminate the process
52 * before waiting.
53 *
54 * @return The exit status of the process, or -1 on error.
55 */
56VLC_API int
57vlc_process_Terminate(struct vlc_process *process, bool kill_process);
58
59/**
60 * Read data from the process's standard output with a timeout.
61 *
62 * Attempts to read up to @p size bytes from the process's standard output
63 * into the provided buffer, waiting up to @p timeout_ms milliseconds for data
64 * to become available.
65 *
66 * On POSIX systems, this uses poll to wait for readability. On Windows,
67 * a platform-specific implementation is used due to limitations with poll on
68 * non-socket handles.
69 *
70 * @param [in] process Pointer to the vlc_process instance.
71 * @param [out] buf Buffer where the read data will be stored.
72 * @param [in] size Maximum number of bytes to read.
73 * @param [in] timeout_ms Timeout in milliseconds to wait for data.
74 *
75 * @return The number of bytes read on success,
76 * -1 on error, and errno is set to indicate the error.
77 */
78VLC_API ssize_t
79vlc_process_fd_Read(struct vlc_process *process, uint8_t *buf, size_t size,
80 vlc_tick_t timeout_ms);
81
82/**
83 * Write data to the process's standard input with a timeout.
84 *
85 * Attempts to write up to @p size bytes from the provided buffer to the
86 * process's standard input, waiting up to @p timeout_ms milliseconds for the
87 * pipe to become writable.
88 *
89 * On POSIX systems, this uses poll to wait for writability. On Windows,
90 * a platform-specific implementation is used due to limitations with poll on
91 * non-socket handles.
92 *
93 * @param [in] process Pointer to the vlc_process instance.
94 * @param [in] buf Buffer containing the data to write.
95 * @param [in] size Number of bytes to write.
96 * @param [in] timeout_ms Timeout in milliseconds to wait for the pipe to be
97 * writable.
98 *
99 * @return The number of bytes read on success,
100 * -1 on error, and errno is set to indicate the error.
101 */
102VLC_API ssize_t
103vlc_process_fd_Write(struct vlc_process *process, const uint8_t *buf, size_t size,
104 vlc_tick_t timeout_ms);
105
106/**
107 * @} process
108 */
109
110#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