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 <stdatomic.h>
14
15#include <vlc_common.h>
16#include <vlc_vector.h>
17#include <vlc_tick.h>
18#include <vlc_threads.h>
19#include <vlc_stream.h>
20
21/**
22 * @ingroup misc
23 * @file
24 * VLC_PROCESS API
25 * @defgroup process Process API
26 * @{
27 */
28
29/**
30 * Spawn a new process with input and output redirection.
31 *
32 * Creates and starts a new vlc_process for the specified executable path with
33 * the given arguments. Sets up pipes to allow reading from the process's
34 * standard output and writing to its standard input.
35 *
36 * @param [in] path Path to the executable to run. Must not be NULL.
37 * @param [in] argc Number of arguments passed to the process (must be
38 * greater than 0).
39 * @param [in] argv Array of argument strings (argv[0] must not be NULL).
40 *
41 * @return A pointer to the newly created vlc_process structure on
42 * success, or NULL on failure.
43 */
44VLC_API struct vlc_process *
45vlc_process_Spawn(const char *path, int argc, const char *const *argv);
46
47/**
48 * Stop a vlc_process and wait for its termination.
49 *
50 * Closes its file descriptors, and waits for it to exit. Optionally sends a
51 * termination signal to the process,
52 *
53 * @param [in] process Pointer to the vlc_process instance. Must not
54 * be NULL.
55 * @param [in] kill_process Whether to forcibly terminate the process
56 * before waiting.
57 *
58 * @return The exit status of the process, or -1 on error.
59 */
60VLC_API int
61vlc_process_Terminate(struct vlc_process *process, bool kill_process);
62
63/**
64 * Read data from the process's standard output with a timeout.
65 *
66 * Attempts to read up to @p size bytes from the process's standard output
67 * into the provided buffer, waiting up to @p timeout_ms milliseconds for data
68 * to become available.
69 *
70 * On POSIX systems, this uses poll to wait for readability. On Windows,
71 * a platform-specific implementation is used due to limitations with poll on
72 * non-socket handles.
73 *
74 * @param [in] process Pointer to the vlc_process instance.
75 * @param [out] buf Buffer where the read data will be stored.
76 * @param [in] size Maximum number of bytes to read.
77 * @param [in] timeout_ms Timeout in milliseconds to wait for data.
78 *
79 * @return The number of bytes read on success,
80 * -1 on error, and errno is set to indicate the error.
81 */
82VLC_API ssize_t
83vlc_process_fd_Read(struct vlc_process *process, uint8_t *buf, size_t size,
84 vlc_tick_t timeout_ms);
85
86/**
87 * Write data to the process's standard input with a timeout.
88 *
89 * Attempts to write up to @p size bytes from the provided buffer to the
90 * process's standard input, waiting up to @p timeout_ms milliseconds for the
91 * pipe to become writable.
92 *
93 * On POSIX systems, this uses poll to wait for writability. On Windows,
94 * a platform-specific implementation is used due to limitations with poll on
95 * non-socket handles.
96 *
97 * @param [in] process Pointer to the vlc_process instance.
98 * @param [in] buf Buffer containing the data to write.
99 * @param [in] size Number of bytes to write.
100 * @param [in] timeout_ms Timeout in milliseconds to wait for the pipe to be
101 * writable.
102 *
103 * @return The number of bytes read on success,
104 * -1 on error, and errno is set to indicate the error.
105 */
106VLC_API ssize_t
107vlc_process_fd_Write(struct vlc_process *process, const uint8_t *buf, size_t size,
108 vlc_tick_t timeout_ms);
109
110/**
111 * @} process
112 */
113
114#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:192
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:222
int vlc_process_Terminate(struct vlc_process *process, bool kill_process)
Stop a vlc_process and wait for its termination.
Definition missing.c:201
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:210
Definition process.c:29
This file is a collection of common definitions and types.
Byte streams and byte stream filter modules interface.
Thread primitive declarations.
int64_t vlc_tick_t
High precision date or time interval.
Definition vlc_tick.h:48
This provides convenience helpers for vectors.