FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
packetsync.h File Reference
#include <stdint.h>
#include "libavutil/log.h"
#include "libavcodec/bsf.h"
#include "libavcodec/packet.h"

Go to the source code of this file.

Data Structures

struct  FFPacketSyncIn
 Input stream structure. More...
 
struct  FFPacketSync
 Packet sync structure. More...
 

Macros

#define PACKETSYNC_DEFINE_PURE_CLASS(name, desc, func_prefix, options)
 
#define PACKETSYNC_AUXILIARY_FUNCS(func_prefix, context, field)
 
#define PACKETSYNC_DEFINE_CLASS_EXT(name, context, field, options)
 
#define PACKETSYNC_DEFINE_CLASS(name, context, field)   PACKETSYNC_DEFINE_CLASS_EXT(name, context, field, name##_options)
 

Enumerations

enum  EOFAction {
  EOF_ACTION_ENDALL, EOF_ACTION_PASS, EOF_ACTION_REPEAT, EOF_ACTION_ENDALL,
  EOF_ACTION_PASS, EOF_ACTION_ROUND, EOF_ACTION_PASS, EOF_ACTION_NB
}
 
enum  FFPacketSyncExtMode { EXT_STOP, EXT_NULL }
 This API is intended as a helper for filters that have several video input and need to combine them somehow. More...
 
enum  FFPacketTSSyncMode { TS_DEFAULT, TS_NEAREST }
 Timestamp synchronization mode. More...
 

Functions

void ff_packetsync_preinit (FFPacketSync *fs)
 Pre-initialize a packet sync structure. More...
 
int ff_packetsync_init (FFPacketSync *fs, AVBitStreamFilterContext *parent, unsigned nb_in)
 Initialize a packet sync structure. More...
 
int ff_packetsync_configure (FFPacketSync *fs)
 Configure a packet sync structure. More...
 
void ff_packetsync_uninit (FFPacketSync *fs)
 Free all memory currently allocated. More...
 
int ff_packetsync_get_packet (FFPacketSync *fs, unsigned in, AVPacket **rpacket, unsigned get)
 Get the current packet in an input. More...
 
int ff_packetsync_activate (FFPacketSync *fs)
 Examine the packets in the filter's input and try to produce output. More...
 
int ff_packetsync_init_dualinput (FFPacketSync *fs, AVBitStreamFilterContext *parent)
 Initialize a packet sync structure for dualinput. More...
 
int ff_packetsync_dualinput_get (FFPacketSync *fs, AVPacket **f0, AVPacket **f1)
 
int ff_packetsync_dualinput_get_writable (FFPacketSync *fs, AVPacket **f0, AVPacket **f1)
 Same as ff_packetsync_dualinput_get(), but make sure that f0 is writable. More...
 
const AVClassff_packetsync_child_class_iterate (void **iter)
 

Variables

const AVClass ff_packetsync_class
 

Macro Definition Documentation

◆ PACKETSYNC_DEFINE_PURE_CLASS

#define PACKETSYNC_DEFINE_PURE_CLASS (   name,
  desc,
  func_prefix,
  options 
)
Value:
static const AVClass name##_class = { \
.class_name = desc, \
.item_name = av_default_item_name, \
.option = options, \
.version = LIBAVUTIL_VERSION_INT, \
.child_class_iterate = ff_packetsync_child_class_iterate, \
.child_next = func_prefix##_child_next, \
}

Definition at line 311 of file packetsync.h.

◆ PACKETSYNC_AUXILIARY_FUNCS

#define PACKETSYNC_AUXILIARY_FUNCS (   func_prefix,
  context,
  field 
)
Value:
static int func_prefix##_packetsync_preinit(AVBitStreamFilterContext *ctx) \
{ \
context *s = ctx->priv_data; \
ff_packetsync_preinit(&s->field); \
return 0; \
} \
static void *func_prefix##_child_next(void *obj, void *prev) \
{ \
context *s = obj; \
return prev ? NULL : &s->field; \
}

Definition at line 325 of file packetsync.h.

◆ PACKETSYNC_DEFINE_CLASS_EXT

