History

avfilter/vsrc_gradients: switch to activate

Allow to set the EOF timestamp.

Paul B Mahol committed 6 years ago

Commit 9f5f9711 parent e8819d81 file · +31 −22Browse files

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

Unified · Split

libavfilter/vsrc_gradients.c+31−22
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 */
2020
2121 #include "avfilter.h"
22+#include "filters.h"
2223 #include "formats.h"
2324 #include "video.h"
2425 #include "internal.h"
@@ -247,44 +248,51 @@ static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int · 222 unmodified lines
247248 return 0;
248249 }
249250
250−static int gradients_request_frame(AVFilterLink *outlink)
251+static int activate(AVFilterContext *ctx)
251252 {
252− AVFilterContext *ctx = outlink->src;
253253 GradientsContext *s = ctx->priv;
254− AVFrame *frame = ff_get_video_buffer(outlink, s->w, s->h);
255− float angle = fmodf(s->pts * s->speed, 2.f * M_PI);
256− const float w2 = s->w / 2.f;
257− const float h2 = s->h / 2.f;
254+ AVFilterLink *outlink = ctx->outputs[0];
258255
259256 if (s->duration >= 0 &&
260− av_rescale_q(s->pts, outlink->time_base, AV_TIME_BASE_Q) >= s->duration)
261− return AVERROR_EOF;
257+ av_rescale_q(s->pts, outlink->time_base, AV_TIME_BASE_Q) >= s->duration) {
258+ ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
259+ return 0;
260+ }
262261
263− s->fx0 = (s->x0 - w2) * cosf(angle) - (s->y0 - h2) * sinf(angle) + w2;
264− s->fy0 = (s->x0 - w2) * sinf(angle) + (s->y0 - h2) * cosf(angle) + h2;
262+ if (ff_outlink_frame_wanted(outlink)) {
263+ AVFrame *frame = ff_get_video_buffer(outlink, s->w, s->h);
264+ float angle = fmodf(s->pts * s->speed, 2.f * M_PI);
265+ const float w2 = s->w / 2.f;
266+ const float h2 = s->h / 2.f;
265267
266− s->fx1 = (s->x1 - w2) * cosf(angle) - (s->y1 - h2) * sinf(angle) + w2;
267− s->fy1 = (s->x1 - w2) * sinf(angle) + (s->y1 - h2) * cosf(angle) + h2;
268+ s->fx0 = (s->x0 - w2) * cosf(angle) - (s->y0 - h2) * sinf(angle) + w2;
269+ s->fy0 = (s->x0 - w2) * sinf(angle) + (s->y0 - h2) * cosf(angle) + h2;
268270
269− if (!frame)
270− return AVERROR(ENOMEM);
271+ s->fx1 = (s->x1 - w2) * cosf(angle) - (s->y1 - h2) * sinf(angle) + w2;
272+ s->fy1 = (s->x1 - w2) * sinf(angle) + (s->y1 - h2) * cosf(angle) + h2;
273+
274+ if (!frame)
275+ return AVERROR(ENOMEM);
271276
272− frame->key_frame = 1;
273− frame->interlaced_frame = 0;
274− frame->pict_type = AV_PICTURE_TYPE_I;
275− frame->sample_aspect_ratio = (AVRational) {1, 1};
276− frame->pts = s->pts++;
277+ frame->key_frame = 1;
278+ frame->interlaced_frame = 0;
279+ frame->pict_type = AV_PICTURE_TYPE_I;
280+ frame->sample_aspect_ratio = (AVRational) {1, 1};
281+ frame->pts = s->pts++;
277282
278− ctx->internal->execute(ctx, s->draw_slice, frame, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
283+ ctx->internal->execute(ctx, s->draw_slice, frame, NULL,
284+ FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
285+
286+ return ff_filter_frame(outlink, frame);
287+ }
279288
280− return ff_filter_frame(outlink, frame);
289+ return FFERROR_NOT_READY;
281290 }
282291
283292 static const AVFilterPad gradients_outputs[] = {
284293 {
285294 .name = "default",
286295 .type = AVMEDIA_TYPE_VIDEO,
287− .request_frame = gradients_request_frame,
288296 .config_props = config_output,
289297 },
290298 { NULL }
@@ -298,5 +306,6 @@ AVFilter ff_vsrc_gradients = { · 7 unmodified lines
298306 .query_formats = query_formats,
299307 .inputs = NULL,
300308 .outputs = gradients_outputs,
309+ .activate = activate,
301310 .flags = AVFILTER_FLAG_SLICE_THREADS,
302311 };

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