ffmpeg/libavfilter/vsrc_mptestsrc.c

366 lines
12 KiB
C
Raw Normal View History

2011-08-08 14:41:22 +02:00
/*
* Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* @file
* MP test source, ported from MPlayer libmpcodecs/vf_test.c
*/
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "internal.h"
#include "formats.h"
#include "video.h"
2011-08-08 14:41:22 +02:00
#define WIDTH 512
#define HEIGHT 512
enum test_type {
TEST_DC_LUMA,
TEST_DC_CHROMA,
TEST_FREQ_LUMA,
TEST_FREQ_CHROMA,
TEST_AMP_LUMA,
TEST_AMP_CHROMA,
TEST_CBP,
TEST_MV,
TEST_RING1,
TEST_RING2,
TEST_ALL,
TEST_NB
};
typedef struct MPTestContext {
const AVClass *class;
AVRational frame_rate;
int64_t pts, max_pts, duration;
int64_t max_frames;
2011-08-08 14:41:22 +02:00
int hsub, vsub;
int test; ///< test_type
2011-08-08 14:41:22 +02:00
} MPTestContext;
#define OFFSET(x) offsetof(MPTestContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
2011-08-08 14:41:22 +02:00
static const AVOption mptestsrc_options[]= {
{ "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
{ "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
{ "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
{ "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
{ "test", "set test to perform", OFFSET(test), AV_OPT_TYPE_INT, {.i64=TEST_ALL}, 0, INT_MAX, FLAGS, "test" },
{ "t", "set test to perform", OFFSET(test), AV_OPT_TYPE_INT, {.i64=TEST_ALL}, 0, INT_MAX, FLAGS, "test" },
{ "dc_luma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_DC_LUMA}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "dc_chroma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_DC_CHROMA}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "freq_luma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_FREQ_LUMA}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "freq_chroma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_FREQ_CHROMA}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "amp_luma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_AMP_LUMA}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "amp_chroma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_AMP_CHROMA}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "cbp", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_CBP}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "mv", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_MV}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "ring1", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_RING1}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "ring2", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_RING2}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "all", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_ALL}, INT_MIN, INT_MAX, FLAGS, "test" },
{ "max_frames", "Set the maximum number of frames generated for each test", OFFSET(max_frames),
AV_OPT_TYPE_INT64, {.i64 = 30}, 1, INT64_MAX, FLAGS },
{ "m", "Set the maximum number of frames generated for each test", OFFSET(max_frames),
AV_OPT_TYPE_INT64, {.i64 = 30}, 1, INT64_MAX, FLAGS },
{ NULL }
2011-08-08 14:41:22 +02:00
};
AVFILTER_DEFINE_CLASS(mptestsrc);
2011-08-08 14:41:22 +02:00
static double c[64];
static void init_idct(void)
{
int i, j;
for (i = 0; i < 8; i++) {
double s = i == 0 ? sqrt(0.125) : 0.5;
for (j = 0; j < 8; j++)
c[i*8+j] = s*cos((M_PI/8.0)*i*(j+0.5));
}
}
static void idct(uint8_t *dst, int dst_linesize, int src[64])
{
int i, j, k;
double tmp[64];
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
double sum = 0.0;
for (k = 0; k < 8; k++)
sum += c[k*8+j] * src[8*i+k];
tmp[8*i+j] = sum;
}
}
for (j = 0; j < 8; j++) {
for (i = 0; i < 8; i++) {
double sum = 0.0;
for (k = 0; k < 8; k++)
sum += c[k*8+i]*tmp[8*k+j];
dst[dst_linesize*i + j] = av_clip_uint8(lrint(sum));
2011-08-08 14:41:22 +02:00
}
}
}
static void draw_dc(uint8_t *dst, int dst_linesize, int color, int w, int h)
{
int x, y;
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
dst[x + y*dst_linesize] = color;
}
static void draw_basis(uint8_t *dst, int dst_linesize, int amp, int freq, int dc)
{
int src[64];
memset(src, 0, 64*sizeof(int));
src[0] = dc;
if (amp)
src[freq] = amp;
idct(dst, dst_linesize, src);
}
static void draw_cbp(uint8_t *dst[3], int dst_linesize[3], int cbp, int amp, int dc)
{
if (cbp&1) draw_basis(dst[0] , dst_linesize[0], amp, 1, dc);
if (cbp&2) draw_basis(dst[0]+8 , dst_linesize[0], amp, 1, dc);
if (cbp&4) draw_basis(dst[0]+ 8*dst_linesize[0], dst_linesize[0], amp, 1, dc);
if (cbp&8) draw_basis(dst[0]+8+8*dst_linesize[0], dst_linesize[0], amp, 1, dc);
if (cbp&16) draw_basis(dst[1] , dst_linesize[1], amp, 1, dc);
if (cbp&32) draw_basis(dst[2] , dst_linesize[2], amp, 1, dc);
}
static void dc_test(uint8_t *dst, int dst_linesize, int w, int h, int off)
{
const int step = FFMAX(256/(w*h/256), 1);
int x, y, color = off;
for (y = 0; y < h; y += 16) {
for (x = 0; x < w; x += 16) {
draw_dc(dst + x + y*dst_linesize, dst_linesize, color, 8, 8);
color += step;
}
}
}
static void freq_test(uint8_t *dst, int dst_linesize, int off)
{
int x, y, freq = 0;
for (y = 0; y < 8*16; y += 16) {
for (x = 0; x < 8*16; x += 16) {
draw_basis(dst + x + y*dst_linesize, dst_linesize, 4*(96+off), freq, 128*8);
freq++;
}
}
}
static void amp_test(uint8_t *dst, int dst_linesize, int off)
{
int x, y, amp = off;
for (y = 0; y < 16*16; y += 16) {
for (x = 0; x < 16*16; x += 16) {
draw_basis(dst + x + y*dst_linesize, dst_linesize, 4*amp, 1, 128*8);
amp++;
}
}
}
static void cbp_test(uint8_t *dst[3], int dst_linesize[3], int off)
{
int x, y, cbp = 0;
for (y = 0; y < 16*8; y += 16) {
for (x = 0; x < 16*8; x += 16) {
uint8_t *dst1[3];
dst1[0] = dst[0] + x*2 + y*2*dst_linesize[0];
dst1[1] = dst[1] + x + y* dst_linesize[1];
dst1[2] = dst[2] + x + y* dst_linesize[2];
draw_cbp(dst1, dst_linesize, cbp, (64+off)*4, 128*8);
cbp++;
}
}
}
static void mv_test(uint8_t *dst, int dst_linesize, int off)
{
int x, y;
for (y = 0; y < 16*16; y++) {
if (y&16)
continue;
for (x = 0; x < 16*16; x++)
dst[x + y*dst_linesize] = x + off*8/(y/32+1);
}
}
static void ring1_test(uint8_t *dst, int dst_linesize, int off)
{
int x, y, color = 0;
for (y = off; y < 16*16; y += 16) {
for (x = off; x < 16*16; x += 16) {
draw_dc(dst + x + y*dst_linesize, dst_linesize, ((x+y)&16) ? color : -color, 16, 16);
color++;
}
}
}
static void ring2_test(uint8_t *dst, int dst_linesize, int off)
{
int x, y;
for (y = 0; y < 16*16; y++) {
for (x = 0; x < 16*16; x++) {
double d = hypot(x-8*16, y-8*16);
2011-08-08 14:41:22 +02:00
double r = d/20 - (int)(d/20);
if (r < off/30.0) {
dst[x + y*dst_linesize] = 255;
dst[x + y*dst_linesize+256] = 0;
} else {
dst[x + y*dst_linesize] = x;
dst[x + y*dst_linesize+256] = x;
}
}
}
}
static av_cold int init(AVFilterContext *ctx)
2011-08-08 14:41:22 +02:00
{
MPTestContext *test = ctx->priv;
test->max_pts = test->duration >= 0 ?
av_rescale_q(test->duration, AV_TIME_BASE_Q, av_inv_q(test->frame_rate)) : -1;
2011-08-08 14:41:22 +02:00
test->pts = 0;
av_log(ctx, AV_LOG_VERBOSE, "rate:%d/%d duration:%f\n",
test->frame_rate.num, test->frame_rate.den,
test->duration < 0 ? -1 : test->max_pts * av_q2d(av_inv_q(test->frame_rate)));
2011-08-08 14:41:22 +02:00
init_idct();
return 0;
}
static int config_props(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
MPTestContext *test = ctx->priv;
const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(outlink->format);
2011-08-08 14:41:22 +02:00
test->hsub = pix_desc->log2_chroma_w;
test->vsub = pix_desc->log2_chroma_h;
outlink->w = WIDTH;
outlink->h = HEIGHT;
outlink->time_base = av_inv_q(test->frame_rate);
2011-08-08 14:41:22 +02:00
return 0;
}
static int query_formats(AVFilterContext *ctx)
{
Merge commit '716d413c13981da15323c7a3821860536eefdbbb' * commit '716d413c13981da15323c7a3821860536eefdbbb': Replace PIX_FMT_* -> AV_PIX_FMT_*, PixelFormat -> AVPixelFormat Conflicts: doc/examples/muxing.c ffmpeg.h ffmpeg_filter.c ffmpeg_opt.c ffplay.c ffprobe.c libavcodec/8bps.c libavcodec/aasc.c libavcodec/aura.c libavcodec/avcodec.h libavcodec/avs.c libavcodec/bfi.c libavcodec/bmp.c libavcodec/bmpenc.c libavcodec/c93.c libavcodec/cscd.c libavcodec/cyuv.c libavcodec/dpx.c libavcodec/dpxenc.c libavcodec/eatgv.c libavcodec/escape124.c libavcodec/ffv1.c libavcodec/flashsv.c libavcodec/fraps.c libavcodec/h264.c libavcodec/huffyuv.c libavcodec/iff.c libavcodec/imgconvert.c libavcodec/indeo3.c libavcodec/kmvc.c libavcodec/libopenjpegdec.c libavcodec/libopenjpegenc.c libavcodec/libx264.c libavcodec/ljpegenc.c libavcodec/mjpegdec.c libavcodec/mjpegenc.c libavcodec/motionpixels.c libavcodec/mpeg12.c libavcodec/mpeg12enc.c libavcodec/mpeg4videodec.c libavcodec/mpegvideo_enc.c libavcodec/pamenc.c libavcodec/pcxenc.c libavcodec/pgssubdec.c libavcodec/pngdec.c libavcodec/pngenc.c libavcodec/pnm.c libavcodec/pnmdec.c libavcodec/pnmenc.c libavcodec/ptx.c libavcodec/qdrw.c libavcodec/qpeg.c libavcodec/qtrleenc.c libavcodec/raw.c libavcodec/rawdec.c libavcodec/rl2.c libavcodec/sgidec.c libavcodec/sgienc.c libavcodec/snowdec.c libavcodec/snowenc.c libavcodec/sunrast.c libavcodec/targa.c libavcodec/targaenc.c libavcodec/tiff.c libavcodec/tiffenc.c libavcodec/tmv.c libavcodec/truemotion2.c libavcodec/utils.c libavcodec/vb.c libavcodec/vp3.c libavcodec/wnv1.c libavcodec/xl.c libavcodec/xwddec.c libavcodec/xwdenc.c libavcodec/yop.c libavdevice/v4l2.c libavdevice/x11grab.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/buffersrc.c libavfilter/drawutils.c libavfilter/formats.c libavfilter/src_movie.c libavfilter/vf_ass.c libavfilter/vf_drawtext.c libavfilter/vf_fade.c libavfilter/vf_format.c libavfilter/vf_hflip.c libavfilter/vf_lut.c libavfilter/vf_overlay.c libavfilter/vf_pad.c libavfilter/vf_scale.c libavfilter/vf_transpose.c libavfilter/vf_yadif.c libavfilter/video.c libavfilter/vsrc_testsrc.c libavformat/movenc.c libavformat/mxf.h libavformat/utils.c libavformat/yuv4mpeg.c libavutil/imgutils.c libavutil/pixdesc.c libswscale/input.c libswscale/output.c libswscale/swscale_internal.h libswscale/swscale_unscaled.c libswscale/utils.c libswscale/x86/swscale_template.c libswscale/x86/yuv2rgb.c libswscale/x86/yuv2rgb_template.c libswscale/yuv2rgb.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-10-08 20:54:00 +02:00
static const enum AVPixelFormat pix_fmts[] = {
AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE
2011-08-08 14:41:22 +02:00
};
return ff_set_common_formats_from_list(ctx, pix_fmts);
2011-08-08 14:41:22 +02:00
}
static int request_frame(AVFilterLink *outlink)
{
MPTestContext *test = outlink->src->priv;
Merge commit '7e350379f87e7f74420b4813170fe808e2313911' * commit '7e350379f87e7f74420b4813170fe808e2313911': lavfi: switch to AVFrame. Conflicts: doc/filters.texi libavfilter/af_ashowinfo.c libavfilter/audio.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/buffersink.c libavfilter/buffersrc.c libavfilter/buffersrc.h libavfilter/f_select.c libavfilter/f_setpts.c libavfilter/fifo.c libavfilter/split.c libavfilter/src_movie.c libavfilter/version.h libavfilter/vf_aspect.c libavfilter/vf_bbox.c libavfilter/vf_blackframe.c libavfilter/vf_delogo.c libavfilter/vf_drawbox.c libavfilter/vf_drawtext.c libavfilter/vf_fade.c libavfilter/vf_fieldorder.c libavfilter/vf_fps.c libavfilter/vf_frei0r.c libavfilter/vf_gradfun.c libavfilter/vf_hqdn3d.c libavfilter/vf_lut.c libavfilter/vf_overlay.c libavfilter/vf_pad.c libavfilter/vf_scale.c libavfilter/vf_showinfo.c libavfilter/vf_transpose.c libavfilter/vf_vflip.c libavfilter/vf_yadif.c libavfilter/video.c libavfilter/vsrc_testsrc.c libavfilter/yadif.h Following are notes about the merge authorship and various technical details. Michael Niedermayer: * Main merge operation, notably avfilter.c and video.c * Switch to AVFrame: - afade - anullsrc - apad - aresample - blackframe - deshake - idet - il - mandelbrot - mptestsrc - noise - setfield - smartblur - tinterlace * various merge changes and fixes in: - ashowinfo - blackdetect - field - fps - select - testsrc - yadif Nicolas George: * Switch to AVFrame: - make rawdec work with refcounted frames. Adapted from commit 759001c534287a96dc96d1e274665feb7059145d by Anton Khirnov. Also, fix the use of || instead of | in a flags check. - make buffer sink and src, audio and video work all together Clément Bœsch: * Switch to AVFrame: - aevalsrc - alphaextract - blend - cellauto - colormatrix - concat - earwax - ebur128 - edgedetect - geq - histeq - histogram - hue - kerndeint - life - movie - mp (with the help of Michael) - overlay - pad - pan - pp - pp - removelogo - sendcmd - showspectrum - showwaves - silencedetect - stereo3d - subtitles - super2xsai - swapuv - thumbnail - tile Hendrik Leppkes: * Switch to AVFrame: - aconvert - amerge - asetnsamples - atempo - biquads Matthieu Bouron: * Switch to AVFrame - alphamerge - decimate - volumedetect Stefano Sabatini: * Switch to AVFrame: - astreamsync - flite - framestep Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Nicolas George <nicolas.george@normalesup.org> Signed-off-by: Clément Bœsch <ubitux@gmail.com> Signed-off-by: Hendrik Leppkes <h.leppkes@gmail.com> Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com> Signed-off-by: Stefano Sabatini <stefasab@gmail.com> Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-10 01:30:30 +01:00
AVFrame *picref;
int w = WIDTH, h = HEIGHT,
cw = AV_CEIL_RSHIFT(w, test->hsub), ch = AV_CEIL_RSHIFT(h, test->vsub);
uint64_t frame = outlink->frame_count_in / test->max_frames;
uint64_t mod = outlink->frame_count_in % test->max_frames;
2011-08-08 14:41:22 +02:00
enum test_type tt = test->test;
int i;
2011-08-08 14:41:22 +02:00
if (test->max_pts >= 0 && test->pts > test->max_pts)
return AVERROR_EOF;
Merge commit '7e350379f87e7f74420b4813170fe808e2313911' * commit '7e350379f87e7f74420b4813170fe808e2313911': lavfi: switch to AVFrame. Conflicts: doc/filters.texi libavfilter/af_ashowinfo.c libavfilter/audio.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/buffersink.c libavfilter/buffersrc.c libavfilter/buffersrc.h libavfilter/f_select.c libavfilter/f_setpts.c libavfilter/fifo.c libavfilter/split.c libavfilter/src_movie.c libavfilter/version.h libavfilter/vf_aspect.c libavfilter/vf_bbox.c libavfilter/vf_blackframe.c libavfilter/vf_delogo.c libavfilter/vf_drawbox.c libavfilter/vf_drawtext.c libavfilter/vf_fade.c libavfilter/vf_fieldorder.c libavfilter/vf_fps.c libavfilter/vf_frei0r.c libavfilter/vf_gradfun.c libavfilter/vf_hqdn3d.c libavfilter/vf_lut.c libavfilter/vf_overlay.c libavfilter/vf_pad.c libavfilter/vf_scale.c libavfilter/vf_showinfo.c libavfilter/vf_transpose.c libavfilter/vf_vflip.c libavfilter/vf_yadif.c libavfilter/video.c libavfilter/vsrc_testsrc.c libavfilter/yadif.h Following are notes about the merge authorship and various technical details. Michael Niedermayer: * Main merge operation, notably avfilter.c and video.c * Switch to AVFrame: - afade - anullsrc - apad - aresample - blackframe - deshake - idet - il - mandelbrot - mptestsrc - noise - setfield - smartblur - tinterlace * various merge changes and fixes in: - ashowinfo - blackdetect - field - fps - select - testsrc - yadif Nicolas George: * Switch to AVFrame: - make rawdec work with refcounted frames. Adapted from commit 759001c534287a96dc96d1e274665feb7059145d by Anton Khirnov. Also, fix the use of || instead of | in a flags check. - make buffer sink and src, audio and video work all together Clément Bœsch: * Switch to AVFrame: - aevalsrc - alphaextract - blend - cellauto - colormatrix - concat - earwax - ebur128 - edgedetect - geq - histeq - histogram - hue - kerndeint - life - movie - mp (with the help of Michael) - overlay - pad - pan - pp - pp - removelogo - sendcmd - showspectrum - showwaves - silencedetect - stereo3d - subtitles - super2xsai - swapuv - thumbnail - tile Hendrik Leppkes: * Switch to AVFrame: - aconvert - amerge - asetnsamples - atempo - biquads Matthieu Bouron: * Switch to AVFrame - alphamerge - decimate - volumedetect Stefano Sabatini: * Switch to AVFrame: - astreamsync - flite - framestep Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Nicolas George <nicolas.george@normalesup.org> Signed-off-by: Clément Bœsch <ubitux@gmail.com> Signed-off-by: Hendrik Leppkes <h.leppkes@gmail.com> Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com> Signed-off-by: Stefano Sabatini <stefasab@gmail.com> Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-10 01:30:30 +01:00
picref = ff_get_video_buffer(outlink, w, h);
if (!picref)
return AVERROR(ENOMEM);
2011-08-08 14:41:22 +02:00
picref->pts = test->pts++;
// clean image
for (i = 0; i < h; i++)
memset(picref->data[0] + i*picref->linesize[0], 0, w);
for (i = 0; i < ch; i++) {
memset(picref->data[1] + i*picref->linesize[1], 128, cw);
memset(picref->data[2] + i*picref->linesize[2], 128, cw);
}
2011-08-08 14:41:22 +02:00
if (tt == TEST_ALL && mod) /* draw a black frame at the beginning of each test */
tt = frame%(TEST_NB-1);
2011-08-08 14:41:22 +02:00
switch (tt) {
case TEST_DC_LUMA: dc_test(picref->data[0], picref->linesize[0], 256, 256, mod); break;
case TEST_DC_CHROMA: dc_test(picref->data[1], picref->linesize[1], 256, 256, mod); break;
case TEST_FREQ_LUMA: freq_test(picref->data[0], picref->linesize[0], mod); break;
case TEST_FREQ_CHROMA: freq_test(picref->data[1], picref->linesize[1], mod); break;
case TEST_AMP_LUMA: amp_test(picref->data[0], picref->linesize[0], mod); break;
case TEST_AMP_CHROMA: amp_test(picref->data[1], picref->linesize[1], mod); break;
case TEST_CBP: cbp_test(picref->data , picref->linesize , mod); break;
case TEST_MV: mv_test(picref->data[0], picref->linesize[0], mod); break;
case TEST_RING1: ring1_test(picref->data[0], picref->linesize[0], mod); break;
case TEST_RING2: ring2_test(picref->data[0], picref->linesize[0], mod); break;
2011-08-08 14:41:22 +02:00
}
return ff_filter_frame(outlink, picref);
2011-08-08 14:41:22 +02:00
}
static const AVFilterPad mptestsrc_outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_VIDEO,
.request_frame = request_frame,
.config_props = config_props,
},
};
const AVFilter ff_vsrc_mptestsrc = {
.name = "mptestsrc",
.description = NULL_IF_CONFIG_SMALL("Generate various test pattern."),
.priv_size = sizeof(MPTestContext),
.priv_class = &mptestsrc_class,
.init = init,
.inputs = NULL,
2021-08-12 13:05:31 +02:00
FILTER_OUTPUTS(mptestsrc_outputs),
avfilter: Replace query_formats callback with union of list and callback If one looks at the many query_formats callbacks in existence, one will immediately recognize that there is one type of default callback for video and a slightly different default callback for audio: It is "return ff_set_common_formats_from_list(ctx, pix_fmts);" for video with a filter-specific pix_fmts list. For audio, it is the same with a filter-specific sample_fmts list together with ff_set_common_all_samplerates() and ff_set_common_all_channel_counts(). This commit allows to remove the boilerplate query_formats callbacks by replacing said callback with a union consisting the old callback and pointers for pixel and sample format arrays. For the not uncommon case in which these lists only contain a single entry (besides the sentinel) enum AVPixelFormat and enum AVSampleFormat fields are also added to the union to store them directly in the AVFilter, thereby avoiding a relocation. The state of said union will be contained in a new, dedicated AVFilter field (the nb_inputs and nb_outputs fields have been shrunk to uint8_t in order to create a hole for this new field; this is no problem, as the maximum of all the nb_inputs is four; for nb_outputs it is only two). The state's default value coincides with the earlier default of query_formats being unset, namely that the filter accepts all formats (and also sample rates and channel counts/layouts for audio) provided that these properties agree coincide for all inputs and outputs. By using different union members for audio and video filters the type-unsafety of using the same functions for audio and video lists will furthermore be more confined to formats.c than before. When the new fields are used, they will also avoid allocations: Currently something nearly equivalent to ff_default_query_formats() is called after every successful call to a query_formats callback; yet in the common case that the newly allocated AVFilterFormats are not used at all (namely if there are no free links) these newly allocated AVFilterFormats are freed again without ever being used. Filters no longer using the callback will not exhibit this any more. Reviewed-by: Paul B Mahol <onemda@gmail.com> Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-27 12:07:35 +02:00
FILTER_QUERY_FUNC(query_formats),
2011-08-08 14:41:22 +02:00
};