Allow to set the EOF timestamp.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -19,6 +19,7 @@ · 18 unmodified lines | ||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | #include "avfilter.h" |
| 22 | +#include "filters.h" | |
| 22 | 23 | #include "formats.h" |
| 23 | 24 | #include "video.h" |
| 24 | 25 | #include "internal.h" |
| @@ -247,44 +248,51 @@ static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int · 222 unmodified lines | ||
| 247 | 248 | return 0; |
| 248 | 249 | } |
| 249 | 250 | |
| 250 | −static int gradients_request_frame(AVFilterLink *outlink) | |
| 251 | +static int activate(AVFilterContext *ctx) | |
| 251 | 252 | { |
| 252 | − AVFilterContext *ctx = outlink->src; | |
| 253 | 253 | 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]; | |
| 258 | 255 | |
| 259 | 256 | 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 | + } | |
| 262 | 261 | |
| 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; | |
| 265 | 267 | |
| 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; | |
| 268 | 270 | |
| 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); | |
| 271 | 276 | |
| 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++; | |
| 277 | 282 | |
| 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 | + } | |
| 279 | 288 | |
| 280 | − return ff_filter_frame(outlink, frame); | |
| 289 | + return FFERROR_NOT_READY; | |
| 281 | 290 | } |
| 282 | 291 | |
| 283 | 292 | static const AVFilterPad gradients_outputs[] = { |
| 284 | 293 | { |
| 285 | 294 | .name = "default", |
| 286 | 295 | .type = AVMEDIA_TYPE_VIDEO, |
| 287 | − .request_frame = gradients_request_frame, | |
| 288 | 296 | .config_props = config_output, |
| 289 | 297 | }, |
| 290 | 298 | { NULL } |
| @@ -298,5 +306,6 @@ AVFilter ff_vsrc_gradients = { · 7 unmodified lines | ||
| 298 | 306 | .query_formats = query_formats, |
| 299 | 307 | .inputs = NULL, |
| 300 | 308 | .outputs = gradients_outputs, |
| 309 | + .activate = activate, | |
| 301 | 310 | .flags = AVFILTER_FLAG_SLICE_THREADS, |
| 302 | 311 | }; |