[FFmpeg-devel] [PATCH] lavfi/vsrc_testsrc: switch to activate.

Nicolas George george at nsup.org
Fri Jun 26 16:51:50 EEST 2020


Allow to set the EOF timestamp.

Also: doc/filters/testsrc*: specify the rounding of the duration option.

The changes in the ref files are right.

For filter-fps-down, the graph is testsrc2=r=7:d=3.5,fps=3.
3.5=24.5/7, so the EOF of testsrc2 will have PTS 25/7.
25/7=(10+5/7)/3, so the EOF PTS for fps should be 11/7,
and the output should contain a frame at PTS 10.

For filter-fps-up, the graph is testsrc2=r=3:d=2,fps=7,
for filter-fps-up-round-down and filter-fps-up-round-up
it is the same with explicit rounding options.
But there is no rounding: testsrc2 produces exactly 6 frames
and 2 seconds, fps converts it into exactly 14 frames.

The tests should probably be adjusted to restore them to
a useful coverage.

Signed-off-by: Nicolas George <george at nsup.org>
---
 doc/filters.texi                        |  4 +++
 libavfilter/vsrc_testsrc.c              | 37 +++++++++++++++----------
 tests/ref/fate/filter-fps-down          |  1 +
 tests/ref/fate/filter-fps-up            |  2 ++
 tests/ref/fate/filter-fps-up-round-down |  3 ++
 tests/ref/fate/filter-fps-up-round-up   |  2 ++
 tests/ref/fate/filter-mpdecimate        |  1 +
 7 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 67892e0afb..280e78687d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -22836,6 +22836,10 @@ for the accepted syntax.
 If not specified, or the expressed duration is negative, the video is
 supposed to be generated forever.
 
+Since the frame rate is used as time base, all frames including the last one
+will have their full duration. If the specified duration is not a multiple
+of the frame duration, it will be rounded up.
+
 @item sar
 Set the sample aspect ratio of the sourced video.
 
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index e8c33b00a0..cf9fa4b2b2 100644
--- a/libavfilter/vsrc_testsrc.c
+++ b/libavfilter/vsrc_testsrc.c
@@ -45,6 +45,7 @@
 #include "libavutil/xga_font_data.h"
 #include "avfilter.h"
 #include "drawutils.h"
+#include "filters.h"
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
@@ -138,14 +139,19 @@ static int config_props(AVFilterLink *outlink)
     return 0;
 }
 
-static int request_frame(AVFilterLink *outlink)
+static int activate(AVFilterContext *ctx)
 {
-    TestSourceContext *test = outlink->src->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+    TestSourceContext *test = ctx->priv;
     AVFrame *frame;
 
+    if (!ff_outlink_frame_wanted(outlink))
+        return FFERROR_NOT_READY;
     if (test->duration >= 0 &&
-        av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
-        return AVERROR_EOF;
+        av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration) {
+        ff_outlink_set_status(outlink, AVERROR_EOF, test->pts);
+        return 0;
+    }
 
     if (test->draw_once) {
         if (test->draw_once_reset) {
@@ -250,7 +256,6 @@ static const AVFilterPad color_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = color_config_props,
     },
     {  NULL }
@@ -263,6 +268,7 @@ AVFilter ff_vsrc_color = {
     .priv_size       = sizeof(TestSourceContext),
     .init            = color_init,
     .uninit          = uninit,
+    .activate        = activate,
     .query_formats   = color_query_formats,
     .inputs          = NULL,
     .outputs         = color_outputs,
@@ -384,7 +390,6 @@ static const AVFilterPad haldclutsrc_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = haldclutsrc_config_props,
     },
     {  NULL }
@@ -398,6 +403,7 @@ AVFilter ff_vsrc_haldclutsrc = {
     .init          = haldclutsrc_init,
     .uninit        = uninit,
     .query_formats = haldclutsrc_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = haldclutsrc_outputs,
 };
@@ -422,7 +428,6 @@ static const AVFilterPad nullsrc_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = config_props,
     },
     { NULL },
@@ -433,6 +438,7 @@ AVFilter ff_vsrc_nullsrc = {
     .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
     .init        = nullsrc_init,
     .uninit      = uninit,
+    .activate    = activate,
     .priv_size   = sizeof(TestSourceContext),
     .priv_class  = &nullsrc_class,
     .inputs      = NULL,
@@ -658,7 +664,6 @@ static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = config_props,
     },
     { NULL }
@@ -672,6 +677,7 @@ AVFilter ff_vsrc_testsrc = {
     .init          = test_init,
     .uninit        = uninit,
     .query_formats = test_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = avfilter_vsrc_testsrc_outputs,
 };
@@ -931,7 +937,6 @@ static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = test2_config_props,
     },
     { NULL }
@@ -945,6 +950,7 @@ AVFilter ff_vsrc_testsrc2 = {
     .init          = test2_init,
     .uninit        = uninit,
     .query_formats = test2_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = avfilter_vsrc_testsrc2_outputs,
 };
@@ -1050,7 +1056,6 @@ static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = rgbtest_config_props,
     },
     { NULL }
@@ -1064,6 +1069,7 @@ AVFilter ff_vsrc_rgbtestsrc = {
     .init          = rgbtest_init,
     .uninit        = uninit,
     .query_formats = rgbtest_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = avfilter_vsrc_rgbtestsrc_outputs,
 };
@@ -1226,7 +1232,6 @@ static const AVFilterPad avfilter_vsrc_yuvtestsrc_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = yuvtest_config_props,
     },
     { NULL }
