avfilter.c File Reference

#include "libavcodec/imgconvert.h"
#include "avfilter.h"

Go to the source code of this file.

Data Structures

struct  FilterList

Defines

#define link_dpad(link)   link->dst-> input_pads[link->dstpad]
#define link_spad(link)   link->src->output_pads[link->srcpad]

Functions

AVFilterPicRefavfilter_ref_pic (AVFilterPicRef *ref, int pmask)
void avfilter_unref_pic (AVFilterPicRef *ref)
void avfilter_insert_pad (unsigned idx, unsigned *count, size_t padidx_off, AVFilterPad **pads, AVFilterLink ***links, AVFilterPad *newpad)
int avfilter_link (AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
int avfilter_insert_filter (AVFilterLink *link, AVFilterContext *filt, unsigned in, unsigned out)
int avfilter_config_links (AVFilterContext *filter)
AVFilterPicRefavfilter_get_video_buffer (AVFilterLink *link, int perms)
int avfilter_request_frame (AVFilterLink *link)
int avfilter_poll_frame (AVFilterLink *link)
void avfilter_start_frame (AVFilterLink *link, AVFilterPicRef *picref)
void avfilter_end_frame (AVFilterLink *link)
void avfilter_draw_slice (AVFilterLink *link, int y, int h)
AVFilteravfilter_get_by_name (const char *name)
void avfilter_register (AVFilter *filter)
void avfilter_uninit (void)
static int pad_count (const AVFilterPad *pads)
static const char * filter_name (void *p)
AVFilterContextavfilter_open (AVFilter *filter, const char *inst_name)
void avfilter_destroy (AVFilterContext *filter)
int avfilter_init_filter (AVFilterContext *filter, const char *args, void *opaque)

Variables

FilterListfilters
static const AVClass avfilter_class


Define Documentation

#define link_dpad ( link   )     link->dst-> input_pads[link->dstpad]

helper macros to get the in/out pad on the dst/src filter

Definition at line 33 of file avfilter.c.

Referenced by avfilter_config_links(), avfilter_end_frame(), avfilter_get_video_buffer(), and avfilter_start_frame().

#define link_spad ( link   )     link->src->output_pads[link->srcpad]

Definition at line 34 of file avfilter.c.

Referenced by avfilter_config_links(), avfilter_poll_frame(), and avfilter_request_frame().


Function Documentation

int avfilter_config_links ( AVFilterContext filter  ) 

Negotiate the colorspace, dimensions, etc of all inputs to a filter.

Parameters:
filter the filter to negotiate the properties for its inputs
Returns:
zero on successful negotiation

Definition at line 121 of file avfilter.c.

References av_log(), AV_LOG_INFO, avfilter_config_links(), avfilter_default_config_output_link(), filter(), link_dpad, and link_spad.

Referenced by avfilter_config_links().

00122 {
00123     int (*config_link)(AVFilterLink *);
00124     unsigned i;
00125 
00126     for(i = 0; i < filter->input_count; i ++) {
00127         AVFilterLink *link = filter->inputs[i];
00128 
00129         if(!link) continue;
00130 
00131         switch(link->init_state) {
00132         case AVLINK_INIT:
00133             continue;
00134         case AVLINK_STARTINIT:
00135             av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
00136             return 0;
00137         case AVLINK_UNINIT:
00138             link->init_state = AVLINK_STARTINIT;
00139 
00140             if(avfilter_config_links(link->src))
00141                 return -1;
00142 
00143             if(!(config_link = link_spad(link).config_props))
00144                 config_link  = avfilter_default_config_output_link;
00145             if(config_link(link))
00146                 return -1;
00147 
00148             if((config_link = link_dpad(link).config_props))
00149                 if(config_link(link))
00150                     return -1;
00151 
00152             link->init_state = AVLINK_INIT;
00153         }
00154     }
00155 
00156     return 0;
00157 }

void avfilter_destroy ( AVFilterContext filter  ) 

Destroy a filter.

Parameters:
filter the filter to destroy

Definition at line 358 of file avfilter.c.

References av_free(), av_freep(), filter(), and NULL.

Referenced by avfilter_destroy_graph(), create_filter(), and query_formats().

00359 {
00360     int i;
00361 
00362     if(filter->filter->uninit)
00363         filter->filter->uninit(filter);
00364 
00365     for(i = 0; i < filter->input_count; i ++) {
00366         if(filter->inputs[i])
00367             filter->inputs[i]->src->outputs[filter->inputs[i]->srcpad] = NULL;
00368         av_freep(&filter->inputs[i]);
00369     }
00370     for(i = 0; i < filter->output_count; i ++) {
00371         if(filter->outputs[i])
00372             filter->outputs[i]->dst->inputs[filter->outputs[i]->dstpad] = NULL;
00373         av_freep(&filter->outputs[i]);
00374     }
00375 
00376     av_freep(&filter->name);
00377     av_freep(&filter->input_pads);
00378     av_freep(&filter->output_pads);
00379     av_freep(&filter->inputs);
00380     av_freep(&filter->outputs);
00381     av_freep(&filter->priv);
00382     av_free(filter);
00383 }

void avfilter_draw_slice ( AVFilterLink link,
int  y,
int  h 
)

Send a slice to the next filter.

Parameters:
link the output link over which the frame is being sent
y offset in pixels from the top of the image for this slice
h height of this slice in pixels

Definition at line 245 of file avfilter.c.

References avcodec_get_chroma_sub_sample(), AVFilterLink::cur_pic, AVFilterPicRef::data, ff_get_plane_bytewidth(), AVFilterLink::format, AVFilterPicRef::linesize, NULL, src, AVFilterLink::srcpic, and AVFilterPicRef::w.

00246 {
00247     uint8_t *src[4], *dst[4];
00248     int i, j, hsub, vsub;
00249 
00250     /* copy the slice if needed for permission reasons */
00251     if(link->srcpic) {
00252         avcodec_get_chroma_sub_sample(link->format, &hsub, &vsub);
00253 
00254         for(i = 0; i < 4; i ++) {
00255             if(link->srcpic->data[i]) {
00256                 src[i] = link->srcpic-> data[i] +
00257                     (y >> (i==0 ? 0 : vsub)) * link->srcpic-> linesize[i];
00258                 dst[i] = link->cur_pic->data[i] +
00259                     (y >> (i==0 ? 0 : vsub)) * link->cur_pic->linesize[i];
00260             } else
00261                 src[i] = dst[i] = NULL;
00262         }
00263 
00264         for(i = 0; i < 4; i ++) {
00265             int planew =
00266                 ff_get_plane_bytewidth(link->format, link->cur_pic->w, i);
00267 
00268             if(!src[i]) continue;
00269 
00270             for(j = 0; j < h >> (i==0 ? 0 : vsub); j ++) {
00271                 memcpy(dst[i], src[i], planew);
00272                 src[i] += link->srcpic ->linesize[i];
00273                 dst[i] += link->cur_pic->linesize[i];
00274             }
00275         }
00276     }
00277 
00278     if(link_dpad(link).draw_slice)
00279         link_dpad(link).draw_slice(link, y, h);
00280 }

void avfilter_end_frame ( AVFilterLink link  ) 

Notify the next filter that the current frame has finished

Parameters:
link the output link the frame was sent over

Definition at line 227 of file avfilter.c.

References avfilter_default_end_frame(), avfilter_unref_pic(), link_dpad, NULL, and AVFilterLink::srcpic.

Referenced by avfilter_default_end_frame().

00228 {
00229     void (*end_frame)(AVFilterLink *);
00230 
00231     if(!(end_frame = link_dpad(link).end_frame))
00232         end_frame = avfilter_default_end_frame;
00233 
00234     end_frame(link);
00235 
00236     /* unreference the source picture if we're feeding the destination filter
00237      * a copied version dues to permission issues */
00238     if(link->srcpic) {
00239         avfilter_unref_pic(link->srcpic);
00240         link->srcpic = NULL;
00241     }
00242 
00243 }

AVFilter* avfilter_get_by_name ( const char *  name  ) 

Gets a filter definition matching the given name.

Parameters:
name the filter name to find
Returns:
the filter definition, if any matching one is registered. NULL if none found.

Definition at line 282 of file avfilter.c.

References FilterList::filter, filters, AVFilter::name, FilterList::next, and NULL.

Referenced by create_filter(), and query_formats().

00283 {
00284     struct FilterList *filt;
00285 
00286     for(filt = filters; filt; filt = filt->next)
00287         if(!strcmp(filt->filter->name, name))
00288             return filt->filter;
00289 
00290     return NULL;
00291 }

AVFilterPicRef* avfilter_get_video_buffer ( AVFilterLink link,
int  perms 
)

Request a picture buffer with a specific set of permissions

Parameters:
link the output link to the filter from which the picture will be requested
perms the required access permissions
Returns:
A reference to the picture. This must be unreferenced with avfilter_unref_pic when you are finished with it.

Definition at line 159 of file avfilter.c.

References avfilter_default_get_video_buffer(), link_dpad, and NULL.

Referenced by avfilter_default_start_frame().

00160 {
00161     AVFilterPicRef *ret = NULL;
00162 
00163     if(link_dpad(link).get_video_buffer)
00164         ret = link_dpad(link).get_video_buffer(link, perms);
00165 
00166     if(!ret)
00167         ret = avfilter_default_get_video_buffer(link, perms);
00168 
00169     return ret;
00170 }

int avfilter_init_filter ( AVFilterContext filter,
const char *  args,
void *  opaque 
)

Initialize a filter.

Parameters:
filter the filter to initialize
args A string of parameters to use when initializing the filter. The format and meaning of this string varies by filter.
opaque Any extra non-string data needed by the filter. The meaning of this parameter varies by filter.
Returns:
zero on success

Definition at line 385 of file avfilter.c.

References filter().

Referenced by create_filter().

00386 {
00387     int ret=0;
00388 
00389     if(filter->filter->init)
00390         ret = filter->filter->init(filter, args, opaque);
00391     return ret;
00392 }

int avfilter_insert_filter ( AVFilterLink link,
AVFilterContext filt,
unsigned  in,
unsigned  out 
)

Insert a filter in the middle of an existing link.

Parameters:
link the link into which the filter should be inserted
filt the filter to be inserted
in the input pad on the filter to connect
out the output pad on the filter to connect
Returns:
zero on success

Definition at line 94 of file avfilter.c.

References av_log(), AV_LOG_INFO, avfilter_formats_changeref(), avfilter_link(), AVFilterLink::dst, AVFilterLink::dstpad, AVFilterContext::filter, AVFilterContext::inputs, AVFilter::name, NULL, AVFilterLink::out_formats, and AVFilterContext::outputs.

Referenced by query_formats().

00096 {
00097     av_log(link->dst, AV_LOG_INFO, "auto-inserting filter '%s'\n",
00098             filt->filter->name);
00099 
00100     link->dst->inputs[link->dstpad] = NULL;
00101     if(avfilter_link(filt, out, link->dst, link->dstpad)) {
00102         /* failed to link output filter to new filter */
00103         link->dst->inputs[link->dstpad] = link;
00104         return -1;
00105     }
00106 
00107     /* re-hookup the link to the new destination filter we inserted */
00108     link->dst = filt;
00109     link->dstpad = in;
00110     filt->inputs[in] = link;
00111 
00112     /* if any information on supported colorspaces already exists on the
00113      * link, we need to preserve that */
00114     if(link->out_formats)
00115         avfilter_formats_changeref(&link->out_formats,
00116                                    &filt->outputs[out]->out_formats);
00117 
00118     return 0;
00119 }

void avfilter_insert_pad ( unsigned  idx,
unsigned *  count,
size_t  padidx_off,
AVFilterPad **  pads,
AVFilterLink ***  links,
AVFilterPad newpad 
)

Insert a new pad.

Parameters:
idx Insertion point. Pad is inserted at the end if this point is beyond the end of the list of pads.
count Pointer to the number of pads in the list
padidx_off Offset within an AVFilterLink structure to the element to increment when inserting a new pad causes link numbering to change
pads Pointer to the pointer to the beginning of the list of pads
links Pointer to the pointer to the beginning of the list of links
newpad The new pad to add. A copy is made when adding.

Definition at line 52 of file avfilter.c.

References av_realloc(), FFMIN, and NULL.

Referenced by avfilter_insert_inpad(), and avfilter_insert_outpad().

00055 {
00056     unsigned i;
00057 
00058     idx = FFMIN(idx, *count);
00059 
00060     *pads  = av_realloc(*pads,  sizeof(AVFilterPad)   * (*count + 1));
00061     *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1));
00062     memmove(*pads +idx+1, *pads +idx, sizeof(AVFilterPad)   * (*count-idx));
00063     memmove(*links+idx+1, *links+idx, sizeof(AVFilterLink*) * (*count-idx));
00064     memcpy(*pads+idx, newpad, sizeof(AVFilterPad));
00065     (*links)[idx] = NULL;
00066 
00067     (*count) ++;
00068     for(i = idx+1; i < *count; i ++)
00069         if(*links[i])
00070             (*(unsigned *)((uint8_t *) *links[i] + padidx_off)) ++;
00071 }

