Skip to content

Commit ae60615

Browse files
committed
upipe_avfilter: support avfilter_graph_send_command
1 parent da287b0 commit ae60615

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

include/upipe-av/upipe_avfilter.h

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2018 OpenHeadend S.A.R.L.
3-
* Copyright (C) 2019-2020 EasyTools
3+
* Copyright (C) 2019-2025 EasyTools
44
*
55
* Authors: Clément Vasseur
66
* Arnaud de Turckheim
@@ -49,6 +49,9 @@ enum upipe_avfilt_command {
4949
UPIPE_AVFILT_SET_FILTERS_DESC,
5050
/** set the hardware config (const char *, const char *) */
5151
UPIPE_AVFILT_SET_HW_CONFIG,
52+
/** sends a command to one or more filter instances
53+
(const char *, const char *, const char *) */
54+
UPIPE_AVFILT_SEND_COMMAND,
5255
};
5356

5457
/** @This converts @ref upipe_avfilt_command to a string.
@@ -61,6 +64,7 @@ static inline const char *upipe_avfilt_command_str(int command)
6164
switch ((enum upipe_avfilt_command)command) {
6265
UBASE_CASE_TO_STR(UPIPE_AVFILT_SET_FILTERS_DESC);
6366
UBASE_CASE_TO_STR(UPIPE_AVFILT_SET_HW_CONFIG);
67+
UBASE_CASE_TO_STR(UPIPE_AVFILT_SEND_COMMAND);
6468
case UPIPE_AVFILT_SENTINEL: break;
6569
}
6670
return NULL;
@@ -95,6 +99,46 @@ static inline int upipe_avfilt_set_hw_config(struct upipe *upipe,
9599
hw_type, hw_device);
96100
}
97101

102+
/** @This sends a command to one or more filter instances
103+
*
104+
* @param upipe description structure of the pipe
105+
* @param target the filter(s) to which the command should be sent "all" sends
106+
* to all filters otherwise it can be a filter or filter instance name which
107+
* will send the command to all matching filters.
108+
* @param command the command to send
109+
* @param arg the arguments of the command
110+
* @return an error code
111+
*/
112+
static inline int upipe_avfilt_send_command(struct upipe *upipe,
113+
const char *target,
114+
const char *command,
115+
const char *arg)
116+
{
117+
return upipe_control(upipe, UPIPE_AVFILT_SEND_COMMAND,
118+
UPIPE_AVFILT_SIGNATURE,
119+
target, command, arg);
120+
}
121+
122+
/** @This sends a command to one or more filter instances
123+
*
124+
* @param upipe description structure of the pipe
125+
* @param target the filter(s) to which the command should be sent "all" sends
126+
* to all filters otherwise it can be a filter or filter instance name which
127+
* will send the command to all matching filters.
128+
* @param command the command to send
129+
* @param format the arguments format string of the command
130+
* @return an error code
131+
*/
132+
UBASE_FMT_PRINTF(4, 5)
133+
static inline int upipe_avfilt_send_command_va(struct upipe *upipe,
134+
const char *target,
135+
const char *command,
136+
const char *format, ...)
137+
{
138+
UBASE_VARARG(upipe_avfilt_send_command(upipe, target, command, string),
139+
UBASE_ERR_INVALID);
140+
}
141+
98142
/** @This returns the management structure for all avfilter pipes.
99143
*
100144
* @return pointer to manager

lib/upipe-av/upipe_avfilter.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2018 OpenHeadend S.A.R.L.
3-
* Copyright (C) 2019-2020 EasyTools
3+
* Copyright (C) 2019-2025 EasyTools
44
*
55
* Authors: Clément Vasseur
66
* Arnaud de Turckheim
@@ -1867,6 +1867,32 @@ static int _upipe_avfilt_set_hw_config(struct upipe *upipe,
18671867
return UBASE_ERR_NONE;
18681868
}
18691869

1870+
/** @This sends a command to one or more filter instances
1871+
*
1872+
* @param upipe description structure of the pipe
1873+
* @param target the filter(s) to which the command should be sent "all" sends
1874+
* to all filters otherwise it can be a filter or filter instance name which
1875+
* will send the command to all matching filters.
1876+
* @param command the command to send
1877+
* @param arg the arguments of the command
1878+
* @return an error code
1879+
*/
1880+
static int _upipe_avfilt_send_command(struct upipe *upipe, const char *target,
1881+
const char *command, const char *arg)
1882+
{
1883+
struct upipe_avfilt *upipe_avfilt = upipe_avfilt_from_upipe(upipe);
1884+
1885+
if (unlikely(!upipe_avfilt->configured))
1886+
return UBASE_ERR_INVALID;
1887+
1888+
int err = avfilter_graph_send_command(upipe_avfilt->filter_graph, target,
1889+
command, arg, NULL, 0, 0);
1890+
if (err < 0)
1891+
return UBASE_ERR_EXTERNAL;
1892+
1893+
return UBASE_ERR_NONE;
1894+
}
1895+
18701896
/** @internal @This sets the input pipe flow definition for video.
18711897
*
18721898
* @param upipe description structure of the pipe
@@ -2488,6 +2514,13 @@ static int upipe_avfilt_control(struct upipe *upipe,
24882514
const char *hw_device = va_arg(args, const char *);
24892515
return _upipe_avfilt_set_hw_config(upipe, hw_type, hw_device);
24902516
}
2517+
case UPIPE_AVFILT_SEND_COMMAND: {
2518+
UBASE_SIGNATURE_CHECK(args, UPIPE_AVFILT_SIGNATURE)
2519+
const char *target = va_arg(args, const char *);
2520+
const char *command = va_arg(args, const char *);
2521+
const char *arg = va_arg(args, const char *);
2522+
return _upipe_avfilt_send_command(upipe, target, command, arg);
2523+
}
24912524
default:
24922525
return UBASE_ERR_UNHANDLED;
24932526
}

0 commit comments

Comments
 (0)