FFmpeg
ffmpeg_sched.h
Go to the documentation of this file.
1 /*
2  * Inter-thread scheduling/synchronization.
3  * Copyright (c) 2023 Anton Khirnov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef FFTOOLS_FFMPEG_SCHED_H
23 #define FFTOOLS_FFMPEG_SCHED_H
24 
25 #include <stddef.h>
26 #include <stdint.h>
27 
28 #include "ffmpeg_utils.h"
29 
30 /*
31  * This file contains the API for the transcode scheduler.
32  *
33  * Overall architecture of the transcoding process involves instances of the
34  * following components:
35  * - demuxers, each containing any number of demuxed streams; demuxed packets
36  * belonging to some stream are sent to any number of decoders (transcoding)
37  * and/or muxers (streamcopy);
38  * - decoders, which receive encoded packets from some demuxed stream or
39  * encoder, decode them, and send decoded frames to any number of filtergraph
40  * inputs (audio/video) or encoders (subtitles);
41  * - filtergraphs, each containing zero or more inputs (0 in case the
42  * filtergraph contains a lavfi source filter), and one or more outputs; the
43  * inputs and outputs need not have matching media types;
44  * each filtergraph input receives decoded frames from some decoder;
45  * filtered frames from each output are sent to some encoder;
46  * - encoders, which receive decoded frames from some decoder (subtitles) or
47  * some filtergraph output (audio/video), encode them, and send encoded
48  * packets to any number of muxed streams or decoders;
49  * - muxers, each containing any number of muxed streams; each muxed stream
50  * receives encoded packets from some demuxed stream (streamcopy) or some
51  * encoder (transcoding); those packets are interleaved and written out by the
52  * muxer.
53  *
54  * There must be at least one muxer instance, otherwise the transcode produces
55  * no output and is meaningless. Otherwise, in a generic transcoding scenario
56  * there may be arbitrary number of instances of any of the above components,
57  * interconnected in various ways.
58  *
59  * The code tries to keep all the output streams across all the muxers in sync
60  * (i.e. at the same DTS), which is accomplished by varying the rates at which
61  * packets are read from different demuxers and lavfi sources. Note that the
62  * degree of control we have over synchronization is fundamentally limited - if
63  * some demuxed streams in the same input are interleaved at different rates
64  * than that at which they are to be muxed (e.g. because an input file is badly
65  * interleaved, or the user changed their speed by mismatching amounts), then
66  * there will be increasing amounts of buffering followed by eventual
67  * transcoding failure.
68  *
69  * N.B. 1: there are meaningful transcode scenarios with no demuxers, e.g.
70  * - encoding and muxing output from filtergraph(s) that have no inputs;
71  * - creating a file that contains nothing but attachments and/or metadata.
72  *
73  * N.B. 2: a filtergraph output could, in principle, feed multiple encoders, but
74  * this is unnecessary because the (a)split filter provides the same
75  * functionality.
76  *
77  * The scheduler, in the above model, is the master object that oversees and
78  * facilitates the transcoding process. The basic idea is that all instances
79  * of the abovementioned components communicate only with the scheduler and not
80  * with each other. The scheduler is then the single place containing the
81  * knowledge about the whole transcoding pipeline.
82  */
83 
84 struct AVFrame;
85 struct AVPacket;
86 
87 typedef struct Scheduler Scheduler;
88 
97 };
98 
99 typedef struct SchedulerNode {
101  unsigned idx;
102  unsigned idx_stream;
103 } SchedulerNode;
104 
105 typedef int (*SchThreadFunc)(void *arg);
106 
107 #define SCH_DSTREAM(file, stream) \
108  (SchedulerNode){ .type = SCH_NODE_TYPE_DEMUX, \
109  .idx = file, .idx_stream = stream }
110 #define SCH_MSTREAM(file, stream) \
111  (SchedulerNode){ .type = SCH_NODE_TYPE_MUX, \
112  .idx = file, .idx_stream = stream }
113 #define SCH_DEC(decoder) \
114  (SchedulerNode){ .type = SCH_NODE_TYPE_DEC, \
115  .idx = decoder }
116 #define SCH_ENC(encoder) \
117  (SchedulerNode){ .type = SCH_NODE_TYPE_ENC, \
118  .idx = encoder }
119 #define SCH_FILTER_IN(filter, input) \
120  (SchedulerNode){ .type = SCH_NODE_TYPE_FILTER_IN, \
121  .idx = filter, .idx_stream = input }
122 #define SCH_FILTER_OUT(filter, output) \
123  (SchedulerNode){ .type = SCH_NODE_TYPE_FILTER_OUT, \
124  .idx = filter, .idx_stream = output }
125 
126 Scheduler *sch_alloc(void);
127 void sch_free(Scheduler **sch);
128 
129 int sch_start(Scheduler *sch);
130 int sch_stop(Scheduler *sch, int64_t *finish_ts);
131 
132 /**
133  * Wait until transcoding terminates or the specified timeout elapses.
134  *
135  * @param timeout_us Amount of time in microseconds after which this function
136  * will timeout.
137  * @param transcode_ts Current transcode timestamp in AV_TIME_BASE_Q, for
138  * informational purposes only.
139  *
140  * @retval 0 waiting timed out, transcoding is not finished
141  * @retval 1 transcoding is finished
142  */
143 int sch_wait(Scheduler *sch, uint64_t timeout_us, int64_t *transcode_ts);
144 
145 /**
146  * Add a demuxer to the scheduler.
147  *
148  * @param func Function executed as the demuxer task.
149  * @param ctx Demuxer state; will be passed to func and used for logging.
150  *
151  * @retval ">=0" Index of the newly-created demuxer.
152  * @retval "<0" Error code.
153  */
154 int sch_add_demux(Scheduler *sch, SchThreadFunc func, void *ctx);
155 /**
156  * Add a demuxed stream for a previously added demuxer.
157  *
158  * @param demux_idx index previously returned by sch_add_demux()
159  *
160  * @retval ">=0" Index of the newly-created demuxed stream.
161  * @retval "<0" Error code.
162  */
163 int sch_add_demux_stream(Scheduler *sch, unsigned demux_idx);
164 
165 /**
166  * Add a decoder to the scheduler.
167  *
168  * @param func Function executed as the decoder task.
169  * @param ctx Decoder state; will be passed to func and used for logging.
170  * @param send_end_ts The decoder will return an end timestamp after flush packets
171  * are delivered to it. See documentation for
172  * sch_dec_receive() for more details.
173  *
174  * @retval ">=0" Index of the newly-created decoder.
175  * @retval "<0" Error code.
176  */
177 int sch_add_dec(Scheduler *sch, SchThreadFunc func, void *ctx,
178  int send_end_ts);
179 
180 /**
181  * Add a filtergraph to the scheduler.
182  *
183  * @param nb_inputs Number of filtergraph inputs.
184  * @param nb_outputs number of filtergraph outputs
185  * @param func Function executed as the filtering task.
186  * @param ctx Filter state; will be passed to func and used for logging.
187  *
188  * @retval ">=0" Index of the newly-created filtergraph.
189  * @retval "<0" Error code.
190  */
191 int sch_add_filtergraph(Scheduler *sch, unsigned nb_inputs, unsigned nb_outputs,
192  SchThreadFunc func, void *ctx);
193 
194 /**
195  * Add a muxer to the scheduler.
196  *
197  * Note that muxer thread startup is more complicated than for other components,
198  * because
199  * - muxer streams fed by audio/video encoders become initialized dynamically at
200  * runtime, after those encoders receive their first frame and initialize
201  * themselves, followed by calling sch_mux_stream_ready()
202  * - the header can be written after all the streams for a muxer are initialized
203  * - we may need to write an SDP, which must happen
204  * - AFTER all the headers are written
205  * - BEFORE any packets are written by any muxer
206  * - with all the muxers quiescent
207  * To avoid complicated muxer-thread synchronization dances, we postpone
208  * starting the muxer threads until after the SDP is written. The sequence of
209  * events is then as follows:
210  * - After sch_mux_stream_ready() is called for all the streams in a given muxer,
211  * the header for that muxer is written (care is taken that headers for
212  * different muxers are not written concurrently, since they write file
213  * information to stderr). If SDP is not wanted, the muxer thread then starts
214  * and muxing begins.
215  * - When SDP _is_ wanted, no muxer threads start until the header for the last
216  * muxer is written. After that, the SDP is written, after which all the muxer
217  * threads are started at once.
218  *
219  * In order for the above to work, the scheduler needs to be able to invoke
220  * just writing the header, which is the reason the init parameter exists.
221  *
222  * @param func Function executed as the muxing task.
223  * @param init Callback that is called to initialize the muxer and write the
224  * header. Called after sch_mux_stream_ready() is called for all the
225  * streams in the muxer.
226  * @param ctx Muxer state; will be passed to func/init and used for logging.
227  * @param sdp_auto Determines automatic SDP writing - see sch_sdp_filename().
228  * @param thread_queue_size number of packets that can be buffered before
229  * sending to the muxer blocks
230  *
231  * @retval ">=0" Index of the newly-created muxer.
232  * @retval "<0" Error code.
233  */
234 int sch_add_mux(Scheduler *sch, SchThreadFunc func, int (*init)(void *),
235  void *ctx, int sdp_auto, unsigned thread_queue_size);
236 
237 /**
238  * Default size of a packet thread queue. For muxing this can be overridden by
239  * the thread_queue_size option as passed to a call to sch_add_mux().
240  */
241 #define DEFAULT_PACKET_THREAD_QUEUE_SIZE 8
242 
243 /**
244  * Default size of a frame thread queue.
245  */
246 #define DEFAULT_FRAME_THREAD_QUEUE_SIZE 8
247 
248 /**
249  * Add a muxed stream for a previously added muxer.
250  *
251  * @param mux_idx index previously returned by sch_add_mux()
252  *
253  * @retval ">=0" Index of the newly-created muxed stream.
254  * @retval "<0" Error code.
255  */
256 int sch_add_mux_stream(Scheduler *sch, unsigned mux_idx);
257 
258 /**
259  * Configure limits on packet buffering performed before the muxer task is
260  * started.
261  *
262  * @param mux_idx index previously returned by sch_add_mux()
263  * @param stream_idx_idx index previously returned by sch_add_mux_stream()
264  * @param data_threshold Total size of the buffered packets' data after which
265  * max_packets applies.
266  * @param max_packets maximum Maximum number of buffered packets after
267  * data_threshold is reached.
268  */
269 void sch_mux_stream_buffering(Scheduler *sch, unsigned mux_idx, unsigned stream_idx,
270  size_t data_threshold, int max_packets);
271 
272 /**
273  * Signal to the scheduler that the specified muxed stream is initialized and
274  * ready. Muxing is started once all the streams are ready.
275  */
276 int sch_mux_stream_ready(Scheduler *sch, unsigned mux_idx, unsigned stream_idx);
277 
278 /**
279  * Set the file path for the SDP.
280  *
281  * The SDP is written when either of the following is true:
282  * - this function is called at least once
283  * - sdp_auto=1 is passed to EVERY call of sch_add_mux()
284  */
285 int sch_sdp_filename(Scheduler *sch, const char *sdp_filename);
286 
287 /**
288  * Add an encoder to the scheduler.
289  *
290  * @param func Function executed as the encoding task.
291  * @param ctx Encoder state; will be passed to func and used for logging.
292  * @param open_cb This callback, if specified, will be called when the first
293  * frame is obtained for this encoder. For audio encoders with a
294  * fixed frame size (which use a sync queue in the scheduler to
295  * rechunk frames), it must return that frame size on success.
296  * Otherwise (non-audio, variable frame size) it should return 0.
297  *
298  * @retval ">=0" Index of the newly-created encoder.
299  * @retval "<0" Error code.
300  */
301 int sch_add_enc(Scheduler *sch, SchThreadFunc func, void *ctx,
302  int (*open_cb)(void *func_arg, const struct AVFrame *frame));
303 
304 /**
305  * Add an pre-encoding sync queue to the scheduler.
306  *
307  * @param buf_size_us Sync queue buffering size, passed to sq_alloc().
308  * @param logctx Logging context for the sync queue. passed to sq_alloc().
309  *
310  * @retval ">=0" Index of the newly-created sync queue.
311  * @retval "<0" Error code.
312  */
313 int sch_add_sq_enc(Scheduler *sch, uint64_t buf_size_us, void *logctx);
314 int sch_sq_add_enc(Scheduler *sch, unsigned sq_idx, unsigned enc_idx,
315  int limiting, uint64_t max_frames);
316 
318 
320  /**
321  * Treat the packet as an EOF for SCH_NODE_TYPE_MUX destinations
322  * send normally to other types.
323  */
325 };
326 
327 /**
328  * Called by demuxer tasks to communicate with their downstreams. The following
329  * may be sent:
330  * - a demuxed packet for the stream identified by pkt->stream_index;
331  * - demuxer discontinuity/reset (e.g. after a seek) - this is signalled by an
332  * empty packet with stream_index=-1.
333  *
334  * @param demux_idx demuxer index
335  * @param pkt A demuxed packet to send.
336  * When flushing (i.e. pkt->stream_index=-1 on entry to this
337  * function), on successful return pkt->pts/pkt->time_base will be
338  * set to the maximum end timestamp of any decoded audio stream, or
339  * AV_NOPTS_VALUE if no decoded audio streams are present.
340  *
341  * @retval "non-negative value" success
342  * @retval AVERROR_EOF all consumers for the stream are done
343  * @retval AVERROR_EXIT all consumers are done, should terminate demuxing
344  * @retval "anoter negative error code" other failure
345  */
346 int sch_demux_send(Scheduler *sch, unsigned demux_idx, struct AVPacket *pkt,
347  unsigned flags);
348 
349 /**
350  * Called by decoder tasks to receive a packet for decoding.
351  *
352  * @param dec_idx decoder index
353  * @param pkt Input packet will be written here on success.
354  *
355  * An empty packet signals that the decoder should be flushed, but
356  * more packets will follow (e.g. after seeking). When a decoder
357  * created with send_end_ts=1 receives a flush packet, it must write
358  * the end timestamp of the stream after flushing to
359  * pkt->pts/time_base on the next call to this function (if any).
360  *
361  * @retval "non-negative value" success
362  * @retval AVERROR_EOF no more packets will arrive, should terminate decoding
363  * @retval "another negative error code" other failure
364  */
365 int sch_dec_receive(Scheduler *sch, unsigned dec_idx, struct AVPacket *pkt);
366 
367 /**
368  * Called by decoder tasks to send a decoded frame downstream.
369  *
370  * @param dec_idx Decoder index previously returned by sch_add_dec().
371  * @param frame Decoded frame; on success it is consumed and cleared by this
372  * function
373  *
374  * @retval ">=0" success
375  * @retval AVERROR_EOF all consumers are done, should terminate decoding
376  * @retval "another negative error code" other failure
377  */
378 int sch_dec_send(Scheduler *sch, unsigned dec_idx, struct AVFrame *frame);
379 
380 /**
381  * Called by filtergraph tasks to obtain frames for filtering. Will wait for a
382  * frame to become available and return it in frame.
383  *
384  * Filtergraphs that contain lavfi sources and do not currently require new
385  * input frames should call this function as a means of rate control - then
386  * in_idx should be set equal to nb_inputs on entry to this function.
387  *
388  * @param fg_idx Filtergraph index previously returned by sch_add_filtergraph().
389  * @param[in,out] in_idx On input contains the index of the input on which a frame
390  * is most desired. May be set to nb_inputs to signal that
391  * the filtergraph does not need more input currently.
392  *
393  * On success, will be replaced with the input index of
394  * the actually returned frame or EOF timestamp.
395  *
396  * @retval ">=0" Frame data or EOF timestamp was delivered into frame, in_idx
397  * contains the index of the input it belongs to.
398  * @retval AVERROR(EAGAIN) No frame was returned, the filtergraph should
399  * resume filtering. May only be returned when
400  * in_idx=nb_inputs on entry to this function.
401  * @retval AVERROR_EOF No more frames will arrive, should terminate filtering.
402  */
403 int sch_filter_receive(Scheduler *sch, unsigned fg_idx,
404  unsigned *in_idx, struct AVFrame *frame);
405 /**
406  * Called by filter tasks to signal that a filter input will no longer accept input.
407  *
408  * @param fg_idx Filtergraph index previously returned from sch_add_filtergraph().
409  * @param in_idx Index of the input to finish.
410  */
411 void sch_filter_receive_finish(Scheduler *sch, unsigned fg_idx, unsigned in_idx);
412 
413 /**
414  * Called by filtergraph tasks to send a filtered frame or EOF to consumers.
415  *
416  * @param fg_idx Filtergraph index previously returned by sch_add_filtergraph().
417  * @param out_idx Index of the output which produced the frame.
418  * @param frame The frame to send to consumers. When NULL, signals that no more
419  * frames will be produced for the specified output. When non-NULL,
420  * the frame is consumed and cleared by this function on success.
421  *
422  * @retval "non-negative value" success
423  * @retval AVERROR_EOF all consumers are done
424  * @retval "anoter negative error code" other failure
425  */
426 int sch_filter_send(Scheduler *sch, unsigned fg_idx, unsigned out_idx,
427  struct AVFrame *frame);
428 
429 int sch_filter_command(Scheduler *sch, unsigned fg_idx, struct AVFrame *frame);
430 
431 /**
432  * Called by encoder tasks to obtain frames for encoding. Will wait for a frame
433  * to become available and return it in frame.
434  *
435  * @param enc_idx Encoder index previously returned by sch_add_enc().
436  * @param frame Newly-received frame will be stored here on success. Must be
437  * clean on entrance to this function.
438  *
439  * @retval 0 A frame was successfully delivered into frame.
440  * @retval AVERROR_EOF No more frames will be delivered, the encoder should
441  * flush everything and terminate.
442  *
443  */
444 int sch_enc_receive(Scheduler *sch, unsigned enc_idx, struct AVFrame *frame);
445 
446 /**
447  * Called by encoder tasks to send encoded packets downstream.
448  *
449  * @param enc_idx Encoder index previously returned by sch_add_enc().
450  * @param pkt An encoded packet; it will be consumed and cleared by this
451  * function on success.
452  *
453  * @retval 0 success
454  * @retval "<0" Error code.
455  */
456 int sch_enc_send (Scheduler *sch, unsigned enc_idx, struct AVPacket *pkt);
457 
458 /**
459  * Called by muxer tasks to obtain packets for muxing. Will wait for a packet
460  * for any muxed stream to become available and return it in pkt.
461  *
462  * @param mux_idx Muxer index previously returned by sch_add_mux().
463  * @param pkt Newly-received packet will be stored here on success. Must be
464  * clean on entrance to this function.
465  *
466  * @retval 0 A packet was successfully delivered into pkt. Its stream_index
467  * corresponds to a stream index previously returned from
468  * sch_add_mux_stream().
469  * @retval AVERROR_EOF When pkt->stream_index is non-negative, this signals that
470  * no more packets will be delivered for this stream index.
471  * Otherwise this indicates that no more packets will be
472  * delivered for any stream and the muxer should therefore
473  * flush everything and terminate.
474  */
475 int sch_mux_receive(Scheduler *sch, unsigned mux_idx, struct AVPacket *pkt);
476 
477 /**
478  * Called by muxer tasks to signal that a stream will no longer accept input.
479  *
480  * @param stream_idx Stream index previously returned from sch_add_mux_stream().
481  */
482 void sch_mux_receive_finish(Scheduler *sch, unsigned mux_idx, unsigned stream_idx);
483 
484 int sch_mux_sub_heartbeat_add(Scheduler *sch, unsigned mux_idx, unsigned stream_idx,
485  unsigned dec_idx);
486 int sch_mux_sub_heartbeat(Scheduler *sch, unsigned mux_idx, unsigned stream_idx,
487  const AVPacket *pkt);
488 
489 #endif /* FFTOOLS_FFMPEG_SCHED_H */
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:68
SchedulerNode::idx_stream
unsigned idx_stream
Definition: ffmpeg_sched.h:102
SCH_NODE_TYPE_ENC
@ SCH_NODE_TYPE_ENC
Definition: ffmpeg_sched.h:94
int64_t
long long int64_t
Definition: coverity.c:34
sch_stop
int sch_stop(Scheduler *sch, int64_t *finish_ts)
Definition: ffmpeg_sched.c:2484
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
sch_add_demux
int sch_add_demux(Scheduler *sch, SchThreadFunc func, void *ctx)
Add a demuxer to the scheduler.
Definition: ffmpeg_sched.c:676
SCH_NODE_TYPE_MUX
@ SCH_NODE_TYPE_MUX
Definition: ffmpeg_sched.h:92
sch_dec_send
int sch_dec_send(Scheduler *sch, unsigned dec_idx, struct AVFrame *frame)
Called by decoder tasks to send a decoded frame downstream.
Definition: ffmpeg_sched.c:2160
SchedulerNode::type
enum SchedulerNodeType type
Definition: ffmpeg_sched.h:100
sch_free
void sch_free(Scheduler **sch)
Definition: ffmpeg_sched.c:461
SchThreadFunc
int(* SchThreadFunc)(void *arg)
Definition: ffmpeg_sched.h:105
SCH_NODE_TYPE_NONE
@ SCH_NODE_TYPE_NONE
Definition: ffmpeg_sched.h:90
sch_mux_receive
int sch_mux_receive(Scheduler *sch, unsigned mux_idx, struct AVPacket *pkt)
Called by muxer tasks to obtain packets for muxing.
Definition: ffmpeg_sched.c:2000
sch_enc_send
int sch_enc_send(Scheduler *sch, unsigned enc_idx, struct AVPacket *pkt)
Called by encoder tasks to send encoded packets downstream.
Definition: ffmpeg_sched.c:2265
pkt
AVPacket * pkt
Definition: movenc.c:59
sch_mux_stream_ready
int sch_mux_stream_ready(Scheduler *sch, unsigned mux_idx, unsigned stream_idx)
Signal to the scheduler that the specified muxed stream is initialized and ready.
Definition: ffmpeg_sched.c:1137
sch_sdp_filename
int sch_sdp_filename(Scheduler *sch, const char *sdp_filename)
Set the file path for the SDP.
Definition: ffmpeg_sched.c:607
SchedulerNodeType
SchedulerNodeType
Definition: ffmpeg_sched.h:89
sch_demux_send
int sch_demux_send(Scheduler *sch, unsigned demux_idx, struct AVPacket *pkt, unsigned flags)
Called by demuxer tasks to communicate with their downstreams.
Definition: ffmpeg_sched.c:1956
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ffmpeg_utils.h
sch_enc_receive
int sch_enc_receive(Scheduler *sch, unsigned enc_idx, struct AVFrame *frame)
Called by encoder tasks to obtain frames for encoding.
Definition: ffmpeg_sched.c:2221
sch_start
int sch_start(Scheduler *sch)
Definition: ffmpeg_sched.c:1516
frame
static AVFrame * frame
Definition: demux_decode.c:54
arg
const char * arg
Definition: jacosubdec.c:67
sch_mux_sub_heartbeat
int sch_mux_sub_heartbeat(Scheduler *sch, unsigned mux_idx, unsigned stream_idx, const AVPacket *pkt)
Definition: ffmpeg_sched.c:2031
DemuxSendFlags
DemuxSendFlags
Definition: ffmpeg_sched.h:319
sch_connect
int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst)
Definition: ffmpeg_sched.c:897
SCH_NODE_TYPE_DEMUX
@ SCH_NODE_TYPE_DEMUX
Definition: ffmpeg_sched.h:91
sch_filter_command
int sch_filter_command(Scheduler *sch, unsigned fg_idx, struct AVFrame *frame)
Definition: ffmpeg_sched.c:2418
sch_alloc
Scheduler * sch_alloc(void)
Definition: ffmpeg_sched.c:573
DEMUX_SEND_STREAMCOPY_EOF
@ DEMUX_SEND_STREAMCOPY_EOF
Treat the packet as an EOF for SCH_NODE_TYPE_MUX destinations send normally to other types.
Definition: ffmpeg_sched.h:324
sch_add_demux_stream
int sch_add_demux_stream(Scheduler *sch, unsigned demux_idx)
Add a demuxed stream for a previously added demuxer.
Definition: ffmpeg_sched.c:703
Scheduler
Definition: ffmpeg_sched.c:269
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
sch_filter_receive_finish
void sch_filter_receive_finish(Scheduler *sch, unsigned fg_idx, unsigned in_idx)
Called by filter tasks to signal that a filter input will no longer accept input.
Definition: ffmpeg_sched.c:2360
sch_add_enc
int sch_add_enc(Scheduler *sch, SchThreadFunc func, void *ctx, int(*open_cb)(void *func_arg, const struct AVFrame *frame))
Add an encoder to the scheduler.
SCH_NODE_TYPE_FILTER_OUT
@ SCH_NODE_TYPE_FILTER_OUT
Definition: ffmpeg_sched.h:96
sch_add_dec
int sch_add_dec(Scheduler *sch, SchThreadFunc func, void *ctx, int send_end_ts)
Add a decoder to the scheduler.
Definition: ffmpeg_sched.c:721
sch_filter_send
int sch_filter_send(Scheduler *sch, unsigned fg_idx, unsigned out_idx, struct AVFrame *frame)
Called by filtergraph tasks to send a filtered frame or EOF to consumers.
Definition: ffmpeg_sched.c:2381
sch_add_sq_enc
int sch_add_sq_enc(Scheduler *sch, uint64_t buf_size_us, void *logctx)
Add an pre-encoding sync queue to the scheduler.
Definition: ffmpeg_sched.c:841
SCH_NODE_TYPE_FILTER_IN
@ SCH_NODE_TYPE_FILTER_IN
Definition: ffmpeg_sched.h:95
SchedulerNode
Definition: ffmpeg_sched.h:99
SCH_NODE_TYPE_DEC
@ SCH_NODE_TYPE_DEC
Definition: ffmpeg_sched.h:93
sch_wait
int sch_wait(Scheduler *sch, uint64_t timeout_us, int64_t *transcode_ts)
Wait until transcoding terminates or the specified timeout elapses.
Definition: ffmpeg_sched.c:1582
sch_add_mux_stream
int sch_add_mux_stream(Scheduler *sch, unsigned mux_idx)
Add a muxed stream for a previously added muxer.
Definition: ffmpeg_sched.c:644
sch_add_filtergraph
int sch_add_filtergraph(Scheduler *sch, unsigned nb_inputs, unsigned nb_outputs, SchThreadFunc func, void *ctx)
Add a filtergraph to the scheduler.
Definition: ffmpeg_sched.c:799
sch_filter_receive
int sch_filter_receive(Scheduler *sch, unsigned fg_idx, unsigned *in_idx, struct AVFrame *frame)
Called by filtergraph tasks to obtain frames for filtering.
Definition: ffmpeg_sched.c:2316
sch_sq_add_enc
int sch_sq_add_enc(Scheduler *sch, unsigned sq_idx, unsigned enc_idx, int limiting, uint64_t max_frames)
Definition: ffmpeg_sched.c:866
sch_mux_sub_heartbeat_add
int sch_mux_sub_heartbeat_add(Scheduler *sch, unsigned mux_idx, unsigned stream_idx, unsigned dec_idx)
Definition: ffmpeg_sched.c:1162
SchedulerNode::idx
unsigned idx
Definition: ffmpeg_sched.h:101
AVPacket
This structure stores compressed data.
Definition: packet.h:499
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
sch_dec_receive
int sch_dec_receive(Scheduler *sch, unsigned dec_idx, struct AVPacket *pkt)
Called by decoder tasks to receive a packet for decoding.
Definition: ffmpeg_sched.c:2084
sch_mux_receive_finish
void sch_mux_receive_finish(Scheduler *sch, unsigned mux_idx, unsigned stream_idx)
Called by muxer tasks to signal that a stream will no longer accept input.
Definition: ffmpeg_sched.c:2013
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
sch_add_mux
int sch_add_mux(Scheduler *sch, SchThreadFunc func, int(*init)(void *), void *ctx, int sdp_auto, unsigned thread_queue_size)
Add a muxer to the scheduler.
Definition: ffmpeg_sched.c:620
int
int
Definition: ffmpeg_filter.c:409
sch_mux_stream_buffering
void sch_mux_stream_buffering(Scheduler *sch, unsigned mux_idx, unsigned stream_idx, size_t data_threshold, int max_packets)
Configure limits on packet buffering performed before the muxer task is started.
Definition: ffmpeg_sched.c:1121