Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -27,12 +27,9 @@ · 26 unmodified lines | ||
| 27 | 27 | #include "libavutil/avstring.h" |
| 28 | 28 | #include "libavutil/opt.h" |
| 29 | 29 | |
| 30 | −#define FF_INTERNAL_FIELDS 1 | |
| 31 | −#include "framequeue.h" | |
| 32 | − | |
| 33 | 30 | #include "avfilter.h" |
| 34 | −#include "bufferqueue.h" | |
| 35 | 31 | #include "formats.h" |
| 32 | +#include "filters.h" | |
| 36 | 33 | #include "internal.h" |
| 37 | 34 | #include "audio.h" |
| 38 | 35 | #include "video.h" |
| @@ -40,7 +37,7 @@ · 1 unmodified line | ||
| 40 | 37 | typedef struct InterleaveContext { |
| 41 | 38 | const AVClass *class; |
| 42 | 39 | int nb_inputs; |
| 43 | − struct FFBufQueue *queues; | |
| 40 | + int64_t pts; | |
| 44 | 41 | } InterleaveContext; |
| 45 | 42 | |
| 46 | 43 | #define OFFSET(x) offsetof(InterleaveContext, x) |
| @@ -52,58 +49,78 @@ static const AVOption filt_name##_options[] = { \ · 5 unmodified lines | ||
| 52 | 49 | { NULL } \ |
| 53 | 50 | } |
| 54 | 51 | |
| 55 | −inline static int push_frame(AVFilterContext *ctx) | |
| 52 | +static int activate(AVFilterContext *ctx) | |
| 56 | 53 | { |
| 54 | + AVFilterLink *outlink = ctx->outputs[0]; | |
| 57 | 55 | 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); | |
| 61 | 60 | |
| 62 | − /* look for oldest frame */ | |
| 63 | 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 | − 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; | |
| 73 | 91 | } |
| 74 | 92 | } |
| 75 | − } | |
| 76 | 93 | |
| 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; | |
| 80 | 97 | |
| 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; | |
| 86 | 101 | |
| 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 | + } | |
| 92 | 106 | |
| 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++; | |
| 98 | 116 | } |
| 99 | 117 | |
| 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 | + } | |
| 105 | 122 | |
| 106 | − return push_frame(ctx); | |
| 123 | + return FFERROR_NOT_READY; | |
| 107 | 124 | } |
| 108 | 125 | |
| 109 | 126 | static av_cold int init(AVFilterContext *ctx) |
| @@ -112,10 +129,6 @@ static av_cold int init(AVFilterContext *ctx) · 2 unmodified lines | ||
| 112 | 129 | const AVFilterPad *outpad = &ctx->filter->outputs[0]; |
| 113 | 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 | 132 | for (i = 0; i < s->nb_inputs; i++) { |
| 120 | 133 | AVFilterPad inpad = { 0 }; |
| 121 | 134 | |
| @@ -123,7 +136,6 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | ||
| 123 | 136 | if (!inpad.name) |
| 124 | 137 | return AVERROR(ENOMEM); |
| 125 | 138 | inpad.type = outpad->type; |
| 126 | − inpad.filter_frame = filter_frame; | |
| 127 | 139 | |
| 128 | 140 | switch (outpad->type) { |
| 129 | 141 | case AVMEDIA_TYPE_VIDEO: |
| @@ -144,14 +156,8 @@ static av_cold int init(AVFilterContext *ctx) · 14 unmodified lines | ||
| 144 | 156 | |
| 145 | 157 | static av_cold void uninit(AVFilterContext *ctx) |
| 146 | 158 | { |
| 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++) | |
| 153 | 160 | av_freep(&ctx->input_pads[i].name); |
| 154 | − } | |
| 155 | 161 | } |
| 156 | 162 | |
| 157 | 163 | static int config_output(AVFilterLink *outlink) |
| @@ -190,23 +196,6 @@ static int config_output(AVFilterLink *outlink) · 32 unmodified lines | ||
| 190 | 196 | return 0; |
| 191 | 197 | } |
| 192 | 198 | |
| 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 | − | |
| 210 | 199 | #if CONFIG_INTERLEAVE_FILTER |
| 211 | 200 | |
| 212 | 201 | 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 | ||
| 217 | 206 | .name = "default", |
| 218 | 207 | .type = AVMEDIA_TYPE_VIDEO, |
| 219 | 208 | .config_props = config_output, |
| 220 | − .request_frame = request_frame, | |
| 221 | 209 | }, |
| 222 | 210 | { NULL } |
| 223 | 211 | }; |
| @@ -228,6 +216,7 @@ AVFilter ff_vf_interleave = { · 4 unmodified lines | ||
| 228 | 216 | .priv_size = sizeof(InterleaveContext), |
| 229 | 217 | .init = init, |
| 230 | 218 | .uninit = uninit, |
| 219 | + .activate = activate, | |
| 231 | 220 | .outputs = interleave_outputs, |
| 232 | 221 | .priv_class = &interleave_class, |
| 233 | 222 | .flags = AVFILTER_FLAG_DYNAMIC_INPUTS, |
| @@ -245,7 +234,6 @@ static const AVFilterPad ainterleave_outputs[] = { · 11 unmodified lines | ||
| 245 | 234 | .name = "default", |
| 246 | 235 | .type = AVMEDIA_TYPE_AUDIO, |
| 247 | 236 | .config_props = config_output, |
| 248 | − .request_frame = request_frame, | |
| 249 | 237 | }, |
| 250 | 238 | { NULL } |
| 251 | 239 | }; |
| @@ -256,6 +244,7 @@ AVFilter ff_af_ainterleave = { · 4 unmodified lines | ||
| 256 | 244 | .priv_size = sizeof(InterleaveContext), |
| 257 | 245 | .init = init, |
| 258 | 246 | .uninit = uninit, |
| 247 | + .activate = activate, | |
| 259 | 248 | .outputs = ainterleave_outputs, |
| 260 | 249 | .priv_class = &ainterleave_class, |
| 261 | 250 | .flags = AVFILTER_FLAG_DYNAMIC_INPUTS, |