00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavcodec/imgconvert.h"
00023 #include "avfilter.h"
00024
00025
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
00037
00038
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
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
00106
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
00114
00115 return -1;
00116 }
00117
00118 return 0;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
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