summaryrefslogtreecommitdiffstats
path: root/libavfilter/vsrc_testsrc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavfilter/vsrc_testsrc.c')
-rw-r--r--libavfilter/vsrc_testsrc.c132
1 files changed, 93 insertions, 39 deletions
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index 0f5596b..0839a2b 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"
@@ -48,6 +47,7 @@ typedef struct {
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);
@@ -57,17 +57,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(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 },
+ { "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, void *opaque)
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
{
TestSourceContext *test = ctx->priv;
AVRational frame_rate_q;
@@ -97,6 +100,12 @@ static av_cold int init_common(AVFilterContext *ctx, const char *args, void *opa
return ret;
}
+ 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;
test->max_pts = duration >= 0 ?
@@ -104,7 +113,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 +137,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 +146,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 +158,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 +333,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,15 +361,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]);
@@ -340,7 +394,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 +402,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, },
@@ -413,7 +467,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;
@@ -446,7 +500,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 +513,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 +534,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, },
OpenPOWER on IntegriCloud