FFmpeg
|
Go to the source code of this file.
Data Structures | |
struct | SchedulerNode |
Macros | |
#define | SCH_DSTREAM(file, stream) |
#define | SCH_MSTREAM(file, stream) |
#define | SCH_DEC_IN(decoder) |
#define | SCH_DEC_OUT(decoder, out_idx) |
#define | SCH_ENC(encoder) |
#define | SCH_FILTER_IN(filter, input) |
#define | SCH_FILTER_OUT(filter, output) |
#define | DEFAULT_PACKET_THREAD_QUEUE_SIZE 8 |
Default size of a packet thread queue. More... | |
#define | DEFAULT_FRAME_THREAD_QUEUE_SIZE 8 |
Default size of a frame thread queue. More... | |
Typedefs | |
typedef int(* | SchThreadFunc) (void *arg) |
Enumerations | |
enum | SchedulerNodeType { SCH_NODE_TYPE_NONE = 0, SCH_NODE_TYPE_DEMUX, SCH_NODE_TYPE_MUX, SCH_NODE_TYPE_DEC, SCH_NODE_TYPE_ENC, SCH_NODE_TYPE_FILTER_IN, SCH_NODE_TYPE_FILTER_OUT } |
enum | DemuxSendFlags { DEMUX_SEND_STREAMCOPY_EOF = (1 << 0) } |
Functions | |
Scheduler * | sch_alloc (void) |
void | sch_free (Scheduler **sch) |
int | sch_start (Scheduler *sch) |
int | sch_stop (Scheduler *sch, int64_t *finish_ts) |
int | sch_wait (Scheduler *sch, uint64_t timeout_us, int64_t *transcode_ts) |
Wait until transcoding terminates or the specified timeout elapses. More... | |
int | sch_add_demux (Scheduler *sch, SchThreadFunc func, void *ctx) |
Add a demuxer to the scheduler. More... | |
int | sch_add_demux_stream (Scheduler *sch, unsigned demux_idx) |
Add a demuxed stream for a previously added demuxer. More... | |
int | sch_add_dec (Scheduler *sch, SchThreadFunc func, void *ctx, int send_end_ts) |
Add a decoder to the scheduler. More... | |
int | sch_add_dec_output (Scheduler *sch, unsigned dec_idx) |
Add another output to decoder (e.g. More... | |
int | sch_add_filtergraph (Scheduler *sch, unsigned nb_inputs, unsigned nb_outputs, SchThreadFunc func, void *ctx) |
Add a filtergraph to the scheduler. More... | |
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. More... | |
int | sch_add_mux_stream (Scheduler *sch, unsigned mux_idx) |
Add a muxed stream for a previously added muxer. More... | |
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. More... | |
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. More... | |
int | sch_sdp_filename (Scheduler *sch, const char *sdp_filename) |
Set the file path for the SDP. More... | |
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. More... | |
int | sch_add_sq_enc (Scheduler *sch, uint64_t buf_size_us, void *logctx) |
Add an pre-encoding sync queue to the scheduler. More... | |
int | sch_sq_add_enc (Scheduler *sch, unsigned sq_idx, unsigned enc_idx, int limiting, uint64_t max_frames) |
int | sch_connect (Scheduler *sch, SchedulerNode src, SchedulerNode dst) |
int | sch_demux_send (Scheduler *sch, unsigned demux_idx, struct AVPacket *pkt, unsigned flags) |
Called by demuxer tasks to communicate with their downstreams. More... | |
int | sch_dec_receive (Scheduler *sch, unsigned dec_idx, struct AVPacket *pkt) |
Called by decoder tasks to receive a packet for decoding. More... | |
int | sch_dec_send (Scheduler *sch, unsigned dec_idx, unsigned out_idx, struct AVFrame *frame) |
Called by decoder tasks to send a decoded frame downstream. More... | |
int | sch_filter_receive (Scheduler *sch, unsigned fg_idx, unsigned *in_idx, struct AVFrame *frame) |
Called by filtergraph tasks to obtain frames for filtering. More... | |
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. More... | |
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. More... | |
int | sch_filter_command (Scheduler *sch, unsigned fg_idx, struct AVFrame *frame) |
int | sch_enc_receive (Scheduler *sch, unsigned enc_idx, struct AVFrame *frame) |
Called by encoder tasks to obtain frames for encoding. More... | |
int | sch_enc_send (Scheduler *sch, unsigned enc_idx, struct AVPacket *pkt) |
Called by encoder tasks to send encoded packets downstream. More... | |
int | sch_mux_receive (Scheduler *sch, unsigned mux_idx, struct AVPacket *pkt) |
Called by muxer tasks to obtain packets for muxing. More... | |
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. More... | |
int | sch_mux_sub_heartbeat_add (Scheduler *sch, unsigned mux_idx, unsigned stream_idx, unsigned dec_idx) |
int | sch_mux_sub_heartbeat (Scheduler *sch, unsigned mux_idx, unsigned stream_idx, const AVPacket *pkt) |
#define SCH_DSTREAM | ( | file, | |
stream | |||
) |
Definition at line 111 of file ffmpeg_sched.h.
#define SCH_MSTREAM | ( | file, | |
stream | |||
) |
Definition at line 114 of file ffmpeg_sched.h.
#define SCH_DEC_IN | ( | decoder | ) |
Definition at line 117 of file ffmpeg_sched.h.
#define SCH_DEC_OUT | ( | decoder, | |
out_idx | |||
) |
Definition at line 120 of file ffmpeg_sched.h.
#define SCH_ENC | ( | encoder | ) |
Definition at line 123 of file ffmpeg_sched.h.
Definition at line 126 of file ffmpeg_sched.h.
Definition at line 129 of file ffmpeg_sched.h.
#define DEFAULT_PACKET_THREAD_QUEUE_SIZE 8 |
Default size of a packet thread queue.
For muxing this can be overridden by the thread_queue_size option as passed to a call to sch_add_mux().
Definition at line 255 of file ffmpeg_sched.h.
#define DEFAULT_FRAME_THREAD_QUEUE_SIZE 8 |
Default size of a frame thread queue.
Definition at line 260 of file ffmpeg_sched.h.
typedef int(* SchThreadFunc) (void *arg) |
Definition at line 109 of file ffmpeg_sched.h.
enum SchedulerNodeType |
Enumerator | |
---|---|
SCH_NODE_TYPE_NONE | |
SCH_NODE_TYPE_DEMUX | |
SCH_NODE_TYPE_MUX | |
SCH_NODE_TYPE_DEC | |
SCH_NODE_TYPE_ENC | |
SCH_NODE_TYPE_FILTER_IN | |
SCH_NODE_TYPE_FILTER_OUT |
Definition at line 93 of file ffmpeg_sched.h.
enum DemuxSendFlags |
Enumerator | |
---|---|
DEMUX_SEND_STREAMCOPY_EOF | Treat the packet as an EOF for SCH_NODE_TYPE_MUX destinations send normally to other types. |
Definition at line 333 of file ffmpeg_sched.h.
Scheduler* sch_alloc | ( | void | ) |
Definition at line 585 of file ffmpeg_sched.c.
Referenced by main().
void sch_free | ( | Scheduler ** | sch | ) |
Definition at line 467 of file ffmpeg_sched.c.
Referenced by main(), and sch_alloc().
int sch_start | ( | Scheduler * | sch | ) |
Definition at line 1599 of file ffmpeg_sched.c.
Referenced by transcode().
Definition at line 2583 of file ffmpeg_sched.c.
Referenced by sch_free(), sch_start(), and transcode().
Wait until transcoding terminates or the specified timeout elapses.
timeout_us | Amount of time in microseconds after which this function will timeout. |
transcode_ts | Current transcode timestamp in AV_TIME_BASE_Q, for informational purposes only. |
0 | waiting timed out, transcoding is not finished |
1 | transcoding is finished |
Definition at line 1665 of file ffmpeg_sched.c.
Referenced by transcode().
int sch_add_demux | ( | Scheduler * | sch, |
SchThreadFunc | func, | ||
void * | ctx | ||
) |
Add a demuxer to the scheduler.
func | Function executed as the demuxer task. |
ctx | Demuxer state; will be passed to func and used for logging. |
>=0 | Index of the newly-created demuxer. |
<0 | Error code. |
Definition at line 688 of file ffmpeg_sched.c.
Referenced by ifile_open().
int sch_add_demux_stream | ( | Scheduler * | sch, |
unsigned | demux_idx | ||
) |
Add a demuxed stream for a previously added demuxer.
demux_idx | index previously returned by sch_add_demux() |
>=0 | Index of the newly-created demuxed stream. |
<0 | Error code. |
Definition at line 715 of file ffmpeg_sched.c.
Referenced by ist_use().
int sch_add_dec | ( | Scheduler * | sch, |
SchThreadFunc | func, | ||
void * | ctx, | ||
int | send_end_ts | ||
) |
Add a decoder to the scheduler.
func | Function executed as the decoder task. |
ctx | Decoder state; will be passed to func and used for logging. |
send_end_ts | The decoder will return an end timestamp after flush packets are delivered to it. See documentation for sch_dec_receive() for more details. |
>=0 | Index of the newly-created decoder. |
<0 | Error code. |
Definition at line 748 of file ffmpeg_sched.c.
Referenced by dec_alloc().
int sch_add_dec_output | ( | Scheduler * | sch, |
unsigned | dec_idx | ||
) |
Add another output to decoder (e.g.
for multiview video).
>=0 | Index of the newly-added decoder output. |
<0 | Error code. |
Definition at line 727 of file ffmpeg_sched.c.
Referenced by dec_request_view(), and sch_add_dec().
int sch_add_filtergraph | ( | Scheduler * | sch, |
unsigned | nb_inputs, | ||
unsigned | nb_outputs, | ||
SchThreadFunc | func, | ||
void * | ctx | ||
) |
Add a filtergraph to the scheduler.
nb_inputs | Number of filtergraph inputs. |
nb_outputs | number of filtergraph outputs |
func | Function executed as the filtering task. |
ctx | Filter state; will be passed to func and used for logging. |
>=0 | Index of the newly-created filtergraph. |
<0 | Error code. |
Definition at line 829 of file ffmpeg_sched.c.
Referenced by fg_create().
int sch_add_mux | ( | Scheduler * | sch, |
SchThreadFunc | func, | ||
int(*)(void *) | init, | ||
void * | ctx, | ||
int | sdp_auto, | ||
unsigned | thread_queue_size | ||
) |
Add a muxer to the scheduler.
Note that muxer thread startup is more complicated than for other components, because
In order for the above to work, the scheduler needs to be able to invoke just writing the header, which is the reason the init parameter exists.
func | Function executed as the muxing task. |
init | Callback that is called to initialize the muxer and write the header. Called after sch_mux_stream_ready() is called for all the streams in the muxer. |
ctx | Muxer state; will be passed to func/init and used for logging. |
sdp_auto | Determines automatic SDP writing - see sch_sdp_filename(). |
thread_queue_size | number of packets that can be buffered before sending to the muxer blocks |
>=0 | Index of the newly-created muxer. |
<0 | Error code. |
Definition at line 632 of file ffmpeg_sched.c.
Referenced by of_open().
int sch_add_mux_stream | ( | Scheduler * | sch, |
unsigned | mux_idx | ||
) |
Add a muxed stream for a previously added muxer.
mux_idx | index previously returned by sch_add_mux() |
>=0 | Index of the newly-created muxed stream. |
<0 | Error code. |
Definition at line 656 of file ffmpeg_sched.c.
Referenced by ost_add().
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.
mux_idx | index previously returned by sch_add_mux() |
stream_idx_idx | index previously returned by sch_add_mux_stream() |
data_threshold | Total size of the buffered packets' data after which max_packets applies. |
max_packets | maximum Maximum number of buffered packets after data_threshold is reached. |
Definition at line 1205 of file ffmpeg_sched.c.
Referenced by ost_add().
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.
Muxing is started once all the streams are ready.
Definition at line 1221 of file ffmpeg_sched.c.
Referenced by of_stream_init().
int sch_sdp_filename | ( | Scheduler * | sch, |
const char * | sdp_filename | ||
) |
Set the file path for the SDP.
The SDP is written when either of the following is true:
Definition at line 619 of file ffmpeg_sched.c.
Referenced by opt_sdp_file().
int sch_add_enc | ( | Scheduler * | sch, |
SchThreadFunc | func, | ||
void * | ctx, | ||
int(*)(void *func_arg, const struct AVFrame *frame) | open_cb | ||
) |
Add an encoder to the scheduler.
func | Function executed as the encoding task. |
ctx | Encoder state; will be passed to func and used for logging. |
open_cb | This callback, if specified, will be called when the first frame is obtained for this encoder. For audio encoders with a fixed frame size (which use a sync queue in the scheduler to rechunk frames), it must return that frame size on success. Otherwise (non-audio, variable frame size) it should return 0. |
>=0 | Index of the newly-created encoder. |
<0 | Error code. |
int sch_add_sq_enc | ( | Scheduler * | sch, |
uint64_t | buf_size_us, | ||
void * | logctx | ||
) |
Add an pre-encoding sync queue to the scheduler.
buf_size_us | Sync queue buffering size, passed to sq_alloc(). |
logctx | Logging context for the sync queue. passed to sq_alloc(). |
>=0 | Index of the newly-created sync queue. |
<0 | Error code. |
Definition at line 871 of file ffmpeg_sched.c.
Referenced by setup_sync_queues().
int sch_sq_add_enc | ( | Scheduler * | sch, |
unsigned | sq_idx, | ||
unsigned | enc_idx, | ||
int | limiting, | ||
uint64_t | max_frames | ||
) |
Definition at line 896 of file ffmpeg_sched.c.
Referenced by setup_sync_queues().
int sch_connect | ( | Scheduler * | sch, |
SchedulerNode | src, | ||
SchedulerNode | dst | ||
) |
Definition at line 927 of file ffmpeg_sched.c.
Referenced by dec_create(), ifilter_bind_dec(), ifilter_bind_fg(), ifilter_bind_ist(), ist_use(), ofilter_bind_enc(), and ost_add().
Called by demuxer tasks to communicate with their downstreams.
The following may be sent:
demux_idx | demuxer index |
pkt | A demuxed packet to send. When flushing (i.e. pkt->stream_index=-1 on entry to this function), on successful return pkt->pts/pkt->time_base will be set to the maximum end timestamp of any decoded audio stream, or AV_NOPTS_VALUE if no decoded audio streams are present. |
non-negative value | success |
AVERROR_EOF | all consumers for the stream are done |
AVERROR_EXIT | all consumers are done, should terminate demuxing |
anoter negative error code | other failure |
Definition at line 2037 of file ffmpeg_sched.c.
Referenced by do_send(), and input_thread().
Called by decoder tasks to receive a packet for decoding.
dec_idx | decoder index |
pkt | Input packet will be written here on success. An empty packet signals that the decoder should be flushed, but more packets will follow (e.g. after seeking). When a decoder created with send_end_ts=1 receives a flush packet, it must write the end timestamp of the stream after flushing to pkt->pts/time_base on the next call to this function (if any). |
non-negative value | success |
AVERROR_EOF | no more packets will arrive, should terminate decoding |
another negative error code | other failure |
Definition at line 2165 of file ffmpeg_sched.c.
Referenced by decoder_thread().
Called by decoder tasks to send a decoded frame downstream.
dec_idx | Decoder index previously returned by sch_add_dec(). |
frame | Decoded frame; on success it is consumed and cleared by this function |
>=0 | success |
AVERROR_EOF | all consumers are done, should terminate decoding |
another negative error code | other failure |
Definition at line 2241 of file ffmpeg_sched.c.
Referenced by decoder_thread(), packet_decode(), process_subtitle(), and transcode_subtitles().
int sch_filter_receive | ( | Scheduler * | sch, |
unsigned | fg_idx, | ||
unsigned * | in_idx, | ||
struct AVFrame * | frame | ||
) |
Called by filtergraph tasks to obtain frames for filtering.
Will wait for a frame to become available and return it in frame.
Filtergraphs that contain lavfi sources and do not currently require new input frames should call this function as a means of rate control - then in_idx should be set equal to nb_inputs on entry to this function.
fg_idx | Filtergraph index previously returned by sch_add_filtergraph(). | |
[in,out] | in_idx | On input contains the index of the input on which a frame is most desired. May be set to nb_inputs to signal that the filtergraph does not need more input currently. |
On success, will be replaced with the input index of the actually returned frame or EOF timestamp.
>=0 | Frame data or EOF timestamp was delivered into frame, in_idx contains the index of the input it belongs to. |
AVERROR(EAGAIN) | No frame was returned, the filtergraph should resume filtering. May only be returned when in_idx=nb_inputs on entry to this function. |
AVERROR_EOF | No more frames will arrive, should terminate filtering. |
Definition at line 2403 of file ffmpeg_sched.c.
Referenced by filter_thread().
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.
fg_idx | Filtergraph index previously returned from sch_add_filtergraph(). |
in_idx | Index of the input to finish. |
Definition at line 2447 of file ffmpeg_sched.c.
Referenced by filter_thread().
Called by filtergraph tasks to send a filtered frame or EOF to consumers.
fg_idx | Filtergraph index previously returned by sch_add_filtergraph(). |
out_idx | Index of the output which produced the frame. |
frame | The frame to send to consumers. When NULL, signals that no more frames will be produced for the specified output. When non-NULL, the frame is consumed and cleared by this function on success. |
non-negative value | success |
AVERROR_EOF | all consumers are done |
anoter negative error code | other failure |
Definition at line 2468 of file ffmpeg_sched.c.
Referenced by close_output(), and fg_output_frame().
Definition at line 2513 of file ffmpeg_sched.c.
Referenced by fg_send_command().
Called by encoder tasks to obtain frames for encoding.
Will wait for a frame to become available and return it in frame.
enc_idx | Encoder index previously returned by sch_add_enc(). |
frame | Newly-received frame will be stored here on success. Must be clean on entrance to this function. |
0 | A frame was successfully delivered into frame. |
AVERROR_EOF | No more frames will be delivered, the encoder should flush everything and terminate. |
Definition at line 2310 of file ffmpeg_sched.c.
Referenced by encoder_thread().
Called by encoder tasks to send encoded packets downstream.
enc_idx | Encoder index previously returned by sch_add_enc(). |
pkt | An encoded packet; it will be consumed and cleared by this function on success. |
0 | success |
<0 | Error code. |
Definition at line 2354 of file ffmpeg_sched.c.
Referenced by do_subtitle_out(), and encode_frame().
Called by muxer tasks to obtain packets for muxing.
Will wait for a packet for any muxed stream to become available and return it in pkt.
mux_idx | Muxer index previously returned by sch_add_mux(). |
pkt | Newly-received packet will be stored here on success. Must be clean on entrance to this function. |
0 | A packet was successfully delivered into pkt. Its stream_index corresponds to a stream index previously returned from sch_add_mux_stream(). |
AVERROR_EOF | When pkt->stream_index is non-negative, this signals that no more packets will be delivered for this stream index. Otherwise this indicates that no more packets will be delivered for any stream and the muxer should therefore flush everything and terminate. |
Definition at line 2081 of file ffmpeg_sched.c.
Referenced by muxer_thread().
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.
stream_idx | Stream index previously returned from sch_add_mux_stream(). |
Definition at line 2094 of file ffmpeg_sched.c.
Referenced by muxer_thread().
int sch_mux_sub_heartbeat_add | ( | Scheduler * | sch, |
unsigned | mux_idx, | ||
unsigned | stream_idx, | ||
unsigned | dec_idx | ||
) |
Definition at line 1246 of file ffmpeg_sched.c.
Referenced by create_streams().
int sch_mux_sub_heartbeat | ( | Scheduler * | sch, |
unsigned | mux_idx, | ||
unsigned | stream_idx, | ||
const AVPacket * | pkt | ||
) |
Definition at line 2112 of file ffmpeg_sched.c.
Referenced by mux_packet_filter().