FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
ffmpeg_sched.c File Reference
#include <stdatomic.h>
#include <stddef.h>
#include <stdint.h>
#include "cmdutils.h"
#include "ffmpeg_sched.h"
#include "ffmpeg_utils.h"
#include "sync_queue.h"
#include "thread_queue.h"
#include "libavcodec/packet.h"
#include "libavutil/avassert.h"
#include "libavutil/error.h"
#include "libavutil/fifo.h"
#include "libavutil/frame.h"
#include "libavutil/mem.h"
#include "libavutil/thread.h"
#include "libavutil/threadmessage.h"
#include "libavutil/time.h"

Go to the source code of this file.

Data Structures

struct  SchWaiter
 
struct  SchTask
 
struct  SchDecOutput
 
struct  SchDec
 
struct  SchSyncQueue
 
struct  SchEnc
 
struct  SchDemuxStream
 
struct  SchDemux
 
struct  PreMuxQueue
 
struct  SchMuxStream
 
struct  SchMux
 
struct  SchFilterIn
 
struct  SchFilterOut
 
struct  SchFilterGraph
 
struct  Scheduler
 

Macros

#define SCHEDULE_TOLERANCE   (100 * 1000)
 

Enumerations

enum  QueueType { QUEUE_PACKETS, QUEUE_FRAMES }
 
enum  SchedulerState { SCH_STATE_UNINIT, SCH_STATE_STARTED, SCH_STATE_STOPPED }
 
enum  { CYCLE_NODE_NEW = 0, CYCLE_NODE_STARTED, CYCLE_NODE_DONE }
 

Functions

static int waiter_wait (Scheduler *sch, SchWaiter *w)
 Wait until this task is allowed to proceed. More...
 
static void waiter_set (SchWaiter *w, int choked)
 
static int waiter_init (SchWaiter *w)
 
static void waiter_uninit (SchWaiter *w)
 
static int queue_alloc (ThreadQueue **ptq, unsigned nb_streams, unsigned queue_size, enum QueueType type)
 
static void * task_wrapper (void *arg)
 
static int task_start (SchTask *task)
 
static void task_init (Scheduler *sch, SchTask *task, enum SchedulerNodeType type, unsigned idx, SchThreadFunc func, void *func_arg)
 
static int64_t trailing_dts (const Scheduler *sch, int count_finished)
 
void sch_free (Scheduler **psch)
 
Schedulersch_alloc (void)
 
int sch_sdp_filename (Scheduler *sch, const char *sdp_filename)
 Set the file path for the SDP. More...
 
