Go to the documentation of this file.
32 #define OFFSET(member) offsetof(FFPacketSync, member)
33 #define FLAGS (AV_OPT_FLAG_BSF_PARAM|AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
41 {
"eof_action",
"Action to take when encountering EOF from secondary input ",
46 {
"ts_sync_mode",
"How strictly to sync streams based on secondary input timestamps",
49 {
"default",
"Packet from secondary input with the nearest lower or equal timestamp to the primary input packet",
51 {
"nearest",
"Packet from secondary input with the absolute nearest timestamp to the primary input packet",
57 .class_name =
"packetsync",
61 .parent_log_context_offset =
OFFSET(parent),
67 *iter = (
void *)(uintptr_t)
c;
118 for (
i = 0;
i <
fs->nb_in;
i++)
122 if (level < fs->sync_level)
125 for (
i = 0;
i <
fs->nb_in;
i++) {
127 fs->in[
i].ts_mode =
fs->opt_ts_sync_mode;
142 for (
i = 1;
i <
fs->nb_in;
i++) {
147 for (
i = 0;
i <
fs->nb_in;
i++)
151 if (!
fs->time_base.num) {
152 for (
i = 0;
i <
fs->nb_in;
i++) {
153 if (
fs->in[
i].sync) {
154 if (
fs->time_base.num) {
158 fs->time_base =
fs->in[
i].time_base;
162 if (!
fs->time_base.num) {
167 fs->time_base.num,
fs->time_base.den);
170 for (
i = 0;
i <
fs->nb_in;
i++)
172 fs->sync_level = UINT_MAX;
184 while (!(
fs->pkt_ready ||
fs->eof)) {
190 for (
i = 0;
i <
fs->nb_in;
i++)
191 if (
fs->in[
i].have_next &&
fs->in[
i].pts_next <
pts)
193 if (
pts == INT64_MAX) {
197 for (
i = 0;
i <
fs->nb_in;
i++) {
198 if (
fs->in[
i].pts_next ==
pts ||
200 fs->in[
i].have_next &&
202 fs->in[
i].pts_next - pts < pts - fs->in[
i].pts)) {
204 fs->in[
i].pkt =
fs->in[
i].pkt_next;
205 fs->in[
i].pts =
fs->in[
i].pts_next;
208 fs->in[
i].have_next = 0;
210 if (
fs->in[
i].sync ==
fs->sync_level &&
fs->in[
i].pkt)
218 for (
i = 0;
i <
fs->nb_in;
i++)
241 fs->in[in].pkt_next =
pkt;
242 fs->in[in].pts_next =
pts;
243 fs->in[in].have_next = 1;
251 fs->in[in].pkt_next =
NULL;
254 fs->in[in].have_next = 1;
261 unsigned need_copy = 0,
i;
264 if (!
fs->in[in].pkt) {
268 pkt =
fs->in[in].pkt;
272 pts_next =
fs->in[in].have_next ?
fs->in[in].pts_next : INT64_MAX;
273 for (
i = 0;
i <
fs->nb_in && !need_copy;
i++)
274 if (
i != in &&
fs->in[
i].sync &&
275 (!
fs->in[
i].have_next ||
fs->in[
i].pts_next < pts_next))
293 for (
i = 0;
i <
fs->nb_in;
i++) {
306 unsigned i, nb_active, nb_miss;
309 nb_active = nb_miss = 0;
310 for (
i = 0;
i <
fs->nb_in;
i++) {
332 for (
i = 0;
i <
fs->nb_in;
i++)
348 for (
i = 0;
i <
ctx->nb_inputs;
i++)
356 if (
fs->eof || !
fs->pkt_ready)
int ff_packetsync_get_packet(FFPacketSync *fs, unsigned in, AVPacket **rpkt, unsigned get)
Get the current packet in an input.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
static void packetsync_eof(FFPacketSync *fs, int64_t pts)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_bsf_inlink_acknowledge_status(AVBitStreamFilterLink *link, int *rstatus, int64_t *rpts)
static void packetsync_inject_packet(FFPacketSync *fs, unsigned in, AVPacket *pkt)
#define AVERROR_EOF
End of file.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int version
LIBAVUTIL_VERSION with which this structure was created.
void ff_bsf_link_set_in_status(AVBitStreamFilterLink *link, int status, int64_t pts)
int ff_bsf_inlink_consume_packet(AVBitStreamFilterLink *link, AVPacket **rpkt)
#define AV_LOG_VERBOSE
Detailed information.
int ff_packetsync_dualinput_get(FFPacketSync *fs, AVPacket **f0, AVPacket **f1)
@ EXT_NULL
Ignore this stream and continue processing the other ones.
@ EXT_STOP
Completely stop all streams with this one.
void ff_bsf_inlink_request_packet(AVBitStreamFilterLink *link)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
static const char * packetsync_name(void *ptr)
@ TS_NEAREST
Sync to packets from secondary input with the absolute nearest timestamp to the packet event one.
AVBitStreamFilterLink ** inputs
array of pointers to input links
static int64_t packetsync_pts_extrapolate(FFPacketSync *fs, unsigned in, int64_t pts)
int ff_bsf_outlink_packet_wanted(AVBitStreamFilterLink *link)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static AVFormatContext * ctx
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void ff_bsf_inlink_set_status(AVBitStreamFilterLink *link, int status)
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
const AVClass * ff_packetsync_child_class_iterate(void **iter)
#define fs(width, name, subs,...)
static int packetsync_advance(FFPacketSync *fs)
#define FFERROR_BSF_NOT_READY
Special return code when activate() did not do anything.
static void get(const uint8_t *pixels, int stride, int16_t *block)
static void packetsync_sync_level_update(FFPacketSync *fs, int64_t eof_pts)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
const AVClass ff_packetsync_class
#define i(width, name, range_min, range_max)
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int consume_from_fifos(FFPacketSync *fs)
int ff_packetsync_configure(FFPacketSync *fs)
Configure a packet sync structure.
static const AVOption packetsync_options[]
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.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
AVRational av_gcd_q(AVRational a, AVRational b, int max_den, AVRational def)
Return the best rational so that a and b are multiple of it.
#define AV_TIME_BASE
Internal time base represented as integer.
void * av_calloc(size_t nmemb, size_t size)
void ff_packetsync_uninit(FFPacketSync *fs)
Free all memory currently allocated.
int ff_packetsync_init(FFPacketSync *fs, AVBitStreamFilterContext *parent, unsigned nb_in)
Initialize a packet sync structure.
void ff_packetsync_preinit(FFPacketSync *fs)
Pre-initialize a packet sync structure.
int ff_bsf_outlink_get_status(AVBitStreamFilterLink *link)
int ff_packetsync_init_dualinput(FFPacketSync *fs, AVBitStreamFilterContext *parent)
Initialize a packet sync structure for dualinput.
unsigned nb_outputs
number of output pads
@ AV_OPT_TYPE_INT
Underlying C type is int.
int av_packet_make_writable(AVPacket *pkt)
Create a writable reference for the data described by a given packet, avoiding data copy if possible.
int ff_packetsync_activate(FFPacketSync *fs)
Examine the packets in the filter's input and try to produce output.
static void packetsync_inject_status(FFPacketSync *fs, unsigned in, int status, int64_t eof_pts)
@ AV_CLASS_CATEGORY_BITSTREAM_FILTER
This structure stores compressed data.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
@ TS_DEFAULT
Sync to packets from secondary input with the nearest, lower or equal timestamp to the packet event o...
AVPacket * av_packet_clone(const AVPacket *src)
Create a new packet that references the same data as src.