58
62
#define OFFSET(x) offsetof(TestSourceContext, x)
60
64
static const AVOption testsrc_options[] = {
61
{ "size", "set video size", OFFSET(size), FF_OPT_TYPE_STRING, {.str = "320x240"}},
62
{ "s", "set video size", OFFSET(size), FF_OPT_TYPE_STRING, {.str = "320x240"}},
63
{ "rate", "set video rate", OFFSET(rate), FF_OPT_TYPE_STRING, {.str = "25"}, },
64
{ "r", "set video rate", OFFSET(rate), FF_OPT_TYPE_STRING, {.str = "25"}, },
65
{ "duration", "set video duration", OFFSET(duration), FF_OPT_TYPE_STRING, {.str = NULL}, },
66
{ "sar", "set video sample aspect ratio", OFFSET(sar), FF_OPT_TYPE_RATIONAL, {1}, 0, INT_MAX },
65
{ "size", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = "320x240"}},
66
{ "s", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = "320x240"}},
67
{ "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, },
68
{ "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, },
69
{ "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, },
70
{ "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl = 1}, 0, INT_MAX },
70
static av_cold int init_common(AVFilterContext *ctx, const char *args, void *opaque)
74
static av_cold int init_common(AVFilterContext *ctx, const char *args)
72
76
TestSourceContext *test = ctx->priv;
73
77
AVRational frame_rate_q;
131
135
if (test->max_pts >= 0 && test->pts > test->max_pts)
132
136
return AVERROR_EOF;
133
picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
137
picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h);
139
return AVERROR(ENOMEM);
135
141
picref->pts = test->pts++;
136
142
picref->pos = -1;
137
143
picref->video->key_frame = 1;
141
147
test->nb_frame++;
142
148
test->fill_picture_fn(outlink->src, picref);
144
avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
145
avfilter_draw_slice(outlink, 0, picref->video->h, 1);
146
avfilter_end_frame(outlink);
147
avfilter_unref_buffer(picref);
150
return ff_filter_frame(outlink, picref);
152
153
#if CONFIG_TESTSRC_FILTER
337
static av_cold int test_init(AVFilterContext *ctx, const char *args, void *opaque)
338
static av_cold int test_init(AVFilterContext *ctx, const char *args)
339
340
TestSourceContext *test = ctx->priv;
341
342
test->class = &testsrc_class;
342
343
test->fill_picture_fn = test_fill_picture;
343
return init_common(ctx, args, opaque);
344
return init_common(ctx, args);
346
347
static int test_query_formats(AVFilterContext *ctx)
348
static const enum PixelFormat pix_fmts[] = {
349
PIX_FMT_RGB24, PIX_FMT_NONE
349
static const enum AVPixelFormat pix_fmts[] = {
350
AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
351
avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
352
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
356
static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
359
.type = AVMEDIA_TYPE_VIDEO,
360
.request_frame = request_frame,
361
.config_props = config_props,
355
366
AVFilter avfilter_vsrc_testsrc = {
356
367
.name = "testsrc",
357
368
.description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
361
372
.query_formats = test_query_formats,
363
.inputs = (AVFilterPad[]) {{ .name = NULL}},
365
.outputs = (AVFilterPad[]) {{ .name = "default",
366
.type = AVMEDIA_TYPE_VIDEO,
367
.request_frame = request_frame,
368
.config_props = config_props, },
376
.outputs = avfilter_vsrc_testsrc_outputs,
372
379
#endif /* CONFIG_TESTSRC_FILTER */
392
399
static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
393
int x, int y, int r, int g, int b, enum PixelFormat fmt,
400
int x, int y, int r, int g, int b, enum AVPixelFormat fmt,
400
case PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
401
case PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
402
case PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
403
case PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
404
case PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
405
case PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
407
case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
408
case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
409
case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
410
case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
411
case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
412
case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
413
case AV_PIX_FMT_RGB24:
414
case AV_PIX_FMT_BGR24:
408
415
v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
409
416
p = dst + 3*x + y*dst_linesize;
419
case AV_PIX_FMT_RGBA:
420
case AV_PIX_FMT_BGRA:
421
case AV_PIX_FMT_ARGB:
422
case AV_PIX_FMT_ABGR:
416
423
v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
417
424
p = dst + 4*x + y*dst_linesize;
443
static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args, void *opaque)
450
static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args)
445
452
TestSourceContext *test = ctx->priv;
447
454
test->class = &rgbtestsrc_class;
448
455
test->fill_picture_fn = rgbtest_fill_picture;
449
return init_common(ctx, args, opaque);
456
return init_common(ctx, args);
452
459
static int rgbtest_query_formats(AVFilterContext *ctx)
454
static const enum PixelFormat pix_fmts[] = {
455
PIX_FMT_RGBA, PIX_FMT_ARGB, PIX_FMT_BGRA, PIX_FMT_ABGR,
456
PIX_FMT_BGR24, PIX_FMT_RGB24,
457
PIX_FMT_RGB444, PIX_FMT_BGR444,
458
PIX_FMT_RGB565, PIX_FMT_BGR565,
459
PIX_FMT_RGB555, PIX_FMT_BGR555,
461
static const enum AVPixelFormat pix_fmts[] = {
462
AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
463
AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
464
AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
465
AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
466
AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
462
avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
469
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
468
475
TestSourceContext *test = outlink->src->priv;
470
477
switch (outlink->format) {
471
case PIX_FMT_ARGB: test->rgba_map[A] = 0; test->rgba_map[R] = 1; test->rgba_map[G] = 2; test->rgba_map[B] = 3; break;
472
case PIX_FMT_ABGR: test->rgba_map[A] = 0; test->rgba_map[B] = 1; test->rgba_map[G] = 2; test->rgba_map[R] = 3; break;
474
case PIX_FMT_RGB24: test->rgba_map[R] = 0; test->rgba_map[G] = 1; test->rgba_map[B] = 2; test->rgba_map[A] = 3; break;
476
case PIX_FMT_BGR24: test->rgba_map[B] = 0; test->rgba_map[G] = 1; test->rgba_map[R] = 2; test->rgba_map[A] = 3; break;
478
case AV_PIX_FMT_ARGB: test->rgba_map[A] = 0; test->rgba_map[R] = 1; test->rgba_map[G] = 2; test->rgba_map[B] = 3; break;
479
case AV_PIX_FMT_ABGR: test->rgba_map[A] = 0; test->rgba_map[B] = 1; test->rgba_map[G] = 2; test->rgba_map[R] = 3; break;
480
case AV_PIX_FMT_RGBA:
481
case AV_PIX_FMT_RGB24: test->rgba_map[R] = 0; test->rgba_map[G] = 1; test->rgba_map[B] = 2; test->rgba_map[A] = 3; break;
482
case AV_PIX_FMT_BGRA:
483
case AV_PIX_FMT_BGR24: test->rgba_map[B] = 0; test->rgba_map[G] = 1; test->rgba_map[R] = 2; test->rgba_map[A] = 3; break;
479
486
return config_props(outlink);
489
static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
492
.type = AVMEDIA_TYPE_VIDEO,
493
.request_frame = request_frame,
494
.config_props = rgbtest_config_props,
482
499
AVFilter avfilter_vsrc_rgbtestsrc = {
483
500
.name = "rgbtestsrc",
484
501
.description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
488
505
.query_formats = rgbtest_query_formats,
490
.inputs = (AVFilterPad[]) {{ .name = NULL}},
492
.outputs = (AVFilterPad[]) {{ .name = "default",
493
.type = AVMEDIA_TYPE_VIDEO,
494
.request_frame = request_frame,
495
.config_props = rgbtest_config_props, },
509
.outputs = avfilter_vsrc_rgbtestsrc_outputs,
499
512
#endif /* CONFIG_RGBTESTSRC_FILTER */