[FFmpeg-soc] [soc]: r418 - in libavfilter: avfilter.c avfilter.h filter_test.c
koorogi
subversion at mplayerhq.hu
Sat Jul 14 22:12:55 CEST 2007
Author: koorogi
Date: Sat Jul 14 22:12:54 2007
New Revision: 418
Log:
Add a simple filter graph structure and functions
Modified:
libavfilter/avfilter.c
libavfilter/avfilter.h
libavfilter/filter_test.c
Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c (original)
+++ libavfilter/avfilter.c Sat Jul 14 22:12:54 2007
@@ -31,6 +31,33 @@
static int filter_count = 0;
static AVFilter **filters = NULL;
+struct AVFilterGraph {
+ unsigned filter_count;
+ AVFilterContext **filters;
+};
+
+AVFilterGraph *avfilter_create_graph(void)
+{
+ return av_mallocz(sizeof(AVFilterGraph));
+}
+
+void avfilter_destroy_graph(AVFilterGraph *graph)
+{
+ unsigned i;
+
+ for(i = 0; i < graph->filter_count; i ++)
+ avfilter_destroy(graph->filters[i]);
+ av_free(graph->filters);
+ av_free(graph);
+}
+
+void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
+{
+ graph->filters = av_realloc(graph->filters,
+ sizeof(AVFilterContext*) * ++graph->filter_count);
+ graph->filters[graph->filter_count - 1] = filter;
+}
+
/* TODO: buffer pool. see comment for avfilter_default_get_video_buffer() */
void avfilter_default_free_video_buffer(AVFilterPic *pic)
{
Modified: libavfilter/avfilter.h
==============================================================================
--- libavfilter/avfilter.h (original)
+++ libavfilter/avfilter.h Sat Jul 14 22:12:54 2007
@@ -225,4 +225,24 @@ void avfilter_destroy(AVFilterContext *f
int *avfilter_make_format_list(int len, ...);
+typedef struct AVFilterGraph AVFilterGraph;
+
+/**
+ * Create a new filter graph
+ */
+AVFilterGraph *avfilter_create_graph(void);
+
+/**
+ * Destroy a filter graph, and any filters in it.
+ * @param graph The filter graph to destroy
+ */
+void avfilter_destroy_graph(AVFilterGraph *graph);
+
+/**
+ * Add an existing filter instance to a filter graph.
+ * @param graph The filter graph
+ * @param filter The filter to be added
+ */
+void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter);
+
#endif /* FFMPEG_AVFILTER_H */
Modified: libavfilter/filter_test.c
==============================================================================
--- libavfilter/filter_test.c (original)
+++ libavfilter/filter_test.c Sat Jul 14 22:12:54 2007
@@ -59,27 +59,30 @@ int main(int argc, char **argv)
int i;
int ret = -1;
int64_t pts = 0, newpts;
- AVFilterContext **filters;
+ AVFilterGraph *graph;
+ AVFilterContext *filters[2];
if(argc < 3) {
av_log(NULL, AV_LOG_ERROR, "require at least two filters\n");
return -1;
}
- filters = av_mallocz((argc-1) * sizeof(AVFilterContext*));
avfilter_init();
+ graph = avfilter_create_graph();
for(i = 0; i < argc-1; i ++) {
- if(!(filters[i] = create_filter(argv[i+1])))
+ if(!(filters[1] = create_filter(argv[i+1])))
goto done;
- if(i && avfilter_link(filters[i-1], 0, filters[i], 0)) {
+ avfilter_graph_add_filter(graph, filters[1]);
+ if(i && avfilter_link(filters[0], 0, filters[1], 0)) {
av_log(NULL, AV_LOG_ERROR, "error linking filters!\n");
goto done;
}
+ filters[0] = filters[1];
}
while(pts < 5000) {
- newpts = sdl_display(filters[argc-2]);
+ newpts = sdl_display(filters[1]);
usleep(newpts - pts);
pts = newpts;
}
@@ -87,9 +90,7 @@ int main(int argc, char **argv)
ret = 0;
done:
- for(i = 0; i < argc-1; i ++)
- if(filters[i]) avfilter_destroy(filters[i]);
- av_free(filters);
+ avfilter_destroy_graph(graph);
return ret;
}
More information about the FFmpeg-soc
mailing list