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

Unified · Split

libavfilter/f_select.c+26−19
@@ -179,8 +179,6 @@ static const AVOption filt_name##_options[] = { \ · 178 unmodified lines
179 { NULL } \179 { NULL } \
180}180}
181 181
182static int request_frame(AVFilterLink *outlink);
183
184static av_cold int init(AVFilterContext *ctx)182static av_cold int init(AVFilterContext *ctx)
185{183{
186 SelectContext *select = ctx->priv;184 SelectContext *select = ctx->priv;
@@ -201,7 +199,6 @@ static av_cold int init(AVFilterContext *ctx) · 14 unmodified lines
201 if (!pad.name)199 if (!pad.name)
202 return AVERROR(ENOMEM);200 return AVERROR(ENOMEM);
203 pad.type = ctx->filter->inputs[0].type;201 pad.type = ctx->filter->inputs[0].type;
204 pad.request_frame = request_frame;
205 if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)202 if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
206 return ret;203 return ret;
207 }204 }
@@ -349,7 +346,7 @@ static void select_frame(AVFilterContext *ctx, AVFrame *frame) · 141 unmodified lines
349 if (isnan(select->var_values[VAR_START_T]))346 if (isnan(select->var_values[VAR_START_T]))
350 select->var_values[VAR_START_T] = TS2D(frame->pts) * av_q2d(inlink->time_base);347 select->var_values[VAR_START_T] = TS2D(frame->pts) * av_q2d(inlink->time_base);
351 348
352 select->var_values[VAR_N ] = inl->frame_count_out;349 select->var_values[VAR_N ] = inl->frame_count_out - 1;
353 select->var_values[VAR_PTS] = TS2D(frame->pts);350 select->var_values[VAR_PTS] = TS2D(frame->pts);
354 select->var_values[VAR_T ] = TS2D(frame->pts) * av_q2d(inlink->time_base);351 select->var_values[VAR_T ] = TS2D(frame->pts) * av_q2d(inlink->time_base);
355 select->var_values[VAR_KEY] = !!(frame->flags & AV_FRAME_FLAG_KEY);352 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
428 select->var_values[VAR_PREV_T] = select->var_values[VAR_T];425 select->var_values[VAR_PREV_T] = select->var_values[VAR_T];
429}426}
430 427
431static int filter_frame(AVFilterLink *inlink, AVFrame *frame)428static int activate(AVFilterContext *ctx)
432{429{
433 AVFilterContext *ctx = inlink->dst;
434 SelectContext *select = ctx->priv;430 SelectContext *select = ctx->priv;
431 AVFilterLink *inlink = ctx->inputs[0];
432 AVFrame *in;
433 int nb_eofs = 0;
434 int ret;
435 435
436 select_frame(ctx, frame);436 for (int i = 0; i < ctx->nb_outputs; i++)
437 if (select->select)437 nb_eofs += ff_outlink_get_status(ctx->outputs[i]) == AVERROR_EOF;
438 return ff_filter_frame(ctx->outputs[select->select_out], frame);
439 438
440 av_frame_free(&frame);439 if (nb_eofs == ctx->nb_outputs) {
441 return 0;440 ff_inlink_set_status(inlink, AVERROR_EOF);
442}441 return 0;
442 }
443 443
444static int request_frame(AVFilterLink *outlink)444 while ((ret = ff_inlink_consume_frame(inlink, &in))) {
445{445 if (ret < 0)
446 AVFilterLink *inlink = outlink->src->inputs[0];446 return ret;
447 int ret = ff_request_frame(inlink);447 select_frame(ctx, in);
448 return ret;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;
449}457}
450 458
451static av_cold void uninit(AVFilterContext *ctx)459static av_cold void uninit(AVFilterContext *ctx)
@@ -486,7 +494,6 @@ static const AVFilterPad avfilter_af_aselect_inputs[] = { · 34 unmodified lines
486 .name = "default",494 .name = "default",
487 .type = AVMEDIA_TYPE_AUDIO,495 .type = AVMEDIA_TYPE_AUDIO,
488 .config_props = config_input,496 .config_props = config_input,
489 .filter_frame = filter_frame,
490 },497 },
491};498};
492 499
@@ -542,7 +549,6 @@ static const AVFilterPad avfilter_vf_select_inputs[] = { · 49 unmodified lines
542 .name = "default",549 .name = "default",
543 .type = AVMEDIA_TYPE_VIDEO,550 .type = AVMEDIA_TYPE_VIDEO,
544 .config_props = config_input,551 .config_props = config_input,
545 .filter_frame = filter_frame,
546 },552 },
547};553};
548 554
@@ -553,6 +559,7 @@ const FFFilter ff_vf_select = { · 4 unmodified lines
553 .p.flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS | AVFILTER_FLAG_METADATA_ONLY,559 .p.flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS | AVFILTER_FLAG_METADATA_ONLY,
554 .init = select_init,560 .init = select_init,
555 .uninit = uninit,561 .uninit = uninit,
562 .activate = activate,
556 .priv_size = sizeof(SelectContext),563 .priv_size = sizeof(SelectContext),
557 FILTER_INPUTS(avfilter_vf_select_inputs),564 FILTER_INPUTS(avfilter_vf_select_inputs),
558 FILTER_QUERY_FUNC2(query_formats),565 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