[FFmpeg-devel] [PATCH] avfilter: Added siti filter

Anton Khirnov anton at khirnov.net
Mon Jan 31 13:53:39 EET 2022


Quoting Thilo Borgmann (2022-01-18 14:58:07)
> >> Violations of code style.
> 
> Enhanced.

Not enough. There are still many remaining, e.g.
* opening brace of a function definition should be on its own line
* the context should generally be the first argument
* unsigned char* should be uint8_t*
* mixed declarations and code (the compiler should warn about that)
* pointless casts all over the place

> +typedef struct SiTiContext {
> +    const AVClass *class;
> +    int pixel_depth;
> +    int width, height;
> +    int nb_frames;

uint64_t

> +static int config_input(AVFilterLink *inlink) {
> +    // Video input data avilable
> +    AVFilterContext *ctx = inlink->dst;
> +    SiTiContext *s = ctx->priv;
> +    int max_pixsteps[4];
> +
> +    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;
> +    size_t pixel_sz = s->pixel_depth==1 ? (size_t) sizeof(uint8_t) : (size_t) sizeof(uint16_t);
> +    size_t data_sz = (size_t) s->width * pixel_sz * s->height;
> +    s->prev_frame = av_malloc(data_sz);

unchecked malloc

> +
> +    return 0;
> +}
> +
> +// Get frame data handling 8 and 10 bit formats
> +static uint16_t get_frame_data(const unsigned char* src, int pixel_depth, int index) {
> +    const uint16_t *src16 = (const uint16_t *)src;
> +    if (pixel_depth == 2)
> +        return src16[index];
> +    return (uint16_t) src[index];
> +}

going through this branch nine times for every single pixel is just atrocious

templatize convolve_sobel()/calculate_motion() for 8/16 bits

> +static int filter_frame(AVFilterLink *inlink, AVFrame *frame) {
> +    AVFilterContext *ctx = inlink->dst;
> +    SiTiContext *s = ctx->priv;
> +
> +    // Gradient matrix will not include the input frame's edges
> +    size_t gradient_data_sz = (size_t) (s->width - 2) * sizeof(double) * (s->height - 2);
> +    double *gradient_matrix = av_malloc(gradient_data_sz);
> +    size_t motion_data_sz = (size_t) s->width * sizeof(double) * s->height;
> +    double *motion_matrix = av_malloc(motion_data_sz);

These have a fixed size that is known at config_input() time, no point
in allocating them anew for each frame.

Also, I don't see where motion_matrix is freed.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list