Allow filters to set the requirements on permissions for incoming buffers.
[libav.git] / libavfilter / defaults.c
CommitLineData
bf4ce7a3
VS
1/*
2 * Filter layer - default implementations
3 * copyright (c) 2007 Bobby Bingham
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "avfilter.h"
23
24/* TODO: buffer pool. see comment for avfilter_default_get_video_buffer() */
25void avfilter_default_free_video_buffer(AVFilterPic *pic)
26{
27 avpicture_free((AVPicture *) pic);
28 av_free(pic);
29}
30
31/* TODO: set the buffer's priv member to a context structure for the whole
32 * filter chain. This will allow for a buffer pool instead of the constant
33 * alloc & free cycle currently implemented. */
34AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link, int perms)
35{
36 AVFilterPic *pic = av_mallocz(sizeof(AVFilterPic));
37 AVFilterPicRef *ref = av_mallocz(sizeof(AVFilterPicRef));
38
39 ref->pic = pic;
40 ref->w = link->w;
41 ref->h = link->h;
42 ref->perms = perms;
43
44 pic->refcount = 1;
45 pic->format = link->format;
46 pic->free = avfilter_default_free_video_buffer;
47 avpicture_alloc((AVPicture *)pic, pic->format, ref->w, ref->h);
48
49 memcpy(ref->data, pic->data, sizeof(pic->data));
50 memcpy(ref->linesize, pic->linesize, sizeof(pic->linesize));
51
52 return ref;
53}
54
55void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
56{
57 AVFilterLink *out = NULL;
58
59 if(link->dst->output_count)
60 out = link->dst->outputs[0];
61
bf4ce7a3
VS
62 if(out) {
63 out->outpic = avfilter_get_video_buffer(out, AV_PERM_WRITE);
64 out->outpic->pts = picref->pts;
65 avfilter_start_frame(out, avfilter_ref_pic(out->outpic, ~0));
66 }
67}
68
69void avfilter_default_end_frame(AVFilterLink *link)
70{
71 AVFilterLink *out = NULL;
72
73 if(link->dst->output_count)
74 out = link->dst->outputs[0];
75
76 avfilter_unref_pic(link->cur_pic);
77 link->cur_pic = NULL;
78
79 if(out) {
80 avfilter_unref_pic(out->outpic);
81 out->outpic = NULL;
82 avfilter_end_frame(out);
83 }
84}
85
86/**
87 * default config_link() implementation for output video links to simplify
88 * the implementation of one input one output video filters */
89int avfilter_default_config_output_link(AVFilterLink *link)
90{
91 if(link->src->input_count && link->src->inputs[0]) {
92 link->w = link->src->inputs[0]->w;
93 link->h = link->src->inputs[0]->h;
94 } else {
95 /* XXX: any non-simple filter which would cause this branch to be taken
96 * really should implement its own config_props() for this link. */
97 link->w =
98 link->h = 0;
99 }
100
101 return 0;
102}
103
104/**
f66f53da
VS
105 * default config_link() implementation for input video links to simplify
106 * the implementation of one input one output video filters */
107int avfilter_default_config_input_link(AVFilterLink *link)
108{
109 if(!link->dst->output_count)
110 return 0;
111 return avfilter_config_link(link->dst->outputs[0]);
112}
113
114/**
bf4ce7a3
VS
115 * default query_formats() implementation for output video links to simplify
116 * the implementation of one input one output video filters */
117int *avfilter_default_query_output_formats(AVFilterLink *link)
118{
119 if(link->src->input_count && link->src->inputs[0])
120 return avfilter_make_format_list(1, link->src->inputs[0]->format);
121 else
122 /* XXX: any non-simple filter which would cause this branch to be taken
123 * really should implement its own query_formats() for this link */
124 return avfilter_make_format_list(0);
125}
126