int sch_add_mux (Scheduler *sch, SchThreadFunc func, int(*init)(void *), void *arg, 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...
 
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_output (Scheduler *sch, unsigned dec_idx)
 Add another output to decoder (e.g. 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_enc (Scheduler *sch, SchThreadFunc func, void *ctx, int(*open_cb)(void *opaque, const AVFrame *frame))
 
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_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)
 
static int mux_task_start (SchMux *mux)
 
int print_sdp (const char *filename)
 
static int mux_init (Scheduler *sch, SchMux *mux)
 
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_mux_sub_heartbeat_add (Scheduler *sch, unsigned mux_idx, unsigned stream_idx, unsigned dec_idx)
 
static void unchoke_for_stream (Scheduler *sch, SchedulerNode src)
 
static void schedule_update_locked (Scheduler *sch)
 
static int check_acyclic_for_output (const Scheduler *sch, SchedulerNode src, uint8_t *filters_visited, SchedulerNode *filters_stack)
 
static int check_acyclic (Scheduler *sch)
 
static int start_prepare (Scheduler *sch)
 
int sch_start (Scheduler *sch)
 
int sch_wait (Scheduler *sch, uint64_t timeout_us, int64_t *transcode_ts)
 Wait until transcoding terminates or the specified timeout elapses. More...
 
static int enc_open (Scheduler *sch, SchEnc *enc, const AVFrame *frame)
 
static int send_to_enc_thread (Scheduler *sch, SchEnc *enc, AVFrame *frame)
 
static int send_to_enc_sq (Scheduler *sch, SchEnc *enc, AVFrame *frame)
 
static int send_to_enc (Scheduler *sch, SchEnc *enc, AVFrame *frame)
 
static int mux_queue_packet (SchMux *mux, SchMuxStream *ms, AVPacket *pkt)
 
static int send_to_mux (Scheduler *sch, SchMux *mux, unsigned stream_idx, AVPacket *pkt)
 
static int demux_stream_send_to_dst (Scheduler *sch, const SchedulerNode dst, uint8_t *dst_finished, AVPacket *pkt, unsigned flags)
 
static int demux_send_for_stream (Scheduler *sch, SchDemux *d, SchDemuxStream *ds, AVPacket *pkt, unsigned flags)
 
static int demux_flush (Scheduler *sch, SchDemux *d, AVPacket *pkt)
 
int sch_demux_send (Scheduler *sch, unsigned demux_idx, AVPacket *pkt, unsigned flags)
 Called by demuxer tasks to communicate with their downstreams. More...
 
static int demux_done (Scheduler *sch, unsigned demux_idx)
 
int sch_mux_receive (Scheduler *sch, unsigned mux_idx, 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 (Scheduler *sch, unsigned mux_idx, unsigned stream_idx, const AVPacket *pkt)
 
static int mux_done (Scheduler *sch, unsigned mux_idx)
 
int sch_dec_receive (Scheduler *sch, unsigned dec_idx, AVPacket *pkt)
 Called by decoder tasks to receive a packet for decoding. More...
 
static int send_to_filter (Scheduler *sch, SchFilterGraph *fg, unsigned in_idx, AVFrame *frame)
 
static int dec_send_to_dst (Scheduler *sch, const SchedulerNode dst, uint8_t *dst_finished, AVFrame *frame)
 
int sch_dec_send (Scheduler *sch, unsigned dec_idx, unsigned out_idx, AVFrame *frame)
 Called by decoder tasks to send a decoded frame downstream. More...
 
static int dec_done (Scheduler *sch, unsigned dec_idx)
 
int sch_enc_receive (Scheduler *sch, unsigned enc_idx, AVFrame *frame)
 Called by encoder tasks to obtain frames for encoding. More...
 
static int enc_send_to_dst (Scheduler *sch, const SchedulerNode dst, uint8_t *dst_finished, AVPacket *pkt)
 
int sch_enc_send (Scheduler *sch, unsigned enc_idx, AVPacket *pkt)
 Called by encoder tasks to send encoded packets downstream. More...
 
static int enc_done (Scheduler *sch, unsigned enc_idx)
 
int sch_filter_receive (Scheduler *sch, unsigned fg_idx, unsigned *in_idx, 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, AVFrame *frame)
 Called by filtergraph tasks to send a filtered frame or EOF to consumers. More...
 
static int filter_done (Scheduler *sch, unsigned fg_idx)
 
int sch_filter_command (Scheduler *sch, unsigned fg_idx, AVFrame *frame)
 
static int task_cleanup (Scheduler *sch, SchedulerNode node)
 
static int task_stop (Scheduler *sch, SchTask *task)
 
int sch_stop (Scheduler *sch, int64_t *finish_ts)
 

Variables

static const AVClass scheduler_class
 
static const AVClass sch_mux_class
 
static const AVClass sch_demux_class
 
static const AVClass sch_dec_class
 
static const AVClass sch_enc_class
 
static const AVClass sch_fg_class
 

Macro Definition Documentation

◆ SCHEDULE_TOLERANCE

#define SCHEDULE_TOLERANCE   (100 * 1000)

Definition at line 45 of file ffmpeg_sched.c.

Enumeration Type Documentation

◆ QueueType

enum QueueType
Enumerator
QUEUE_PACKETS 
QUEUE_FRAMES 

Definition at line 47 of file ffmpeg_sched.c.

◆ SchedulerState

Enumerator
SCH_STATE_UNINIT 
SCH_STATE_STARTED 
SCH_STATE_STOPPED 

Definition at line 269 of file ffmpeg_sched.c.

◆ anonymous enum

anonymous enum
Enumerator
CYCLE_NODE_NEW 
CYCLE_NODE_STARTED 
CYCLE_NODE_DONE 

Definition at line 1366 of file ffmpeg_sched.c.

Function Documentation

◆ waiter_wait()

static int waiter_wait ( Scheduler sch,
SchWaiter w 
)
static

Wait until this task is allowed to proceed.

Return values
0the caller should proceed
1the caller should terminate

Definition at line 322 of file ffmpeg_sched.c.

Referenced by sch_demux_send(), and sch_filter_receive().

◆ waiter_set()

static void waiter_set ( SchWaiter w,
int  choked 
)
static

Definition at line 341 of file ffmpeg_sched.c.

Referenced by sch_stop(), and schedule_update_locked().

◆ waiter_init()

static int waiter_init ( SchWaiter w)
static

Definition at line 351 of file ffmpeg_sched.c.

Referenced by sch_add_demux(), and sch_add_filtergraph().

◆ waiter_uninit()

static void waiter_uninit ( SchWaiter w)
static

Definition at line 368 of file ffmpeg_sched.c.

Referenced by sch_free().

◆ queue_alloc()

static int queue_alloc ( ThreadQueue **  ptq,
unsigned  nb_streams,
unsigned  queue_size,
enum QueueType  type 
)
static

Definition at line 374 of file ffmpeg_sched.c.

Referenced by sch_add_dec(), sch_add_enc(), sch_add_filtergraph(), and start_prepare().

◆ task_wrapper()

static void * task_wrapper ( void *  arg)
static

Definition at line 2537 of file ffmpeg_sched.c.

Referenced by task_start().

◆ task_start()

static int task_start ( SchTask task)
static

Definition at line 414 of file ffmpeg_sched.c.

Referenced by mux_task_start(), and sch_start().

◆ task_init()

static void task_init ( Scheduler sch,
SchTask task,
enum SchedulerNodeType  type,
unsigned  idx,
SchThreadFunc  func,
void *  func_arg 
)
static

◆ trailing_dts()

static int64_t trailing_dts ( const Scheduler sch,
int  count_finished 
)
static

Definition at line 445 of file ffmpeg_sched.c.

Referenced by sch_stop(), and schedule_update_locked().

◆ sch_free()

void sch_free ( Scheduler **  psch)

Definition at line 467 of file ffmpeg_sched.c.

Referenced by main(), and sch_alloc().

◆ sch_alloc()

Scheduler* sch_alloc ( void  )

Definition at line 585 of file ffmpeg_sched.c.

Referenced by main().

◆ sch_sdp_filename()

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:

  • this function is called at least once
  • sdp_auto=1 is passed to EVERY call of sch_add_mux()

Definition at line 619 of file ffmpeg_sched.c.

Referenced by opt_sdp_file().

◆ sch_add_mux()

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

  • muxer streams fed by audio/video encoders become initialized dynamically at runtime, after those encoders receive their first frame and initialize themselves, followed by calling sch_mux_stream_ready()
  • the header can be written after all the streams for a muxer are initialized
  • we may need to write an SDP, which must happen
    • AFTER all the headers are written
    • BEFORE any packets are written by any muxer
    • with all the muxers quiescent To avoid complicated muxer-thread synchronization dances, we postpone starting the muxer threads until after the SDP is written. The sequence of events is then as follows:
  • After sch_mux_stream_ready() is called for all the streams in a given muxer, the header for that muxer is written (care is taken that headers for different muxers are not written concurrently, since they write file information to stderr). If SDP is not wanted, the muxer thread then starts and muxing begins.
  • When SDP is wanted, no muxer threads start until the header for the last muxer is written. After that, the SDP is written, after which all the muxer threads are started at once.

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.

Parameters
funcFunction executed as the muxing task.
initCallback 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.
ctxMuxer state; will be passed to func/init and used for logging.
sdp_autoDetermines automatic SDP writing - see sch_sdp_filename().
thread_queue_sizenumber of packets that can be buffered before sending to the muxer blocks
Return values
>=0Index of the newly-created muxer.
<0Error code.

Definition at line 632 of file ffmpeg_sched.c.

Referenced by of_open().

◆ sch_add_mux_stream()

int sch_add_mux_stream ( Scheduler sch,
unsigned  mux_idx 
)

Add a muxed stream for a previously added muxer.

Parameters
mux_idxindex previously returned by sch_add_mux()
Return values
>=0Index of the newly-created muxed stream.
<0Error code.

Definition at line 656 of file ffmpeg_sched.c.

Referenced by ost_add().

◆ sch_add_demux()

int sch_add_demux ( Scheduler sch,
SchThreadFunc  func,
void *  ctx 
)

Add a demuxer to the scheduler.

Parameters
funcFunction executed as the demuxer task.
ctxDemuxer state; will be passed to func and used for logging.
Return values
>=0Index of the newly-created demuxer.
<0Error code.

Definition at line 688 of file ffmpeg_sched.c.

Referenced by ifile_open().

◆ sch_add_demux_stream()

int sch_add_demux_stream ( Scheduler sch,
unsigned  demux_idx 
)

Add a demuxed stream for a previously added demuxer.

Parameters
demux_idxindex previously returned by sch_add_demux()
Return values
>=0Index of the newly-created demuxed stream.
<0Error code.

Definition at line 715 of file ffmpeg_sched.c.

Referenced by ist_use().

◆ sch_add_dec_output()

int sch_add_dec_output ( Scheduler sch,
unsigned  dec_idx 
)

Add another output to decoder (e.g.

for multiview video).

Return values
>=0Index of the newly-added decoder output.
<0Error code.

Definition at line 727 of file ffmpeg_sched.c.

Referenced by dec_request_view(), and sch_add_dec().

◆ sch_add_dec()

int sch_add_dec ( Scheduler sch,
SchThreadFunc  func,
void *  ctx,
int  send_end_ts 
)

Add a decoder to the scheduler.

Parameters
funcFunction executed as the decoder task.
ctxDecoder state; will be passed to func and used for logging.
send_end_tsThe decoder will return an end timestamp after flush packets are delivered to it. See documentation for sch_dec_receive() for more details.
Return values
>=0Index of the newly-created decoder.
<0Error code.

Definition at line 748 of file ffmpeg_sched.c.

Referenced by dec_alloc().

◆ sch_add_enc()

int sch_add_enc ( Scheduler sch,
SchThreadFunc  func,
void *  ctx,
int(*)(void *opaque, const AVFrame *frame open_cb 
)

Definition at line 791 of file ffmpeg_sched.c.

Referenced by ost_add().

◆ 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.

Parameters
nb_inputsNumber of filtergraph inputs.
nb_outputsnumber of filtergraph outputs
funcFunction executed as the filtering task.
ctxFilter state; will be passed to func and used for logging.
Return values
>=0Index of the newly-created filtergraph.
<0Error code.

Definition at line 829 of file ffmpeg_sched.c.

Referenced by fg_create().

◆ 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.

Parameters
buf_size_usSync queue buffering size, passed to sq_alloc().
logctxLogging context for the sync queue. passed to sq_alloc().
Return values
>=0Index of the newly-created sync queue.
<0Error code.

Definition at line 871 of file ffmpeg_sched.c.

Referenced by setup_sync_queues().

◆ sch_sq_add_enc()

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().

◆ sch_connect()

int sch_connect ( Scheduler sch,
SchedulerNode  src,
SchedulerNode  dst 
)

◆ mux_task_start()

static int mux_task_start ( SchMux mux)
static

Definition at line 1105 of file ffmpeg_sched.c.

Referenced by mux_init().

◆ print_sdp()

int print_sdp ( const char *  filename)

Definition at line 507 of file ffmpeg_mux.c.

Referenced by mux_init().

◆ mux_init()

static int mux_init ( Scheduler sch,
SchMux mux 
)
static

Definition at line 1169 of file ffmpeg_sched.c.

Referenced by sch_mux_stream_ready(), and sch_start().

◆ 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.

Parameters
mux_idxindex previously returned by sch_add_mux()
stream_idx_idxindex previously returned by sch_add_mux_stream()
data_thresholdTotal size of the buffered packets' data after which max_packets applies.
max_packetsmaximum Maximum number of buffered packets after data_threshold is reached.

Definition at line 1205 of file ffmpeg_sched.c.

Referenced by ost_add().

◆ 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.

Muxing is started once all the streams are ready.

Definition at line 1221 of file ffmpeg_sched.c.

Referenced by of_stream_init().

◆ sch_mux_sub_heartbeat_add()

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().

◆ unchoke_for_stream()

static void unchoke_for_stream ( Scheduler sch,
SchedulerNode  src 
)
static

Definition at line 1275 of file ffmpeg_sched.c.

Referenced by schedule_update_locked().

◆ schedule_update_locked()

static void schedule_update_locked ( Scheduler sch)
static

◆ check_acyclic_for_output()

static int check_acyclic_for_output ( const Scheduler sch,
SchedulerNode  src,
uint8_t *  filters_visited,
SchedulerNode filters_stack 
)
static

Definition at line 1373 of file ffmpeg_sched.c.

Referenced by check_acyclic().

◆ check_acyclic()

static int check_acyclic ( Scheduler sch)
static

Definition at line 1418 of file ffmpeg_sched.c.

Referenced by start_prepare().

◆ start_prepare()

static int start_prepare ( Scheduler sch)
static

Definition at line 1454 of file ffmpeg_sched.c.

Referenced by sch_start().

◆ sch_start()

int sch_start ( Scheduler sch)

Definition at line 1599 of file ffmpeg_sched.c.

Referenced by transcode().

◆ sch_wait()

int sch_wait ( Scheduler sch,
uint64_t  timeout_us,
int64_t transcode_ts 
)

Wait until transcoding terminates or the specified timeout elapses.

Parameters
timeout_usAmount of time in microseconds after which this function will timeout.
transcode_tsCurrent transcode timestamp in AV_TIME_BASE_Q, for informational purposes only.
Return values
0waiting timed out, transcoding is not finished
1transcoding is finished

Definition at line 1665 of file ffmpeg_sched.c.

Referenced by transcode().

◆ enc_open()

static int enc_open ( Scheduler sch,
SchEnc enc,
const AVFrame frame 
)
static

Definition at line 1692 of file ffmpeg_sched.c.

Referenced by send_to_enc().

◆ send_to_enc_thread()

static int send_to_enc_thread ( Scheduler sch,
SchEnc enc,
AVFrame frame 
)
static

Definition at line 1718 of file ffmpeg_sched.c.

Referenced by send_to_enc(), and send_to_enc_sq().

◆ send_to_enc_sq()

static int send_to_enc_sq ( Scheduler sch,
SchEnc enc,
AVFrame frame 
)
static

Definition at line 1737 of file ffmpeg_sched.c.

Referenced by send_to_enc().

◆ send_to_enc()

static int send_to_enc ( Scheduler sch,
SchEnc enc,
AVFrame frame 
)
static

Definition at line 1813 of file ffmpeg_sched.c.

Referenced by dec_send_to_dst(), filter_done(), and sch_filter_send().

◆ mux_queue_packet()

static int mux_queue_packet ( SchMux mux,
SchMuxStream ms,
AVPacket pkt 
)
static

Definition at line 1833 of file ffmpeg_sched.c.

Referenced by send_to_mux().

◆ send_to_mux()

static int send_to_mux ( Scheduler sch,
SchMux mux,
unsigned  stream_idx,
AVPacket pkt 
)
static

Definition at line 1869 of file ffmpeg_sched.c.

Referenced by demux_stream_send_to_dst(), and enc_send_to_dst().

◆ demux_stream_send_to_dst()

static int demux_stream_send_to_dst ( Scheduler sch,
const SchedulerNode  dst,
uint8_t *  dst_finished,
AVPacket pkt,
unsigned  flags 
)
static

Definition at line 1928 of file ffmpeg_sched.c.

Referenced by demux_send_for_stream().

◆ demux_send_for_stream()

static int demux_send_for_stream ( Scheduler sch,
SchDemux d,
SchDemuxStream ds,
AVPacket pkt,
unsigned  flags 
)
static

Definition at line 1963 of file ffmpeg_sched.c.

Referenced by demux_done(), and sch_demux_send().

◆ demux_flush()

static int demux_flush ( Scheduler sch,
SchDemux d,
AVPacket pkt 
)
static

Definition at line 1995 of file ffmpeg_sched.c.

Referenced by sch_demux_send().

◆ 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.

The following may be sent:

  • a demuxed packet for the stream identified by pkt->stream_index;
  • demuxer discontinuity/reset (e.g. after a seek) - this is signalled by an empty packet with stream_index=-1.
Parameters
demux_idxdemuxer index
pktA 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.
Return values
non-negative valuesuccess
AVERROR_EOFall consumers for the stream are done
AVERROR_EXITall consumers are done, should terminate demuxing
anoter negative error codeother failure

Definition at line 2039 of file ffmpeg_sched.c.

Referenced by do_send(), and input_thread().

◆ demux_done()

static int demux_done ( Scheduler sch,
unsigned  demux_idx 
)
static

Definition at line 2061 of file ffmpeg_sched.c.

Referenced by task_cleanup().

◆ sch_mux_receive()

int sch_mux_receive ( Scheduler sch,
unsigned  mux_idx,
struct AVPacket pkt 
)

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.

Parameters
mux_idxMuxer index previously returned by sch_add_mux().
pktNewly-received packet will be stored here on success. Must be clean on entrance to this function.
Return values
0A packet was successfully delivered into pkt. Its stream_index corresponds to a stream index previously returned from sch_add_mux_stream().
AVERROR_EOFWhen 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 2083 of file ffmpeg_sched.c.

Referenced by muxer_thread().

◆ 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.

Parameters
stream_idxStream index previously returned from sch_add_mux_stream().

Definition at line 2096 of file ffmpeg_sched.c.

Referenced by muxer_thread().

◆ sch_mux_sub_heartbeat()

int sch_mux_sub_heartbeat ( Scheduler sch,
unsigned  mux_idx,
unsigned  stream_idx,
const AVPacket pkt 
)

Definition at line 2114 of file ffmpeg_sched.c.

Referenced by mux_packet_filter().

◆ mux_done()

static int mux_done ( Scheduler sch,
unsigned  mux_idx 
)
static

Definition at line 2140 of file ffmpeg_sched.c.

Referenced by task_cleanup().

◆ 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.

Parameters
dec_idxdecoder index
pktInput 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).
Return values
non-negative valuesuccess
AVERROR_EOFno more packets will arrive, should terminate decoding
another negative error codeother failure

Definition at line 2167 of file ffmpeg_sched.c.

Referenced by decoder_thread().

◆ send_to_filter()

static int send_to_filter ( Scheduler sch,
SchFilterGraph fg,
unsigned  in_idx,
AVFrame frame 
)
static

Definition at line 2196 of file ffmpeg_sched.c.

Referenced by dec_send_to_dst(), filter_done(), sch_filter_command(), and sch_filter_send().

◆ dec_send_to_dst()

static int dec_send_to_dst ( Scheduler sch,
const SchedulerNode  dst,
uint8_t *  dst_finished,
AVFrame frame 
)
static

Definition at line 2213 of file ffmpeg_sched.c.

Referenced by dec_done(), and sch_dec_send().

◆ sch_dec_send()

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.

Parameters
dec_idxDecoder index previously returned by sch_add_dec().
frameDecoded frame; on success it is consumed and cleared by this function
Return values
>=0success
AVERROR_EOFall consumers are done, should terminate decoding
another negative error codeother failure

Definition at line 2243 of file ffmpeg_sched.c.

Referenced by decoder_thread(), packet_decode(), process_subtitle(), and transcode_subtitles().

◆ dec_done()

static int dec_done ( Scheduler sch,
unsigned  dec_idx 
)
static

Definition at line 2287 of file ffmpeg_sched.c.

Referenced by task_cleanup().

◆ sch_enc_receive()

int sch_enc_receive ( Scheduler sch,
unsigned  enc_idx,
struct AVFrame frame 
)

Called by encoder tasks to obtain frames for encoding.

Will wait for a frame to become available and return it in frame.

Parameters
enc_idxEncoder index previously returned by sch_add_enc().
frameNewly-received frame will be stored here on success. Must be clean on entrance to this function.
Return values
0A frame was successfully delivered into frame.
AVERROR_EOFNo more frames will be delivered, the encoder should flush everything and terminate.

Definition at line 2312 of file ffmpeg_sched.c.

Referenced by encoder_thread().

◆ enc_send_to_dst()

static int enc_send_to_dst ( Scheduler sch,
const SchedulerNode  dst,
uint8_t *  dst_finished,
AVPacket pkt 
)
static

Definition at line 2326 of file ffmpeg_sched.c.

Referenced by enc_done(), and sch_enc_send().

◆ sch_enc_send()

int sch_enc_send ( Scheduler sch,
unsigned  enc_idx,
struct AVPacket pkt 
)

Called by encoder tasks to send encoded packets downstream.

Parameters
enc_idxEncoder index previously returned by sch_add_enc().
pktAn encoded packet; it will be consumed and cleared by this function on success.
Return values
0success
<0Error code.

Definition at line 2356 of file ffmpeg_sched.c.

Referenced by do_subtitle_out(), and encode_frame().

◆ enc_done()

static int enc_done ( Scheduler sch,
unsigned  enc_idx 
)
static

Definition at line 2389 of file ffmpeg_sched.c.

Referenced by task_cleanup().

◆ 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.

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.

Parameters
fg_idxFiltergraph index previously returned by sch_add_filtergraph().
[in,out]in_idxOn 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.

Return values
>=0Frame 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_EOFNo more frames will arrive, should terminate filtering.

Definition at line 2405 of file ffmpeg_sched.c.

Referenced by filter_thread().

◆ 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.

Parameters
fg_idxFiltergraph index previously returned from sch_add_filtergraph().
in_idxIndex of the input to finish.

Definition at line 2449 of file ffmpeg_sched.c.

Referenced by filter_thread().

◆ 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.

Parameters
fg_idxFiltergraph index previously returned by sch_add_filtergraph().
out_idxIndex of the output which produced the frame.
frameThe 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.
Return values
non-negative valuesuccess
AVERROR_EOFall consumers are done
anoter negative error codeother failure

Definition at line 2470 of file ffmpeg_sched.c.

Referenced by close_output(), and fg_output_frame().

◆ filter_done()

static int filter_done ( Scheduler sch,
unsigned  fg_idx 
)
static

Definition at line 2486 of file ffmpeg_sched.c.

Referenced by task_cleanup().

◆ sch_filter_command()

int sch_filter_command ( Scheduler sch,
unsigned  fg_idx,
AVFrame frame 
)

Definition at line 2515 of file ffmpeg_sched.c.

Referenced by fg_send_command().

◆ task_cleanup()

static int task_cleanup ( Scheduler sch,
SchedulerNode  node 
)
static

Definition at line 2525 of file ffmpeg_sched.c.

Referenced by task_stop(), and task_wrapper().

◆ task_stop()

static int task_stop ( Scheduler sch,
SchTask task 
)
static

Definition at line 2565 of file ffmpeg_sched.c.

Referenced by sch_stop().

◆ sch_stop()

int sch_stop ( Scheduler sch,
int64_t finish_ts 
)

Definition at line 2581 of file ffmpeg_sched.c.

Referenced by sch_free(), sch_start(), and transcode().

Variable Documentation

◆ scheduler_class

const AVClass scheduler_class
static
Initial value:
= {
.class_name = "Scheduler",
}

Definition at line 580 of file ffmpeg_sched.c.

Referenced by sch_alloc().

◆ sch_mux_class

const AVClass sch_mux_class
static
Initial value:
= {
.class_name = "SchMux",
.parent_log_context_offset = 0x42,
}

Definition at line 626 of file ffmpeg_sched.c.

Referenced by sch_add_mux().

◆ sch_demux_class

const AVClass sch_demux_class
static
Initial value:
= {
.class_name = "SchDemux",
.parent_log_context_offset = 0x42,
}

Definition at line 682 of file ffmpeg_sched.c.

Referenced by sch_add_demux().

◆ sch_dec_class

const AVClass sch_dec_class
static
Initial value:
= {
.class_name = "SchDec",
.parent_log_context_offset = 0x42,
}

Definition at line 742 of file ffmpeg_sched.c.

Referenced by sch_add_dec().

◆ sch_enc_class

const AVClass sch_enc_class
static
Initial value:
= {
.class_name = "SchEnc",
.parent_log_context_offset = 0x42,
}

Definition at line 785 of file ffmpeg_sched.c.

Referenced by sch_add_enc().

◆ sch_fg_class

const AVClass sch_fg_class
static
Initial value:
= {
.class_name = "SchFilterGraph",
.parent_log_context_offset = 0x42,
}

Definition at line 823 of file ffmpeg_sched.c.

Referenced by sch_add_filtergraph().

LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85