Browse code

lavfi: drop the requirement that request_frame returns a frame.

It requires a loop in filters or the framework,
that makes the scheduling less efficient and more complex.
This is purely an internal change since the loop is now
present in buffersink.
Note that no filter except buffersink did rely on the requirement.

Nicolas George authored on 2015/08/26 03:33:48
Showing 4 changed files
... ...
@@ -232,7 +232,8 @@ Frame scheduling
232 232
     one of its inputs, repeatedly until at least one frame has been pushed.
233 233
 
234 234
     Return values:
235
-    if request_frame could produce a frame, it should return 0;
235
+    if request_frame could produce a frame, or at least make progress
236
+    towards producing a frame, it should return 0;
236 237
     if it could not for temporary reasons, it should return AVERROR(EAGAIN);
237 238
     if it could not because there are no more frames, it should return
238 239
     AVERROR_EOF.
... ...
@@ -244,20 +245,18 @@ Frame scheduling
244 244
             push_one_frame();
245 245
             return 0;
246 246
         }
247
-        while (!frame_pushed) {
248
-            input = input_where_a_frame_is_most_needed();
249
-            ret = ff_request_frame(input);
250
-            if (ret == AVERROR_EOF) {
251
-                process_eof_on_input();
252
-            } else if (ret < 0) {
253
-                return ret;
254
-            }
247
+        input = input_where_a_frame_is_most_needed();
248
+        ret = ff_request_frame(input);
249
+        if (ret == AVERROR_EOF) {
250
+            process_eof_on_input();
251
+        } else if (ret < 0) {
252
+            return ret;
255 253
         }
256 254
         return 0;
257 255
 
258 256
     Note that, except for filters that can have queued frames, request_frame
259 257
     does not push frames: it requests them to its input, and as a reaction,
260
-    the filter_frame method will be called and do the work.
258
+    the filter_frame method possibly will be called and do the work.
261 259
 
262 260
 Legacy API
263 261
 ==========
... ...
@@ -347,9 +347,7 @@ int ff_request_frame(AVFilterLink *link)
347 347
 
348 348
     if (link->closed)
349 349
         return AVERROR_EOF;
350
-    av_assert0(!link->frame_requested);
351
-    link->frame_requested = 1;
352
-    while (link->frame_requested) {
350
+    // TODO reindent
353 351
         if (link->srcpad->request_frame)
354 352
             ret = link->srcpad->request_frame(link);
355 353
         else if (link->src->inputs[0])
... ...
@@ -360,14 +358,9 @@ int ff_request_frame(AVFilterLink *link)
360 360
             ret = ff_filter_frame_framed(link, pbuf);
361 361
         }
362 362
         if (ret < 0) {
363
-            link->frame_requested = 0;
364 363
             if (ret == AVERROR_EOF)
365 364
                 link->closed = 1;
366
-        } else {
367
-            av_assert0(!link->frame_requested ||
368
-                       link->flags & FF_LINK_FLAG_REQUEST_LOOP);
369 365
         }
370
-    }
371 366
     return ret;
372 367
 }
373 368
 
... ...
@@ -1088,7 +1081,6 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame)
1088 1088
     }
1089 1089
     ret = filter_frame(link, out);
1090 1090
     link->frame_count++;
1091
-    link->frame_requested = 0;
1092 1091
     ff_update_link_current_pts(link, pts);
1093 1092
     return ret;
1094 1093
 
... ...
@@ -500,12 +500,6 @@ struct AVFilterLink {
500 500
     int channels;
501 501
 
502 502
     /**
503
-     * True if a frame is being requested on the link.
504
-     * Used internally by the framework.
505
-     */
506
-    unsigned frame_requested;
507
-
508
-    /**
509 503
      * Link processing flags.
510 504
      */
511 505
     unsigned flags;
... ...
@@ -102,9 +102,9 @@ struct AVFilterPad {
102 102
     int (*poll_frame)(AVFilterLink *link);
103 103
 
104 104
     /**
105
-     * Frame request callback. A call to this should result in at least one
106
-     * frame being output over the given link. This should return zero on
107
-     * success, and another value on error.
105
+     * Frame request callback. A call to this should result in some progress
106
+     * towards producing output over the given link. This should return zero
107
+     * on success, and another value on error.
108 108
      *
109 109
      * Output pads only.
110 110
      */
... ...
@@ -291,8 +291,11 @@ int ff_poll_frame(AVFilterLink *link);
291 291
  * caller (generally eventually a user application) as this step may (but does
292 292
  * not have to be) necessary to provide the input with the next frame.
293 293
  *
294
- * If a request is successful then the filter_frame() function will be called
295
- * at least once before ff_request_frame() returns
294
+ * If a request is successful then some progress has been made towards
295
+ * providing a frame on the link (through ff_filter_frame()). A filter that
296
+ * needs several frames to produce one is allowed to return success if one
297
+ * more frame has been processed but no output has been produced yet. A
298
+ * filter is also allowed to simply forward a success return value.
296 299
  *
297 300
  * @param link the input link
298 301
  * @return     zero on success