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_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
00125
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