You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1134 lines
38KB

  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. #include "libavutil/avassert.h"
  21. #include "libavutil/intreadwrite.h"
  22. #include "libavutil/opt.h"
  23. #include "libavutil/parseutils.h"
  24. #include "libavutil/pixdesc.h"
  25. #include "libavutil/xga_font_data.h"
  26. #include "avfilter.h"
  27. #include "drawutils.h"
  28. #include "formats.h"
  29. #include "internal.h"
  30. #include "video.h"
  31. typedef struct DatascopeContext {
  32. const AVClass *class;
  33. int ow, oh;
  34. int x, y;
  35. int mode;
  36. int dformat;
  37. int axis;
  38. int components;
  39. float opacity;
  40. int nb_planes;
  41. int nb_comps;
  42. int chars;
  43. FFDrawContext draw;
  44. FFDrawColor yellow;
  45. FFDrawColor white;
  46. FFDrawColor black;
  47. FFDrawColor gray;
  48. void (*pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value);
  49. void (*reverse_color)(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse);
  50. int (*filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
  51. } DatascopeContext;
  52. #define OFFSET(x) offsetof(DatascopeContext, x)
  53. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  54. #define FLAGSR AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
  55. static const AVOption datascope_options[] = {
  56. { "size", "set output size", OFFSET(ow), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, 0, 0, FLAGS },
  57. { "s", "set output size", OFFSET(ow), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, 0, 0, FLAGS },
  58. { "x", "set x offset", OFFSET(x), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
  59. { "y", "set y offset", OFFSET(y), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
  60. { "mode", "set scope mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "mode" },
  61. { "mono", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
  62. { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
  63. { "color2", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "mode" },
  64. { "axis", "draw column/row numbers", OFFSET(axis), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
  65. { "opacity", "set background opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
  66. { "format", "set display number format", OFFSET(dformat), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "format" },
  67. { "hex", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "format" },
  68. { "dec", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "format" },
  69. { "components", "set components to display", OFFSET(components), AV_OPT_TYPE_INT, {.i64=15}, 1, 15, FLAGS },
  70. { NULL }
  71. };
  72. AVFILTER_DEFINE_CLASS(datascope);
  73. static int query_formats(AVFilterContext *ctx)
  74. {
  75. return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
  76. }
  77. static void draw_text(FFDrawContext *draw, AVFrame *frame, FFDrawColor *color,
  78. int x0, int y0, const uint8_t *text, int vertical)
  79. {
  80. int x = x0;
  81. for (; *text; text++) {
  82. if (*text == '\n') {
  83. x = x0;
  84. y0 += 8;
  85. continue;
  86. }
  87. ff_blend_mask(draw, color, frame->data, frame->linesize,
  88. frame->width, frame->height,
  89. avpriv_cga_font + *text * 8, 1, 8, 8, 0, 0, x, y0);
  90. if (vertical) {
  91. x = x0;
  92. y0 += 8;
  93. } else {
  94. x += 8;
  95. }
  96. }
  97. }
  98. static void pick_color8(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value)
  99. {
  100. int p, i;
  101. color->rgba[3] = 255;
  102. for (p = 0; p < draw->nb_planes; p++) {
  103. if (draw->nb_planes == 1) {
  104. for (i = 0; i < 4; i++) {
  105. value[i] = in->data[0][y * in->linesize[0] + x * draw->pixelstep[0] + i];
  106. color->comp[0].u8[i] = value[i];
  107. }
  108. } else {
  109. value[p] = in->data[p][(y >> draw->vsub[p]) * in->linesize[p] + (x >> draw->hsub[p])];
  110. color->comp[p].u8[0] = value[p];
  111. }
  112. }
  113. }
  114. static void pick_color16(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value)
  115. {
  116. int p, i;
  117. color->rgba[3] = 255;
  118. for (p = 0; p < draw->nb_planes; p++) {
  119. if (draw->nb_planes == 1) {
  120. for (i = 0; i < 4; i++) {
  121. value[i] = AV_RL16(in->data[0] + y * in->linesize[0] + x * draw->pixelstep[0] + i * 2);
  122. color->comp[0].u16[i] = value[i];
  123. }
  124. } else {
  125. value[p] = AV_RL16(in->data[p] + (y >> draw->vsub[p]) * in->linesize[p] + (x >> draw->hsub[p]) * 2);
  126. color->comp[p].u16[0] = value[p];
  127. }
  128. }
  129. }
  130. static void reverse_color8(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse)
  131. {
  132. int p;
  133. reverse->rgba[3] = 255;
  134. for (p = 0; p < draw->nb_planes; p++) {
  135. reverse->comp[p].u8[0] = color->comp[p].u8[0] > 127 ? 0 : 255;
  136. reverse->comp[p].u8[1] = color->comp[p].u8[1] > 127 ? 0 : 255;
  137. reverse->comp[p].u8[2] = color->comp[p].u8[2] > 127 ? 0 : 255;
  138. }
  139. }
  140. static void reverse_color16(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse)
  141. {
  142. int p;
  143. reverse->rgba[3] = 255;
  144. for (p = 0; p < draw->nb_planes; p++) {
  145. const unsigned max = (1 << draw->desc->comp[p].depth) - 1;
  146. const unsigned mid = (max + 1) / 2;
  147. reverse->comp[p].u16[0] = color->comp[p].u16[0] > mid ? 0 : max;
  148. reverse->comp[p].u16[1] = color->comp[p].u16[1] > mid ? 0 : max;
  149. reverse->comp[p].u16[2] = color->comp[p].u16[2] > mid ? 0 : max;
  150. }
  151. }
  152. typedef struct ThreadData {
  153. AVFrame *in, *out;
  154. int xoff, yoff, PP;
  155. } ThreadData;
  156. static int filter_color2(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  157. {
  158. DatascopeContext *s = ctx->priv;
  159. AVFilterLink *outlink = ctx->outputs[0];
  160. AVFilterLink *inlink = ctx->inputs[0];
  161. ThreadData *td = arg;
  162. AVFrame *in = td->in;
  163. AVFrame *out = td->out;
  164. const int PP = td->PP;
  165. const int xoff = td->xoff;
  166. const int yoff = td->yoff;
  167. const int P = FFMAX(s->nb_planes, s->nb_comps);
  168. const int C = s->chars;
  169. const int D = ((s->chars - s->dformat) >> 2) + s->dformat * 2;
  170. const int W = (outlink->w - xoff) / (C * 10);
  171. const int H = (outlink->h - yoff) / (PP * 12);
  172. const char *format[4] = {"%02X\n", "%04X\n", "%03d\n", "%05d\n"};
  173. const int slice_start = (W * jobnr) / nb_jobs;
  174. const int slice_end = (W * (jobnr+1)) / nb_jobs;
  175. int x, y, p;
  176. for (y = 0; y < H && (y + s->y < inlink->h); y++) {
  177. for (x = slice_start; x < slice_end && (x + s->x < inlink->w); x++) {
  178. FFDrawColor color = { { 0 } };
  179. FFDrawColor reverse = { { 0 } };
  180. int value[4] = { 0 }, pp = 0;
  181. s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value);
  182. s->reverse_color(&s->draw, &color, &reverse);
  183. ff_fill_rectangle(&s->draw, &color, out->data, out->linesize,
  184. xoff + x * C * 10, yoff + y * PP * 12, C * 10, PP * 12);
  185. for (p = 0; p < P; p++) {
  186. char text[256];
  187. if (!(s->components & (1 << p)))
  188. continue;
  189. snprintf(text, sizeof(text), format[D], value[p]);
  190. draw_text(&s->draw, out, &reverse, xoff + x * C * 10 + 2, yoff + y * PP * 12 + pp * 10 + 2, text, 0);
  191. pp++;
  192. }
  193. }
  194. }
  195. return 0;
  196. }
  197. static int filter_color(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  198. {
  199. DatascopeContext *s = ctx->priv;
  200. AVFilterLink *outlink = ctx->outputs[0];
  201. AVFilterLink *inlink = ctx->inputs[0];
  202. ThreadData *td = arg;
  203. AVFrame *in = td->in;
  204. AVFrame *out = td->out;
  205. const int PP = td->PP;
  206. const int xoff = td->xoff;
  207. const int yoff = td->yoff;
  208. const int P = FFMAX(s->nb_planes, s->nb_comps);
  209. const int C = s->chars;
  210. const int D = ((s->chars - s->dformat) >> 2) + s->dformat * 2;
  211. const int W = (outlink->w - xoff) / (C * 10);
  212. const int H = (outlink->h - yoff) / (PP * 12);
  213. const char *format[4] = {"%02X\n", "%04X\n", "%03d\n", "%05d\n"};
  214. const int slice_start = (W * jobnr) / nb_jobs;
  215. const int slice_end = (W * (jobnr+1)) / nb_jobs;
  216. int x, y, p;
  217. for (y = 0; y < H && (y + s->y < inlink->h); y++) {
  218. for (x = slice_start; x < slice_end && (x + s->x < inlink->w); x++) {
  219. FFDrawColor color = { { 0 } };
  220. int value[4] = { 0 }, pp = 0;
  221. s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value);
  222. for (p = 0; p < P; p++) {
  223. char text[256];
  224. if (!(s->components & (1 << p)))
  225. continue;
  226. snprintf(text, sizeof(text), format[D], value[p]);
  227. draw_text(&s->draw, out, &color, xoff + x * C * 10 + 2, yoff + y * PP * 12 + pp * 10 + 2, text, 0);
  228. pp++;
  229. }
  230. }
  231. }
  232. return 0;
  233. }
  234. static int filter_mono(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  235. {
  236. DatascopeContext *s = ctx->priv;
  237. AVFilterLink *outlink = ctx->outputs[0];
  238. AVFilterLink *inlink = ctx->inputs[0];
  239. ThreadData *td = arg;
  240. AVFrame *in = td->in;
  241. AVFrame *out = td->out;
  242. const int PP = td->PP;
  243. const int xoff = td->xoff;
  244. const int yoff = td->yoff;
  245. const int P = FFMAX(s->nb_planes, s->nb_comps);
  246. const int C = s->chars;
  247. const int D = ((s->chars - s->dformat) >> 2) + s->dformat * 2;
  248. const int W = (outlink->w - xoff) / (C * 10);
  249. const int H = (outlink->h - yoff) / (PP * 12);
  250. const char *format[4] = {"%02X\n", "%04X\n", "%03d\n", "%05d\n"};
  251. const int slice_start = (W * jobnr) / nb_jobs;
  252. const int slice_end = (W * (jobnr+1)) / nb_jobs;
  253. int x, y, p;
  254. for (y = 0; y < H && (y + s->y < inlink->h); y++) {
  255. for (x = slice_start; x < slice_end && (x + s->x < inlink->w); x++) {
  256. FFDrawColor color = { { 0 } };
  257. int value[4] = { 0 }, pp = 0;
  258. s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value);
  259. for (p = 0; p < P; p++) {
  260. char text[256];
  261. if (!(s->components & (1 << p)))
  262. continue;
  263. snprintf(text, sizeof(text), format[D], value[p]);
  264. draw_text(&s->draw, out, &s->white, xoff + x * C * 10 + 2, yoff + y * PP * 12 + pp * 10 + 2, text, 0);
  265. pp++;
  266. }
  267. }
  268. }
  269. return 0;
  270. }
  271. static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  272. {
  273. AVFilterContext *ctx = inlink->dst;
  274. DatascopeContext *s = ctx->priv;
  275. AVFilterLink *outlink = ctx->outputs[0];
  276. const int P = FFMAX(s->nb_planes, s->nb_comps);
  277. ThreadData td = { 0 };
  278. int ymaxlen = 0;
  279. int xmaxlen = 0;
  280. int PP = 0;
  281. AVFrame *out;
  282. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  283. if (!out) {
  284. av_frame_free(&in);
  285. return AVERROR(ENOMEM);
  286. }
  287. out->pts = in->pts;
  288. ff_fill_rectangle(&s->draw, &s->black, out->data, out->linesize,
  289. 0, 0, outlink->w, outlink->h);
  290. for (int p = 0; p < P; p++) {
  291. if (s->components & (1 << p))
  292. PP++;
  293. }
  294. PP = FFMAX(PP, 1);
  295. if (s->axis) {
  296. const int C = s->chars;
  297. int Y = outlink->h / (PP * 12);
  298. int X = outlink->w / (C * 10);
  299. char text[256] = { 0 };
  300. int x, y;
  301. snprintf(text, sizeof(text), "%d", s->y + Y);
  302. ymaxlen = strlen(text);
  303. ymaxlen *= 10;
  304. snprintf(text, sizeof(text), "%d", s->x + X);
  305. xmaxlen = strlen(text);
  306. xmaxlen *= 10;
  307. Y = (outlink->h - xmaxlen) / (PP * 12);
  308. X = (outlink->w - ymaxlen) / (C * 10);
  309. for (y = 0; y < Y; y++) {
  310. snprintf(text, sizeof(text), "%d", s->y + y);
  311. ff_fill_rectangle(&s->draw, &s->gray, out->data, out->linesize,
  312. 0, xmaxlen + y * PP * 12 + (PP + 1) * PP - 2, ymaxlen, 10);
  313. draw_text(&s->draw, out, &s->yellow, 2, xmaxlen + y * PP * 12 + (PP + 1) * PP, text, 0);
  314. }
  315. for (x = 0; x < X; x++) {
  316. snprintf(text, sizeof(text), "%d", s->x + x);
  317. ff_fill_rectangle(&s->draw, &s->gray, out->data, out->linesize,
  318. ymaxlen + x * C * 10 + 2 * C - 2, 0, 10, xmaxlen);
  319. draw_text(&s->draw, out, &s->yellow, ymaxlen + x * C * 10 + 2 * C, 2, text, 1);
  320. }
  321. }
  322. td.in = in; td.out = out, td.yoff = xmaxlen, td.xoff = ymaxlen, td.PP = PP;
  323. ctx->internal->execute(ctx, s->filter, &td, NULL, FFMIN(ff_filter_get_nb_threads(ctx), FFMAX(outlink->w / 20, 1)));
  324. av_frame_free(&in);
  325. return ff_filter_frame(outlink, out);
  326. }
  327. static int config_input(AVFilterLink *inlink)
  328. {
  329. DatascopeContext *s = inlink->dst->priv;
  330. uint8_t alpha = s->opacity * 255;
  331. s->nb_planes = av_pix_fmt_count_planes(inlink->format);
  332. ff_draw_init(&s->draw, inlink->format, 0);
  333. ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
  334. ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, alpha} );
  335. ff_draw_color(&s->draw, &s->yellow, (uint8_t[]){ 255, 255, 0, 255} );
  336. ff_draw_color(&s->draw, &s->gray, (uint8_t[]){ 77, 77, 77, 255} );
  337. s->chars = (s->draw.desc->comp[0].depth + 7) / 8 * 2 + s->dformat;
  338. s->nb_comps = s->draw.desc->nb_components;
  339. switch (s->mode) {
  340. case 0: s->filter = filter_mono; break;
  341. case 1: s->filter = filter_color; break;
  342. case 2: s->filter = filter_color2; break;
  343. }
  344. if (s->draw.desc->comp[0].depth <= 8) {
  345. s->pick_color = pick_color8;
  346. s->reverse_color = reverse_color8;
  347. } else {
  348. s->pick_color = pick_color16;
  349. s->reverse_color = reverse_color16;
  350. }
  351. return 0;
  352. }
  353. static int config_output(AVFilterLink *outlink)
  354. {
  355. DatascopeContext *s = outlink->src->priv;
  356. outlink->h = s->oh;
  357. outlink->w = s->ow;
  358. outlink->sample_aspect_ratio = (AVRational){1,1};
  359. return 0;
  360. }
  361. static const AVFilterPad inputs[] = {
  362. {
  363. .name = "default",
  364. .type = AVMEDIA_TYPE_VIDEO,
  365. .filter_frame = filter_frame,
  366. .config_props = config_input,
  367. },
  368. { NULL }
  369. };
  370. static const AVFilterPad outputs[] = {
  371. {
  372. .name = "default",
  373. .type = AVMEDIA_TYPE_VIDEO,
  374. .config_props = config_output,
  375. },
  376. { NULL }
  377. };
  378. AVFilter ff_vf_datascope = {
  379. .name = "datascope",
  380. .description = NULL_IF_CONFIG_SMALL("Video data analysis."),
  381. .priv_size = sizeof(DatascopeContext),
  382. .priv_class = &datascope_class,
  383. .query_formats = query_formats,
  384. .inputs = inputs,
  385. .outputs = outputs,
  386. .flags = AVFILTER_FLAG_SLICE_THREADS,
  387. };
  388. typedef struct PixscopeContext {
  389. const AVClass *class;
  390. float xpos, ypos;
  391. float wx, wy;
  392. int w, h;
  393. float o;
  394. int x, y;
  395. int ww, wh;
  396. int nb_planes;
  397. int nb_comps;
  398. int is_rgb;
  399. uint8_t rgba_map[4];
  400. FFDrawContext draw;
  401. FFDrawColor dark;
  402. FFDrawColor black;
  403. FFDrawColor white;
  404. FFDrawColor green;
  405. FFDrawColor blue;
  406. FFDrawColor red;
  407. FFDrawColor *colors[4];
  408. uint16_t values[4][80][80];
  409. void (*pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value);
  410. } PixscopeContext;
  411. #define POFFSET(x) offsetof(PixscopeContext, x)
  412. static const AVOption pixscope_options[] = {
  413. { "x", "set scope x offset", POFFSET(xpos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
  414. { "y", "set scope y offset", POFFSET(ypos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
  415. { "w", "set scope width", POFFSET(w), AV_OPT_TYPE_INT, {.i64=7}, 1, 80, FLAGS },
  416. { "h", "set scope height", POFFSET(h), AV_OPT_TYPE_INT, {.i64=7}, 1, 80, FLAGS },
  417. { "o", "set window opacity", POFFSET(o), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
  418. { "wx", "set window x offset", POFFSET(wx), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 1, FLAGS },
  419. { "wy", "set window y offset", POFFSET(wy), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 1, FLAGS },
  420. { NULL }
  421. };
  422. AVFILTER_DEFINE_CLASS(pixscope);
  423. static int pixscope_config_input(AVFilterLink *inlink)
  424. {
  425. PixscopeContext *s = inlink->dst->priv;
  426. s->nb_planes = av_pix_fmt_count_planes(inlink->format);
  427. ff_draw_init(&s->draw, inlink->format, 0);
  428. ff_draw_color(&s->draw, &s->dark, (uint8_t[]){ 0, 0, 0, s->o * 255} );
  429. ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, 255} );
  430. ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
  431. ff_draw_color(&s->draw, &s->green, (uint8_t[]){ 0, 255, 0, 255} );
  432. ff_draw_color(&s->draw, &s->blue, (uint8_t[]){ 0, 0, 255, 255} );
  433. ff_draw_color(&s->draw, &s->red, (uint8_t[]){ 255, 0, 0, 255} );
  434. s->nb_comps = s->draw.desc->nb_components;
  435. s->is_rgb = s->draw.desc->flags & AV_PIX_FMT_FLAG_RGB;
  436. if (s->is_rgb) {
  437. s->colors[0] = &s->red;
  438. s->colors[1] = &s->green;
  439. s->colors[2] = &s->blue;
  440. s->colors[3] = &s->white;
  441. ff_fill_rgba_map(s->rgba_map, inlink->format);
  442. } else {
  443. s->colors[0] = &s->white;
  444. s->colors[1] = &s->blue;
  445. s->colors[2] = &s->red;
  446. s->colors[3] = &s->white;
  447. s->rgba_map[0] = 0;
  448. s->rgba_map[1] = 1;
  449. s->rgba_map[2] = 2;
  450. s->rgba_map[3] = 3;
  451. }
  452. if (s->draw.desc->comp[0].depth <= 8) {
  453. s->pick_color = pick_color8;
  454. } else {
  455. s->pick_color = pick_color16;
  456. }
  457. if (inlink->w < 640 || inlink->h < 480) {
  458. av_log(inlink->dst, AV_LOG_ERROR, "min supported resolution is 640x480\n");
  459. return AVERROR(EINVAL);
  460. }
  461. s->ww = 300;
  462. s->wh = 300 * 1.6;
  463. s->x = s->xpos * (inlink->w - 1);
  464. s->y = s->ypos * (inlink->h - 1);
  465. if (s->x + s->w >= inlink->w || s->y + s->h >= inlink->h) {
  466. av_log(inlink->dst, AV_LOG_WARNING, "scope position is out of range, clipping\n");
  467. s->x = FFMIN(s->x, inlink->w - s->w);
  468. s->y = FFMIN(s->y, inlink->h - s->h);
  469. }
  470. return 0;
  471. }
  472. #define SQR(x) ((x)*(x))
  473. static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in)
  474. {
  475. AVFilterContext *ctx = inlink->dst;
  476. PixscopeContext *s = ctx->priv;
  477. AVFilterLink *outlink = ctx->outputs[0];
  478. AVFrame *out = ff_get_video_buffer(outlink, in->width, in->height);
  479. int max[4] = { 0 }, min[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };
  480. float average[4] = { 0 };
  481. double std[4] = { 0 }, rms[4] = { 0 };
  482. const char rgba[4] = { 'R', 'G', 'B', 'A' };
  483. const char yuva[4] = { 'Y', 'U', 'V', 'A' };
  484. int x, y, X, Y, i, w, h;
  485. char text[128];
  486. if (!out) {
  487. av_frame_free(&in);
  488. return AVERROR(ENOMEM);
  489. }
  490. av_frame_copy_props(out, in);
  491. av_frame_copy(out, in);
  492. w = s->ww / s->w;
  493. h = s->ww / s->h;
  494. if (s->wx >= 0) {
  495. X = (in->width - s->ww) * s->wx;
  496. } else {
  497. X = (in->width - s->ww) * -s->wx;
  498. }
  499. if (s->wy >= 0) {
  500. Y = (in->height - s->wh) * s->wy;
  501. } else {
  502. Y = (in->height - s->wh) * -s->wy;
  503. }
  504. if (s->wx < 0) {
  505. if (s->x + s->w >= X && (s->x + s->w <= X + s->ww) &&
  506. s->y + s->h >= Y && (s->y + s->h <= Y + s->wh)) {
  507. X = (in->width - s->ww) * (1 + s->wx);
  508. }
  509. }
  510. if (s->wy < 0) {
  511. if (s->x + s->w >= X && (s->x + s->w <= X + s->ww) &&
  512. s->y + s->h >= Y && (s->y + s->h <= Y + s->wh)) {
  513. Y = (in->height - s->wh) * (1 + s->wy);
  514. }
  515. }
  516. ff_blend_rectangle(&s->draw, &s->dark, out->data, out->linesize,
  517. out->width, out->height,
  518. X,
  519. Y,
  520. s->ww,
  521. s->wh);
  522. for (y = 0; y < s->h; y++) {
  523. for (x = 0; x < s->w; x++) {
  524. FFDrawColor color = { { 0 } };
  525. int value[4] = { 0 };
  526. s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value);
  527. ff_fill_rectangle(&s->draw, &color, out->data, out->linesize,
  528. x * w + (s->ww - 4 - (s->w * w)) / 2 + X, y * h + 2 + Y, w, h);
  529. for (i = 0; i < 4; i++) {
  530. s->values[i][x][y] = value[i];
  531. rms[i] += (double)value[i] * (double)value[i];
  532. average[i] += value[i];
  533. min[i] = FFMIN(min[i], value[i]);
  534. max[i] = FFMAX(max[i], value[i]);
  535. }
  536. }
  537. }
  538. ff_blend_rectangle(&s->draw, &s->black, out->data, out->linesize,
  539. out->width, out->height,
  540. s->x - 2, s->y - 2, s->w + 4, 1);
  541. ff_blend_rectangle(&s->draw, &s->white, out->data, out->linesize,
  542. out->width, out->height,
  543. s->x - 1, s->y - 1, s->w + 2, 1);
  544. ff_blend_rectangle(&s->draw, &s->white, out->data, out->linesize,
  545. out->width, out->height,
  546. s->x - 1, s->y - 1, 1, s->h + 2);
  547. ff_blend_rectangle(&s->draw, &s->black, out->data, out->linesize,
  548. out->width, out->height,
  549. s->x - 2, s->y - 2, 1, s->h + 4);
  550. ff_blend_rectangle(&s->draw, &s->white, out->data, out->linesize,
  551. out->width, out->height,
  552. s->x - 1, s->y + 1 + s->h, s->w + 3, 1);
  553. ff_blend_rectangle(&s->draw, &s->black, out->data, out->linesize,
  554. out->width, out->height,
  555. s->x - 2, s->y + 2 + s->h, s->w + 4, 1);
  556. ff_blend_rectangle(&s->draw, &s->white, out->data, out->linesize,
  557. out->width, out->height,
  558. s->x + 1 + s->w, s->y - 1, 1, s->h + 2);
  559. ff_blend_rectangle(&s->draw, &s->black, out->data, out->linesize,
  560. out->width, out->height,
  561. s->x + 2 + s->w, s->y - 2, 1, s->h + 5);
  562. for (i = 0; i < 4; i++) {
  563. rms[i] /= s->w * s->h;
  564. rms[i] = sqrt(rms[i]);
  565. average[i] /= s->w * s->h;
  566. }
  567. for (y = 0; y < s->h; y++) {
  568. for (x = 0; x < s->w; x++) {
  569. for (i = 0; i < 4; i++)
  570. std[i] += SQR(s->values[i][x][y] - average[i]);
  571. }
  572. }
  573. for (i = 0; i < 4; i++) {
  574. std[i] /= s->w * s->h;
  575. std[i] = sqrt(std[i]);
  576. }
  577. snprintf(text, sizeof(text), "CH AVG MIN MAX RMS\n");
  578. draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 5, text, 0);
  579. for (i = 0; i < s->nb_comps; i++) {
  580. int c = s->rgba_map[i];
  581. 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]);
  582. draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 15 * (i + 1), text, 0);
  583. }
  584. snprintf(text, sizeof(text), "CH STD\n");
  585. draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 15 * (0 + 5), text, 0);
  586. for (i = 0; i < s->nb_comps; i++) {
  587. int c = s->rgba_map[i];
  588. snprintf(text, sizeof(text), "%c %07.2f\n", s->is_rgb ? rgba[i] : yuva[i], std[c]);
  589. draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 15 * (i + 6), text, 0);
  590. }
  591. av_frame_free(&in);
  592. return ff_filter_frame(outlink, out);
  593. }
  594. static const AVFilterPad pixscope_inputs[] = {
  595. {
  596. .name = "default",
  597. .type = AVMEDIA_TYPE_VIDEO,
  598. .filter_frame = pixscope_filter_frame,
  599. .config_props = pixscope_config_input,
  600. },
  601. { NULL }
  602. };
  603. static const AVFilterPad pixscope_outputs[] = {
  604. {
  605. .name = "default",
  606. .type = AVMEDIA_TYPE_VIDEO,
  607. },
  608. { NULL }
  609. };
  610. AVFilter ff_vf_pixscope = {
  611. .name = "pixscope",
  612. .description = NULL_IF_CONFIG_SMALL("Pixel data analysis."),
  613. .priv_size = sizeof(PixscopeContext),
  614. .priv_class = &pixscope_class,
  615. .query_formats = query_formats,
  616. .inputs = pixscope_inputs,
  617. .outputs = pixscope_outputs,
  618. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
  619. };
  620. typedef struct PixelValues {
  621. uint16_t p[4];
  622. } PixelValues;
  623. typedef struct OscilloscopeContext {
  624. const AVClass *class;
  625. float xpos, ypos;
  626. float tx, ty;
  627. float size;
  628. float tilt;
  629. float theight, twidth;
  630. float o;
  631. int components;
  632. int grid;
  633. int statistics;
  634. int scope;
  635. int x1, y1, x2, y2;
  636. int ox, oy;
  637. int height, width;
  638. int max;
  639. int nb_planes;
  640. int nb_comps;
  641. int is_rgb;
  642. uint8_t rgba_map[4];
  643. FFDrawContext draw;
  644. FFDrawColor dark;
  645. FFDrawColor black;
  646. FFDrawColor white;
  647. FFDrawColor green;
  648. FFDrawColor blue;
  649. FFDrawColor red;
  650. FFDrawColor cyan;
  651. FFDrawColor magenta;
  652. FFDrawColor gray;
  653. FFDrawColor *colors[4];
  654. int nb_values;
  655. PixelValues *values;
  656. void (*pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value);
  657. void (*draw_trace)(struct OscilloscopeContext *s, AVFrame *frame);
  658. } OscilloscopeContext;
  659. #define OOFFSET(x) offsetof(OscilloscopeContext, x)
  660. static const AVOption oscilloscope_options[] = {
  661. { "x", "set scope x position", OOFFSET(xpos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
  662. { "y", "set scope y position", OOFFSET(ypos), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
  663. { "s", "set scope size", OOFFSET(size), AV_OPT_TYPE_FLOAT, {.dbl=0.8}, 0, 1, FLAGSR },
  664. { "t", "set scope tilt", OOFFSET(tilt), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
  665. { "o", "set trace opacity", OOFFSET(o), AV_OPT_TYPE_FLOAT, {.dbl=0.8}, 0, 1, FLAGSR },
  666. { "tx", "set trace x position", OOFFSET(tx), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGSR },
  667. { "ty", "set trace y position", OOFFSET(ty), AV_OPT_TYPE_FLOAT, {.dbl=0.9}, 0, 1, FLAGSR },
  668. { "tw", "set trace width", OOFFSET(twidth), AV_OPT_TYPE_FLOAT, {.dbl=0.8},.1, 1, FLAGSR },
  669. { "th", "set trace height", OOFFSET(theight), AV_OPT_TYPE_FLOAT, {.dbl=0.3},.1, 1, FLAGSR },
  670. { "c", "set components to trace", OOFFSET(components), AV_OPT_TYPE_INT, {.i64=7}, 0, 15, FLAGSR },
  671. { "g", "draw trace grid", OOFFSET(grid), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGSR },
  672. { "st", "draw statistics", OOFFSET(statistics), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGSR },
  673. { "sc", "draw scope", OOFFSET(scope), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGSR },
  674. { NULL }
  675. };
  676. AVFILTER_DEFINE_CLASS(oscilloscope);
  677. static void oscilloscope_uninit(AVFilterContext *ctx)
  678. {
  679. OscilloscopeContext *s = ctx->priv;
  680. av_freep(&s->values);
  681. }
  682. static void draw_line(FFDrawContext *draw, int x0, int y0, int x1, int y1,
  683. AVFrame *out, FFDrawColor *color)
  684. {
  685. int dx = FFABS(x1 - x0), sx = x0 < x1 ? 1 : -1;
  686. int dy = FFABS(y1 - y0), sy = y0 < y1 ? 1 : -1;
  687. int err = (dx > dy ? dx : -dy) / 2, e2;
  688. int p, i;
  689. for (;;) {
  690. if (x0 >= 0 && y0 >= 0 && x0 < out->width && y0 < out->height) {
  691. for (p = 0; p < draw->nb_planes; p++) {
  692. if (draw->desc->comp[p].depth == 8) {
  693. if (draw->nb_planes == 1) {
  694. for (i = 0; i < draw->desc->nb_components; i++) {
  695. out->data[0][y0 * out->linesize[0] + x0 * draw->pixelstep[0] + i] = color->comp[0].u8[i];
  696. }
  697. } else {
  698. out->data[p][out->linesize[p] * (y0 >> draw->vsub[p]) + (x0 >> draw->hsub[p])] = color->comp[p].u8[0];
  699. }
  700. } else {
  701. if (draw->nb_planes == 1) {
  702. for (i = 0; i < draw->desc->nb_components; i++) {
  703. AV_WN16(out->data[0] + y0 * out->linesize[0] + (x0 * draw->pixelstep[0] + i), color->comp[0].u16[i]);
  704. }
  705. } else {
  706. AV_WN16(out->data[p] + out->linesize[p] * (y0 >> draw->vsub[p]) + (x0 >> draw->hsub[p]) * 2, color->comp[p].u16[0]);
  707. }
  708. }
  709. }
  710. }
  711. if (x0 == x1 && y0 == y1)
  712. break;
  713. e2 = err;
  714. if (e2 >-dx) {
  715. err -= dy;
  716. x0 += sx;
  717. }
  718. if (e2 < dy) {
  719. err += dx;
  720. y0 += sy;
  721. }
  722. }
  723. }
  724. static void draw_trace8(OscilloscopeContext *s, AVFrame *frame)
  725. {
  726. int i, c;
  727. for (i = 1; i < s->nb_values; i++) {
  728. for (c = 0; c < s->nb_comps; c++) {
  729. if ((1 << c) & s->components) {
  730. int x = i * s->width / s->nb_values;
  731. int px = (i - 1) * s->width / s->nb_values;
  732. int py = s->height - s->values[i-1].p[s->rgba_map[c]] * s->height / 256;
  733. int y = s->height - s->values[i].p[s->rgba_map[c]] * s->height / 256;
  734. draw_line(&s->draw, s->ox + x, s->oy + y, s->ox + px, s->oy + py, frame, s->colors[c]);
  735. }
  736. }
  737. }
  738. }
  739. static void draw_trace16(OscilloscopeContext *s, AVFrame *frame)
  740. {
  741. int i, c;
  742. for (i = 1; i < s->nb_values; i++) {
  743. for (c = 0; c < s->nb_comps; c++) {
  744. if ((1 << c) & s->components) {
  745. int x = i * s->width / s->nb_values;
  746. int px = (i - 1) * s->width / s->nb_values;
  747. int py = s->height - s->values[i-1].p[s->rgba_map[c]] * s->height / s->max;
  748. int y = s->height - s->values[i].p[s->rgba_map[c]] * s->height / s->max;
  749. draw_line(&s->draw, s->ox + x, s->oy + y, s->ox + px, s->oy + py, frame, s->colors[c]);
  750. }
  751. }
  752. }
  753. }
  754. static void update_oscilloscope(AVFilterContext *ctx)
  755. {
  756. OscilloscopeContext *s = ctx->priv;
  757. AVFilterLink *inlink = ctx->inputs[0];
  758. int cx, cy, size;
  759. double tilt;
  760. ff_draw_color(&s->draw, &s->dark, (uint8_t[]){ 0, 0, 0, s->o * 255} );
  761. s->height = s->theight * inlink->h;
  762. s->width = s->twidth * inlink->w;
  763. size = hypot(inlink->w, inlink->h);
  764. size *= s->size;
  765. tilt = (s->tilt - 0.5) * M_PI;
  766. cx = s->xpos * (inlink->w - 1);
  767. cy = s->ypos * (inlink->h - 1);
  768. s->x1 = cx - size / 2.0 * cos(tilt);
  769. s->x2 = cx + size / 2.0 * cos(tilt);
  770. s->y1 = cy - size / 2.0 * sin(tilt);
  771. s->y2 = cy + size / 2.0 * sin(tilt);
  772. s->ox = (inlink->w - s->width) * s->tx;
  773. s->oy = (inlink->h - s->height) * s->ty;
  774. }
  775. static int oscilloscope_config_input(AVFilterLink *inlink)
  776. {
  777. OscilloscopeContext *s = inlink->dst->priv;
  778. int size;
  779. s->nb_planes = av_pix_fmt_count_planes(inlink->format);
  780. ff_draw_init(&s->draw, inlink->format, 0);
  781. ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, 255} );
  782. ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
  783. ff_draw_color(&s->draw, &s->green, (uint8_t[]){ 0, 255, 0, 255} );
  784. ff_draw_color(&s->draw, &s->blue, (uint8_t[]){ 0, 0, 255, 255} );
  785. ff_draw_color(&s->draw, &s->red, (uint8_t[]){ 255, 0, 0, 255} );
  786. ff_draw_color(&s->draw, &s->cyan, (uint8_t[]){ 0, 255, 255, 255} );
  787. ff_draw_color(&s->draw, &s->magenta, (uint8_t[]){ 255, 0, 255, 255} );
  788. ff_draw_color(&s->draw, &s->gray, (uint8_t[]){ 128, 128, 128, 255} );
  789. s->nb_comps = s->draw.desc->nb_components;
  790. s->is_rgb = s->draw.desc->flags & AV_PIX_FMT_FLAG_RGB;
  791. if (s->is_rgb) {
  792. s->colors[0] = &s->red;
  793. s->colors[1] = &s->green;
  794. s->colors[2] = &s->blue;
  795. s->colors[3] = &s->white;
  796. ff_fill_rgba_map(s->rgba_map, inlink->format);
  797. } else {
  798. s->colors[0] = &s->white;
  799. s->colors[1] = &s->cyan;
  800. s->colors[2] = &s->magenta;
  801. s->colors[3] = &s->white;
  802. s->rgba_map[0] = 0;
  803. s->rgba_map[1] = 1;
  804. s->rgba_map[2] = 2;
  805. s->rgba_map[3] = 3;
  806. }
  807. if (s->draw.desc->comp[0].depth <= 8) {
  808. s->pick_color = pick_color8;
  809. s->draw_trace = draw_trace8;
  810. } else {
  811. s->pick_color = pick_color16;
  812. s->draw_trace = draw_trace16;
  813. }
  814. s->max = (1 << s->draw.desc->comp[0].depth);
  815. size = hypot(inlink->w, inlink->h);
  816. s->values = av_calloc(size, sizeof(*s->values));
  817. if (!s->values)
  818. return AVERROR(ENOMEM);
  819. update_oscilloscope(inlink->dst);
  820. return 0;
  821. }
  822. static void draw_scope(OscilloscopeContext *s, int x0, int y0, int x1, int y1,
  823. AVFrame *out, PixelValues *p, int state)
  824. {
  825. int dx = FFABS(x1 - x0), sx = x0 < x1 ? 1 : -1;
  826. int dy = FFABS(y1 - y0), sy = y0 < y1 ? 1 : -1;
  827. int err = (dx > dy ? dx : -dy) / 2, e2;
  828. for (;;) {
  829. if (x0 >= 0 && y0 >= 0 && x0 < out->width && y0 < out->height) {
  830. FFDrawColor color = { { 0 } };
  831. int value[4] = { 0 };
  832. s->pick_color(&s->draw, &color, out, x0, y0, value);
  833. s->values[s->nb_values].p[0] = value[0];
  834. s->values[s->nb_values].p[1] = value[1];
  835. s->values[s->nb_values].p[2] = value[2];
  836. s->values[s->nb_values].p[3] = value[3];
  837. s->nb_values++;
  838. if (s->scope) {
  839. if (s->draw.desc->comp[0].depth == 8) {
  840. if (s->draw.nb_planes == 1) {
  841. int i;
  842. for (i = 0; i < s->nb_comps; i++)
  843. out->data[0][out->linesize[0] * y0 + x0 * s->draw.pixelstep[0] + i] = 255 * ((s->nb_values + state) & 1);
  844. } else {
  845. out->data[0][out->linesize[0] * y0 + x0] = 255 * ((s->nb_values + state) & 1);
  846. }
  847. } else {
  848. if (s->draw.nb_planes == 1) {
  849. int i;
  850. for (i = 0; i < s->nb_comps; i++)
  851. AV_WN16(out->data[0] + out->linesize[0] * y0 + x0 * s->draw.pixelstep[0] + i, (s->max - 1) * ((s->nb_values + state) & 1));
  852. } else {
  853. AV_WN16(out->data[0] + out->linesize[0] * y0 + 2 * x0, (s->max - 1) * ((s->nb_values + state) & 1));
  854. }
  855. }
  856. }
  857. }
  858. if (x0 == x1 && y0 == y1)
  859. break;
  860. e2 = err;
  861. if (e2 >-dx) {
  862. err -= dy;
  863. x0 += sx;
  864. }
  865. if (e2 < dy) {
  866. err += dx;
  867. y0 += sy;
  868. }
  869. }
  870. }
  871. static int oscilloscope_filter_frame(AVFilterLink *inlink, AVFrame *frame)
  872. {
  873. AVFilterContext *ctx = inlink->dst;
  874. OscilloscopeContext *s = ctx->priv;
  875. AVFilterLink *outlink = ctx->outputs[0];
  876. float average[4] = { 0 };
  877. int max[4] = { 0 };
  878. int min[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };
  879. int i, c;
  880. s->nb_values = 0;
  881. draw_scope(s, s->x1, s->y1, s->x2, s->y2, frame, s->values, inlink->frame_count_in & 1);
  882. ff_blend_rectangle(&s->draw, &s->dark, frame->data, frame->linesize,
  883. frame->width, frame->height,
  884. s->ox, s->oy, s->width, s->height + 20 * s->statistics);
  885. if (s->grid && outlink->h >= 10) {
  886. ff_fill_rectangle(&s->draw, &s->gray, frame->data, frame->linesize,
  887. s->ox, s->oy, s->width - 1, 1);
  888. for (i = 1; i < 5; i++) {
  889. ff_fill_rectangle(&s->draw, &s->gray, frame->data, frame->linesize,
  890. s->ox, s->oy + i * (s->height - 1) / 4, s->width, 1);
  891. }
  892. for (i = 0; i < 10; i++) {
  893. ff_fill_rectangle(&s->draw, &s->gray, frame->data, frame->linesize,
  894. s->ox + i * (s->width - 1) / 10, s->oy, 1, s->height);
  895. }
  896. ff_fill_rectangle(&s->draw, &s->gray, frame->data, frame->linesize,
  897. s->ox + s->width - 1, s->oy, 1, s->height);
  898. }
  899. s->draw_trace(s, frame);
  900. for (i = 0; i < s->nb_values; i++) {
  901. for (c = 0; c < s->nb_comps; c++) {
  902. if ((1 << c) & s->components) {
  903. max[c] = FFMAX(max[c], s->values[i].p[s->rgba_map[c]]);
  904. min[c] = FFMIN(min[c], s->values[i].p[s->rgba_map[c]]);
  905. average[c] += s->values[i].p[s->rgba_map[c]];
  906. }
  907. }
  908. }
  909. for (c = 0; c < s->nb_comps; c++) {
  910. average[c] /= s->nb_values;
  911. }
  912. if (s->statistics && s->height > 10 && s->width > 280 * av_popcount(s->components)) {
  913. for (c = 0, i = 0; c < s->nb_comps; c++) {
  914. if ((1 << c) & s->components) {
  915. const char rgba[4] = { 'R', 'G', 'B', 'A' };
  916. const char yuva[4] = { 'Y', 'U', 'V', 'A' };
  917. char text[128];
  918. 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]);
  919. draw_text(&s->draw, frame, &s->white, s->ox + 2 + 280 * i++, s->oy + s->height + 4, text, 0);
  920. }
  921. }
  922. }
  923. return ff_filter_frame(outlink, frame);
  924. }
  925. static int oscilloscope_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
  926. char *res, int res_len, int flags)
  927. {
  928. int ret;
  929. ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
  930. if (ret < 0)
  931. return ret;
  932. update_oscilloscope(ctx);
  933. return 0;
  934. }
  935. static const AVFilterPad oscilloscope_inputs[] = {
  936. {
  937. .name = "default",
  938. .type = AVMEDIA_TYPE_VIDEO,
  939. .filter_frame = oscilloscope_filter_frame,
  940. .config_props = oscilloscope_config_input,
  941. .needs_writable = 1,
  942. },
  943. { NULL }
  944. };
  945. static const AVFilterPad oscilloscope_outputs[] = {
  946. {
  947. .name = "default",
  948. .type = AVMEDIA_TYPE_VIDEO,
  949. },
  950. { NULL }
  951. };
  952. AVFilter ff_vf_oscilloscope = {
  953. .name = "oscilloscope",
  954. .description = NULL_IF_CONFIG_SMALL("2D Video Oscilloscope."),
  955. .priv_size = sizeof(OscilloscopeContext),
  956. .priv_class = &oscilloscope_class,
  957. .query_formats = query_formats,
  958. .uninit = oscilloscope_uninit,
  959. .inputs = oscilloscope_inputs,
  960. .outputs = oscilloscope_outputs,
  961. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
  962. .process_command = oscilloscope_process_command,
  963. };