~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavfilter/vsrc_testsrc.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
#include <float.h>
34
34
 
 
35
#include "libavutil/common.h"
35
36
#include "libavutil/mathematics.h"
36
37
#include "libavutil/opt.h"
37
38
#include "libavutil/intreadwrite.h"
38
39
#include "libavutil/parseutils.h"
39
40
#include "avfilter.h"
 
41
#include "formats.h"
 
42
#include "internal.h"
 
43
#include "video.h"
40
44
 
41
45
typedef struct {
42
46
    const AVClass *class;
58
62
#define OFFSET(x) offsetof(TestSourceContext, x)
59
63
 
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 },
67
71
    { NULL },
68
72
};
69
73
 
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)
71
75
{
72
76
    TestSourceContext *test = ctx->priv;
73
77
    AVRational frame_rate_q;
130
134
 
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,
134
 
                                       test->w, test->h);
 
137
    picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h);
 
138
    if (!picref)
 
139
        return AVERROR(ENOMEM);
 
140
 
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);
143
149
 
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);
148
 
 
149
 
    return 0;
 
150
    return ff_filter_frame(outlink, picref);
150
151
}
151
152
 
152
153
#if CONFIG_TESTSRC_FILTER
334
335
    }
335
336
}
336
337
 
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)
338
339
{
339
340
    TestSourceContext *test = ctx->priv;
340
341
 
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);
344
345
}
345
346
 
346
347
static int test_query_formats(AVFilterContext *ctx)
347
348
{
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
350
351
    };
351
 
    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
 
352
    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
352
353
    return 0;
353
354
}
354
355
 
 
356
static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
 
357
    {
 
358
        .name          = "default",
 
359
        .type          = AVMEDIA_TYPE_VIDEO,
 
360
        .request_frame = request_frame,
 
361
        .config_props  = config_props,
 
362
    },
 
363
    { NULL }
 
364
};
 
365
 
355
366
AVFilter avfilter_vsrc_testsrc = {
356
367
    .name          = "testsrc",
357
368
    .description   = NULL_IF_CONFIG_SMALL("Generate test pattern."),
360
371
 
361
372
    .query_formats = test_query_formats,
362
373
 
363
 
    .inputs    = (AVFilterPad[]) {{ .name = NULL}},
 
374
    .inputs    = NULL,
364
375
 
365
 
    .outputs   = (AVFilterPad[]) {{ .name = "default",
366
 
                                    .type = AVMEDIA_TYPE_VIDEO,
367
 
                                    .request_frame = request_frame,
368
 
                                    .config_props  = config_props, },
369
 
                                  { .name = NULL }},
 
376
    .outputs   = avfilter_vsrc_testsrc_outputs,
370
377
};
371
378
 
372
379
#endif /* CONFIG_TESTSRC_FILTER */
390
397
#define A 3
391
398
 
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,
394
401
                              int rgba_map[4])
395
402
{
396
403
    int32_t v;
397
404
    uint8_t *p;
398
405
 
399
406
    switch (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;
406
 
    case PIX_FMT_RGB24:
407
 
    case PIX_FMT_BGR24:
 
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;
410
417
        AV_WL24(p, v);
411
418
        break;
412
 
    case PIX_FMT_RGBA:
413
 
    case PIX_FMT_BGRA:
414
 
    case PIX_FMT_ARGB:
415
 
    case PIX_FMT_ABGR:
 
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;
418
425
        AV_WL32(p, v);
440
447
     }
441
448
}
442
449
 
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)
444
451
{
445
452
    TestSourceContext *test = ctx->priv;
446
453
 
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);
450
457
}
451
458
 
452
459
static int rgbtest_query_formats(AVFilterContext *ctx)
453
460
{
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,
460
 
        PIX_FMT_NONE
 
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,
 
467
        AV_PIX_FMT_NONE
461
468
    };
462
 
    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
 
469
    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
463
470
    return 0;
464
471
}
465
472
 
468
475
    TestSourceContext *test = outlink->src->priv;
469
476
 
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;
473
 
    case PIX_FMT_RGBA:
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;
475
 
    case PIX_FMT_BGRA:
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;
477
484
    }
478
485
 
479
486
    return config_props(outlink);
480
487
}
481
488
 
 
489
static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
 
490
    {
 
491
        .name          = "default",
 
492
        .type          = AVMEDIA_TYPE_VIDEO,
 
493
        .request_frame = request_frame,
 
494
        .config_props  = rgbtest_config_props,
 
495
    },
 
496
    { NULL }
 
497
};
 
498
 
482
499
AVFilter avfilter_vsrc_rgbtestsrc = {
483
500
    .name          = "rgbtestsrc",
484
501
    .description   = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
487
504
 
488
505
    .query_formats = rgbtest_query_formats,
489
506
 
490
 
    .inputs    = (AVFilterPad[]) {{ .name = NULL}},
 
507
    .inputs    = NULL,
491
508
 
492
 
    .outputs   = (AVFilterPad[]) {{ .name = "default",
493
 
                                    .type = AVMEDIA_TYPE_VIDEO,
494
 
                                    .request_frame = request_frame,
495
 
                                    .config_props  = rgbtest_config_props, },
496
 
                                  { .name = NULL }},
 
509
    .outputs   = avfilter_vsrc_rgbtestsrc_outputs,
497
510
};
498
511
 
499
512
#endif /* CONFIG_RGBTESTSRC_FILTER */