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

Unified · Split

libavfilter/vsrc_gradients.c+31−22
@@ -19,6 +19,7 @@ · 18 unmodified lines
19 */19 */
20 20
21#include "avfilter.h"21#include "avfilter.h"
22#include "filters.h"
22#include "formats.h"23#include "formats.h"
23#include "video.h"24#include "video.h"
24#include "internal.h"25#include "internal.h"
@@ -247,44 +248,51 @@ static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int · 222 unmodified lines
247 return 0;248 return 0;
248}249}
249 250
250static int gradients_request_frame(AVFilterLink *outlink)251static int activate(AVFilterContext *ctx)
251{252{
252 AVFilterContext *ctx = outlink->src;
253 GradientsContext *s = ctx->priv;253 GradientsContext *s = ctx->priv;
254 AVFrame *frame = ff_get_video_buffer(outlink, s->w, s->h);254 AVFilterLink *outlink = ctx->outputs[0];
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;
258 255
259 if (s->duration >= 0 &&256 if (s->duration >= 0 &&
260 av_rescale_q(s->pts, outlink->time_base, AV_TIME_BASE_Q) >= s->duration)257 av_rescale_q(s->pts, outlink->time_base, AV_TIME_BASE_Q) >= s->duration) {
261 return AVERROR_EOF;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;262 if (ff_outlink_frame_wanted(outlink)) {
264 s->fy0 = (s->x0 - w2) * sinf(angle) + (s->y0 - h2) * cosf(angle) + h2;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;268 s->fx0 = (s->x0 - w2) * cosf(angle) - (s->y0 - h2) * sinf(angle) + w2;
267 s->fy1 = (s->x1 - w2) * sinf(angle) + (s->y1 - h2) * cosf(angle) + h2;269 s->fy0 = (s->x0 - w2) * sinf(angle) + (s->y0 - h2) * cosf(angle) + h2;
268 270
269 if (!frame)271 s->fx1 = (s->x1 - w2) * cosf(angle) - (s->y1 - h2) * sinf(angle) + w2;
270 return AVERROR(ENOMEM);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;277 frame->key_frame = 1;
273 frame->interlaced_frame = 0;278 frame->interlaced_frame = 0;
274 frame->pict_type = AV_PICTURE_TYPE_I;279 frame->pict_type = AV_PICTURE_TYPE_I;
275 frame->sample_aspect_ratio = (AVRational) {1, 1};280 frame->sample_aspect_ratio = (AVRational) {1, 1};
276 frame->pts = s->pts++;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
283static const AVFilterPad gradients_outputs[] = {292static const AVFilterPad gradients_outputs[] = {
284 {293 {
285 .name = "default",294 .name = "default",
286 .type = AVMEDIA_TYPE_VIDEO,295 .type = AVMEDIA_TYPE_VIDEO,
287 .request_frame = gradients_request_frame,
288 .config_props = config_output,296 .config_props = config_output,
289 },297 },
290 { NULL }298 { NULL }
@@ -298,5 +306,6 @@ AVFilter ff_vsrc_gradients = { · 7 unmodified lines
298 .query_formats = query_formats,306 .query_formats = query_formats,
299 .inputs = NULL,307 .inputs = NULL,
300 .outputs = gradients_outputs,308 .outputs = gradients_outputs,
309 .activate = activate,
301 .flags = AVFILTER_FLAG_SLICE_THREADS,310 .flags = AVFILTER_FLAG_SLICE_THREADS,
302};311};

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