Revision b9a7a65a

View differences:

libavfilter/avfiltergraph.c
26 26
#include "avfilter.h"
27 27
#include "avfiltergraph.h"
28 28

  
29
struct AVFilterGraph {
29
typedef struct AVFilterGraph {
30 30
    unsigned filter_count;
31 31
    AVFilterContext **filters;
32
};
32
} GraphContext;
33 33

  
34
AVFilterGraph *avfilter_create_graph(void)
34
static void uninit(AVFilterContext *ctx)
35 35
{
36
    return av_mallocz(sizeof(AVFilterGraph));
37
}
36
    GraphContext *graph = ctx->priv;
38 37

  
39
static void destroy_graph_filters(AVFilterGraph *graph)
40
{
41 38
    for(; graph->filter_count > 0; graph->filter_count --)
42 39
        avfilter_destroy(graph->filters[graph->filter_count - 1]);
43 40
    av_freep(&graph->filters);
44 41
}
45 42

  
46
void avfilter_destroy_graph(AVFilterGraph *graph)
43
void avfilter_graph_add_filter(AVFilterContext *graphctx, AVFilterContext *filter)
47 44
{
48
    destroy_graph_filters(graph);
49
    av_free(graph);
50
}
45
    GraphContext *graph = graphctx->priv;
51 46

  
52
void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
53
{
54 47
    graph->filters = av_realloc(graph->filters,
55 48
                                sizeof(AVFilterContext*) * ++graph->filter_count);
56 49
    graph->filters[graph->filter_count - 1] = filter;
......
89 82
    return NULL;
90 83
}
91 84

  
92
int avfilter_graph_load_chain(AVFilterGraph *graph,
85
static int graph_load_chain(AVFilterContext *graphctx,
93 86
                              unsigned count, char **filter_list, void **opaque,
94 87
                              AVFilterContext **first, AVFilterContext **last)
95 88
{
......
112 105
                goto fail;
113 106
            }
114 107
        }
115
        avfilter_graph_add_filter(graph, filters[1]);
108
        avfilter_graph_add_filter(graphctx, filters[1]);
116 109
        filters[0] = filters[1];
117 110
    }
118 111

  
......
120 113
    return 0;
121 114

  
122 115
fail:
123
    destroy_graph_filters(graph);
116
    uninit(graphctx);
124 117
    if(first) *first = NULL;
125 118
    if(last)  *last  = NULL;
126 119
    return -1;
127 120
}
128 121

  
122
static int graph_load_chain_from_string(AVFilterContext *ctx, const char *str,
123
                                        AVFilterContext **first,
124
                                        AVFilterContext **last)
125
{
126
    int count, ret = 0;
127
    char **strings;
128
    char *filt;
129

  
130
    strings    = av_malloc(sizeof(char *));
131
    strings[0] = av_strdup(str);
132

  
133
    filt = strchr(strings[0], ',');
134
    for(count = 1; filt; count ++) {
135
        if(filt == strings[count-1]) {
136
            ret = -1;
137
            goto done;
138
        }
139

  
140
        strings = av_realloc(strings, sizeof(char *) * (count+1));
141
        strings[count] = filt + 1;
142
        *filt = '\0';
143
        filt = strchr(strings[count], ',');
144
    }
145

  
146
    ret = graph_load_chain(ctx, count, strings, NULL, first, last);
147

  
148
done:
149
    av_free(strings[0]);
150
    av_free(strings);
151

  
152
    return ret;
153
}
154

  
155
static int init(AVFilterContext *ctx, const char *args, void *opaque)
156
{
157
    AVFilterContext **filters = opaque;
158

  
159
    if(!args)
160
        return 0;
161
    if(!opaque)
162
        return -1;
163

  
164
    return graph_load_chain_from_string(ctx, args, filters, filters + 1);
165
}
166

  
167
AVFilter vf_graph =
168
{
169
    .name      = "graph",
170
    .author    = "Bobby Bingham",
171

  
172
    .priv_size = sizeof(GraphContext),
173

  
174
    .init      = init,
175
    .uninit    = uninit,
176

  
177
    .inputs    = (AVFilterPad[]) {{ .name = NULL, }},
178
    .outputs   = (AVFilterPad[]) {{ .name = NULL, }},
179
};
180

  
libavfilter/avfiltergraph.h
24 24

  
25 25
#include "avfilter.h"
26 26

  
27
typedef struct AVFilterGraph AVFilterGraph;
28

  
29
/**
30
 * Create a new filter graph
31
 */
32
AVFilterGraph *avfilter_create_graph(void);
33

  
34
/**
35
 * Destroy a filter graph, and any filters in it.
36
 * @param graph The filter graph to destroy
37
 */
38
void avfilter_destroy_graph(AVFilterGraph *graph);
39

  
40 27
/**
41 28
 * Add an existing filter instance to a filter graph.
42 29
 * @param graph  The filter graph
43 30
 * @param filter The filter to be added
44 31
 */
45
void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter);
32
void avfilter_graph_add_filter(AVFilterContext *graphctx, AVFilterContext *filter);
46 33

  
47
/**
48
 * Loads the filter graph with a simple chain described by filters.
49
 * @param graph   The filter graph to load filters into
50
 * @param count   The number of filters to be created
51
 * @param filters_list An array of strings describing the filters to be created.
52
 *                The format of each string is "name=params".
53
 * @param first   If non-NULL, will be set to the first filter in the chain.
54
 * @param last    If non-NULL, will be set to the last filter in the chain.
55
 * @return 0 on success.  -1 on error.
56
 */
57
int avfilter_graph_load_chain(AVFilterGraph *graph,
58
                              unsigned count, char **filter_list, void **opaque,
59
                              AVFilterContext **first, AVFilterContext **last);
60 34
#endif  /* FFMPEG_AVFILTER_H */

Also available in: Unified diff