FFmpeg
Macros | Enumerations | Functions | Variables
packetsync.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavcodec/bsf.h"
#include "filters.h"
#include "packetsync.h"

Go to the source code of this file.

Macros

#define OFFSET(member)   offsetof(FFPacketSync, member)
 
#define FLAGS   (AV_OPT_FLAG_BSF_PARAM|AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
 

Enumerations

enum  { STATE_BOF, STATE_RUN, STATE_EOF }
 

Functions

static const char * packetsync_name (void *ptr)
 
const AVClassff_packetsync_child_class_iterate (void **iter)
 
static int consume_from_fifos (FFPacketSync *fs)
 
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...
 
static void packetsync_eof (FFPacketSync *fs, int64_t pts)
 
static void packetsync_sync_level_update (FFPacketSync *fs, int64_t eof_pts)
 
int ff_packetsync_configure (FFPacketSync *fs)
 Configure a packet sync structure. More...
 
static int packetsync_advance (FFPacketSync *fs)
 
static int64_t packetsync_pts_extrapolate (FFPacketSync *fs, unsigned in, int64_t pts)
 
static void packetsync_inject_packet (FFPacketSync *fs, unsigned in, AVPacket *pkt)
 
static void packetsync_inject_status (FFPacketSync *fs, unsigned in, int status, int64_t eof_pts)
 
int ff_packetsync_get_packet (FFPacketSync *fs, unsigned in, AVPacket **rpkt, unsigned get)
 Get the current packet in an input. More...
 
void ff_packetsync_uninit (FFPacketSync *fs)
 Free all memory currently allocated. 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...
 

Variables

static const AVOption packetsync_options []
 
const AVClass ff_packetsync_class
 

Detailed Description

Packet sync API. Heavily based on libavfilter/framesync.c by Nicolas George

Definition in file packetsync.c.

Macro Definition Documentation

◆ OFFSET

#define OFFSET (   member)    offsetof(FFPacketSync, member)

Definition at line 32 of file packetsync.c.

◆ FLAGS

Definition at line 33 of file packetsync.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
STATE_BOF 
STATE_RUN 
STATE_EOF 

Definition at line 71 of file packetsync.c.

Function Documentation

◆ packetsync_name()

static const char* packetsync_name ( void *  ptr)
static

Definition at line 35 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.

◆ consume_from_fifos()

static int consume_from_fifos ( FFPacketSync fs)
static

Definition at line 301 of file packetsync.c.

Referenced by packetsync_advance().

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

◆ packetsync_eof()

static void packetsync_eof ( FFPacketSync fs,
int64_t  pts 
)
static

Definition at line 107 of file packetsync.c.

Referenced by packetsync_advance(), and packetsync_sync_level_update().

◆ packetsync_sync_level_update()

static void packetsync_sync_level_update ( FFPacketSync fs,
int64_t  eof_pts 
)
static

Definition at line 114 of file packetsync.c.

Referenced by ff_packetsync_configure(), and packetsync_inject_status().

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

◆ packetsync_advance()

static int packetsync_advance ( FFPacketSync fs)
static

Definition at line 178 of file packetsync.c.

Referenced by ff_packetsync_activate().

◆ packetsync_pts_extrapolate()

static int64_t packetsync_pts_extrapolate ( FFPacketSync fs,
unsigned  in,
int64_t  pts 
)
static

Definition at line 227 of file packetsync.c.

Referenced by packetsync_inject_status().

◆ packetsync_inject_packet()

static void packetsync_inject_packet ( FFPacketSync fs,
unsigned  in,
AVPacket pkt 
)
static

Definition at line 233 of file packetsync.c.

Referenced by consume_from_fifos().

◆ packetsync_inject_status()

static void packetsync_inject_status ( FFPacketSync fs,
unsigned  in,
int  status,
int64_t  eof_pts 
)
static

Definition at line 246 of file packetsync.c.

Referenced by consume_from_fifos().

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

Variable Documentation

◆ packetsync_options

const AVOption packetsync_options[]
static
Initial value:
= {
{ "eof_action", "Action to take when encountering EOF from secondary input ",
OFFSET(opt_eof_action), AV_OPT_TYPE_INT, { .i64 = EOF_ACTION_PASS },
EOF_ACTION_ENDALL, EOF_ACTION_PASS, .flags = FLAGS, .unit = "eof_action" },
{ "endall", "End both streams.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_ENDALL }, .flags = FLAGS, .unit = "eof_action" },
{ "pass", "Pass through the main input.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_PASS }, .flags = FLAGS, .unit = "eof_action" },
{ "ts_sync_mode", "How strictly to sync streams based on secondary input timestamps",
OFFSET(opt_ts_sync_mode), AV_OPT_TYPE_INT, { .i64 = TS_DEFAULT },
TS_DEFAULT, TS_NEAREST, .flags = FLAGS, .unit = "ts_sync_mode" },
{ "default", "Packet from secondary input with the nearest lower or equal timestamp to the primary input packet",
0, AV_OPT_TYPE_CONST, { .i64 = TS_DEFAULT }, .flags = FLAGS, .unit = "ts_sync_mode" },
{ "nearest", "Packet from secondary input with the absolute nearest timestamp to the primary input packet",
0, AV_OPT_TYPE_CONST, { .i64 = TS_NEAREST }, .flags = FLAGS, .unit = "ts_sync_mode" },
{ NULL }
}

Definition at line 40 of file packetsync.c.

◆ ff_packetsync_class

const AVClass ff_packetsync_class
Initial value:
= {
.class_name = "packetsync",
.item_name = packetsync_name,
.option = packetsync_options,
.parent_log_context_offset = OFFSET(parent),
}

Definition at line 55 of file packetsync.c.

Referenced by ff_packetsync_child_class_iterate(), and ff_packetsync_preinit().

packetsync_name
static const char * packetsync_name(void *ptr)
Definition: packetsync.c:35
TS_NEAREST
@ TS_NEAREST
Sync to packets from secondary input with the absolute nearest timestamp to the packet event one.
Definition: packetsync.h:88
EOF_ACTION_ENDALL
@ EOF_ACTION_ENDALL
Definition: packetsync.h:30
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
packetsync_options
static const AVOption packetsync_options[]
Definition: packetsync.c:40
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:258
FLAGS
#define FLAGS
Definition: packetsync.c:33
AV_CLASS_CATEGORY_BITSTREAM_FILTER
@ AV_CLASS_CATEGORY_BITSTREAM_FILTER
Definition: log.h:37
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:298
OFFSET
#define OFFSET(member)
Definition: packetsync.c:32
TS_DEFAULT
@ TS_DEFAULT
Sync to packets from secondary input with the nearest, lower or equal timestamp to the packet event o...
Definition: packetsync.h:82
EOF_ACTION_PASS
@ EOF_ACTION_PASS
Definition: packetsync.h:31