History

avfilter/f_select: port to activate

Multi-input or multi-output filters should use activate now.

Marton Balint committed 1 year ago

Commit af189e41 parent 223c2b01 file · +26 −19Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/f_select.c+26−19
@@ -179,8 +179,6 @@ static const AVOption filt_name##_options[] = { \ · 178 unmodified lines
179179 { NULL } \
180180 }
181181
182−static int request_frame(AVFilterLink *outlink);
183−
184182 static av_cold int init(AVFilterContext *ctx)
185183 {
186184 SelectContext *select = ctx->priv;
@@ -201,7 +199,6 @@ static av_cold int init(AVFilterContext *ctx) · 14 unmodified lines
201199 if (!pad.name)
202200 return AVERROR(ENOMEM);
203201 pad.type = ctx->filter->inputs[0].type;
204− pad.request_frame = request_frame;
205202 if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
206203 return ret;
207204 }
@@ -349,7 +346,7 @@ static void select_frame(AVFilterContext *ctx, AVFrame *frame) · 141 unmodified lines
349346 if (isnan(select->var_values[VAR_START_T]))
350347 select->var_values[VAR_START_T] = TS2D(frame->pts) * av_q2d(inlink->time_base);
351348
352− select->var_values[VAR_N ] = inl->frame_count_out;
349+ select->var_values[VAR_N ] = inl->frame_count_out - 1;
353350 select->var_values[VAR_PTS] = TS2D(frame->pts);
354351 select->var_values[VAR_T ] = TS2D(frame->pts) * av_q2d(inlink->time_base);
355352 select->var_values[VAR_KEY] = !!(frame->flags & AV_FRAME_FLAG_KEY);
@@ -428,24 +425,35 @@ static void select_frame(AVFilterContext *ctx, AVFrame *frame) · 72 unmodified lines
428425 select->var_values[VAR_PREV_T] = select->var_values[VAR_T];
429426 }
430427
431−static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
428+static int activate(AVFilterContext *ctx)
432429 {
433− AVFilterContext *ctx = inlink->dst;
434430 SelectContext *select = ctx->priv;
431+ AVFilterLink *inlink = ctx->inputs[0];
432+ AVFrame *in;
433+ int nb_eofs = 0;
434+ int ret;
435435
436− select_frame(ctx, frame);
437− if (select->select)
438− return ff_filter_frame(ctx->outputs[select->select_out], frame);
436+ for (int i = 0; i < ctx->nb_outputs; i++)
437+ nb_eofs += ff_outlink_get_status(ctx->outputs[i]) == AVERROR_EOF;
439438
440− av_frame_free(&frame);
441− return 0;
442−}
439+ if (nb_eofs == ctx->nb_outputs) {
440+ ff_inlink_set_status(inlink, AVERROR_EOF);
441+ return 0;
442+ }
443443
444−static int request_frame(AVFilterLink *outlink)
445−{
446− AVFilterLink *inlink = outlink->src->inputs[0];
447− int ret = ff_request_frame(inlink);
448− return ret;
444+ while ((ret = ff_inlink_consume_frame(inlink, &in))) {
445+ if (ret < 0)
446+ return ret;
447+ select_frame(ctx, in);
448+ if (select->select && !ff_outlink_get_status(ctx->outputs[select->select_out]))
449+ return ff_filter_frame(ctx->outputs[select->select_out], in);
450+ av_frame_free(&in);
451+ };
452+
453+ FF_FILTER_FORWARD_STATUS_ALL(inlink, ctx);
454+ FF_FILTER_FORWARD_WANTED_ANY(ctx, inlink);
455+
456+ return FFERROR_NOT_READY;
449457 }
450458
451459 static av_cold void uninit(AVFilterContext *ctx)
@@ -486,7 +494,6 @@ static const AVFilterPad avfilter_af_aselect_inputs[] = { · 34 unmodified lines
486494 .name = "default",
487495 .type = AVMEDIA_TYPE_AUDIO,
488496 .config_props = config_input,
489− .filter_frame = filter_frame,
490497 },
491498 };
492499
@@ -542,7 +549,6 @@ static const AVFilterPad avfilter_vf_select_inputs[] = { · 49 unmodified lines
542549 .name = "default",
543550 .type = AVMEDIA_TYPE_VIDEO,
544551 .config_props = config_input,
545− .filter_frame = filter_frame,
546552 },
547553 };
548554
@@ -553,6 +559,7 @@ const FFFilter ff_vf_select = { · 4 unmodified lines
553559 .p.flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS | AVFILTER_FLAG_METADATA_ONLY,
554560 .init = select_init,
555561 .uninit = uninit,
562+ .activate = activate,
556563 .priv_size = sizeof(SelectContext),
557564 FILTER_INPUTS(avfilter_vf_select_inputs),
558565 FILTER_QUERY_FUNC2(query_formats),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t