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.

662 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. int avfilter_link_get_channels(AVFilterLink *link)
  143. {
  144. return link->channels;
  145. }
  146. void avfilter_link_set_closed(AVFilterLink *link, int closed)
  147. {
  148. link->closed = closed;
  149. }
  150. int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
  151. unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
  152. {
  153. int ret;
  154. unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
  155. av_log(link->dst, AV_LOG_VERBOSE, "auto-inserting filter '%s' "
  156. "between the filter '%s' and the filter '%s'\n",
  157. filt->name, link->src->name, link->dst->name);
  158. link->dst->inputs[dstpad_idx] = NULL;
  159. if ((ret = avfilter_link(filt, filt_dstpad_idx, link->dst, dstpad_idx)) < 0) {
  160. /* failed to link output filter to new filter */
  161. link->dst->inputs[dstpad_idx] = link;
  162. return ret;
  163. }
  164. /* re-hookup the link to the new destination filter we inserted */
  165. link->dst = filt;
  166. link->dstpad = &filt->input_pads[filt_srcpad_idx];
  167. filt->inputs[filt_srcpad_idx] = link;
  168. /* if any information on supported media formats already exists on the
  169. * link, we need to preserve that */
  170. if (link->out_formats)
  171. ff_formats_changeref(&link->out_formats,
  172. &filt->outputs[filt_dstpad_idx]->out_formats);
  173. if (link->out_samplerates)
  174. ff_formats_changeref(&link->out_samplerates,
  175. &filt->outputs[filt_dstpad_idx]->out_samplerates);
  176. if (link->out_channel_layouts)
  177. ff_channel_layouts_changeref(&link->out_channel_layouts,
  178. &filt->outputs[filt_dstpad_idx]->out_channel_layouts);
  179. return 0;
  180. }
  181. int avfilter_config_links(AVFilterContext *filter)
  182. {
  183. int (*config_link)(AVFilterLink *);
  184. unsigned i;
  185. int ret;
  186. for (i = 0; i < filter->nb_inputs; i ++) {
  187. AVFilterLink *link = filter->inputs[i];
  188. AVFilterLink *inlink = link->src->nb_inputs ?
  189. link->src->inputs[0] : NULL;
  190. if (!link) continue;
  191. link->current_pts = AV_NOPTS_VALUE;
  192. switch (link->init_state) {
  193. case AVLINK_INIT:
  194. continue;
  195. case AVLINK_STARTINIT:
  196. av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
  197. return 0;
  198. case AVLINK_UNINIT:
  199. link->init_state = AVLINK_STARTINIT;
  200. if ((ret = avfilter_config_links(link->src)) < 0)
  201. return ret;
  202. if (!(config_link = link->srcpad->config_props)) {
  203. if (link->src->nb_inputs != 1) {
  204. av_log(link->src, AV_LOG_ERROR, "Source filters and filters "
  205. "with more than one input "
  206. "must set config_props() "
  207. "callbacks on all outputs\n");
  208. return AVERROR(EINVAL);
  209. }
  210. } else if ((ret = config_link(link)) < 0) {
  211. av_log(link->src, AV_LOG_ERROR,
  212. "Failed to configure output pad on %s\n",
  213. link->src->name);
  214. return ret;
  215. }
  216. switch (link->type) {
  217. case AVMEDIA_TYPE_VIDEO:
  218. if (!link->time_base.num && !link->time_base.den)
  219. link->time_base = inlink ? inlink->time_base : AV_TIME_BASE_Q;
  220. if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den)
  221. link->sample_aspect_ratio = inlink ?
  222. inlink->sample_aspect_ratio : (AVRational){1,1};
  223. if (inlink && !link->frame_rate.num && !link->frame_rate.den)
  224. link->frame_rate = inlink->frame_rate;
  225. if (inlink) {
  226. if (!link->w)
  227. link->w = inlink->w;
  228. if (!link->h)
  229. link->h = inlink->h;
  230. } else if (!link->w || !link->h) {
  231. av_log(link->src, AV_LOG_ERROR,
  232. "Video source filters must set their output link's "
  233. "width and height\n");
  234. return AVERROR(EINVAL);
  235. }
  236. break;
  237. case AVMEDIA_TYPE_AUDIO:
  238. if (inlink) {
  239. if (!link->sample_rate)
  240. link->sample_rate = inlink->sample_rate;
  241. if (!link->time_base.num && !link->time_base.den)
  242. link->time_base = inlink->time_base;
  243. if (!link->channel_layout)
  244. link->channel_layout = inlink->channel_layout;
  245. } else if (!link->sample_rate) {
  246. av_log(link->src, AV_LOG_ERROR,
  247. "Audio source filters must set their output link's "
  248. "sample_rate\n");
  249. return AVERROR(EINVAL);
  250. }
  251. if (!link->time_base.num && !link->time_base.den)
  252. link->time_base = (AVRational) {1, link->sample_rate};
  253. }
  254. if ((config_link = link->dstpad->config_props))
  255. if ((ret = config_link(link)) < 0) {
  256. av_log(link->src, AV_LOG_ERROR,
  257. "Failed to configure input pad on %s\n",
  258. link->dst->name);
  259. return ret;
  260. }
  261. link->init_state = AVLINK_INIT;
  262. }
  263. }
  264. return 0;
  265. }
  266. void ff_tlog_link(void *ctx, AVFilterLink *link, int end)
  267. {
  268. if (link->type == AVMEDIA_TYPE_VIDEO) {
  269. ff_tlog(ctx,
  270. "link[%p s:%dx%d fmt:%s %s->%s]%s",
  271. link, link->w, link->h,
  272. av_get_pix_fmt_name(link->format),
  273. link->src ? link->src->filter->name : "",
  274. link->dst ? link->dst->filter->name : "",
  275. end ? "\n" : "");
  276. } else {
  277. char buf[128];
  278. av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
  279. ff_tlog(ctx,
  280. "link[%p r:%d cl:%s fmt:%s %s->%s]%s",
  281. link, (int)link->sample_rate, buf,
  282. av_get_sample_fmt_name(link->format),
  283. link->src ? link->src->filter->name : "",
  284. link->dst ? link->dst->filter->name : "",
  285. end ? "\n" : "");
  286. }
  287. }
  288. int ff_request_frame(AVFilterLink *link)
  289. {
  290. int ret = -1;
  291. FF_TPRINTF_START(NULL, request_frame); ff_tlog_link(NULL, link, 1);
  292. if (link->closed)
  293. return AVERROR_EOF;
  294. if (link->srcpad->request_frame)
  295. ret = link->srcpad->request_frame(link);
  296. else if (link->src->inputs[0])
  297. ret = ff_request_frame(link->src->inputs[0]);
  298. if (ret == AVERROR_EOF && link->partial_buf) {
  299. AVFilterBufferRef *pbuf = link->partial_buf;
  300. link->partial_buf = NULL;
  301. ff_filter_samples_framed(link, pbuf);
  302. return 0;
  303. }
  304. if (ret == AVERROR_EOF)
  305. link->closed = 1;
  306. return ret;
  307. }
  308. int ff_poll_frame(AVFilterLink *link)
  309. {
  310. int i, min = INT_MAX;
  311. if (link->srcpad->poll_frame)
  312. return link->srcpad->poll_frame(link);
  313. for (i = 0; i < link->src->nb_inputs; i++) {
  314. int val;
  315. if (!link->src->inputs[i])
  316. return -1;
  317. val = ff_poll_frame(link->src->inputs[i]);
  318. min = FFMIN(min, val);
  319. }
  320. return min;
  321. }
  322. void ff_update_link_current_pts(AVFilterLink *link, int64_t pts)
  323. {
  324. if (pts == AV_NOPTS_VALUE)
  325. return;
  326. link->current_pts = av_rescale_q(pts, link->time_base, AV_TIME_BASE_Q);
  327. /* TODO use duration */
  328. if (link->graph && link->age_index >= 0)
  329. ff_avfilter_graph_update_heap(link->graph, link);
  330. }
  331. int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags)
  332. {
  333. if(!strcmp(cmd, "ping")){
  334. av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name);
  335. return 0;
  336. }else if(filter->filter->process_command) {
  337. return filter->filter->process_command(filter, cmd, arg, res, res_len, flags);
  338. }
  339. return AVERROR(ENOSYS);
  340. }
  341. #define MAX_REGISTERED_AVFILTERS_NB 128
  342. static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
  343. static int next_registered_avfilter_idx = 0;
  344. AVFilter *avfilter_get_by_name(const char *name)
  345. {
  346. int i;
  347. for (i = 0; registered_avfilters[i]; i++)
  348. if (!strcmp(registered_avfilters[i]->name, name))
  349. return registered_avfilters[i];
  350. return NULL;
  351. }
  352. int avfilter_register(AVFilter *filter)
  353. {
  354. int i;
  355. if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB) {
  356. av_log(NULL, AV_LOG_ERROR,
  357. "Maximum number of registered filters %d reached, "
  358. "impossible to register filter with name '%s'\n",
  359. MAX_REGISTERED_AVFILTERS_NB, filter->name);
  360. return AVERROR(ENOMEM);
  361. }
  362. for(i=0; filter->inputs && filter->inputs[i].name; i++) {
  363. const AVFilterPad *input = &filter->inputs[i];
  364. av_assert0( !input->filter_frame
  365. || (!input->start_frame && !input->end_frame && !input->draw_slice));
  366. }
  367. registered_avfilters[next_registered_avfilter_idx++] = filter;
  368. return 0;
  369. }
  370. AVFilter **av_filter_next(AVFilter **filter)
  371. {
  372. return filter ? ++filter : &registered_avfilters[0];
  373. }
  374. void avfilter_uninit(void)
  375. {
  376. memset(registered_avfilters, 0, sizeof(registered_avfilters));
  377. next_registered_avfilter_idx = 0;
  378. }
  379. static int pad_count(const AVFilterPad *pads)
  380. {
  381. int count;
  382. if (!pads)
  383. return 0;
  384. for(count = 0; pads->name; count ++) pads ++;
  385. return count;
  386. }
  387. static const char *default_filter_name(void *filter_ctx)
  388. {
  389. AVFilterContext *ctx = filter_ctx;
  390. return ctx->name ? ctx->name : ctx->filter->name;
  391. }
  392. static void *filter_child_next(void *obj, void *prev)
  393. {
  394. AVFilterContext *ctx = obj;
  395. if (!prev && ctx->filter && ctx->filter->priv_class)
  396. return ctx->priv;
  397. return NULL;
  398. }
  399. static const AVClass *filter_child_class_next(const AVClass *prev)
  400. {
  401. AVFilter **filter_ptr = NULL;
  402. /* find the filter that corresponds to prev */
  403. while (prev && *(filter_ptr = av_filter_next(filter_ptr)))
  404. if ((*filter_ptr)->priv_class == prev)
  405. break;
  406. /* could not find filter corresponding to prev */
  407. if (prev && !(*filter_ptr))
  408. return NULL;
  409. /* find next filter with specific options */
  410. while (*(filter_ptr = av_filter_next(filter_ptr)))
  411. if ((*filter_ptr)->priv_class)
  412. return (*filter_ptr)->priv_class;
  413. return NULL;
  414. }
  415. static const AVClass avfilter_class = {
  416. .class_name = "AVFilter",
  417. .item_name = default_filter_name,
  418. .version = LIBAVUTIL_VERSION_INT,
  419. .category = AV_CLASS_CATEGORY_FILTER,
  420. .child_next = filter_child_next,
  421. .child_class_next = filter_child_class_next,
  422. };
  423. const AVClass *avfilter_get_class(void)
  424. {
  425. return &avfilter_class;
  426. }
  427. int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
  428. {
  429. AVFilterContext *ret;
  430. *filter_ctx = NULL;
  431. if (!filter)
  432. return AVERROR(EINVAL);
  433. ret = av_mallocz(sizeof(AVFilterContext));
  434. if (!ret)
  435. return AVERROR(ENOMEM);
  436. ret->av_class = &avfilter_class;
  437. ret->filter = filter;
  438. ret->name = inst_name ? av_strdup(inst_name) : NULL;
  439. if (filter->priv_size) {
  440. ret->priv = av_mallocz(filter->priv_size);
  441. if (!ret->priv)
  442. goto err;
  443. }
  444. ret->nb_inputs = pad_count(filter->inputs);
  445. if (ret->nb_inputs ) {
  446. ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs);
  447. if (!ret->input_pads)
  448. goto err;
  449. memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->nb_inputs);
  450. ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_inputs);
  451. if (!ret->inputs)
  452. goto err;
  453. }
  454. ret->nb_outputs = pad_count(filter->outputs);
  455. if (ret->nb_outputs) {
  456. ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_outputs);
  457. if (!ret->output_pads)
  458. goto err;
  459. memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->nb_outputs);
  460. ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_outputs);
  461. if (!ret->outputs)
  462. goto err;
  463. }
  464. #if FF_API_FOO_COUNT
  465. ret->output_count = ret->nb_outputs;
  466. ret->input_count = ret->nb_inputs;
  467. #endif
  468. *filter_ctx = ret;
  469. return 0;
  470. err:
  471. av_freep(&ret->inputs);
  472. av_freep(&ret->input_pads);
  473. ret->nb_inputs = 0;
  474. av_freep(&ret->outputs);
  475. av_freep(&ret->output_pads);
  476. ret->nb_outputs = 0;
  477. av_freep(&ret->priv);
  478. av_free(ret);
  479. return AVERROR(ENOMEM);
  480. }
  481. void avfilter_free(AVFilterContext *filter)
  482. {
  483. int i;
  484. AVFilterLink *link;
  485. if (!filter)
  486. return;
  487. if (filter->filter->uninit)
  488. filter->filter->uninit(filter);
  489. for (i = 0; i < filter->nb_inputs; i++) {
  490. if ((link = filter->inputs[i])) {
  491. if (link->src)
  492. link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
  493. ff_formats_unref(&link->in_formats);
  494. ff_formats_unref(&link->out_formats);
  495. ff_formats_unref(&link->in_samplerates);
  496. ff_formats_unref(&link->out_samplerates);
  497. ff_channel_layouts_unref(&link->in_channel_layouts);
  498. ff_channel_layouts_unref(&link->out_channel_layouts);
  499. }
  500. avfilter_link_free(&link);
  501. }
  502. for (i = 0; i < filter->nb_outputs; i++) {
  503. if ((link = filter->outputs[i])) {
  504. if (link->dst)
  505. link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
  506. ff_formats_unref(&link->in_formats);
  507. ff_formats_unref(&link->out_formats);
  508. ff_formats_unref(&link->in_samplerates);
  509. ff_formats_unref(&link->out_samplerates);
  510. ff_channel_layouts_unref(&link->in_channel_layouts);
  511. ff_channel_layouts_unref(&link->out_channel_layouts);
  512. }
  513. avfilter_link_free(&link);
  514. }
  515. av_freep(&filter->name);
  516. av_freep(&filter->input_pads);
  517. av_freep(&filter->output_pads);
  518. av_freep(&filter->inputs);
  519. av_freep(&filter->outputs);
  520. av_freep(&filter->priv);
  521. while(filter->command_queue){
  522. ff_command_queue_pop(filter);
  523. }
  524. av_free(filter);
  525. }
  526. int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque)
  527. {
  528. int ret=0;
  529. if (filter->filter->init_opaque)
  530. ret = filter->filter->init_opaque(filter, args, opaque);
  531. else if (filter->filter->init)
  532. ret = filter->filter->init(filter, args);
  533. return ret;
  534. }
  535. const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx)
  536. {
  537. return pads[pad_idx].name;
  538. }
  539. enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx)
  540. {
  541. return pads[pad_idx].type;
  542. }
  543. int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
  544. {
  545. int ret;
  546. FF_TPRINTF_START(NULL, filter_frame); ff_tlog_link(NULL, link, 1); ff_tlog(NULL, " "); ff_tlog_ref(NULL, frame, 1);
  547. switch (link->type) {
  548. case AVMEDIA_TYPE_VIDEO:
  549. if((ret = ff_start_frame(link, frame)) < 0)
  550. return ret;
  551. if((ret = ff_draw_slice(link, 0, frame->video->h, 1)) < 0)
  552. return ret;
  553. if((ret = ff_end_frame(link)) < 0)
  554. return ret;
  555. return ret;
  556. case AVMEDIA_TYPE_AUDIO:
  557. return ff_filter_samples(link, frame);
  558. default: return AVERROR(EINVAL);
  559. }
  560. }