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.

710 lines
21KB

  1. /*
  2. * filter layer
  3. * Copyright (c) 2007 Bobby Bingham
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/avassert.h"
  22. #include "libavutil/avstring.h"
  23. #include "libavutil/buffer.h"
  24. #include "libavutil/channel_layout.h"
  25. #include "libavutil/common.h"
  26. #include "libavutil/hwcontext.h"
  27. #include "libavutil/imgutils.h"
  28. #include "libavutil/internal.h"
  29. #include "libavutil/opt.h"
  30. #include "libavutil/pixdesc.h"
  31. #include "libavutil/rational.h"
  32. #include "libavutil/samplefmt.h"
  33. #include "audio.h"
  34. #include "avfilter.h"
  35. #include "formats.h"
  36. #include "internal.h"
  37. #include "video.h"
  38. unsigned avfilter_version(void)
  39. {
  40. return LIBAVFILTER_VERSION_INT;
  41. }
  42. const char *avfilter_configuration(void)
  43. {
  44. return LIBAV_CONFIGURATION;
  45. }
  46. const char *avfilter_license(void)
  47. {
  48. #define LICENSE_PREFIX "libavfilter license: "
  49. return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  50. }
  51. void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
  52. AVFilterPad **pads, AVFilterLink ***links,
  53. AVFilterPad *newpad)
  54. {
  55. unsigned i;
  56. idx = FFMIN(idx, *count);
  57. *pads = av_realloc(*pads, sizeof(AVFilterPad) * (*count + 1));
  58. *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1));
  59. memmove(*pads + idx + 1, *pads + idx, sizeof(AVFilterPad) * (*count - idx));
  60. memmove(*links + idx + 1, *links + idx, sizeof(AVFilterLink*) * (*count - idx));
  61. memcpy(*pads + idx, newpad, sizeof(AVFilterPad));
  62. (*links)[idx] = NULL;
  63. (*count)++;
  64. for (i = idx + 1; i < *count; i++)
  65. if (*links[i])
  66. (*(unsigned *)((uint8_t *) *links[i] + padidx_off))++;
  67. }
  68. int avfilter_link(AVFilterContext *src, unsigned srcpad,
  69. AVFilterContext *dst, unsigned dstpad)
  70. {
  71. AVFilterLink *link;
  72. if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad ||
  73. src->outputs[srcpad] || dst->inputs[dstpad])
  74. return AVERROR(EINVAL);
  75. if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) {
  76. av_log(src, AV_LOG_ERROR,
  77. "Media type mismatch between the '%s' filter output pad %d and the '%s' filter input pad %d\n",
  78. src->name, srcpad, dst->name, dstpad);
  79. return AVERROR(EINVAL);
  80. }
  81. link = av_mallocz(sizeof(*link));
  82. if (!link)
  83. return AVERROR(ENOMEM);
  84. src->outputs[srcpad] = dst->inputs[dstpad] = link;
  85. link->src = src;
  86. link->dst = dst;
  87. link->srcpad = &src->output_pads[srcpad];
  88. link->dstpad = &dst->input_pads[dstpad];
  89. link->type = src->output_pads[srcpad].type;
  90. assert(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
  91. link->format = -1;
  92. return 0;
  93. }
  94. int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
  95. unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
  96. {
  97. int ret;
  98. unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
  99. av_log(link->dst, AV_LOG_VERBOSE, "auto-inserting filter '%s' "
  100. "between the filter '%s' and the filter '%s'\n",
  101. filt->name, link->src->name, link->dst->name);
  102. link->dst->inputs[dstpad_idx] = NULL;
  103. if ((ret = avfilter_link(filt, filt_dstpad_idx, link->dst, dstpad_idx)) < 0) {
  104. /* failed to link output filter to new filter */
  105. link->dst->inputs[dstpad_idx] = link;
  106. return ret;
  107. }
  108. /* re-hookup the link to the new destination filter we inserted */
  109. link->dst = filt;
  110. link->dstpad = &filt->input_pads[filt_srcpad_idx];
  111. filt->inputs[filt_srcpad_idx] = link;
  112. /* if any information on supported media formats already exists on the
  113. * link, we need to preserve that */
  114. if (link->out_formats)
  115. ff_formats_changeref(&link->out_formats,
  116. &filt->outputs[filt_dstpad_idx]->out_formats);
  117. if (link->out_samplerates)
  118. ff_formats_changeref(&link->out_samplerates,
  119. &filt->outputs[filt_dstpad_idx]->out_samplerates);
  120. if (link->out_channel_layouts)
  121. ff_channel_layouts_changeref(&link->out_channel_layouts,
  122. &filt->outputs[filt_dstpad_idx]->out_channel_layouts);
  123. return 0;
  124. }
  125. int avfilter_config_links(AVFilterContext *filter)
  126. {
  127. int (*config_link)(AVFilterLink *);
  128. unsigned i;
  129. int ret;
  130. for (i = 0; i < filter->nb_inputs; i ++) {
  131. AVFilterLink *link = filter->inputs[i];
  132. if (!link) continue;
  133. if (!link->src || !link->dst) {
  134. av_log(filter, AV_LOG_ERROR,
  135. "Not all input and output are properly linked (%d).\n", i);
  136. return AVERROR(EINVAL);
  137. }
  138. switch (link->init_state) {
  139. case AVLINK_INIT:
  140. continue;
  141. case AVLINK_STARTINIT:
  142. av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
  143. return 0;
  144. case AVLINK_UNINIT:
  145. link->init_state = AVLINK_STARTINIT;
  146. if ((ret = avfilter_config_links(link->src)) < 0)
  147. return ret;
  148. if (!(config_link = link->srcpad->config_props)) {
  149. if (link->src->nb_inputs != 1) {
  150. av_log(link->src, AV_LOG_ERROR, "Source filters and filters "
  151. "with more than one input "
  152. "must set config_props() "
  153. "callbacks on all outputs\n");
  154. return AVERROR(EINVAL);
  155. }
  156. } else if ((ret = config_link(link)) < 0) {
  157. av_log(link->src, AV_LOG_ERROR,
  158. "Failed to configure output pad on %s\n",
  159. link->src->name);
  160. return ret;
  161. }
  162. if (link->time_base.num == 0 && link->time_base.den == 0)
  163. link->time_base = link->src->nb_inputs ?
  164. link->src->inputs[0]->time_base : AV_TIME_BASE_Q;
  165. if (link->type == AVMEDIA_TYPE_VIDEO) {
  166. if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den)
  167. link->sample_aspect_ratio = link->src->nb_inputs ?
  168. link->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1};
  169. if (link->src->nb_inputs) {
  170. if (!link->frame_rate.num && !link->frame_rate.den)
  171. link->frame_rate = link->src->inputs[0]->frame_rate;
  172. if (!link->w)
  173. link->w = link->src->inputs[0]->w;
  174. if (!link->h)
  175. link->h = link->src->inputs[0]->h;
  176. } else if (!link->w || !link->h) {
  177. av_log(link->src, AV_LOG_ERROR,
  178. "Video source filters must set their output link's "
  179. "width and height\n");
  180. return AVERROR(EINVAL);
  181. }
  182. }
  183. if (link->src->nb_inputs && link->src->inputs[0]->hw_frames_ctx &&
  184. !(link->src->filter->flags_internal & FF_FILTER_FLAG_HWFRAME_AWARE)) {
  185. av_assert0(!link->hw_frames_ctx &&
  186. "should not be set by non-hwframe-aware filter");
  187. link->hw_frames_ctx = av_buffer_ref(link->src->inputs[0]->hw_frames_ctx);
  188. if (!link->hw_frames_ctx)
  189. return AVERROR(ENOMEM);
  190. }
  191. if ((config_link = link->dstpad->config_props))
  192. if ((ret = config_link(link)) < 0) {
  193. av_log(link->dst, AV_LOG_ERROR,
  194. "Failed to configure input pad on %s\n",
  195. link->dst->name);
  196. return ret;
  197. }
  198. link->init_state = AVLINK_INIT;
  199. }
  200. }
  201. return 0;
  202. }
  203. void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
  204. {
  205. if (link->type == AVMEDIA_TYPE_VIDEO) {
  206. av_log(ctx, AV_LOG_TRACE,
  207. "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",
  208. link, link->w, link->h,
  209. av_get_pix_fmt_name(link->format),
  210. link->src ? link->src->filter->name : "",
  211. link->dst ? link->dst->filter->name : "",
  212. end ? "\n" : "");
  213. } else {
  214. char buf[128];
  215. av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
  216. av_log(ctx, AV_LOG_TRACE,
  217. "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s",
  218. link, link->sample_rate, buf,
  219. av_get_sample_fmt_name(link->format),
  220. link->src ? link->src->filter->name : "",
  221. link->dst ? link->dst->filter->name : "",
  222. end ? "\n" : "");
  223. }
  224. }
  225. int ff_request_frame(AVFilterLink *link)
  226. {
  227. FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1);
  228. if (link->srcpad->request_frame)
  229. return link->srcpad->request_frame(link);
  230. else if (link->src->inputs[0])
  231. return ff_request_frame(link->src->inputs[0]);
  232. else
  233. return AVERROR(EINVAL);
  234. }
  235. int ff_poll_frame(AVFilterLink *link)
  236. {
  237. int i, min = INT_MAX;
  238. if (link->srcpad->poll_frame)
  239. return link->srcpad->poll_frame(link);
  240. for (i = 0; i < link->src->nb_inputs; i++) {
  241. int val;
  242. if (!link->src->inputs[i])
  243. return AVERROR(EINVAL);
  244. val = ff_poll_frame(link->src->inputs[i]);
  245. min = FFMIN(min, val);
  246. }
  247. return min;
  248. }
  249. static AVFilter *first_filter;
  250. const AVFilter *avfilter_get_by_name(const char *name)
  251. {
  252. const AVFilter *f = NULL;
  253. if (!name)
  254. return NULL;
  255. while ((f = avfilter_next(f)))
  256. if (!strcmp(f->name, name))
  257. return f;
  258. return NULL;
  259. }
  260. int avfilter_register(AVFilter *filter)
  261. {
  262. AVFilter **f = &first_filter;
  263. while (*f)
  264. f = &(*f)->next;
  265. *f = filter;
  266. filter->next = NULL;
  267. return 0;
  268. }
  269. const AVFilter *avfilter_next(const AVFilter *prev)
  270. {
  271. return prev ? prev->next : first_filter;
  272. }
  273. int avfilter_pad_count(const AVFilterPad *pads)
  274. {
  275. int count;
  276. if (!pads)
  277. return 0;
  278. for (count = 0; pads->name; count++)
  279. pads++;
  280. return count;
  281. }
  282. static const char *filter_name(void *p)
  283. {
  284. AVFilterContext *filter = p;
  285. return filter->filter->name;
  286. }
  287. static void *filter_child_next(void *obj, void *prev)
  288. {
  289. AVFilterContext *ctx = obj;
  290. if (!prev && ctx->filter && ctx->filter->priv_class && ctx->priv)
  291. return ctx->priv;
  292. return NULL;
  293. }
  294. static const AVClass *filter_child_class_next(const AVClass *prev)
  295. {
  296. const AVFilter *f = NULL;
  297. while (prev && (f = avfilter_next(f)))
  298. if (f->priv_class == prev)
  299. break;
  300. while ((f = avfilter_next(f)))
  301. if (f->priv_class)
  302. return f->priv_class;
  303. return NULL;
  304. }
  305. #define OFFSET(x) offsetof(AVFilterContext, x)
  306. #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
  307. static const AVOption avfilter_options[] = {
  308. { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
  309. { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" },
  310. { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .unit = "thread_type" },
  311. { NULL },
  312. };
  313. static const AVClass avfilter_class = {
  314. .class_name = "AVFilter",
  315. .item_name = filter_name,
  316. .version = LIBAVUTIL_VERSION_INT,
  317. .child_next = filter_child_next,
  318. .child_class_next = filter_child_class_next,
  319. .option = avfilter_options,
  320. };
  321. static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg,
  322. int *ret, int nb_jobs)
  323. {
  324. int i;
  325. for (i = 0; i < nb_jobs; i++) {
  326. int r = func(ctx, arg, i, nb_jobs);
  327. if (ret)
  328. ret[i] = r;
  329. }
  330. return 0;
  331. }
  332. AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
  333. {
  334. AVFilterContext *ret;
  335. if (!filter)
  336. return NULL;
  337. ret = av_mallocz(sizeof(AVFilterContext));
  338. if (!ret)
  339. return NULL;
  340. ret->av_class = &avfilter_class;
  341. ret->filter = filter;
  342. ret->name = inst_name ? av_strdup(inst_name) : NULL;
  343. if (filter->priv_size) {
  344. ret->priv = av_mallocz(filter->priv_size);
  345. if (!ret->priv)
  346. goto err;
  347. }
  348. av_opt_set_defaults(ret);
  349. if (filter->priv_class) {
  350. *(const AVClass**)ret->priv = filter->priv_class;
  351. av_opt_set_defaults(ret->priv);
  352. }
  353. ret->internal = av_mallocz(sizeof(*ret->internal));
  354. if (!ret->internal)
  355. goto err;
  356. ret->internal->execute = default_execute;
  357. ret->nb_inputs = avfilter_pad_count(filter->inputs);
  358. if (ret->nb_inputs ) {
  359. ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs);
  360. if (!ret->input_pads)
  361. goto err;
  362. memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->nb_inputs);
  363. ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_inputs);
  364. if (!ret->inputs)
  365. goto err;
  366. }
  367. ret->nb_outputs = avfilter_pad_count(filter->outputs);
  368. if (ret->nb_outputs) {
  369. ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_outputs);
  370. if (!ret->output_pads)
  371. goto err;
  372. memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->nb_outputs);
  373. ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_outputs);
  374. if (!ret->outputs)
  375. goto err;
  376. }
  377. return ret;
  378. err:
  379. av_freep(&ret->inputs);
  380. av_freep(&ret->input_pads);
  381. ret->nb_inputs = 0;
  382. av_freep(&ret->outputs);
  383. av_freep(&ret->output_pads);
  384. ret->nb_outputs = 0;
  385. av_freep(&ret->priv);
  386. av_freep(&ret->internal);
  387. av_free(ret);
  388. return NULL;
  389. }
  390. static void free_link(AVFilterLink *link)
  391. {
  392. if (!link)
  393. return;
  394. if (link->src)
  395. link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
  396. if (link->dst)
  397. link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
  398. av_buffer_unref(&link->hw_frames_ctx);
  399. ff_formats_unref(&link->in_formats);
  400. ff_formats_unref(&link->out_formats);
  401. ff_formats_unref(&link->in_samplerates);
  402. ff_formats_unref(&link->out_samplerates);
  403. ff_channel_layouts_unref(&link->in_channel_layouts);
  404. ff_channel_layouts_unref(&link->out_channel_layouts);
  405. av_freep(&link);
  406. }
  407. void avfilter_free(AVFilterContext *filter)
  408. {
  409. int i;
  410. if (filter->graph)
  411. ff_filter_graph_remove_filter(filter->graph, filter);
  412. if (filter->filter->uninit)
  413. filter->filter->uninit(filter);
  414. for (i = 0; i < filter->nb_inputs; i++) {
  415. free_link(filter->inputs[i]);
  416. }
  417. for (i = 0; i < filter->nb_outputs; i++) {
  418. free_link(filter->outputs[i]);
  419. }
  420. if (filter->filter->priv_class)
  421. av_opt_free(filter->priv);
  422. av_buffer_unref(&filter->hw_device_ctx);
  423. av_freep(&filter->name);
  424. av_freep(&filter->input_pads);
  425. av_freep(&filter->output_pads);
  426. av_freep(&filter->inputs);
  427. av_freep(&filter->outputs);
  428. av_freep(&filter->priv);
  429. av_freep(&filter->internal);
  430. av_free(filter);
  431. }
  432. /* process a list of value1:value2:..., each value corresponding
  433. * to subsequent AVOption, in the order they are declared */
  434. static int process_unnamed_options(AVFilterContext *ctx, AVDictionary **options,
  435. const char *args)
  436. {
  437. const AVOption *o = NULL;
  438. const char *p = args;
  439. char *val;
  440. while (*p) {
  441. o = av_opt_next(ctx->priv, o);
  442. if (!o) {
  443. av_log(ctx, AV_LOG_ERROR, "More options provided than "
  444. "this filter supports.\n");
  445. return AVERROR(EINVAL);
  446. }
  447. if (o->type == AV_OPT_TYPE_CONST)
  448. continue;
  449. val = av_get_token(&p, ":");
  450. if (!val)
  451. return AVERROR(ENOMEM);
  452. av_dict_set(options, o->name, val, 0);
  453. av_freep(&val);
  454. if (*p)
  455. p++;
  456. }
  457. return 0;
  458. }
  459. int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
  460. {
  461. int ret = 0;
  462. ret = av_opt_set_dict(ctx, options);
  463. if (ret < 0) {
  464. av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n");
  465. return ret;
  466. }
  467. if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS &&
  468. ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&
  469. ctx->graph->internal->thread_execute) {
  470. ctx->thread_type = AVFILTER_THREAD_SLICE;
  471. ctx->internal->execute = ctx->graph->internal->thread_execute;
  472. } else {
  473. ctx->thread_type = 0;
  474. }
  475. if (ctx->filter->priv_class) {
  476. ret = av_opt_set_dict(ctx->priv, options);
  477. if (ret < 0) {
  478. av_log(ctx, AV_LOG_ERROR, "Error applying options to the filter.\n");
  479. return ret;
  480. }
  481. }
  482. if (ctx->filter->init)
  483. ret = ctx->filter->init(ctx);
  484. else if (ctx->filter->init_dict)
  485. ret = ctx->filter->init_dict(ctx, options);
  486. return ret;
  487. }
  488. int avfilter_init_str(AVFilterContext *filter, const char *args)
  489. {
  490. AVDictionary *options = NULL;
  491. AVDictionaryEntry *e;
  492. int ret = 0;
  493. if (args && *args) {
  494. if (!filter->filter->priv_class) {
  495. av_log(filter, AV_LOG_ERROR, "This filter does not take any "
  496. "options, but options were provided: %s.\n", args);
  497. return AVERROR(EINVAL);
  498. }
  499. if (strchr(args, '=')) {
  500. /* assume a list of key1=value1:key2=value2:... */
  501. ret = av_dict_parse_string(&options, args, "=", ":", 0);
  502. if (ret < 0)
  503. goto fail;
  504. } else {
  505. ret = process_unnamed_options(filter, &options, args);
  506. if (ret < 0)
  507. goto fail;
  508. }
  509. }
  510. ret = avfilter_init_dict(filter, &options);
  511. if (ret < 0)
  512. goto fail;
  513. if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
  514. av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key);
  515. ret = AVERROR_OPTION_NOT_FOUND;
  516. goto fail;
  517. }
  518. fail:
  519. av_dict_free(&options);
  520. return ret;
  521. }
  522. const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
  523. {
  524. return pads[pad_idx].name;
  525. }
  526. enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
  527. {
  528. return pads[pad_idx].type;
  529. }
  530. static int default_filter_frame(AVFilterLink *link, AVFrame *frame)
  531. {
  532. return ff_filter_frame(link->dst->outputs[0], frame);
  533. }
  534. int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
  535. {
  536. int (*filter_frame)(AVFilterLink *, AVFrame *);
  537. AVFilterPad *dst = link->dstpad;
  538. AVFrame *out = NULL;
  539. int ret;
  540. FF_DPRINTF_START(NULL, filter_frame);
  541. ff_dlog_link(NULL, link, 1);
  542. if (!(filter_frame = dst->filter_frame))
  543. filter_frame = default_filter_frame;
  544. /* copy the frame if needed */
  545. if (dst->needs_writable && !av_frame_is_writable(frame)) {
  546. av_log(link->dst, AV_LOG_DEBUG, "Copying data in avfilter.\n");
  547. switch (link->type) {
  548. case AVMEDIA_TYPE_VIDEO:
  549. out = ff_get_video_buffer(link, link->w, link->h);
  550. break;
  551. case AVMEDIA_TYPE_AUDIO:
  552. out = ff_get_audio_buffer(link, frame->nb_samples);
  553. break;
  554. default:
  555. ret = AVERROR(EINVAL);
  556. goto fail;
  557. }
  558. if (!out) {
  559. ret = AVERROR(ENOMEM);
  560. goto fail;
  561. }
  562. ret = av_frame_copy_props(out, frame);
  563. if (ret < 0)
  564. goto fail;
  565. switch (link->type) {
  566. case AVMEDIA_TYPE_VIDEO:
  567. av_image_copy(out->data, out->linesize, frame->data, frame->linesize,
  568. frame->format, frame->width, frame->height);
  569. break;
  570. case AVMEDIA_TYPE_AUDIO:
  571. av_samples_copy(out->extended_data, frame->extended_data,
  572. 0, 0, frame->nb_samples,
  573. av_get_channel_layout_nb_channels(frame->channel_layout),
  574. frame->format);
  575. break;
  576. default:
  577. ret = AVERROR(EINVAL);
  578. goto fail;
  579. }
  580. av_frame_free(&frame);
  581. } else
  582. out = frame;
  583. return filter_frame(link, out);
  584. fail:
  585. av_frame_free(&out);
  586. av_frame_free(&frame);
  587. return ret;
  588. }
  589. const AVClass *avfilter_get_class(void)
  590. {
  591. return &avfilter_class;
  592. }