Showing the changes to libavfilter/src_buffer.c (1 of 1 file). Show all
Unified · Split
| @@ -69,11 +69,75 @@ typedef struct { · 68 unmodified lines | ||
| 69 | 69 | return AVERROR(EINVAL);\ |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | +static void buf_free(AVFilterBuffer *ptr) | |
| 73 | +{ | |
| 74 | + av_free(ptr); | |
| 75 | + return; | |
| 76 | +} | |
| 77 | + | |
| 78 | +static void set_link_source(AVFilterContext *src, AVFilterLink *link) | |
| 79 | +{ | |
| 80 | + link->src = src; | |
| 81 | + link->srcpad = &(src->output_pads[0]); | |
| 82 | + src->outputs[0] = link; | |
| 83 | +} | |
| 84 | + | |
| 85 | +static int reconfigure_filter(BufferSourceContext *abuffer, AVFilterContext *filt_ctx) | |
| 86 | +{ | |
| 87 | + int ret; | |
| 88 | + AVFilterLink * const inlink = filt_ctx->inputs[0]; | |
| 89 | + AVFilterLink * const outlink = filt_ctx->outputs[0]; | |
| 90 | + | |
| 91 | + inlink->format = abuffer->sample_format; | |
| 92 | + inlink->channel_layout = abuffer->channel_layout; | |
| 93 | + inlink->planar = abuffer->packing_format; | |
| 94 | + inlink->sample_rate = abuffer->sample_rate; | |
| 95 | + | |
| 96 | + filt_ctx->filter->uninit(filt_ctx); | |
| 97 | + memset(filt_ctx->priv, 0, filt_ctx->filter->priv_size); | |
| 98 | + if ((ret = filt_ctx->filter->init(filt_ctx, NULL , NULL)) < 0) | |
| 99 | + return ret; | |
| 100 | + if ((ret = inlink->srcpad->config_props(inlink)) < 0) | |
| 101 | + return ret; | |
| 102 | + return outlink->srcpad->config_props(outlink); | |
| 103 | +} | |
| 104 | + | |
| 72 | 105 | static int insert_filter(BufferSourceContext *abuffer, |
| 73 | 106 | AVFilterLink *link, AVFilterContext **filt_ctx, |
| 74 | − const char *filt_name); | |
| 75 | −static void remove_filter(AVFilterContext **filt_ctx); | |
| 76 | −static int reconfigure_filter(BufferSourceContext *abuffer, AVFilterContext *filt_ctx); | |
| 107 | + const char *filt_name) | |
| 108 | +{ | |
| 109 | + int ret; | |
| 110 | + | |
| 111 | + if ((ret = avfilter_open(filt_ctx, avfilter_get_by_name(filt_name), NULL)) < 0) | |
| 112 | + return ret; | |
| 113 | + | |
| 114 | + link->src->outputs[0] = NULL; | |
| 115 | + if ((ret = avfilter_link(link->src, 0, *filt_ctx, 0)) < 0) { | |
| 116 | + link->src->outputs[0] = link; | |
| 117 | + return ret; | |
| 118 | + } | |
| 119 | + | |
| 120 | + set_link_source(*filt_ctx, link); | |
| 121 | + | |
| 122 | + if ((ret = reconfigure_filter(abuffer, *filt_ctx)) < 0) { | |
| 123 | + avfilter_free(*filt_ctx); | |
| 124 | + return ret; | |
| 125 | + } | |
| 126 | + | |
| 127 | + return 0; | |
| 128 | +} | |
| 129 | + | |
| 130 | +static void remove_filter(AVFilterContext **filt_ctx) | |
| 131 | +{ | |
| 132 | + AVFilterLink *outlink = (*filt_ctx)->outputs[0]; | |
| 133 | + AVFilterContext *src = (*filt_ctx)->inputs[0]->src; | |
| 134 | + | |
| 135 | + (*filt_ctx)->outputs[0] = NULL; | |
| 136 | + avfilter_free(*filt_ctx); | |
| 137 | + *filt_ctx = NULL; | |
| 138 | + | |
| 139 | + set_link_source(src, outlink); | |
| 140 | +} | |
| 77 | 141 | |
| 78 | 142 | static inline void log_input_change(void *ctx, AVFilterLink *link, AVFilterBufferRef *ref) |
| 79 | 143 | { |
| @@ -516,76 +580,6 @@ static int poll_frame(AVFilterLink *link) · 436 unmodified lines | ||
| 516 | 580 | return size/sizeof(AVFilterBufferRef*); |
| 517 | 581 | } |
| 518 | 582 | |
| 519 | −static void buf_free(AVFilterBuffer *ptr) | |
| 520 | −{ | |
| 521 | − av_free(ptr); | |
| 522 | − return; | |
| 523 | −} | |
| 524 | − | |
| 525 | −static void set_link_source(AVFilterContext *src, AVFilterLink *link) | |
| 526 | −{ | |
| 527 | − link->src = src; | |
| 528 | − link->srcpad = &(src->output_pads[0]); | |
| 529 | − src->outputs[0] = link; | |
| 530 | −} | |
| 531 | − | |
| 532 | −static int reconfigure_filter(BufferSourceContext *abuffer, AVFilterContext *filt_ctx) | |
| 533 | −{ | |
| 534 | − int ret; | |
| 535 | − AVFilterLink * const inlink = filt_ctx->inputs[0]; | |
| 536 | − AVFilterLink * const outlink = filt_ctx->outputs[0]; | |
| 537 | − | |
| 538 | − inlink->format = abuffer->sample_format; | |
| 539 | − inlink->channel_layout = abuffer->channel_layout; | |
| 540 | − inlink->planar = abuffer->packing_format; | |
| 541 | − inlink->sample_rate = abuffer->sample_rate; | |
| 542 | − | |
| 543 | − filt_ctx->filter->uninit(filt_ctx); | |
| 544 | − memset(filt_ctx->priv, 0, filt_ctx->filter->priv_size); | |
| 545 | − if ((ret = filt_ctx->filter->init(filt_ctx, NULL , NULL)) < 0) | |
| 546 | − return ret; | |
| 547 | − if ((ret = inlink->srcpad->config_props(inlink)) < 0) | |
| 548 | − return ret; | |
| 549 | − return outlink->srcpad->config_props(outlink); | |
| 550 | −} | |
| 551 | − | |
| 552 | −static int insert_filter(BufferSourceContext *abuffer, | |
| 553 | − AVFilterLink *link, AVFilterContext **filt_ctx, | |
| 554 | − const char *filt_name) | |
| 555 | −{ | |
| 556 | − int ret; | |
| 557 | − | |
| 558 | − if ((ret = avfilter_open(filt_ctx, avfilter_get_by_name(filt_name), NULL)) < 0) | |
| 559 | − return ret; | |
| 560 | − | |
| 561 | − link->src->outputs[0] = NULL; | |
| 562 | − if ((ret = avfilter_link(link->src, 0, *filt_ctx, 0)) < 0) { | |
| 563 | − link->src->outputs[0] = link; | |
| 564 | − return ret; | |
| 565 | − } | |
| 566 | − | |
| 567 | − set_link_source(*filt_ctx, link); | |
| 568 | − | |
| 569 | − if ((ret = reconfigure_filter(abuffer, *filt_ctx)) < 0) { | |
| 570 | − avfilter_free(*filt_ctx); | |
| 571 | − return ret; | |
| 572 | − } | |
| 573 | − | |
| 574 | − return 0; | |
| 575 | −} | |
| 576 | − | |
| 577 | −static void remove_filter(AVFilterContext **filt_ctx) | |
| 578 | −{ | |
| 579 | − AVFilterLink *outlink = (*filt_ctx)->outputs[0]; | |
| 580 | − AVFilterContext *src = (*filt_ctx)->inputs[0]->src; | |
| 581 | − | |
| 582 | − (*filt_ctx)->outputs[0] = NULL; | |
| 583 | − avfilter_free(*filt_ctx); | |
| 584 | − *filt_ctx = NULL; | |
| 585 | − | |
| 586 | − set_link_source(src, outlink); | |
| 587 | −} | |
| 588 | − | |
| 589 | 583 | int av_asrc_buffer_add_audio_buffer_ref(AVFilterContext *ctx, |
| 590 | 584 | AVFilterBufferRef *samplesref, |
| 591 | 585 | int av_unused flags) |