[FFmpeg-soc] [soc]: r618 - in libavfilter: avfilter.c avfilter.h avfiltergraph.c avfiltergraph.h defaults.c ffmpeg.diff filter_test.c vf_crop.c vf_slicify.c

koorogi subversion at mplayerhq.hu
Tue Aug 7 23:02:19 CEST 2007


Author: koorogi
Date: Tue Aug  7 23:02:18 2007
New Revision: 618

Log:
Separate the process of creating links between filters from that of configuring
the links.


Modified:
   libavfilter/avfilter.c
   libavfilter/avfilter.h
   libavfilter/avfiltergraph.c
   libavfilter/avfiltergraph.h
   libavfilter/defaults.c
   libavfilter/ffmpeg.diff
   libavfilter/filter_test.c
   libavfilter/vf_crop.c
   libavfilter/vf_slicify.c

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Tue Aug  7 23:02:18 2007
@@ -51,7 +51,6 @@ int avfilter_link(AVFilterContext *src, 
                   AVFilterContext *dst, unsigned dstpad)
 {
     AVFilterLink *link;
-    int *fmts[2], i, j;
 
     if(src->output_count <= srcpad || dst->input_count <= dstpad ||
        src->outputs[srcpad]        || dst->inputs[dstpad])
@@ -65,14 +64,26 @@ int avfilter_link(AVFilterContext *src, 
     link->srcpad  = srcpad;
     link->dstpad  = dstpad;
     link->cur_pic = NULL;
+    link->format  = -1;
+
+    return 0;
+}
+
+int avfilter_config_link(AVFilterLink *link)
+{
+    int *fmts[2], i, j;
+    int (*config_link)(AVFilterLink *);
+
+    if(!link)
+        return 0;
 
     /* find a format both filters support - TODO: auto-insert conversion filter */
     link->format = -1;
-    if(src->output_pads[srcpad].query_formats)
-        fmts[0] = src->output_pads[srcpad].query_formats(link);
+    if(link->src->output_pads[link->srcpad].query_formats)
+        fmts[0] = link->src->output_pads[link->srcpad].query_formats(link);
     else
         fmts[0] = avfilter_default_query_output_formats(link);
-    fmts[1] = dst->input_pads[dstpad].query_formats(link);
+    fmts[1] = link->dst->input_pads[link->dstpad].query_formats(link);
     for(i = 0; fmts[0][i] != -1; i ++)
         for(j = 0; fmts[1][j] != -1; j ++)
             if(fmts[0][i] == fmts[1][j]) {
@@ -83,21 +94,18 @@ int avfilter_link(AVFilterContext *src, 
 format_done:
     av_free(fmts[0]);
     av_free(fmts[1]);
-    if(link->format == -1) {
-        /* failed to find a format.  fail at creating the link */
-        av_free(link);
-        src->outputs[srcpad] = NULL;
-        dst->inputs[dstpad]  = NULL;
+    if(link->format == -1)
         return -1;
-    }
 
-    if (src->output_pads[srcpad].config_props)
-        src->output_pads[srcpad].config_props(link);
-    else
-        avfilter_default_config_output_link(link);
+    if(!(config_link = link->src->output_pads[link->srcpad].config_props))
+        config_link  = avfilter_default_config_output_link;
+    if(config_link(link))
+            return -1;
 
-    if (dst->input_pads[dstpad].config_props)
-        dst->input_pads[dstpad].config_props(link);
+    if(!(config_link = link->dst->input_pads[link->dstpad].config_props))
+        config_link  = avfilter_default_config_input_link;
+    if(config_link(link))
+            return -1;
 
     return 0;
 }

Modified: libavfilter/avfilter.h
==============================================================================
--- libavfilter/avfilter.h	(original)
+++ libavfilter/avfilter.h	Tue Aug  7 23:02:18 2007
@@ -156,6 +156,7 @@ struct AVFilterPad
 void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
 void avfilter_default_end_frame(AVFilterLink *link);
 int avfilter_default_config_output_link(AVFilterLink *link);
+int avfilter_default_config_input_link (AVFilterLink *link);
 int *avfilter_default_query_output_formats(AVFilterLink *link);
 AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link,
                                                   int perms);
@@ -218,6 +219,9 @@ struct AVFilterLink
 int avfilter_link(AVFilterContext *src, unsigned srcpad,
                   AVFilterContext *dst, unsigned dstpad);
 
+/** Configure the colorspace, dimensions, etc of a link */
+int avfilter_config_link(AVFilterLink *link);
+
 AVFilterPicRef *avfilter_get_video_buffer(AVFilterLink *link, int perms);
 void avfilter_request_frame(AVFilterLink *link);
 void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref);

Modified: libavfilter/avfiltergraph.c
==============================================================================
--- libavfilter/avfiltergraph.c	(original)
+++ libavfilter/avfiltergraph.c	Tue Aug  7 23:02:18 2007
@@ -49,6 +49,20 @@ void avfilter_graph_add_filter(AVFilterC
     graph->filters[graph->filter_count - 1] = filter;
 }
 
+int avfilter_graph_config_links(AVFilterContext *graphctx)
+{
+    GraphContext *graph = graphctx->priv;
+    int i, j;
+
+    for(i = 0; i < graph->filter_count; i ++) {
+        for(j = 0; j < graph->filters[i]->input_count; j ++)
+            if(avfilter_config_link(graph->filters[i]->inputs[j]))
+                return -1;
+    }
+
+    return 0;
+}
+
 static AVFilterContext *create_filter_with_args(const char *filt, void *opaque)
 {
     AVFilterContext *ret;

Modified: libavfilter/avfiltergraph.h
==============================================================================
--- libavfilter/avfiltergraph.h	(original)
+++ libavfilter/avfiltergraph.h	Tue Aug  7 23:02:18 2007
@@ -31,4 +31,9 @@
  */
 void avfilter_graph_add_filter(AVFilterContext *graphctx, AVFilterContext *filter);
 
+/**
+ * Configure the colorspace, resolution, etc of all links in the graph
+ */
+int avfilter_graph_config_links(AVFilterContext *graphctx);
+
 #endif  /* FFMPEG_AVFILTER_H */

Modified: libavfilter/defaults.c
==============================================================================
--- libavfilter/defaults.c	(original)
+++ libavfilter/defaults.c	Tue Aug  7 23:02:18 2007
@@ -104,6 +104,16 @@ int avfilter_default_config_output_link(
 }
 
 /**
+ * default config_link() implementation for input video links to simplify
+ * the implementation of one input one output video filters */
+int avfilter_default_config_input_link(AVFilterLink *link)
+{
+    if(!link->dst->output_count)
+        return 0;
+    return avfilter_config_link(link->dst->outputs[0]);
+}
+
+/**
  * default query_formats() implementation for output video links to simplify
  * the implementation of one input one output video filters */
 int *avfilter_default_query_output_formats(AVFilterLink *link)

Modified: libavfilter/ffmpeg.diff
==============================================================================
--- libavfilter/ffmpeg.diff	(original)
+++ libavfilter/ffmpeg.diff	Tue Aug  7 23:02:18 2007
@@ -183,7 +183,7 @@ Index: ffplay.c
          if(pkt->data == flush_pkt.data){
              avcodec_flush_buffers(is->video_st->codec);
              continue;
-@@ -1356,31 +1382,203 @@
+@@ -1356,31 +1382,204 @@
          /* NOTE: ipts is the PTS of the _first_ picture beginning in
             this packet, if any */
          global_video_pkt_pts= pkt->pts;
@@ -370,6 +370,7 @@ Index: ffplay.c
 +    if(avfilter_init_filter(filt_out, NULL, frame))          goto the_end;
 +
 +    if(avfilter_link(filt_src, 0, filt_out, 0) < 0)          goto the_end;
++    if(avfilter_config_link(filt_src->outputs[0]))           goto the_end;
 +    is->out_video_filter = filt_out;
 +#endif
 +
@@ -399,7 +400,7 @@ Index: ffplay.c
      av_free(frame);
      return 0;
  }
-@@ -2131,6 +2329,12 @@
+@@ -2131,6 +2330,12 @@
      /* free all pictures */
      for(i=0;i<VIDEO_PICTURE_QUEUE_SIZE; i++) {
          vp = &is->pictq[i];

Modified: libavfilter/filter_test.c
==============================================================================
--- libavfilter/filter_test.c	(original)
+++ libavfilter/filter_test.c	Tue Aug  7 23:02:18 2007
@@ -44,6 +44,11 @@ int main(int argc, char **argv)
     if(avfilter_init_filter(graph, argv[1], filters) < 0)
         goto done;
 
+    if(avfilter_graph_config_links(graph)) {
+        av_log(NULL, AV_LOG_ERROR, "cannot configure graph\n");
+        goto done;
+    }
+
     while(pts < 5000) {
         newpts = sdl_display(filters[1]);
         usleep(newpts - pts);

Modified: libavfilter/vf_crop.c
==============================================================================
--- libavfilter/vf_crop.c	(original)
+++ libavfilter/vf_crop.c	Tue Aug  7 23:02:18 2007
@@ -63,7 +63,7 @@ static int config_input(AVFilterLink *li
     if(crop->cw <= 0) crop->cw = link->w - crop->cx;
     if(crop->ch <= 0) crop->ch = link->h - crop->cy;
 
-    return 0;
+    return avfilter_config_link(link->dst->outputs[0]);
 }
 
 static int config_output(AVFilterLink *link)

Modified: libavfilter/vf_slicify.c
==============================================================================
--- libavfilter/vf_slicify.c	(original)
+++ libavfilter/vf_slicify.c	Tue Aug  7 23:02:18 2007
@@ -57,7 +57,7 @@ static int config_props(AVFilterLink *li
      * a reasonable minimum size for the slices */
     slice->h = FFMAX(8, slice->h & (-1 << slice->vshift));
 
-    return 0;
+    return avfilter_config_link(link->dst->outputs[0]);
 }
 
 static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)



More information about the FFmpeg-soc mailing list