#define PACKETSYNC_DEFINE_CLASS_EXT (   name,
  context,
  field,
  options 
)
Value:
PACKETSYNC_DEFINE_PURE_CLASS(name, #name, name, options)

Definition at line 338 of file packetsync.h.

◆ PACKETSYNC_DEFINE_CLASS

#define PACKETSYNC_DEFINE_CLASS (   name,
  context,
  field 
)    PACKETSYNC_DEFINE_CLASS_EXT(name, context, field, name##_options)

Definition at line 342 of file packetsync.h.

Enumeration Type Documentation

◆ EOFAction

enum EOFAction
Enumerator
EOF_ACTION_ENDALL 
EOF_ACTION_PASS 
EOF_ACTION_REPEAT 
EOF_ACTION_ENDALL 
EOF_ACTION_PASS 
EOF_ACTION_ROUND 
EOF_ACTION_PASS 
EOF_ACTION_NB 

Definition at line 29 of file packetsync.h.

◆ FFPacketSyncExtMode

This API is intended as a helper for filters that have several video input and need to combine them somehow.

If the inputs have different or variable frame rate, getting the input packets to match requires a rather complex logic and a few user-tunable options.

In this API, when a set of synchronized input packets is ready to be processed is called a packet event. packet event can be generated in response to input packets on any or all inputs and the handling of situations where some stream extend beyond the beginning or the end of others can be configured.

The basic working of this API is the following: set the on_event callback, then call ff_packetsync_activate() from the filter's activate callback. Stream extrapolation mode

Describe how the packets of a stream are extrapolated before the first one and after EOF to keep sync with possibly longer other streams.

Enumerator
EXT_STOP 

Completely stop all streams with this one.

EXT_NULL 

Ignore this stream and continue processing the other ones.

Definition at line 57 of file packetsync.h.

◆ FFPacketTSSyncMode

Timestamp synchronization mode.

Describe how the packets of a stream are synchronized based on timestamp distance.

Enumerator
TS_DEFAULT 

Sync to packets from secondary input with the nearest, lower or equal timestamp to the packet event one.

TS_NEAREST 

Sync to packets from secondary input with the absolute nearest timestamp to the packet event one.

Definition at line 76 of file packetsync.h.

Function Documentation

◆ ff_packetsync_preinit()

void ff_packetsync_preinit ( FFPacketSync fs)

Pre-initialize a packet sync structure.

It sets the class pointer and inits the options to their default values. The entire structure is expected to be already set to 0. This step is optional, but necessary to use the options.

Definition at line 79 of file packetsync.c.

Referenced by ff_packetsync_init().

◆ ff_packetsync_init()

int ff_packetsync_init ( FFPacketSync fs,
AVBitStreamFilterContext parent,
unsigned  nb_in 
)

Initialize a packet sync structure.

The entire structure is expected to be already set to 0 or preinited.

Parameters
fspacket sync structure to initialize
parentparent AVBitStreamFilterContext object
nb_innumber of inputs
Returns
>= 0 for success or a negative error code

Definition at line 87 of file packetsync.c.

Referenced by ff_packetsync_init_dualinput().

◆ ff_packetsync_configure()

int ff_packetsync_configure ( FFPacketSync fs)

Configure a packet sync structure.

Must be called after all options are set but before all use.

Returns
>= 0 for success or a negative error code

Definition at line 138 of file packetsync.c.

Referenced by config_output().

◆ ff_packetsync_uninit()

void ff_packetsync_uninit ( FFPacketSync fs)

Free all memory currently allocated.

Definition at line 289 of file packetsync.c.

Referenced by uninit().

◆ ff_packetsync_get_packet()

int ff_packetsync_get_packet ( FFPacketSync fs,
unsigned  in,
AVPacket **  rpacket,
unsigned  get 
)

Get the current packet in an input.

Parameters
fspacket sync structure
inindex of the input
rpacketused to return the current packet (or NULL)
getif not zero, the calling code needs to get ownership of the returned packet; the current packet will either be duplicated or removed from the packetsync structure

Definition at line 257 of file packetsync.c.

Referenced by ff_packetsync_dualinput_get().

◆ ff_packetsync_activate()

int ff_packetsync_activate ( FFPacketSync fs)

Examine the packets in the filter's input and try to produce output.

This function can be the complete implementation of the activate method of a filter using packetsync.

Definition at line 340 of file packetsync.c.

Referenced by activate().

◆ ff_packetsync_init_dualinput()

int ff_packetsync_init_dualinput ( FFPacketSync fs,
AVBitStreamFilterContext parent 
)

Initialize a packet sync structure for dualinput.

Compared to generic packetsync, dualinput assumes the first input is the main one and the filtering is performed on it. The first input will be the only one with sync set and generic timeline support will just pass it unchanged when disabled.

Equivalent to ff_packetsync_init(fs, parent, 2) then setting the time base, sync and ext modes on the inputs.

Definition at line 366 of file packetsync.c.

Referenced by config_output().

◆ ff_packetsync_dualinput_get()

int ff_packetsync_dualinput_get ( FFPacketSync fs,
AVPacket **  f0,
AVPacket **  f1 
)
Parameters
f0used to return the main packet
f1used to return the second packet, or NULL if disabled
Returns
>=0 for success or AVERROR code
Note
The packet returned in f0 belongs to the caller (get = 1 in ff_packetsync_get_packet()) while the packet returned in f1 is still owned by the packetsync structure.

Definition at line 384 of file packetsync.c.

Referenced by ff_packetsync_dualinput_get_writable(), and lcevc_merge().

◆ ff_packetsync_dualinput_get_writable()

int ff_packetsync_dualinput_get_writable ( FFPacketSync fs,
AVPacket **  f0,
AVPacket **  f1 
)

Same as ff_packetsync_dualinput_get(), but make sure that f0 is writable.

Definition at line 402 of file packetsync.c.

◆ ff_packetsync_child_class_iterate()

const AVClass* ff_packetsync_child_class_iterate ( void **  iter)

Definition at line 64 of file packetsync.c.

Variable Documentation

◆ ff_packetsync_class

const AVClass ff_packetsync_class

Definition at line 55 of file packetsync.c.

Referenced by ff_packetsync_child_class_iterate(), and ff_packetsync_preinit().

name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
PACKETSYNC_AUXILIARY_FUNCS
#define PACKETSYNC_AUXILIARY_FUNCS(func_prefix, context, field)
Definition: packetsync.h:325
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
field
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
Definition: writing_filters.txt:78
context
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
Definition: writing_filters.txt:91
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
options
Definition: swscale.c:50
options
const OptionDef options[]
AVClass::child_next
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
Definition: log.h:150
ff_packetsync_child_class_iterate
const AVClass * ff_packetsync_child_class_iterate(void **iter)
Definition: packetsync.c:64
s
uint8_t s
Definition: llvidencdsp.c:39
desc
const char * desc
Definition: libsvtav1.c:83
AV_CLASS_CATEGORY_BITSTREAM_FILTER
@ AV_CLASS_CATEGORY_BITSTREAM_FILTER
Definition: log.h:37
AVBitStreamFilterContext
An instance of a filter.
Definition: bsf.h:347
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1342