FFmpeg
framesync.h
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 #ifndef AVFILTER_FRAMESYNC_H
22 #define AVFILTER_FRAMESYNC_H
23 
24 #include "bufferqueue.h"
25 
26 enum EOFAction {
27  EOF_ACTION_REPEAT,
28  EOF_ACTION_ENDALL,
29  EOF_ACTION_PASS
30 };
31 
32 /*
33  * TODO
34  * Export convenient options.
35  */
36 
60 enum FFFrameSyncExtMode {
61 
65  EXT_STOP,
66 
70  EXT_NULL,
71 
75  EXT_INFINITY,
76 };
77 
81 typedef struct FFFrameSyncIn {
82 
86  enum FFFrameSyncExtMode before;
87 
91  enum FFFrameSyncExtMode after;
92 
97 
102 
107 
111  int64_t pts;
112 
116  int64_t pts_next;
117 
121  uint8_t have_next;
122 
126  uint8_t state;
127 
139  unsigned sync;
140 
141 } FFFrameSyncIn;
142 
146 typedef struct FFFrameSync {
147  const AVClass *class;
148 
153 
157  unsigned nb_in;
158 
163 
167  int64_t pts;
168 
172  int (*on_event)(struct FFFrameSync *fs);
173 
177  void *opaque;
178 
182  unsigned in_request;
183 
188  unsigned sync_level;
189 
193  uint8_t frame_ready;
194 
198  uint8_t eof;
199 
204 
205  int opt_repeatlast;
206  int opt_shortest;
207  int opt_eof_action;
208 
209 } FFFrameSync;
210 
214 const AVClass *framesync_get_class(void);
215 
223 void ff_framesync_preinit(FFFrameSync *fs);
224 
235 int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in);
236 
244 int ff_framesync_configure(FFFrameSync *fs);
245 
249 void ff_framesync_uninit(FFFrameSync *fs);
250 
261 int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe,
262  unsigned get);
263 
270 int ff_framesync_activate(FFFrameSync *fs);
271 
283 int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent);
284 
293 int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1);
294 
298 int ff_framesync_dualinput_get_writable(FFFrameSync *fs, AVFrame **f0, AVFrame **f1);
299 
300 #define FRAMESYNC_DEFINE_CLASS(name, context, field) \
301 static int name##_framesync_preinit(AVFilterContext *ctx) { \
302  context *s = ctx->priv; \
303  ff_framesync_preinit(&s->field); \
304  return 0; \
305 } \
306 static const AVClass *name##_child_class_next(const AVClass *prev) { \
307  return prev ? NULL : framesync_get_class(); \
308 } \
309 static void *name##_child_next(void *obj, void *prev) { \
310  context *s = obj; \
311  s->fs.class = framesync_get_class(); /* FIXME */ \
312  return prev ? NULL : &s->field; \
313 } \
314 static const AVClass name##_class = { \
315  .class_name = #name, \
316  .item_name = av_default_item_name, \
317  .option = name##_options, \
318  .version = LIBAVUTIL_VERSION_INT, \
319  .category = AV_CLASS_CATEGORY_FILTER, \
320  .child_class_next = name##_child_class_next, \
321  .child_next = name##_child_next, \
322 }
323 
324 #endif /* AVFILTER_FRAMESYNC_H */
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
int64_t pts
Timestamp of the current event.
Definition: framesync.h:167
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:86
AVFilterContext * parent
Parent filter context.
Definition: framesync.h:152
uint8_t have_next
Boolean flagging the next frame, for internal use.
Definition: framesync.h:121
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
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:91
Input stream structure.
Definition: framesync.h:81
AVFrame * frame_next
Next frame, for internal use.
Definition: framesync.h:106
Frame sync structure.
Definition: framesync.h:146
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:96
uint8_t eof
Flag indicating that output has reached EOF.
Definition: framesync.h:198
unsigned in_request
Index of the input that requires a request.
Definition: framesync.h:182
AVRational time_base
Time base for the output events.
Definition: framesync.h:162
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:177
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
Rational number (pair of numerator and denominator).
Definition: rational.h:58
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
uint8_t frame_ready
Flag indicating that a frame event is ready.
Definition: framesync.h:193
int64_t pts
PTS of the current frame.
Definition: framesync.h:111
An instance of a filter.
Definition: avfilter.h:338
int64_t pts_next
PTS of the next frame, for internal use.
Definition: framesync.h:116