Quoting Paul B Mahol (2022-02-15 10:10:17)
On Tue, Feb 15, 2022 at 9:55 AM Anton Khirnov <anton@khirnov.net> wrote:
Quoting Thilo Borgmann (2022-02-12 11:55:39)
Am 31.01.22 um 12:55 schrieb James Almer: +static int config_input(AVFilterLink *inlink) +{ + // Video input data avilable + AVFilterContext *ctx = inlink->dst; + SiTiContext *s = ctx->priv; + int max_pixsteps[4]; + size_t pixel_sz; + size_t data_sz; + size_t gradient_sz; + size_t motion_sz; + + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); + av_image_fill_max_pixsteps(max_pixsteps, NULL, desc); + + s->pixel_depth = max_pixsteps[0]; + s->width = inlink->w; + s->height = inlink->h; + pixel_sz = s->pixel_depth == 1 ? sizeof(uint8_t) : sizeof(uint16_t); + data_sz = s->width * pixel_sz * s->height; + + s->prev_frame = av_malloc(data_sz); + + gradient_sz = (s->width - 2) * sizeof(double) * (s->height - 2); + s->gradient_matrix = (double*)av_malloc(gradient_sz); + + motion_sz = s->width * sizeof(double) * s->height; + s->motion_matrix = (double*)av_malloc(motion_sz);
useless casts
+ + if (!s->prev_frame || ! s->gradient_matrix || !s->motion_matrix) { + av_freep(&s->prev_frame); + av_freep(&s->gradient_matrix); + av_freep(&s->motion_matrix);
You don't need to free them on failure, that will be done in uninit. But you should free them at the beginning of this function, because config_input can be called multiple times.
In which scenarios? When its called, uninit is also called before. Was thinking to add better support for frame w/h changes when midstream filtering....
Actually I'm not sure it currently will be called more than once, but IIRC the code was supposed to assume it, precisely for future parameter change support. -- Anton Khirnov