[FFmpeg-devel] [PATCH] showinfo: fix computation of Adler CRC

Stefano Sabatini stefano.sabatini-lala at poste.it
Sat May 14 13:21:54 CEST 2011


Previously the code was computing the CRC only for the first line of
each plane.
---
 libavfilter/vf_showinfo.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index d512199..bc644a7 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -29,6 +29,7 @@
 
 typedef struct {
     unsigned int frame;
+    int vsub;
 } ShowInfoContext;
 
 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
@@ -38,18 +39,32 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
     return 0;
 }
 
+static int config_input(AVFilterLink *inlink)
+{
+    ShowInfoContext *showinfo = inlink->dst->priv;
+
+    showinfo->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
+    return 0;
+}
+
 static void end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     ShowInfoContext *showinfo = ctx->priv;
     AVFilterBufferRef *picref = inlink->cur_buf;
     uint32_t plane_crc[4], crc = 0;
-    int plane;
+    int i, plane;
 
-    for (plane = 0; plane < 4; plane++) {
+    for (plane = 0; picref->data[plane] && plane < 4; plane++) {
         size_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane);
-        plane_crc[plane] = av_adler32_update(0  , picref->data[plane], linesize);
-        crc              = av_adler32_update(crc, picref->data[plane], linesize);
+        uint8_t *data = picref->data[plane];
+        int h = plane == 1 || plane == 2 ? inlink->h >> showinfo->vsub : inlink->h;
+
+        for (i = 0; i < h; i++) {
+            plane_crc[plane] = av_adler32_update(plane_crc[plane], data, linesize);
+            crc = av_adler32_update(crc, data, linesize);
+            data += picref->linesize[plane];
+        }
     }
 
     av_log(ctx, AV_LOG_INFO,
@@ -83,7 +98,8 @@ AVFilter avfilter_vf_showinfo = {
                                     .get_video_buffer = avfilter_null_get_video_buffer,
                                     .start_frame      = avfilter_null_start_frame,
                                     .end_frame        = end_frame,
-                                    .min_perms       = AV_PERM_READ, },
+                                    .min_perms        = AV_PERM_READ,
+                                    .config_props     = config_input },
                                   { .name = NULL}},
 
     .outputs   = (AVFilterPad[]) {{ .name             = "default",
-- 
1.7.2.3



More information about the ffmpeg-devel mailing list