avfilter.c 20 KB

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