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.

657 lines
21KB

  1. /*
  2. * filter layer
  3. * Copyright (c) 2007 Bobby Bingham
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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/channel_layout.h"
  24. #include "libavutil/common.h"
  25. #include "libavutil/imgutils.h"
  26. #include "libavutil/pixdesc.h"
  27. #include "libavutil/rational.h"
  28. #include "libavutil/samplefmt.h"
  29. #include "audio.h"
  30. #include "avfilter.h"
  31. #include "formats.h"
  32. #include "internal.h"
  33. #include "audio.h"
  34. char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms)
  35. {
  36. snprintf(buf, buf_size, "%s%s%s%s%s%s",
  37. perms & AV_PERM_READ ? "r" : "",
  38. perms & AV_PERM_WRITE ? "w" : "",
  39. perms & AV_PERM_PRESERVE ? "p" : "",
  40. perms & AV_PERM_REUSE ? "u" : "",
  41. perms & AV_PERM_REUSE2 ? "U" : "",
  42. perms & AV_PERM_NEG_LINESIZES ? "n" : "");
  43. return buf;
  44. }
  45. void ff_tlog_ref(void *ctx, AVFilterBufferRef *ref, int end)
  46. {
  47. av_unused char buf[16];
  48. ff_tlog(ctx,
  49. "ref[%p buf:%p refcount:%d perms:%s data:%p linesize[%d, %d, %d, %d] pts:%"PRId64" pos:%"PRId64,
  50. ref, ref->buf, ref->buf->refcount, ff_get_ref_perms_string(buf, sizeof(buf), ref->perms), ref->data[0],
  51. ref->linesize[0], ref->linesize[1], ref->linesize[2], ref->linesize[3],
  52. ref->pts, ref->pos);
  53. if (ref->video) {
  54. ff_tlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c",
  55. ref->video->sample_aspect_ratio.num, ref->video->sample_aspect_ratio.den,
  56. ref->video->w, ref->video->h,
  57. !ref->video->interlaced ? 'P' : /* Progressive */
  58. ref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */
  59. ref->video->key_frame,
  60. av_get_picture_type_char(ref->video->pict_type));
  61. }
  62. if (ref->audio) {
  63. ff_tlog(ctx, " cl:%"PRId64"d n:%d r:%d",
  64. ref->audio->channel_layout,
  65. ref->audio->nb_samples,
  66. ref->audio->sample_rate);
  67. }
  68. ff_tlog(ctx, "]%s", end ? "\n" : "");
  69. }
  70. unsigned avfilter_version(void) {
  71. av_assert0(LIBAVFILTER_VERSION_MICRO >= 100);
  72. return LIBAVFILTER_VERSION_INT;
  73. }
  74. const char *avfilter_configuration(void)
  75. {
  76. return FFMPEG_CONFIGURATION;
  77. }
  78. const char *avfilter_license(void)
  79. {
  80. #define LICENSE_PREFIX "libavfilter license: "
  81. return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  82. }
  83. void ff_command_queue_pop(AVFilterContext *filter)
  84. {
  85. AVFilterCommand *c= filter->command_queue;
  86. av_freep(&c->arg);
  87. av_freep(&c->command);
  88. filter->command_queue= c->next;
  89. av_free(c);
  90. }
  91. void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
  92. AVFilterPad **pads, AVFilterLink ***links,
  93. AVFilterPad *newpad)
  94. {
  95. unsigned i;
  96. idx = FFMIN(idx, *count);
  97. *pads = av_realloc(*pads, sizeof(AVFilterPad) * (*count + 1));
  98. *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1));
  99. memmove(*pads +idx+1, *pads +idx, sizeof(AVFilterPad) * (*count-idx));
  100. memmove(*links+idx+1, *links+idx, sizeof(AVFilterLink*) * (*count-idx));
  101. memcpy(*pads+idx, newpad, sizeof(AVFilterPad));
  102. (*links)[idx] = NULL;
  103. (*count)++;
  104. for (i = idx+1; i < *count; i++)
  105. if (*links[i])
  106. (*(unsigned *)((uint8_t *) *links[i] + padidx_off))++;
  107. }
  108. int avfilter_link(AVFilterContext *src, unsigned srcpad,
  109. AVFilterContext *dst, unsigned dstpad)
  110. {
  111. AVFilterLink *link;
  112. if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad ||
  113. src->outputs[srcpad] || dst->inputs[dstpad])
  114. return -1;
  115. if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) {
  116. av_log(src, AV_LOG_ERROR,
  117. "Media type mismatch between the '%s' filter output pad %d (%s) and the '%s' filter input pad %d (%s)\n",
  118. src->name, srcpad, (char *)av_x_if_null(av_get_media_type_string(src->output_pads[srcpad].type), "?"),
  119. dst->name, dstpad, (char *)av_x_if_null(av_get_media_type_string(dst-> input_pads[dstpad].type), "?"));
  120. return AVERROR(EINVAL);
  121. }
  122. src->outputs[srcpad] =
  123. dst-> inputs[dstpad] = link = av_mallocz(sizeof(AVFilterLink));
  124. link->src = src;
  125. link->dst = dst;
  126. link->srcpad = &src->output_pads[srcpad];
  127. link->dstpad = &dst->input_pads[dstpad];
  128. link->type = src->output_pads[srcpad].type;
  129. av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
  130. link->format = -1;
  131. return 0;
  132. }
  133. void avfilter_link_free(AVFilterLink **link)
  134. {
  135. if (!*link)
  136. return;
  137. if ((*link)->pool)
  138. ff_free_pool((*link)->pool);
  139. avfilter_unref_bufferp(&(*link)->partial_buf);
  140. av_freep(link);
  141. }
  142. void avfilter_link_set_closed(AVFilterLink *link, int closed)
  143. {
  144. link->closed = closed;
  145. }
  146. int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
  147. unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
  148. {
  149. int ret;
  150. unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
  151. av_log(link->dst, AV_LOG_VERBOSE, "auto-inserting filter '%s' "
  152. "between the filter '%s' and the filter '%s'\n",
  153. filt->name, link->src->name, link->dst->name);
  154. link->dst->inputs[dstpad_idx] = NULL;
  155. if ((ret = avfilter_link(filt, filt_dstpad_idx, link->dst, dstpad_idx)) < 0) {
  156. /* failed to link output filter to new filter */
  157. link->dst->inputs[dstpad_idx] = link;
  158. return ret;
  159. }
  160. /* re-hookup the link to the new destination filter we inserted */
  161. link->dst = filt;
  162. link->dstpad = &filt->input_pads[filt_srcpad_idx];
  163. filt->inputs[filt_srcpad_idx] = link;
  164. /* if any information on supported media formats already exists on the
  165. * link, we need to preserve that */
  166. if (link->out_formats)
  167. ff_formats_changeref(&link->out_formats,
  168. &filt->outputs[filt_dstpad_idx]->out_formats);
  169. if (link->out_samplerates)
  170. ff_formats_changeref(&link->out_samplerates,
  171. &filt->outputs[filt_dstpad_idx]->out_samplerates);
  172. if (link->out_channel_layouts)
  173. ff_channel_layouts_changeref(&link->out_channel_layouts,
  174. &filt->outputs[filt_dstpad_idx]->out_channel_layouts);
  175. return 0;
  176. }
  177. int avfilter_config_links(AVFilterContext *filter)
  178. {
  179. int (*config_link)(AVFilterLink *);
  180. unsigned i;
  181. int ret;
  182. for (i = 0; i < filter->nb_inputs; i ++) {
  183. AVFilterLink *link = filter->inputs[i];
  184. AVFilterLink *inlink = link->src->nb_inputs ?
  185. link->src->inputs[0] : NULL;
  186. if (!link) continue;
  187. link->current_pts = AV_NOPTS_VALUE;
  188. switch (link->init_state) {
  189. case AVLINK_INIT:
  190. continue;
  191. case AVLINK_STARTINIT:
  192. av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
  193. return 0;
  194. case AVLINK_UNINIT:
  195. link->init_state = AVLINK_STARTINIT;
  196. if ((ret = avfilter_config_links(link->src)) < 0)
  197. return ret;
  198. if (!(config_link = link->srcpad->config_props)) {
  199. if (link->src->nb_inputs != 1) {
  200. av_log(link->src, AV_LOG_ERROR, "Source filters and filters "
  201. "with more than one input "
  202. "must set config_props() "
  203. "callbacks on all outputs\n");
  204. return AVERROR(EINVAL);
  205. }
  206. } else if ((ret = config_link(link)) < 0) {
  207. av_log(link->src, AV_LOG_ERROR,
  208. "Failed to configure output pad on %s\n",
  209. link->src->name);
  210. return ret;
  211. }
  212. switch (link->type) {
  213. case AVMEDIA_TYPE_VIDEO:
  214. if (!link->time_base.num && !link->time_base.den)
  215. link->time_base = inlink ? inlink->time_base : AV_TIME_BASE_Q;
  216. if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den)
  217. link->sample_aspect_ratio = inlink ?
  218. inlink->sample_aspect_ratio : (AVRational){1,1};
  219. if (inlink && !link->frame_rate.num && !link->frame_rate.den)
  220. link->frame_rate = inlink->frame_rate;
  221. if (inlink) {
  222. if (!link->w)
  223. link->w = inlink->w;
  224. if (!link->h)
  225. link->h = inlink->h;
  226. } else if (!link->w || !link->h) {
  227. av_log(link->src, AV_LOG_ERROR,
  228. "Video source filters must set their output link's "
  229. "width and height\n");
  230. return AVERROR(EINVAL);
  231. }
  232. break;
  233. case AVMEDIA_TYPE_AUDIO:
  234. if (inlink) {
  235. if (!link->sample_rate)
  236. link->sample_rate = inlink->sample_rate;
  237. if (!link->time_base.num && !link->time_base.den)
  238. link->time_base = inlink->time_base;
  239. if (!link->channel_layout)
  240. link->channel_layout = inlink->channel_layout;
  241. } else if (!link->sample_rate) {
  242. av_log(link->src, AV_LOG_ERROR,
  243. "Audio source filters must set their output link's "
  244. "sample_rate\n");
  245. return AVERROR(EINVAL);
  246. }
  247. if (!link->time_base.num && !link->time_base.den)
  248. link->time_base = (AVRational) {1, link->sample_rate};
  249. }
  250. if ((config_link = link->dstpad->config_props))
  251. if ((ret = config_link(link)) < 0) {
  252. av_log(link->src, AV_LOG_ERROR,
  253. "Failed to configure input pad on %s\n",
  254. link->dst->name);
  255. return ret;
  256. }
  257. link->init_state = AVLINK_INIT;
  258. }
  259. }
  260. return 0;
  261. }
  262. void ff_tlog_link(void *ctx, AVFilterLink *link, int end)
  263. {
  264. if (link->type == AVMEDIA_TYPE_VIDEO) {
  265. ff_tlog(ctx,
  266. "link[%p s:%dx%d fmt:%s %s->%s]%s",
  267. link, link->w, link->h,
  268. av_get_pix_fmt_name(link->format),
  269. link->src ? link->src->filter->name : "",
  270. link->dst ? link->dst->filter->name : "",
  271. end ? "\n" : "");
  272. } else {
  273. char buf[128];
  274. av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
  275. ff_tlog(ctx,
  276. "link[%p r:%d cl:%s fmt:%s %s->%s]%s",
  277. link, (int)link->sample_rate, buf,
  278. av_get_sample_fmt_name(link->format),
  279. link->src ? link->src->filter->name : "",
  280. link->dst ? link->dst->filter->name : "",
  281. end ? "\n" : "");
  282. }
  283. }
  284. int ff_request_frame(AVFilterLink *link)
  285. {
  286. int ret = -1;
  287. FF_TPRINTF_START(NULL, request_frame); ff_tlog_link(NULL, link, 1);
  288. if (link->closed)
  289. return AVERROR_EOF;
  290. if (link->srcpad->request_frame)
  291. ret = link->srcpad->request_frame(link);
  292. else if (link->src->inputs[0])
  293. ret = ff_request_frame(link->src->inputs[0]);
  294. if (ret == AVERROR_EOF && link->partial_buf) {
  295. AVFilterBufferRef *pbuf = link->partial_buf;
  296. link->partial_buf = NULL;
  297. ff_filter_samples_framed(link, pbuf);
  298. return 0;
  299. }
  300. if (ret == AVERROR_EOF)
  301. link->closed = 1;
  302. return ret;
  303. }
  304. int ff_poll_frame(AVFilterLink *link)
  305. {
  306. int i, min = INT_MAX;
  307. if (link->srcpad->poll_frame)
  308. return link->srcpad->poll_frame(link);
  309. for (i = 0; i < link->src->nb_inputs; i++) {
  310. int val;
  311. if (!link->src->inputs[i])
  312. return -1;
  313. val = ff_poll_frame(link->src->inputs[i]);
  314. min = FFMIN(min, val);
  315. }
  316. return min;
  317. }
  318. void ff_update_link_current_pts(AVFilterLink *link, int64_t pts)
  319. {
  320. if (pts == AV_NOPTS_VALUE)
  321. return;
  322. link->current_pts = av_rescale_q(pts, link->time_base, AV_TIME_BASE_Q);
  323. /* TODO use duration */
  324. if (link->graph && link->age_index >= 0)
  325. ff_avfilter_graph_update_heap(link->graph, link);
  326. }
  327. int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags)
  328. {
  329. if(!strcmp(cmd, "ping")){
  330. av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name);
  331. return 0;
  332. }else if(filter->filter->process_command) {
  333. return filter->filter->process_command(filter, cmd, arg, res, res_len, flags);
  334. }
  335. return AVERROR(ENOSYS);
  336. }
  337. #define MAX_REGISTERED_AVFILTERS_NB 128
  338. static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
  339. static int next_registered_avfilter_idx = 0;
  340. AVFilter *avfilter_get_by_name(const char *name)
  341. {
  342. int i;
  343. for (i = 0; registered_avfilters[i]; i++)
  344. if (!strcmp(registered_avfilters[i]->name, name))
  345. return registered_avfilters[i];
  346. return NULL;
  347. }
  348. int avfilter_register(AVFilter *filter)
  349. {
  350. int i;
  351. if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB) {
  352. av_log(NULL, AV_LOG_ERROR,
  353. "Maximum number of registered filters %d reached, "
  354. "impossible to register filter with name '%s'\n",
  355. MAX_REGISTERED_AVFILTERS_NB, filter->name);
  356. return AVERROR(ENOMEM);
  357. }
  358. for(i=0; filter->inputs && filter->inputs[i].name; i++) {
  359. const AVFilterPad *input = &filter->inputs[i];
  360. av_assert0( !input->filter_frame
  361. || (!input->start_frame && !input->end_frame && !input->draw_slice));
  362. }
  363. registered_avfilters[next_registered_avfilter_idx++] = filter;
  364. return 0;
  365. }
  366. AVFilter **av_filter_next(AVFilter **filter)
  367. {
  368. return filter ? ++filter : &registered_avfilters[0];
  369. }
  370. void avfilter_uninit(void)
  371. {
  372. memset(registered_avfilters, 0, sizeof(registered_avfilters));
  373. next_registered_avfilter_idx = 0;
  374. }
  375. static int pad_count(const AVFilterPad *pads)
  376. {
  377. int count;
  378. if (!pads)
  379. return 0;
  380. for(count = 0; pads->name; count ++) pads ++;
  381. return count;
  382. }
  383. static const char *default_filter_name(void *filter_ctx)
  384. {
  385. AVFilterContext *ctx = filter_ctx;
  386. return ctx->name ? ctx->name : ctx->filter->name;
  387. }
  388. static void *filter_child_next(void *obj, void *prev)
  389. {
  390. AVFilterContext *ctx = obj;
  391. if (!prev && ctx->filter && ctx->filter->priv_class)
  392. return ctx->priv;
  393. return NULL;
  394. }
  395. static const AVClass *filter_child_class_next(const AVClass *prev)
  396. {
  397. AVFilter **filter_ptr = NULL;
  398. /* find the filter that corresponds to prev */
  399. while (prev && *(filter_ptr = av_filter_next(filter_ptr)))
  400. if ((*filter_ptr)->priv_class == prev)
  401. break;
  402. /* could not find filter corresponding to prev */
  403. if (prev && !(*filter_ptr))
  404. return NULL;
  405. /* find next filter with specific options */
  406. while (*(filter_ptr = av_filter_next(filter_ptr)))
  407. if ((*filter_ptr)->priv_class)
  408. return (*filter_ptr)->priv_class;
  409. return NULL;
  410. }
  411. static const AVClass avfilter_class = {
  412. .class_name = "AVFilter",
  413. .item_name = default_filter_name,
  414. .version = LIBAVUTIL_VERSION_INT,
  415. .category = AV_CLASS_CATEGORY_FILTER,
  416. .child_next = filter_child_next,
  417. .child_class_next = filter_child_class_next,
  418. };
  419. const AVClass *avfilter_get_class(void)
  420. {
  421. return &avfilter_class;
  422. }
  423. int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
  424. {
  425. AVFilterContext *ret;
  426. *filter_ctx = NULL;
  427. if (!filter)
  428. return AVERROR(EINVAL);
  429. ret = av_mallocz(sizeof(AVFilterContext));
  430. if (!ret)
  431. return AVERROR(ENOMEM);
  432. ret->av_class = &avfilter_class;
  433. ret->filter = filter;
  434. ret->name = inst_name ? av_strdup(inst_name) : NULL;
  435. if (filter->priv_size) {
  436. ret->priv = av_mallocz(filter->priv_size);
  437. if (!ret->priv)
  438. goto err;
  439. }
  440. ret->nb_inputs = pad_count(filter->inputs);
  441. if (ret->nb_inputs ) {
  442. ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs);
  443. if (!ret->input_pads)
  444. goto err;
  445. memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->nb_inputs);
  446. ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_inputs);
  447. if (!ret->inputs)
  448. goto err;
  449. }
  450. ret->nb_outputs = pad_count(filter->outputs);
  451. if (ret->nb_outputs) {
  452. ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_outputs);
  453. if (!ret->output_pads)
  454. goto err;
  455. memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->nb_outputs);
  456. ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_outputs);
  457. if (!ret->outputs)
  458. goto err;
  459. }
  460. #if FF_API_FOO_COUNT
  461. ret->output_count = ret->nb_outputs;
  462. ret->input_count = ret->nb_inputs;
  463. #endif
  464. *filter_ctx = ret;
  465. return 0;
  466. err:
  467. av_freep(&ret->inputs);
  468. av_freep(&ret->input_pads);
  469. ret->nb_inputs = 0;
  470. av_freep(&ret->outputs);
  471. av_freep(&ret->output_pads);
  472. ret->nb_outputs = 0;
  473. av_freep(&ret->priv);
  474. av_free(ret);
  475. return AVERROR(ENOMEM);
  476. }
  477. void avfilter_free(AVFilterContext *filter)
  478. {
  479. int i;
  480. AVFilterLink *link;
  481. if (!filter)
  482. return;
  483. if (filter->filter->uninit)
  484. filter->filter->uninit(filter);
  485. for (i = 0; i < filter->nb_inputs; i++) {
  486. if ((link = filter->inputs[i])) {
  487. if (link->src)
  488. link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
  489. ff_formats_unref(&link->in_formats);
  490. ff_formats_unref(&link->out_formats);
  491. ff_formats_unref(&link->in_samplerates);
  492. ff_formats_unref(&link->out_samplerates);
  493. ff_channel_layouts_unref(&link->in_channel_layouts);
  494. ff_channel_layouts_unref(&link->out_channel_layouts);
  495. }
  496. avfilter_link_free(&link);
  497. }
  498. for (i = 0; i < filter->nb_outputs; i++) {
  499. if ((link = filter->outputs[i])) {
  500. if (link->dst)
  501. link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
  502. ff_formats_unref(&link->in_formats);
  503. ff_formats_unref(&link->out_formats);
  504. ff_formats_unref(&link->in_samplerates);
  505. ff_formats_unref(&link->out_samplerates);
  506. ff_channel_layouts_unref(&link->in_channel_layouts);
  507. ff_channel_layouts_unref(&link->out_channel_layouts);
  508. }
  509. avfilter_link_free(&link);
  510. }
  511. av_freep(&filter->name);
  512. av_freep(&filter->input_pads);
  513. av_freep(&filter->output_pads);
  514. av_freep(&filter->inputs);
  515. av_freep(&filter->outputs);
  516. av_freep(&filter->priv);
  517. while(filter->command_queue){
  518. ff_command_queue_pop(filter);
  519. }
  520. av_free(filter);
  521. }
  522. int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque)
  523. {
  524. int ret=0;
  525. if (filter->filter->init_opaque)
  526. ret = filter->filter->init_opaque(filter, args, opaque);
  527. else if (filter->filter->init)
  528. ret = filter->filter->init(filter, args);
  529. return ret;
  530. }
  531. const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx)
  532. {
  533. return pads[pad_idx].name;
  534. }
  535. enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx)
  536. {
  537. return pads[pad_idx].type;
  538. }
  539. int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
  540. {
  541. int ret;
  542. FF_TPRINTF_START(NULL, filter_frame); ff_tlog_link(NULL, link, 1); ff_tlog(NULL, " "); ff_tlog_ref(NULL, frame, 1);
  543. switch (link->type) {
  544. case AVMEDIA_TYPE_VIDEO:
  545. if((ret = ff_start_frame(link, frame)) < 0)
  546. return ret;
  547. if((ret = ff_draw_slice(link, 0, frame->video->h, 1)) < 0)
  548. return ret;
  549. if((ret = ff_end_frame(link)) < 0)
  550. return ret;
  551. return ret;
  552. case AVMEDIA_TYPE_AUDIO:
  553. return ff_filter_samples(link, frame);
  554. default: return AVERROR(EINVAL);
  555. }
  556. }