Statistics
| Branch: | Revision:

ffmpeg / libavfilter / defaults.c @ 0eb4ff9e

History | View | Annotate | Download (4.79 KB)

1 bf4ce7a3 Vitor Sessak
/*
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 245976da Diego Biurrun
#include "libavcodec/imgconvert.h"
23 bf4ce7a3 Vitor Sessak
#include "avfilter.h"
24
25
/* TODO: buffer pool.  see comment for avfilter_default_get_video_buffer() */
26
void avfilter_default_free_video_buffer(AVFilterPic *pic)
27
{
28 790a03d7 Vitor Sessak
    av_free(pic->data[0]);
29 bf4ce7a3 Vitor Sessak
    av_free(pic);
30
}
31
32
/* TODO: set the buffer's priv member to a context structure for the whole
33
 * filter chain.  This will allow for a buffer pool instead of the constant
34
 * alloc & free cycle currently implemented. */
35 0eb4ff9e Stefano Sabatini
AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
36 bf4ce7a3 Vitor Sessak
{
37
    AVFilterPic *pic = av_mallocz(sizeof(AVFilterPic));
38
    AVFilterPicRef *ref = av_mallocz(sizeof(AVFilterPicRef));
39 790a03d7 Vitor Sessak
    int i, tempsize;
40
    char *buf;
41 bf4ce7a3 Vitor Sessak
42
    ref->pic   = pic;
43 0eb4ff9e Stefano Sabatini
    ref->w     = pic->w = w;
44
    ref->h     = pic->h = h;
45 4f909565 Vitor Sessak
46
    /* make sure the buffer gets read permission or it's useless for output */
47
    ref->perms = perms | AV_PERM_READ;
48 bf4ce7a3 Vitor Sessak
49
    pic->refcount = 1;
50
    pic->format   = link->format;
51
    pic->free     = avfilter_default_free_video_buffer;
52 790a03d7 Vitor Sessak
    ff_fill_linesize((AVPicture *)pic, pic->format, ref->w);
53
54
    for (i=0; i<4;i++)
55 ef516f73 David Conrad
        pic->linesize[i] = FFALIGN(pic->linesize[i], 16);
56 790a03d7 Vitor Sessak
57
    tempsize = ff_fill_pointer((AVPicture *)pic, NULL, pic->format, ref->h);
58
    buf = av_malloc(tempsize);
59
    ff_fill_pointer((AVPicture *)pic, buf, pic->format, ref->h);
60 bf4ce7a3 Vitor Sessak
61
    memcpy(ref->data,     pic->data,     sizeof(pic->data));
62
    memcpy(ref->linesize, pic->linesize, sizeof(pic->linesize));
63
64
    return ref;
65
}
66
67
void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
68
{
69
    AVFilterLink *out = NULL;
70
71
    if(link->dst->output_count)
72
        out = link->dst->outputs[0];
73
74
    if(out) {
75 0eb4ff9e Stefano Sabatini
        out->outpic      = avfilter_get_video_buffer(out, AV_PERM_WRITE, link->w, link->h);
76 bf4ce7a3 Vitor Sessak
        out->outpic->pts = picref->pts;
77 23274667 Vitor Sessak
        avfilter_start_frame(out, avfilter_ref_pic(out->outpic, ~0));
78 bf4ce7a3 Vitor Sessak
    }
79
}
80
81 b9609848 Stefano Sabatini
void avfilter_default_draw_slice(AVFilterLink *link, int y, int h)
82
{
83
    AVFilterLink *out = NULL;
84
85
    if(link->dst->output_count)
86
        out = link->dst->outputs[0];
87
88
    if(out)
89
        avfilter_draw_slice(out, y, h);
90
}
91
92 bf4ce7a3 Vitor Sessak
void avfilter_default_end_frame(AVFilterLink *link)
93
{
94
    AVFilterLink *out = NULL;
95
96
    if(link->dst->output_count)
97
        out = link->dst->outputs[0];
98
99
    avfilter_unref_pic(link->cur_pic);
100
    link->cur_pic = NULL;
101
102
    if(out) {
103 552c0208 Vitor Sessak
        if(out->outpic) {
104 fc0f39c2 Vitor Sessak
            avfilter_unref_pic(out->outpic);
105
            out->outpic = NULL;
106 552c0208 Vitor Sessak
        }
107 bf4ce7a3 Vitor Sessak
        avfilter_end_frame(out);
108
    }
109
}
110
111
/**
112
 * default config_link() implementation for output video links to simplify
113
 * the implementation of one input one output video filters */
114
int avfilter_default_config_output_link(AVFilterLink *link)
115
{
116
    if(link->src->input_count && link->src->inputs[0]) {
117
        link->w = link->src->inputs[0]->w;
118
        link->h = link->src->inputs[0]->h;
119
    } else {
120
        /* XXX: any non-simple filter which would cause this branch to be taken
121
         * really should implement its own config_props() for this link. */
122 d0e4eba5 Vitor Sessak
        return -1;
123 bf4ce7a3 Vitor Sessak
    }
124
125
    return 0;
126
}
127
128
/**
129 e363730c Vitor Sessak
 * A helper for query_formats() which sets all links to the same list of
130
 * formats. If there are no links hooked to this filter, the list of formats is
131
 * freed.
132
 *
133
 * FIXME: this will need changed for filters with a mix of pad types
134
 * (video + audio, etc)
135
 */
136
void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
137 bf4ce7a3 Vitor Sessak
{
138 e363730c Vitor Sessak
    int count = 0, i;
139
140
    for(i = 0; i < ctx->input_count; i ++) {
141
        if(ctx->inputs[i]) {
142
            avfilter_formats_ref(formats, &ctx->inputs[i]->out_formats);
143
            count ++;
144
        }
145
    }
146
    for(i = 0; i < ctx->output_count; i ++) {
147
        if(ctx->outputs[i]) {
148
            avfilter_formats_ref(formats, &ctx->outputs[i]->in_formats);
149
            count ++;
150
        }
151
    }
152
153
    if(!count) {
154
        av_free(formats->formats);
155
        av_free(formats->refs);
156
        av_free(formats);
157
    }
158
}
159
160
int avfilter_default_query_formats(AVFilterContext *ctx)
161
{
162
    avfilter_set_common_formats(ctx, avfilter_all_colorspaces());
163
    return 0;
164 bf4ce7a3 Vitor Sessak
}