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
27#include "libavutil/avstring.h"27#include "libavutil/avstring.h"
28#include "libavutil/opt.h"28#include "libavutil/opt.h"
29 29
30#define FF_INTERNAL_FIELDS 1
31#include "framequeue.h"
32
33#include "avfilter.h"30#include "avfilter.h"
34#include "bufferqueue.h"
35#include "formats.h"31#include "formats.h"
32#include "filters.h"
36#include "internal.h"33#include "internal.h"
37#include "audio.h"34#include "audio.h"
38#include "video.h"35#include "video.h"
@@ -40,7 +37,7 @@ · 1 unmodified line
40typedef struct InterleaveContext {37typedef struct InterleaveContext {
41 const AVClass *class;38 const AVClass *class;
42 int nb_inputs;39 int nb_inputs;
43 struct FFBufQueue *queues;40 int64_t pts;
44} InterleaveContext;41} InterleaveContext;
45 42
46#define OFFSET(x) offsetof(InterleaveContext, x)43#define OFFSET(x) offsetof(InterleaveContext, x)
@@ -52,58 +49,78 @@ static const AVOption filt_name##_options[] = { \ · 5 unmodified lines
52 { NULL } \49 { NULL } \
53}50}
54 51
55inline static int push_frame(AVFilterContext *ctx)52static int activate(AVFilterContext *ctx)
56{53{
54 AVFilterLink *outlink = ctx->outputs[0];
57 InterleaveContext *s = ctx->priv;55 InterleaveContext *s = ctx->priv;
58 AVFrame *frame;56 int64_t q_pts, pts = INT64_MAX;
59 int i, queue_idx = -1;57 int i, nb_eofs = 0, input_idx = -1;
60 int64_t pts_min = INT64_MAX;58
59 FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);
61 60
62 /* look for oldest frame */
63 for (i = 0; i < ctx->nb_inputs; i++) {61 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 }
65 66
66 if (!q->available && !ctx->inputs[i]->status_out)67 if (i == ctx->nb_inputs) {
67 return 0;68 for (i = 0; i < ctx->nb_inputs; i++) {
68 if (q->available) {69 AVFrame *frame;
69 frame = ff_bufqueue_peek(q, 0);70
70 if (frame->pts < pts_min) {71 if (ff_outlink_get_status(ctx->inputs[i]))
71 pts_min = frame->pts;72 continue;
72 queue_idx = i;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;
73 }91 }
74 }92 }
75 }
76 93
77 /* all inputs are closed */94 if (input_idx >= 0) {
78 if (queue_idx < 0)95 AVFrame *frame;
79 return AVERROR_EOF;96 int ret;
80 97
81 frame = ff_bufqueue_get(&s->queues[queue_idx]);98 ret = ff_inlink_consume_frame(ctx->inputs[input_idx], &frame);
82 av_log(ctx, AV_LOG_DEBUG, "queue:%d -> frame time:%f\n",99 if (ret < 0)
83 queue_idx, frame->pts * av_q2d(AV_TIME_BASE_Q));100 return ret;
84 return ff_filter_frame(ctx->outputs[0], frame);
85}
86 101
87static int filter_frame(AVFilterLink *inlink, AVFrame *frame)102 frame->pts = s->pts = pts;
88{103 return ff_filter_frame(outlink, frame);
89 AVFilterContext *ctx = inlink->dst;104 }
90 InterleaveContext *s = ctx->priv;105 }
91 unsigned in_no = FF_INLINK_IDX(inlink);
92 106
93 if (frame->pts == AV_NOPTS_VALUE) {107 for (i = 0; i < ctx->nb_inputs; i++) {
94 av_log(ctx, AV_LOG_WARNING,108 if (ff_inlink_queued_frames(ctx->inputs[i]))
95 "NOPTS value for input frame cannot be accepted, frame discarded\n");109 continue;
96 av_frame_free(&frame);110 if (ff_outlink_frame_wanted(outlink) &&
97 return AVERROR_INVALIDDATA;111 !ff_outlink_get_status(ctx->inputs[i])) {
112 ff_inlink_request_frame(ctx->inputs[i]);
113 return 0;
114 }
115 nb_eofs++;
98 }116 }
99 117
100 /* queue frame */118 if (nb_eofs == ctx->nb_inputs) {
101 frame->pts = av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q);119 ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
102 av_log(ctx, AV_LOG_DEBUG, "frame pts:%f -> queue idx:%d available:%d\n",120 return 0;
103 frame->pts * av_q2d(AV_TIME_BASE_Q), in_no, s->queues[in_no].available);121 }
104 ff_bufqueue_add(ctx, &s->queues[in_no], frame);
105 122
106 return push_frame(ctx);123 return FFERROR_NOT_READY;
107}124}
108 125
109static av_cold int init(AVFilterContext *ctx)126static av_cold int init(AVFilterContext *ctx)
@@ -112,10 +129,6 @@ static av_cold int init(AVFilterContext *ctx) · 2 unmodified lines
112 const AVFilterPad *outpad = &ctx->filter->outputs[0];129 const AVFilterPad *outpad = &ctx->filter->outputs[0];
113 int i, ret;130 int i, ret;
114 131
115 s->queues = av_calloc(s->nb_inputs, sizeof(s->queues[0]));
116 if (!s->queues)
117 return AVERROR(ENOMEM);
118
119 for (i = 0; i < s->nb_inputs; i++) {132 for (i = 0; i < s->nb_inputs; i++) {
120 AVFilterPad inpad = { 0 };133 AVFilterPad inpad = { 0 };
121 134
@@ -123,7 +136,6 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line
123 if (!inpad.name)136 if (!inpad.name)
124 return AVERROR(ENOMEM);137 return AVERROR(ENOMEM);
125 inpad.type = outpad->type;138 inpad.type = outpad->type;
126 inpad.filter_frame = filter_frame;
127 139
128 switch (outpad->type) {140 switch (outpad->type) {
129 case AVMEDIA_TYPE_VIDEO:141 case AVMEDIA_TYPE_VIDEO:
@@ -144,14 +156,8 @@ static av_cold int init(AVFilterContext *ctx) · 14 unmodified lines
144 156
145static av_cold void uninit(AVFilterContext *ctx)157static av_cold void uninit(AVFilterContext *ctx)
146{158{
147 InterleaveContext *s = ctx->priv;159 for (int i = 0; i < ctx->nb_inputs; i++)
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]);
153 av_freep(&ctx->input_pads[i].name);160 av_freep(&ctx->input_pads[i].name);
154 }
155}161}
156 162
157static int config_output(AVFilterLink *outlink)163static int config_output(AVFilterLink *outlink)
@@ -190,23 +196,6 @@ static int config_output(AVFilterLink *outlink) · 32 unmodified lines
190 return 0;196 return 0;
191}197}
192 198
193static 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
210#if CONFIG_INTERLEAVE_FILTER199#if CONFIG_INTERLEAVE_FILTER
211 200
212DEFINE_OPTIONS(interleave, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM);201DEFINE_OPTIONS(interleave, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM);
@@ -217,7 +206,6 @@ static const AVFilterPad interleave_outputs[] = { · 4 unmodified lines
217 .name = "default",206 .name = "default",
218 .type = AVMEDIA_TYPE_VIDEO,207 .type = AVMEDIA_TYPE_VIDEO,
219 .config_props = config_output,208 .config_props = config_output,
220 .request_frame = request_frame,
221 },209 },
222 { NULL }210 { NULL }
223};211};
@@ -228,6 +216,7 @@ AVFilter ff_vf_interleave = { · 4 unmodified lines
228 .priv_size = sizeof(InterleaveContext),216 .priv_size = sizeof(InterleaveContext),
229 .init = init,217 .init = init,
230 .uninit = uninit,218 .uninit = uninit,
219 .activate = activate,
231 .outputs = interleave_outputs,220 .outputs = interleave_outputs,
232 .priv_class = &interleave_class,221 .priv_class = &interleave_class,
233 .flags = AVFILTER_FLAG_DYNAMIC_INPUTS,222 .flags = AVFILTER_FLAG_DYNAMIC_INPUTS,
@@ -245,7 +234,6 @@ static const AVFilterPad ainterleave_outputs[] = { · 11 unmodified lines
245 .name = "default",234 .name = "default",
246 .type = AVMEDIA_TYPE_AUDIO,235 .type = AVMEDIA_TYPE_AUDIO,
247 .config_props = config_output,236 .config_props = config_output,
248 .request_frame = request_frame,
249 },237 },
250 { NULL }238 { NULL }
251};239};
@@ -256,6 +244,7 @@ AVFilter ff_af_ainterleave = { · 4 unmodified lines
256 .priv_size = sizeof(InterleaveContext),244 .priv_size = sizeof(InterleaveContext),
257 .init = init,245 .init = init,
258 .uninit = uninit,246 .uninit = uninit,
247 .activate = activate,
259 .outputs = ainterleave_outputs,248 .outputs = ainterleave_outputs,
260 .priv_class = &ainterleave_class,249 .priv_class = &ainterleave_class,
261 .flags = AVFILTER_FLAG_DYNAMIC_INPUTS,250 .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