History

avfilter/f_interleave: switch to activate

Paul B Mahol committed 7 years ago

Commit 73f234f1 parent fcc01ba1 file · +63 −74Browse files

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

Unified · Split

libavfilter/f_interleave.c+63−74
@@ -27,12 +27,9 @@ · 26 unmodified lines
2727 #include "libavutil/avstring.h"
2828 #include "libavutil/opt.h"
2929
30−#define FF_INTERNAL_FIELDS 1
31−#include "framequeue.h"
32−
3330 #include "avfilter.h"
34−#include "bufferqueue.h"
3531 #include "formats.h"
32+#include "filters.h"
3633 #include "internal.h"
3734 #include "audio.h"
3835 #include "video.h"
@@ -40,7 +37,7 @@ · 1 unmodified line
4037 typedef struct InterleaveContext {
4138 const AVClass *class;
4239 int nb_inputs;
43− struct FFBufQueue *queues;
40+ int64_t pts;
4441 } InterleaveContext;
4542
4643 #define OFFSET(x) offsetof(InterleaveContext, x)
@@ -52,58 +49,78 @@ static const AVOption filt_name##_options[] = { \ · 5 unmodified lines
5249 { NULL } \
5350 }
5451
55−inline static int push_frame(AVFilterContext *ctx)
52+static int activate(AVFilterContext *ctx)
5653 {
54+ AVFilterLink *outlink = ctx->outputs[0];
5755 InterleaveContext *s = ctx->priv;
58− AVFrame *frame;
59− int i, queue_idx = -1;
60− int64_t pts_min = INT64_MAX;
56+ int64_t q_pts, pts = INT64_MAX;
57+ int i, nb_eofs = 0, input_idx = -1;
58+
59+ FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);
6160
62− /* look for oldest frame */
6361 for (i = 0; i < ctx->nb_inputs; i++) {
64− struct FFBufQueue *q = &s->queues[i];
62+ if (!ff_outlink_get_status(ctx->inputs[i]) &&
63+ !ff_inlink_queued_frames(ctx->inputs[i]))
64+ break;
65+ }
6566
66− if (!q->available && !ctx->inputs[i]->status_out)
67− return 0;
68− if (q->available) {
69− frame = ff_bufqueue_peek(q, 0);
70− if (frame->pts < pts_min) {
71− pts_min = frame->pts;
72− queue_idx = i;
67+ if (i == ctx->nb_inputs) {
68+ for (i = 0; i < ctx->nb_inputs; i++) {
69+ AVFrame *frame;
70+
71+ if (ff_outlink_get_status(ctx->inputs[i]))
72+ continue;
73+
74+ frame = ff_inlink_peek_frame(ctx->inputs[i], 0);
75+ if (frame->pts == AV_NOPTS_VALUE) {
76+ int ret;
77+
78+ av_log(ctx, AV_LOG_WARNING,
79+ "NOPTS value for input frame cannot be accepted, frame discarded\n");
80+ ret = ff_inlink_consume_frame(ctx->inputs[i], &frame);
81+ if (ret < 0)
82+ return ret;
83+ av_frame_free(&frame);
84+ return AVERROR_INVALIDDATA;
85+ }
86+
87+ q_pts = av_rescale_q(frame->pts, ctx->inputs[i]->time_base, AV_TIME_BASE_Q);
88+ if (q_pts < pts) {
89+ pts = q_pts;
90+ input_idx = i;
7391 }
7492 }
75− }
7693
77− /* all inputs are closed */
78− if (queue_idx < 0)
79− return AVERROR_EOF;
94+ if (input_idx >= 0) {
95+ AVFrame *frame;
96+ int ret;
8097
81− frame = ff_bufqueue_get(&s->queues[queue_idx]);
82− av_log(ctx, AV_LOG_DEBUG, "queue:%d -> frame time:%f\n",
83− queue_idx, frame->pts * av_q2d(AV_TIME_BASE_Q));
84− return ff_filter_frame(ctx->outputs[0], frame);
85−}
98+ ret = ff_inlink_consume_frame(ctx->inputs[input_idx], &frame);
99+ if (ret < 0)
100+ return ret;
86101
87−static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
88−{
89− AVFilterContext *ctx = inlink->dst;
90− InterleaveContext *s = ctx->priv;
91− unsigned in_no = FF_INLINK_IDX(inlink);
102+ frame->pts = s->pts = pts;
103+ return ff_filter_frame(outlink, frame);
104+ }
105+ }
92106
93− if (frame->pts == AV_NOPTS_VALUE) {
94− av_log(ctx, AV_LOG_WARNING,
95− "NOPTS value for input frame cannot be accepted, frame discarded\n");
96− av_frame_free(&frame);
97− return AVERROR_INVALIDDATA;
107+ for (i = 0; i < ctx->nb_inputs; i++) {
108+ if (ff_inlink_queued_frames(ctx->inputs[i]))
109+ continue;
110+ if (ff_outlink_frame_wanted(outlink) &&
111+ !ff_outlink_get_status(ctx->inputs[i])) {
112+ ff_inlink_request_frame(ctx->inputs[i]);
113+ return 0;
114+ }
115+ nb_eofs++;
98116 }
99117
100− /* queue frame */
101− frame->pts = av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q);
102− av_log(ctx, AV_LOG_DEBUG, "frame pts:%f -> queue idx:%d available:%d\n",
103− frame->pts * av_q2d(AV_TIME_BASE_Q), in_no, s->queues[in_no].available);
104− ff_bufqueue_add(ctx, &s->queues[in_no], frame);
118+ if (nb_eofs == ctx->nb_inputs) {
119+ ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
120+ return 0;
121+ }
105122
106− return push_frame(ctx);
123+ return FFERROR_NOT_READY;
107124 }
108125
109126 static av_cold int init(AVFilterContext *ctx)
@@ -112,10 +129,6 @@ static av_cold int init(AVFilterContext *ctx) · 2 unmodified lines
112129 const AVFilterPad *outpad = &ctx->filter->outputs[0];
113130 int i, ret;
114131
115− s->queues = av_calloc(s->nb_inputs, sizeof(s->queues[0]));
116− if (!s->queues)
117− return AVERROR(ENOMEM);
118−
119132 for (i = 0; i < s->nb_inputs; i++) {
120133 AVFilterPad inpad = { 0 };
121134
@@ -123,7 +136,6 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line
123136 if (!inpad.name)
124137 return AVERROR(ENOMEM);
125138 inpad.type = outpad->type;
126− inpad.filter_frame = filter_frame;
127139
128140 switch (outpad->type) {
129141 case AVMEDIA_TYPE_VIDEO:
@@ -144,14 +156,8 @@ static av_cold int init(AVFilterContext *ctx) · 14 unmodified lines
144156
145157 static av_cold void uninit(AVFilterContext *ctx)
146158 {
147− InterleaveContext *s = ctx->priv;
148− int i;
149−
150− for (i = 0; i < ctx->nb_inputs; i++) {
151− ff_bufqueue_discard_all(&s->queues[i]);
152− av_freep(&s->queues[i]);
159+ for (int i = 0; i < ctx->nb_inputs; i++)
153160 av_freep(&ctx->input_pads[i].name);
154− }
155161 }
156162
157163 static int config_output(AVFilterLink *outlink)
@@ -190,23 +196,6 @@ static int config_output(AVFilterLink *outlink) · 32 unmodified lines
190196 return 0;
191197 }
192198
193−static int request_frame(AVFilterLink *outlink)
194−{
195− AVFilterContext *ctx = outlink->src;
196− InterleaveContext *s = ctx->priv;
197− int i, ret;
198−
199− for (i = 0; i < ctx->nb_inputs; i++) {
200− if (!s->queues[i].available && !ctx->inputs[i]->status_out) {
201− ret = ff_request_frame(ctx->inputs[i]);
202− if (ret != AVERROR_EOF)
203− return ret;
204− }
205− }
206−
207− return push_frame(ctx);
208−}
209−
210199 #if CONFIG_INTERLEAVE_FILTER
211200
212201 DEFINE_OPTIONS(interleave, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM);
@@ -217,7 +206,6 @@ static const AVFilterPad interleave_outputs[] = { · 4 unmodified lines
217206 .name = "default",
218207 .type = AVMEDIA_TYPE_VIDEO,
219208 .config_props = config_output,
220− .request_frame = request_frame,
221209 },
222210 { NULL }
223211 };
@@ -228,6 +216,7 @@ AVFilter ff_vf_interleave = { · 4 unmodified lines
228216 .priv_size = sizeof(InterleaveContext),
229217 .init = init,
230218 .uninit = uninit,
219+ .activate = activate,
231220 .outputs = interleave_outputs,
232221 .priv_class = &interleave_class,
233222 .flags = AVFILTER_FLAG_DYNAMIC_INPUTS,
@@ -245,7 +234,6 @@ static const AVFilterPad ainterleave_outputs[] = { · 11 unmodified lines
245234 .name = "default",
246235 .type = AVMEDIA_TYPE_AUDIO,
247236 .config_props = config_output,
248− .request_frame = request_frame,
249237 },
250238 { NULL }
251239 };
@@ -256,6 +244,7 @@ AVFilter ff_af_ainterleave = { · 4 unmodified lines
256244 .priv_size = sizeof(InterleaveContext),
257245 .init = init,
258246 .uninit = uninit,
247+ .activate = activate,
259248 .outputs = ainterleave_outputs,
260249 .priv_class = &ainterleave_class,
261250 .flags = AVFILTER_FLAG_DYNAMIC_INPUTS,

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