1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avfilter/af_join: switch to activate

Fixes #6780.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2017-10-27 17:59:29 +02:00
parent e6055af025
commit d0920da029

View File

@ -32,6 +32,7 @@
#include "audio.h"
#include "avfilter.h"
#include "formats.h"
#include "filters.h"
#include "internal.h"
typedef struct ChannelMap {
@ -78,34 +79,6 @@ static const AVOption join_options[] = {
AVFILTER_DEFINE_CLASS(join);
static int try_push_frame(AVFilterContext *ctx);
static int filter_frame(AVFilterLink *link, AVFrame *frame)
{
AVFilterContext *ctx = link->dst;
JoinContext *s = ctx->priv;
int i, j;
for (i = 0; i < ctx->nb_inputs; i++)
if (link == ctx->inputs[i])
break;
av_assert0(i < ctx->nb_inputs);
av_assert0(!s->input_frames[i]);
s->input_frames[i] = frame;
/* request the same number of samples on all inputs */
/* FIXME that means a frame arriving asynchronously on a different input
will not have the requested number of samples */
if (i == 0) {
int nb_samples = s->input_frames[0]->nb_samples;
for (j = 1; !i && j < ctx->nb_inputs; j++)
ctx->inputs[j]->request_samples = nb_samples;
}
return try_push_frame(ctx);
}
static int parse_maps(AVFilterContext *ctx)
{
JoinContext *s = ctx->priv;
@ -220,9 +193,6 @@ static av_cold int join_init(AVFilterContext *ctx)
pad.name = av_strdup(name);
if (!pad.name)
return AVERROR(ENOMEM);
pad.filter_frame = filter_frame;
pad.needs_fifo = 1;
if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) {
av_freep(&pad.name);
@ -390,21 +360,6 @@ fail:
return ret;
}
static int join_request_frame(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
JoinContext *s = ctx->priv;
int i;
/* get a frame on each input */
for (i = 0; i < ctx->nb_inputs; i++) {
AVFilterLink *inlink = ctx->inputs[i];
if (!s->input_frames[i])
return ff_request_frame(inlink);
}
return 0;
}
static int try_push_frame(AVFilterContext *ctx)
{
AVFilterLink *outlink = ctx->outputs[0];
@ -420,6 +375,8 @@ static int try_push_frame(AVFilterContext *ctx)
return 0;
nb_samples = FFMIN(nb_samples, s->input_frames[i]->nb_samples);
}
if (!nb_samples)
return 0;
/* setup the output frame */
frame = av_frame_alloc();
@ -508,12 +465,58 @@ fail:
return ret;
}
static int activate(AVFilterContext *ctx)
{
JoinContext *s = ctx->priv;
int i, ret, status;
int nb_samples = 0;
int64_t pts;
if (!s->input_frames[0]) {
ret = ff_inlink_consume_frame(ctx->inputs[0], &s->input_frames[0]);
if (ret < 0) {
return ret;
} else if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) {
ff_outlink_set_status(ctx->outputs[0], status, pts);
return 0;
} else {
if (ff_outlink_frame_wanted(ctx->outputs[0]) && !s->input_frames[0]) {
ff_inlink_request_frame(ctx->inputs[0]);
return 0;
}
}
}
nb_samples = s->input_frames[0]->nb_samples;
for (i = 1; i < ctx->nb_inputs && nb_samples > 0; i++) {
if (s->input_frames[i])
continue;
if (ff_inlink_check_available_samples(ctx->inputs[i], nb_samples) > 0) {
ret = ff_inlink_consume_samples(ctx->inputs[i], nb_samples, nb_samples, &s->input_frames[i]);
if (ret < 0) {
return ret;
} else if (ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts)) {
ff_outlink_set_status(ctx->outputs[0], status, pts);
return 0;
}
} else {
if (ff_outlink_frame_wanted(ctx->outputs[0])) {
ff_inlink_request_frame(ctx->inputs[i]);
return 0;
}
}
}
return try_push_frame(ctx);
}
static const AVFilterPad avfilter_af_join_outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
.config_props = join_config_output,
.request_frame = join_request_frame,
},
{ NULL }
};
@ -526,6 +529,7 @@ AVFilter ff_af_join = {
.priv_class = &join_class,
.init = join_init,
.uninit = join_uninit,
.activate = activate,
.query_formats = join_query_formats,
.inputs = NULL,
.outputs = avfilter_af_join_outputs,