[FFmpeg-soc] [soc]: r1664 - in libavfilter: avfilter.c avfilter.h avfiltergraph.c defaults.c diffs/03_ffplay_filters.diff diffs/04_ffmpeg_filters.diff vf_crop.c vf_hflip.c vf_overlay.c vf_slicify.c vf_vflip.c

koorogi subversion at mplayerhq.hu
Mon Dec 24 04:22:10 CET 2007


Author: koorogi
Date: Mon Dec 24 04:22:10 2007
New Revision: 1664

Log:
Rework link property configuration system.
This can now handle filters which are added to graphs out of order,
including auto-inserted scale filters.  As an added bonus, it can
now detect circular filter chains which wouldn't work anyway.


Modified:
   libavfilter/avfilter.c
   libavfilter/avfilter.h
   libavfilter/avfiltergraph.c
   libavfilter/defaults.c
   libavfilter/diffs/03_ffplay_filters.diff
   libavfilter/diffs/04_ffmpeg_filters.diff
   libavfilter/vf_crop.c
   libavfilter/vf_hflip.c
   libavfilter/vf_overlay.c
   libavfilter/vf_slicify.c
   libavfilter/vf_vflip.c

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Mon Dec 24 04:22:10 2007
@@ -125,23 +125,41 @@ int avfilter_insert_filter(AVFilterLink 
     return 0;
 }
 
-int avfilter_config_link(AVFilterLink *link)
+int avfilter_config_links(AVFilterContext *filter)
 {
     int (*config_link)(AVFilterLink *);
+    unsigned i;
 
-    if(!link)
-        return 0;
+    for(i = 0; i < filter->input_count; i ++) {
+        AVFilterLink *link;
+
+        if(!(link = filter->inputs[i])) continue;
+
+        switch(link->init_state) {
+        case AVLINK_INIT:
+            continue;
+        case AVLINK_STARTINIT:
+            av_log(filter, AV_LOG_ERROR, "circular filter chain detected\n");
+            return -1;
+        case AVLINK_UNINIT:
+            link->init_state = AVLINK_STARTINIT;
+
+            if(avfilter_config_links(link->src))
+                return -1;
 
     if(!(config_link = link_spad(link).config_props))
         config_link  = avfilter_default_config_output_link;
     if(config_link(link))
             return -1;
 
-    if(!(config_link = link_dpad(link).config_props))
-        config_link  = avfilter_default_config_input_link;
+    if((config_link = link_dpad(link).config_props))
     if(config_link(link))
             return -1;
 
+            link->init_state = AVLINK_INIT;
+        }
+    }
+
     return 0;
 }
 

Modified: libavfilter/avfilter.h
==============================================================================
--- libavfilter/avfilter.h	(original)
+++ libavfilter/avfilter.h	Mon Dec 24 04:22:10 2007
@@ -381,6 +381,13 @@ struct AVFilterLink
     AVFilterContext *dst;       ///< dest filter
     unsigned int dstpad;        ///< index of the input pad on the dest filter
 
+    /** stage of the initialization of the link properties (dimensions, etc) */
+    enum {
+        AVLINK_UNINIT = 0,      ///< not started
+        AVLINK_STARTINIT,       ///< started, but incomplete
+        AVLINK_INIT             ///< complete
+    } init_state;
+
     int w;                      ///< agreed upon image width
     int h;                      ///< agreed upon image height
     enum PixelFormat format;    ///< agreed upon image colorspace
@@ -418,11 +425,11 @@ int avfilter_link(AVFilterContext *src, 
                   AVFilterContext *dst, unsigned dstpad);
 
 /**
- * Negotiate the colorspace, dimensions, etc of a link
- * @param link The link to negotiate the properties of
+ * Negotiate the colorspace, dimensions, etc of all inputs to a filter.
+ * @param filter The filter to negotiate the properties for its inputs
  * @return     Zero on successful negotiation
  */
-int avfilter_config_link(AVFilterLink *link);
+int avfilter_config_links(AVFilterContext *filter);
 
 /**
  * Request a picture buffer with a specific set of permissions

Modified: libavfilter/avfiltergraph.c
==============================================================================
--- libavfilter/avfiltergraph.c	(original)
+++ libavfilter/avfiltergraph.c	Mon Dec 24 04:22:10 2007
@@ -101,7 +101,6 @@ static inline AVFilterLink *get_extern_o
 static int link_out_config_props(AVFilterLink *link)
 {
     AVFilterLink *link2 = get_extern_output_link(link);
-    int (*config_props)(AVFilterLink *);
 
     if(!link2)
         return 0;
@@ -109,9 +108,7 @@ static int link_out_config_props(AVFilte
     link2->w = link->w;
     link2->h = link->h;
 
-    if(!(config_props = link2->dst->input_pads[link2->dstpad].config_props))
-        config_props = avfilter_default_config_input_link;
-    return config_props(link2);
+    return 0;
 }
 
 static void link_out_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
@@ -203,6 +200,7 @@ static int graph_in_config_props(AVFilte
 {
     AVFilterLink *link2 = get_intern_input_link(link);
     int (*config_props)(AVFilterLink *);
+    int ret;
 
     if(!link2)
         return -1;
@@ -215,7 +213,12 @@ static int graph_in_config_props(AVFilte
     if(!(config_props = link2->dst->input_pads[link2->dstpad].config_props))
         return 0;   /* FIXME? */
         //config_props = avfilter_default_config_input_link;
