FFmpeg
vsrc_life.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) Stefano Sabatini 2010
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * life video source, based on John Conways' Life Game
24  */
25 
26 /* #define DEBUG */
27 
28 #include "libavutil/file.h"
29 #include "libavutil/internal.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/lfg.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/random_seed.h"
35 #include "libavutil/avstring.h"
36 #include "avfilter.h"
37 #include "filters.h"
38 #include "formats.h"
39 #include "video.h"
40 
41 typedef struct LifeContext {
42  const AVClass *class;
43  int w, h;
44  char *filename;
45  char *rule_str;
46  uint8_t *file_buf;
47  size_t file_bufsize;
48 
49  /**
50  * The two grid state buffers.
51  *
52  * A 0xFF (ALIVE_CELL) value means the cell is alive (or new born), while
53  * the decreasing values from 0xFE to 0 means the cell is dead; the range
54  * of values is used for the slow death effect, or mold (0xFE means dead,
55  * 0xFD means very dead, 0xFC means very very dead... and 0x00 means
56  * definitely dead/mold).
57  */
58  uint8_t *buf[2];
59 
60  uint8_t buf_idx;
61  uint16_t stay_rule; ///< encode the behavior for filled cells
62  uint16_t born_rule; ///< encode the behavior for empty cells
63  uint64_t pts;
67  int stitch;
68  int mold;
69  uint8_t life_color[4];
70  uint8_t death_color[4];
71  uint8_t mold_color[4];
74 } LifeContext;
75 
76 #define ALIVE_CELL 0xFF
77 #define OFFSET(x) offsetof(LifeContext, x)
78 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
79 
80 static const AVOption life_options[] = {
81  { "filename", "set source file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
82  { "f", "set source file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
83  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS },
84  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS },
85  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
86  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
87  { "rule", "set rule", OFFSET(rule_str), AV_OPT_TYPE_STRING, {.str = "B3/S23"}, 0, 0, FLAGS },
88  { "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 },
89  { "ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=1/M_PHI}, 0, 1, FLAGS },
90  { "random_seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT64, {.i64=-1}, -1, UINT32_MAX, FLAGS },
91  { "seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT64, {.i64=-1}, -1, UINT32_MAX, FLAGS },
92  { "stitch", "stitch boundaries", OFFSET(stitch), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
93  { "mold", "set mold speed for dead cells", OFFSET(mold), AV_OPT_TYPE_INT, {.i64=0}, 0, 0xFF, FLAGS },
94  { "life_color", "set life color", OFFSET( life_color), AV_OPT_TYPE_COLOR, {.str="white"}, 0, 0, FLAGS },
95  { "death_color", "set death color", OFFSET(death_color), AV_OPT_TYPE_COLOR, {.str="black"}, 0, 0, FLAGS },
96  { "mold_color", "set mold color", OFFSET( mold_color), AV_OPT_TYPE_COLOR, {.str="black"}, 0, 0, FLAGS },
97  { NULL }
98 };
99 
101 
102 static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule,
103  const char *rule_str, void *log_ctx)
104 {
105  char *tail;
106  const char *p = rule_str;
107  *born_rule = 0;
108  *stay_rule = 0;
109 
110  if (strchr("bBsS", *p)) {
111  /* parse rule as a Born / Stay Alive code, see
112  * http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life */
113  do {
114  uint16_t *rule = (*p == 'b' || *p == 'B') ? born_rule : stay_rule;
115  p++;
116  while (*p >= '0' && *p <= '8') {
117  *rule += 1<<(*p - '0');
118  p++;
119  }
120  if (*p != '/')
121  break;
122  p++;
123  } while (strchr("bBsS", *p));
124 
125  if (*p)
126  goto error;
127  } else {
128  /* parse rule as a number, expressed in the form STAY|(BORN<<9),
129  * where STAY and BORN encode the corresponding 9-bits rule */
130  long int rule = strtol(rule_str, &tail, 10);
131  if (*tail)
132  goto error;
133  *born_rule = ((1<<9)-1) & rule;
134  *stay_rule = rule >> 9;
135  }
136 
137  return 0;
138 
139 error:
140  av_log(log_ctx, AV_LOG_ERROR, "Invalid rule code '%s' provided\n", rule_str);
141  return AVERROR(EINVAL);
142 }
143 
144 #ifdef DEBUG
145 static void show_life_grid(AVFilterContext *ctx)
146 {
147  LifeContext *life = ctx->priv;
148  int i, j;
149 
150  char *line = av_malloc(life->w + 1);
151  if (!line)
152  return;
153  for (i = 0; i < life->h; i++) {
154  for (j = 0; j < life->w; j++)
155  line[j] = life->buf[life->buf_idx][i*life->w + j] == ALIVE_CELL ? '@' : ' ';
156  line[j] = 0;
157  av_log(ctx, AV_LOG_DEBUG, "%3d: %s\n", i, line);
158  }
159  av_free(line);
160 }
161 #endif
162 
164 {
165  LifeContext *life = ctx->priv;
166  char *p;
167  int ret, i, i0, j, h = 0, w, max_w = 0;
168 
169  if ((ret = av_file_map(life->filename, &life->file_buf, &life->file_bufsize,
170  0, ctx)) < 0)
171  return ret;
172  av_freep(&life->filename);
173 
174  /* prescan file to get the number of lines and the maximum width */
175  w = 0;
176  for (i = 0; i < life->file_bufsize; i++) {
177  if (life->file_buf[i] == '\n') {
178  h++; max_w = FFMAX(w, max_w); w = 0;
179  } else {
180  w++;
181  }
182  }
183  av_log(ctx, AV_LOG_DEBUG, "h:%d max_w:%d\n", h, max_w);
184 
185  if (life->w) {
186  if (max_w > life->w || h > life->h) {
188  "The specified size is %dx%d which cannot contain the provided file size of %dx%d\n",
189  life->w, life->h, max_w, h);
190  return AVERROR(EINVAL);
191  }
192  } else {
193  /* size was not specified, set it to size of the grid */
194  life->w = max_w;
195  life->h = h;
196  }
197 
198  if (!(life->buf[0] = av_calloc(life->h * life->w, sizeof(*life->buf[0]))) ||
199  !(life->buf[1] = av_calloc(life->h * life->w, sizeof(*life->buf[1])))) {
200  av_freep(&life->buf[0]);
201  av_freep(&life->buf[1]);
202  return AVERROR(ENOMEM);
203  }
204 
205  /* fill buf[0] */
206  p = life->file_buf;
207  for (i0 = 0, i = (life->h - h)/2; i0 < h; i0++, i++) {
208  for (j = (life->w - max_w)/2;; j++) {
209  av_log(ctx, AV_LOG_DEBUG, "%d:%d %c\n", i, j, *p == '\n' ? 'N' : *p);
210  if (*p == '\n') {
211  p++; break;
212  } else
213  life->buf[0][i*life->w + j] = av_isgraph(*(p++)) ? ALIVE_CELL : 0;
214  }
215  }
216  life->buf_idx = 0;
217 
218  return 0;
219 }
220 
222 {
223  LifeContext *life = ctx->priv;
224  int ret;
225 
226  if (!life->w && !life->filename)
227  av_opt_set(life, "size", "320x240", 0);
228 
229  if ((ret = parse_rule(&life->born_rule, &life->stay_rule, life->rule_str, ctx)) < 0)
230  return ret;
231 
232  if (!life->mold && memcmp(life->mold_color, "\x00\x00\x00", 3))
234  "Mold color is set while mold isn't, ignoring the color.\n");
235 
236  if (!life->filename) {
237  /* fill the grid randomly */
238  int i;
239 
240  if (!(life->buf[0] = av_calloc(life->h * life->w, sizeof(*life->buf[0]))) ||
241  !(life->buf[1] = av_calloc(life->h * life->w, sizeof(*life->buf[1])))) {
242  av_freep(&life->buf[0]);
243  av_freep(&life->buf[1]);
244  return AVERROR(ENOMEM);
245  }
246  if (life->random_seed == -1)
248 
249  av_lfg_init(&life->lfg, life->random_seed);
250 
251  for (i = 0; i < life->w * life->h; i++) {
252  double r = (double)av_lfg_get(&life->lfg) / UINT32_MAX;
253  if (r <= life->random_fill_ratio)
254  life->buf[0][i] = ALIVE_CELL;
255  }
256  life->buf_idx = 0;
257  } else {
258  if ((ret = init_pattern_from_file(ctx)) < 0)
259  return ret;
260  }
261 
263  "s:%dx%d r:%d/%d rule:%s stay_rule:%d born_rule:%d stitch:%d seed:%"PRId64"\n",
264  life->w, life->h, life->frame_rate.num, life->frame_rate.den,
265  life->rule_str, life->stay_rule, life->born_rule, life->stitch,
266  life->random_seed);
267  return 0;
268 }
269 
271 {
272  LifeContext *life = ctx->priv;
273 
274  av_file_unmap(life->file_buf, life->file_bufsize);
275  av_freep(&life->rule_str);
276  av_freep(&life->buf[0]);
277  av_freep(&life->buf[1]);
278 }
279 
280 static int config_props(AVFilterLink *outlink)
281 {
282  LifeContext *life = outlink->src->priv;
283  FilterLink *l = ff_filter_link(outlink);
284 
285  outlink->w = life->w;
286  outlink->h = life->h;
287  outlink->time_base = av_inv_q(life->frame_rate);
288  l->frame_rate = life->frame_rate;
289 
290  return 0;
291 }
292 
294 {
295  LifeContext *life = ctx->priv;
296  int i, j;
297  uint8_t *oldbuf = life->buf[ life->buf_idx];
298  uint8_t *newbuf = life->buf[!life->buf_idx];
299 
300  enum { NW, N, NE, W, E, SW, S, SE };
301 
302  /* evolve the grid */
303  for (i = 0; i < life->h; i++) {
304  for (j = 0; j < life->w; j++) {
305  int pos[8][2], n, alive, cell;
306  if (life->stitch) {
307  pos[NW][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NW][1] = (j-1) < 0 ? life->w-1 : j-1;
308  pos[N ][0] = (i-1) < 0 ? life->h-1 : i-1; pos[N ][1] = j ;
309  pos[NE][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NE][1] = (j+1) == life->w ? 0 : j+1;
310  pos[W ][0] = i ; pos[W ][1] = (j-1) < 0 ? life->w-1 : j-1;
311  pos[E ][0] = i ; pos[E ][1] = (j+1) == life->w ? 0 : j+1;
312  pos[SW][0] = (i+1) == life->h ? 0 : i+1; pos[SW][1] = (j-1) < 0 ? life->w-1 : j-1;
313  pos[S ][0] = (i+1) == life->h ? 0 : i+1; pos[S ][1] = j ;
314  pos[SE][0] = (i+1) == life->h ? 0 : i+1; pos[SE][1] = (j+1) == life->w ? 0 : j+1;
315  } else {
316  pos[NW][0] = (i-1) < 0 ? -1 : i-1; pos[NW][1] = (j-1) < 0 ? -1 : j-1;
317  pos[N ][0] = (i-1) < 0 ? -1 : i-1; pos[N ][1] = j ;
318  pos[NE][0] = (i-1) < 0 ? -1 : i-1; pos[NE][1] = (j+1) == life->w ? -1 : j+1;
319  pos[W ][0] = i ; pos[W ][1] = (j-1) < 0 ? -1 : j-1;
320  pos[E ][0] = i ; pos[E ][1] = (j+1) == life->w ? -1 : j+1;
321  pos[SW][0] = (i+1) == life->h ? -1 : i+1; pos[SW][1] = (j-1) < 0 ? -1 : j-1;
322  pos[S ][0] = (i+1) == life->h ? -1 : i+1; pos[S ][1] = j ;
323  pos[SE][0] = (i+1) == life->h ? -1 : i+1; pos[SE][1] = (j+1) == life->w ? -1 : j+1;
324  }
325 
326  /* compute the number of live neighbor cells */
327  n = (pos[NW][0] == -1 || pos[NW][1] == -1 ? 0 : oldbuf[pos[NW][0]*life->w + pos[NW][1]] == ALIVE_CELL) +
328  (pos[N ][0] == -1 || pos[N ][1] == -1 ? 0 : oldbuf[pos[N ][0]*life->w + pos[N ][1]] == ALIVE_CELL) +
329  (pos[NE][0] == -1 || pos[NE][1] == -1 ? 0 : oldbuf[pos[NE][0]*life->w + pos[NE][1]] == ALIVE_CELL) +
330  (pos[W ][0] == -1 || pos[W ][1] == -1 ? 0 : oldbuf[pos[W ][0]*life->w + pos[W ][1]] == ALIVE_CELL) +
331  (pos[E ][0] == -1 || pos[E ][1] == -1 ? 0 : oldbuf[pos[E ][0]*life->w + pos[E ][1]] == ALIVE_CELL) +
332  (pos[SW][0] == -1 || pos[SW][1] == -1 ? 0 : oldbuf[pos[SW][0]*life->w + pos[SW][1]] == ALIVE_CELL) +
333  (pos[S ][0] == -1 || pos[S ][1] == -1 ? 0 : oldbuf[pos[S ][0]*life->w + pos[S ][1]] == ALIVE_CELL) +
334  (pos[SE][0] == -1 || pos[SE][1] == -1 ? 0 : oldbuf[pos[SE][0]*life->w + pos[SE][1]] == ALIVE_CELL);
335  cell = oldbuf[i*life->w + j];
336  alive = 1<<n & (cell == ALIVE_CELL ? life->stay_rule : life->born_rule);
337  if (alive) *newbuf = ALIVE_CELL; // new cell is alive
338  else if (cell) *newbuf = cell - 1; // new cell is dead and in the process of mold
339  else *newbuf = 0; // new cell is definitely dead
340  ff_dlog(ctx, "i:%d j:%d live_neighbors:%d cell:%d -> cell:%d\n", i, j, n, cell, *newbuf);
341  newbuf++;
342  }
343  }
344 
345  life->buf_idx = !life->buf_idx;
346 }
347 
349 {
350  LifeContext *life = ctx->priv;
351  uint8_t *buf = life->buf[life->buf_idx];
352  int i, j, k;
353 
354  /* fill the output picture with the old grid buffer */
355  for (i = 0; i < life->h; i++) {
356  uint8_t byte = 0;
357  uint8_t *p = picref->data[0] + i * picref->linesize[0];
358  for (k = 0, j = 0; j < life->w; j++) {
359  byte |= (buf[i*life->w+j] == ALIVE_CELL)<<(7-k++);
360  if (k==8 || j == life->w-1) {
361  k = 0;
362  *p++ = byte;
363  byte = 0;
364  }
365  }
366  }
367 }
368 
369 // divide by 255 and round to nearest
370 // apply a fast variant: (X+127)/255 = ((X+127)*257+257)>>16 = ((X+128)*257)>>16
371 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
372 
374 {
375  LifeContext *life = ctx->priv;
376  uint8_t *buf = life->buf[life->buf_idx];
377  int i, j;
378 
379  /* fill the output picture with the old grid buffer */
380  for (i = 0; i < life->h; i++) {
381  uint8_t *p = picref->data[0] + i * picref->linesize[0];
382  for (j = 0; j < life->w; j++) {
383  uint8_t v = buf[i*life->w + j];
384  if (life->mold && v != ALIVE_CELL) {
385  const uint8_t *c1 = life-> mold_color;
386  const uint8_t *c2 = life->death_color;
387  int death_age = FFMIN((0xff - v) * life->mold, 0xff);
388  *p++ = FAST_DIV255((c2[0] << 8) + ((int)c1[0] - (int)c2[0]) * death_age);
389  *p++ = FAST_DIV255((c2[1] << 8) + ((int)c1[1] - (int)c2[1]) * death_age);
390  *p++ = FAST_DIV255((c2[2] << 8) + ((int)c1[2] - (int)c2[2]) * death_age);
391  } else {
392  const uint8_t *c = v == ALIVE_CELL ? life->life_color : life->death_color;
393  AV_WB24(p, c[0]<<16 | c[1]<<8 | c[2]);
394  p += 3;
395  }
396  }
397  }
398 }
399 
400 static int request_frame(AVFilterLink *outlink)
401 {
402  LifeContext *life = outlink->src->priv;
403  AVFrame *picref = ff_get_video_buffer(outlink, life->w, life->h);
404  if (!picref)
405  return AVERROR(ENOMEM);
406  picref->sample_aspect_ratio = (AVRational) {1, 1};
407  picref->pts = life->pts++;
408  picref->duration = 1;
409 
410  life->draw(outlink->src, picref);
411  evolve(outlink->src);
412 #ifdef DEBUG
413  show_life_grid(outlink->src);
414 #endif
415  return ff_filter_frame(outlink, picref);
416 }
417 
419 {
420  LifeContext *life = ctx->priv;
422 
423  if (life->mold || memcmp(life-> life_color, "\xff\xff\xff", 3)
424  || memcmp(life->death_color, "\x00\x00\x00", 3)) {
426  life->draw = fill_picture_rgb;
427  } else {
430  }
431 
433 }
434 
435 static const AVFilterPad life_outputs[] = {
436  {
437  .name = "default",
438  .type = AVMEDIA_TYPE_VIDEO,
439  .request_frame = request_frame,
440  .config_props = config_props,
441  },
442 };
443 
445  .name = "life",
446  .description = NULL_IF_CONFIG_SMALL("Create life."),
447  .priv_size = sizeof(LifeContext),
448  .priv_class = &life_class,
449  .init = init,
450  .uninit = uninit,
451  .inputs = NULL,
454 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:116
LifeContext::rule_str
char * rule_str
Definition: vsrc_life.c:45
config_props
static int config_props(AVFilterLink *outlink)
Definition: vsrc_life.c:280
OFFSET
#define OFFSET(x)
Definition: vsrc_life.c:77
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
r
const char * r
Definition: vf_curves.c:127
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
evolve
static void evolve(AVFilterContext *ctx)
Definition: vsrc_life.c:293
M_PHI
#define M_PHI
Definition: mathematics.h:61
av_lfg_init
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
LifeContext::random_fill_ratio
double random_fill_ratio
Definition: vsrc_life.c:65
LifeContext::frame_rate
AVRational frame_rate
Definition: vsrc_life.c:64
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1023
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:795
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
Definition: opt.h:315
LifeContext::pts
uint64_t pts
Definition: vsrc_life.c:63
int64_t
long long int64_t
Definition: coverity.c:34
LifeContext::mold
int mold
Definition: vsrc_life.c:68
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vsrc_life.c:270
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:501
w
uint8_t w
Definition: llviddspenc.c:38
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vsrc_life.c:418
ALIVE_CELL
#define ALIVE_CELL
Definition: vsrc_life.c:76
AVOption
AVOption.
Definition: opt.h:429
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
c1
static const uint64_t c1
Definition: murmur3.c:52
life_options
static const AVOption life_options[]
Definition: vsrc_life.c:80
video.h
LifeContext::born_rule
uint16_t born_rule
encode the behavior for empty cells
Definition: vsrc_life.c:62
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:410
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
FLAGS
#define FLAGS
Definition: vsrc_life.c:78
av_get_random_seed
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:167
formats.h
S
#define S(s, c, i)
Definition: flacdsp_template.c:46
av_file_map
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
Definition: file.c:55
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:472
LifeContext::random_seed
int64_t random_seed
Definition: vsrc_life.c:66
LifeContext::buf
uint8_t * buf[2]
The two grid state buffers.
Definition: vsrc_life.c:58
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:748
LifeContext::stitch
int stitch
Definition: vsrc_life.c:67
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
LifeContext::lfg
AVLFG lfg
Definition: vsrc_life.c:72
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
SW
#define SW(val, pdst)
Definition: generic_macros_msa.h:167
LifeContext::draw
void(* draw)(AVFilterContext *, AVFrame *)
Definition: vsrc_life.c:73
intreadwrite.h
LifeContext::file_buf
uint8_t * file_buf
Definition: vsrc_life.c:46
av_lfg_get
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
lfg.h
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:873
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
Definition: opt.h:263
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
LifeContext::stay_rule
uint16_t stay_rule
encode the behavior for filled cells
Definition: vsrc_life.c:61
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:49
life_outputs
static const AVFilterPad life_outputs[]
Definition: vsrc_life.c:435
init
static av_cold int init(AVFilterContext *ctx)
Definition: vsrc_life.c:221
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
av_file_unmap
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:142
E
#define E
Definition: avdct.c:33
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
LifeContext::death_color
uint8_t death_color[4]
Definition: vsrc_life.c:70
LifeContext::filename
char * filename
Definition: vsrc_life.c:44
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PIX_FMT_MONOBLACK
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:83
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
Definition: opt.h:323
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition: opt.h:303
double
double
Definition: af_crystalizer.c:132
LifeContext::w
int w
Definition: vsrc_life.c:43
W
@ W
Definition: vf_addroi.c:27
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
parse_rule
static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule, const char *rule_str, void *log_ctx)
Definition: vsrc_life.c:102
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
byte
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
Definition: bytestream.h:99
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(life)
AV_WB24
#define AV_WB24(p, d)
Definition: intreadwrite.h:446
LifeContext::mold_color
uint8_t mold_color[4]
Definition: vsrc_life.c:71
av_isgraph
static av_const int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
Definition: avstring.h:210
init_pattern_from_file
static int init_pattern_from_file(AVFilterContext *ctx)
Definition: vsrc_life.c:163
line
Definition: graph2dot.c:48
LifeContext
Definition: vsrc_life.c:41
N
#define N
Definition: af_mcompand.c:54
ff_vsrc_life
const AVFilter ff_vsrc_life
Definition: vsrc_life.c:444
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
LifeContext::h
int h
Definition: vsrc_life.c:43
internal.h
LifeContext::buf_idx
uint8_t buf_idx
Definition: vsrc_life.c:60
SE
#define SE
Definition: dvdsubenc.c:491
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
AVFilter
Filter definition.
Definition: avfilter.h:201
LifeContext::file_bufsize
size_t file_bufsize
Definition: vsrc_life.c:47
ret
ret
Definition: filter_design.txt:187
pos
unsigned int pos
Definition: spdifenc.c:414
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:496
c2
static const uint64_t c2
Definition: murmur3.c:53
random_seed.h
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: vsrc_life.c:400
file.h
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
fill_picture_monoblack
static void fill_picture_monoblack(AVFilterContext *ctx, AVFrame *picref)
Definition: vsrc_life.c:348
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
FAST_DIV255
#define FAST_DIV255(x)
Definition: vsrc_life.c:371
LifeContext::life_color
uint8_t life_color[4]
Definition: vsrc_life.c:69
fill_picture_rgb
static void fill_picture_rgb(AVFilterContext *ctx, AVFrame *picref)
Definition: vsrc_life.c:373
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:434
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2070
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: filters.h:236