00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef AVFILTER_AVFILTER_H
00023 #define AVFILTER_AVFILTER_H
00024
00025 #include "libavutil/avutil.h"
00026 #include "libavutil/log.h"
00027 #include "libavutil/samplefmt.h"
00028 #include "libavutil/pixfmt.h"
00029 #include "libavutil/rational.h"
00030 #include "libavcodec/avcodec.h"
00031
00032
00033 #ifndef FF_API_OLD_VSINK_API
00034 #define FF_API_OLD_VSINK_API (LIBAVFILTER_VERSION_MAJOR < 3)
00035 #endif
00036 #ifndef FF_API_OLD_ALL_FORMATS_API
00037 #define FF_API_OLD_ALL_FORMATS_API (LIBAVFILTER_VERSION_MAJOR < 3)
00038 #endif
00039
00040 #include <stddef.h>
00041
00042 #include "libavfilter/version.h"
00043
00047 unsigned avfilter_version(void);
00048
00052 const char *avfilter_configuration(void);
00053
00057 const char *avfilter_license(void);
00058
00059
00060 typedef struct AVFilterContext AVFilterContext;
00061 typedef struct AVFilterLink AVFilterLink;
00062 typedef struct AVFilterPad AVFilterPad;
00063
00069 typedef struct AVFilterBuffer {
00070 uint8_t *data[8];
00071 int linesize[8];
00072
00073 unsigned refcount;
00074
00076 void *priv;
00083 void (*free)(struct AVFilterBuffer *buf);
00084
00085 int format;
00086 int w, h;
00087 } AVFilterBuffer;
00088
00089 #define AV_PERM_READ 0x01
00090 #define AV_PERM_WRITE 0x02
00091 #define AV_PERM_PRESERVE 0x04
00092 #define AV_PERM_REUSE 0x08
00093 #define AV_PERM_REUSE2 0x10
00094 #define AV_PERM_NEG_LINESIZES 0x20
00095 #define AV_PERM_ALIGN 0x40
00096
00097 #define AVFILTER_ALIGN 16 //not part of ABI
00098
00104 typedef struct AVFilterBufferRefAudioProps {
00105 uint64_t channel_layout;
00106 int nb_samples;
00107 int sample_rate;
00108 int planar;
00109 } AVFilterBufferRefAudioProps;
00110
00116 typedef struct AVFilterBufferRefVideoProps {
00117 int w;
00118 int h;
00119 AVRational sample_aspect_ratio;
00120 int interlaced;
00121 int top_field_first;
00122 enum AVPictureType pict_type;
00123 int key_frame;
00124 } AVFilterBufferRefVideoProps;
00125
00134 typedef struct AVFilterBufferRef {
00135 AVFilterBuffer *buf;
00136 uint8_t *data[8];
00137 int linesize[8];
00138 int format;
00139
00145 int64_t pts;
00146 int64_t pos;
00147
00148 int perms;
00149
00150 enum AVMediaType type;
00151 AVFilterBufferRefVideoProps *video;
00152 AVFilterBufferRefAudioProps *audio;
00153 } AVFilterBufferRef;
00154
00158 static inline void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
00159 {
00160
00161 dst->pts = src->pts;
00162 dst->pos = src->pos;
00163
00164 switch (src->type) {
00165 case AVMEDIA_TYPE_VIDEO: *dst->video = *src->video; break;
00166 case AVMEDIA_TYPE_AUDIO: *dst->audio = *src->audio; break;
00167 default: break;
00168 }
00169 }
00170
00180 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
00181
00188 void avfilter_unref_buffer(AVFilterBufferRef *ref);
00189
00230 typedef struct AVFilterFormats {
00231 unsigned format_count;
00232 int64_t *formats;
00233
00234 unsigned refcount;
00235 struct AVFilterFormats ***refs;
00236 } AVFilterFormats;
00237
00246 AVFilterFormats *avfilter_make_format_list(const int *fmts);
00247 AVFilterFormats *avfilter_make_format64_list(const int64_t *fmts);
00248
00257 int avfilter_add_format(AVFilterFormats **avff, int64_t fmt);
00258
00259 #if FF_API_OLD_ALL_FORMATS_API
00260
00263 attribute_deprecated
00264 AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
00265 #endif
00266
00270 AVFilterFormats *avfilter_make_all_formats(enum AVMediaType type);
00271
00275 extern const int64_t avfilter_all_channel_layouts[];
00276
00280 AVFilterFormats *avfilter_make_all_channel_layouts(void);
00281
00285 AVFilterFormats *avfilter_make_all_packing_formats(void);
00286
00295 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
00296
00309 void avfilter_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
00310
00326 void avfilter_formats_unref(AVFilterFormats **ref);
00327
00341 void avfilter_formats_changeref(AVFilterFormats **oldref,
00342 AVFilterFormats **newref);
00343
00347 struct AVFilterPad {
00353 const char *name;
00354
00358 enum AVMediaType type;
00359
00367 int min_perms;
00368
00378 int rej_perms;
00379
00387 void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
00388
00395 AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
00396
00403 AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms, int nb_samples);
00404
00412 void (*end_frame)(AVFilterLink *link);
00413
00420 void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
00421
00428 void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
00429
00439 int (*poll_frame)(AVFilterLink *link);
00440
00448 int (*request_frame)(AVFilterLink *link);
00449
00467 int (*config_props)(AVFilterLink *link);
00468 };
00469
00471 void avfilter_default_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
00472
00474 void avfilter_default_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
00475
00477 void avfilter_default_end_frame(AVFilterLink *link);
00478
00480 void avfilter_default_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
00481
00483 AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
00484 int perms, int w, int h);
00485
00487 AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link,
00488 int perms, int nb_samples);
00489
00495 void avfilter_set_common_pixel_formats(AVFilterContext *ctx, AVFilterFormats *formats);
00496 void avfilter_set_common_sample_formats(AVFilterContext *ctx, AVFilterFormats *formats);
00497 void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *formats);
00498 void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats);
00499
00501 int avfilter_default_query_formats(AVFilterContext *ctx);
00502
00504 void avfilter_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
00505
00507 void avfilter_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
00508
00510 void avfilter_null_end_frame(AVFilterLink *link);
00511
00513 void avfilter_null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
00514
00516 AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
00517 int perms, int w, int h);
00518
00520 AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link,
00521 int perms, int nb_samples);
00522
00527 typedef struct AVFilter {
00528 const char *name;
00529
00530 int priv_size;
00531
00538 int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
00539
00545 void (*uninit)(AVFilterContext *ctx);
00546
00555 int (*query_formats)(AVFilterContext *);
00556
00557 const AVFilterPad *inputs;
00558 const AVFilterPad *outputs;
00559
00564 const char *description;
00565
00578 int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
00579 } AVFilter;
00580
00582 struct AVFilterContext {
00583 const AVClass *av_class;
00584
00585 AVFilter *filter;
00586
00587 char *name;
00588
00589 unsigned input_count;
00590 AVFilterPad *input_pads;
00591 AVFilterLink **inputs;
00592
00593 unsigned output_count;
00594 AVFilterPad *output_pads;
00595 AVFilterLink **outputs;
00596
00597 void *priv;
00598
00599 struct AVFilterCommand *command_queue;
00600 };
00601
00602 enum AVFilterPacking {
00603 AVFILTER_PACKED = 0,
00604 AVFILTER_PLANAR,
00605 };
00606
00614 struct AVFilterLink {
00615 AVFilterContext *src;
00616 AVFilterPad *srcpad;
00617
00618 AVFilterContext *dst;
00619 AVFilterPad *dstpad;
00620
00622 enum {
00623 AVLINK_UNINIT = 0,
00624 AVLINK_STARTINIT,
00625 AVLINK_INIT
00626 } init_state;
00627
00628 enum AVMediaType type;
00629
00630
00631 int w;
00632 int h;
00633 AVRational sample_aspect_ratio;
00634
00635 uint64_t channel_layout;
00636 #if LIBAVFILTER_VERSION_MAJOR < 3
00637 int64_t sample_rate;
00638 #else
00639 int sample_rate;
00640 #endif
00641 int planar;
00642
00643 int format;
00644
00652 AVFilterFormats *in_formats;
00653 AVFilterFormats *out_formats;
00654
00655 AVFilterFormats *in_chlayouts;
00656 AVFilterFormats *out_chlayouts;
00657 AVFilterFormats *in_packing;
00658 AVFilterFormats *out_packing;
00659
00667 AVFilterBufferRef *src_buf;
00668
00669 AVFilterBufferRef *cur_buf;
00670 AVFilterBufferRef *out_buf;
00671
00679 AVRational time_base;
00680
00681 struct AVFilterPool *pool;
00682 };
00683
00693 int avfilter_link(AVFilterContext *src, unsigned srcpad,
00694 AVFilterContext *dst, unsigned dstpad);
00695
00699 void avfilter_link_free(AVFilterLink **link);
00700
00707 int avfilter_config_links(AVFilterContext *filter);
00708
00720 AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
00721 int w, int h);
00722
00734 AVFilterBufferRef *
00735 avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
00736 int w, int h, enum PixelFormat format);
00737
00748 AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
00749 int nb_samples);
00750
00763 AVFilterBufferRef *
00764 avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms,
00765 int nb_samples, enum AVSampleFormat sample_fmt,
00766 uint64_t channel_layout, int planar);
00773 int avfilter_request_frame(AVFilterLink *link);
00774
00782 int avfilter_poll_frame(AVFilterLink *link);
00783
00793 void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
00794
00800 void avfilter_end_frame(AVFilterLink *link);
00801
00817 void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
00818
00819 #define AVFILTER_CMD_FLAG_ONE 1
00820 #define AVFILTER_CMD_FLAG_FAST 2
00821
00822
00826 int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
00827
00836 void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
00837
00839 void avfilter_register_all(void);
00840
00842 void avfilter_uninit(void);
00843
00854 int avfilter_register(AVFilter *filter);
00855
00863 AVFilter *avfilter_get_by_name(const char *name);
00864
00871 AVFilter **av_filter_next(AVFilter **filter);
00872
00882 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
00883
00894 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
00895
00901 void avfilter_free(AVFilterContext *filter);
00902
00912 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
00913 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
00914
00928 void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
00929 AVFilterPad **pads, AVFilterLink ***links,
00930 AVFilterPad *newpad);
00931
00933 static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
00934 AVFilterPad *p)
00935 {
00936 avfilter_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad),
00937 &f->input_pads, &f->inputs, p);
00938 }
00939
00941 static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
00942 AVFilterPad *p)
00943 {
00944 avfilter_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad),
00945 &f->output_pads, &f->outputs, p);
00946 }
00947
00948 #endif