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++)
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 &&
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)
358 ret =
fs->on_event(
fs);
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_bsf_inlink_acknowledge_status(AVBitStreamFilterLink *link, int *rstatus, int64_t *rpts)
int ff_bsf_inlink_consume_packet(AVBitStreamFilterLink *link, AVPacket **rpkt)
int ff_bsf_outlink_packet_wanted(AVBitStreamFilterLink *link)
int ff_bsf_outlink_get_status(AVBitStreamFilterLink *link)
void ff_bsf_link_set_in_status(AVBitStreamFilterLink *link, int status, int64_t pts)
void ff_bsf_inlink_set_status(AVBitStreamFilterLink *link, int status)
void ff_bsf_inlink_request_packet(AVBitStreamFilterLink *link)
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
AVPacket * av_packet_clone(const AVPacket *src)
Create a new packet that references the same data as src.
int av_packet_make_writable(AVPacket *pkt)
Create a writable reference for the data described by a given packet, avoiding data copy if possible.
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
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.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
#define FFERROR_BSF_NOT_READY
Special return code when activate() did not do anything.
@ AV_CLASS_CATEGORY_BITSTREAM_FILTER
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
void ff_packetsync_uninit(FFPacketSync *fs)
Free all memory currently allocated.
static int consume_from_fifos(FFPacketSync *fs)
int ff_packetsync_init_dualinput(FFPacketSync *fs, AVBitStreamFilterContext *parent)
Initialize a packet sync structure for dualinput.
int ff_packetsync_configure(FFPacketSync *fs)
Configure a packet sync structure.
const AVClass * ff_packetsync_child_class_iterate(void **iter)
static const AVOption packetsync_options[]
static int64_t packetsync_pts_extrapolate(FFPacketSync *fs, unsigned in, int64_t pts)
static const char * packetsync_name(void *ptr)
const AVClass ff_packetsync_class
static int packetsync_advance(FFPacketSync *fs)
int ff_packetsync_activate(FFPacketSync *fs)
Examine the packets in the filter's input and try to produce output.
int ff_packetsync_get_packet(FFPacketSync *fs, unsigned in, AVPacket **rpkt, unsigned get)
Get the current packet in an input.
int ff_packetsync_init(FFPacketSync *fs, AVBitStreamFilterContext *parent, unsigned nb_in)
Initialize a packet sync structure.
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.
void ff_packetsync_preinit(FFPacketSync *fs)
Pre-initialize a packet sync structure.
static void packetsync_inject_status(FFPacketSync *fs, unsigned in, int status, int64_t eof_pts)
static void packetsync_inject_packet(FFPacketSync *fs, unsigned in, AVPacket *pkt)
static void packetsync_sync_level_update(FFPacketSync *fs, int64_t eof_pts)
static void packetsync_eof(FFPacketSync *fs, int64_t pts)
@ TS_DEFAULT
Sync to packets from secondary input with the nearest, lower or equal timestamp to the packet event o...
@ TS_NEAREST
Sync to packets from secondary input with the absolute nearest timestamp to the packet event one.
@ EXT_STOP
Completely stop all streams with this one.
@ EXT_NULL
Ignore this stream and continue processing the other ones.
static void get(const uint8_t *pixels, int stride, int16_t *block)
unsigned nb_outputs
number of output pads
AVBitStreamFilterLink ** inputs
array of pointers to input links
Describe the class of an AVClass context structure.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...