summaryrefslogtreecommitdiff
path: root/libavfilter/vsrc_testsrc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavfilter/vsrc_testsrc.c')
-rw-r--r--libavfilter/vsrc_testsrc.c146
1 files changed, 90 insertions, 56 deletions
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index 6de16768e8..511a546007 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"
@@ -43,14 +42,14 @@
typedef struct {
const AVClass *class;
- int h, w;
+ int w, h;
unsigned int nb_frame;
AVRational time_base;
int64_t pts, max_pts;
- char *size; ///< video frame size
char *rate; ///< video frame rate
char *duration; ///< total duration of the generated video
AVRational sar; ///< sample aspect ratio
+ int nb_decimals;
void (* fill_picture_fn)(AVFilterContext *ctx, AVFilterBufferRef *picref);
@@ -60,17 +59,20 @@ 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(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
+ { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.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 },
+ { "d", "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 },
+ { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
+ { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
{ NULL },
};
-static av_cold int init_common(AVFilterContext *ctx, const char *args)
+static av_cold int init(AVFilterContext *ctx, const char *args)
{
TestSourceContext *test = ctx->priv;
AVRational frame_rate_q;
@@ -84,21 +86,23 @@ static av_cold int init_common(AVFilterContext *ctx, const char *args)
return ret;
}
- if ((ret = av_parse_video_size(&test->w, &test->h, test->size)) < 0) {
- av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", test->size);
- return ret;
- }
-
- if ((ret = av_parse_video_rate(&frame_rate_q, test->rate)) < 0 ||
- frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
+ if ((ret = av_parse_video_rate(&frame_rate_q, test->rate)) < 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->rate);
return ret;
}
+ av_freep(&test->rate);
if ((test->duration) && (ret = av_parse_time(&duration, test->duration, 1)) < 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration);
return ret;
}
+ av_freep(&test->duration);
+
+ if (test->nb_decimals && strcmp(ctx->filter->name, "testsrc")) {
+ av_log(ctx, AV_LOG_WARNING,
+ "Option 'decimals' is ignored with source '%s'\n",
+ ctx->filter->name);
+ }
test->time_base.num = frame_rate_q.den;
test->time_base.den = frame_rate_q.num;
@@ -107,7 +111,7 @@ static av_cold int init_common(AVFilterContext *ctx, const char *args)
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_VERBOSE, "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);
@@ -131,7 +135,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 = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h);
picref->pts = test->pts++;
@@ -139,9 +143,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++;
ff_start_frame(outlink, picref);
ff_draw_slice(outlink, 0, test->h, 1);
@@ -150,19 +154,47 @@ static int request_frame(AVFilterLink *outlink)
return 0;
}
-#if CONFIG_TESTSRC_FILTER
+#if CONFIG_NULLSRC_FILTER
+
+static const AVClass nullsrc_class = {
+ .class_name = "nullsrc",
+ .item_name = av_default_item_name,
+ .option = testsrc_options,
+ .version = LIBAVUTIL_VERSION_INT,
+ .category = AV_CLASS_CATEGORY_FILTER,
+};
+
+static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { }
-static const char *testsrc_get_name(void *ctx)
+static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args)
{
- return "testsrc";
+ TestSourceContext *test = ctx->priv;
+
+ test->class = &nullsrc_class;
+ test->fill_picture_fn = nullsrc_fill_picture;
+ return init(ctx, args);
}
-static const AVClass testsrc_class = {
- .class_name = "TestSourceContext",
- .item_name = testsrc_get_name,
- .option = testsrc_options,
+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
+
+AVFILTER_DEFINE_CLASS(testsrc);
+
/**
* Fill a rectangle with value val.
*
@@ -285,7 +317,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;
@@ -313,15 +345,20 @@ 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];
}
/* draw digits */
seg_size = width / 80;
if (seg_size >= 1 && height >= 13 * seg_size) {
- second = test->nb_frame * test->time_base.num / test->time_base.den;
+ double time = av_q2d(test->time_base) * test->nb_frame *
+ pow(10, test->nb_decimals);
+ if (time > INT_MAX)
+ return;
+ second = (int)time;
x = width - (width - seg_size * 64) / 2;
y = (height - seg_size * 13) / 2;
p = data + (x*3 + y * picref->linesize[0]);
@@ -341,7 +378,7 @@ static av_cold int test_init(AVFilterContext *ctx, const char *args)
test->class = &testsrc_class;
test->fill_picture_fn = test_fill_picture;
- return init_common(ctx, args);
+ return init(ctx, args);
}
static int test_query_formats(AVFilterContext *ctx)
@@ -354,12 +391,12 @@ static int test_query_formats(AVFilterContext *ctx)
}
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 = (const AVFilterPad[]) {{ .name = NULL}},
@@ -374,15 +411,12 @@ AVFilter avfilter_vsrc_testsrc = {
#if CONFIG_RGBTESTSRC_FILTER
-static const char *rgbtestsrc_get_name(void *ctx)
-{
- return "rgbtestsrc";
-}
-
static const AVClass rgbtestsrc_class = {
- .class_name = "RGBTestSourceContext",
- .item_name = rgbtestsrc_get_name,
+ .class_name = "rgbtestsrc",
+ .item_name = av_default_item_name,
.option = testsrc_options,
+ .version = LIBAVUTIL_VERSION_INT,
+ .category = AV_CLASS_CATEGORY_FILTER,
};
#define R 0
@@ -414,7 +448,7 @@ static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
case PIX_FMT_BGRA:
case PIX_FMT_ARGB:
case PIX_FMT_ABGR:
- v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
+ v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
p = dst + 4*x + y*dst_linesize;
AV_WL32(p, v);
break;
@@ -447,7 +481,7 @@ static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args)
test->class = &rgbtestsrc_class;
test->fill_picture_fn = rgbtest_fill_picture;
- return init_common(ctx, args);
+ return init(ctx, args);
}
static int rgbtest_query_formats(AVFilterContext *ctx)
@@ -481,12 +515,12 @@ 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 = (const AVFilterPad[]) {{ .name = NULL}},