int avfilter_link ( AVFilterContext src,
unsigned  srcpad,
AVFilterContext dst,
unsigned  dstpad 
)

Link two filters together.

Parameters:
src the source filter
srcpad index of the output pad on the source filter
dst the destination filter
dstpad index of the input pad on the destination filter
Returns:
zero on success

Definition at line 73 of file avfilter.c.

References av_mallocz(), AVFilterLink::dst, AVFilterLink::dstpad, AVFilterLink::format, AVFilterContext::input_count, AVFilterContext::inputs, src, AVFilterLink::src, and AVFilterLink::srcpad.

Referenced by avfilter_insert_filter(), and link_filter().

00075 {
00076     AVFilterLink *link;
00077 
00078     if(src->output_count <= srcpad || dst->input_count <= dstpad ||
00079        src->outputs[srcpad]        || dst->inputs[dstpad])
00080         return -1;
00081 
00082     src->outputs[srcpad] =
00083     dst-> inputs[dstpad] = link = av_mallocz(sizeof(AVFilterLink));
00084 
00085     link->src     = src;
00086     link->dst     = dst;
00087     link->srcpad  = srcpad;
00088     link->dstpad  = dstpad;
00089     link->format  = -1;
00090 
00091     return 0;
00092 }

AVFilterContext* avfilter_open ( AVFilter filter,
const char *  inst_name 
)