-    return config_props(link2);
+    if(!(ret = config_props(link2)))
+        link2->init_state = AVLINK_INIT;
+    else
+        link2->init_state = AVLINK_STARTINIT;
+
+    return ret;
 }
 
 static AVFilterLink *get_intern_output_link(AVFilterLink *link)
@@ -235,26 +238,21 @@ static int graph_out_request_frame(AVFil
 
 static int graph_out_config_props(AVFilterLink *link)
 {
-    AVFilterLink *link2 = get_intern_output_link(link);
-    int (*config_props)(AVFilterLink *);
+    GraphContext *graph = link->src->priv;
+    AVFilterLink *link2 = graph->link_filter_out->inputs[link->srcpad];
     int ret;
 
+    if((ret = avfilter_config_links(graph->link_filter_out)))
+        return ret;
+
     if(!link2)
         return 0;
 
-    link2->w = link->w;
-    link2->h = link->h;
-    link2->format = link->format;
-
-    if(!(config_props = link2->src->output_pads[link2->srcpad].config_props))
-        config_props = avfilter_default_config_output_link;
-    ret = config_props(link2);
-
     link->w = link2->w;
     link->h = link2->h;
     link->format = link2->format;
 
-    return ret;
+    return 0;
 }
 
 static int add_graph_input(AVFilterContext *gctx, AVFilterContext *filt, unsigned idx,
@@ -477,27 +475,6 @@ int avfilter_graph_config_formats(AVFilt
     return 0;
 }
 
-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 ++) {
-            /* ensure that graphs contained within graphs are configured */
-            if((graph->filters[i]->filter == &avfilter_vf_graph     ||
-                graph->filters[i]->filter == &avfilter_vf_graphfile ||
-                graph->filters[i]->filter == &avfilter_vf_graphdesc) &&
-                avfilter_graph_config_links(graph->filters[i]))
-                return -1;
-            if(avfilter_config_link(graph->filters[i]->inputs[j]))
-                return -1;
-        }
-    }
-
-    return 0;
-}
-
 static int graph_load_from_desc(AVFilterContext *ctx, AVFilterGraphDesc *desc)
 {
     AVFilterGraphDescFilter *curfilt;

Modified: libavfilter/defaults.c
==============================================================================
--- libavfilter/defaults.c	(original)
+++ libavfilter/defaults.c	Mon Dec 24 04:22:10 2007
@@ -105,16 +105,6 @@ 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]);
-}
-
-/**
  * A helper for query_formats() which sets all links to the same list of
  * formats. If there are no links hooked to this filter, the list of formats is
  * freed.

Modified: libavfilter/diffs/03_ffplay_filters.diff
==============================================================================
--- libavfilter/diffs/03_ffplay_filters.diff	(original)
+++ libavfilter/diffs/03_ffplay_filters.diff	Mon Dec 24 04:22:10 2007
@@ -361,7 +361,7 @@
 +    avfilter_graph_add_filter(graph, filt_src);
 +    avfilter_graph_add_filter(graph, filt_out);
 +    if(avfilter_graph_config_formats(graph))                 goto the_end;
-+    if(avfilter_graph_config_links(graph))                   goto the_end;
++    if(avfilter_config_links(filt_out))                      goto the_end;
 +
 +    is->out_video_filter = filt_out;
 +#endif

Modified: libavfilter/diffs/04_ffmpeg_filters.diff
==============================================================================
--- libavfilter/diffs/04_ffmpeg_filters.diff	(original)
+++ libavfilter/diffs/04_ffmpeg_filters.diff	Mon Dec 24 04:22:10 2007
@@ -1,6 +1,6 @@
 Index: ffmpeg.c
 ===================================================================
---- ffmpeg.c	(revision 11293)
+--- ffmpeg.c	(revision 11312)
 +++ ffmpeg.c	(working copy)
 @@ -36,6 +36,11 @@
  #include "avstring.h"
@@ -37,7 +37,7 @@ Index: ffmpeg.c
  } AVInputStream;
  
  typedef struct AVInputFile {
-@@ -290,6 +304,259 @@
+@@ -290,6 +304,255 @@
  static struct termios oldtty;
  #endif
  
@@ -228,8 +228,6 @@ Index: ffmpeg.c
 +            return -1;
 +        if (avfilter_link(curr_filter, 0, filt_crop, 0))
 +            return -1;
-+        if (avfilter_config_link(curr_filter->outputs[0]))
-+            return -1;
 +        curr_filter = filt_crop;
 +    }
 +
@@ -250,8 +248,6 @@ Index: ffmpeg.c
 +            return -1;
 +        if (avfilter_link(curr_filter, 0, filt_scale, 0))
 +            return -1;
-+        if (avfilter_config_link(curr_filter->outputs[0]))
-+            return -1;
 +        curr_filter = filt_scale;
 +    }
 +
@@ -284,7 +280,7 @@ Index: ffmpeg.c
 +    /* configure all the filter links */
 +    if(avfilter_graph_config_formats(filt_graph_all))
 +        return -1;
