h264_metadata: Add option to delete filler data
[libav.git] / libavfilter / avfilter.c
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
22 #include "libavutil/avassert.h"
23 #include "libavutil/avstring.h"
24 #include "libavutil/buffer.h"
25 #include "libavutil/channel_layout.h"
26 #include "libavutil/common.h"
27 #include "libavutil/hwcontext.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/internal.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/rational.h"
33 #include "libavutil/samplefmt.h"
34
35 #include "audio.h"
36 #include "avfilter.h"
37 #include "formats.h"
38 #include "internal.h"
39 #include "video.h"
40
41 unsigned avfilter_version(void)
42 {
43 return LIBAVFILTER_VERSION_INT;
44 }
45
46 const char *avfilter_configuration(void)
47 {
48 return LIBAV_CONFIGURATION;
49 }
50
51 const char *avfilter_license(void)
52 {
53 #define LICENSE_PREFIX "libavfilter license: "
54 return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
55 }
56
57 void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
58 AVFilterPad **pads, AVFilterLink ***links,
59 AVFilterPad *newpad)
60 {
61 unsigned i;
62
63 idx = FFMIN(idx, *count);
64
65 *pads = av_realloc(*pads, sizeof(AVFilterPad) * (*count + 1));
66 *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1));
67 memmove(*pads + idx + 1, *pads + idx, sizeof(AVFilterPad) * (*count - idx));
68 memmove(*links + idx + 1, *links + idx, sizeof(AVFilterLink*) * (*count - idx));
69 memcpy(*pads + idx, newpad, sizeof(AVFilterPad));
70 (*links)[idx] = NULL;
71
72 (*count)++;
73 for (i = idx + 1; i < *count; i++)
74 if (*links[i])
75 (*(unsigned *)((uint8_t *) *links[i] + padidx_off))++;
76 }
77
78 int avfilter_link(AVFilterContext *src, unsigned srcpad,
79 AVFilterContext *dst, unsigned dstpad)
80 {
81 AVFilterLink *link;
82
83 if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad ||
84 src->outputs[srcpad] || dst->inputs[dstpad])
85 return AVERROR(EINVAL);
86
87 if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) {
88 av_log(src, AV_LOG_ERROR,
89 "Media type mismatch between the '%s' filter output pad %d and the '%s' filter input pad %d\n",
90 src->name, srcpad, dst->name, dstpad);
91 return AVERROR(EINVAL);
92 }
93
94 link = av_mallocz(sizeof(*link));
95 if (!link)
96 return AVERROR(ENOMEM);
97
98 src->outputs[srcpad] = dst->inputs[dstpad] = link;
99
100 link->src = src;
101 link->dst = dst;
102 link->srcpad = &src->output_pads[srcpad];
103 link->dstpad = &dst->input_pads[dstpad];
104 link->type = src->output_pads[srcpad].type;
105 assert(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
106 link->format = -1;
107
108 return 0;
109 }
110
111 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
112 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
113 {
114 int ret;
115 unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
116
117 av_log(link->dst, AV_LOG_VERBOSE, "auto-inserting filter '%s' "
118 "between the filter '%s' and the filter '%s'\n",
119 filt->name, link->src->name, link->dst->name);
120
121 link->dst->inputs[dstpad_idx] = NULL;
122 if ((ret = avfilter_link(filt, filt_dstpad_idx, link->dst, dstpad_idx)) < 0) {
123 /* failed to link output filter to new filter */
124 link->dst->inputs[dstpad_idx] = link;
125 return ret;
126 }
127
128 /* re-hookup the link to the new destination filter we inserted */
129 link->dst = filt;
130 link->dstpad = &filt->input_pads[filt_srcpad_idx];
131 filt->inputs[filt_srcpad_idx] = link;
132
133 /* if any information on supported media formats already exists on the
134 * link, we need to preserve that */
135 if (link->out_formats)
136 ff_formats_changeref(&link->out_formats,
137 &filt->outputs[filt_dstpad_idx]->out_formats);
138 if (link->out_samplerates)
139 ff_formats_changeref(&link->out_samplerates,
140 &filt->outputs[filt_dstpad_idx]->out_samplerates);
141 if (link->out_channel_layouts)
142 ff_channel_layouts_changeref(&link->out_channel_layouts,
143 &filt->outputs[filt_dstpad_idx]->out_channel_layouts);
144
145 return 0;
146 }
147
148 int avfilter_config_links(AVFilterContext *filter)
149 {
150 int (*config_link)(AVFilterLink *);
151 unsigned i;
152 int ret;
153
154 for (i = 0; i < filter->nb_inputs; i ++) {
155 AVFilterLink *link = filter->inputs[i];
156
157 if (!link) continue;
158 if (!link->src || !link->dst) {
159 av_log(filter, AV_LOG_ERROR,
160 "Not all input and output are properly linked (%d).\n", i);
161 return AVERROR(EINVAL);
162 }
163
164 switch (link->init_state) {
165 case AVLINK_INIT:
166 continue;
167 case AVLINK_STARTINIT:
168 av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
169 return 0;
170 case AVLINK_UNINIT:
171 link->init_state = AVLINK_STARTINIT;
172
173 if ((ret = avfilter_config_links(link->src)) < 0)
174 return ret;
175
176 if (!(config_link = link->srcpad->config_props)) {
177 if (link->src->nb_inputs != 1) {
178 av_log(link->src, AV_LOG_ERROR, "Source filters and filters "
179 "with more than one input "
180 "must set config_props() "
181 "callbacks on all outputs\n");
182 return AVERROR(EINVAL);
183 }
184 } else if ((ret = config_link(link)) < 0) {
185 av_log(link->src, AV_LOG_ERROR,
186 "Failed to configure output pad on %s\n",
187 link->src->name);
188 return ret;
189 }
190
191 if (link->time_base.num == 0 && link->time_base.den == 0)
192 link->time_base = link->src->nb_inputs ?
193 link->src->inputs[0]->time_base : AV_TIME_BASE_Q;
194
195 if (link->type == AVMEDIA_TYPE_VIDEO) {
196 if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den)
197 link->sample_aspect_ratio = link->src->nb_inputs ?
198 link->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1};
199
200 if (link->src->nb_inputs) {
201 if (!link->frame_rate.num && !link->frame_rate.den)
202 link->frame_rate = link->src->inputs[0]->frame_rate;
203 if (!link->w)
204 link->w = link->src->inputs[0]->w;
205 if (!link->h)
206 link->h = link->src->inputs[0]->h;
207 } else if (!link->w || !link->h) {
208 av_log(link->src, AV_LOG_ERROR,
209 "Video source filters must set their output link's "
210 "width and height\n");
211 return AVERROR(EINVAL);
212 }
213 }
214
215 if (link->src->nb_inputs && link->src->inputs[0]->hw_frames_ctx &&
216 !(link->src->filter->flags_internal & FF_FILTER_FLAG_HWFRAME_AWARE)) {
217 av_assert0(!link->hw_frames_ctx &&
218 "should not be set by non-hwframe-aware filter");
219 link->hw_frames_ctx = av_buffer_ref(link->src->inputs[0]->hw_frames_ctx);
220 if (!link->hw_frames_ctx)
221 return AVERROR(ENOMEM);
222 }
223
224 if ((config_link = link->dstpad->config_props))
225 if ((ret = config_link(link)) < 0) {
226 av_log(link->dst, AV_LOG_ERROR,
227 "Failed to configure input pad on %s\n",
228 link->dst->name);
229 return ret;
230 }
231
232 link->init_state = AVLINK_INIT;
233 }
234 }
235
236 return 0;
237 }
238
239 void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
240 {
241 if (link->type == AVMEDIA_TYPE_VIDEO) {
242 av_log(ctx, AV_LOG_TRACE,
243 "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",
244 link, link->w, link->h,
245 av_get_pix_fmt_name(link->format),
246 link->src ? link->src->filter->name : "",
247 link->dst ? link->dst->filter->name : "",
248 end ? "\n" : "");
249 } else {
250 char buf[128];
251 av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
252
253 av_log(ctx, AV_LOG_TRACE,
254 "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s",
255 link, link->sample_rate, buf,
256 av_get_sample_fmt_name(link->format),
257 link->src ? link->src->filter->name : "",
258 link->dst ? link->dst->filter->name : "",
259 end ? "\n" : "");
260 }
261 }
262
263 int ff_request_frame(AVFilterLink *link)
264 {
265 FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1);
266
267 if (link->srcpad->request_frame)
268 return link->srcpad->request_frame(link);
269 else if (link->src->inputs[0])
270 return ff_request_frame(link->src->inputs[0]);
271 else
272 return AVERROR(EINVAL);
273 }
274
275 int ff_poll_frame(AVFilterLink *link)
276 {
277 int i, min = INT_MAX;
278
279 if (link->srcpad->poll_frame)
280 return link->srcpad->poll_frame(link);
281
282 for (i = 0; i < link->src->nb_inputs; i++) {
283 int val;
284 if (!link->src->inputs[i])
285 return AVERROR(EINVAL);
286 val = ff_poll_frame(link->src->inputs[i]);
287 min = FFMIN(min, val);
288 }
289
290 return min;
291 }
292
293 static AVFilter *first_filter;
294
295 const AVFilter *avfilter_get_by_name(const char *name)
296 {
297 const AVFilter *f = NULL;
298
299 if (!name)
300 return NULL;
301
302 while ((f = avfilter_next(f)))
303 if (!strcmp(f->name, name))
304 return f;
305
306 return NULL;
307 }
308
309 int avfilter_register(AVFilter *filter)
310 {
311 AVFilter **f = &first_filter;
312 while (*f)
313 f = &(*f)->next;
314 *f = filter;
315 filter->next = NULL;
316 return 0;
317 }
318
319 const AVFilter *avfilter_next(const AVFilter *prev)
320 {
321 return prev ? prev->next : first_filter;
322 }
323
324 int avfilter_pad_count(const AVFilterPad *pads)
325 {
326 int count;
327
328 if (!pads)
329 return 0;
330
331 for (count = 0; pads->name; count++)
332 pads++;
333 return count;
334 }
335
336 static const char *filter_name(void *p)
337 {
338 AVFilterContext *filter = p;
339 return filter->filter->name;
340 }
341
342 static void *filter_child_next(void *obj, void *prev)
343 {
344 AVFilterContext *ctx = obj;
345 if (!prev && ctx->filter && ctx->filter->priv_class && ctx->priv)
346 return ctx->priv;
347 return NULL;
348 }
349
350 static const AVClass *filter_child_class_next(const AVClass *prev)
351 {
352 const AVFilter *f = NULL;
353
354 while (prev && (f = avfilter_next(f)))
355 if (f->priv_class == prev)
356 break;
357
358 while ((f = avfilter_next(f)))
359 if (f->priv_class)
360 return f->priv_class;
361
362 return NULL;
363 }
364
365 #define OFFSET(x) offsetof(AVFilterContext, x)
366 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
367 static const AVOption avfilter_options[] = {
368 { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
369 { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" },
370 { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .unit = "thread_type" },
371 { "extra_hw_frames", "Number of extra hardware frames to allocate for the user",
372 OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
373 { NULL },
374 };
375
376 static const AVClass avfilter_class = {
377 .class_name = "AVFilter",
378 .item_name = filter_name,
379 .version = LIBAVUTIL_VERSION_INT,
380 .child_next = filter_child_next,
381 .child_class_next = filter_child_class_next,
382 .option = avfilter_options,
383 };
384
385 static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg,
386 int *ret, int nb_jobs)
387 {
388 int i;
389
390 for (i = 0; i < nb_jobs; i++) {
391 int r = func(ctx, arg, i, nb_jobs);
392 if (ret)
393 ret[i] = r;
394 }
395 return 0;
396 }
397
398 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
399 {
400 AVFilterContext *ret;
401
402 if (!filter)
403 return NULL;
404
405 ret = av_mallocz(sizeof(AVFilterContext));
406 if (!ret)
407 return NULL;
408
409 ret->av_class = &avfilter_class;
410 ret->filter = filter;
411 ret->name = inst_name ? av_strdup(inst_name) : NULL;
412 if (filter->priv_size) {
413 ret->priv = av_mallocz(filter->priv_size);
414 if (!ret->priv)
415 goto err;
416 }
417
418 av_opt_set_defaults(ret);
419 if (filter->priv_class) {
420 *(const AVClass**)ret->priv = filter->priv_class;
421 av_opt_set_defaults(ret->priv);
422 }
423
424 ret->internal = av_mallocz(sizeof(*ret->internal));
425 if (!ret->internal)
426 goto err;
427 ret->internal->execute = default_execute;
428
429 ret->nb_inputs = avfilter_pad_count(filter->inputs);
430 if (ret->nb_inputs ) {
431 ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs);
432 if (!ret->input_pads)
433 goto err;
434 memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->nb_inputs);
435 ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_inputs);
436 if (!ret->inputs)
437 goto err;
438 }
439
440 ret->nb_outputs = avfilter_pad_count(filter->outputs);
441 if (ret->nb_outputs) {
442 ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_outputs);
443 if (!ret->output_pads)
444 goto err;
445 memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->nb_outputs);
446 ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_outputs);
447 if (!ret->outputs)
448 goto err;
449 }
450
451 return ret;
452
453 err:
454 av_freep(&ret->inputs);
455 av_freep(&ret->input_pads);
456 ret->nb_inputs = 0;
457 av_freep(&ret->outputs);
458 av_freep(&ret->output_pads);
459 ret->nb_outputs = 0;
460 av_freep(&ret->priv);
461 av_freep(&ret->internal);
462 av_free(ret);
463 return NULL;
464 }
465
466 static void free_link(AVFilterLink *link)
467 {
468 if (!link)
469 return;
470
471 if (link->src)
472 link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
473 if (link->dst)
474 link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
475
476 av_buffer_unref(&link->hw_frames_ctx);
477
478 ff_formats_unref(&link->in_formats);
479 ff_formats_unref(&link->out_formats);
480 ff_formats_unref(&link->in_samplerates);
481 ff_formats_unref(&link->out_samplerates);
482 ff_channel_layouts_unref(&link->in_channel_layouts);
483 ff_channel_layouts_unref(&link->out_channel_layouts);
484 av_freep(&link);
485 }
486
487 void avfilter_free(AVFilterContext *filter)
488 {
489 int i;
490
491 if (filter->graph)
492 ff_filter_graph_remove_filter(filter->graph, filter);
493
494 if (filter->filter->uninit)
495 filter->filter->uninit(filter);
496
497 for (i = 0; i < filter->nb_inputs; i++) {
498 free_link(filter->inputs[i]);
499 }
500 for (i = 0; i < filter->nb_outputs; i++) {
501 free_link(filter->outputs[i]);
502 }
503
504 if (filter->filter->priv_class)
505 av_opt_free(filter->priv);
506
507 av_buffer_unref(&filter->hw_device_ctx);
508
509 av_freep(&filter->name);
510 av_freep(&filter->input_pads);
511 av_freep(&filter->output_pads);
512 av_freep(&filter->inputs);
513 av_freep(&filter->outputs);
514 av_freep(&filter->priv);
515 av_freep(&filter->internal);
516 av_free(filter);
517 }
518
519 /* process a list of value1:value2:..., each value corresponding
520 * to subsequent AVOption, in the order they are declared */
521 static int process_unnamed_options(AVFilterContext *ctx, AVDictionary **options,
522 const char *args)
523 {
524 const AVOption *o = NULL;
525 const char *p = args;
526 char *val;
527
528 while (*p) {
529 o = av_opt_next(ctx->priv, o);
530 if (!o) {
531 av_log(ctx, AV_LOG_ERROR, "More options provided than "
532 "this filter supports.\n");
533 return AVERROR(EINVAL);
534 }
535 if (o->type == AV_OPT_TYPE_CONST)
536 continue;
537
538 val = av_get_token(&p, ":");
539 if (!val)
540 return AVERROR(ENOMEM);
541
542 av_dict_set(options, o->name, val, 0);
543
544 av_freep(&val);
545 if (*p)
546 p++;
547 }
548
549 return 0;
550 }
551
552 int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
553 {
554 int ret = 0;
555
556 ret = av_opt_set_dict(ctx, options);
557 if (ret < 0) {
558 av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n");
559 return ret;
560 }
561
562 if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS &&
563 ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&
564 ctx->graph->internal->thread_execute) {
565 ctx->thread_type = AVFILTER_THREAD_SLICE;
566 ctx->internal->execute = ctx->graph->internal->thread_execute;
567 } else {
568 ctx->thread_type = 0;
569 }
570
571 if (ctx->filter->priv_class) {
572 ret = av_opt_set_dict(ctx->priv, options);
573 if (ret < 0) {
574 av_log(ctx, AV_LOG_ERROR, "Error applying options to the filter.\n");
575 return ret;
576 }
577 }
578
579 if (ctx->filter->init)
580 ret = ctx->filter->init(ctx);
581 else if (ctx->filter->init_dict)
582 ret = ctx->filter->init_dict(ctx, options);
583
584 return ret;
585 }
586
587 int avfilter_init_str(AVFilterContext *filter, const char *args)
588 {
589 AVDictionary *options = NULL;
590 AVDictionaryEntry *e;
591 int ret = 0;
592
593 if (args && *args) {
594 if (!filter->filter->priv_class) {
595 av_log(filter, AV_LOG_ERROR, "This filter does not take any "
596 "options, but options were provided: %s.\n", args);
597 return AVERROR(EINVAL);
598 }
599
600 if (strchr(args, '=')) {
601 /* assume a list of key1=value1:key2=value2:... */
602 ret = av_dict_parse_string(&options, args, "=", ":", 0);
603 if (ret < 0)
604 goto fail;
605 } else {
606 ret = process_unnamed_options(filter, &options, args);
607 if (ret < 0)
608 goto fail;
609 }
610 }
611
612 ret = avfilter_init_dict(filter, &options);
613 if (ret < 0)
614 goto fail;
615
616 if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
617 av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key);
618 ret = AVERROR_OPTION_NOT_FOUND;
619 goto fail;
620 }
621
622 fail:
623 av_dict_free(&options);
624
625 return ret;
626 }
627
628 const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
629 {
630 return pads[pad_idx].name;
631 }
632
633 enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
634 {
635 return pads[pad_idx].type;
636 }
637
638 static int default_filter_frame(AVFilterLink *link, AVFrame *frame)
639 {
640 return ff_filter_frame(link->dst->outputs[0], frame);
641 }
642
643 int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
644 {
645 int (*filter_frame)(AVFilterLink *, AVFrame *);
646 AVFilterPad *dst = link->dstpad;
647 AVFrame *out = NULL;
648 int ret;
649
650 FF_DPRINTF_START(NULL, filter_frame);
651 ff_dlog_link(NULL, link, 1);
652
653 if (!(filter_frame = dst->filter_frame))
654 filter_frame = default_filter_frame;
655
656 /* copy the frame if needed */
657 if (dst->needs_writable && !av_frame_is_writable(frame)) {
658 av_log(link->dst, AV_LOG_DEBUG, "Copying data in avfilter.\n");
659
660 switch (link->type) {
661 case AVMEDIA_TYPE_VIDEO:
662 out = ff_get_video_buffer(link, link->w, link->h);
663 break;
664 case AVMEDIA_TYPE_AUDIO:
665 out = ff_get_audio_buffer(link, frame->nb_samples);
666 break;
667 default:
668 ret = AVERROR(EINVAL);
669 goto fail;
670 }
671 if (!out) {
672 ret = AVERROR(ENOMEM);
673 goto fail;
674 }
675
676 ret = av_frame_copy_props(out, frame);
677 if (ret < 0)
678 goto fail;
679
680 switch (link->type) {
681 case AVMEDIA_TYPE_VIDEO:
682 av_image_copy(out->data, out->linesize, frame->data, frame->linesize,
683 frame->format, frame->width, frame->height);
684 break;
685 case AVMEDIA_TYPE_AUDIO:
686 av_samples_copy(out->extended_data, frame->extended_data,
687 0, 0, frame->nb_samples,
688 av_get_channel_layout_nb_channels(frame->channel_layout),
689 frame->format);
690 break;
691 default:
692 ret = AVERROR(EINVAL);
693 goto fail;
694 }
695
696 av_frame_free(&frame);
697 } else
698 out = frame;
699
700 return filter_frame(link, out);
701
702 fail:
703 av_frame_free(&out);
704 av_frame_free(&frame);
705 return ret;
706 }
707
708 const AVClass *avfilter_get_class(void)
709 {
710 return &avfilter_class;
711 }
712
713 int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
714 int default_pool_size)
715 {
716 AVHWFramesContext *frames;
717
718 // Must already be set by caller.
719 av_assert0(link->hw_frames_ctx);
720
721 frames = (AVHWFramesContext*)link->hw_frames_ctx->data;
722
723 if (frames->initial_pool_size == 0) {
724 // Dynamic allocation is necessarily supported.
725 } else if (avctx->extra_hw_frames >= 0) {
726 frames->initial_pool_size += avctx->extra_hw_frames;
727 } else {
728 frames->initial_pool_size = default_pool_size;
729 }
730
731 return 0;
732 }