FFmpeg  4.4.9
vf_datascope.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Paul B Mahol
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 #include "libavutil/avassert.h"
22 #include "libavutil/intreadwrite.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/parseutils.h"
25 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "filters.h"
29 #include "drawutils.h"
30 #include "formats.h"
31 #include "internal.h"
32 #include "video.h"
33 
34 typedef struct DatascopeContext {
35  const AVClass *class;
36  int ow, oh;
37  int x, y;
38  int mode;
39  int dformat;
40  int axis;
42  float opacity;
43 
44  int nb_planes;
45  int nb_comps;
46  int chars;
52 
55  int (*filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
57 
58 #define OFFSET(x) offsetof(DatascopeContext, x)
59 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
60 #define FLAGSR AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
61 
62 static const AVOption datascope_options[] = {
63  { "size", "set output size", OFFSET(ow), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, 0, 0, FLAGS },
64  { "s", "set output size", OFFSET(ow), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, 0, 0, FLAGS },
65  { "x", "set x offset", OFFSET(x), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGSR },
66  { "y", "set y offset", OFFSET(y), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGSR },
67  { "mode", "set scope mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGSR, "mode" },
68  { "mono", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGSR, "mode" },
69  { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGSR, "mode" },
70  { "color2", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGSR, "mode" },
71  { "axis", "draw column/row numbers", OFFSET(axis), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGSR },
72  { "opacity", "set background opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGSR },
73  { "format", "set display number format", OFFSET(dformat), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGSR, "format" },
74  { "hex", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGSR, "format" },
75  { "dec", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGSR, "format" },
76  { "components", "set components to display", OFFSET(components), AV_OPT_TYPE_INT, {.i64=15}, 1, 15, FLAGSR },
77  { NULL }
78 };
79 
81 
83 {
85 }
86 
88  int x0, int y0, const uint8_t *text, int vertical)
89 {
90  int x = x0;
91 
92  for (; *text; text++) {
93  if (*text == '\n') {
94  x = x0;
95  y0 += 8;
96  continue;
97  }
100  avpriv_cga_font + *text * 8, 1, 8, 8, 0, 0, x, y0);
101  if (vertical) {
102  x = x0;
103  y0 += 8;
104  } else {
105  x += 8;
106  }
107  }
108 }
109 
110 static void pick_color8(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value)
111 {
112  int p, i;
113 
114  color->rgba[3] = 255;
115  for (p = 0; p < draw->nb_planes; p++) {
116  if (draw->nb_planes == 1) {
117  for (i = 0; i < 4; i++) {
118  value[i] = in->data[0][y * in->linesize[0] + x * draw->pixelstep[0] + i];
119  color->comp[0].u8[i] = value[i];
120  }
121  } else {
122  value[p] = in->data[p][(y >> draw->vsub[p]) * in->linesize[p] + (x >> draw->hsub[p])];
123  color->comp[p].u8[0] = value[p];
124  }
125  }
126 }
127 
128 static void pick_color16(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value)
129 {
130  int p, i;
131 
132  color->rgba[3] = 255;
133  for (p = 0; p < draw->nb_planes; p++) {
134  if (draw->nb_planes == 1) {
135  for (i = 0; i < 4; i++) {
136  value[i] = AV_RL16(in->data[0] + y * in->linesize[0] + x * draw->pixelstep[0] + i * 2);
137  color->comp[0].u16[i] = value[i];
138  }
139  } else {
140  value[p] = AV_RL16(in->data[p] + (y >> draw->vsub[p]) * in->linesize[p] + (x >> draw->hsub[p]) * 2);
141  color->comp[p].u16[0] = value[p];
142  }
143  }
144 }
145 
147 {
148  int p;
149 
150  reverse->rgba[3] = 255;
151  for (p = 0; p < draw->nb_planes; p++) {
152  reverse->comp[p].u8[0] = color->comp[p].u8[0] > 127 ? 0 : 255;
153  reverse->comp[p].u8[1] = color->comp[p].u8[1] > 127 ? 0 : 255;
154  reverse->comp[p].u8[2] = color->comp[p].u8[2] > 127 ? 0 : 255;
155  }
156 }
157 
159 {
160  int p;
161 
162  reverse->rgba[3] = 255;
163  for (p = 0; p < draw->nb_planes; p++) {
164  const unsigned max = (1 << draw->desc->comp[p].depth) - 1;
165  const unsigned mid = (max + 1) / 2;
166 
167  reverse->comp[p].u16[0] = color->comp[p].u16[0] > mid ? 0 : max;
168  reverse->comp[p].u16[1] = color->comp[p].u16[1] > mid ? 0 : max;
169  reverse->comp[p].u16[2] = color->comp[p].u16[2] > mid ? 0 : max;
170  }
171 }
172 
173 typedef struct ThreadData {
174  AVFrame *in, *out;
175  int xoff, yoff, PP;
176 } ThreadData;
177 
178 static int filter_color2(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
179 {
180  DatascopeContext *s = ctx->priv;
181  AVFilterLink *outlink = ctx->outputs[0];
182  AVFilterLink *inlink = ctx->inputs[0];
183  ThreadData *td = arg;
184  AVFrame *in = td->in;
185  AVFrame *out = td->out;
186  const int PP = td->PP;
187  const int xoff = td->xoff;
188  const int yoff = td->yoff;
189  const int P = FFMAX(s->nb_planes, s->nb_comps);
190  const int C = s->chars;
191  const int D = ((s->chars - s->dformat) >> 2) + s->dformat * 2;
192  const int W = (outlink->w - xoff) / (C * 10);
193  const int H = (outlink->h - yoff) / (PP * 12);
194  const char *format[4] = {"%02X\n", "%04X\n", "%03d\n", "%05d\n"};
195  const int slice_start = ff_slice_pos(W, jobnr, nb_jobs);
196  const int slice_end = ff_slice_pos(W, jobnr + 1, nb_jobs);
197  int x, y, p;
198 
199  for (y = 0; y < H && (y + s->y < inlink->h); y++) {
200  for (x = slice_start; x < slice_end && (x + s->x < inlink->w); x++) {
201  FFDrawColor color = { { 0 } };
202  FFDrawColor reverse = { { 0 } };
203  int value[4] = { 0 }, pp = 0;
204 
205  s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value);
206  s->reverse_color(&s->draw, &color, &reverse);
207  ff_fill_rectangle(&s->draw, &color, out->data, out->linesize,
208  xoff + x * C * 10, yoff + y * PP * 12, C * 10, PP * 12);
209 
210  for (p = 0; p < P; p++) {
211  char text[256];
212 
213  if (!(s->components & (1 << p)))
214  continue;
215  snprintf(text, sizeof(text), format[D], value[p]);
216  draw_text(&s->draw, out, &reverse, xoff + x * C * 10 + 2, yoff + y * PP * 12 + pp * 10 + 2, text, 0);
217  pp++;
218  }
219  }
220  }
221 
222  return 0;
223 }
224 
225 static int filter_color(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
226 {
227  DatascopeContext *s = ctx->priv;
228  AVFilterLink *outlink = ctx->outputs[0];
229  AVFilterLink *inlink = ctx->inputs[0];
230  ThreadData *td = arg;
231  AVFrame *in = td->in;
232  AVFrame *out = td->out;
233  const int PP = td->PP;
234  const int xoff = td->xoff;
235  const int yoff = td->yoff;
236  const int P = FFMAX(s->nb_planes, s->nb_comps);
237  const int C = s->chars;
238  const int D = ((s->chars - s->dformat) >> 2) + s->dformat * 2;
239  const int W = (outlink->w - xoff) / (C * 10);
240  const int H = (outlink->h - yoff) / (PP * 12);
241  const char *format[4] = {"%02X\n", "%04X\n", "%03d\n", "%05d\n"};
242  const int slice_start = ff_slice_pos(W, jobnr, nb_jobs);
243  const int slice_end = ff_slice_pos(W, jobnr + 1, nb_jobs);
244  int x, y, p;
245 
246  for (y = 0; y < H && (y + s->y < inlink->h); y++) {
247  for (x = slice_start; x < slice_end && (x + s->x < inlink->w); x++) {
248  FFDrawColor color = { { 0 } };
249  int value[4] = { 0 }, pp = 0;
250 
251  s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value);
252 
253  for (p = 0; p < P; p++) {
254  char text[256];
255 
256  if (!(s->components & (1 << p)))
257  continue;
258  snprintf(text, sizeof(text), format[D], value[p]);
259  draw_text(&s->draw, out, &color, xoff + x * C * 10 + 2, yoff + y * PP * 12 + pp * 10 + 2, text, 0);
260  pp++;
261  }
262  }
263  }
264 
265  return 0;
266 }
267 
268 static int filter_mono(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
269 {
270  DatascopeContext *s = ctx->priv;
271  AVFilterLink *outlink = ctx->outputs[0];
272  AVFilterLink *inlink = ctx->inputs[0];
273  ThreadData *td = arg;
274  AVFrame *in = td->in;
275  AVFrame *out = td->out;
276  const int PP = td->PP;
277  const int xoff = td->xoff;
278  const int yoff = td->yoff;
279  const int P = FFMAX(s->nb_planes, s->nb_comps);
280  const int C = s->chars;
281  const int D = ((s->chars - s->dformat) >> 2) + s->dformat * 2;
282  const int W = (outlink->w - xoff) / (C * 10);
283  const int H = (outlink->h - yoff) / (PP * 12);
284  const char *format[4] = {"%02X\n", "%04X\n", "%03d\n", "%05d\n"};
285  const int slice_start = ff_slice_pos(W, jobnr, nb_jobs);
286  const int slice_end = ff_slice_pos(W, jobnr + 1, nb_jobs);
287  int x, y, p;
288 
289  for (y = 0; y < H && (y + s->y < inlink->h); y++) {
290  for (x = slice_start; x < slice_end && (x + s->x < inlink->w); x++) {
291  FFDrawColor color = { { 0 } };
292  int value[4] = { 0 }, pp = 0;
293 
294  s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value);
295  for (p = 0; p < P; p++) {
296  char text[256];
297 
298  if (!(s->components & (1 << p)))
299  continue;
300  snprintf(text, sizeof(text), format[D], value[p]);
301  draw_text(&s->draw, out, &s->white, xoff + x * C * 10 + 2, yoff + y * PP * 12 + pp * 10 + 2, text, 0);
302  pp++;
303  }
304  }
305  }
306 
307  return 0;
308 }
309 
310 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
311 {
312  AVFilterContext *ctx = inlink->dst;
313  DatascopeContext *s = ctx->priv;
314  AVFilterLink *outlink = ctx->outputs[0];
315  const int P = FFMAX(s->nb_planes, s->nb_comps);
316  ThreadData td = { 0 };
317  int ymaxlen = 0;
318  int xmaxlen = 0;
319  int PP = 0;
320  AVFrame *out;
321 
322  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
323  if (!out) {
324  av_frame_free(&in);
325  return AVERROR(ENOMEM);
326  }
327  out->pts = in->pts;
328 
329  ff_fill_rectangle(&s->draw, &s->black, out->data, out->linesize,
330  0, 0, outlink->w, outlink->h);
331 
332  for (int p = 0; p < P; p++) {
333  if (s->components & (1 << p))
334  PP++;
335  }
336  PP = FFMAX(PP, 1);
337 
338  if (s->axis) {
339  const int C = s->chars;
340  int Y = outlink->h / (PP * 12);
341  int X = outlink->w / (C * 10);
342  char text[256] = { 0 };
343  int x, y;
344 
345  snprintf(text, sizeof(text), "%d", s->y + Y);
346  ymaxlen = strlen(text);
347  ymaxlen *= 10;
348  snprintf(text, sizeof(text), "%d", s->x + X);
349  xmaxlen = strlen(text);
350  xmaxlen *= 10;
351 
352  Y = (outlink->h - xmaxlen) / (PP * 12);
353  X = (outlink->w - ymaxlen) / (C * 10);
354 
355  for (y = 0; y < Y; y++) {
356  snprintf(text, sizeof(text), "%d", s->y + y);
357 
358  ff_fill_rectangle(&s->draw, &s->gray, out->data, out->linesize,
359  0, xmaxlen + y * PP * 12 + (PP + 1) * PP - 2, ymaxlen, 10);
360 
361  draw_text(&s->draw, out, &s->yellow, 2, xmaxlen + y * PP * 12 + (PP + 1) * PP, text, 0);
362  }
363 
364  for (x = 0; x < X; x++) {
365  snprintf(text, sizeof(text), "%d", s->x + x);
366 
367  ff_fill_rectangle(&s->draw, &s->gray, out->data, out->linesize,
368  ymaxlen + x * C * 10 + 2 * C - 2, 0, 10, xmaxlen);
369 
370  draw_text(&s->draw, out, &s->yellow, ymaxlen + x * C * 10 + 2 * C, 2, text, 1);
371  }
372  }
373 
374  td.in = in; td.out = out, td.yoff = xmaxlen, td.xoff = ymaxlen, td.PP = PP;
375  ctx->internal->execute(ctx, s->filter, &td, NULL, FFMIN(ff_filter_get_nb_threads(ctx), FFMAX(outlink->w / 20, 1)));
376 
377  av_frame_free(&in);
378  return ff_filter_frame(outlink, out);
379 }
380 
381 static int config_input(AVFilterLink *inlink)
382 {
383  AVFilterContext *ctx = inlink->dst;
384  DatascopeContext *s = ctx->priv;
385 
386  uint8_t alpha = s->opacity * 255;
387  int ret;
388 
389  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
390  ret = ff_draw_init(&s->draw, inlink->format, 0);
391  if (ret < 0) {
392  av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
393  return ret;
394  }
395  ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
396  ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, alpha} );
397  ff_draw_color(&s->draw, &s->yellow, (uint8_t[]){ 255, 255, 0, 255} );
398  ff_draw_color(&s->draw, &s->gray, (uint8_t[]){ 77, 77, 77, 255} );
399  s->chars = (s->draw.desc->comp[0].depth + 7) / 8 * 2 + s->dformat;
400  s->nb_comps = s->draw.desc->nb_components;
401 
402  switch (s->mode) {
403  case 0: s->filter = filter_mono; break;
404  case 1: s->filter = filter_color; break;
405  case 2: s->filter = filter_color2; break;
406  }
407 
408  if (s->draw.desc->comp[0].depth <= 8) {
409  s->pick_color = pick_color8;
410  s->reverse_color = reverse_color8;
411  } else {
412  s->pick_color = pick_color16;
413  s->reverse_color = reverse_color16;
414  }
415 
416  return 0;
417 }
418 
419 static int config_output(AVFilterLink *outlink)
420 {
421  DatascopeContext *s = outlink->src->priv;
422 
423  outlink->h = s->oh;
424  outlink->w = s->ow;
425  outlink->sample_aspect_ratio = (AVRational){1,1};
426 
427  return 0;
428 }
429 
430 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
431  char *res, int res_len, int flags)
432 {
433  int ret;
434 
435  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
436  if (ret < 0)
437  return ret;
438 
439  return config_input(ctx->inputs[0]);
440 }
441 
442 static const AVFilterPad inputs[] = {
443  {
444  .name = "default",
445  .type = AVMEDIA_TYPE_VIDEO,
446  .filter_frame = filter_frame,
447  .config_props = config_input,
448  },
449  { NULL }
450 };
451 
452 static const AVFilterPad outputs[] = {
453  {
454  .name = "default",
455  .type = AVMEDIA_TYPE_VIDEO,
456  .config_props = config_output,
457  },
458  { NULL }
459 };
460 
462  .name = "datascope",
463  .description = NULL_IF_CONFIG_SMALL("Video data analysis."),
464  .priv_size = sizeof(DatascopeContext),
465  .priv_class = &datascope_class,
467  .inputs = inputs,
468  .outputs = outputs,
471 };
472 
473 typedef struct PixscopeContext {
474  const AVClass *class;
475 
476  float xpos, ypos;
477  float wx, wy;
478  int w, h;
479  float o;
480 
481  int x, y;
482  int ww, wh;
483 
485  int nb_comps;
486  int is_rgb;
496 
497  uint16_t values[4][80][80];
498 
501 
502 #define POFFSET(x) offsetof(PixscopeContext, x)
503 
504 static const AVOption pixscope_options[] = {
505  { "x", "set scope x offset", POFFSET(xpos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
506  { "y", "set scope y offset", POFFSET(ypos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
507  { "w", "set scope width", POFFSET(w), AV_OPT_TYPE_INT, {.i64=7}, 1, 80, FLAGSR },
508  { "h", "set scope height", POFFSET(h), AV_OPT_TYPE_INT, {.i64=7}, 1, 80, FLAGSR },
509  { "o", "set window opacity", POFFSET(o), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
510  { "wx", "set window x offset", POFFSET(wx), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 1, FLAGSR },
511  { "wy", "set window y offset", POFFSET(wy), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 1, FLAGSR },
512  { NULL }
513 };
514 
516 
518 {
519  AVFilterContext *ctx = inlink->dst;
520  PixscopeContext *s = ctx->priv;
521  int ret;
522 
523  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
524  ret = ff_draw_init(&s->draw, inlink->format, 0);
525  if (ret < 0) {
526  av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
527  return ret;
528  }
529  ff_draw_color(&s->draw, &s->dark, (uint8_t[]){ 0, 0, 0, s->o * 255} );
530  ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, 255} );
531  ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
532  ff_draw_color(&s->draw, &s->green, (uint8_t[]){ 0, 255, 0, 255} );
533  ff_draw_color(&s->draw, &s->blue, (uint8_t[]){ 0, 0, 255, 255} );
534  ff_draw_color(&s->draw, &s->red, (uint8_t[]){ 255, 0, 0, 255} );
535  s->nb_comps = s->draw.desc->nb_components;
536  s->is_rgb = s->draw.desc->flags & AV_PIX_FMT_FLAG_RGB;
537 
538  if (s->is_rgb) {
539  s->colors[0] = &s->red;
540  s->colors[1] = &s->green;
541  s->colors[2] = &s->blue;
542  s->colors[3] = &s->white;
543  ff_fill_rgba_map(s->rgba_map, inlink->format);
544  } else {
545  s->colors[0] = &s->white;
546  s->colors[1] = &s->blue;
547  s->colors[2] = &s->red;
548  s->colors[3] = &s->white;
549  s->rgba_map[0] = 0;
550  s->rgba_map[1] = 1;
551  s->rgba_map[2] = 2;
552  s->rgba_map[3] = 3;
553  }
554 
555  if (s->draw.desc->comp[0].depth <= 8) {
556  s->pick_color = pick_color8;
557  } else {
558  s->pick_color = pick_color16;
559  }
560 
561  if (inlink->w < 640 || inlink->h < 480) {
562  av_log(inlink->dst, AV_LOG_ERROR, "min supported resolution is 640x480\n");
563  return AVERROR(EINVAL);
564  }
565 
566  s->ww = 300;
567  s->wh = 300 * 1.6;
568  s->x = s->xpos * (inlink->w - 1);
569  s->y = s->ypos * (inlink->h - 1);
570  if (s->x + s->w >= inlink->w || s->y + s->h >= inlink->h) {
571  av_log(inlink->dst, AV_LOG_WARNING, "scope position is out of range, clipping\n");
572  s->x = FFMIN(s->x, inlink->w - s->w);
573  s->y = FFMIN(s->y, inlink->h - s->h);
574  }
575 
576  return 0;
577 }
578 
579 #define SQR(x) ((x)*(x))
580 
582 {
583  AVFilterContext *ctx = inlink->dst;
584  PixscopeContext *s = ctx->priv;
585  AVFilterLink *outlink = ctx->outputs[0];
586  AVFrame *out = ff_get_video_buffer(outlink, in->width, in->height);
587  int max[4] = { 0 }, min[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };
588  float average[4] = { 0 };
589  double std[4] = { 0 }, rms[4] = { 0 };
590  const char rgba[4] = { 'R', 'G', 'B', 'A' };
591  const char yuva[4] = { 'Y', 'U', 'V', 'A' };
592  int x, y, X, Y, i, w, h;
593  char text[128];
594 
595  if (!out) {
596  av_frame_free(&in);
597  return AVERROR(ENOMEM);
598  }
600  av_frame_copy(out, in);
601 
602  w = s->ww / s->w;
603  h = s->ww / s->h;
604 
605  if (s->wx >= 0) {
606  X = (in->width - s->ww) * s->wx;
607  } else {
608  X = (in->width - s->ww) * -s->wx;
609  }
610  if (s->wy >= 0) {
611  Y = (in->height - s->wh) * s->wy;
612  } else {
613  Y = (in->height - s->wh) * -s->wy;
614  }
615 
616  if (s->wx < 0) {
617  if (s->x + s->w >= X && (s->x + s->w <= X + s->ww) &&
618  s->y + s->h >= Y && (s->y + s->h <= Y + s->wh)) {
619  X = (in->width - s->ww) * (1 + s->wx);
620  }
621  }
622 
623  if (s->wy < 0) {
624  if (s->x + s->w >= X && (s->x + s->w <= X + s->ww) &&
625  s->y + s->h >= Y && (s->y + s->h <= Y + s->wh)) {
626  Y = (in->height - s->wh) * (1 + s->wy);
627  }
628  }
629 
630  ff_blend_rectangle(&s->draw, &s->dark, out->data, out->linesize,
631  out->width, out->height,
632  X,
633  Y,
634  s->ww,
635  s->wh);
636 
637  for (y = 0; y < s->h; y++) {
638  for (x = 0; x < s->w; x++) {
639  FFDrawColor color = { { 0 } };
640  int value[4] = { 0 };
641 
642  s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value);
643  ff_fill_rectangle(&s->draw, &color, out->data, out->linesize,
644  x * w + (s->ww - 4 - (s->w * w)) / 2 + X, y * h + 2 + Y, w, h);
645  for (i = 0; i < 4; i++) {
646  s->values[i][x][y] = value[i];
647  rms[i] += (double)value[i] * (double)value[i];
648  average[i] += value[i];
649  min[i] = FFMIN(min[i], value[i]);
650  max[i] = FFMAX(max[i], value[i]);
651  }
652  }
653  }
654 
655  ff_blend_rectangle(&s->draw, &s->black, out->data, out->linesize,
656  out->width, out->height,
657  s->x - 2, s->y - 2, s->w + 4, 1);
658 
659  ff_blend_rectangle(&s->draw, &s->white, out->data, out->linesize,
660  out->width, out->height,
661  s->x - 1, s->y - 1, s->w + 2, 1);
662 
663  ff_blend_rectangle(&s->draw, &s->white, out->data, out->linesize,
664  out->width, out->height,
665  s->x - 1, s->y - 1, 1, s->h + 2);
666 
667  ff_blend_rectangle(&s->draw, &s->black, out->data, out->linesize,
668  out->width, out->height,
669  s->x - 2, s->y - 2, 1, s->h + 4);
670 
671  ff_blend_rectangle(&s->draw, &s->white, out->data, out->linesize,
672  out->width, out->height,
673  s->x - 1, s->y + 1 + s->h, s->w + 3, 1);
674 
675  ff_blend_rectangle(&s->draw, &s->black, out->data, out->linesize,
676  out->width, out->height,
677  s->x - 2, s->y + 2 + s->h, s->w + 4, 1);
678 
679  ff_blend_rectangle(&s->draw, &s->white, out->data, out->linesize,
680  out->width, out->height,
681  s->x + 1 + s->w, s->y - 1, 1, s->h + 2);
682 
683  ff_blend_rectangle(&s->draw, &s->black, out->data, out->linesize,
684  out->width, out->height,
685  s->x + 2 + s->w, s->y - 2, 1, s->h + 5);
686 
687  for (i = 0; i < 4; i++) {
688  rms[i] /= s->w * s->h;
689  rms[i] = sqrt(rms[i]);
690  average[i] /= s->w * s->h;
691  }
692 
693  for (y = 0; y < s->h; y++) {
694  for (x = 0; x < s->w; x++) {
695  for (i = 0; i < 4; i++)
696  std[i] += SQR(s->values[i][x][y] - average[i]);
697  }
698  }
699 
700  for (i = 0; i < 4; i++) {
701  std[i] /= s->w * s->h;
702  std[i] = sqrt(std[i]);
703  }
704 
705  snprintf(text, sizeof(text), "CH AVG MIN MAX RMS\n");
706  draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 5, text, 0);
707  for (i = 0; i < s->nb_comps; i++) {
708  int c = s->rgba_map[i];
709 
710  snprintf(text, sizeof(text), "%c %07.1f %05d %05d %07.1f\n", s->is_rgb ? rgba[i] : yuva[i], average[c], min[c], max[c], rms[c]);
711  draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 15 * (i + 1), text, 0);
712  }
713  snprintf(text, sizeof(text), "CH STD\n");
714  draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 15 * (0 + 5), text, 0);
715  for (i = 0; i < s->nb_comps; i++) {
716  int c = s->rgba_map[i];
717 
718  snprintf(text, sizeof(text), "%c %07.2f\n", s->is_rgb ? rgba[i] : yuva[i], std[c]);
719  draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 15 * (i + 6), text, 0);
720  }
721 
722  av_frame_free(&in);
723  return ff_filter_frame(outlink, out);
724 }
725 
726 static int pixscope_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
727  char *res, int res_len, int flags)
728 {
729  int ret;
730 
731  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
732  if (ret < 0)
733  return ret;
734 
735  return pixscope_config_input(ctx->inputs[0]);
736 }
737 
738 static const AVFilterPad pixscope_inputs[] = {
739  {
740  .name = "default",
741  .type = AVMEDIA_TYPE_VIDEO,
742  .filter_frame = pixscope_filter_frame,
743  .config_props = pixscope_config_input,
744  },
745  { NULL }
746 };
747 
748 static const AVFilterPad pixscope_outputs[] = {
749  {
750  .name = "default",
751  .type = AVMEDIA_TYPE_VIDEO,
752  },
753  { NULL }
754 };
755 
757  .name = "pixscope",
758  .description = NULL_IF_CONFIG_SMALL("Pixel data analysis."),
759  .priv_size = sizeof(PixscopeContext),
760  .priv_class = &pixscope_class,
766 };
767 
768 typedef struct PixelValues {
769  uint16_t p[4];
770 } PixelValues;
771 
772 typedef struct OscilloscopeContext {
773  const AVClass *class;
774 
775  float xpos, ypos;
776  float tx, ty;
777  float size;
778  float tilt;
779  float theight, twidth;
780  float o;
782  int grid;
784  int scope;
785 
786  int x1, y1, x2, y2;
787  int ox, oy;
788  int height, width;
789 
790  int max;
792  int nb_comps;
793  int is_rgb;
806 
809 
813 
814 #define OOFFSET(x) offsetof(OscilloscopeContext, x)
815 
816 static const AVOption oscilloscope_options[] = {
817  { "x", "set scope x position", OOFFSET(xpos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
818  { "y", "set scope y position", OOFFSET(ypos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
819  { "s", "set scope size", OOFFSET(size), AV_OPT_TYPE_FLOAT, {.dbl=0.8}, 0, 1, FLAGSR },
820  { "t", "set scope tilt", OOFFSET(tilt), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
821  { "o", "set trace opacity", OOFFSET(o), AV_OPT_TYPE_FLOAT, {.dbl=0.8}, 0, 1, FLAGSR },
822  { "tx", "set trace x position", OOFFSET(tx), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
823  { "ty", "set trace y position", OOFFSET(ty), AV_OPT_TYPE_FLOAT, {.dbl=0.9}, 0, 1, FLAGSR },
824  { "tw", "set trace width", OOFFSET(twidth), AV_OPT_TYPE_FLOAT, {.dbl=0.8},.1, 1, FLAGSR },
825  { "th", "set trace height", OOFFSET(theight), AV_OPT_TYPE_FLOAT, {.dbl=0.3},.1, 1, FLAGSR },
826  { "c", "set components to trace", OOFFSET(components), AV_OPT_TYPE_INT, {.i64=7}, 0, 15, FLAGSR },
827  { "g", "draw trace grid", OOFFSET(grid), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGSR },
828  { "st", "draw statistics", OOFFSET(statistics), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGSR },
829  { "sc", "draw scope", OOFFSET(scope), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGSR },
830  { NULL }
831 };
832 
833 AVFILTER_DEFINE_CLASS(oscilloscope);
834 
836 {
837  OscilloscopeContext *s = ctx->priv;
838 
839  av_freep(&s->values);
840 }
841 
842 static void draw_line(FFDrawContext *draw, int x0, int y0, int x1, int y1,
844 {
845  int dx = FFABS(x1 - x0), sx = x0 < x1 ? 1 : -1;
846  int dy = FFABS(y1 - y0), sy = y0 < y1 ? 1 : -1;
847  int err = (dx > dy ? dx : -dy) / 2, e2;
848  int p, i;
849 
850  for (;;) {
851  if (x0 >= 0 && y0 >= 0 && x0 < out->width && y0 < out->height) {
852  for (p = 0; p < draw->nb_planes; p++) {
853  if (draw->desc->comp[p].depth == 8) {
854  if (draw->nb_planes == 1) {
855  for (i = 0; i < draw->desc->nb_components; i++) {
856  out->data[0][y0 * out->linesize[0] + x0 * draw->pixelstep[0] + i] = color->comp[0].u8[i];
857  }
858  } else {
859  out->data[p][out->linesize[p] * (y0 >> draw->vsub[p]) + (x0 >> draw->hsub[p])] = color->comp[p].u8[0];
860  }
861  } else {
862  if (draw->nb_planes == 1) {
863  for (i = 0; i < draw->desc->nb_components; i++) {
864  AV_WN16(out->data[0] + y0 * out->linesize[0] + (x0 * draw->pixelstep[0] + i), color->comp[0].u16[i]);
865  }
866  } else {
867  AV_WN16(out->data[p] + out->linesize[p] * (y0 >> draw->vsub[p]) + (x0 >> draw->hsub[p]) * 2, color->comp[p].u16[0]);
868  }
869  }
870  }
871  }
872 
873  if (x0 == x1 && y0 == y1)
874  break;
875 
876  e2 = err;
877 
878  if (e2 >-dx) {
879  err -= dy;
880  x0 += sx;
881  }
882 
883  if (e2 < dy) {
884  err += dx;
885  y0 += sy;
886  }
887  }
888 }
889 
891 {
892  int i, c;
893 
894  for (i = 1; i < s->nb_values; i++) {
895  for (c = 0; c < s->nb_comps; c++) {
896  if ((1 << c) & s->components) {
897  int x = i * s->width / s->nb_values;
898  int px = (i - 1) * s->width / s->nb_values;
899  int py = s->height - s->values[i-1].p[s->rgba_map[c]] * s->height / 256;
900  int y = s->height - s->values[i].p[s->rgba_map[c]] * s->height / 256;
901 
902  draw_line(&s->draw, s->ox + x, s->oy + y, s->ox + px, s->oy + py, frame, s->colors[c]);
903  }
904  }
905  }
906 }
907 
908 
910 {
911  int i, c;
912 
913  for (i = 1; i < s->nb_values; i++) {
914  for (c = 0; c < s->nb_comps; c++) {
915  if ((1 << c) & s->components) {
916  int x = i * s->width / s->nb_values;
917  int px = (i - 1) * s->width / s->nb_values;
918  int py = s->height - s->values[i-1].p[s->rgba_map[c]] * s->height / s->max;
919  int y = s->height - s->values[i].p[s->rgba_map[c]] * s->height / s->max;
920 
921  draw_line(&s->draw, s->ox + x, s->oy + y, s->ox + px, s->oy + py, frame, s->colors[c]);
922  }
923  }
924  }
925 }
926 
928 {
929  OscilloscopeContext *s = ctx->priv;
930  AVFilterLink *inlink = ctx->inputs[0];
931  int cx, cy, size;
932  double tilt;
933 
934  ff_draw_color(&s->draw, &s->dark, (uint8_t[]){ 0, 0, 0, s->o * 255} );
935  s->height = s->theight * inlink->h;
936  s->width = s->twidth * inlink->w;
937  size = hypot(inlink->w, inlink->h);
938  size *= s->size;
939  tilt = (s->tilt - 0.5) * M_PI;
940  cx = s->xpos * (inlink->w - 1);
941  cy = s->ypos * (inlink->h - 1);
942  s->x1 = cx - size / 2.0 * cos(tilt);
943  s->x2 = cx + size / 2.0 * cos(tilt);
944  s->y1 = cy - size / 2.0 * sin(tilt);
945  s->y2 = cy + size / 2.0 * sin(tilt);
946  s->ox = (inlink->w - s->width) * s->tx;
947  s->oy = (inlink->h - s->height) * s->ty;
948 }
949 
951 {
952  AVFilterContext *ctx = inlink->dst;
953  OscilloscopeContext *s = ctx->priv;
954  int size;
955  int ret;
956 
957  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
958  ret = ff_draw_init(&s->draw, inlink->format, 0);
959  if (ret < 0) {
960  av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
961  return ret;
962  }
963  ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, 255} );
964  ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
965  ff_draw_color(&s->draw, &s->green, (uint8_t[]){ 0, 255, 0, 255} );
966  ff_draw_color(&s->draw, &s->blue, (uint8_t[]){ 0, 0, 255, 255} );
967  ff_draw_color(&s->draw, &s->red, (uint8_t[]){ 255, 0, 0, 255} );
968  ff_draw_color(&s->draw, &s->cyan, (uint8_t[]){ 0, 255, 255, 255} );
969  ff_draw_color(&s->draw, &s->magenta, (uint8_t[]){ 255, 0, 255, 255} );
970  ff_draw_color(&s->draw, &s->gray, (uint8_t[]){ 128, 128, 128, 255} );
971  s->nb_comps = s->draw.desc->nb_components;
972  s->is_rgb = s->draw.desc->flags & AV_PIX_FMT_FLAG_RGB;
973 
974  if (s->is_rgb) {
975  s->colors[0] = &s->red;
976  s->colors[1] = &s->green;
977  s->colors[2] = &s->blue;
978  s->colors[3] = &s->white;
979  ff_fill_rgba_map(s->rgba_map, inlink->format);
980  } else {
981  s->colors[0] = &s->white;
982  s->colors[1] = &s->cyan;
983  s->colors[2] = &s->magenta;
984  s->colors[3] = &s->white;
985  s->rgba_map[0] = 0;
986  s->rgba_map[1] = 1;
987  s->rgba_map[2] = 2;
988  s->rgba_map[3] = 3;
989  }
990 
991  if (s->draw.desc->comp[0].depth <= 8) {
992  s->pick_color = pick_color8;
993  s->draw_trace = draw_trace8;
994  } else {
995  s->pick_color = pick_color16;
996  s->draw_trace = draw_trace16;
997  }
998 
999  s->max = (1 << s->draw.desc->comp[0].depth);
1000  size = hypot(inlink->w, inlink->h);
1001 
1002  s->values = av_calloc(size, sizeof(*s->values));
1003  if (!s->values)
1004  return AVERROR(ENOMEM);
1005 
1006  update_oscilloscope(inlink->dst);
1007 
1008  return 0;
1009 }
1010 
1011 static void draw_scope(OscilloscopeContext *s, int x0, int y0, int x1, int y1,
1012  AVFrame *out, PixelValues *p, int state)
1013 {
1014  int dx = FFABS(x1 - x0), sx = x0 < x1 ? 1 : -1;
1015  int dy = FFABS(y1 - y0), sy = y0 < y1 ? 1 : -1;
1016  int err = (dx > dy ? dx : -dy) / 2, e2;
1017 
1018  for (;;) {
1019  if (x0 >= 0 && y0 >= 0 && x0 < out->width && y0 < out->height) {
1020  FFDrawColor color = { { 0 } };
1021  int value[4] = { 0 };
1022 
1023  s->pick_color(&s->draw, &color, out, x0, y0, value);
1024  s->values[s->nb_values].p[0] = value[0];
1025  s->values[s->nb_values].p[1] = value[1];
1026  s->values[s->nb_values].p[2] = value[2];
1027  s->values[s->nb_values].p[3] = value[3];
1028  s->nb_values++;
1029 
1030  if (s->scope) {
1031  if (s->draw.desc->comp[0].depth == 8) {
1032  if (s->draw.nb_planes == 1) {
1033  int i;
1034 
1035  for (i = 0; i < s->nb_comps; i++)
1036  out->data[0][out->linesize[0] * y0 + x0 * s->draw.pixelstep[0] + i] = 255 * ((s->nb_values + state) & 1);
1037  } else {
1038  out->data[0][out->linesize[0] * y0 + x0] = 255 * ((s->nb_values + state) & 1);
1039  }
1040  } else {
1041  if (s->draw.nb_planes == 1) {
1042  int i;
1043 
1044  for (i = 0; i < s->nb_comps; i++)
1045  AV_WN16(out->data[0] + out->linesize[0] * y0 + x0 * s->draw.pixelstep[0] + i, (s->max - 1) * ((s->nb_values + state) & 1));
1046  } else {
1047  AV_WN16(out->data[0] + out->linesize[0] * y0 + 2 * x0, (s->max - 1) * ((s->nb_values + state) & 1));
1048  }
1049  }
1050  }
1051  }
1052 
1053  if (x0 == x1 && y0 == y1)
1054  break;
1055 
1056  e2 = err;
1057 
1058  if (e2 >-dx) {
1059  err -= dy;
1060  x0 += sx;
1061  }
1062 
1063  if (e2 < dy) {
1064  err += dx;
1065  y0 += sy;
1066  }
1067  }
1068 }
1069 
1071 {
1072  AVFilterContext *ctx = inlink->dst;
1073  OscilloscopeContext *s = ctx->priv;
1074  AVFilterLink *outlink = ctx->outputs[0];
1075  float average[4] = { 0 };
1076  int max[4] = { 0 };
1077  int min[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };
1078  int i, c;
1079 
1080  s->nb_values = 0;
1081  draw_scope(s, s->x1, s->y1, s->x2, s->y2, frame, s->values, inlink->frame_count_in & 1);
1082  ff_blend_rectangle(&s->draw, &s->dark, frame->data, frame->linesize,
1083  frame->width, frame->height,
1084  s->ox, s->oy, s->width, s->height + 20 * s->statistics);
1085 
1086  if (s->grid && outlink->h >= 10) {
1087  ff_fill_rectangle(&s->draw, &s->gray, frame->data, frame->linesize,
1088  s->ox, s->oy, s->width - 1, 1);
1089 
1090  for (i = 1; i < 5; i++) {
1091  ff_fill_rectangle(&s->draw, &s->gray, frame->data, frame->linesize,
1092  s->ox, s->oy + i * (s->height - 1) / 4, s->width, 1);
1093  }
1094 
1095  for (i = 0; i < 10; i++) {
1096  ff_fill_rectangle(&s->draw, &s->gray, frame->data, frame->linesize,
1097  s->ox + i * (s->width - 1) / 10, s->oy, 1, s->height);
1098  }
1099 
1100  ff_fill_rectangle(&s->draw, &s->gray, frame->data, frame->linesize,
1101  s->ox + s->width - 1, s->oy, 1, s->height);
1102  }
1103 
1104  s->draw_trace(s, frame);
1105 
1106  for (i = 0; i < s->nb_values; i++) {
1107  for (c = 0; c < s->nb_comps; c++) {
1108  if ((1 << c) & s->components) {
1109  max[c] = FFMAX(max[c], s->values[i].p[s->rgba_map[c]]);
1110  min[c] = FFMIN(min[c], s->values[i].p[s->rgba_map[c]]);
1111  average[c] += s->values[i].p[s->rgba_map[c]];
1112  }
1113  }
1114  }
1115  for (c = 0; c < s->nb_comps; c++) {
1116  average[c] /= s->nb_values;
1117  }
1118 
1119  if (s->statistics && s->height > 10 && s->width > 280 * av_popcount(s->components)) {
1120  for (c = 0, i = 0; c < s->nb_comps; c++) {
1121  if ((1 << c) & s->components) {
1122  const char rgba[4] = { 'R', 'G', 'B', 'A' };
1123  const char yuva[4] = { 'Y', 'U', 'V', 'A' };
1124  char text[128];
1125 
1126  snprintf(text, sizeof(text), "%c avg:%.1f min:%d max:%d\n", s->is_rgb ? rgba[c] : yuva[c], average[c], min[c], max[c]);
1127  draw_text(&s->draw, frame, &s->white, s->ox + 2 + 280 * i++, s->oy + s->height + 4, text, 0);
1128  }
1129  }
1130  }
1131 
1132  return ff_filter_frame(outlink, frame);
1133 }
1134 
1135 static int oscilloscope_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
1136  char *res, int res_len, int flags)
1137 {
1138  int ret;
1139 
1140  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1141  if (ret < 0)
1142  return ret;
1143 
1145 
1146  return 0;
1147 }
1148 
1150  {
1151  .name = "default",
1152  .type = AVMEDIA_TYPE_VIDEO,
1153  .filter_frame = oscilloscope_filter_frame,
1154  .config_props = oscilloscope_config_input,
1155  .needs_writable = 1,
1156  },
1157  { NULL }
1158 };
1159 
1161  {
1162  .name = "default",
1163  .type = AVMEDIA_TYPE_VIDEO,
1164  },
1165  { NULL }
1166 };
1167 
1169  .name = "oscilloscope",
1170  .description = NULL_IF_CONFIG_SMALL("2D Video Oscilloscope."),
1171  .priv_size = sizeof(OscilloscopeContext),
1172  .priv_class = &oscilloscope_class,
1179 };
static const char *const format[]
Definition: af_aiir.c:457
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
uint8_t
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:885
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:805
Main libavfilter public API header.
#define AV_RL16
Definition: intreadwrite.h:42
#define Y
Definition: boxblur.h:38
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
static struct @322 state
#define FFMIN(a, b)
Definition: common.h:105
#define av_popcount
Definition: common.h:176
#define FFMAX(a, b)
Definition: common.h:103
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define NULL
Definition: coverity.c:32
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
#define max(a, b)
Definition: cuda_runtime.h:33
static AVFrame * frame
void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, int x0, int y0, int w, int h)
Blend a rectangle with an uniform color.
Definition: drawutils.c:358
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:84
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:144
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:35
void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_x, int dst_y, int w, int h)
Fill a rectangle with an uniform color.
Definition: drawutils.c:231
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, const uint8_t *mask, int mask_linesize, int mask_w, int mask_h, int l2depth, unsigned endianness, int x0, int y0)
Blend an alpha mask with an uniform color.
Definition: drawutils.c:535
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:644
misc drawing utilities
mode
Use these values in ebur128_init (or'ed).
Definition: ebur128.h:83
double value
Definition: eval.c:100
int
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
Definition: filters.h:282
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:126
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:799
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
static const int16_t alpha[]
Definition: ilbcdata.h:55
int i
Definition: input.c:407
#define AV_WN16(p, v)
Definition: intreadwrite.h:372
#define C
const char * arg
Definition: jacosubdec.c:67
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static av_const double hypot(double x, double y)
Definition: libm.h:366
uint8_t w
Definition: llviddspenc.c:39
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:92
#define M_PI
Definition: mathematics.h:52
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2035
#define P
AVOptions.
misc parsing utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2613
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
#define td
Definition: regdef.h:70
D(D(float, sse)
Definition: rematrix_init.c:28
typedef void(RENAME(mix_any_func_type))
#define snprintf
Definition: snprintf.h:34
static uint32_t reverse(uint32_t num, int bits)
Definition: speedhqenc.c:51
Describe the class of an AVClass context structure.
Definition: log.h:67
int depth
Number of bits in the component.
Definition: pixdesc.h:58
An instance of a filter.
Definition: avfilter.h:341
void * priv
private data for use by the filter
Definition: avfilter.h:356
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
int height
Definition: frame.h:376
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
AVOption.
Definition: opt.h:248
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
Rational number (pair of numerator and denominator).
Definition: rational.h:58
void(* pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value)
Definition: vf_datascope.c:53
FFDrawColor yellow
Definition: vf_datascope.c:48
void(* reverse_color)(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse)
Definition: vf_datascope.c:54
FFDrawContext draw
Definition: vf_datascope.c:47
FFDrawColor white
Definition: vf_datascope.c:49
FFDrawColor black
Definition: vf_datascope.c:50
int(* filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_datascope.c:55
FFDrawColor gray
Definition: vf_datascope.c:51
unsigned nb_planes
Definition: drawutils.h:38
const struct AVPixFmtDescriptor * desc
Definition: drawutils.h:36
uint8_t vsub[MAX_PLANES]
Definition: drawutils.h:42
uint8_t hsub[MAX_PLANES]
Definition: drawutils.h:41
int pixelstep[MAX_PLANES]
Definition: drawutils.h:39
FFDrawColor * colors[4]
Definition: vf_datascope.c:805
void(* pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value)
Definition: vf_datascope.c:810
PixelValues * values
Definition: vf_datascope.c:808
FFDrawColor magenta
Definition: vf_datascope.c:803
void(* draw_trace)(struct OscilloscopeContext *s, AVFrame *frame)
Definition: vf_datascope.c:811
FFDrawContext draw
Definition: vf_datascope.c:795
uint16_t p[4]
Definition: vf_datascope.c:769
FFDrawColor black
Definition: vf_datascope.c:490
uint16_t values[4][80][80]
Definition: vf_datascope.c:497
uint8_t rgba_map[4]
Definition: vf_datascope.c:487
FFDrawColor green
Definition: vf_datascope.c:492
FFDrawColor dark
Definition: vf_datascope.c:489
FFDrawColor * colors[4]
Definition: vf_datascope.c:495
FFDrawColor white
Definition: vf_datascope.c:491
void(* pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value)
Definition: vf_datascope.c:499
FFDrawColor blue
Definition: vf_datascope.c:493
FFDrawColor red
Definition: vf_datascope.c:494
FFDrawContext draw
Definition: vf_datascope.c:488
Used for passing data between threads.
Definition: dsddec.c:67
AVFrame * out
Definition: af_adeclick.c:505
AVFrame * in
Definition: af_adenorm.c:223
#define av_freep(p)
#define av_log(a,...)
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
#define height
#define width
int size
@ H
Definition: vf_addroi.c:26
@ X
Definition: vf_addroi.c:26
@ W
Definition: vf_addroi.c:26
static int filter_mono(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_datascope.c:268
static const AVOption datascope_options[]
Definition: vf_datascope.c:62
static const AVFilterPad oscilloscope_outputs[]
#define FLAGSR
Definition: vf_datascope.c:60
static int filter_color(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_datascope.c:225
static void draw_trace8(OscilloscopeContext *s, AVFrame *frame)
Definition: vf_datascope.c:890
static void draw_trace16(OscilloscopeContext *s, AVFrame *frame)
Definition: vf_datascope.c:909
static void draw_text(FFDrawContext *draw, AVFrame *frame, FFDrawColor *color, int x0, int y0, const uint8_t *text, int vertical)
Definition: vf_datascope.c:87
static const AVOption oscilloscope_options[]
Definition: vf_datascope.c:816
static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_datascope.c:581
static void oscilloscope_uninit(AVFilterContext *ctx)
Definition: vf_datascope.c:835
AVFILTER_DEFINE_CLASS(datascope)
static int query_formats(AVFilterContext *ctx)
Definition: vf_datascope.c:82
static int config_input(AVFilterLink *inlink)
Definition: vf_datascope.c:381
#define FLAGS
Definition: vf_datascope.c:59
static const AVFilterPad inputs[]
Definition: vf_datascope.c:442
static const AVOption pixscope_options[]
Definition: vf_datascope.c:504
static void draw_scope(OscilloscopeContext *s, int x0, int y0, int x1, int y1, AVFrame *out, PixelValues *p, int state)
static const AVFilterPad outputs[]
Definition: vf_datascope.c:452
static int oscilloscope_process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static void pick_color16(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value)
Definition: vf_datascope.c:128
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_datascope.c:310
#define POFFSET(x)
Definition: vf_datascope.c:502
static int pixscope_process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_datascope.c:726
#define SQR(x)
Definition: vf_datascope.c:579
#define OOFFSET(x)
Definition: vf_datascope.c:814
static int oscilloscope_filter_frame(AVFilterLink *inlink, AVFrame *frame)
static void reverse_color8(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse)
Definition: vf_datascope.c:146
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_datascope.c:430
static int filter_color2(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_datascope.c:178
static const AVFilterPad oscilloscope_inputs[]
static void reverse_color16(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse)
Definition: vf_datascope.c:158
static int pixscope_config_input(AVFilterLink *inlink)
Definition: vf_datascope.c:517
AVFilter ff_vf_datascope
Definition: vf_datascope.c:461
static const AVFilterPad pixscope_outputs[]
Definition: vf_datascope.c:748
#define OFFSET(x)
Definition: vf_datascope.c:58
static int config_output(AVFilterLink *outlink)
Definition: vf_datascope.c:419
static void draw_line(FFDrawContext *draw, int x0, int y0, int x1, int y1, AVFrame *out, FFDrawColor *color)
Definition: vf_datascope.c:842
AVFilter ff_vf_oscilloscope
AVFilter ff_vf_pixscope
Definition: vf_datascope.c:756
static void update_oscilloscope(AVFilterContext *ctx)
Definition: vf_datascope.c:927
static const AVFilterPad pixscope_inputs[]
Definition: vf_datascope.c:738
static int oscilloscope_config_input(AVFilterLink *inlink)
Definition: vf_datascope.c:950
static void pick_color8(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value)
Definition: vf_datascope.c:110
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104
float min
static double c[64]
const uint8_t avpriv_cga_font[2048]
Definition: xga_font_data.c:29
CGA/EGA/VGA ROM font data.