Libav
avfilter.h
Go to the documentation of this file.
1 /*
2  * filter layer
3  * Copyright (c) 2007 Bobby Bingham
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVFILTER_AVFILTER_H
23 #define AVFILTER_AVFILTER_H
24 
36 #include "libavutil/attributes.h"
37 #include "libavutil/avutil.h"
38 #include "libavutil/frame.h"
39 #include "libavutil/log.h"
40 #include "libavutil/samplefmt.h"
41 #include "libavutil/pixfmt.h"
42 #include "libavutil/rational.h"
43 #include "libavcodec/avcodec.h"
44 
45 #include <stddef.h>
46 
47 #include "libavfilter/version.h"
48 
52 unsigned avfilter_version(void);
53 
57 const char *avfilter_configuration(void);
58 
62 const char *avfilter_license(void);
63 
64 
65 typedef struct AVFilterContext AVFilterContext;
66 typedef struct AVFilterLink AVFilterLink;
67 typedef struct AVFilterPad AVFilterPad;
68 typedef struct AVFilterFormats AVFilterFormats;
69 
70 #if FF_API_AVFILTERBUFFER
71 
76 typedef struct AVFilterBuffer {
77  uint8_t *data[8];
78 
93  uint8_t **extended_data;
94  int linesize[8];
95 
97  void *priv;
104  void (*free)(struct AVFilterBuffer *buf);
105 
106  int format;
107  int w, h;
108  unsigned refcount;
109 } AVFilterBuffer;
110 
111 #define AV_PERM_READ 0x01
112 #define AV_PERM_WRITE 0x02
113 #define AV_PERM_PRESERVE 0x04
114 #define AV_PERM_REUSE 0x08
115 #define AV_PERM_REUSE2 0x10
116 #define AV_PERM_NEG_LINESIZES 0x20
117 
118 
123 typedef struct AVFilterBufferRefAudioProps {
124  uint64_t channel_layout;
125  int nb_samples;
126  int sample_rate;
127  int planar;
128 } AVFilterBufferRefAudioProps;
129 
135 typedef struct AVFilterBufferRefVideoProps {
136  int w;
137  int h;
139  int interlaced;
140  int top_field_first;
141  enum AVPictureType pict_type;
142  int key_frame;
143 } AVFilterBufferRefVideoProps;
144 
153 typedef struct AVFilterBufferRef {
154  AVFilterBuffer *buf;
155  uint8_t *data[8];
156 
170  uint8_t **extended_data;
171  int linesize[8];
172 
173  AVFilterBufferRefVideoProps *video;
174  AVFilterBufferRefAudioProps *audio;
175 
181  int64_t pts;
182  int64_t pos;
183 
184  int format;
185 
186  int perms;
187 
188  enum AVMediaType type;
189 } AVFilterBufferRef;
190 
195 void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
196 
207 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
208 
219 void avfilter_unref_buffer(AVFilterBufferRef *ref);
220 
229 void avfilter_unref_bufferp(AVFilterBufferRef **ref);
230 #endif
231 
232 #if FF_API_AVFILTERPAD_PUBLIC
233 
241 struct AVFilterPad {
247  const char *name;
248 
252  enum AVMediaType type;
253 
261  attribute_deprecated int min_perms;
262 
272  attribute_deprecated int rej_perms;
273 
277  int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
278 
285  AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
286 
293  AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
294 
298  int (*end_frame)(AVFilterLink *link);
299 
303  int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
304 
315  int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
316 
326  int (*poll_frame)(AVFilterLink *link);
327 
335  int (*request_frame)(AVFilterLink *link);
336 
351  int (*config_props)(AVFilterLink *link);
352 
359  int needs_fifo;
360 
367  int needs_writable;
368 };
369 #endif
370 
375 int avfilter_pad_count(const AVFilterPad *pads);
376 
386 const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
387 
397 enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
398 
404 #define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
405 
410 #define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
411 
415 #define AVFILTER_FLAG_SLICE_THREADS (1 << 2)
416 
421 typedef struct AVFilter {
425  const char *name;
426 
432  const char *description;
433 
450 
460 
464  int flags;
465 
466  /*****************************************************************
467  * All fields below this line are not part of the public API. They
468  * may not be used outside of libavfilter and can be changed and
469  * removed at will.
470  * New public fields should be added right above.
471  *****************************************************************
472  */
473 
495  int (*init)(AVFilterContext *ctx);
496 
509 
521 
545 
546  int priv_size;
547 
552  struct AVFilter *next;
553 } AVFilter;
554 
558 #define AVFILTER_THREAD_SLICE (1 << 0)
559 
560 typedef struct AVFilterInternal AVFilterInternal;
561 
564  const AVClass *av_class;
565 
566  const AVFilter *filter;
567 
568  char *name;
569 
572 #if FF_API_FOO_COUNT
573  attribute_deprecated unsigned input_count;
574 #endif
575  unsigned nb_inputs;
576 
579 #if FF_API_FOO_COUNT
580  attribute_deprecated unsigned output_count;
581 #endif
582  unsigned nb_outputs;
583 
584  void *priv;
585 
587 
605 
609  AVFilterInternal *internal;
610 };
611 
619 struct AVFilterLink {
622 
625 
627 
628  /* These parameters apply only to video */
629  int w;
630  int h;
632  /* These two parameters apply only to audio */
633  uint64_t channel_layout;
635 
636  int format;
637 
646 
647  /*****************************************************************
648  * All fields below this line are not part of the public API. They
649  * may not be used outside of libavfilter and can be changed and
650  * removed at will.
651  * New public fields should be added right above.
652  *****************************************************************
653  */
661 
670 
679 
681  enum {
685  } init_state;
686 };
687 
697 int avfilter_link(AVFilterContext *src, unsigned srcpad,
698  AVFilterContext *dst, unsigned dstpad);
699 
707 
708 #if FF_API_AVFILTERBUFFER
709 
721 AVFilterBufferRef *
722 avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
723  int w, int h, enum AVPixelFormat format);
724 
737 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
738  int linesize,
739  int perms,
740  int nb_samples,
742  uint64_t channel_layout);
743 #endif
744 
746 void avfilter_register_all(void);
747 
748 #if FF_API_OLD_FILTER_REGISTER
749 
751 void avfilter_uninit(void);
752 #endif
753 
765 
773 #if !FF_API_NOCONST_GET_NAME
774 const
775 #endif
776 AVFilter *avfilter_get_by_name(const char *name);
777 
783 const AVFilter *avfilter_next(const AVFilter *prev);
784 
785 #if FF_API_OLD_FILTER_REGISTER
786 
794 AVFilter **av_filter_next(AVFilter **filter);
795 #endif
796 
797 #if FF_API_AVFILTER_OPEN
798 
809 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
810 #endif
811 
812 
813 #if FF_API_AVFILTER_INIT_FILTER
814 
825 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
826 #endif
827 
838 int avfilter_init_str(AVFilterContext *ctx, const char *args);
839 
861 
869 
880  unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
881 
882 #if FF_API_AVFILTERBUFFER
883 
890 int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
891 
899 int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
900 #endif
901 
907 const AVClass *avfilter_get_class(void);
908 
910 
923 typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
924 
938  void *arg, int *ret, int nb_jobs);
939 
940 typedef struct AVFilterGraph {
942 #if FF_API_FOO_COUNT
944  unsigned filter_count;
945 #endif
947 #if !FF_API_FOO_COUNT
948  unsigned nb_filters;
949 #endif
950 
953 #if FF_API_FOO_COUNT
954  unsigned nb_filters;
955 #endif
956 
970 
977 
982 
988  void *opaque;
989 
1003 } AVFilterGraph;
1004 
1009 
1025  const AVFilter *filter,
1026  const char *name);
1027 
1035 
1036 #if FF_API_AVFILTER_OPEN
1037 
1047 int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
1048 #endif
1049 
1063 int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
1064  const char *name, const char *args, void *opaque,
1065  AVFilterGraph *graph_ctx);
1066 
1074 int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
1075 
1080 void avfilter_graph_free(AVFilterGraph **graph);
1081 
1091 typedef struct AVFilterInOut {
1093  char *name;
1094 
1097 
1099  int pad_idx;
1100 
1103 } AVFilterInOut;
1104 
1111 
1116 void avfilter_inout_free(AVFilterInOut **inout);
1117 
1127 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
1129  void *log_ctx);
1130 
1161 int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
1164 
1169 #endif /* AVFILTER_AVFILTER_H */
AVFilterContext ** filters
Definition: avfilter.h:946
int(* poll_frame)(AVFilterLink *link)
Frame poll callback.
Definition: internal.h:86
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
int thread_type
Type of multithreading allowed for filters in this graph.
Definition: avfilter.h:969
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition: avfilter.c:491
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:71
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:232
int(* init)(AVFilterContext *ctx)
Filter initialization function.
Definition: avfilter.h:495
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:179
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
Definition: avfilter.h:1102
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:718
Libavfilter version macros.
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
external API header
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:47
int(* query_formats)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
Definition: avfilter.h:544
static const AVRational pixel_aspect[17]
Definition: h264_ps.c:40
int thread_type
Type of multithreading being allowed/used.
Definition: avfilter.h:604
Macro definitions for various function/variable attributes.
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:951
static void draw_slice(HYuvContext *s, AVFrame *frame, int y)
Definition: huffyuvdec.c:470
struct AVFilterGraph * graph
filtergraph this filter belongs to
Definition: avfilter.h:586
const char * name
Pad name.
Definition: internal.h:42
int priv_size
size of private data to allocate for the filter
Definition: avfilter.h:546
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:571
char * name
name of this filter instance
Definition: avfilter.h:568
avfilter_execute_func * execute
This callback may be set by the caller immediately after allocating the graph and before adding any f...
Definition: avfilter.h:1002
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:75
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:577
const char * avfilter_license(void)
Return the libavfilter license.
Definition: avfilter.c:48
uint8_t
int(* request_frame)(AVFilterLink *link)
Frame request callback.
Definition: internal.h:95
const char * name
int flags
A combination of AVFILTER_FLAG_*.
Definition: avfilter.h:464
void avfilter_register_all(void)
Initialize the filter system.
Definition: allfilters.c:39
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
char * resample_lavr_opts
libavresample options to use for the auto-inserted resample filters
Definition: avfilter.h:952
const char data[16]
Definition: mxf.c:70
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:976
int avfilter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
Definition: avfilter.c:145
const AVFilter * avfilter_next(const AVFilter *prev)
Iterate over all registered filters.
Definition: avfilter.c:302
void(* uninit)(AVFilterContext *ctx)
Filter uninitialization function.
Definition: avfilter.h:520
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
Definition: graphparser.c:383
const OptionDef options[]
Definition: avconv_opt.c:2187
A filter pad used for either input or output.
Definition: internal.h:36
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:570
int( avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A function pointer passed to the AVFilterGraph::execute callback to be executed multiple times...
Definition: avfilter.h:923
const AVClass * av_class
Definition: avfilter.h:941
unsigned nb_outputs
number of output pads
Definition: avfilter.h:582
unsigned avfilter_version(void)
Return the LIBAVFILTER_VERSION_INT constant.
Definition: avfilter.c:38
void * priv
private data for use by the filter
Definition: avfilter.h:584
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
Definition: internal.h:75
int(* init_dict)(AVFilterContext *ctx, AVDictionary **options)
Should be set instead of init by the filters that want to pass a dictionary of AVOptions to nested co...
Definition: avfilter.h:508
reference-counted frame API
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:278
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:307
unsigned nb_inputs
number of input pads
Definition: avfilter.h:575
int needs_writable
The filter expects writable frames from its input link, duplicating data buffers if needed...
Definition: internal.h:127
AVFilterContext * filter_ctx
filter context associated to this input/output
Definition: avfilter.h:1096
int avfilter_init_str(AVFilterContext *ctx, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:596
const AVFilterPad * inputs
List of inputs, terminated by a zeroed element.
Definition: avfilter.h:441
const AVClass * avfilter_get_class(void)
Definition: avfilter.c:793
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1091
int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
Insert a filter in the middle of an existing link.
Definition: avfilter.c:108
int( avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
A function executing multiple jobs, possibly in parallel.
Definition: avfilter.h:937
const AVClass * priv_class
A class for the private data, used to declare filter private AVOptions.
Definition: avfilter.h:459
sample_fmt
Definition: avconv_filter.c:68
Libavcodec external API header.
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:61
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut *inputs, AVFilterInOut *outputs, void *log_ctx)
Add a graph described by a string to a graph.
Definition: graphparser.c:451
Describe the class of an AVClass context structure.
Definition: log.h:33
Filter definition.
Definition: avfilter.h:421
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:221
int pad_idx
index of the filt_ctx pad to use for linking
Definition: avfilter.h:1099
rational number numerator/denominator
Definition: rational.h:43
struct AVFilter * next
Used by the filter registration system.
Definition: avfilter.h:552
AVMediaType
Definition: avutil.h:185
const char * name
Filter name.
Definition: avfilter.h:425
AVPictureType
Definition: avutil.h:252
unsigned nb_filters
Definition: avfilter.h:948
const char * avfilter_configuration(void)
Return the libavfilter build-time configuration.
Definition: avfilter.c:43
const char * avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
Get the name of an AVFilterPad.
Definition: avfilter.c:713
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
char * name
unique name for this input/output in the list
Definition: avfilter.h:1093
#define attribute_deprecated
Definition: attributes.h:80
int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options.
Definition: avfilter.c:561
int height
Definition: gxfenc.c:72
void * opaque
Opaque user data.
Definition: avfilter.h:988
AVFilterInOut * avfilter_inout_alloc(void)
Allocate a single AVFilterInOut entry.
Definition: graphparser.c:174
rational numbers
AVFilterBufferRef * avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms, int w, int h, enum AVPixelFormat format)
Definition: video.c:59
pixel format definitions
const char * description
A description of the filter.
Definition: avfilter.h:432
int avfilter_register(AVFilter *filter)
Register a filter.
Definition: avfilter.c:292
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
const AVClass * av_class
needed for av_log()
Definition: avfilter.h:564
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:563
int avfilter_pad_count(const AVFilterPad *pads)
Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
Definition: avfilter.c:318
const AVFilterPad * outputs
List of outputs, terminated by a zeroed element.
Definition: avfilter.h:449
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:111
AVFilterContext * avfilter_graph_get_filter(AVFilterGraph *graph, char *name)
Get a filter instance with name name from graph.
int needs_fifo
The filter expects a fifo to be inserted on its input link, typically because it has a delay...
Definition: internal.h:119
started, but incomplete
Definition: avfilter.h:683
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:566