diff options
Diffstat (limited to 'libavfilter/vsrc_testsrc.c')
-rw-r--r-- | libavfilter/vsrc_testsrc.c | 114 |
1 files changed, 77 insertions, 37 deletions
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c index 0f5596b715..1383550e91 100644 --- a/libavfilter/vsrc_testsrc.c +++ b/libavfilter/vsrc_testsrc.c @@ -2,20 +2,20 @@ * Copyright (c) 2007 Nicolas George <nicolas.george@normalesup.org> * Copyright (c) 2011 Stefano Sabatini * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -32,7 +32,6 @@ #include <float.h> -#include "libavutil/mathematics.h" #include "libavutil/opt.h" #include "libavutil/intreadwrite.h" #include "libavutil/parseutils.h" @@ -57,17 +56,17 @@ typedef struct { #define OFFSET(x) offsetof(TestSourceContext, x) -static const AVOption testsrc_options[] = { - { "size", "set video size", OFFSET(size), FF_OPT_TYPE_STRING, {.str = "320x240"}}, - { "s", "set video size", OFFSET(size), FF_OPT_TYPE_STRING, {.str = "320x240"}}, - { "rate", "set video rate", OFFSET(rate), FF_OPT_TYPE_STRING, {.str = "25"}, }, - { "r", "set video rate", OFFSET(rate), FF_OPT_TYPE_STRING, {.str = "25"}, }, - { "duration", "set video duration", OFFSET(duration), FF_OPT_TYPE_STRING, {.str = NULL}, }, - { "sar", "set video sample aspect ratio", OFFSET(sar), FF_OPT_TYPE_RATIONAL, {1}, 0, INT_MAX }, +static const AVOption testsrc_options[]= { + { "size", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = "320x240"}, 0, 0 }, + { "s", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = "320x240"}, 0, 0 }, + { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, + { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, + { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, + { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX }, { NULL }, }; -static av_cold int init_common(AVFilterContext *ctx, const char *args, void *opaque) +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) { TestSourceContext *test = ctx->priv; AVRational frame_rate_q; @@ -104,7 +103,7 @@ static av_cold int init_common(AVFilterContext *ctx, const char *args, void *opa test->nb_frame = 0; test->pts = 0; - av_log(ctx, AV_LOG_DEBUG, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n", + av_log(ctx, AV_LOG_INFO, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n", test->w, test->h, frame_rate_q.num, frame_rate_q.den, duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base), test->sar.num, test->sar.den); @@ -128,7 +127,7 @@ static int request_frame(AVFilterLink *outlink) TestSourceContext *test = outlink->src->priv; AVFilterBufferRef *picref; - if (test->max_pts >= 0 && test->pts > test->max_pts) + if (test->max_pts >= 0 && test->pts >= test->max_pts) return AVERROR_EOF; picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h); @@ -137,9 +136,9 @@ static int request_frame(AVFilterLink *outlink) picref->video->key_frame = 1; picref->video->interlaced = 0; picref->video->pict_type = AV_PICTURE_TYPE_I; - picref->video->pixel_aspect = test->sar; - test->nb_frame++; + picref->video->sample_aspect_ratio = test->sar; test->fill_picture_fn(outlink->src, picref); + test->nb_frame++; avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0)); avfilter_draw_slice(outlink, 0, picref->video->h, 1); @@ -149,6 +148,46 @@ static int request_frame(AVFilterLink *outlink) return 0; } +#if CONFIG_NULLSRC_FILTER + +static const char *nullsrc_get_name(void *ctx) +{ + return "nullsrc"; +} + +static const AVClass nullsrc_class = { + .class_name = "NullSourceContext", + .item_name = nullsrc_get_name, + .option = testsrc_options, +}; + +static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { } + +static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args, void *opaque) +{ + TestSourceContext *test = ctx->priv; + + test->class = &nullsrc_class; + test->fill_picture_fn = nullsrc_fill_picture; + return init(ctx, args, opaque); +} + +AVFilter avfilter_vsrc_nullsrc = { + .name = "nullsrc", + .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."), + .init = nullsrc_init, + .priv_size = sizeof(TestSourceContext), + + .inputs = (const AVFilterPad[]) {{ .name = NULL}}, + .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .request_frame = request_frame, + .config_props = config_props, }, + { .name = NULL}}, +}; + +#endif /* CONFIG_NULLSRC_FILTER */ + #if CONFIG_TESTSRC_FILTER static const char *testsrc_get_name(void *ctx) @@ -284,7 +323,7 @@ static void test_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) } /* draw sliding color line */ - p = data + picref->linesize[0] * height * 3/4; + p0 = p = data + picref->linesize[0] * height * 3/4; grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) % GRADIENT_SIZE; rgrad = 0; @@ -312,8 +351,9 @@ static void test_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) if (grad >= GRADIENT_SIZE) grad -= GRADIENT_SIZE; } + p = p0; for (y = height / 8; y > 0; y--) { - memcpy(p, p - picref->linesize[0], 3 * width); + memcpy(p+picref->linesize[0], p, 3 * width); p += picref->linesize[0]; } @@ -340,7 +380,7 @@ static av_cold int test_init(AVFilterContext *ctx, const char *args, void *opaqu test->class = &testsrc_class; test->fill_picture_fn = test_fill_picture; - return init_common(ctx, args, opaque); + return init(ctx, args, opaque); } static int test_query_formats(AVFilterContext *ctx) @@ -348,21 +388,21 @@ static int test_query_formats(AVFilterContext *ctx) static const enum PixelFormat pix_fmts[] = { PIX_FMT_RGB24, PIX_FMT_NONE }; - avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); + avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); return 0; } AVFilter avfilter_vsrc_testsrc = { - .name = "testsrc", - .description = NULL_IF_CONFIG_SMALL("Generate test pattern."), - .priv_size = sizeof(TestSourceContext), - .init = test_init, + .name = "testsrc", + .description = NULL_IF_CONFIG_SMALL("Generate test pattern."), + .priv_size = sizeof(TestSourceContext), + .init = test_init, - .query_formats = test_query_formats, + .query_formats = test_query_formats, - .inputs = (AVFilterPad[]) {{ .name = NULL}}, + .inputs = (const AVFilterPad[]) {{ .name = NULL}}, - .outputs = (AVFilterPad[]) {{ .name = "default", + .outputs = (const AVFilterPad[]) {{ .name = "default", .type = AVMEDIA_TYPE_VIDEO, .request_frame = request_frame, .config_props = config_props, }, @@ -446,7 +486,7 @@ static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args, void *op test->class = &rgbtestsrc_class; test->fill_picture_fn = rgbtest_fill_picture; - return init_common(ctx, args, opaque); + return init(ctx, args, opaque); } static int rgbtest_query_formats(AVFilterContext *ctx) @@ -459,7 +499,7 @@ static int rgbtest_query_formats(AVFilterContext *ctx) PIX_FMT_RGB555, PIX_FMT_BGR555, PIX_FMT_NONE }; - avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); + avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); return 0; } @@ -480,16 +520,16 @@ static int rgbtest_config_props(AVFilterLink *outlink) } AVFilter avfilter_vsrc_rgbtestsrc = { - .name = "rgbtestsrc", - .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."), - .priv_size = sizeof(TestSourceContext), - .init = rgbtest_init, + .name = "rgbtestsrc", + .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."), + .priv_size = sizeof(TestSourceContext), + .init = rgbtest_init, - .query_formats = rgbtest_query_formats, + .query_formats = rgbtest_query_formats, - .inputs = (AVFilterPad[]) {{ .name = NULL}}, + .inputs = (const AVFilterPad[]) {{ .name = NULL}}, - .outputs = (AVFilterPad[]) {{ .name = "default", + .outputs = (const AVFilterPad[]) {{ .name = "default", .type = AVMEDIA_TYPE_VIDEO, .request_frame = request_frame, .config_props = rgbtest_config_props, }, |