Create a filter instance.

Parameters:
filter the filter to create an instance of
inst_name Name to give to the new instance. Can be NULL for none.
Returns:
Pointer to the new instance on success. NULL on failure.

Definition at line 331 of file avfilter.c.

References AVFilterContext::av_class, av_malloc(), av_mallocz(), av_strdup(), avfilter_class, filter(), AVFilterContext::filter, AVFilterContext::input_count, AVFilterContext::input_pads, AVFilterContext::inputs, AVFilterContext::name, NULL, AVFilterContext::output_count, AVFilterContext::output_pads, AVFilterContext::outputs, pad_count(), and AVFilterContext::priv.

Referenced by create_filter(), and query_formats().

00332 {
00333     AVFilterContext *ret;
00334 
00335     if (!filter)
00336         return 0;
00337 
00338     ret = av_malloc(sizeof(AVFilterContext));
00339 
00340     ret->av_class = &avfilter_class;
00341     ret->filter   = filter;
00342     ret->name     = inst_name ? av_strdup(inst_name) : NULL;
00343     ret->priv     = av_mallocz(filter->priv_size);
00344 
00345     ret->input_count  = pad_count(filter->inputs);
00346     ret->input_pads   = av_malloc(sizeof(AVFilterPad) * ret->input_count);
00347     memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad)*ret->input_count);
00348     ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
00349 
00350     ret->output_count = pad_count(filter->outputs);
00351     ret->output_pads  = av_malloc(sizeof(AVFilterPad) * ret->output_count);
00352     memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad)*ret->output_count);
00353     ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
00354 
00355     return ret;
00356 }

