[FFmpeg-devel] [PATCH 2/2] avfilter: remove frame_wanted_out/in

Michael Niedermayer michael at niedermayer.cc
Fri May 27 15:29:17 CEST 2016


The flags are redundant now, but maybe this makes the code
less readable

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavfilter/avfilter.c      |    8 +++-----
 libavfilter/avfilter.h      |   15 ++++++++-------
 libavfilter/avfiltergraph.c |    6 +-----
 libavfilter/buffersink.c    |    2 +-
 4 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index e270628..6ee97bf 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -183,7 +183,7 @@ int avfilter_link_get_channels(AVFilterLink *link)
 #define MAKE_SET_CLEAR_FRAME_WANTED_FUNC(DIR) \
 static void set_frame_wanted_ ## DIR(AVFilterLink *link)\
 {\
-    if (!link->frame_wanted_ ## DIR) {\
+    if (!link->next_link_wanting_frame_ ## DIR) {\
         AVFilterGraph *graph = link->graph;\
         AVFilterLink *next, *prev;\
         next = graph->next_link_wanting_frame_ ## DIR;\
@@ -196,13 +196,12 @@ static void set_frame_wanted_ ## DIR(AVFilterLink *link)\
         prev->prev_link_wanting_frame_ ## DIR = \
         next->prev_link_wanting_frame_ ## DIR = link;\
         graph->next_link_wanting_frame_ ## DIR = link;\
-        link->frame_wanted_ ## DIR = 1;\
     }\
 }\
 \
 static void clear_frame_wanted_ ## DIR(AVFilterLink *link)\
 {\
-    if (link->frame_wanted_ ## DIR) {\
+    if (link->next_link_wanting_frame_ ## DIR) {\
         AVFilterGraph *graph = link->graph;\
         AVFilterLink *prev = link->prev_link_wanting_frame_ ## DIR;\
         AVFilterLink *next = link->next_link_wanting_frame_ ## DIR;\
@@ -211,7 +210,6 @@ static void clear_frame_wanted_ ## DIR(AVFilterLink *link)\
         link->next_link_wanting_frame_ ## DIR = NULL;\
         graph->next_link_wanting_frame_ ## DIR = prev->next_link_wanting_frame_ ## DIR;\
         link->prev_link_wanting_frame_ ## DIR = NULL;\
-        link->frame_wanted_ ## DIR = 0;\
     }\
 }
 
@@ -1207,7 +1205,7 @@ static int ff_filter_frame_needs_framing(AVFilterLink *link, AVFrame *frame)
             ret = ff_filter_frame_framed(link, pbuf);
             pbuf = NULL;
         } else {
-            if (link->frame_wanted_out)
+            if (link->next_link_wanting_frame_out)
                 set_frame_wanted_in(link);
         }
     }
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 7d05f4c..5c08e71 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -538,21 +538,22 @@ struct AVFilterLink {
     void *video_frame_pool;
 
     /**
-     * True if a frame is currently wanted on the input of this filter.
+     * Non NULL if a frame is currently wanted on the input of this filter.
      * Set when ff_request_frame() is called by the output,
      * cleared when the request is handled or forwarded.
+     * This is a double linked circular linked list of all links in the AVFilterGraph
+     * which want a frame in.
      */
-    int frame_wanted_in;
+    AVFilterLink *next_link_wanting_frame_in;
+    AVFilterLink *prev_link_wanting_frame_in;
 
     /**
-     * True if a frame is currently wanted on the output of this filter.
+     * Non NULL if a frame is currently wanted on the output of this filter.
      * Set when ff_request_frame() is called by the output,
      * cleared when a frame is filtered.
+     * This is a double linked circular linked list of all links in the AVFilterGraph
+     * which want a frame out.
      */
-    int frame_wanted_out;
-
-    AVFilterLink *next_link_wanting_frame_in;
-    AVFilterLink *prev_link_wanting_frame_in;
     AVFilterLink *next_link_wanting_frame_out;
     AVFilterLink *prev_link_wanting_frame_out;
 };
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index af6a554..694f776 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -1395,7 +1395,7 @@ int avfilter_graph_request_oldest(AVFilterGraph *graph)
     if (!graph->sink_links_count)
         return AVERROR_EOF;
     av_assert1(oldest->age_index >= 0);
-    while (oldest->frame_wanted_out) {
+    while (oldest->next_link_wanting_frame_out) {
         r = ff_filter_graph_run_once(graph);
         if (r < 0)
             return r;
@@ -1406,14 +1406,10 @@ int avfilter_graph_request_oldest(AVFilterGraph *graph)
 static AVFilterLink *graph_run_once_find_filter(AVFilterGraph *graph)
 {
     AVFilterLink *link = graph->next_link_wanting_frame_in;
-    if (link)
-        av_assert0(link->frame_wanted_in);
     if (!link)
         link = graph->next_link_wanting_frame_out;
     if (link)
         av_assert0(link->graph == graph);
-    if (link)
-        av_assert0(link->frame_wanted_in || link->frame_wanted_out);
 
     return link;
 }
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index 2feb56d..eb5955c 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -140,7 +140,7 @@ int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFr
             return AVERROR(EAGAIN);
         if ((ret = ff_request_frame(inlink)) < 0)
             return ret;
-        while (inlink->frame_wanted_out) {
+        while (inlink->next_link_wanting_frame_out) {
             ret = ff_filter_graph_run_once(ctx->graph);
             if (ret < 0)
                 return ret;
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list