defaults.c

Go to the documentation of this file.
00001 /*
00002  * Filter layer - default implementations
00003  * copyright (c) 2007 Bobby Bingham
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "libavcodec/imgconvert.h"
00023 #include "avfilter.h"
00024 
00025 /* TODO: buffer pool.  see comment for avfilter_default_get_video_buffer() */
00026 void avfilter_default_free_video_buffer(AVFilterPic *pic)
00027 {
00028     av_free(pic->data[0]);
00029     av_free(pic);
00030 }
00031 
00032 #define ALIGN(a) do{ \
00033                      (a) = ((a) + 15) & (~15); \
00034                  } while(0);
00035 
00036 /* TODO: set the buffer's priv member to a context structure for the whole
00037  * filter chain.  This will allow for a buffer pool instead of the constant
00038  * alloc & free cycle currently implemented. */
00039 AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link, int perms)
00040 {
00041     AVFilterPic *pic = av_mallocz(sizeof(AVFilterPic));
00042     AVFilterPicRef *ref = av_mallocz(sizeof(AVFilterPicRef));
00043     int i, tempsize;
00044     char *buf;
00045 
00046     ref->pic   = pic;
00047     ref->w     = link->w;
00048     ref->h     = link->h;
00049 
00050     /* make sure the buffer gets read permission or it's useless for output */
00051     ref->perms = perms | AV_PERM_READ;
00052 
00053     pic->refcount = 1;
00054     pic->format   = link->format;
00055     pic->free     = avfilter_default_free_video_buffer;
00056     ff_fill_linesize((AVPicture *)pic, pic->format, ref->w);
00057 
00058     for (i=0; i<4;i++)
00059         ALIGN(pic->linesize[i]);
00060 
00061     tempsize = ff_fill_pointer((AVPicture *)pic, NULL, pic->format, ref->h);
00062     buf = av_malloc(tempsize);
00063     ff_fill_pointer((AVPicture *)pic, buf, pic->format, ref->h);
00064 
00065     memcpy(ref->data,     pic->data,     sizeof(pic->data));
00066     memcpy(ref->linesize, pic->linesize, sizeof(pic->linesize));
00067 
00068     return ref;
00069 }
00070 
00071 void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
00072 {
00073     AVFilterLink *out = NULL;
00074 
00075     if(link->dst->output_count)
00076         out = link->dst->outputs[0];
00077 
00078     if(out) {
00079         out->outpic      = avfilter_get_video_buffer(out, AV_PERM_WRITE);
00080         out->outpic->pts = picref->pts;
00081         avfilter_start_frame(out, avfilter_ref_pic(out->outpic, ~0));
00082     }
00083 }
00084 
00085 void avfilter_default_end_frame(AVFilterLink *link)
00086 {
00087     AVFilterLink *out = NULL;
00088 
00089     if(link->dst->output_count)
00090         out = link->dst->outputs[0];
00091 
00092     avfilter_unref_pic(link->cur_pic);
00093     link->cur_pic = NULL;
00094 
00095     if(out) {
00096         if(out->outpic) {
00097             avfilter_unref_pic(out->outpic);
00098             out->outpic = NULL;
00099         }
00100         avfilter_end_frame(out);
00101     }
00102 }
00103 
00104 /**
00105  * default config_link() implementation for output video links to simplify
00106  * the implementation of one input one output video filters */
00107 int avfilter_default_config_output_link(AVFilterLink *link)
00108 {
00109     if(link->src->input_count && link->src->inputs[0]) {
00110         link->w = link->src->inputs[0]->w;
00111         link->h = link->src->inputs[0]->h;
00112     } else {
00113         /* XXX: any non-simple filter which would cause this branch to be taken
00114          * really should implement its own config_props() for this link. */
00115         return -1;
00116     }
00117 
00118     return 0;
00119 }
00120 
00121 /**
00122  * A helper for query_formats() which sets all links to the same list of
00123  * formats. If there are no links hooked to this filter, the list of formats is
00124  * freed.
00125  *
00126  * FIXME: this will need changed for filters with a mix of pad types
00127  * (video + audio, etc)
00128  */
00129 void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
00130 {
00131     int count = 0, i;
00132 
00133     for(i = 0; i < ctx->input_count; i ++) {
00134         if(ctx->inputs[i]) {
00135             avfilter_formats_ref(formats, &ctx->inputs[i]->out_formats);
00136             count ++;
00137         }
00138     }
00139     for(i = 0; i < ctx->output_count; i ++) {
00140         if(ctx->outputs[i]) {
00141             avfilter_formats_ref(formats, &ctx->outputs[i]->in_formats);
00142             count ++;
00143         }
00144     }
00145 
00146     if(!count) {
00147         av_free(formats->formats);
00148         av_free(formats->refs);
00149         av_free(formats);
00150     }
00151 }
00152 
00153 int avfilter_default_query_formats(AVFilterContext *ctx)
00154 {
00155     avfilter_set_common_formats(ctx, avfilter_all_colorspaces());
00156     return 0;
00157 }
00158 

Generated on Fri Jan 9 12:44:26 2009 for libextractor by  doxygen 1.5.1