int avfilter_poll_frame ( AVFilterLink link  ) 

Poll a frame from the filter chain.

Parameters:
link the input link
Returns:
the number of imediately available frames

Definition at line 181 of file avfilter.c.

References avfilter_poll_frame(), FFMIN, link_spad, and min.

Referenced by avfilter_poll_frame().

00182 {
00183     int i, min=INT_MAX;
00184 
00185     if(link_spad(link).poll_frame)
00186         return link_spad(link).poll_frame(link);
00187 
00188     for (i=0; i<link->src->input_count; i++) {
00189         if(!link->src->inputs[i])
00190             return -1;
00191         min = FFMIN(min, avfilter_poll_frame(link->src->inputs[i]));
00192     }
00193 
00194     return min;
00195 }

AVFilterPicRef* avfilter_ref_pic ( AVFilterPicRef ref,
int  pmask 
)

Add a new reference to a picture.

Parameters:
ref an existing reference to the picture
pmask a bitmask containing the allowable permissions in the new reference
Returns:
a new reference to the picture with the same properties as the old, excluding any permissions denied by pmask

Definition at line 36 of file avfilter.c.

References av_malloc(), AVFilterPicRef::perms, AVFilterPicRef::pic, and AVFilterPic::refcount.

Referenced by avfilter_default_start_frame().

00037 {
00038     AVFilterPicRef *ret = av_malloc(sizeof(AVFilterPicRef));
00039     *ret = *ref;
00040     ret->perms &= pmask;
00041     ret->pic->refcount ++;
00042     return ret;
00043 }

void avfilter_register ( AVFilter filter  ) 

Register a filter. This is only needed if you plan to use avfilter_get_by_name later to lookup the AVFilter structure by name. A filter can still by instantiated with avfilter_open even if it is not registered.

Parameters:
filter the filter to register

Definition at line 293 of file avfilter.c.

References av_malloc(), FilterList::filter, filter(), filters, and FilterList::next.

