ffmpeg/libavfilter/vsrc_cellauto.c

337 lines
11 KiB
C
Raw Normal View History

2011-12-08 18:07:52 +01:00
/*
* Copyright (c) Stefano Sabatini 2011
*
* This file is part of FFmpeg.
*
* 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.
*
* 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* cellular automaton video source, based on Stephen Wolfram "experimentus crucis"
*/
/* #define DEBUG */
#include "libavutil/file.h"
#include "libavutil/internal.h"
2011-12-08 18:07:52 +01:00
#include "libavutil/lfg.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/random_seed.h"
#include "libavutil/avstring.h"
2011-12-08 18:07:52 +01:00
#include "avfilter.h"
#include "internal.h"
#include "formats.h"
#include "video.h"
2011-12-08 18:07:52 +01:00
typedef struct CellAutoContext {
2011-12-08 18:07:52 +01:00
const AVClass *class;
int w, h;
char *filename;
char *rule_str;
uint8_t *file_buf;
size_t file_bufsize;
uint8_t *buf;
int buf_prev_row_idx, buf_row_idx;
uint8_t rule;
uint64_t pts;
AVRational frame_rate;
2011-12-08 18:07:52 +01:00
double random_fill_ratio;
int64_t random_seed;
2011-12-08 18:07:52 +01:00
int stitch, scroll, start_full;
int64_t generation; ///< the generation number, starting from 0
AVLFG lfg;
char *pattern;
} CellAutoContext;
#define OFFSET(x) offsetof(CellAutoContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
2011-12-08 18:07:52 +01:00
static const AVOption cellauto_options[] = {
{ "filename", "read initial pattern from file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "f", "read initial pattern from file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "pattern", "set initial pattern", OFFSET(pattern), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "p", "set initial pattern", OFFSET(pattern), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "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 },
{ "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS },
{ "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS },
{ "rule", "set rule", OFFSET(rule), AV_OPT_TYPE_INT, {.i64 = 110}, 0, 255, FLAGS },
{ "random_fill_ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl = 1/M_PHI}, 0, 1, FLAGS },
{ "ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl = 1/M_PHI}, 0, 1, FLAGS },
{ "random_seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT64, {.i64 = -1}, -1, UINT32_MAX, FLAGS },
{ "seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT64, {.i64 = -1}, -1, UINT32_MAX, FLAGS },
{ "scroll", "scroll pattern downward", OFFSET(scroll), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
{ "start_full", "start filling the whole video", OFFSET(start_full), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
{ "full", "start filling the whole video", OFFSET(start_full), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
{ "stitch", "stitch boundaries", OFFSET(stitch), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
{ NULL }
2011-12-08 18:07:52 +01:00
};
AVFILTER_DEFINE_CLASS(cellauto);
2011-12-08 18:07:52 +01:00
#ifdef DEBUG
static void show_cellauto_row(AVFilterContext *ctx)
{
CellAutoContext *s = ctx->priv;
2011-12-08 18:07:52 +01:00
int i;
uint8_t *row = s->buf + s->w * s->buf_row_idx;
char *line = av_malloc(s->w + 1);
2011-12-08 18:07:52 +01:00
if (!line)
return;
for (i = 0; i < s->w; i++)
2011-12-08 18:07:52 +01:00
line[i] = row[i] ? '@' : ' ';
line[i] = 0;
av_log(ctx, AV_LOG_DEBUG, "generation:%"PRId64" row:%s|\n", s->generation, line);
2011-12-08 18:07:52 +01:00
av_free(line);
}
#endif
static int init_pattern_from_string(AVFilterContext *ctx)
{
CellAutoContext *s = ctx->priv;
2011-12-08 18:07:52 +01:00
char *p;
int i, w = 0;
w = strlen(s->pattern);
2011-12-08 18:07:52 +01:00
av_log(ctx, AV_LOG_DEBUG, "w:%d\n", w);
if (s->w) {
if (w > s->w) {
2011-12-08 18:07:52 +01:00
av_log(ctx, AV_LOG_ERROR,
"The specified width is %d which cannot contain the provided string width of %d\n",
s->w, w);
2011-12-08 18:07:52 +01:00
return AVERROR(EINVAL);
}
} else {
/* width was not specified, set it to width of the provided row */
s->w = w;
s->h = (double)s->w * M_PHI;
2011-12-08 18:07:52 +01:00
}
s->buf = av_calloc(s->w, s->h * sizeof(*s->buf));
if (!s->buf)
2011-12-08 18:07:52 +01:00
return AVERROR(ENOMEM);
/* fill buf */
p = s->pattern;
for (i = (s->w - w)/2;; i++) {
2011-12-08 18:07:52 +01:00
av_log(ctx, AV_LOG_DEBUG, "%d %c\n", i, *p == '\n' ? 'N' : *p);
if (*p == '\n' || !*p)
break;
else
s->buf[i] = !!av_isgraph(*(p++));
2011-12-08 18:07:52 +01:00
}
return 0;
}
static int init_pattern_from_file(AVFilterContext *ctx)
{
CellAutoContext *s = ctx->priv;
2011-12-08 18:07:52 +01:00
int ret;
ret = av_file_map(s->filename,
&s->file_buf, &s->file_bufsize, 0, ctx);
2011-12-08 18:07:52 +01:00
if (ret < 0)
return ret;
/* create a string based on the read file */
s->pattern = av_malloc(s->file_bufsize + 1);
if (!s->pattern)
2011-12-08 18:07:52 +01:00
return AVERROR(ENOMEM);
memcpy(s->pattern, s->file_buf, s->file_bufsize);
s->pattern[s->file_bufsize] = 0;
2011-12-08 18:07:52 +01:00
return init_pattern_from_string(ctx);
}
static av_cold int init(AVFilterContext *ctx)
2011-12-08 18:07:52 +01:00
{
CellAutoContext *s = ctx->priv;
2011-12-08 18:07:52 +01:00
int ret;
if (!s->w && !s->filename && !s->pattern)
av_opt_set(s, "size", "320x518", 0);
2011-12-08 18:07:52 +01:00
if (s->filename && s->pattern) {
2011-12-08 18:07:52 +01:00
av_log(ctx, AV_LOG_ERROR, "Only one of the filename or pattern options can be used\n");
return AVERROR(EINVAL);
}
if (s->filename) {
2011-12-08 18:07:52 +01:00
if ((ret = init_pattern_from_file(ctx)) < 0)
return ret;
} else if (s->pattern) {
2011-12-08 18:07:52 +01:00
if ((ret = init_pattern_from_string(ctx)) < 0)
return ret;
} else {
/* fill the first row randomly */
int i;
s->buf = av_calloc(s->w, s->h * sizeof(*s->buf));
if (!s->buf)
2011-12-08 18:07:52 +01:00
return AVERROR(ENOMEM);
if (s->random_seed == -1)
s->random_seed = av_get_random_seed();
2011-12-08 18:07:52 +01:00
av_lfg_init(&s->lfg, s->random_seed);
2011-12-08 18:07:52 +01:00
for (i = 0; i < s->w; i++) {
double r = (double)av_lfg_get(&s->lfg) / UINT32_MAX;
if (r <= s->random_fill_ratio)
s->buf[i] = 1;
2011-12-08 18:07:52 +01:00
}
}
av_log(ctx, AV_LOG_VERBOSE,
"s:%dx%d r:%d/%d rule:%d stitch:%d scroll:%d full:%d seed:%"PRId64"\n",
s->w, s->h, s->frame_rate.num, s->frame_rate.den,
s->rule, s->stitch, s->scroll, s->start_full,
s->random_seed);
2011-12-08 18:07:52 +01:00
return 0;
}
static av_cold void uninit(AVFilterContext *ctx)
{
CellAutoContext *s = ctx->priv;
2011-12-08 18:07:52 +01:00
av_file_unmap(s->file_buf, s->file_bufsize);
av_freep(&s->buf);
av_freep(&s->pattern);
2011-12-08 18:07:52 +01:00
}
static int config_props(AVFilterLink *outlink)
{
CellAutoContext *s = outlink->src->priv;
2011-12-08 18:07:52 +01:00
outlink->w = s->w;
outlink->h = s->h;
outlink->time_base = av_inv_q(s->frame_rate);
2011-12-08 18:07:52 +01:00
return 0;
}
static void evolve(AVFilterContext *ctx)
{
CellAutoContext *s = ctx->priv;
2011-12-08 18:07:52 +01:00
int i, v, pos[3];
uint8_t *row, *prev_row = s->buf + s->buf_row_idx * s->w;
2011-12-08 18:07:52 +01:00
enum { NW, N, NE };
s->buf_prev_row_idx = s->buf_row_idx;
s->buf_row_idx = s->buf_row_idx == s->h-1 ? 0 : s->buf_row_idx+1;
row = s->buf + s->w * s->buf_row_idx;
2011-12-08 18:07:52 +01:00
for (i = 0; i < s->w; i++) {
if (s->stitch) {
pos[NW] = i-1 < 0 ? s->w-1 : i-1;
2011-12-08 18:07:52 +01:00
pos[N] = i;
pos[NE] = i+1 == s->w ? 0 : i+1;
2011-12-08 18:07:52 +01:00
v = prev_row[pos[NW]]<<2 | prev_row[pos[N]]<<1 | prev_row[pos[NE]];
} else {
v = 0;
v|= i-1 >= 0 ? prev_row[i-1]<<2 : 0;
v|= prev_row[i ]<<1 ;
v|= i+1 < s->w ? prev_row[i+1] : 0;
2011-12-08 18:07:52 +01:00
}
row[i] = !!(s->rule & (1<<v));
ff_dlog(ctx, "i:%d context:%c%c%c -> cell:%d\n", i,
2011-12-08 18:07:52 +01:00
v&4?'@':' ', v&2?'@':' ', v&1?'@':' ', row[i]);
}
s->generation++;
2011-12-08 18:07:52 +01:00
}
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
static void fill_picture(AVFilterContext *ctx, AVFrame *picref)
2011-12-08 18:07:52 +01:00
{
CellAutoContext *s = ctx->priv;
2011-12-08 18:07:52 +01:00
int i, j, k, row_idx = 0;
uint8_t *p0 = picref->data[0];
if (s->scroll && s->generation >= s->h)
2011-12-08 18:07:52 +01:00
/* show on top the oldest row */
row_idx = (s->buf_row_idx + 1) % s->h;
2011-12-08 18:07:52 +01:00
/* fill the output picture with the whole buffer */
for (i = 0; i < s->h; i++) {
2011-12-08 18:07:52 +01:00
uint8_t byte = 0;
uint8_t *row = s->buf + row_idx*s->w;
2011-12-08 18:07:52 +01:00
uint8_t *p = p0;
for (k = 0, j = 0; j < s->w; j++) {
2011-12-08 18:07:52 +01:00
byte |= row[j]<<(7-k++);
if (k==8 || j == s->w-1) {
2011-12-08 18:07:52 +01:00
k = 0;
*p++ = byte;
byte = 0;
}
}
row_idx = (row_idx + 1) % s->h;
2011-12-08 18:07:52 +01:00
p0 += picref->linesize[0];
}
}
static int request_frame(AVFilterLink *outlink)
{
CellAutoContext *s = outlink->src->priv;
AVFrame *picref = ff_get_video_buffer(outlink, s->w, s->h);
if (!picref)
return AVERROR(ENOMEM);
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->sample_aspect_ratio = (AVRational) {1, 1};
if (s->generation == 0 && s->start_full) {
2011-12-08 18:07:52 +01:00
int i;
for (i = 0; i < s->h-1; i++)
2011-12-08 18:07:52 +01:00
evolve(outlink->src);
}
fill_picture(outlink->src, picref);
evolve(outlink->src);
picref->pts = s->pts++;
2011-12-08 18:07:52 +01:00
#ifdef DEBUG
show_cellauto_row(outlink->src);
#endif
return ff_filter_frame(outlink, picref);
2011-12-08 18:07:52 +01:00
}
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_MONOBLACK, AV_PIX_FMT_NONE };
return ff_set_common_formats_from_list(ctx, pix_fmts);
2011-12-08 18:07:52 +01:00
}
static const AVFilterPad cellauto_outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_VIDEO,
.request_frame = request_frame,
.config_props = config_props,
},
};
const AVFilter ff_vsrc_cellauto = {
.name = "cellauto",
.description = NULL_IF_CONFIG_SMALL("Create pattern generated by an elementary cellular automaton."),
.priv_size = sizeof(CellAutoContext),
.priv_class = &cellauto_class,
.init = init,
.uninit = uninit,
.inputs = NULL,
2021-08-12 13:05:31 +02:00
FILTER_OUTPUTS(cellauto_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-12-08 18:07:52 +01:00
};