FFmpeg
framesync.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Nicolas George
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/avassert.h"
22 #include "libavutil/opt.h"
23 #include "avfilter.h"
24 #include "filters.h"
25 #include "framesync.h"
26 #include "internal.h"
27 
28 #define OFFSET(member) offsetof(FFFrameSync, member)
29 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
30 
31 static const char *framesync_name(void *ptr)
32 {
33  return "framesync";
34 }
35 
36 static const AVOption framesync_options[] = {
37  { "eof_action", "Action to take when encountering EOF from secondary input ",
38  OFFSET(opt_eof_action), AV_OPT_TYPE_INT, { .i64 = EOF_ACTION_REPEAT },
39  EOF_ACTION_REPEAT, EOF_ACTION_PASS, .flags = FLAGS, "eof_action" },
40  { "repeat", "Repeat the previous frame.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_REPEAT }, .flags = FLAGS, "eof_action" },
41  { "endall", "End both streams.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_ENDALL }, .flags = FLAGS, "eof_action" },
42  { "pass", "Pass through the main input.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_PASS }, .flags = FLAGS, "eof_action" },
43  { "shortest", "force termination when the shortest input terminates", OFFSET(opt_shortest), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
44  { "repeatlast", "extend last frame of secondary streams beyond EOF", OFFSET(opt_repeatlast), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
45  { NULL }
46 };
47 static const AVClass framesync_class = {
49  .class_name = "framesync",
50  .item_name = framesync_name,
51  .category = AV_CLASS_CATEGORY_FILTER,
52  .option = framesync_options,
53  .parent_log_context_offset = OFFSET(parent),
54 };
55 
56 enum {
60 };
61 
62 static int consume_from_fifos(FFFrameSync *fs);
63 
65 {
66  return &framesync_class;
67 }
68 
70 {
71  if (fs->class)
72  return;
73  fs->class = &framesync_class;
75 }
76 
77 int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
78 {
79  /* For filters with several outputs, we will not be able to assume which
80  output is relevant for ff_outlink_frame_wanted() and
81  ff_outlink_set_status(). To be designed when needed. */
82  av_assert0(parent->nb_outputs == 1);
83 
85  fs->parent = parent;
86  fs->nb_in = nb_in;
87 
88  fs->in = av_calloc(nb_in, sizeof(*fs->in));
89  if (!fs->in)
90  return AVERROR(ENOMEM);
91  return 0;
92 }
93 
95 {
96  fs->eof = 1;
97  fs->frame_ready = 0;
99 }
100 
102 {
103  unsigned i, level = 0;
104 
105  for (i = 0; i < fs->nb_in; i++)
106  if (fs->in[i].state != STATE_EOF)
107  level = FFMAX(level, fs->in[i].sync);
108  av_assert0(level <= fs->sync_level);
109  if (level < fs->sync_level)
110  av_log(fs, AV_LOG_VERBOSE, "Sync level %u\n", level);
111  if (level)
112  fs->sync_level = level;
113  else
114  framesync_eof(fs);
115 }
116 
118 {
119  unsigned i;
120 
121  if (!fs->opt_repeatlast || fs->opt_eof_action == EOF_ACTION_PASS) {
122  fs->opt_repeatlast = 0;
124  }
125  if (fs->opt_shortest || fs->opt_eof_action == EOF_ACTION_ENDALL) {
126  fs->opt_shortest = 1;
128  }
129  if (!fs->opt_repeatlast) {
130  for (i = 1; i < fs->nb_in; i++) {
131  fs->in[i].after = EXT_NULL;
132  fs->in[i].sync = 0;
133  }
134  }
135  if (fs->opt_shortest) {
136  for (i = 0; i < fs->nb_in; i++)
137  fs->in[i].after = EXT_STOP;
138  }
139 
140  if (!fs->time_base.num) {
141  for (i = 0; i < fs->nb_in; i++) {
142  if (fs->in[i].sync) {
143  if (fs->time_base.num) {
144  fs->time_base = av_gcd_q(fs->time_base, fs->in[i].time_base,
146  } else {
147  fs->time_base = fs->in[i].time_base;
148  }
149  }
150  }
151  if (!fs->time_base.num) {
152  av_log(fs, AV_LOG_ERROR, "Impossible to set time base\n");
153  return AVERROR(EINVAL);
154  }
155  av_log(fs, AV_LOG_VERBOSE, "Selected %d/%d time base\n",
156  fs->time_base.num, fs->time_base.den);
157  }
158 
159  for (i = 0; i < fs->nb_in; i++)
160  fs->in[i].pts = fs->in[i].pts_next = AV_NOPTS_VALUE;
161  fs->sync_level = UINT_MAX;
163 
164  return 0;
165 }
166 
168 {
169  unsigned i;
170  int64_t pts;
171  int ret;
172 
173  while (!(fs->frame_ready || fs->eof)) {
174  ret = consume_from_fifos(fs);
175  if (ret <= 0)
176  return ret;
177 
178  pts = INT64_MAX;
179  for (i = 0; i < fs->nb_in; i++)
180  if (fs->in[i].have_next && fs->in[i].pts_next < pts)
181  pts = fs->in[i].pts_next;
182  if (pts == INT64_MAX) {
183  framesync_eof(fs);
184  break;
185  }
186  for (i = 0; i < fs->nb_in; i++) {
187  if (fs->in[i].pts_next == pts ||
188  (fs->in[i].before == EXT_INFINITY &&
189  fs->in[i].state == STATE_BOF)) {
190  av_frame_free(&fs->in[i].frame);
191  fs->in[i].frame = fs->in[i].frame_next;
192  fs->in[i].pts = fs->in[i].pts_next;
193  fs->in[i].frame_next = NULL;
194  fs->in[i].pts_next = AV_NOPTS_VALUE;
195  fs->in[i].have_next = 0;
196  fs->in[i].state = fs->in[i].frame ? STATE_RUN : STATE_EOF;
197  if (fs->in[i].sync == fs->sync_level && fs->in[i].frame)
198  fs->frame_ready = 1;
199  if (fs->in[i].state == STATE_EOF &&
200  fs->in[i].after == EXT_STOP)
201  framesync_eof(fs);
202  }
203  }
204  if (fs->frame_ready)
205  for (i = 0; i < fs->nb_in; i++)
206  if ((fs->in[i].state == STATE_BOF &&
207  fs->in[i].before == EXT_STOP))
208  fs->frame_ready = 0;
209  fs->pts = pts;
210  }
211  return 0;
212 }
213 
214 static int64_t framesync_pts_extrapolate(FFFrameSync *fs, unsigned in,
215  int64_t pts)
216 {
217  /* Possible enhancement: use the link's frame rate */
218  return pts + 1;
219 }
220 
222 {
223  int64_t pts;
224 
225  av_assert0(!fs->in[in].have_next);
226  av_assert0(frame);
227  pts = av_rescale_q(frame->pts, fs->in[in].time_base, fs->time_base);
228  frame->pts = pts;
229  fs->in[in].frame_next = frame;
230  fs->in[in].pts_next = pts;
231  fs->in[in].have_next = 1;
232 }
233 
234 static void framesync_inject_status(FFFrameSync *fs, unsigned in, int status, int64_t pts)
235 {
236  av_assert0(!fs->in[in].have_next);
237  pts = fs->in[in].state != STATE_RUN || fs->in[in].after == EXT_INFINITY
238  ? INT64_MAX : framesync_pts_extrapolate(fs, in, fs->in[in].pts);
239  fs->in[in].sync = 0;
241  fs->in[in].frame_next = NULL;
242  fs->in[in].pts_next = pts;
243  fs->in[in].have_next = 1;
244 }
245 
246 int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe,
247  unsigned get)
248 {
249  AVFrame *frame;
250  unsigned need_copy = 0, i;
251  int64_t pts_next;
252  int ret;
253 
254  if (!fs->in[in].frame) {
255  *rframe = NULL;
256  return 0;
257  }
258  frame = fs->in[in].frame;
259  if (get) {
260  /* Find out if we need to copy the frame: is there another sync
261  stream, and do we know if its current frame will outlast this one? */
262  pts_next = fs->in[in].have_next ? fs->in[in].pts_next : INT64_MAX;
263  for (i = 0; i < fs->nb_in && !need_copy; i++)
264  if (i != in && fs->in[i].sync &&
265  (!fs->in[i].have_next || fs->in[i].pts_next < pts_next))
266  need_copy = 1;
267  if (need_copy) {
268  if (!(frame = av_frame_clone(frame)))
269  return AVERROR(ENOMEM);
270  if ((ret = av_frame_make_writable(frame)) < 0) {
271  av_frame_free(&frame);
272  return ret;
273  }
274  } else {
275  fs->in[in].frame = NULL;
276  }
277  fs->frame_ready = 0;
278  }
279  *rframe = frame;
280  return 0;
281 }
282 
284 {
285  unsigned i;
286 
287  for (i = 0; i < fs->nb_in; i++) {
288  av_frame_free(&fs->in[i].frame);
289  av_frame_free(&fs->in[i].frame_next);
290  }
291 
292  av_freep(&fs->in);
293 }
294 
296 {
297  AVFilterContext *ctx = fs->parent;
298  AVFrame *frame = NULL;
299  int64_t pts;
300  unsigned i, nb_active, nb_miss;
301  int ret, status;
302 
303  nb_active = nb_miss = 0;
304  for (i = 0; i < fs->nb_in; i++) {
305  if (fs->in[i].have_next || fs->in[i].state == STATE_EOF)
306  continue;
307  nb_active++;
308  ret = ff_inlink_consume_frame(ctx->inputs[i], &frame);
309  if (ret < 0)
310  return ret;
311  if (ret) {
312  av_assert0(frame);
313  framesync_inject_frame(fs, i, frame);
314  } else {
315  ret = ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts);
316  if (ret > 0) {
317  framesync_inject_status(fs, i, status, pts);
318  } else if (!ret) {
319  nb_miss++;
320  }
321  }
322  }
323  if (nb_miss) {
324  if (nb_miss == nb_active && !ff_outlink_frame_wanted(ctx->outputs[0]))
325  return FFERROR_NOT_READY;
326  for (i = 0; i < fs->nb_in; i++)
327  if (!fs->in[i].have_next && fs->in[i].state != STATE_EOF)
329  return 0;
330  }
331  return 1;
332 }
333 
335 {
336  int ret;
337 
338  ret = framesync_advance(fs);
339  if (ret < 0)
340  return ret;
341  if (fs->eof || !fs->frame_ready)
342  return 0;
343  ret = fs->on_event(fs);
344  if (ret < 0)
345  return ret;
346  fs->frame_ready = 0;
347 
348  return 0;
349 }
350 
352 {
353  int ret;
354 
355  ret = ff_framesync_init(fs, parent, 2);
356  if (ret < 0)
357  return ret;
358  fs->in[0].time_base = parent->inputs[0]->time_base;
359  fs->in[1].time_base = parent->inputs[1]->time_base;
360  fs->in[0].sync = 2;
361  fs->in[0].before = EXT_STOP;
362  fs->in[0].after = EXT_INFINITY;
363  fs->in[1].sync = 1;
364  fs->in[1].before = EXT_NULL;
365  fs->in[1].after = EXT_INFINITY;
366  return 0;
367 }
368 
370 {
371  AVFilterContext *ctx = fs->parent;
372  AVFrame *mainpic = NULL, *secondpic = NULL;
373  int ret;
374 
375  if ((ret = ff_framesync_get_frame(fs, 0, &mainpic, 1)) < 0 ||
376  (ret = ff_framesync_get_frame(fs, 1, &secondpic, 0)) < 0) {
377  av_frame_free(&mainpic);
378  return ret;
379  }
380  av_assert0(mainpic);
381  mainpic->pts = av_rescale_q(fs->pts, fs->time_base, ctx->outputs[0]->time_base);
382  if (ctx->is_disabled)
383  secondpic = NULL;
384  *f0 = mainpic;
385  *f1 = secondpic;
386  return 0;
387 }
388 
390 {
391  int ret;
392 
393  ret = ff_framesync_dualinput_get(fs, f0, f1);
394  if (ret < 0)
395  return ret;
396  ret = ff_inlink_make_frame_writable(fs->parent->inputs[0], f0);
397  if (ret < 0) {
398  av_frame_free(f0);
399  *f1 = NULL;
400  return ret;
401  }
402  return 0;
403 }
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link&#39;s FIFO and update the link&#39;s stats.
Definition: avfilter.c:1476
#define NULL
Definition: coverity.c:32
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
static void framesync_sync_level_update(FFFrameSync *fs)
Definition: framesync.c:101
AVOption.
Definition: opt.h:246
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
Main libavfilter public API header.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1357
void ff_framesync_preinit(FFFrameSync *fs)
Pre-initialize a frame sync structure.
Definition: framesync.c:69
static const AVOption framesync_options[]
Definition: framesync.c:36
int num
Numerator.
Definition: rational.h:59
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:117
static const char * framesync_name(void *ptr)
Definition: framesync.c:31
return FFERROR_NOT_READY
static void framesync_inject_status(FFFrameSync *fs, unsigned in, int status, int64_t pts)
Definition: framesync.c:234
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:385
int64_t pts
Timestamp of the current event.
Definition: framesync.h:167
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1602
static void framesync_eof(FFFrameSync *fs)
Definition: framesync.c:94
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:86
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
AVFilterContext * parent
Parent filter context.
Definition: framesync.h:152
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
uint8_t have_next
Boolean flagging the next frame, for internal use.
Definition: framesync.h:121
#define fs(width, name, subs,...)
Definition: cbs_vp9.c:259
AVOptions.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
Definition: framesync.c:351
const AVClass * ff_framesync_get_class(void)
Get the class for the framesync object.
Definition: framesync.c:64
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
Definition: framesync.c:369
int ff_framesync_dualinput_get_writable(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
Same as ff_framesync_dualinput_get(), but make sure that f0 is writable.
Definition: framesync.c:389
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:393
unsigned sync_level
Synchronization level: only inputs with the same sync level are sync sources.
Definition: framesync.h:188
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:203
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:91
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function.If this function returns true
#define av_log(a,...)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1431
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:283
AVFrame * frame_next
Next frame, for internal use.
Definition: framesync.h:106
Frame sync structure.
Definition: framesync.h:146
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
unsigned nb_outputs
number of output pads
Definition: avfilter.h:351
#define OFFSET(member)
Definition: framesync.c:28
simple assert() macros that are a bit more flexible than ISO C assert().
int opt_shortest
Definition: framesync.h:206
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:96
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter&#39;s input and try to produce output.
Definition: framesync.c:334
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
Definition: framesync.h:172
int opt_repeatlast
Definition: framesync.h:205
#define FLAGS
Definition: framesync.c:29
#define FFMAX(a, b)
Definition: common.h:94
uint8_t eof
Flag indicating that output has reached EOF.
Definition: framesync.h:198
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
AVFormatContext * ctx
Definition: movenc.c:48
AVRational time_base
Time base for the output events.
Definition: framesync.h:162
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Definition: avfilter.c:1520
static int64_t framesync_pts_extrapolate(FFFrameSync *fs, unsigned in, int64_t pts)
Definition: framesync.c:214
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:541
static const AVClass framesync_class
Definition: framesync.c:47
Extend the frame to infinity.
Definition: framesync.h:75
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:77
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
uint8_t state
State: before first, in stream or after EOF, for internal use.
Definition: framesync.h:126
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events...
Definition: framesync.h:139
Describe the class of an AVClass context structure.
Definition: log.h:67
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
Ignore this stream and continue processing the other ones.
Definition: framesync.h:70
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.
Definition: rational.c:186
unsigned nb_in
Number of input streams.
Definition: framesync.h:157
AVFrame * frame
Current frame, may be NULL before the first one or after EOF.
Definition: framesync.h:101
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static int consume_from_fifos(FFFrameSync *fs)
Definition: framesync.c:295
static int64_t pts
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:612
uint8_t frame_ready
Flag indicating that a frame event is ready.
Definition: framesync.h:193
uint8_t level
Definition: svq3.c:209
int version
LIBAVUTIL_VERSION with which this structure was created.
Definition: log.h:93
int opt_eof_action
Definition: framesync.h:207
int64_t pts
PTS of the current frame.
Definition: framesync.h:111
int den
Denominator.
Definition: rational.h:60
Completely stop all streams with this one.
Definition: framesync.h:65
static int framesync_advance(FFFrameSync *fs)
Definition: framesync.c:167
An instance of a filter.
Definition: avfilter.h:338
#define av_freep(p)
static void framesync_inject_frame(FFFrameSync *fs, unsigned in, AVFrame *frame)
Definition: framesync.c:221
internal API functions
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_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
Definition: framesync.c:246
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
const AVClass * class
Definition: framesync.h:147
int64_t pts_next
PTS of the next frame, for internal use.
Definition: framesync.h:116