@@ -1240,6 +1245,7 @@ AVFilter ff_vsrc_yuvtestsrc = {
     .init          = yuvtest_init,
     .uninit        = uninit,
     .query_formats = yuvtest_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = avfilter_vsrc_yuvtestsrc_outputs,
 };
@@ -1369,7 +1375,6 @@ static const AVFilterPad smptebars_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = config_props,
     },
     { NULL }
@@ -1417,6 +1422,7 @@ AVFilter ff_vsrc_pal75bars = {
     .init          = pal75bars_init,
     .uninit        = uninit,
     .query_formats = smptebars_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = smptebars_outputs,
 };
@@ -1463,6 +1469,7 @@ AVFilter ff_vsrc_pal100bars = {
     .init          = pal100bars_init,
     .uninit        = uninit,
     .query_formats = smptebars_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = smptebars_outputs,
 };
@@ -1530,6 +1537,7 @@ AVFilter ff_vsrc_smptebars = {
     .init          = smptebars_init,
     .uninit        = uninit,
     .query_formats = smptebars_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = smptebars_outputs,
 };
@@ -1635,6 +1643,7 @@ AVFilter ff_vsrc_smptehdbars = {
     .init          = smptehdbars_init,
     .uninit        = uninit,
     .query_formats = smptebars_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = smptebars_outputs,
 };
@@ -1703,7 +1712,6 @@ static const AVFilterPad avfilter_vsrc_allyuv_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = config_props,
     },
     { NULL }
@@ -1717,6 +1725,7 @@ AVFilter ff_vsrc_allyuv = {
     .init          = allyuv_init,
     .uninit        = uninit,
     .query_formats = allyuv_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = avfilter_vsrc_allyuv_outputs,
 };
@@ -1784,7 +1793,6 @@ static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = allrgb_config_props,
     },
     { NULL }
@@ -1798,6 +1806,7 @@ AVFilter ff_vsrc_allrgb = {
     .init          = allrgb_init,
     .uninit        = uninit,
     .query_formats = allrgb_query_formats,
+    .activate      = activate,
     .inputs        = NULL,
     .outputs       = avfilter_vsrc_allrgb_outputs,
 };
diff --git a/tests/ref/fate/filter-fps-down b/tests/ref/fate/filter-fps-down
index eb8b368985..0b6725f037 100644
--- a/tests/ref/fate/filter-fps-down
+++ b/tests/ref/fate/filter-fps-down
@@ -13,3 +13,4 @@
 0,          7,          7,        1,   115200, 0xc705ccd9
 0,          8,          8,        1,   115200, 0x5635daa5
 0,          9,          9,        1,   115200, 0x7161ef8f
+0,         10,         10,        1,   115200, 0xccf02fed
diff --git a/tests/ref/fate/filter-fps-up b/tests/ref/fate/filter-fps-up
index f1a847864f..dfb957c63a 100644
--- a/tests/ref/fate/filter-fps-up
+++ b/tests/ref/fate/filter-fps-up
@@ -15,3 +15,5 @@
 0,          9,          9,        1,   115200, 0xb0dfacf8
 0,         10,         10,        1,   115200, 0xb0dfacf8
 0,         11,         11,        1,   115200, 0xb0dfacf8
+0,         12,         12,        1,   115200, 0x53d5b181
+0,         13,         13,        1,   115200, 0x53d5b181
diff --git a/tests/ref/fate/filter-fps-up-round-down b/tests/ref/fate/filter-fps-up-round-down
index daecb125e3..b68e4fe972 100644
--- a/tests/ref/fate/filter-fps-up-round-down
+++ b/tests/ref/fate/filter-fps-up-round-down
@@ -14,3 +14,6 @@
 0,          8,          8,        1,   115200, 0x33f15918
 0,          9,          9,        1,   115200, 0xb0dfacf8
 0,         10,         10,        1,   115200, 0xb0dfacf8
+0,         11,         11,        1,   115200, 0x53d5b181
+0,         12,         12,        1,   115200, 0x53d5b181
+0,         13,         13,        1,   115200, 0x53d5b181
diff --git a/tests/ref/fate/filter-fps-up-round-up b/tests/ref/fate/filter-fps-up-round-up
index d69dbf67ff..692c1d6c69 100644
--- a/tests/ref/fate/filter-fps-up-round-up
+++ b/tests/ref/fate/filter-fps-up-round-up
@@ -15,3 +15,5 @@
 0,          9,          9,        1,   115200, 0x33f15918
 0,         10,         10,        1,   115200, 0xb0dfacf8
 0,         11,         11,        1,   115200, 0xb0dfacf8
+0,         12,         12,        1,   115200, 0x53d5b181
+0,         13,         13,        1,   115200, 0x53d5b181
diff --git a/tests/ref/fate/filter-mpdecimate b/tests/ref/fate/filter-mpdecimate
index 9c1dc36562..d438dacc2e 100644
--- a/tests/ref/fate/filter-mpdecimate
+++ b/tests/ref/fate/filter-mpdecimate
@@ -22,3 +22,4 @@
 0,         24,         24,        1,   115200, 0x056d40ca
 0,         26,         26,        1,   115200, 0xa4374737
 0,         27,         27,        1,   115200, 0x3eaa3ae8
+0,         29,         29,        1,   115200, 0x7551e9ee
-- 
2.27.0



More information about the ffmpeg-devel mailing list