libavfilter/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_draw_slice(AVFilterLink *link, int y, int h)
00086 {
00087 AVFilterLink *out = NULL;
00088 
00089 if(link->dst->output_count)
00090 out = link->dst->outputs[0];
00091 
00092 if(out)
00093 avfilter_draw_slice(out, y, h);
00094 }
00095 
00096 void avfilter_default_end_frame(AVFilterLink *link)
00097 {
00098 AVFilterLink *out = NULL;
00099 
00100 if(link->dst->output_count)
00101 out = link->dst->outputs[0];
00102 
00103 avfilter_unref_pic(link->cur_pic);
00104 link->cur_pic = NULL;
00105 
00106 if(out) {
00107 if(out->outpic) {
00108 avfilter_unref_pic(out->outpic);
00109 out->outpic = NULL;
00110 }
00111 avfilter_end_frame(out);
00112 }
00113 }
00114 
00118 int avfilter_default_config_output_link(AVFilterLink *link)
00119 {
00120 if(link->src->input_count && link->src->inputs[0]) {
00121 link->w = link->src->inputs[0]->w;
00122 link->h = link->src->inputs[0]->h;
00123 } else {
00124 /* XXX: any non-simple filter which would cause this branch to be taken
00125  * really should implement its own config_props() for this link. */
00126 return -1;
00127 }
00128 
00129 return 0;
00130 }
00131 
00140 void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
00141 {
00142 int count = 0, i;
00143 
00144 for(i = 0; i < ctx->input_count; i ++) {
00145 if(ctx->inputs[i]) {
00146 avfilter_formats_ref(formats, &ctx->inputs[i]->out_formats);
00147 count ++;
00148 }
00149 }
00150 for(i = 0; i < ctx->output_count; i ++) {
00151 if(ctx->outputs[i]) {
00152 avfilter_formats_ref(formats, &ctx->outputs[i]->in_formats);
00153 count ++;
00154 }
00155 }
00156 
00157 if(!count) {
00158 av_free(formats->formats);
00159 av_free(formats->refs);
00160 av_free(formats);
00161 }
00162 }
00163 
00164 int avfilter_default_query_formats(AVFilterContext *ctx)
00165 {
00166 avfilter_set_common_formats(ctx, avfilter_all_colorspaces());
00167 return 0;
00168 }
00169 

Generated on Fri Oct 26 02:35:40 2012 for FFmpeg by doxygen 1.5.8

AltStyle によって変換されたページ (->オリジナル) /