Libav 0.7.1
libavfilter/avfilter.h
Go to the documentation of this file.
00001 /*
00002  * filter layer
00003  * Copyright (c) 2007 Bobby Bingham
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #ifndef AVFILTER_AVFILTER_H
00023 #define AVFILTER_AVFILTER_H
00024 
00025 #include "libavutil/avutil.h"
00026 #include "libavutil/samplefmt.h"
00027 
00028 #define LIBAVFILTER_VERSION_MAJOR  2
00029 #define LIBAVFILTER_VERSION_MINOR  4
00030 #define LIBAVFILTER_VERSION_MICRO  0
00031 
00032 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
00033                                                LIBAVFILTER_VERSION_MINOR, \
00034                                                LIBAVFILTER_VERSION_MICRO)
00035 #define LIBAVFILTER_VERSION     AV_VERSION(LIBAVFILTER_VERSION_MAJOR,   \
00036                                            LIBAVFILTER_VERSION_MINOR,   \
00037                                            LIBAVFILTER_VERSION_MICRO)
00038 #define LIBAVFILTER_BUILD       LIBAVFILTER_VERSION_INT
00039 
00040 #include <stddef.h>
00041 
00045 unsigned avfilter_version(void);
00046 
00050 const char *avfilter_configuration(void);
00051 
00055 const char *avfilter_license(void);
00056 
00057 
00058 typedef struct AVFilterContext AVFilterContext;
00059 typedef struct AVFilterLink    AVFilterLink;
00060 typedef struct AVFilterPad     AVFilterPad;
00061 
00067 typedef struct AVFilterBuffer {
00068     uint8_t *data[8];           
00069     int linesize[8];            
00070 
00071     unsigned refcount;          
00072 
00074     void *priv;
00081     void (*free)(struct AVFilterBuffer *buf);
00082 
00083     int format;                 
00084     int w, h;                   
00085 } AVFilterBuffer;
00086 
00087 #define AV_PERM_READ     0x01   ///< can read from the buffer
00088 #define AV_PERM_WRITE    0x02   ///< can write to the buffer
00089 #define AV_PERM_PRESERVE 0x04   ///< nobody else can overwrite the buffer
00090 #define AV_PERM_REUSE    0x08   ///< can output the buffer multiple times, with the same contents each time
00091 #define AV_PERM_REUSE2   0x10   ///< can output the buffer multiple times, modified each time
00092 #define AV_PERM_NEG_LINESIZES 0x20  ///< the buffer requested can have negative linesizes
00093 
00099 typedef struct AVFilterBufferRefAudioProps {
00100     int64_t channel_layout;     
00101     int nb_samples;             
00102     int size;                   
00103     uint32_t sample_rate;       
00104     int planar;                 
00105 } AVFilterBufferRefAudioProps;
00106 
00112 typedef struct AVFilterBufferRefVideoProps {
00113     int w;                      
00114     int h;                      
00115     AVRational pixel_aspect;    
00116     int interlaced;             
00117     int top_field_first;        
00118     enum AVPictureType pict_type; 
00119     int key_frame;              
00120 } AVFilterBufferRefVideoProps;
00121 
00130 typedef struct AVFilterBufferRef {
00131     AVFilterBuffer *buf;        
00132     uint8_t *data[8];           
00133     int linesize[8];            
00134     int format;                 
00135 
00141     int64_t pts;
00142     int64_t pos;                
00143 
00144     int perms;                  
00145 
00146     enum AVMediaType type;      
00147     AVFilterBufferRefVideoProps *video; 
00148     AVFilterBufferRefAudioProps *audio; 
00149 } AVFilterBufferRef;
00150 
00154 static inline void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
00155 {
00156     // copy common properties
00157     dst->pts             = src->pts;
00158     dst->pos             = src->pos;
00159 
00160     switch (src->type) {
00161     case AVMEDIA_TYPE_VIDEO: *dst->video = *src->video; break;
00162     case AVMEDIA_TYPE_AUDIO: *dst->audio = *src->audio; break;
00163     }
00164 }
00165 
00175 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
00176 
00183 void avfilter_unref_buffer(AVFilterBufferRef *ref);
00184 
00225 typedef struct AVFilterFormats {
00226     unsigned format_count;      
00227     int *formats;               
00228 
00229     unsigned refcount;          
00230     struct AVFilterFormats ***refs; 
00231 }  AVFilterFormats;
00232 
00240 AVFilterFormats *avfilter_make_format_list(const int *fmts);
00241 
00250 int avfilter_add_format(AVFilterFormats **avff, int fmt);
00251 
00255 AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
00256 
00265 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
00266 
00279 void avfilter_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
00280 
00296 void avfilter_formats_unref(AVFilterFormats **ref);
00297 
00311 void avfilter_formats_changeref(AVFilterFormats **oldref,
00312                                 AVFilterFormats **newref);
00313 
00317 struct AVFilterPad {
00323     const char *name;
00324 
00329     enum AVMediaType type;
00330 
00338     int min_perms;
00339 
00349     int rej_perms;
00350 
00358     void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
00359 
00366     AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
00367 
00374     AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
00375                                            enum AVSampleFormat sample_fmt, int size,
00376                                            int64_t channel_layout, int planar);
00377 
00385     void (*end_frame)(AVFilterLink *link);
00386 
00393     void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
00394 
00401     void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
00402 
00412     int (*poll_frame)(AVFilterLink *link);
00413 
00421     int (*request_frame)(AVFilterLink *link);
00422 
00437     int (*config_props)(AVFilterLink *link);
00438 };
00439 
00441 void avfilter_default_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
00442 
00444 void avfilter_default_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
00445 
00447 void avfilter_default_end_frame(AVFilterLink *link);
00448 
00450 void avfilter_default_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
00451 
00453 int avfilter_default_config_output_link(AVFilterLink *link);
00454 
00456 int avfilter_default_config_input_link (AVFilterLink *link);
00457 
00459 AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
00460                                                      int perms, int w, int h);
00461 
00463 AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,
00464                                                      enum AVSampleFormat sample_fmt, int size,
00465                                                      int64_t channel_layout, int planar);
00466 
00472 void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats);
00473 
00475 int avfilter_default_query_formats(AVFilterContext *ctx);
00476 
00478 void avfilter_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
00479 
00481 void avfilter_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
00482 
00484 void avfilter_null_end_frame(AVFilterLink *link);
00485 
00487 void avfilter_null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
00488 
00490 AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
00491                                                   int perms, int w, int h);
00492 
00494 AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link, int perms,
00495                                                   enum AVSampleFormat sample_fmt, int size,
00496                                                   int64_t channel_layout, int planar);
00497 
00502 typedef struct AVFilter {
00503     const char *name;         
00504 
00505     int priv_size;      
00506 
00513     int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
00514 
00520     void (*uninit)(AVFilterContext *ctx);
00521 
00530     int (*query_formats)(AVFilterContext *);
00531 
00532     const AVFilterPad *inputs;  
00533     const AVFilterPad *outputs; 
00534 
00539     const char *description;
00540 } AVFilter;
00541 
00543 struct AVFilterContext {
00544     const AVClass *av_class;              
00545 
00546     AVFilter *filter;               
00547 
00548     char *name;                     
00549 
00550     unsigned input_count;           
00551     AVFilterPad   *input_pads;      
00552     AVFilterLink **inputs;          
00553 
00554     unsigned output_count;          
00555     AVFilterPad   *output_pads;     
00556     AVFilterLink **outputs;         
00557 
00558     void *priv;                     
00559 };
00560 
00568 struct AVFilterLink {
00569     AVFilterContext *src;       
00570     AVFilterPad *srcpad;        
00571 
00572     AVFilterContext *dst;       
00573     AVFilterPad *dstpad;        
00574 
00576     enum {
00577         AVLINK_UNINIT = 0,      
00578         AVLINK_STARTINIT,       
00579         AVLINK_INIT             
00580     } init_state;
00581 
00582     enum AVMediaType type;      
00583 
00584     /* These parameters apply only to video */
00585     int w;                      
00586     int h;                      
00587     AVRational sample_aspect_ratio; 
00588     /* These two parameters apply only to audio */
00589     int64_t channel_layout;     
00590     int64_t sample_rate;        
00591 
00592     int format;                 
00593 
00599     AVFilterFormats *in_formats;
00600     AVFilterFormats *out_formats;
00601 
00609     AVFilterBufferRef *src_buf;
00610 
00611     AVFilterBufferRef *cur_buf;
00612     AVFilterBufferRef *out_buf;
00613 
00621     AVRational time_base;
00622 };
00623 
00633 int avfilter_link(AVFilterContext *src, unsigned srcpad,
00634                   AVFilterContext *dst, unsigned dstpad);
00635 
00642 int avfilter_config_links(AVFilterContext *filter);
00643 
00655 AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
00656                                           int w, int h);
00657 
00669 AVFilterBufferRef *
00670 avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
00671                                           int w, int h, enum PixelFormat format);
00672 
00686 AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
00687                                              enum AVSampleFormat sample_fmt, int size,
00688                                              int64_t channel_layout, int planar);
00689 
00696 int avfilter_request_frame(AVFilterLink *link);
00697 
00705 int avfilter_poll_frame(AVFilterLink *link);
00706 
00716 void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
00717 
00723 void avfilter_end_frame(AVFilterLink *link);
00724 
00740 void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
00741 
00750 void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
00751 
00753 void avfilter_register_all(void);
00754 
00756 void avfilter_uninit(void);
00757 
00768 int avfilter_register(AVFilter *filter);
00769 
00777 AVFilter *avfilter_get_by_name(const char *name);
00778 
00785 AVFilter **av_filter_next(AVFilter **filter);
00786 
00796 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
00797 
00808 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
00809 
00815 void avfilter_free(AVFilterContext *filter);
00816 
00826 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
00827                            unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
00828 
00842 void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
00843                          AVFilterPad **pads, AVFilterLink ***links,
00844                          AVFilterPad *newpad);
00845 
00847 static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
00848                                          AVFilterPad *p)
00849 {
00850     avfilter_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad),
00851                         &f->input_pads, &f->inputs, p);
00852 }
00853 
00855 static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
00856                                           AVFilterPad *p)
00857 {
00858     avfilter_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad),
00859                         &f->output_pads, &f->outputs, p);
00860 }
00861 
00862 #endif /* AVFILTER_AVFILTER_H */