Derive input parameters from correct inlink when using ppsrc. Previously both input frames would use dimensions of first inlink, causing crash if first inlink w/h was smaller than second one.
Unified · Split
| @@ -297,46 +297,12 @@ static int activate(AVFilterContext *ctx) · 296 unmodified lines | ||
| 297 | 297 | return 0; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | −static int config_input(AVFilterLink *inlink) | |
| 301 | −{ | |
| 302 | − int max_value; | |
| 303 | − AVFilterContext *ctx = inlink->dst; | |
| 304 | − DecimateContext *dm = ctx->priv; | |
| 305 | − const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); | |
| 306 | − const int w = inlink->w; | |
| 307 | − const int h = inlink->h; | |
| 308 | − | |
| 309 | − dm->hsub = pix_desc->log2_chroma_w; | |
| 310 | − dm->vsub = pix_desc->log2_chroma_h; | |
| 311 | − dm->depth = pix_desc->comp[0].depth; | |
| 312 | − max_value = (1 << dm->depth) - 1; | |
| 313 | − dm->scthresh = (int64_t)(((int64_t)max_value * w * h * dm->scthresh_flt) / 100); | |
| 314 | − dm->dupthresh = (int64_t)(((int64_t)max_value * dm->blockx * dm->blocky * dm->dupthresh_flt) / 100); | |
| 315 | − dm->nxblocks = (w + dm->blockx/2 - 1) / (dm->blockx/2); | |
| 316 | − dm->nyblocks = (h + dm->blocky/2 - 1) / (dm->blocky/2); | |
| 317 | − dm->bdiffsize = dm->nxblocks * dm->nyblocks; | |
| 318 | − dm->bdiffs = av_malloc_array(dm->bdiffsize, sizeof(*dm->bdiffs)); | |
| 319 | − dm->queue = av_calloc(dm->cycle, sizeof(*dm->queue)); | |
| 320 | − | |
| 321 | − if (!dm->bdiffs || !dm->queue) | |
| 322 | − return AVERROR(ENOMEM); | |
| 323 | − | |
| 324 | − if (dm->ppsrc) { | |
| 325 | − dm->clean_src = av_calloc(dm->cycle, sizeof(*dm->clean_src)); | |
| 326 | − if (!dm->clean_src) | |
| 327 | − return AVERROR(ENOMEM); | |
| 328 | − } | |
| 329 | − | |
| 330 | − return 0; | |
| 331 | −} | |
| 332 | − | |
| 333 | 300 | static av_cold int decimate_init(AVFilterContext *ctx) |
| 334 | 301 | { |
| 335 | 302 | DecimateContext *dm = ctx->priv; |
| 336 | 303 | AVFilterPad pad = { |
| 337 | 304 | .name = "main", |
| 338 | 305 | .type = AVMEDIA_TYPE_VIDEO, |
| 339 | − .config_props = config_input, | |
| 340 | 306 | }; |
| 341 | 307 | int ret; |
| 342 | 308 | |
| @@ -404,6 +370,31 @@ static int config_output(AVFilterLink *outlink) · 61 unmodified lines | ||
| 404 | 370 | const AVFilterLink *inlink = |
| 405 | 371 | ctx->inputs[dm->ppsrc ? INPUT_CLEANSRC : INPUT_MAIN]; |
| 406 | 372 | AVRational fps = inlink->frame_rate; |
| 373 | + int max_value; | |
| 374 | + const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); | |
| 375 | + const int w = inlink->w; | |
| 376 | + const int h = inlink->h; | |
| 377 | + | |
| 378 | + dm->hsub = pix_desc->log2_chroma_w; | |
| 379 | + dm->vsub = pix_desc->log2_chroma_h; | |
| 380 | + dm->depth = pix_desc->comp[0].depth; | |
| 381 | + max_value = (1 << dm->depth) - 1; | |
| 382 | + dm->scthresh = (int64_t)(((int64_t)max_value * w * h * dm->scthresh_flt) / 100); | |
| 383 | + dm->dupthresh = (int64_t)(((int64_t)max_value * dm->blockx * dm->blocky * dm->dupthresh_flt) / 100); | |
| 384 | + dm->nxblocks = (w + dm->blockx/2 - 1) / (dm->blockx/2); | |
| 385 | + dm->nyblocks = (h + dm->blocky/2 - 1) / (dm->blocky/2); | |
| 386 | + dm->bdiffsize = dm->nxblocks * dm->nyblocks; | |
| 387 | + dm->bdiffs = av_malloc_array(dm->bdiffsize, sizeof(*dm->bdiffs)); | |
| 388 | + dm->queue = av_calloc(dm->cycle, sizeof(*dm->queue)); | |
| 389 | + | |
| 390 | + if (!dm->bdiffs || !dm->queue) | |
| 391 | + return AVERROR(ENOMEM); | |
| 392 | + | |
| 393 | + if (dm->ppsrc) { | |
| 394 | + dm->clean_src = av_calloc(dm->cycle, sizeof(*dm->clean_src)); | |
| 395 | + if (!dm->clean_src) | |
| 396 | + return AVERROR(ENOMEM); | |
| 397 | + } | |
| 407 | 398 | |
| 408 | 399 | if (!fps.num || !fps.den) { |
| 409 | 400 | av_log(ctx, AV_LOG_ERROR, "The input needs a constant frame rate; " |