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.

763 lines
20KB

  1. /*
  2. * Copyright (c) 2003 Rich Felker
  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 General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * 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/imgutils.h"
  22. #include "libavutil/opt.h"
  23. #include "libavutil/pixdesc.h"
  24. #include "avfilter.h"
  25. #include "formats.h"
  26. #include "internal.h"
  27. #include "video.h"
  28. #include "vf_pullup.h"
  29. #define F_HAVE_BREAKS 1
  30. #define F_HAVE_AFFINITY 2
  31. #define BREAK_LEFT 1
  32. #define BREAK_RIGHT 2
  33. #define OFFSET(x) offsetof(PullupContext, x)
  34. #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  35. static const AVOption pullup_options[] = {
  36. { "jl", "set left junk size", OFFSET(junk_left), AV_OPT_TYPE_INT, {.i64=1}, 0, INT_MAX, FLAGS },
  37. { "jr", "set right junk size", OFFSET(junk_right), AV_OPT_TYPE_INT, {.i64=1}, 0, INT_MAX, FLAGS },
  38. { "jt", "set top junk size", OFFSET(junk_top), AV_OPT_TYPE_INT, {.i64=4}, 1, INT_MAX, FLAGS },
  39. { "jd", "set down junk size", OFFSET(junk_down), AV_OPT_TYPE_INT, {.i64=4}, 1, INT_MAX, FLAGS },
  40. { "sb", "set strict breaks", OFFSET(strict_breaks), AV_OPT_TYPE_INT, {.i64=0},-1, 1, FLAGS },
  41. { "mp", "set metric plane", OFFSET(metric_plane), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "mp" },
  42. { "y", "luma", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mp" },
  43. { "u", "chroma blue", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mp" },
  44. { "v", "chroma red", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "mp" },
  45. { NULL }
  46. };
  47. AVFILTER_DEFINE_CLASS(pullup);
  48. static int query_formats(AVFilterContext *ctx)
  49. {
  50. static const enum AVPixelFormat pix_fmts[] = {
  51. AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P,
  52. AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
  53. AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
  54. AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
  55. AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
  56. AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_GRAY8,
  57. AV_PIX_FMT_NONE
  58. };
  59. ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
  60. return 0;
  61. }
  62. #define ABS(a) (((a) ^ ((a) >> 31)) - ((a) >> 31))
  63. static int diff_c(const uint8_t *a, const uint8_t *b, int s)
  64. {
  65. int i, j, diff = 0;
  66. for (i = 0; i < 4; i++) {
  67. for (j = 0; j < 8; j++)
  68. diff += ABS(a[j] - b[j]);
  69. a += s;
  70. b += s;
  71. }
  72. return diff;
  73. }
  74. static int comb_c(const uint8_t *a, const uint8_t *b, int s)
  75. {
  76. int i, j, comb = 0;
  77. for (i = 0; i < 4; i++) {
  78. for (j = 0; j < 8; j++)
  79. comb += ABS((a[j] << 1) - b[j - s] - b[j ]) +
  80. ABS((b[j] << 1) - a[j ] - a[j + s]);
  81. a += s;
  82. b += s;
  83. }
  84. return comb;
  85. }
  86. static int var_c(const uint8_t *a, const uint8_t *b, int s)
  87. {
  88. int i, j, var = 0;
  89. for (i = 0; i < 3; i++) {
  90. for (j = 0; j < 8; j++)
  91. var += ABS(a[j] - a[j + s]);
  92. a += s;
  93. }
  94. return 4 * var; /* match comb scaling */
  95. }
  96. static int alloc_metrics(PullupContext *s, PullupField *f)
  97. {
  98. f->diffs = av_calloc(FFALIGN(s->metric_length, 16), sizeof(*f->diffs));
  99. f->combs = av_calloc(FFALIGN(s->metric_length, 16), sizeof(*f->combs));
  100. f->vars = av_calloc(FFALIGN(s->metric_length, 16), sizeof(*f->vars));
  101. if (!f->diffs || !f->combs || !f->vars) {
  102. av_freep(&f->diffs);
  103. av_freep(&f->combs);
  104. av_freep(&f->vars);
  105. return AVERROR(ENOMEM);
  106. }
  107. return 0;
  108. }
  109. static PullupField *make_field_queue(PullupContext *s, int len)
  110. {
  111. PullupField *head, *f;
  112. f = head = av_mallocz(sizeof(*head));
  113. if (!f)
  114. return NULL;
  115. if (alloc_metrics(s, f) < 0) {
  116. av_free(f);
  117. return NULL;
  118. }
  119. for (; len > 0; len--) {
  120. f->next = av_mallocz(sizeof(*f->next));
  121. if (!f->next)
  122. return NULL;
  123. f->next->prev = f;
  124. f = f->next;
  125. if (alloc_metrics(s, f) < 0)
  126. return NULL;
  127. }
  128. f->next = head;
  129. head->prev = f;
  130. return head;
  131. }
  132. static int config_input(AVFilterLink *inlink)
  133. {
  134. AVFilterContext *ctx = inlink->dst;
  135. PullupContext *s = ctx->priv;
  136. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  137. const int mp = s->metric_plane;
  138. s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
  139. s->planeheight[0] = s->planeheight[3] = inlink->h;
  140. s->planewidth[1] = s->planewidth[2] = FF_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
  141. s->planewidth[0] = s->planewidth[3] = inlink->w;
  142. s->nb_planes = av_pix_fmt_count_planes(inlink->format);
  143. s->metric_w = (s->planewidth[mp] - ((s->junk_left + s->junk_right) << 3)) >> 3;
  144. s->metric_h = (s->planeheight[mp] - ((s->junk_top + s->junk_bottom) << 1)) >> 3;
  145. s->metric_offset = (s->junk_left << 3) + (s->junk_top << 1) * s->planewidth[mp];
  146. s->metric_length = s->metric_w * s->metric_h;
  147. av_log(ctx, AV_LOG_DEBUG, "w: %d h: %d\n", s->metric_w, s->metric_h);
  148. av_log(ctx, AV_LOG_DEBUG, "offset: %d length: %d\n", s->metric_offset, s->metric_length);
  149. s->head = make_field_queue(s, 8);
  150. if (!s->head)
  151. return AVERROR(ENOMEM);
  152. s->diff = diff_c;
  153. s->comb = comb_c;
  154. s->var = var_c;
  155. if (ARCH_X86)
  156. ff_pullup_init_x86(s);
  157. return 0;
  158. }
  159. static int config_output(AVFilterLink *outlink)
  160. {
  161. outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
  162. return 0;
  163. }
  164. static PullupBuffer *pullup_lock_buffer(PullupBuffer *b, int parity)
  165. {
  166. if (!b)
  167. return NULL;
  168. if ((parity + 1) & 1)
  169. b->lock[0]++;
  170. if ((parity + 1) & 2)
  171. b->lock[1]++;
  172. return b;
  173. }
  174. static void pullup_release_buffer(PullupBuffer *b, int parity)
  175. {
  176. if (!b)
  177. return;
  178. if ((parity + 1) & 1)
  179. b->lock[0]--;
  180. if ((parity + 1) & 2)
  181. b->lock[1]--;
  182. }
  183. static int alloc_buffer(PullupContext *s, PullupBuffer *b)
  184. {
  185. int i;
  186. if (b->planes[0])
  187. return 0;
  188. for (i = 0; i < s->nb_planes; i++) {
  189. b->planes[i] = av_malloc(s->planeheight[i] * s->planewidth[i]);
  190. }
  191. return 0;
  192. }
  193. static PullupBuffer *pullup_get_buffer(PullupContext *s, int parity)
  194. {
  195. int i;
  196. /* Try first to get the sister buffer for the previous field */
  197. if (parity < 2 && s->last && parity != s->last->parity
  198. && !s->last->buffer->lock[parity]) {
  199. alloc_buffer(s, s->last->buffer);
  200. return pullup_lock_buffer(s->last->buffer, parity);
  201. }
  202. /* Prefer a buffer with both fields open */
  203. for (i = 0; i < FF_ARRAY_ELEMS(s->buffers); i++) {
  204. if (s->buffers[i].lock[0])
  205. continue;
  206. if (s->buffers[i].lock[1])
  207. continue;
  208. alloc_buffer(s, &s->buffers[i]);
  209. return pullup_lock_buffer(&s->buffers[i], parity);
  210. }
  211. if (parity == 2)
  212. return 0;
  213. /* Search for any half-free buffer */
  214. for (i = 0; i < FF_ARRAY_ELEMS(s->buffers); i++) {
  215. if (((parity + 1) & 1) && s->buffers[i].lock[0])
  216. continue;
  217. if (((parity + 1) & 2) && s->buffers[i].lock[1])
  218. continue;
  219. alloc_buffer(s, &s->buffers[i]);
  220. return pullup_lock_buffer(&s->buffers[i], parity);
  221. }
  222. return NULL;
  223. }
  224. static int queue_length(PullupField *begin, PullupField *end)
  225. {
  226. PullupField *f;
  227. int count = 1;
  228. if (!begin || !end)
  229. return 0;
  230. for (f = begin; f != end; f = f->next)
  231. count++;
  232. return count;
  233. }
  234. static int find_first_break(PullupField *f, int max)
  235. {
  236. int i;
  237. for (i = 0; i < max; i++) {
  238. if (f->breaks & BREAK_RIGHT || f->next->breaks & BREAK_LEFT)
  239. return i + 1;
  240. f = f->next;
  241. }
  242. return 0;
  243. }
  244. static void compute_breaks(PullupContext *s, PullupField *f0)
  245. {
  246. PullupField *f1 = f0->next;
  247. PullupField *f2 = f1->next;
  248. PullupField *f3 = f2->next;
  249. int i, l, max_l = 0, max_r = 0;
  250. if (f0->flags & F_HAVE_BREAKS)
  251. return;
  252. f0->flags |= F_HAVE_BREAKS;
  253. /* Special case when fields are 100% identical */
  254. if (f0->buffer == f2->buffer && f1->buffer != f3->buffer) {
  255. f2->breaks |= BREAK_RIGHT;
  256. return;
  257. }
  258. if (f0->buffer != f2->buffer && f1->buffer == f3->buffer) {
  259. f1->breaks |= BREAK_LEFT;
  260. return;
  261. }
  262. for (i = 0; i < s->metric_length; i++) {
  263. l = f2->diffs[i] - f3->diffs[i];
  264. if ( l > max_l)
  265. max_l = l;
  266. if (-l > max_r)
  267. max_r = -l;
  268. }
  269. /* Don't get tripped up when differences are mostly quant error */
  270. if (max_l + max_r < 128)
  271. return;
  272. if (max_l > 4 * max_r)
  273. f1->breaks |= BREAK_LEFT;
  274. if (max_r > 4 * max_l)
  275. f2->breaks |= BREAK_RIGHT;
  276. }
  277. static void compute_affinity(PullupContext *s, PullupField *f)
  278. {
  279. int i, max_l = 0, max_r = 0, l;
  280. if (f->flags & F_HAVE_AFFINITY)
  281. return;
  282. f->flags |= F_HAVE_AFFINITY;
  283. if (f->buffer == f->next->next->buffer) {
  284. f->affinity = 1;
  285. f->next->affinity = 0;
  286. f->next->next->affinity = -1;
  287. f->next->flags |= F_HAVE_AFFINITY;
  288. f->next->next->flags |= F_HAVE_AFFINITY;
  289. return;
  290. }
  291. for (i = 0; i < s->metric_length; i++) {
  292. int v = f->vars[i];
  293. int lv = f->prev->vars[i];
  294. int rv = f->next->vars[i];
  295. int lc = f->combs[i] - (v + lv) + ABS(v - lv);
  296. int rc = f->next->combs[i] - (v + rv) + ABS(v - rv);
  297. lc = FFMAX(lc, 0);
  298. rc = FFMAX(rc, 0);
  299. l = lc - rc;
  300. if ( l > max_l)
  301. max_l = l;
  302. if (-l > max_r)
  303. max_r = -l;
  304. }
  305. if (max_l + max_r < 64)
  306. return;
  307. if (max_r > 6 * max_l)
  308. f->affinity = -1;
  309. else if (max_l > 6 * max_r)
  310. f->affinity = 1;
  311. }
  312. static int decide_frame_length(PullupContext *s)
  313. {
  314. PullupField *f0 = s->first;
  315. PullupField *f1 = f0->next;
  316. PullupField *f2 = f1->next;
  317. PullupField *f;
  318. int i, l, n;
  319. if (queue_length(s->first, s->last) < 4)
  320. return 0;
  321. f = s->first;
  322. n = queue_length(f, s->last);
  323. for (i = 0; i < n - 1; i++) {
  324. if (i < n - 3)
  325. compute_breaks(s, f);
  326. compute_affinity(s, f);
  327. f = f->next;
  328. }
  329. if (f0->affinity == -1)
  330. return 1;
  331. l = find_first_break(f0, 3);
  332. if (l == 1 && s->strict_breaks < 0)
  333. l = 0;
  334. switch (l) {
  335. case 1:
  336. return 1 + (s->strict_breaks < 1 && f0->affinity == 1 && f1->affinity == -1);
  337. case 2:
  338. /* FIXME: strictly speaking, f0->prev is no longer valid... :) */
  339. if (s->strict_pairs
  340. && (f0->prev->breaks & BREAK_RIGHT) && (f2->breaks & BREAK_LEFT)
  341. && (f0->affinity != 1 || f1->affinity != -1) )
  342. return 1;
  343. return 1 + (f1->affinity != 1);
  344. case 3:
  345. return 2 + (f2->affinity != 1);
  346. default:
  347. /* 9 possibilities covered before switch */
  348. if (f1->affinity == 1)
  349. return 1; /* covers 6 */
  350. else if (f1->affinity == -1)
  351. return 2; /* covers 6 */
  352. else if (f2->affinity == -1) { /* covers 2 */
  353. return (f0->affinity == 1) ? 3 : 1;
  354. } else {
  355. return 2; /* the remaining 6 */
  356. }
  357. }
  358. }
  359. static PullupFrame *pullup_get_frame(PullupContext *s)
  360. {
  361. PullupFrame *fr = &s->frame;
  362. int i, n = decide_frame_length(s);
  363. int aff = s->first->next->affinity;
  364. av_assert1(n < FF_ARRAY_ELEMS(fr->ifields));
  365. if (!n || fr->lock)
  366. return NULL;
  367. fr->lock++;
  368. fr->length = n;
  369. fr->parity = s->first->parity;
  370. fr->buffer = 0;
  371. for (i = 0; i < n; i++) {
  372. /* We cheat and steal the buffer without release+relock */
  373. fr->ifields[i] = s->first->buffer;
  374. s->first->buffer = 0;
  375. s->first = s->first->next;
  376. }
  377. if (n == 1) {
  378. fr->ofields[fr->parity ] = fr->ifields[0];
  379. fr->ofields[fr->parity ^ 1] = 0;
  380. } else if (n == 2) {
  381. fr->ofields[fr->parity ] = fr->ifields[0];
  382. fr->ofields[fr->parity ^ 1] = fr->ifields[1];
  383. } else if (n == 3) {
  384. if (!aff)
  385. aff = (fr->ifields[0] == fr->ifields[1]) ? -1 : 1;
  386. fr->ofields[fr->parity ] = fr->ifields[1 + aff];
  387. fr->ofields[fr->parity ^ 1] = fr->ifields[1 ];
  388. }
  389. pullup_lock_buffer(fr->ofields[0], 0);
  390. pullup_lock_buffer(fr->ofields[1], 1);
  391. if (fr->ofields[0] == fr->ofields[1]) {
  392. fr->buffer = fr->ofields[0];
  393. pullup_lock_buffer(fr->buffer, 2);
  394. return fr;
  395. }
  396. return fr;
  397. }
  398. static void pullup_release_frame(PullupFrame *f)
  399. {
  400. int i;
  401. for (i = 0; i < f->length; i++)
  402. pullup_release_buffer(f->ifields[i], f->parity ^ (i & 1));
  403. pullup_release_buffer(f->ofields[0], 0);
  404. pullup_release_buffer(f->ofields[1], 1);
  405. if (f->buffer)
  406. pullup_release_buffer(f->buffer, 2);
  407. f->lock--;
  408. }
  409. static void compute_metric(PullupContext *s, int *dest,
  410. PullupField *fa, int pa, PullupField *fb, int pb,
  411. int (*func)(const uint8_t *, const uint8_t *, int))
  412. {
  413. int mp = s->metric_plane;
  414. int xstep = 8;
  415. int ystep = s->planewidth[mp] << 3;
  416. int stride = s->planewidth[mp] << 1; /* field stride */
  417. int w = s->metric_w * xstep;
  418. uint8_t *a, *b;
  419. int x, y;
  420. if (!fa->buffer || !fb->buffer)
  421. return;
  422. /* Shortcut for duplicate fields (e.g. from RFF flag) */
  423. if (fa->buffer == fb->buffer && pa == pb) {
  424. memset(dest, 0, s->metric_length * sizeof(*dest));
  425. return;
  426. }
  427. a = fa->buffer->planes[mp] + pa * s->planewidth[mp] + s->metric_offset;
  428. b = fb->buffer->planes[mp] + pb * s->planewidth[mp] + s->metric_offset;
  429. for (y = 0; y < s->metric_h; y++) {
  430. for (x = 0; x < w; x += xstep)
  431. *dest++ = func(a + x, b + x, stride);
  432. a += ystep; b += ystep;
  433. }
  434. }
  435. static int check_field_queue(PullupContext *s)
  436. {
  437. int ret;
  438. if (s->head->next == s->first) {
  439. PullupField *f = av_mallocz(sizeof(*f));
  440. if (!f)
  441. return AVERROR(ENOMEM);
  442. if ((ret = alloc_metrics(s, f)) < 0) {
  443. av_free(f);
  444. return ret;
  445. }
  446. f->prev = s->head;
  447. f->next = s->first;
  448. s->head->next = f;
  449. s->first->prev = f;
  450. }
  451. return 0;
  452. }
  453. static void pullup_submit_field(PullupContext *s, PullupBuffer *b, int parity)
  454. {
  455. PullupField *f;
  456. /* Grow the circular list if needed */
  457. if (check_field_queue(s) < 0)
  458. return;
  459. /* Cannot have two fields of same parity in a row; drop the new one */
  460. if (s->last && s->last->parity == parity)
  461. return;
  462. f = s->head;
  463. f->parity = parity;
  464. f->buffer = pullup_lock_buffer(b, parity);
  465. f->flags = 0;
  466. f->breaks = 0;
  467. f->affinity = 0;
  468. compute_metric(s, f->diffs, f, parity, f->prev->prev, parity, s->diff);
  469. compute_metric(s, f->combs, parity ? f->prev : f, 0, parity ? f : f->prev, 1, s->comb);
  470. compute_metric(s, f->vars, f, parity, f, -1, s->var);
  471. emms_c();
  472. /* Advance the circular list */
  473. if (!s->first)
  474. s->first = s->head;
  475. s->last = s->head;
  476. s->head = s->head->next;
  477. }
  478. static void copy_field(PullupContext *s,
  479. PullupBuffer *dst, PullupBuffer *src, int parity)
  480. {
  481. uint8_t *dd, *ss;
  482. int i;
  483. for (i = 0; i < s->nb_planes; i++) {
  484. ss = src->planes[i] + parity * s->planewidth[i];
  485. dd = dst->planes[i] + parity * s->planewidth[i];
  486. av_image_copy_plane(dd, s->planewidth[i] << 1,
  487. ss, s->planewidth[i] << 1,
  488. s->planewidth[i], s->planeheight[i] >> 1);
  489. }
  490. }
  491. static void pullup_pack_frame(PullupContext *s, PullupFrame *fr)
  492. {
  493. int i;
  494. if (fr->buffer)
  495. return;
  496. if (fr->length < 2)
  497. return; /* FIXME: deal with this */
  498. for (i = 0; i < 2; i++) {
  499. if (fr->ofields[i]->lock[i^1])
  500. continue;
  501. fr->buffer = fr->ofields[i];
  502. pullup_lock_buffer(fr->buffer, 2);
  503. copy_field(s, fr->buffer, fr->ofields[i^1], i^1);
  504. return;
  505. }
  506. fr->buffer = pullup_get_buffer(s, 2);
  507. copy_field(s, fr->buffer, fr->ofields[0], 0);
  508. copy_field(s, fr->buffer, fr->ofields[1], 1);
  509. }
  510. static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  511. {
  512. AVFilterContext *ctx = inlink->dst;
  513. AVFilterLink *outlink = ctx->outputs[0];
  514. PullupContext *s = ctx->priv;
  515. PullupBuffer *b;
  516. PullupFrame *f;
  517. AVFrame *out;
  518. int p, ret = 0;
  519. b = pullup_get_buffer(s, 2);
  520. if (!b) {
  521. av_log(ctx, AV_LOG_WARNING, "Could not get buffer!\n");
  522. f = pullup_get_frame(s);
  523. pullup_release_frame(f);
  524. goto end;
  525. }
  526. av_image_copy(b->planes, s->planewidth,
  527. (const uint8_t**)in->data, in->linesize,
  528. inlink->format, inlink->w, inlink->h);
  529. p = !!in->interlaced_frame;
  530. pullup_submit_field(s, b, p );
  531. pullup_submit_field(s, b, p^1);
  532. if (in->repeat_pict)
  533. pullup_submit_field(s, b, p);
  534. pullup_release_buffer(b, 2);
  535. f = pullup_get_frame(s);
  536. if (!f)
  537. goto end;
  538. if (f->length < 2) {
  539. pullup_release_frame(f);
  540. f = pullup_get_frame(s);
  541. if (!f)
  542. goto end;
  543. if (f->length < 2) {
  544. pullup_release_frame(f);
  545. if (!in->repeat_pict)
  546. goto end;
  547. f = pullup_get_frame(s);
  548. if (!f)
  549. goto end;
  550. if (f->length < 2) {
  551. pullup_release_frame(f);
  552. goto end;
  553. }
  554. }
  555. }
  556. /* If the frame isn't already exportable... */
  557. if (!f->buffer)
  558. pullup_pack_frame(s, f);
  559. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  560. if (!out) {
  561. ret = AVERROR(ENOMEM);
  562. goto end;
  563. }
  564. av_frame_copy_props(out, in);
  565. av_image_copy(out->data, out->linesize,
  566. (const uint8_t**)f->buffer->planes, s->planewidth,
  567. inlink->format, inlink->w, inlink->h);
  568. ret = ff_filter_frame(outlink, out);
  569. pullup_release_frame(f);
  570. end:
  571. av_frame_free(&in);
  572. return ret;
  573. }
  574. static av_cold void uninit(AVFilterContext *ctx)
  575. {
  576. PullupContext *s = ctx->priv;
  577. PullupField *f;
  578. int i;
  579. f = s->head;
  580. do {
  581. if (!f)
  582. break;
  583. av_free(f->diffs);
  584. av_free(f->combs);
  585. av_free(f->vars);
  586. f = f->next;
  587. av_freep(&f->prev);
  588. } while (f != s->last);
  589. av_freep(&s->last);
  590. for (i = 0; i < FF_ARRAY_ELEMS(s->buffers); i++) {
  591. av_freep(&s->buffers[i].planes[0]);
  592. av_freep(&s->buffers[i].planes[1]);
  593. av_freep(&s->buffers[i].planes[2]);
  594. }
  595. }
  596. static const AVFilterPad pullup_inputs[] = {
  597. {
  598. .name = "default",
  599. .type = AVMEDIA_TYPE_VIDEO,
  600. .filter_frame = filter_frame,
  601. .config_props = config_input,
  602. },
  603. { NULL }
  604. };
  605. static const AVFilterPad pullup_outputs[] = {
  606. {
  607. .name = "default",
  608. .type = AVMEDIA_TYPE_VIDEO,
  609. .config_props = config_output,
  610. },
  611. { NULL }
  612. };
  613. AVFilter avfilter_vf_pullup = {
  614. .name = "pullup",
  615. .description = NULL_IF_CONFIG_SMALL("Pullup from field sequence to frames."),
  616. .priv_size = sizeof(PullupContext),
  617. .priv_class = &pullup_class,
  618. .uninit = uninit,
  619. .query_formats = query_formats,
  620. .inputs = pullup_inputs,
  621. .outputs = pullup_outputs,
  622. };