[FFmpeg-devel] [PATCH] tools: add an AV_CODEC_CAP_ENCODER_RECON_FRAME test tool

James Almer jamrial at gmail.com
Fri Oct 21 15:42:52 EEST 2022


On 10/21/2022 5:30 AM, Anton Khirnov wrote:
> +static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts,
> +                      const AVFrame *frame)
> +{
> +    FrameChecksum *c;
> +    int shift_h, shift_v;
> +
> +    c = av_realloc_array(*pc, *nb_c + 1, sizeof(*c));

Use av_fast_realloc(), or the size_t replacement if it's pushed before 
this. Or maybe port this to AVFifo with auto grow. Either case will 
reduce the amount of reallocations considerably.

> +    if (!c)
> +        return AVERROR(ENOMEM);
> +    *pc = c;
> +    (*nb_c)++;
> +
> +    c += *nb_c - 1;
> +    memset(c, 0, sizeof(*c));
> +
> +    av_pix_fmt_get_chroma_sub_sample(frame->format, &shift_h, &shift_v);
> +
> +    c->ts = ts;
> +    for (int p = 0; frame->data[p]; p++) {
> +        const uint8_t *data = frame->data[p];
> +        int linesize = av_image_get_linesize(frame->format, frame->width, p);
> +        uint32_t checksum = 0;
> +
> +        for (int j = 0; j < frame->height >> shift_v; j++) {

Isn't the shift meant for the chroma planes only?

> +            checksum = av_adler32_update(checksum, data, linesize);
> +            data += frame->linesize[p];
> +        }
> +
> +        c->checksum[p] = checksum;
> +    }
> +
> +    return 0;
> +}


More information about the ffmpeg-devel mailing list