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;
+}
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to