[Libva] [PATCH] trace: use an adler32 checksum for data buffer types.

Gwenole Beauchesne gwenole.beauchesne at intel.com
Mon Oct 10 02:17:35 PDT 2011


Hi,

This patch uses an Alder32 checksum for data buffer types. This was useful
to debug VC-1 Bit Planes. I can push it if you find it useful.

Note: the implementation of the algorithm is pretty naive.

Regards,
Gwenole.
---
 va/va_trace.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/va/va_trace.c b/va/va_trace.c
index b954cd7..a6e1910 100644
--- a/va/va_trace.c
+++ b/va/va_trace.c
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdint.h>
 #include <dlfcn.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -108,6 +109,37 @@ static struct _trace_context {
 
 #define TRACE_FUNCNAME(idx)    va_TraceMsg(idx, "==========%s\n", __func__); 
 
+/* Adler32 checksum */
+typedef struct {
+    uint32_t a;
+    uint32_t b;
+} Checksum;
+
+static inline void
+checksum_init(Checksum *ck)
+{
+    ck->a = 1;
+    ck->b = 0;
+}
+
+static inline void
+checksum_update(Checksum *ck, uint8_t v)
+{
+#define CHECKSUM_MOD 65521
+    ck->a += v;
+    if (ck->a >= CHECKSUM_MOD)
+        ck->a -= CHECKSUM_MOD;
+    ck->b += ck->a;
+    if (ck->b >= CHECKSUM_MOD)
+        ck->b -= CHECKSUM_MOD;
+}
+
+static inline uint32_t
+checksum_get(Checksum *ck)
+{
+    return (ck->b << 16) | ck->a;
+}
+
 /* Prototype declarations (functions defined in va.c) */
 
 void va_errorMessage(const char *msg, ...);
@@ -287,7 +319,7 @@ void va_TraceCodedBuf(VADisplay dpy)
 {
     VACodedBufferSegment *buf_list = NULL;
     VAStatus va_status;
-    unsigned char check_sum = 0;
+    Checksum ck;
     DPY2INDEX(dpy);
     
     /* can only truncate at a sequence boudary */
@@ -305,6 +337,8 @@ void va_TraceCodedBuf(VADisplay dpy)
         return;
 
     va_TraceMsg(idx, "==========dump codedbuf into file %s\n", trace_context[idx].trace_codedbuf_fn);
+
+    checksum_init(&ck);
     
     while (buf_list != NULL) {
         unsigned int i;
@@ -314,13 +348,13 @@ void va_TraceCodedBuf(VADisplay dpy)
             fwrite(buf_list->buf, buf_list->size, 1, trace_context[idx].trace_fp_codedbuf);
 
         for (i=0; i<buf_list->size; i++)
-            check_sum ^= *((unsigned char *)buf_list->buf + i);
+            checksum_update(&ck, *((unsigned char *)buf_list->buf + i));
 
         buf_list = buf_list->next;
     }
     vaUnmapBuffer(dpy,trace_context[idx].trace_codedbuf);
     
-    va_TraceMsg(idx, "\tchecksum = 0x%02x\n", check_sum);
+    va_TraceMsg(idx, "\tchecksum = 0x%08x\n", checksum_get(&ck));
     va_TraceMsg(idx, NULL);
 }
 
@@ -339,7 +373,7 @@ void va_TraceSurface(VADisplay dpy)
     void *buffer = NULL;
     unsigned char *Y_data, *UV_data, *tmp;
     VAStatus va_status;
-    unsigned char check_sum = 0;
+    Checksum ck;
     DPY2INDEX(dpy);
     
     va_TraceMsg(idx, "==========dump surface data in file %s\n", trace_context[idx].trace_surface_fn);
@@ -386,10 +420,12 @@ void va_TraceSurface(VADisplay dpy)
     Y_data = (unsigned char*)buffer;
     UV_data = (unsigned char*)buffer + chroma_u_offset;
 
+    checksum_init(&ck);
+
     tmp = Y_data;
     for (i=0; i<trace_context[idx].trace_frame_height; i++) {
         for (j=0; j<trace_context[idx].trace_frame_width; j++)
-            check_sum ^= tmp[j];
+            checksum_update(&ck, tmp[j]);
 
         if (trace_context[idx].trace_fp_surface)
             fwrite(tmp, trace_context[idx].trace_frame_width, 1, trace_context[idx].trace_fp_surface);
@@ -401,7 +437,7 @@ void va_TraceSurface(VADisplay dpy)
     if (fourcc == VA_FOURCC_NV12) {
         for (i=0; i<trace_context[idx].trace_frame_height/2; i++) {
             for (j=0; j<trace_context[idx].trace_frame_width; j++)
-                check_sum ^= tmp[j];
+                checksum_update(&ck, tmp[j]);
             
             if (trace_context[idx].trace_fp_surface)
                 fwrite(tmp, trace_context[idx].trace_frame_width, 1, trace_context[idx].trace_fp_surface);
@@ -412,7 +448,7 @@ void va_TraceSurface(VADisplay dpy)
 
     vaUnlockSurface(dpy, trace_context[idx].trace_rendertarget);
 
-    va_TraceMsg(idx, "\tchecksum = 0x%02x\n", check_sum & 0xff);
+    va_TraceMsg(idx, "\tchecksum = 0x%08x\n", checksum_get(&ck));
     va_TraceMsg(idx, NULL);
 }
 
@@ -602,11 +638,13 @@ static void va_TraceVABuffers(
 {
     unsigned int i;
     unsigned char *p = pbuf;
-    unsigned char  check_sum = 0;
+    Checksum ck;
     DPY2INDEX(dpy);
     
     va_TraceMsg(idx, "%s\n",  buffer_type_to_string(type));
 
+    checksum_init(&ck);
+
     for (i=0; i<size; i++) {
         unsigned char value =  p[i];
             
@@ -616,10 +654,10 @@ static void va_TraceVABuffers(
         if (trace_buffer_data)
             va_TraceMsg(idx, " %02x", value);
 
-        check_sum ^= value;
+        checksum_update(&ck, value);
     }
 
-    va_TraceMsg(idx, "\tchecksum = 0x%02x\n", check_sum & 0xff);
+    va_TraceMsg(idx, "\tchecksum = 0x%08x\n", checksum_get(&ck));
     va_TraceMsg(idx, NULL);
 
     return;
-- 
1.7.4.1



More information about the Libva mailing list