00294 {
00295     struct FilterList *newfilt = av_malloc(sizeof(struct FilterList));
00296 
00297     newfilt->filter = filter;
00298     newfilt->next   = filters;
00299     filters         = newfilt;
00300 }

int avfilter_request_frame ( AVFilterLink link  ) 

Request an input frame from the filter at the other end of the link.

Parameters:
link the input link
Returns:
zero on success

Definition at line 172 of file avfilter.c.

References avfilter_request_frame(), and link_spad.

Referenced by avfilter_request_frame().

00173 {
00174     if(link_spad(link).request_frame)
00175         return link_spad(link).request_frame(link);
00176     else if(link->src->inputs[0])
00177         return avfilter_request_frame(link->src->inputs[0]);
00178     else return -1;
00179 }

void avfilter_start_frame ( AVFilterLink link,
AVFilterPicRef picref 
)

Notify the next filter of the start of a frame.

Parameters:
link the output link the frame will be sent over
picref A reference to the frame about to be sent. The data for this frame need only be valid once draw_slice() is called for that portion. The receiving filter will free this reference when it no longer needs it.

Definition at line 199 of file avfilter.c.

References avfilter_default_get_video_buffer(), avfilter_default_start_frame(), AVFilterLink::cur_pic, link_dpad, AVFilterPad::min_perms, AVFilterPicRef::perms, AVFilterPicRef::pts, AVFilterPad::rej_perms, AVFilterLink::srcpic, and AVFilterPad::start_frame.

Referenced by avfilter_default_start_frame().

00200 {
00201     void (*start_frame)(AVFilterLink *, AVFilterPicRef *);
00202     AVFilterPad *dst = &link_dpad(link);
00203 
00204     if(!(start_frame = dst->start_frame))
00205         start_frame = avfilter_default_start_frame;
00206 
00207     /* prepare to copy the picture if it has insufficient permissions */
00208     if((dst->min_perms & picref->perms) != dst->min_perms ||
00209         dst->rej_perms & picref->perms) {
00210         /*
00211         av_log(link->dst, AV_LOG_INFO,
00212                 "frame copy needed (have perms %x, need %x, reject %x)\n",
00213                 picref->perms,
00214                 link_dpad(link).min_perms, link_dpad(link).rej_perms);
00215         */
00216 
00217         link->cur_pic = avfilter_default_get_video_buffer(link, dst->min_perms);
00218         link->srcpic = picref;
00219         link->cur_pic->pts = link->srcpic->pts;
00220     }
00221     else
00222         link->cur_pic = picref;
00223 
00224     start_frame(link, link->cur_pic);
00225 }

void avfilter_uninit ( void   ) 

Uninitialize the filter system. Unregisters all filters

Definition at line 302 of file avfilter.c.

References av_free(), filters, and FilterList::next.

00303 {
00304     struct FilterList *tmp;
00305 
00306     for(; filters; filters = tmp) {
00307         tmp = filters->next;
00308         av_free(filters);
00309     }
00310 }

void avfilter_unref_pic ( AVFilterPicRef ref  ) 

Remove a reference to a picture. If this is the last reference to the picture, the picture itself is also automatically freed.

Parameters:
ref reference to the picture

Definition at line 45 of file avfilter.c.

References av_free(), AVFilterPic::free, AVFilterPicRef::pic, and AVFilterPic::refcount.

Referenced by avfilter_default_end_frame(), and avfilter_end_frame().

00046 {
00047     if(!(--ref->pic->refcount))
00048         ref->pic->free(ref->pic);
00049     av_free(ref);
00050 }

static const char* filter_name ( void *  p  )  [static]

Definition at line 320 of file avfilter.c.

References filter().

00321 {
00322     AVFilterContext *filter = p;
00323     return filter->filter->name;
00324 }

static int pad_count ( const AVFilterPad pads  )  [static]

Definition at line 312 of file avfilter.c.

References AVFilterPad::name.

Referenced by avfilter_open().

00313 {
00314     int count;
00315 
00316     for(count = 0; pads->name; count ++) pads ++;
00317     return count;
00318 }


Variable Documentation

const AVClass avfilter_class [static]

Initial value:

 {
    "AVFilter",
    filter_name
}

Definition at line 326 of file avfilter.c.

Referenced by avfilter_open().

struct FilterList * filters

list of registered filters

Referenced by avfilter_get_by_name(), avfilter_register(), avfilter_uninit(), pp_get_mode_by_name_and_quality(), and tta_decode_frame().


Generated on Wed Jan 7 05:44:47 2009 for libextractor by  doxygen 1.5.1