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.

606 lines
20KB

  1. /*
  2. * Copyright (C) 2012 British Broadcasting Corporation, All Rights Reserved
  3. * Author of de-interlace algorithm: Jim Easterbrook for BBC R&D
  4. * Based on the process described by Martin Weston for BBC R&D
  5. * Author of FFmpeg filter: Mark Himsley for BBC Broadcast Systems Development
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include "libavutil/common.h"
  24. #include "libavutil/imgutils.h"
  25. #include "libavutil/opt.h"
  26. #include "libavutil/pixdesc.h"
  27. #include "avfilter.h"
  28. #include "formats.h"
  29. #include "internal.h"
  30. #include "video.h"
  31. #include "w3fdif.h"
  32. typedef struct W3FDIFContext {
  33. const AVClass *class;
  34. int filter; ///< 0 is simple, 1 is more complex
  35. int deint; ///< which frames to deinterlace
  36. int linesize[4]; ///< bytes of pixel data per line for each plane
  37. int planeheight[4]; ///< height of each plane
  38. int field; ///< which field are we on, 0 or 1
  39. int eof;
  40. int nb_planes;
  41. AVFrame *prev, *cur, *next; ///< previous, current, next frames
  42. int32_t **work_line; ///< lines we are calculating
  43. int nb_threads;
  44. int max;
  45. W3FDIFDSPContext dsp;
  46. } W3FDIFContext;
  47. #define OFFSET(x) offsetof(W3FDIFContext, x)
  48. #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  49. #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, unit }
  50. static const AVOption w3fdif_options[] = {
  51. { "filter", "specify the filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "filter" },
  52. CONST("simple", NULL, 0, "filter"),
  53. CONST("complex", NULL, 1, "filter"),
  54. { "deint", "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "deint" },
  55. CONST("all", "deinterlace all frames", 0, "deint"),
  56. CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"),
  57. { NULL }
  58. };
  59. AVFILTER_DEFINE_CLASS(w3fdif);
  60. static int query_formats(AVFilterContext *ctx)
  61. {
  62. static const enum AVPixelFormat pix_fmts[] = {
  63. AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
  64. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
  65. AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
  66. AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P,
  67. AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
  68. AV_PIX_FMT_YUVJ411P,
  69. AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P,
  70. AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
  71. AV_PIX_FMT_GRAY8,
  72. AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
  73. AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
  74. AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12,
  75. AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
  76. AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14,
  77. AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_YUVA444P16,
  78. AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA422P16,
  79. AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA420P16,
  80. AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
  81. AV_PIX_FMT_NONE
  82. };
  83. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  84. if (!fmts_list)
  85. return AVERROR(ENOMEM);
  86. return ff_set_common_formats(ctx, fmts_list);
  87. }
  88. static void filter_simple_low(int32_t *work_line,
  89. uint8_t *in_lines_cur[2],
  90. const int16_t *coef, int linesize)
  91. {
  92. int i;
  93. for (i = 0; i < linesize; i++) {
  94. *work_line = *in_lines_cur[0]++ * coef[0];
  95. *work_line++ += *in_lines_cur[1]++ * coef[1];
  96. }
  97. }
  98. static void filter_complex_low(int32_t *work_line,
  99. uint8_t *in_lines_cur[4],
  100. const int16_t *coef, int linesize)
  101. {
  102. int i;
  103. for (i = 0; i < linesize; i++) {
  104. *work_line = *in_lines_cur[0]++ * coef[0];
  105. *work_line += *in_lines_cur[1]++ * coef[1];
  106. *work_line += *in_lines_cur[2]++ * coef[2];
  107. *work_line++ += *in_lines_cur[3]++ * coef[3];
  108. }
  109. }
  110. static void filter_simple_high(int32_t *work_line,
  111. uint8_t *in_lines_cur[3],
  112. uint8_t *in_lines_adj[3],
  113. const int16_t *coef, int linesize)
  114. {
  115. int i;
  116. for (i = 0; i < linesize; i++) {
  117. *work_line += *in_lines_cur[0]++ * coef[0];
  118. *work_line += *in_lines_adj[0]++ * coef[0];
  119. *work_line += *in_lines_cur[1]++ * coef[1];
  120. *work_line += *in_lines_adj[1]++ * coef[1];
  121. *work_line += *in_lines_cur[2]++ * coef[2];
  122. *work_line++ += *in_lines_adj[2]++ * coef[2];
  123. }
  124. }
  125. static void filter_complex_high(int32_t *work_line,
  126. uint8_t *in_lines_cur[5],
  127. uint8_t *in_lines_adj[5],
  128. const int16_t *coef, int linesize)
  129. {
  130. int i;
  131. for (i = 0; i < linesize; i++) {
  132. *work_line += *in_lines_cur[0]++ * coef[0];
  133. *work_line += *in_lines_adj[0]++ * coef[0];
  134. *work_line += *in_lines_cur[1]++ * coef[1];
  135. *work_line += *in_lines_adj[1]++ * coef[1];
  136. *work_line += *in_lines_cur[2]++ * coef[2];
  137. *work_line += *in_lines_adj[2]++ * coef[2];
  138. *work_line += *in_lines_cur[3]++ * coef[3];
  139. *work_line += *in_lines_adj[3]++ * coef[3];
  140. *work_line += *in_lines_cur[4]++ * coef[4];
  141. *work_line++ += *in_lines_adj[4]++ * coef[4];
  142. }
  143. }
  144. static void filter_scale(uint8_t *out_pixel, const int32_t *work_pixel, int linesize, int max)
  145. {
  146. int j;
  147. for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
  148. *out_pixel = av_clip(*work_pixel, 0, 255 * 256 * 128) >> 15;
  149. }
  150. static void filter16_simple_low(int32_t *work_line,
  151. uint8_t *in_lines_cur8[2],
  152. const int16_t *coef, int linesize)
  153. {
  154. uint16_t *in_lines_cur[2] = { (uint16_t *)in_lines_cur8[0], (uint16_t *)in_lines_cur8[1] };
  155. int i;
  156. linesize /= 2;
  157. for (i = 0; i < linesize; i++) {
  158. *work_line = *in_lines_cur[0]++ * coef[0];
  159. *work_line++ += *in_lines_cur[1]++ * coef[1];
  160. }
  161. }
  162. static void filter16_complex_low(int32_t *work_line,
  163. uint8_t *in_lines_cur8[4],
  164. const int16_t *coef, int linesize)
  165. {
  166. uint16_t *in_lines_cur[4] = { (uint16_t *)in_lines_cur8[0],
  167. (uint16_t *)in_lines_cur8[1],
  168. (uint16_t *)in_lines_cur8[2],
  169. (uint16_t *)in_lines_cur8[3] };
  170. int i;
  171. linesize /= 2;
  172. for (i = 0; i < linesize; i++) {
  173. *work_line = *in_lines_cur[0]++ * coef[0];
  174. *work_line += *in_lines_cur[1]++ * coef[1];
  175. *work_line += *in_lines_cur[2]++ * coef[2];
  176. *work_line++ += *in_lines_cur[3]++ * coef[3];
  177. }
  178. }
  179. static void filter16_simple_high(int32_t *work_line,
  180. uint8_t *in_lines_cur8[3],
  181. uint8_t *in_lines_adj8[3],
  182. const int16_t *coef, int linesize)
  183. {
  184. uint16_t *in_lines_cur[3] = { (uint16_t *)in_lines_cur8[0],
  185. (uint16_t *)in_lines_cur8[1],
  186. (uint16_t *)in_lines_cur8[2] };
  187. uint16_t *in_lines_adj[3] = { (uint16_t *)in_lines_adj8[0],
  188. (uint16_t *)in_lines_adj8[1],
  189. (uint16_t *)in_lines_adj8[2] };
  190. int i;
  191. linesize /= 2;
  192. for (i = 0; i < linesize; i++) {
  193. *work_line += *in_lines_cur[0]++ * coef[0];
  194. *work_line += *in_lines_adj[0]++ * coef[0];
  195. *work_line += *in_lines_cur[1]++ * coef[1];
  196. *work_line += *in_lines_adj[1]++ * coef[1];
  197. *work_line += *in_lines_cur[2]++ * coef[2];
  198. *work_line++ += *in_lines_adj[2]++ * coef[2];
  199. }
  200. }
  201. static void filter16_complex_high(int32_t *work_line,
  202. uint8_t *in_lines_cur8[5],
  203. uint8_t *in_lines_adj8[5],
  204. const int16_t *coef, int linesize)
  205. {
  206. uint16_t *in_lines_cur[5] = { (uint16_t *)in_lines_cur8[0],
  207. (uint16_t *)in_lines_cur8[1],
  208. (uint16_t *)in_lines_cur8[2],
  209. (uint16_t *)in_lines_cur8[3],
  210. (uint16_t *)in_lines_cur8[4] };
  211. uint16_t *in_lines_adj[5] = { (uint16_t *)in_lines_adj8[0],
  212. (uint16_t *)in_lines_adj8[1],
  213. (uint16_t *)in_lines_adj8[2],
  214. (uint16_t *)in_lines_adj8[3],
  215. (uint16_t *)in_lines_adj8[4] };
  216. int i;
  217. linesize /= 2;
  218. for (i = 0; i < linesize; i++) {
  219. *work_line += *in_lines_cur[0]++ * coef[0];
  220. *work_line += *in_lines_adj[0]++ * coef[0];
  221. *work_line += *in_lines_cur[1]++ * coef[1];
  222. *work_line += *in_lines_adj[1]++ * coef[1];
  223. *work_line += *in_lines_cur[2]++ * coef[2];
  224. *work_line += *in_lines_adj[2]++ * coef[2];
  225. *work_line += *in_lines_cur[3]++ * coef[3];
  226. *work_line += *in_lines_adj[3]++ * coef[3];
  227. *work_line += *in_lines_cur[4]++ * coef[4];
  228. *work_line++ += *in_lines_adj[4]++ * coef[4];
  229. }
  230. }
  231. static void filter16_scale(uint8_t *out_pixel8, const int32_t *work_pixel, int linesize, int max)
  232. {
  233. uint16_t *out_pixel = (uint16_t *)out_pixel8;
  234. int j;
  235. linesize /= 2;
  236. for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
  237. *out_pixel = av_clip(*work_pixel, 0, max) >> 15;
  238. }
  239. static int config_input(AVFilterLink *inlink)
  240. {
  241. AVFilterContext *ctx = inlink->dst;
  242. W3FDIFContext *s = ctx->priv;
  243. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  244. int ret, i, depth;
  245. if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
  246. return ret;
  247. s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
  248. s->planeheight[0] = s->planeheight[3] = inlink->h;
  249. if (inlink->h < 3) {
  250. av_log(ctx, AV_LOG_ERROR, "Video of less than 3 lines is not supported\n");
  251. return AVERROR(EINVAL);
  252. }
  253. s->nb_planes = av_pix_fmt_count_planes(inlink->format);
  254. s->nb_threads = ff_filter_get_nb_threads(ctx);
  255. s->work_line = av_calloc(s->nb_threads, sizeof(*s->work_line));
  256. if (!s->work_line)
  257. return AVERROR(ENOMEM);
  258. for (i = 0; i < s->nb_threads; i++) {
  259. s->work_line[i] = av_calloc(FFALIGN(s->linesize[0], 32), sizeof(*s->work_line[0]));
  260. if (!s->work_line[i])
  261. return AVERROR(ENOMEM);
  262. }
  263. depth = desc->comp[0].depth;
  264. s->max = ((1 << depth) - 1) * 256 * 128;
  265. if (depth <= 8) {
  266. s->dsp.filter_simple_low = filter_simple_low;
  267. s->dsp.filter_complex_low = filter_complex_low;
  268. s->dsp.filter_simple_high = filter_simple_high;
  269. s->dsp.filter_complex_high = filter_complex_high;
  270. s->dsp.filter_scale = filter_scale;
  271. } else {
  272. s->dsp.filter_simple_low = filter16_simple_low;
  273. s->dsp.filter_complex_low = filter16_complex_low;
  274. s->dsp.filter_simple_high = filter16_simple_high;
  275. s->dsp.filter_complex_high = filter16_complex_high;
  276. s->dsp.filter_scale = filter16_scale;
  277. }
  278. if (ARCH_X86)
  279. ff_w3fdif_init_x86(&s->dsp, depth);
  280. return 0;
  281. }
  282. static int config_output(AVFilterLink *outlink)
  283. {
  284. AVFilterLink *inlink = outlink->src->inputs[0];
  285. outlink->time_base.num = inlink->time_base.num;
  286. outlink->time_base.den = inlink->time_base.den * 2;
  287. outlink->frame_rate.num = inlink->frame_rate.num * 2;
  288. outlink->frame_rate.den = inlink->frame_rate.den;
  289. return 0;
  290. }
  291. /*
  292. * Filter coefficients from PH-2071, scaled by 256 * 128.
  293. * Each set of coefficients has a set for low-frequencies and high-frequencies.
  294. * n_coef_lf[] and n_coef_hf[] are the number of coefs for simple and more-complex.
  295. * It is important for later that n_coef_lf[] is even and n_coef_hf[] is odd.
  296. * coef_lf[][] and coef_hf[][] are the coefficients for low-frequencies
  297. * and high-frequencies for simple and more-complex mode.
  298. */
  299. static const int8_t n_coef_lf[2] = { 2, 4 };
  300. static const int16_t coef_lf[2][4] = {{ 16384, 16384, 0, 0},
  301. { -852, 17236, 17236, -852}};
  302. static const int8_t n_coef_hf[2] = { 3, 5 };
  303. static const int16_t coef_hf[2][5] = {{ -2048, 4096, -2048, 0, 0},
  304. { 1016, -3801, 5570, -3801, 1016}};
  305. typedef struct ThreadData {
  306. AVFrame *out, *cur, *adj;
  307. int plane;
  308. } ThreadData;
  309. static int deinterlace_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  310. {
  311. W3FDIFContext *s = ctx->priv;
  312. ThreadData *td = arg;
  313. AVFrame *out = td->out;
  314. AVFrame *cur = td->cur;
  315. AVFrame *adj = td->adj;
  316. const int plane = td->plane;
  317. const int filter = s->filter;
  318. uint8_t *in_line, *in_lines_cur[5], *in_lines_adj[5];
  319. uint8_t *out_line, *out_pixel;
  320. int32_t *work_line, *work_pixel;
  321. uint8_t *cur_data = cur->data[plane];
  322. uint8_t *adj_data = adj->data[plane];
  323. uint8_t *dst_data = out->data[plane];
  324. const int linesize = s->linesize[plane];
  325. const int height = s->planeheight[plane];
  326. const int cur_line_stride = cur->linesize[plane];
  327. const int adj_line_stride = adj->linesize[plane];
  328. const int dst_line_stride = out->linesize[plane];
  329. const int start = (height * jobnr) / nb_jobs;
  330. const int end = (height * (jobnr+1)) / nb_jobs;
  331. const int max = s->max;
  332. int j, y_in, y_out;
  333. /* copy unchanged the lines of the field */
  334. y_out = start + ((s->field == cur->top_field_first) ^ (start & 1));
  335. in_line = cur_data + (y_out * cur_line_stride);
  336. out_line = dst_data + (y_out * dst_line_stride);
  337. while (y_out < end) {
  338. memcpy(out_line, in_line, linesize);
  339. y_out += 2;
  340. in_line += cur_line_stride * 2;
  341. out_line += dst_line_stride * 2;
  342. }
  343. /* interpolate other lines of the field */
  344. y_out = start + ((s->field != cur->top_field_first) ^ (start & 1));
  345. out_line = dst_data + (y_out * dst_line_stride);
  346. while (y_out < end) {
  347. /* get low vertical frequencies from current field */
  348. for (j = 0; j < n_coef_lf[filter]; j++) {
  349. y_in = (y_out + 1) + (j * 2) - n_coef_lf[filter];
  350. while (y_in < 0)
  351. y_in += 2;
  352. while (y_in >= height)
  353. y_in -= 2;
  354. in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
  355. }
  356. work_line = s->work_line[jobnr];
  357. switch (n_coef_lf[filter]) {
  358. case 2:
  359. s->dsp.filter_simple_low(work_line, in_lines_cur,
  360. coef_lf[filter], linesize);
  361. break;
  362. case 4:
  363. s->dsp.filter_complex_low(work_line, in_lines_cur,
  364. coef_lf[filter], linesize);
  365. }
  366. /* get high vertical frequencies from adjacent fields */
  367. for (j = 0; j < n_coef_hf[filter]; j++) {
  368. y_in = (y_out + 1) + (j * 2) - n_coef_hf[filter];
  369. while (y_in < 0)
  370. y_in += 2;
  371. while (y_in >= height)
  372. y_in -= 2;
  373. in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
  374. in_lines_adj[j] = adj_data + (y_in * adj_line_stride);
  375. }
  376. work_line = s->work_line[jobnr];
  377. switch (n_coef_hf[filter]) {
  378. case 3:
  379. s->dsp.filter_simple_high(work_line, in_lines_cur, in_lines_adj,
  380. coef_hf[filter], linesize);
  381. break;
  382. case 5:
  383. s->dsp.filter_complex_high(work_line, in_lines_cur, in_lines_adj,
  384. coef_hf[filter], linesize);
  385. }
  386. /* save scaled result to the output frame, scaling down by 256 * 128 */
  387. work_pixel = s->work_line[jobnr];
  388. out_pixel = out_line;
  389. s->dsp.filter_scale(out_pixel, work_pixel, linesize, max);
  390. /* move on to next line */
  391. y_out += 2;
  392. out_line += dst_line_stride * 2;
  393. }
  394. return 0;
  395. }
  396. static int filter(AVFilterContext *ctx, int is_second)
  397. {
  398. W3FDIFContext *s = ctx->priv;
  399. AVFilterLink *outlink = ctx->outputs[0];
  400. AVFrame *out, *adj;
  401. ThreadData td;
  402. int plane;
  403. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  404. if (!out)
  405. return AVERROR(ENOMEM);
  406. av_frame_copy_props(out, s->cur);
  407. out->interlaced_frame = 0;
  408. if (!is_second) {
  409. if (out->pts != AV_NOPTS_VALUE)
  410. out->pts *= 2;
  411. } else {
  412. int64_t cur_pts = s->cur->pts;
  413. int64_t next_pts = s->next->pts;
  414. if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) {
  415. out->pts = cur_pts + next_pts;
  416. } else {
  417. out->pts = AV_NOPTS_VALUE;
  418. }
  419. }
  420. adj = s->field ? s->next : s->prev;
  421. td.out = out; td.cur = s->cur; td.adj = adj;
  422. for (plane = 0; plane < s->nb_planes; plane++) {
  423. td.plane = plane;
  424. ctx->internal->execute(ctx, deinterlace_slice, &td, NULL, FFMIN(s->planeheight[plane], s->nb_threads));
  425. }
  426. s->field = !s->field;
  427. return ff_filter_frame(outlink, out);
  428. }
  429. static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
  430. {
  431. AVFilterContext *ctx = inlink->dst;
  432. W3FDIFContext *s = ctx->priv;
  433. int ret;
  434. av_frame_free(&s->prev);
  435. s->prev = s->cur;
  436. s->cur = s->next;
  437. s->next = frame;
  438. if (!s->cur) {
  439. s->cur = av_frame_clone(s->next);
  440. if (!s->cur)
  441. return AVERROR(ENOMEM);
  442. }
  443. if ((s->deint && !s->cur->interlaced_frame) || ctx->is_disabled) {
  444. AVFrame *out = av_frame_clone(s->cur);
  445. if (!out)
  446. return AVERROR(ENOMEM);
  447. av_frame_free(&s->prev);
  448. if (out->pts != AV_NOPTS_VALUE)
  449. out->pts *= 2;
  450. return ff_filter_frame(ctx->outputs[0], out);
  451. }
  452. if (!s->prev)
  453. return 0;
  454. ret = filter(ctx, 0);
  455. if (ret < 0)
  456. return ret;
  457. return filter(ctx, 1);
  458. }
  459. static int request_frame(AVFilterLink *outlink)
  460. {
  461. AVFilterContext *ctx = outlink->src;
  462. W3FDIFContext *s = ctx->priv;
  463. int ret;
  464. if (s->eof)
  465. return AVERROR_EOF;
  466. ret = ff_request_frame(ctx->inputs[0]);
  467. if (ret == AVERROR_EOF && s->cur) {
  468. AVFrame *next = av_frame_clone(s->next);
  469. if (!next)
  470. return AVERROR(ENOMEM);
  471. next->pts = s->next->pts * 2 - s->cur->pts;
  472. filter_frame(ctx->inputs[0], next);
  473. s->eof = 1;
  474. } else if (ret < 0) {
  475. return ret;
  476. }
  477. return 0;
  478. }
  479. static av_cold void uninit(AVFilterContext *ctx)
  480. {
  481. W3FDIFContext *s = ctx->priv;
  482. int i;
  483. av_frame_free(&s->prev);
  484. av_frame_free(&s->cur );
  485. av_frame_free(&s->next);
  486. for (i = 0; i < s->nb_threads; i++)
  487. av_freep(&s->work_line[i]);
  488. av_freep(&s->work_line);
  489. }
  490. static const AVFilterPad w3fdif_inputs[] = {
  491. {
  492. .name = "default",
  493. .type = AVMEDIA_TYPE_VIDEO,
  494. .filter_frame = filter_frame,
  495. .config_props = config_input,
  496. },
  497. { NULL }
  498. };
  499. static const AVFilterPad w3fdif_outputs[] = {
  500. {
  501. .name = "default",
  502. .type = AVMEDIA_TYPE_VIDEO,
  503. .config_props = config_output,
  504. .request_frame = request_frame,
  505. },
  506. { NULL }
  507. };
  508. AVFilter ff_vf_w3fdif = {
  509. .name = "w3fdif",
  510. .description = NULL_IF_CONFIG_SMALL("Apply Martin Weston three field deinterlace."),
  511. .priv_size = sizeof(W3FDIFContext),
  512. .priv_class = &w3fdif_class,
  513. .uninit = uninit,
  514. .query_formats = query_formats,
  515. .inputs = w3fdif_inputs,
  516. .outputs = w3fdif_outputs,
  517. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
  518. };