-+    if(avfilter_graph_config_links(filt_graph_all))
++    if(avfilter_config_links(ist->out_video_filter))
 +        return -1;
 +
 +    codec->width = ist->out_video_filter->inputs[0]->w;
@@ -297,7 +293,7 @@ Index: ffmpeg.c
  static void term_exit(void)
  {
  #ifdef HAVE_TERMIOS_H
-@@ -635,6 +902,13 @@
+@@ -635,6 +898,13 @@
          frame_hook_process(picture2, dec->pix_fmt, dec->width, dec->height,
                             1000000 * ist->pts / AV_TIME_BASE);
  
@@ -311,7 +307,7 @@ Index: ffmpeg.c
      if (picture != picture2)
          *picture = *picture2;
      *bufp = buf;
-@@ -745,6 +1019,9 @@
+@@ -745,6 +1015,9 @@
      if (nb_frames <= 0)
          return;
  
@@ -321,7 +317,7 @@ Index: ffmpeg.c
      if (ost->video_crop) {
          if (av_picture_crop((AVPicture *)&picture_crop_temp, (AVPicture *)in_picture, dec->pix_fmt, ost->topBand, ost->leftBand) < 0) {
              av_log(NULL, AV_LOG_ERROR, "error cropping picture\n");
-@@ -754,6 +1031,7 @@
+@@ -754,6 +1027,7 @@
      } else {
          formatted_picture = in_picture;
      }
@@ -329,7 +325,7 @@ Index: ffmpeg.c
  
      final_picture = formatted_picture;
      padding_src = formatted_picture;
-@@ -769,12 +1047,14 @@
+@@ -769,12 +1043,14 @@
          }
      }
  
@@ -344,7 +340,7 @@ Index: ffmpeg.c
  
      if (ost->video_pad) {
          av_picture_pad((AVPicture*)final_picture, (AVPicture *)padding_src,
-@@ -1275,6 +1555,10 @@
+@@ -1275,6 +1551,10 @@
                      }
                  }
              }
@@ -355,7 +351,7 @@ Index: ffmpeg.c
          av_free(buffer_to_free);
          /* XXX: allocate the subtitles in the codec ? */
          if (subtitle_to_free) {
-@@ -1680,10 +1964,21 @@
+@@ -1680,10 +1960,21 @@
                          fprintf(stderr, "Cannot get resampling context\n");
                          exit(1);
                      }
@@ -377,7 +373,7 @@ Index: ffmpeg.c
                  break;
              case CODEC_TYPE_SUBTITLE:
                  ost->encoding_needed = 1;
-@@ -3782,6 +4077,9 @@
+@@ -3782,6 +4073,9 @@
  #ifdef CONFIG_VHOOK
      { "vhook", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)add_frame_hooker}, "insert video processing module", "module" },
  #endif

Modified: libavfilter/vf_crop.c
==============================================================================
--- libavfilter/vf_crop.c	(original)
+++ libavfilter/vf_crop.c	Mon Dec 24 04:22:10 2007
@@ -87,7 +87,7 @@ static int config_input(AVFilterLink *li
     crop->cw &= ~((1 << crop->hsub) - 1);
     crop->ch &= ~((1 << crop->vsub) - 1);
 
-    return avfilter_config_link(link->dst->outputs[0]);
+    return 0;
 }
 
 static int config_output(AVFilterLink *link)

Modified: libavfilter/vf_hflip.c
==============================================================================
--- libavfilter/vf_hflip.c	(original)
+++ libavfilter/vf_hflip.c	Mon Dec 24 04:22:10 2007
@@ -33,7 +33,7 @@ static int config_props(AVFilterLink *li
 
     avcodec_get_chroma_sub_sample(link->format, &flip->hsub, &flip->vsub);
 
-    return avfilter_config_link(link->dst->outputs[0]);
+    return 0;
 }
 
 static void draw_slice(AVFilterLink *link, int y, int h)

Modified: libavfilter/vf_overlay.c
==============================================================================
--- libavfilter/vf_overlay.c	(original)
+++ libavfilter/vf_overlay.c	Mon Dec 24 04:22:10 2007
@@ -86,7 +86,7 @@ static int config_input_main(AVFilterLin
 
     /* TODO: unlink the subpicture link if it is using a different format */
 
-    return avfilter_config_link(link->dst->outputs[0]);
+    return 0;
 }
 
 static int config_input_sub(AVFilterLink *link)

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

Modified: libavfilter/vf_vflip.c
==============================================================================
--- libavfilter/vf_vflip.c	(original)
+++ libavfilter/vf_vflip.c	Mon Dec 24 04:22:10 2007
@@ -36,7 +36,7 @@ static int config_input(AVFilterLink *li
 
     avcodec_get_chroma_sub_sample(link->format, &tmp, &flip->vsub);
 
-    return avfilter_config_link(link->dst->outputs[0]);
+    return 0;
 }
 
 static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)



More information about the FFmpeg-soc mailing list