FFmpeg
Loading...
Searching...
No Matches
bitstreamfilter.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "config.h"
20
21#include <string.h>
22
23#include "libavutil/avassert.h"
24#include "libavutil/mem.h"
25#include "libavutil/opt.h"
26
27#include "bsf.h"
28#include "bsf_internal.h"
29
30static const char *default_bsf_name(void *filter_ctx)
31{
33 return ctx->name ? ctx->name : ctx->filter->name;
34}
35
36static void *bsf_child_next(void *obj, void *prev)
37{
39 if (!prev && ctx->filter && ctx->filter->priv_class && ctx->priv_data)
40 return ctx->priv_data;
41 return NULL;
42}
43
45 .class_name = "AVBitStreamFilterContext",
46 .item_name = default_bsf_name,
47 .version = LIBAVUTIL_VERSION_INT,
49 .child_next = bsf_child_next,
50 .child_class_iterate = ff_bsf_child_class_iterate,
51 .state_flags_offset = offsetof(FFBitStreamFilterContext, state_flags),
52};
53
54int ff_bsf_alloc(const AVBitStreamFilter *filter, const char *inst_name, AVBitStreamFilterContext **pctx)
55{
58 const FFBitStreamFilter *const fi = ff_bsf(filter);
59 int ret = AVERROR(ENOMEM), preinited = 0;
60
62
63 ctxi = av_mallocz(sizeof(*ctxi));
64 if (!ctxi)
65 return AVERROR(ENOMEM);
66 *pctx = ctx = &ctxi->p;
67
68 ctx->av_class = &bitstreamfilter_class;
69 ctx->filter = filter;
70 ctx->name = inst_name ? av_strdup(inst_name) : NULL;
71 if (fi->priv_data_size) {
72 ctx->priv_data = av_mallocz(fi->priv_data_size);
73 if (!ctx->priv_data)
74 goto err;
75 }
76 if (fi->preinit) {
77 ret = fi->preinit(ctx);
78 if (ret < 0)
79 goto err;
80 preinited = 1;
81 }
82
84 if (filter->priv_class) {
85 *(const AVClass**)ctx->priv_data = filter->priv_class;
86 av_opt_set_defaults(ctx->priv_data);
87 }
88
89 ctx->nb_inputs = fi->nb_inputs;
90 if (ctx->nb_inputs ) {
91 ctx->input_pads = av_memdup(fi->inputs, ctx->nb_inputs * sizeof(*fi->inputs));
92 if (!ctx->input_pads)
93 goto err;
94 ctx->inputs = av_calloc(ctx->nb_inputs, sizeof(*ctx->inputs));
95 if (!ctx->inputs)
96 goto err;
97 }
98
99 ctx->nb_outputs = fi->nb_outputs;
100 if (ctx->nb_outputs) {
101 ctx->output_pads = av_memdup(fi->outputs, ctx->nb_outputs * sizeof(*fi->outputs));
102 if (!ctx->output_pads)
103 goto err;
104 ctx->outputs = av_calloc(ctx->nb_outputs, sizeof(*ctx->outputs));
105 if (!ctx->outputs)
106 goto err;
107 }
108
109 return 0;
110
111err:
112 if (preinited)
113 fi->uninit(ctx);
114 av_freep(&ctx->name);
115 av_freep(&ctx->inputs);
116 av_freep(&ctx->input_pads);
117 ctx->nb_inputs = 0;
118 av_freep(&ctx->outputs);
119 av_freep(&ctx->output_pads);
120 ctx->nb_outputs = 0;
121 av_freep(&ctx->priv_data);
122 av_freep(pctx);
123 return ret;
124}
125
127 AVBitStreamFilterContext *dst, unsigned dstpad)
128{
131
132 av_assert0(src->graph);
133 av_assert0(dst->graph);
134 av_assert0(src->graph == dst->graph);
135
136 if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad ||
137 src->outputs[srcpad] || dst->inputs[dstpad])
138 return AVERROR(EINVAL);
139
140 if (!(ffbsfctx(src)->state_flags & AV_CLASS_STATE_INITIALIZED) ||
141 !(ffbsfctx(dst)->state_flags & AV_CLASS_STATE_INITIALIZED)) {
142 av_log(src, AV_LOG_ERROR, "Filters must be initialized before linking.\n");
143 return AVERROR(EINVAL);
144 }
145
146 if (src->output_pads[srcpad].codec_ids && dst->input_pads[dstpad].codec_ids) {
147 int found = 0;
148 for (int i = 0; src->output_pads[srcpad].codec_ids[i] != AV_CODEC_ID_NONE; i++) {
149 for (int j = 0; dst->input_pads[dstpad].codec_ids[j] != AV_CODEC_ID_NONE; j++)
150 if (src->output_pads[srcpad].codec_ids[i] == dst->input_pads[dstpad].codec_ids[j]) {
151 found = 1;
152 break;
153 }
154 if (found)
155 break;
156 }
157
158 if (!found) {
159 av_log(src, AV_LOG_ERROR, "No common codec id between source and dest pads\n");
160 av_log(src, AV_LOG_ERROR, "Supported input pad codecs are: ");
161 for (int i = 0; dst->input_pads[dstpad].codec_ids[i] != AV_CODEC_ID_NONE; i++) {
162 enum AVCodecID codec_id = dst->input_pads[dstpad].codec_ids[i];
163 av_log(src, AV_LOG_ERROR, "%s (%d) ",
165 }
166 av_log(src, AV_LOG_ERROR, "\n");
167 av_log(src, AV_LOG_ERROR, "Supported output pad codecs are: ");
168 for (int i = 0; src->output_pads[srcpad].codec_ids[i] != AV_CODEC_ID_NONE; i++) {
169 enum AVCodecID codec_id = src->output_pads[srcpad].codec_ids[i];
170 av_log(src, AV_LOG_ERROR, "%s (%d) ",
172 }
173 av_log(src, AV_LOG_ERROR, "\n");
174
175 return AVERROR(EINVAL);
176 }
177 }
178
179 li = av_mallocz(sizeof(*li));
180 if (!li)
181 return AVERROR(ENOMEM);
182 link = &li->l;
183
184 src->outputs[srcpad] = dst->inputs[dstpad] = link;
185
186 link->src = src;
187 link->dst = dst;
188 link->srcpad = &src->output_pads[srcpad];
189 link->dstpad = &dst->input_pads[dstpad];
190 link->graph = src->graph;
192 if (!li->fifo)
193 return AVERROR(ENOMEM);
194
195 return 0;
196}
197
199{
200 AVBitStreamFilterLink *link = *plink;
202
203 if (!link)
204 return;
205 li = ff_link_internal(link);
206
209
210 av_freep(plink);
211}
212
214{
215 if (!link)
216 return;
217
218 if (link->src)
219 link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
220 if (link->dst)
221 link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
222
223 link_free(&link);
224}
225
227{
228 int i;
229
230 if (!ctx)
231 return;
232
233 if (ctx->graph)
235
236 if (ff_bsf(ctx->filter)->uninit)
237 ff_bsf(ctx->filter)->uninit(ctx);
238
239 for (i = 0; i < ctx->nb_inputs; i++) {
240 free_link(ctx->inputs[i]);
241 if (ctx->input_pads[i].flags & FF_BSF_PAD_FLAG_FREE_NAME)
242 av_freep(&ctx->input_pads[i].name);
243 }
244 for (i = 0; i < ctx->nb_outputs; i++) {
245 free_link(ctx->outputs[i]);
246 if (ctx->output_pads[i].flags & FF_BSF_PAD_FLAG_FREE_NAME)
247 av_freep(&ctx->output_pads[i].name);
248 }
249
250 if (ctx->filter->priv_class)
251 av_opt_free(ctx->priv_data);
252
253 av_freep(&ctx->name);
254 av_freep(&ctx->input_pads);
255 av_freep(&ctx->output_pads);
256 av_freep(&ctx->inputs);
257 av_freep(&ctx->outputs);
258 av_freep(&ctx->priv_data);
260 av_free(ctx);
261}
262
263/**
264 * Parse filter options into a dictionary.
265 *
266 * @param logctx context for logging
267 * @param priv_class a filter's private class for shorthand options or NULL
268 * @param options dictionary to store parsed options in
269 * @param args options string to parse
270 *
271 * @return a non-negative number on success, a negative error code on failure
272 */
273static int bsf_opt_parse(void *logctx, const AVClass *priv_class,
274 AVDictionary **options, const char *args)
275{
276 const AVOption *o = NULL;
277 int ret;
278 int offset= -1;
279
280 if (!args)
281 return 0;
282
283 while (*args) {
284 char *parsed_key, *value;
285 const char *key;
286 const char *shorthand = NULL;
287 int additional_flags = 0;
288
289 if (priv_class && (o = av_opt_next(&priv_class, o))) {
290 if (o->type == AV_OPT_TYPE_CONST || o->offset == offset)
291 continue;
292 offset = o->offset;
293 shorthand = o->name;
294 }
295
296 ret = av_opt_get_key_value(&args, "=", ":",
297 shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
298 &parsed_key, &value);
299 if (ret < 0) {
300 if (ret == AVERROR(EINVAL))
301 av_log(logctx, AV_LOG_ERROR, "No option name near '%s'\n", args);
302 else
303 av_log(logctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", args,
304 av_err2str(ret));
305 return ret;
306 }
307 if (*args)
308 args++;
309 if (parsed_key) {
310 key = parsed_key;
311 additional_flags = AV_DICT_DONT_STRDUP_KEY;
312 priv_class = NULL; /* reject all remaining shorthand */
313 } else {
314 key = shorthand;
315 }
316
317 av_log(logctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
318
320 additional_flags | AV_DICT_DONT_STRDUP_VAL | AV_DICT_MULTIKEY);
321 }
322
323 return 0;
324}
325
327{
329 int ret = 0;
330
332 av_log(ctx, AV_LOG_ERROR, "Filter already initialized\n");
333 return AVERROR(EINVAL);
334 }
335
337 if (ret < 0) {
338 av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n");
339 return ret;
340 }
341
342 if (ff_bsf(ctx->filter)->init2)
343 ret = ff_bsf(ctx->filter)->init2(ctx);
344 if (ret < 0)
345 return ret;
346
348
349 return 0;
350}
351
353{
355 const AVDictionaryEntry *e;
356 int ret = 0;
357
358 if (args && *args) {
359 ret = bsf_opt_parse(ctx, ctx->filter->priv_class, &options, args);
360 if (ret < 0)
361 goto fail;
362 }
363
365 if (ret < 0)
366 goto fail;
367
368 if ((e = av_dict_iterate(options, NULL))) {
369 av_log(ctx, AV_LOG_ERROR, "No such option: %s.\n", e->key);
371 goto fail;
372 }
373
374fail:
376
377 return ret;
378}
379
380const char *av_bsf_pad_get_name(const AVBitStreamFilterPad *pads, int pad_idx)
381{
382 return pads[pad_idx].name;
383}
384
385const enum AVCodecID *av_bsf_pad_get_codec_ids(const AVBitStreamFilterPad *pads, int pad_idx)
386{
387 return pads[pad_idx].codec_ids;
388}
389
391{
392 if (pts == AV_NOPTS_VALUE)
393 return;
394 li->l.current_pts = pts;
396 if (li->l.graph && li->age_index >= 0)
398}
399
401{
403 ctxi->ready = FFMAX(ctxi->ready, priority);
404}
405
406/**
407 * Clear packet_blocked_in on all outputs.
408 * This is necessary whenever something changes on input.
409 */
411{
412 unsigned i;
413
414 for (i = 0; i < filter->nb_outputs; i++) {
416 li->packet_blocked_in = 0;
417 }
418}
419
421{
423
424 if (li->status_in == status)
425 return;
426 av_assert0(!li->status_in);
427 li->status_in = status;
428 li->status_in_pts = pts;
429 li->packet_wanted_out = 0;
430 li->packet_blocked_in = 0;
431 filter_unblock(link->dst);
432 ff_bsf_set_ready(link->dst, 200);
433}
434
435/**
436 * Set the status field of a link from the destination filter.
437 * The pts should probably be left unset (AV_NOPTS_VALUE).
438 */
440{
442
445 li->status_out = status;
446 if (pts != AV_NOPTS_VALUE)
448 filter_unblock(link->dst);
449 ff_bsf_set_ready(link->src, 200);
450}
451
453{
454 int (*config_link)(AVBitStreamFilterLink *);
455 unsigned i;
456 int ret;
457
458 for (i = 0; i < filter->nb_inputs; i ++) {
459 AVBitStreamFilterLink *link = filter->inputs[i];
460 AVBitStreamFilterLink *inlink;
462
463 if (!link) continue;
464 if (!link->src || !link->dst) {
466 "Not all input and output are properly linked (%d).\n", i);
467 return AVERROR(EINVAL);
468 }
469
470 inlink = link->src->nb_inputs ? link->src->inputs[0] : NULL;
471 link->current_pts =
473
474 switch (li->init_state) {
475 case AVLINK_INIT:
476 continue;
477 case AVLINK_STARTINIT:
478 av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
479 return 0;
480 case AVLINK_UNINIT:
481 li->init_state = AVLINK_STARTINIT;
482
483 if ((ret = ff_bsf_config_links(link->src)) < 0)
484 return ret;
485
486 if (!(config_link = link->srcpad->config_props)) {
487 if (link->src->nb_inputs != 1) {
488 av_log(link->src, AV_LOG_ERROR, "Source filters and filters "
489 "with more than one input "
490 "must set config_props() "
491 "callbacks on all outputs\n");
492 return AVERROR(EINVAL);
493 }
494 }
495
496 if (inlink) {
497 av_assert0(!link->par && inlink->par);
499 if (!link->par)
500 return AVERROR(ENOMEM);
501 ret = avcodec_parameters_copy(link->par, inlink->par);
502 if (ret < 0)
503 return ret;
504 } else {
505 av_assert0(!link->par);
507 if (!link->par)
508 return AVERROR(ENOMEM);
509 }
510
511 if (config_link && (ret = config_link(link)) < 0) {
512 av_log(link->src, AV_LOG_ERROR,
513 "Failed to configure output pad on %s\n",
514 link->src->name);
515 return ret;
516 }
517
518 switch (link->par->codec_type) {
520 if (!link->time_base.num && !link->time_base.den)
521 link->time_base = inlink ? inlink->time_base : AV_TIME_BASE_Q;
522 break;
523
525 if (inlink) {
526 if (!link->time_base.num && !link->time_base.den)
527 link->time_base = inlink->time_base;
528 }
529
530 if (!link->time_base.num && !link->time_base.den)
531 link->time_base = (AVRational) {1, link->par->sample_rate};
532 break;
533 }
534
535 if (link->dstpad->codec_ids) {
536 int j;
537 for (j = 0; link->dstpad->codec_ids[j] != AV_CODEC_ID_NONE; j++)
538 if (link->par->codec_id == link->dstpad->codec_ids[j])
539 break;
540 if (link->dstpad->codec_ids[j] == AV_CODEC_ID_NONE) {
541 av_log(link->dst, AV_LOG_ERROR, "Unsupported input codec id %s (%d). Supported input pad codecs are: ",
542 avcodec_get_name(link->par->codec_id), link->par->codec_id);
543 for (j = 0; link->dstpad->codec_ids[j] != AV_CODEC_ID_NONE; j++) {
544 enum AVCodecID codec_id = link->dstpad->codec_ids[j];
545 av_log(link->dst, AV_LOG_ERROR, "%s (%d) ",
547 }
548 av_log(link->dst, AV_LOG_ERROR, "\n");
549 return AVERROR(EINVAL);
550 }
551 }
552
553 if ((config_link = link->dstpad->config_props))
554 if ((ret = config_link(link)) < 0) {
555 av_log(link->dst, AV_LOG_ERROR,
556 "Failed to configure input pad on %s\n",
557 link->dst->name);
558 return ret;
559 }
560
561 li->init_state = AVLINK_INIT;
562 }
563 }
564
565 return 0;
566}
567
569{
571
573 if (li->status_out)
574 return li->status_out;
575 if (li->status_in) {
578 av_assert1(ffbsfctx(link->dst)->ready >= 300);
579 return 0;
580 } else {
581 /* Acknowledge status change. Filters using ff_bsf_request_packet() will
582 handle the change automatically. Filters can also check the
583 status directly but none do yet. */
585 return li->status_out;
586 }
587 }
588 li->packet_wanted_out = 1;
589 ff_bsf_set_ready(link->src, 100);
590 return 0;
591}
592
594{
595 unsigned i;
596 int64_t r = INT64_MAX;
597
598 for (i = 0; i < ctx->nb_inputs; i++) {
599 AVBitStreamFilterLink * const link = ctx->inputs[i];
601 if (li->status_out == status)
602 r = FFMIN(r, av_rescale_q(link->current_pts, link->time_base, link_time_base));
603 }
604 if (r < INT64_MAX)
605 return r;
606 av_log(ctx, AV_LOG_WARNING, "EOF timestamp not reliable\n");
607 for (i = 0; i < ctx->nb_inputs; i++) {
608 AVBitStreamFilterLink * const link = ctx->inputs[i];
610 r = FFMIN(r, av_rescale_q(li->status_in_pts, link->time_base, link_time_base));
611 }
612 if (r < INT64_MAX)
613 return r;
614 return AV_NOPTS_VALUE;
615}
616
618{
620 int ret = -1;
621
622 /* Assume the filter is blocked, let the method clear it if not */
623 li->packet_blocked_in = 1;
624 if (link->srcpad->request_packet)
625 ret = link->srcpad->request_packet(link);
626 else if (link->src->inputs[0])
627 ret = ff_bsf_request_packet(link->src->inputs[0]);
628 if (ret < 0) {
629 if (ret != AVERROR(EAGAIN) && ret != li->status_in)
630 ff_bsf_link_set_in_status(link, ret, guess_status_pts(link->src, ret, link->time_base));
631 if (ret == AVERROR_EOF)
632 ret = 0;
633 }
634 return ret;
635}
636
638{
639 return ff_bsf_filter_packet(link->dst->outputs[0], pkt);
640}
641
643{
646 int ret;
647
648 if (!(filter = dst->filter))
650
651 if (dst->flags & FF_BSF_PAD_FLAG_NEEDS_WRITABLE) {
653 if (ret < 0)
654 goto fail;
655 }
656
657 ret = filter(link, pkt);
658 link->packet_count_out++;
659 return ret;
660
661fail:
663 return ret;
664}
665
667{
669 FFBitStreamFilterGraph * const graphi = ffbsffiltergraph(link->graph);
670 int ret;
671
673 link->packet_count_in++;
674 filter_unblock(link->dst);
676 return AVERROR(ENOMEM);
677 ret = av_container_fifo_write(li->fifo, pkt, 0);
679 if (ret < 0)
680 return ret;
681 av_assert1(graphi->packets_queued < graphi->max_packet_queue);
682 graphi->packets_queued++;
683 ff_bsf_set_ready(link->dst, 300);
684 return 0;
685}
686
688{
690 AVPacket *pkt = NULL;
692 int ret;
693
695 ret = ff_bsf_inlink_consume_packet(link, &pkt);
696 av_assert1(ret);
697 if (ret < 0) {
698 av_assert1(!pkt);
699 return ret;
700 }
701
702 /* The filter will soon have received a new packet, that may allow it to
703 produce one or more: unblock its outputs. */
705 /* AVBitStreamFilterPad.filter_packet() expect packet_count_out to have the value
706 before the packet; filter_packet_framed() will re-increment it. */
707 link->packet_count_out--;
708 ret = filter_packet_framed(link, pkt);
709 if (ret < 0 && ret != li->status_out) {
711 } else {
712 /* Run once again, to see if several packets were available, or if
713 the input status has also changed, or any other reason. */
714 ff_bsf_set_ready(dst, 300);
715 }
716 return ret;
717}
718
720{
721 AVBitStreamFilterLink *in = &li_in->l;
722 unsigned out = 0, progress = 0;
723 int ret;
724
725 av_assert0(!li_in->status_out);
726 if (!filter->nb_outputs) {
727 /* not necessary with the current API and sinks */
728 return 0;
729 }
730 while (!li_in->status_out) {
732
733 if (!li_out->status_in) {
734 progress++;
735 ret = request_packet_to_filter(filter->outputs[out]);
736 if (ret < 0)
737 return ret;
738 }
739 if (++out == filter->nb_outputs) {
740 if (!progress) {
741 /* Every output already closed: input no longer interesting. */
742 link_set_out_status(in, li_in->status_in, li_in->status_in_pts);
743 return 0;
744 }
745 progress = 0;
746 out = 0;
747 }
748 }
750 return 0;
751}
752
754{
755 int i, nb_eofs = 0;
756
757 for (i = 0; i < ctx->nb_outputs; i++)
758 nb_eofs += ff_bsf_outlink_get_status(ctx->outputs[i]) == AVERROR_EOF;
759 if (ctx->nb_outputs && nb_eofs == ctx->nb_outputs) {
760 for (int j = 0; j < ctx->nb_inputs; j++)
762 return 0;
763 }
764
765 for (i = 0; i < ctx->nb_inputs; i++) {
768 return filter_packet_to_filter(ctx->inputs[i]);
769 }
770 }
771 for (i = 0; i < ctx->nb_inputs; i++) {
772 BitStreamFilterLinkInternal * const li = ff_link_internal(ctx->inputs[i]);
773 if (li->status_in && !li->status_out) {
775 return forward_status_change(ctx, li);
776 }
777 }
778 for (i = 0; i < ctx->nb_outputs; i++) {
779 BitStreamFilterLinkInternal * const li = ff_link_internal(ctx->outputs[i]);
780 if (li->packet_wanted_out &&
781 !li->packet_blocked_in) {
782 return request_packet_to_filter(ctx->outputs[i]);
783 }
784 }
785 for (i = 0; i < ctx->nb_outputs; i++) {
786 BitStreamFilterLinkInternal * const li = ff_link_internal(ctx->outputs[i]);
787 if (li->packet_wanted_out)
788 return request_packet_to_filter(ctx->outputs[i]);
789 }
790 if (!ctx->nb_outputs) {
792 return 0;
793 }
795}
796
798{
800 const FFBitStreamFilter *const fi = ff_bsf(ctx->filter);
801 int ret;
802
803 ctxi->ready = 0;
804 ret = fi->activate ? fi->activate(ctx) : filter_activate_default(ctx);
805 if (ret == FFERROR_BSF_NOT_READY)
806 ret = 0;
807 return ret;
808}
809
811{
813 *rpts = link->current_pts;
815 return *rstatus = 0;
816 if (li->status_out)
817 return *rstatus = li->status_out;
818 if (!li->status_in)
819 return *rstatus = 0;
820 *rstatus = li->status_out = li->status_in;
822 *rpts = link->current_pts;
823 return 1;
824}
825
831
837
839{
841 li->l.packet_count_out++;
842}
843
845{
847 FFBitStreamFilterGraph * const graphi = ffbsffiltergraph(link->graph);
848 AVPacket *pkt;
849
850 *rpkt = NULL;
852 return 0;
853
855 if (!pkt)
856 return AVERROR(ENOMEM);
857
859 consume_update(li, pkt);
860 av_assert1(graphi->packets_queued > 0);
861 graphi->packets_queued--;
862 *rpkt = pkt;
863 return 1;
864}
865
874
876{
878 FFBitStreamFilterGraph * const graphi = ffbsffiltergraph(link->graph);
879 if (li->status_out)
880 return;
881 li->packet_wanted_out = 0;
882 li->packet_blocked_in = 0;
883 link_set_out_status(link, status, AV_NOPTS_VALUE);
884 while (av_container_fifo_can_read(li->fifo)) {
888 av_assert1(graphi->packets_queued > 0);
889 graphi->packets_queued--;
890 }
891 if (!li->status_in)
892 li->status_in = status;
893}
894
900
906
908 {
909 .name = "default",
910 }
911};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
const AVClass * ff_bsf_child_class_iterate(void **opaque)
void ff_bsf_set_ready(AVBitStreamFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
static int filter_packet_framed(AVBitStreamFilterLink *link, AVPacket *pkt)
int ff_bsf_inlink_acknowledge_status(AVBitStreamFilterLink *link, int *rstatus, int64_t *rpts)
int ff_bsf_inlink_consume_packet(AVBitStreamFilterLink *link, AVPacket **rpkt)
int ff_bsf_outlink_packet_wanted(AVBitStreamFilterLink *link)
static const char * default_bsf_name(void *filter_ctx)
static void consume_update(BitStreamFilterLinkInternal *li, const AVPacket *pkt)
static int filter_activate_default(AVBitStreamFilterContext *ctx)
int ff_bsf_config_links(AVBitStreamFilterContext *filter)
static int filter_packet_to_filter(AVBitStreamFilterLink *link)
static int request_packet_to_filter(AVBitStreamFilterLink *link)
int ff_bsf_filter_packet(AVBitStreamFilterLink *link, AVPacket *pkt)
Send a packet of data to the next filter.
int ff_bsf_outlink_get_status(AVBitStreamFilterLink *link)
static int bsf_opt_parse(void *logctx, const AVClass *priv_class, AVDictionary **options, const char *args)
Parse filter options into a dictionary.
void ff_bsf_link_set_in_status(AVBitStreamFilterLink *link, int status, int64_t pts)
static void filter_unblock(AVBitStreamFilterContext *filter)
Clear packet_blocked_in on all outputs.
static void link_set_out_status(AVBitStreamFilterLink *link, int status, int64_t pts)
Set the status field of a link from the destination filter.
static void * bsf_child_next(void *obj, void *prev)
static const AVClass bitstreamfilter_class
static int default_filter_packet(AVBitStreamFilterLink *link, AVPacket *pkt)
void ff_bsf_inlink_set_status(AVBitStreamFilterLink *link, int status)
static void link_free(AVBitStreamFilterLink **plink)
void ff_bsf_free(AVBitStreamFilterContext *ctx)
Free a filter context.
size_t ff_bsf_inlink_queued_packets(AVBitStreamFilterLink *link)
static int forward_status_change(AVBitStreamFilterContext *filter, BitStreamFilterLinkInternal *li_in)
int ff_bsf_request_packet(AVBitStreamFilterLink *link)
int ff_bsf_alloc(const AVBitStreamFilter *filter, const char *inst_name, AVBitStreamFilterContext **pctx)
Allocate a new filter context and return it.
int ff_bsf_activate(AVBitStreamFilterContext *ctx)
static void update_link_current_pts(BitStreamFilterLinkInternal *li, int64_t pts)
static int64_t guess_status_pts(AVBitStreamFilterContext *ctx, int status, AVRational link_time_base)
const AVBitStreamFilterPad ff_default_bsf_pad[1]
void ff_bsf_inlink_request_packet(AVBitStreamFilterLink *link)
int ff_bsf_inlink_check_available_packet(AVBitStreamFilterLink *link)
static void free_link(AVBitStreamFilterLink *link)
static BitStreamFilterLinkInternal * ff_link_internal(AVBitStreamFilterLink *link)
void ff_bsf_graph_remove_filter(AVBitStreamFilterGraph *graph, AVBitStreamFilterContext *filter)
Remove a filter from a graph;.
Definition bsfgraph.c:64
void ff_bsf_graph_update_heap(AVBitStreamFilterGraph *graph, BitStreamFilterLinkInternal *li)
Definition bsfgraph.c:353
static FFBitStreamFilterGraph * ffbsffiltergraph(AVBitStreamFilterGraph *graph)
static FFBitStreamFilterContext * ffbsfctx(AVBitStreamFilterContext *ctx)
static av_always_inline const FFBitStreamFilter * ff_bsf(const AVBitStreamFilter *bsf)
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
AVCodecParameters * avcodec_parameters_alloc(void)
Definition codec_par.c:57
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Definition codec_par.c:107
void avcodec_parameters_free(AVCodecParameters **ppar)
Definition codec_par.c:67
int av_container_fifo_write(AVContainerFifo *cf, void *obj, unsigned flags)
Write the contents of obj to the FIFO.
void av_container_fifo_free(AVContainerFifo **pcf)
Free a AVContainerFifo and everything in it.
int av_container_fifo_read(AVContainerFifo *cf, void *obj, unsigned flags)
Read the next available object from the FIFO into obj.
size_t av_container_fifo_can_read(const AVContainerFifo *cf)
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
double value
Definition eval.c:102
const char * key
#define fail
Definition test.h:479
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
enum AVCodecID * av_bsf_pad_get_codec_ids(const AVBitStreamFilterPad *pads, int pad_idx)
Get the codec ids supported by an AVBitStreamFilterPad.
int av_bsf_init_dict(AVBitStreamFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options.
int av_bsf_init_str(AVBitStreamFilterContext *ctx, const char *args)
Initialize a filter with the supplied parameters.
int av_bsf_link(AVBitStreamFilterContext *src, unsigned srcpad, AVBitStreamFilterContext *dst, unsigned dstpad)
Link two filters together.
const char * av_bsf_pad_get_name(const AVBitStreamFilterPad *pads, int pad_idx)
Get the name of an AVBitStreamFilterPad.
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition utils.c:421
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
AVContainerFifo * av_container_fifo_alloc_avpacket(unsigned flags)
Allocate an AVContainerFifo instance for AVPacket.
Definition packet.c:695
int av_packet_make_writable(AVPacket *pkt)
Create a writable reference for the data described by a given packet, avoiding data copy if possible.
Definition packet.c:516
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition packet.c:63
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
Definition dict.h:84
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:233
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition dict.c:42
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition dict.h:79
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:86
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function.
Definition dict.h:77
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition error.h:63
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition mem.c:302
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int av_opt_get_key_value(const char **ropts, const char *key_val_sep, const char *pairs_sep, unsigned flags, char **rkey, char **rval)
Extract a key-value pair from the beginning of a string.
Definition opt.c:1951
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition opt.h:604
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition opt.c:2025
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition opt.c:1754
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition opt.c:47
@ AV_OPT_FLAG_IMPLICIT_KEY
Accept to parse a value without a key; the key will then be returned as NULL.
Definition opt.h:723
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
Definition opt.c:2038
#define r
Definition input.c:42
unsigned offset
Definition libaomenc.c:763
#define FF_BSF_PAD_FLAG_NEEDS_WRITABLE
The filter expects writable packets from its input link, duplicating data buffers if needed.
Definition filters.h:56
#define FFERROR_BSF_NOT_READY
Special return code when activate() did not do anything.
Definition filters.h:32
#define FF_BSF_PAD_FLAG_FREE_NAME
The pad's name is allocated and should be freed generically.
Definition filters.h:61
@ AV_CLASS_STATE_INITIALIZED
Object initialization has finished and it is now in the 'runtime' stage.
Definition log.h:56
@ AV_CLASS_CATEGORY_BITSTREAM_FILTER
Definition log.h:37
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
An instance of a filter.
Definition bsf.h:347
AVBitStreamFilterPad * output_pads
array of output pads
Definition bsf.h:367
unsigned nb_inputs
number of input pads
Definition bsf.h:365
const struct AVBitStreamFilter * filter
The bitstream filter this context is an instance of.
Definition bsf.h:356
AVBitStreamFilterLink ** outputs
array of pointers to output links
Definition bsf.h:368
AVBitStreamFilterPad * input_pads
array of input pads
Definition bsf.h:363
char * name
name of this filter instance
Definition bsf.h:361
AVBitStreamFilterLink ** inputs
array of pointers to input links
Definition bsf.h:364
A filter pad used for either input or output.
Definition filters.h:35
const char * name
Pad name.
Definition filters.h:41
int(* config_props)(AVBitStreamFilterLink *link)
Link configuration callback.
Definition filters.h:101
enum AVCodecID * codec_ids
A list of codec ids supported by the pad, terminated by AV_CODEC_ID_NONE.
Definition filters.h:48
int(* request_packet)(AVBitStreamFilterLink *link)
Packet request callback.
Definition filters.h:87
Describe the class of an AVClass context structure.
Definition log.h:76
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
char * key
Definition dict.h:91
AVOption.
Definition opt.h:428
int offset
Native access only.
Definition opt.h:443
const char * name
Definition opt.h:429
enum AVOptionType type
Definition opt.h:444
This structure stores compressed data.
Definition packet.h:580
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
int status_out
Link output status.
int packet_blocked_in
If set, the source filter can not generate a packet as is.
int packet_wanted_out
True if a packet is currently wanted on the output of this filter.
int64_t status_in_pts
Timestamp of the input status change.
AVBitStreamFilterLink l
AVContainerFifo * fifo
Queue of packets waiting to be filtered.
enum BitStreamFilterLinkInternal::@063320061117101100004225063044155055066225214332 init_state
stage of the initialization of the link properties (dimensions, etc)
int status_in
Link input status.
int age_index
Index in the age array.
AVBitStreamFilterContext p
The public AVBitStreamFilterContext.
unsigned ready
Ready status of the filter.
uint8_t nb_inputs
The number of entries in the list of inputs.
void(* uninit)(AVBitStreamFilterContext *ctx)
int(* preinit)(AVBitStreamFilterContext *ctx)
int(* activate)(AVBitStreamFilterContext *ctx)
Filter activation function.
const struct AVBitStreamFilterPad * outputs
List of static outputs.
uint8_t nb_outputs
The number of entries in the list of outputs.
int(* init2)(AVBitStreamFilterContext *ctx)
const struct AVBitStreamFilterPad * inputs
List of static inputs.
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
#define src
Definition vp8dsp.c:248
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
static FilteringContext * filter_ctx
Definition transcode.c:52
static int64_t pts
enum AVCodecID codec_id