OSDN Git Service

va_trace: avoid to dereference a NULL pointer
[android-x86/hardware-intel-common-libva.git] / va / va_trace.c
index d85a48a..5c4b468 100644 (file)
 
 #define _GNU_SOURCE 1
 #include "va.h"
+#include "va_enc_h264.h"
 #include "va_backend.h"
 #include "va_trace.h"
-
+#include "va_enc_h264.h"
+#include "va_dec_jpeg.h"
 #include <assert.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <time.h>
 #include <errno.h>
 
-
 /*
  * Env. to debug some issue, e.g. the decode/encode issue in a video conference scenerio:
  * .LIBVA_TRACE=log_file: general VA parameters saved into log_file
  * .LIBVA_TRACE_BUFDATA: dump VA buffer data into log_file (if not set, just calculate a checksum)
  * .LIBVA_TRACE_CODEDBUF=coded_clip_file: save the coded clip into file coded_clip_file
- * .LIBVA_TRACE_SURFACE=decoded_yuv_file: save the decoded YUV file decoded_yuv_file
+ * .LIBVA_TRACE_SURFACE=yuv_file: save surface YUV into file yuv_file. Use file name to determine
+ *                                decode/encode or jpeg surfaces
+ * .LIBVA_TRACE_SURFACE_GEOMETRY=WIDTHxHEIGHT+XOFF+YOFF: only save part of surface context into file
+ *                                due to storage bandwidth limitation
  * .LIBVA_TRACE_LOGSIZE=numeric number: truncate the log_file or coded_clip_file, or decoded_yuv_file
  *                                      when the size is bigger than the number
  */
 
-
 /* global settings */
 
 /* LIBVA_TRACE */
-unsigned int trace_flag = 0;
+int trace_flag = 0;
 
 /* LIBVA_TRACE_LOGSIZE */
 static unsigned int trace_logsize = 0xffffffff; /* truncate the log when the size is bigger than it */
 
-/* LIBVA_TRACE_BUFDATA */
-static unsigned int trace_buffer_data; /* dump buffer data or not */
-
 #define TRACE_CONTEXT_MAX 4
 /* per context settings */
 static struct _trace_context {
@@ -70,15 +70,15 @@ static struct _trace_context {
     
     /* LIBVA_TRACE */
     FILE *trace_fp_log; /* save the log into a file */
-    char trace_log_fn[1024]; /* file name */
+    char *trace_log_fn; /* file name */
     
     /* LIBVA_TRACE_CODEDBUF */
     FILE *trace_fp_codedbuf; /* save the encode result into a file */
-    char trace_codedbuf_fn[1024]; /* file name */
+    char *trace_codedbuf_fn; /* file name */
     
     /* LIBVA_TRACE_SURFACE */
     FILE *trace_fp_surface; /* save the surface YUV into a file */
-    char trace_surface_fn[1024]; /* file name */
+    char *trace_surface_fn; /* file name */
 
     VAContextID  trace_context; /* current context */
     
@@ -91,10 +91,15 @@ static struct _trace_context {
     unsigned int trace_slice_no; /* current slice NO */
     unsigned int trace_slice_size; /* current slice buffer size */
 
+    unsigned int trace_surface_width; /* surface dumping geometry */
+    unsigned int trace_surface_height;
+    unsigned int trace_surface_xoff;
+    unsigned int trace_surface_yoff;
+
     unsigned int trace_frame_width; /* current frame width */
     unsigned int trace_frame_height; /* current frame height */
     unsigned int trace_sequence_start; /* get a new sequence for encoding or not */
-} trace_context[TRACE_CONTEXT_MAX] = { {0} }; /* trace five context at the same time */
+} trace_context[TRACE_CONTEXT_MAX]; /* trace five context at the same time */
 
 #define DPY2INDEX(dpy)                                  \
     int idx;                                            \
@@ -141,11 +146,22 @@ VAStatus vaUnlockSurface(VADisplay dpy,
                          VASurfaceID surface
                          );
 
+#define FILE_NAME_SUFFIX(env_value)                      \
+do {                                                    \
+    int tmp = strnlen(env_value, sizeof(env_value));    \
+    int left = sizeof(env_value) - tmp;                 \
+                                                        \
+    snprintf(env_value+tmp,                             \
+             left,                                      \
+             ".%04d.%05d",                              \
+             trace_index,                               \
+             suffix);                                   \
+} while (0)
 
 void va_TraceInit(VADisplay dpy)
 {
     char env_value[1024];
-    unsigned int suffix = 0xffff & ((unsigned int)time(NULL));
+    unsigned short suffix = 0xffff & ((unsigned int)time(NULL));
     int trace_index = 0;
     FILE *tmp;    
     
@@ -156,79 +172,77 @@ void va_TraceInit(VADisplay dpy)
     if (trace_index == TRACE_CONTEXT_MAX)
         return;
 
+    memset(&trace_context[trace_index], 0, sizeof(struct _trace_context));
     if (va_parseConfig("LIBVA_TRACE", &env_value[0]) == 0) {
-        trace_flag = 1;
-
-        /*Check if there is still room for suffix .%d.%d*/
-    if (strnlen(env_value, 1024) < (1024 - 8))
-        snprintf(env_value+strnlen(env_value, 1024),
-                 (1025 - 8 - strnlen(env_value, 1024)),
-                 ".%d.%d", trace_index, suffix);
-
+        FILE_NAME_SUFFIX(env_value);
+        trace_context[trace_index].trace_log_fn = strdup(env_value);
+        
         tmp = fopen(env_value, "w");
         if (tmp) {
             trace_context[trace_index].trace_fp_log = tmp;
-            strcpy(trace_context[trace_index].trace_log_fn, env_value);
-        } else {
+            va_infoMessage("LIBVA_TRACE is on, save log into %s\n", trace_context[trace_index].trace_log_fn);
+            trace_flag = VA_TRACE_FLAG_LOG;
+        } else
             va_errorMessage("Open file %s failed (%s)\n", env_value, strerror(errno));
-            trace_context[trace_index].trace_fp_log = stderr;
-            strcpy(trace_context[trace_index].trace_codedbuf_fn, "/dev/stderr");
-        }
-        va_infoMessage("LIBVA_TRACE is on, save log into %s\n", trace_context[trace_index].trace_log_fn);
     }
 
-    if (trace_flag == 0)
-        return;
-
     /* may re-get the global settings for multiple context */
     if (va_parseConfig("LIBVA_TRACE_LOGSIZE", &env_value[0]) == 0) {
         trace_logsize = atoi(env_value);
         va_infoMessage("LIBVA_TRACE_LOGSIZE is on, size is %d\n", trace_logsize);
     }
-    
 
-    if (va_parseConfig("LIBVA_TRACE_BUFDATA", NULL) == 0) {
-        trace_buffer_data = 1; /* dump buffer data */
+    if ((trace_flag & VA_TRACE_FLAG_LOG) && (va_parseConfig("LIBVA_TRACE_BUFDATA", NULL) == 0)) {
+        trace_flag |= VA_TRACE_FLAG_BUFDATA;
         va_infoMessage("LIBVA_TRACE_BUFDATA is on, dump buffer into log file\n");
     }
-    
 
     /* per-context setting */
     if (va_parseConfig("LIBVA_TRACE_CODEDBUF", &env_value[0]) == 0) {
-        if (strnlen(env_value, 1024) < (1024 - 8))
-            snprintf(env_value+strnlen(env_value, 1024),
-                     (1025 - 8 - strnlen(env_value, 1024)),
-                     ".%d.%d", trace_index, suffix);
-
-        tmp = fopen(env_value, "w");
-        
-        if (tmp) {
-            trace_context[trace_index].trace_fp_codedbuf = tmp;
-            strcpy(trace_context[trace_index].trace_codedbuf_fn, env_value);
-        } else {
-            va_errorMessage("Open file %s failed (%s)\n", env_value, strerror(errno));
-            trace_context[trace_index].trace_fp_codedbuf = stderr;
-            strcpy(trace_context[trace_index].trace_codedbuf_fn, "/dev/stderr");
-        }
-
-        va_infoMessage("LIBVA_TRACE_CODEDBUF is on, save coded clip into %s\n", trace_context[trace_index].trace_codedbuf_fn);
+        FILE_NAME_SUFFIX(env_value);
+        trace_context[trace_index].trace_codedbuf_fn = strdup(env_value);
+        va_infoMessage("LIBVA_TRACE_CODEDBUF is on, save codedbuf into log file %s\n",
+                       trace_context[trace_index].trace_codedbuf_fn);
+        trace_flag |= VA_TRACE_FLAG_CODEDBUF;
     }
 
     if (va_parseConfig("LIBVA_TRACE_SURFACE", &env_value[0]) == 0) {
-        sprintf(env_value+strnlen(env_value, 1024), ".%d.%d", trace_index, suffix);
-
-        tmp = fopen(env_value, "w");
-        
-        if (tmp) {
-            trace_context[trace_index].trace_fp_surface = tmp;
-            strcpy(trace_context[trace_index].trace_surface_fn, env_value);
-        } else {
-            va_errorMessage("Open file %s failed (%s)\n", env_value, strerror(errno));
-            trace_context[trace_index].trace_fp_surface = stderr;
-            strcpy(trace_context[trace_index].trace_surface_fn, "/dev/stderr");
+        FILE_NAME_SUFFIX(env_value);
+        trace_context[trace_index].trace_surface_fn = strdup(env_value);
+
+        va_infoMessage("LIBVA_TRACE_SURFACE is on, save surface into %s\n",
+                       trace_context[trace_index].trace_surface_fn);
+
+        /* for surface data dump, it is time-consume, and may
+         * cause some side-effect, so only trace the needed surfaces
+         * to trace encode surface, set the trace file name to sth like *enc*
+         * to trace decode surface, set the trace file name to sth like *dec*
+         * if no dec/enc in file name, set both
+         */
+        if (strstr(env_value, "dec"))
+            trace_flag |= VA_TRACE_FLAG_SURFACE_DECODE;
+        if (strstr(env_value, "enc"))
+            trace_flag |= VA_TRACE_FLAG_SURFACE_ENCODE;
+        if (strstr(env_value, "jpeg") || strstr(env_value, "jpg"))
+            trace_flag |= VA_TRACE_FLAG_SURFACE_JPEG;
+
+        if (va_parseConfig("LIBVA_TRACE_SURFACE_GEOMETRY", &env_value[0]) == 0) {
+            char *p = env_value, *q;
+
+            trace_context[trace_index].trace_surface_width = strtod(p, &q);
+            p = q+1; /* skip "x" */
+            trace_context[trace_index].trace_surface_height = strtod(p, &q);
+            p = q+1; /* skip "+" */
+            trace_context[trace_index].trace_surface_xoff = strtod(p, &q);
+            p = q+1; /* skip "+" */
+            trace_context[trace_index].trace_surface_yoff = strtod(p, &q);
+
+            va_infoMessage("LIBVA_TRACE_SURFACE_GEOMETRY is on, only dump surface %dx%d+%d+%d content\n",
+                           trace_context[trace_index].trace_surface_width,
+                           trace_context[trace_index].trace_surface_height,
+                           trace_context[trace_index].trace_surface_xoff,
+                           trace_context[trace_index].trace_surface_yoff);
         }
-
-        va_infoMessage("LIBVA_TRACE_SURFACE is on, save coded clip into %s\n", trace_context[trace_index].trace_surface_fn);
     }
 
     trace_context[trace_index].dpy = dpy;
@@ -239,15 +253,24 @@ void va_TraceEnd(VADisplay dpy)
 {
     DPY2INDEX(dpy);
     
-    if (trace_context[idx].trace_fp_log && (trace_context[idx].trace_fp_log != stderr))
+    if (trace_context[idx].trace_fp_log)
         fclose(trace_context[idx].trace_fp_log);
     
-    if (trace_context[idx].trace_fp_codedbuf && (trace_context[idx].trace_fp_codedbuf != stderr))
+    if (trace_context[idx].trace_fp_codedbuf)
         fclose(trace_context[idx].trace_fp_codedbuf);
     
-    if (trace_context[idx].trace_fp_surface && (trace_context[idx].trace_fp_surface != stderr))
+    if (trace_context[idx].trace_fp_surface)
         fclose(trace_context[idx].trace_fp_surface);
 
+    if (trace_context[idx].trace_log_fn)
+        free(trace_context[idx].trace_log_fn);
+    
+    if (trace_context[idx].trace_codedbuf_fn)
+        free(trace_context[idx].trace_codedbuf_fn);
+    
+    if (trace_context[idx].trace_surface_fn)
+        free(trace_context[idx].trace_surface_fn);
+    
     memset(&trace_context[idx], 0, sizeof(struct _trace_context));
 }
 
@@ -272,9 +295,11 @@ void va_TraceMsg(int idx, const char *msg, ...)
 {
     va_list args;
 
+    if (!(trace_flag & VA_TRACE_FLAG_LOG))
+        return;
+
     if (file_size(trace_context[idx].trace_fp_log) >= trace_logsize)
         truncate_file(trace_context[idx].trace_fp_log);
-
     if (msg)  {
         va_start(args, msg);
         vfprintf(trace_context[idx].trace_fp_log, msg, args);
@@ -310,7 +335,7 @@ void va_TraceCodedBuf(VADisplay dpy)
         unsigned int i;
         
         va_TraceMsg(idx, "\tsize = %d\n", buf_list->size);
-        if (trace_context[idx].trace_fp_log)
+        if (trace_context[idx].trace_fp_codedbuf)
             fwrite(buf_list->buf, buf_list->size, 1, trace_context[idx].trace_fp_codedbuf);
 
         for (i=0; i<buf_list->size; i++)
@@ -341,7 +366,7 @@ void va_TraceSurface(VADisplay dpy)
     VAStatus va_status;
     unsigned char check_sum = 0;
     DPY2INDEX(dpy);
-    
+
     va_TraceMsg(idx, "==========dump surface data in file %s\n", trace_context[idx].trace_surface_fn);
 
     if ((file_size(trace_context[idx].trace_fp_surface) >= trace_logsize)) {
@@ -386,33 +411,29 @@ void va_TraceSurface(VADisplay dpy)
     Y_data = (unsigned char*)buffer;
     UV_data = (unsigned char*)buffer + chroma_u_offset;
 
-    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];
-
+    tmp = Y_data + luma_stride * trace_context[idx].trace_surface_yoff;
+    for (i=0; i<trace_context[idx].trace_surface_height; i++) {
         if (trace_context[idx].trace_fp_surface)
-            fwrite(tmp, trace_context[idx].trace_frame_width, 1, trace_context[idx].trace_fp_surface);
+            fwrite(tmp + trace_context[idx].trace_surface_xoff,
+                   trace_context[idx].trace_surface_width,
+                   1, trace_context[idx].trace_fp_surface);
         
-        tmp = Y_data + i * luma_stride;
+        tmp += luma_stride;
     }
-
-    tmp = UV_data;
+    tmp = UV_data + chroma_u_stride * trace_context[idx].trace_surface_yoff;
     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];
-            
+        for (i=0; i<trace_context[idx].trace_surface_height/2; i++) {
             if (trace_context[idx].trace_fp_surface)
-                fwrite(tmp, trace_context[idx].trace_frame_width, 1, trace_context[idx].trace_fp_surface);
+                fwrite(tmp + trace_context[idx].trace_surface_xoff,
+                       trace_context[idx].trace_surface_width,
+                       1, trace_context[idx].trace_fp_surface);
             
-            tmp = UV_data + i * chroma_u_stride;
+            tmp += chroma_u_stride;
         }
     }
 
     vaUnlockSurface(dpy, trace_context[idx].trace_rendertarget);
 
-    va_TraceMsg(idx, "\tchecksum = 0x%02x\n", check_sum & 0xff);
     va_TraceMsg(idx, NULL);
 }
 
@@ -446,6 +467,7 @@ void va_TraceCreateConfig(
 )
 {
     int i;
+    int encode, decode, jpeg;
     DPY2INDEX(dpy);
 
     TRACE_FUNCNAME(idx);
@@ -453,24 +475,97 @@ void va_TraceCreateConfig(
     va_TraceMsg(idx, "\tprofile = %d\n", profile);
     va_TraceMsg(idx, "\tentrypoint = %d\n", entrypoint);
     va_TraceMsg(idx, "\tnum_attribs = %d\n", num_attribs);
-    for (i = 0; i < num_attribs; i++) {
-        va_TraceMsg(idx, "\t\tattrib_list[%d].type = 0x%08x\n", i, attrib_list[i].type);
-        va_TraceMsg(idx, "\t\tattrib_list[%d].value = 0x%08x\n", i, attrib_list[i].value);
+    if (attrib_list) {
+        for (i = 0; i < num_attribs; i++) {
+            va_TraceMsg(idx, "\t\tattrib_list[%d].type = 0x%08x\n", i, attrib_list[i].type);
+            va_TraceMsg(idx, "\t\tattrib_list[%d].value = 0x%08x\n", i, attrib_list[i].value);
+        }
     }
     va_TraceMsg(idx, NULL);
 
     trace_context[idx].trace_profile = profile;
     trace_context[idx].trace_entrypoint = entrypoint;
+
+    /* avoid to create so many empty files */
+    encode = (trace_context[idx].trace_entrypoint == VAEntrypointEncSlice);
+    decode = (trace_context[idx].trace_entrypoint == VAEntrypointVLD);
+    jpeg = (trace_context[idx].trace_entrypoint == VAEntrypointEncPicture);
+    if ((encode && (trace_flag & VA_TRACE_FLAG_SURFACE_ENCODE)) ||
+        (decode && (trace_flag & VA_TRACE_FLAG_SURFACE_DECODE)) ||
+        (jpeg && (trace_flag & VA_TRACE_FLAG_SURFACE_JPEG))) {
+        FILE *tmp = fopen(trace_context[idx].trace_surface_fn, "w");
+        
+        if (tmp)
+            trace_context[idx].trace_fp_surface = tmp;
+        else {
+            va_errorMessage("Open file %s failed (%s)\n",
+                            trace_context[idx].trace_surface_fn,
+                            strerror(errno));
+            trace_context[idx].trace_fp_surface = NULL;
+            trace_flag &= ~(VA_TRACE_FLAG_SURFACE);
+        }
+    }
+
+    if (encode && (trace_flag & VA_TRACE_FLAG_CODEDBUF)) {
+        FILE *tmp = fopen(trace_context[idx].trace_codedbuf_fn, "w");
+        
+        if (tmp)
+            trace_context[idx].trace_fp_codedbuf = tmp;
+        else {
+            va_errorMessage("Open file %s failed (%s)\n",
+                            trace_context[idx].trace_codedbuf_fn,
+                            strerror(errno));
+            trace_context[idx].trace_fp_codedbuf = NULL;
+            trace_flag &= ~VA_TRACE_FLAG_CODEDBUF;
+        }
+    }
 }
 
+static void va_TraceSurfaceAttributes(
+    int idx,
+    VASurfaceAttrib    *attrib_list,
+    unsigned int       *num_attribs
+)
+{
+    int i, num;
+    VASurfaceAttrib *p;
+    
+    if (!attrib_list || !num_attribs)
+        return;
+    
+    p = attrib_list;
+    num = *num_attribs;
+    if (num > VASurfaceAttribCount)
+        num = VASurfaceAttribCount;
+
+    for (i=0; i<num; i++) {
+        va_TraceMsg(idx, "\tattrib_list[%i] =\n", i);
+        
+        va_TraceMsg(idx, "\t\ttype = %d\n", p->type);
+        va_TraceMsg(idx, "\t\tflags = %d\n", p->flags);
+        va_TraceMsg(idx, "\t\tvalue.type = %d\n", p->value.type);
+        if (p->value.type == VAGenericValueTypeInteger)
+            va_TraceMsg(idx, "\t\tvalue.value.i = 0x%08x\n", p->value.value.i);
+        else if (p->value.type == VAGenericValueTypeFloat)
+        va_TraceMsg(idx, "\t\tvalue.value.f = %f\n", p->value.value.f);
+        else if (p->value.type == VAGenericValueTypePointer)
+            va_TraceMsg(idx, "\t\tvalue.value.p = %p\n", p->value.value.p);
+        else if (p->value.type == VAGenericValueTypeFunc)
+            va_TraceMsg(idx, "\t\tvalue.value.fn = %p\n", p->value.value.fn);
+
+        p++;
+    }
+}
 
-void va_TraceCreateSurface(
+void va_TraceCreateSurfaces(
     VADisplay dpy,
     int width,
     int height,
     int format,
     int num_surfaces,
-    VASurfaceID *surfaces    /* out */
+    VASurfaceID *surfaces,    /* out */
+    VASurfaceAttrib    *attrib_list,
+    unsigned int        num_attribs
 )
 {
     int i;
@@ -483,9 +578,33 @@ void va_TraceCreateSurface(
     va_TraceMsg(idx, "\tformat = %d\n", format);
     va_TraceMsg(idx, "\tnum_surfaces = %d\n", num_surfaces);
 
-    for (i = 0; i < num_surfaces; i++)
-        va_TraceMsg(idx, "\t\tsurfaces[%d] = 0x%08x\n", i, surfaces[i]);
+    if (surfaces) {
+        for (i = 0; i < num_surfaces; i++)
+            va_TraceMsg(idx, "\t\tsurfaces[%d] = 0x%08x\n", i, surfaces[i]);
+    }
+    
+    va_TraceSurfaceAttributes(idx, attrib_list, &num_attribs);
+
+    va_TraceMsg(idx, NULL);
+}
 
+
+void va_TraceDestroySurfaces(
+    VADisplay dpy,
+    VASurfaceID *surface_list,
+    int num_surfaces
+)
+{
+    int i;
+    DPY2INDEX(dpy);
+
+    TRACE_FUNCNAME(idx);
+
+    if (surface_list) {
+        for (i = 0; i < num_surfaces; i++)
+            va_TraceMsg(idx, "\t\tsurfaces[%d] = 0x%08x\n", i, surface_list[i]);
+    }
+    
     va_TraceMsg(idx, NULL);
 }
 
@@ -505,23 +624,32 @@ void va_TraceCreateContext(
     DPY2INDEX(dpy);
 
     TRACE_FUNCNAME(idx);
-    
+
+    va_TraceMsg(idx, "\tconfig = 0x%08x\n", config_id);
     va_TraceMsg(idx, "\twidth = %d\n", picture_width);
     va_TraceMsg(idx, "\theight = %d\n", picture_height);
     va_TraceMsg(idx, "\tflag = 0x%08x\n", flag);
     va_TraceMsg(idx, "\tnum_render_targets = %d\n", num_render_targets);
-    for (i=0; i<num_render_targets; i++)
-        va_TraceMsg(idx, "\t\trender_targets[%d] = 0x%08x\n", i, render_targets[i]);
-    va_TraceMsg(idx, "\tcontext = 0x%08x\n", *context);
-    va_TraceMsg(idx, NULL);
-
-    trace_context[idx].trace_context = *context;
-
+    if (render_targets) {
+        for (i=0; i<num_render_targets; i++)
+            va_TraceMsg(idx, "\t\trender_targets[%d] = 0x%08x\n", i, render_targets[i]);
+    }
+    if (context) {
+        va_TraceMsg(idx, "\tcontext = 0x%08x\n", *context);
+        trace_context[idx].trace_context = *context;
+    } else
+        trace_context[idx].trace_context = VA_INVALID_ID;
+    
     trace_context[idx].trace_frame_no = 0;
     trace_context[idx].trace_slice_no = 0;
 
     trace_context[idx].trace_frame_width = picture_width;
     trace_context[idx].trace_frame_height = picture_height;
+
+    if (trace_context[idx].trace_surface_width == 0)
+        trace_context[idx].trace_surface_width = picture_width;
+    if (trace_context[idx].trace_surface_height == 0)
+        trace_context[idx].trace_surface_height = picture_height;
 }
 
 
@@ -539,15 +667,79 @@ static char * buffer_type_to_string(int type)
     case VAResidualDataBufferType: return "VAResidualDataBufferType";
     case VADeblockingParameterBufferType: return "VADeblockingParameterBufferType";
     case VAImageBufferType: return "VAImageBufferType";
+    case VAQMatrixBufferType: return "VAQMatrixBufferType";
+    case VAHuffmanTableBufferType: return "VAHuffmanTableBufferType";
+/* Following are encode buffer types */
     case VAEncCodedBufferType: return "VAEncCodedBufferType";
     case VAEncSequenceParameterBufferType: return "VAEncSequenceParameterBufferType";
     case VAEncPictureParameterBufferType: return "VAEncPictureParameterBufferType";
     case VAEncSliceParameterBufferType: return "VAEncSliceParameterBufferType";
+    case VAEncPackedHeaderParameterBufferType: return "VAEncPackedHeaderParameterBufferType";
+    case VAEncPackedHeaderDataBufferType: return "VAEncPackedHeaderDataBufferType";
     case VAEncMiscParameterBufferType: return "VAEncMiscParameterBufferType";
+    case VAEncMacroblockParameterBufferType: return "VAEncMacroblockParameterBufferType";
+    case VAProcPipelineParameterBufferType: return "VAProcPipelineParameterBufferType";
+    case VAProcFilterParameterBufferType: return "VAProcFilterParameterBufferType";
     default: return "UnknowBuffer";
     }
 }
 
+void va_TraceCreateBuffer (
+    VADisplay dpy,
+    VAContextID context,       /* in */
+    VABufferType type,         /* in */
+    unsigned int size,         /* in */
+    unsigned int num_elements, /* in */
+    void *data,                        /* in */
+    VABufferID *buf_id         /* out */
+)
+{
+    DPY2INDEX(dpy);
+
+    /* only trace CodedBuffer */
+    if (type != VAEncCodedBufferType)
+        return;
+
+    TRACE_FUNCNAME(idx);
+    va_TraceMsg(idx, "\tbuf_type=%s\n", buffer_type_to_string(type));
+    if (buf_id)
+        va_TraceMsg(idx, "\tbuf_id=0x%x\n", *buf_id);
+    va_TraceMsg(idx, "\tsize=%d\n", size);
+    va_TraceMsg(idx, "\tnum_elements=%d\n", num_elements);
+    
+    va_TraceMsg(idx, NULL);
+}
+
+void va_TraceDestroyBuffer (
+    VADisplay dpy,
+    VABufferID buf_id    /* in */
+)
+{
+    VABufferType type;
+    unsigned int size;
+    unsigned int num_elements;
+    
+    VACodedBufferSegment *buf_list;
+    int i = 0;
+    
+    DPY2INDEX(dpy);
+
+    vaBufferInfo(dpy, trace_context[idx].trace_context, buf_id, &type, &size, &num_elements);    
+    
+    /* only trace CodedBuffer */
+    if (type != VAEncCodedBufferType)
+        return;
+
+    TRACE_FUNCNAME(idx);
+    va_TraceMsg(idx, "\tbuf_type=%s\n", buffer_type_to_string(type));
+    va_TraceMsg(idx, "\tbuf_id=0x%x\n", buf_id);
+    va_TraceMsg(idx, "\tsize=%d\n", size);
+    va_TraceMsg(idx, "\tnum_elements=%d\n", num_elements);
+    
+    va_TraceMsg(idx, NULL);
+}
+
+
 void va_TraceMapBuffer (
     VADisplay dpy,
     VABufferID buf_id,    /* in */
@@ -564,16 +756,16 @@ void va_TraceMapBuffer (
     DPY2INDEX(dpy);
 
     vaBufferInfo(dpy, trace_context[idx].trace_context, buf_id, &type, &size, &num_elements);    
-    /*
-      va_TraceMsg(idx, "\tbuf_id=0x%x\n", buf_id);
-      va_TraceMsg(idx, "\tbuf_type=%s\n", buffer_type_to_string(type));
-      va_TraceMsg(idx, "\tbuf_size=%s\n", size);
-      va_TraceMsg(idx, "\tbuf_elements=%s\n", &num_elements);
-    */
     
     /* only trace CodedBuffer */
     if (type != VAEncCodedBufferType)
         return;
+
+    TRACE_FUNCNAME(idx);
+    va_TraceMsg(idx, "\tbuf_id=0x%x\n", buf_id);
+    va_TraceMsg(idx, "\tbuf_type=%s\n", buffer_type_to_string(type));
+    if ((pbuf == NULL) || (*pbuf == NULL))
+        return;
     
     buf_list = (VACodedBufferSegment *)(*pbuf);
     while (buf_list != NULL) {
@@ -605,21 +797,21 @@ static void va_TraceVABuffers(
     unsigned char  check_sum = 0;
     DPY2INDEX(dpy);
     
-    va_TraceMsg(idx, "%s\n",  buffer_type_to_string(type));
+    va_TraceMsg(idx, "%s",  buffer_type_to_string(type));
 
     for (i=0; i<size; i++) {
         unsigned char value =  p[i];
             
-        if ((trace_buffer_data) && ((i%16) == 0))
-            va_TraceMsg(idx, "\n0x%08x:", i);
+        if ((trace_flag & VA_TRACE_FLAG_BUFDATA) && ((i%16) == 0))
+            va_TraceMsg(idx, "\n\t0x%08x:", i);
 
-        if (trace_buffer_data)
+        if (trace_flag & VA_TRACE_FLAG_BUFDATA)
             va_TraceMsg(idx, " %02x", value);
 
         check_sum ^= value;
     }
 
-    va_TraceMsg(idx, "\tchecksum = 0x%02x\n", check_sum & 0xff);
+    va_TraceMsg(idx, "\n\tchecksum = 0x%02x\n", check_sum & 0xff);
     va_TraceMsg(idx, NULL);
 
     return;
@@ -725,6 +917,132 @@ static void va_TraceVASliceParameterBufferMPEG2(
     return;
 }
 
+static void va_TraceVAPictureParameterBufferJPEG(
+    VADisplay dpy,
+    VAContextID context,
+    VABufferID buffer,
+    VABufferType type,
+    unsigned int size,
+    unsigned int num_elements,
+    void *data)
+{
+    int i;
+    VAPictureParameterBufferJPEGBaseline *p=(VAPictureParameterBufferJPEGBaseline *)data;
+    DPY2INDEX(dpy);
+
+    va_TraceMsg(idx,"*VAPictureParameterBufferJPEG\n");
+    va_TraceMsg(idx,"\tpicture_width = %u\n", p->picture_width);
+    va_TraceMsg(idx,"\tpicture_height = %u\n", p->picture_height);
+    va_TraceMsg(idx,"\tcomponents = \n");
+    for (i = 0; i < p->num_components && i < 255; ++i) {
+        va_TraceMsg(idx,"\t\t[%d] component_id = %u\n", i, p->components[i].component_id);
+        va_TraceMsg(idx,"\t\t[%d] h_sampling_factor = %u\n", i, p->components[i].h_sampling_factor);
+        va_TraceMsg(idx,"\t\t[%d] v_sampling_factor = %u\n", i, p->components[i].v_sampling_factor);
+        va_TraceMsg(idx,"\t\t[%d] quantiser_table_selector = %u\n", i, p->components[i].quantiser_table_selector);
+    }
+}
+
+static void va_TraceVAIQMatrixBufferJPEG(
+    VADisplay dpy,
+    VAContextID context,
+    VABufferID buffer,
+    VABufferType type,
+    unsigned int size,
+    unsigned int num_elements,
+    void *data)
+{
+    int i, j;
+    static char tmp[1024];
+    VAIQMatrixBufferJPEGBaseline *p=(VAIQMatrixBufferJPEGBaseline *)data;
+    DPY2INDEX(dpy);
+    va_TraceMsg(idx,"*VAIQMatrixParameterBufferJPEG\n");
+    va_TraceMsg(idx,"\tload_quantiser_table =\n");
+    for (i = 0; i < 4; ++i) {
+        va_TraceMsg(idx,"\t\t[%d] = %u\n", i, p->load_quantiser_table[i]);
+    }
+    va_TraceMsg(idx,"\tquantiser_table =\n");
+    for (i = 0; i < 4; ++i) {
+        memset(tmp, 0, sizeof tmp);
+        for (j = 0; j < 64; ++j) {
+            sprintf(tmp + strlen(tmp), "%u ", p->quantiser_table[i][j]);
+        }
+        va_TraceMsg(idx,"\t\t[%d] = %s\n", i, tmp);
+    }
+}
+
+static void va_TraceVASliceParameterBufferJPEG(
+    VADisplay dpy,
+    VAContextID context,
+    VABufferID buffer,
+    VABufferType type,
+    unsigned int size,
+    unsigned int num_elements,
+    void *data)
+{
+    int i;
+    VASliceParameterBufferJPEGBaseline *p=(VASliceParameterBufferJPEGBaseline *)data;
+    DPY2INDEX(dpy);
+    va_TraceMsg(idx,"*VASliceParameterBufferJPEG\n");
+    va_TraceMsg(idx,"\tslice_data_size = %u\n", p->slice_data_size);
+    va_TraceMsg(idx,"\tslice_data_offset = %u\n", p->slice_data_offset);
+    va_TraceMsg(idx,"\tslice_data_flag = %u\n", p->slice_data_flag);
+    va_TraceMsg(idx,"\tslice_horizontal_position = %u\n", p->slice_horizontal_position);
+    va_TraceMsg(idx,"\tslice_vertical_position = %u\n", p->slice_vertical_position);
+    va_TraceMsg(idx,"\tcomponents = \n");
+    for (i = 0; i < p->num_components && i < 4; ++i) {
+        va_TraceMsg(idx,"\t\t[%d] component_selector = %u\n", i, p->components[i].component_selector);
+        va_TraceMsg(idx,"\t\t[%d] dc_table_selector = %u\n", i, p->components[i].dc_table_selector);
+        va_TraceMsg(idx,"\t\t[%d] ac_table_selector = %u\n", i, p->components[i].ac_table_selector);
+    }
+    va_TraceMsg(idx,"\trestart_interval = %u\n", p->restart_interval);
+    va_TraceMsg(idx,"\tnum_mcus = %u\n", p->num_mcus);
+}
+
+static void va_TraceVAHuffmanTableBufferJPEG(
+    VADisplay dpy,
+    VAContextID context,
+    VABufferID buffer,
+    VABufferType type,
+    unsigned int size,
+    unsigned int num_elements,
+    void *data)
+{
+    int i, j;
+    static char tmp[1024];
+    VAHuffmanTableBufferJPEGBaseline *p=(VAHuffmanTableBufferJPEGBaseline *)data;
+    DPY2INDEX(dpy);
+    va_TraceMsg(idx,"*VAHuffmanTableBufferJPEG\n");
+
+    for (i = 0; i < 2; ++i) {
+        va_TraceMsg(idx,"\tload_huffman_table[%d] =%u\n", i, p->load_huffman_table[0]);
+        va_TraceMsg(idx,"\thuffman_table[%d] =\n", i);
+        memset(tmp, 0, sizeof tmp);
+        for (j = 0; j < 16; ++j) {
+            sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].num_dc_codes[j]);
+        }
+        va_TraceMsg(idx,"\t\tnum_dc_codes =%s\n", tmp);
+        memset(tmp, 0, sizeof tmp);
+        for (j = 0; j < 12; ++j) {
+            sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].dc_values[j]);
+        }
+        va_TraceMsg(idx,"\t\tdc_values =%s\n", tmp);
+        memset(tmp, 0, sizeof tmp);
+        for (j = 0; j < 16; ++j) {
+            sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].num_ac_codes[j]);
+        }
+        va_TraceMsg(idx,"\t\tnum_dc_codes =%s\n", tmp);
+        memset(tmp, 0, sizeof tmp);
+        for (j = 0; j < 162; ++j) {
+            sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].ac_values[j]);
+        }
+        va_TraceMsg(idx,"\t\tnum_dc_codes =%s\n", tmp);
+        memset(tmp, 0, sizeof tmp);
+        for (j = 0; j < 2; ++j) {
+            sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].pad[j]);
+        }
+        va_TraceMsg(idx,"\t\tnum_dc_codes =%s\n", tmp);
+    }
+}
 
 static void va_TraceVAPictureParameterBufferMPEG4(
     VADisplay dpy,
@@ -863,7 +1181,7 @@ static void va_TraceVAEncPictureParameterBufferMPEG4(
     va_TraceMsg(idx, "VAEncPictureParameterBufferMPEG4\n");
     va_TraceMsg(idx, "\treference_picture = 0x%08x\n", p->reference_picture);
     va_TraceMsg(idx, "\treconstructed_picture = 0x%08x\n", p->reconstructed_picture);
-    va_TraceMsg(idx, "\tcoded_buf = %08x\n", p->coded_buf);
+    va_TraceMsg(idx, "\tcoded_buf = 0x%08x\n", p->coded_buf);
     va_TraceMsg(idx, "\tpicture_width = %d\n", p->picture_width);
     va_TraceMsg(idx, "\tpicture_height = %d\n", p->picture_height);
     va_TraceMsg(idx, "\tmodulo_time_base = %d\n", p->modulo_time_base);
@@ -942,17 +1260,19 @@ static void va_TraceVAPictureParameterBufferH264(
     va_TraceMsg(idx, "\tCurrPic.TopFieldOrderCnt = %d\n", p->CurrPic.TopFieldOrderCnt);
     va_TraceMsg(idx, "\tCurrPic.BottomFieldOrderCnt = %d\n", p->CurrPic.BottomFieldOrderCnt);
 
-    va_TraceMsg(idx, "\tReferenceFrames (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-frame_idx:\n");
+    va_TraceMsg(idx, "\tReferenceFrames (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-frame_idx-flags:\n");
     for (i = 0; i < 16; i++)
     {
-        if (p->ReferenceFrames[i].flags != VA_PICTURE_H264_INVALID) {
-            va_TraceMsg(idx, "\t\t%d-%d-0x%08x-%d\n",
+        if ((p->ReferenceFrames[i].picture_id != VA_INVALID_SURFACE) &&
+            ((p->ReferenceFrames[i].flags & VA_PICTURE_H264_INVALID) == 0)) {
+            va_TraceMsg(idx, "\t\t%08d-%08d-0x%08x-%08d-0x%08x\n",
                         p->ReferenceFrames[i].TopFieldOrderCnt,
                         p->ReferenceFrames[i].BottomFieldOrderCnt,
                         p->ReferenceFrames[i].picture_id,
-                        p->ReferenceFrames[i].frame_idx);
+                        p->ReferenceFrames[i].frame_idx,
+                        p->ReferenceFrames[i].flags);
         } else
-            va_TraceMsg(idx, "\t\tinv-inv-inv-inv\n");
+            va_TraceMsg(idx, "\t\tinv-inv-inv-inv-inv\n");
     }
     va_TraceMsg(idx, "\n");
     
@@ -1026,14 +1346,14 @@ static void va_TraceVASliceParameterBufferH264(
 
     if (p->slice_type == 0 || p->slice_type == 1) {
         va_TraceMsg(idx, "\tRefPicList0 =");
-        for (i = 0; i < p->num_ref_idx_l0_active_minus1 + 1; i++) {
-            va_TraceMsg(idx, "%d-%d-0x%08x-%d\n", p->RefPicList0[i].TopFieldOrderCnt, p->RefPicList0[i].BottomFieldOrderCnt, p->RefPicList0[i].picture_id, p->RefPicList0[i].frame_idx);
+        for (i = 0; (i < p->num_ref_idx_l0_active_minus1 + 1 && i < 32); i++) {
+            va_TraceMsg(idx, "%08d-%08d-0x%08x-%08d-0x%08x\n", p->RefPicList0[i].TopFieldOrderCnt, p->RefPicList0[i].BottomFieldOrderCnt, p->RefPicList0[i].picture_id, p->RefPicList0[i].frame_idx,  p->RefPicList0[i].flags);
         }
         if (p->slice_type == 1) {
             va_TraceMsg(idx, "\tRefPicList1 =");
-            for (i = 0; i < p->num_ref_idx_l1_active_minus1 + 1; i++)
+            for (i = 0; (i < p->num_ref_idx_l1_active_minus1 + 1 && i < 32); i++)
             {
-                va_TraceMsg(idx, "%d-%d-0x%08x-%d\n", p->RefPicList1[i].TopFieldOrderCnt, p->RefPicList1[i].BottomFieldOrderCnt, p->RefPicList1[i].picture_id, p->RefPicList1[i].frame_idx);
+                va_TraceMsg(idx, "%08d-%08d-0x%08x-%08d-0x%08x\n", p->RefPicList1[i].TopFieldOrderCnt, p->RefPicList1[i].BottomFieldOrderCnt, p->RefPicList1[i].picture_id, p->RefPicList1[i].frame_idx, p->RefPicList1[i].flags);
             }
         }
     }
@@ -1117,6 +1437,8 @@ static void va_TraceVAIQMatrixBufferH264(
     va_TraceMsg(idx, NULL);
 }
 
+
+
 static void va_TraceVAEncSequenceParameterBufferH264(
     VADisplay dpy,
     VAContextID context,
@@ -1128,22 +1450,52 @@ static void va_TraceVAEncSequenceParameterBufferH264(
 {
     VAEncSequenceParameterBufferH264 *p = (VAEncSequenceParameterBufferH264 *)data;
     DPY2INDEX(dpy);
-    
+    int i;
+
     va_TraceMsg(idx, "VAEncSequenceParameterBufferH264\n");
-    
+
     va_TraceMsg(idx, "\tseq_parameter_set_id = %d\n", p->seq_parameter_set_id);
     va_TraceMsg(idx, "\tlevel_idc = %d\n", p->level_idc);
     va_TraceMsg(idx, "\tintra_period = %d\n", p->intra_period);
     va_TraceMsg(idx, "\tintra_idr_period = %d\n", p->intra_idr_period);
+    va_TraceMsg(idx, "\tip_period = %d\n", p->ip_period);
+    va_TraceMsg(idx, "\tbits_per_second = %d\n", p->bits_per_second);
     va_TraceMsg(idx, "\tmax_num_ref_frames = %d\n", p->max_num_ref_frames);
     va_TraceMsg(idx, "\tpicture_width_in_mbs = %d\n", p->picture_width_in_mbs);
     va_TraceMsg(idx, "\tpicture_height_in_mbs = %d\n", p->picture_height_in_mbs);
-    va_TraceMsg(idx, "\tbits_per_second = %d\n", p->bits_per_second);
-    va_TraceMsg(idx, "\tframe_rate = %d\n", p->frame_rate);
-    va_TraceMsg(idx, "\tinitial_qp = %d\n", p->initial_qp);
-    va_TraceMsg(idx, "\tmin_qp = %d\n", p->min_qp);
-    va_TraceMsg(idx, "\tbasic_unit_size = %d\n", p->basic_unit_size);
-    va_TraceMsg(idx, "\tvui_flag = %d\n", p->vui_flag);
+    va_TraceMsg(idx, "\tchroma_format_idc = %d\n", p->seq_fields.bits.chroma_format_idc);
+    va_TraceMsg(idx, "\tframe_mbs_only_flag = %d\n", p->seq_fields.bits.frame_mbs_only_flag);
+    va_TraceMsg(idx, "\tmb_adaptive_frame_field_flag = %d\n", p->seq_fields.bits.mb_adaptive_frame_field_flag);
+    va_TraceMsg(idx, "\tseq_scaling_matrix_present_flag = %d\n", p->seq_fields.bits.seq_scaling_matrix_present_flag);
+    va_TraceMsg(idx, "\tdirect_8x8_inference_flag = %d\n", p->seq_fields.bits.direct_8x8_inference_flag);
+    va_TraceMsg(idx, "\tlog2_max_frame_num_minus4 = %d\n", p->seq_fields.bits.log2_max_frame_num_minus4);
+    va_TraceMsg(idx, "\tpic_order_cnt_type = %d\n", p->seq_fields.bits.pic_order_cnt_type);
+    va_TraceMsg(idx, "\tlog2_max_pic_order_cnt_lsb_minus4 = %d\n", p->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4);
+    va_TraceMsg(idx, "\tdelta_pic_order_always_zero_flag = %d\n", p->seq_fields.bits.delta_pic_order_always_zero_flag);
+    va_TraceMsg(idx, "\tbit_depth_luma_minus8 = %d\n", p->bit_depth_luma_minus8);
+    va_TraceMsg(idx, "\tbit_depth_chroma_minus8 = %d\n", p->bit_depth_chroma_minus8);
+    va_TraceMsg(idx, "\tnum_ref_frames_in_pic_order_cnt_cycle = %d\n", p->num_ref_frames_in_pic_order_cnt_cycle);
+    va_TraceMsg(idx, "\toffset_for_non_ref_pic = %d\n", p->offset_for_non_ref_pic);
+    va_TraceMsg(idx, "\toffset_for_top_to_bottom_field = %d\n", p->offset_for_top_to_bottom_field);
+    for(i = 0; i< p->max_num_ref_frames; ++i)
+        va_TraceMsg(idx, "\toffset_for_ref_frame[%d] = %d\n", i, p->offset_for_ref_frame[i]);
+    va_TraceMsg(idx, "\tframe_cropping_flag = %d\n", p->frame_cropping_flag);
+    va_TraceMsg(idx, "\tframe_crop_left_offset = %d\n", p->frame_crop_left_offset);
+    va_TraceMsg(idx, "\tframe_crop_right_offset = %d\n", p->frame_crop_right_offset);
+    va_TraceMsg(idx, "\tframe_crop_top_offset = %d\n", p->frame_crop_top_offset);
+    va_TraceMsg(idx, "\tframe_crop_bottom_offset = %d\n", p->frame_crop_bottom_offset);
+    va_TraceMsg(idx, "\tvui_parameters_present_flag = %d\n", p->vui_parameters_present_flag);
+    va_TraceMsg(idx, "\taspect_ratio_info_present_flag = %d\n", p->vui_fields.bits.aspect_ratio_info_present_flag);
+    va_TraceMsg(idx, "\ttiming_info_present_flag = %d\n", p->vui_fields.bits.timing_info_present_flag);
+    va_TraceMsg(idx, "\tbitstream_restriction_flag = %d\n", p->vui_fields.bits.bitstream_restriction_flag);
+    va_TraceMsg(idx, "\tlog2_max_mv_length_horizontal = %d\n", p->vui_fields.bits.log2_max_mv_length_horizontal);
+    va_TraceMsg(idx, "\tlog2_max_mv_length_vertical = %d\n", p->vui_fields.bits.log2_max_mv_length_vertical);
+    va_TraceMsg(idx, "\taspect_ratio_idc = %d\n", p->aspect_ratio_idc);
+    va_TraceMsg(idx, "\tsar_width = %d\n", p->sar_width);
+    va_TraceMsg(idx, "\tsar_height = %d\n", p->sar_height);
+    va_TraceMsg(idx, "\tnum_units_in_tick = %d\n", p->num_units_in_tick);
+    va_TraceMsg(idx, "\ttime_scale = %d\n", p->time_scale);
+
     va_TraceMsg(idx, NULL);
 
     /* start a new sequce, coded log file can be truncated */
@@ -1152,6 +1504,7 @@ static void va_TraceVAEncSequenceParameterBufferH264(
     return;
 }
 
+
 static void va_TraceVAEncPictureParameterBufferH264(
     VADisplay dpy,
     VAContextID context,
@@ -1163,22 +1516,60 @@ static void va_TraceVAEncPictureParameterBufferH264(
 {
     VAEncPictureParameterBufferH264 *p = (VAEncPictureParameterBufferH264 *)data;
     DPY2INDEX(dpy);
-    
+    int i;
+
     va_TraceMsg(idx, "VAEncPictureParameterBufferH264\n");
-    va_TraceMsg(idx, "\treference_picture = 0x%08x\n", p->reference_picture);
-    va_TraceMsg(idx, "\treconstructed_picture = 0x%08x\n", p->reconstructed_picture);
+
+    va_TraceMsg(idx, "\tCurrPic.picture_id = 0x%08x\n", p->CurrPic.picture_id);
+    va_TraceMsg(idx, "\tCurrPic.frame_idx = %d\n", p->CurrPic.frame_idx);
+    va_TraceMsg(idx, "\tCurrPic.flags = %d\n", p->CurrPic.flags);
+    va_TraceMsg(idx, "\tCurrPic.TopFieldOrderCnt = %d\n", p->CurrPic.TopFieldOrderCnt);
+    va_TraceMsg(idx, "\tCurrPic.BottomFieldOrderCnt = %d\n", p->CurrPic.BottomFieldOrderCnt);
+    va_TraceMsg(idx, "\tReferenceFrames (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-frame_idx-flags):\n");
+    for (i = 0; i < 16; i++)
+    {
+        if ((p->ReferenceFrames[i].picture_id != VA_INVALID_SURFACE) &&
+            ((p->ReferenceFrames[i].flags & VA_PICTURE_H264_INVALID) == 0)) {
+            va_TraceMsg(idx, "\t\t%08d-%08d-0x%08x-%08d-0x%08x\n",
+                        p->ReferenceFrames[i].TopFieldOrderCnt,
+                        p->ReferenceFrames[i].BottomFieldOrderCnt,
+                        p->ReferenceFrames[i].picture_id,
+                        p->ReferenceFrames[i].frame_idx,
+                        p->ReferenceFrames[i].flags
+                        );
+        } else
+            va_TraceMsg(idx, "\t\tinv-inv-inv-inv-inv\n");
+    }
     va_TraceMsg(idx, "\tcoded_buf = %08x\n", p->coded_buf);
-    va_TraceMsg(idx, "\tpicture_width = %d\n", p->picture_width);
-    va_TraceMsg(idx, "\tpicture_height = %d\n", p->picture_height);
+    va_TraceMsg(idx, "\tpic_parameter_set_id = %d\n", p->pic_parameter_set_id);
+    va_TraceMsg(idx, "\tseq_parameter_set_id = %d\n", p->seq_parameter_set_id);
     va_TraceMsg(idx, "\tlast_picture = 0x%08x\n", p->last_picture);
+    va_TraceMsg(idx, "\tframe_num = %d\n", p->frame_num);
+    va_TraceMsg(idx, "\tpic_init_qp = %d\n", p->pic_init_qp);
+    va_TraceMsg(idx, "\tnum_ref_idx_l0_active_minus1 = %d\n", p->num_ref_idx_l0_active_minus1);
+    va_TraceMsg(idx, "\tnum_ref_idx_l1_active_minus1 = %d\n", p->num_ref_idx_l1_active_minus1);
+    va_TraceMsg(idx, "\tchroma_qp_index_offset = %d\n", p->chroma_qp_index_offset);
+    va_TraceMsg(idx, "\tsecond_chroma_qp_index_offset = %d\n", p->second_chroma_qp_index_offset);
+    va_TraceMsg(idx, "\tpic_fields = 0x%03x\n", p->pic_fields.value);
+    va_TraceMsg(idx, "\tidr_pic_flag = %d\n", p->pic_fields.bits.idr_pic_flag);
+    va_TraceMsg(idx, "\treference_pic_flag = %d\n", p->pic_fields.bits.reference_pic_flag);
+    va_TraceMsg(idx, "\tentropy_coding_mode_flag = %d\n", p->pic_fields.bits.entropy_coding_mode_flag);
+    va_TraceMsg(idx, "\tweighted_pred_flag = %d\n", p->pic_fields.bits.weighted_pred_flag);
+    va_TraceMsg(idx, "\tweighted_bipred_idc = %d\n", p->pic_fields.bits.weighted_bipred_idc);
+    va_TraceMsg(idx, "\tconstrained_intra_pred_flag = %d\n", p->pic_fields.bits.constrained_intra_pred_flag);
+    va_TraceMsg(idx, "\ttransform_8x8_mode_flag = %d\n", p->pic_fields.bits.transform_8x8_mode_flag);
+    va_TraceMsg(idx, "\tdeblocking_filter_control_present_flag = %d\n", p->pic_fields.bits.deblocking_filter_control_present_flag);
+    va_TraceMsg(idx, "\tredundant_pic_cnt_present_flag = %d\n", p->pic_fields.bits.redundant_pic_cnt_present_flag);
+    va_TraceMsg(idx, "\tpic_order_present_flag = %d\n", p->pic_fields.bits.pic_order_present_flag);
+    va_TraceMsg(idx, "\tpic_scaling_matrix_present_flag = %d\n", p->pic_fields.bits.pic_scaling_matrix_present_flag);
+
     va_TraceMsg(idx, NULL);
 
     trace_context[idx].trace_codedbuf =  p->coded_buf;
-    
+
     return;
 }
 
-
 static void va_TraceVAEncSliceParameterBuffer(
     VADisplay dpy,
     VAContextID context,
@@ -1204,6 +1595,145 @@ static void va_TraceVAEncSliceParameterBuffer(
     return;
 }
 
+static void va_TraceVAEncSliceParameterBufferH264(
+    VADisplay dpy,
+    VAContextID context,
+    VABufferID buffer,
+    VABufferType type,
+    unsigned int size,
+    unsigned int num_elements,
+    void *data)
+{
+    VAEncSliceParameterBufferH264* p = (VAEncSliceParameterBufferH264*)data;
+    DPY2INDEX(dpy);
+    int i;
+
+    if (!p)
+        return;
+    va_TraceMsg(idx, "VAEncSliceParameterBufferH264\n");
+    va_TraceMsg(idx, "\tmacroblock_address = %d\n", p->macroblock_address);
+    va_TraceMsg(idx, "\tnum_macroblocks = %d\n", p->num_macroblocks);
+    va_TraceMsg(idx, "\tmacroblock_info = %08x\n", p->macroblock_info);
+    va_TraceMsg(idx, "\tslice_type = %d\n", p->slice_type);
+    va_TraceMsg(idx, "\tpic_parameter_set_id = %d\n", p->pic_parameter_set_id);
+    va_TraceMsg(idx, "\tidr_pic_id = %d\n", p->idr_pic_id);
+    va_TraceMsg(idx, "\tpic_order_cnt_lsb = %d\n", p->pic_order_cnt_lsb);
+    va_TraceMsg(idx, "\tdelta_pic_order_cnt_bottom = %d\n", p->delta_pic_order_cnt_bottom);
+    va_TraceMsg(idx, "\tdelta_pic_order_cnt[0] = %d\n", p->delta_pic_order_cnt[0]);
+    va_TraceMsg(idx, "\tdelta_pic_order_cnt[1] = %d\n", p->delta_pic_order_cnt[1]);
+    va_TraceMsg(idx, "\tdirect_spatial_mv_pred_flag = %d\n", p->direct_spatial_mv_pred_flag);
+    va_TraceMsg(idx, "\tnum_ref_idx_active_override_flag = %d\n", p->num_ref_idx_active_override_flag);
+    va_TraceMsg(idx, "\tnum_ref_idx_l1_active_minus1 = %d\n", p->num_ref_idx_l1_active_minus1);
+    va_TraceMsg(idx, "\tslice_beta_offset_div2 = %d\n", p->slice_beta_offset_div2);
+
+    if (p->slice_type == 0 || p->slice_type == 1) {
+        va_TraceMsg(idx, "\tRefPicList0 (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-frame_idx-flags):\n");
+        for (i = 0; i < 32; i++) {
+            if ((p->RefPicList0[i].picture_id != VA_INVALID_SURFACE) &&
+                ((p->RefPicList0[i].flags & VA_PICTURE_H264_INVALID) == 0))
+                va_TraceMsg(idx, "\t\t%08d-%08d-0x%08x-%08d-0x%08x\n",
+                            p->RefPicList0[i].TopFieldOrderCnt,
+                            p->RefPicList0[i].BottomFieldOrderCnt,
+                            p->RefPicList0[i].picture_id,
+                            p->RefPicList0[i].frame_idx,
+                            p->RefPicList0[i].flags);
+            else
+                break;
+        }
+    }
+    
+    if (p->slice_type == 1) {
+        va_TraceMsg(idx, "\tRefPicList1 (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-frame_idx-flags):\n");
+        for (i = 0; i < 32; i++) {
+            if ((p->RefPicList1[i].picture_id != VA_INVALID_SURFACE) &&
+                ((p->RefPicList1[i].flags & VA_PICTURE_H264_INVALID) == 0))
+                va_TraceMsg(idx, "\t\t%08d-%08d-0x%08x-%08d-0x%08d\n",
+                            p->RefPicList1[i].TopFieldOrderCnt,
+                            p->RefPicList1[i].BottomFieldOrderCnt,
+                            p->RefPicList1[i].picture_id,
+                            p->RefPicList1[i].frame_idx,
+                            p->RefPicList1[i].flags
+                            );
+            else
+                break;
+        }
+    }
+    
+    va_TraceMsg(idx, "\tluma_log2_weight_denom = %d\n", p->luma_log2_weight_denom);
+    va_TraceMsg(idx, "\tchroma_log2_weight_denom = %d\n", p->chroma_log2_weight_denom);
+    va_TraceMsg(idx, "\tluma_weight_l0_flag = %d\n", p->luma_weight_l0_flag);
+    if (p->luma_weight_l0_flag && p->num_ref_idx_l0_active_minus1 < 32) {
+        for (i = 0; i <=  p->num_ref_idx_l0_active_minus1; i++) {
+            va_TraceMsg(idx, "\t%d ", p->luma_weight_l0[i]);
+            va_TraceMsg(idx, "\t%d ", p->luma_offset_l0[i]);
+        }
+    }
+
+    va_TraceMsg(idx, "\tchroma_weight_l0_flag = %d\n", p->chroma_weight_l0_flag);
+    if (p->chroma_weight_l0_flag && p->num_ref_idx_l0_active_minus1 < 32) {
+        for (i = 0; i <= p->num_ref_idx_l0_active_minus1; i++) {
+            va_TraceMsg(idx, "\t\t%d ", p->chroma_weight_l0[i][0]);
+            va_TraceMsg(idx, "\t\t%d ", p->chroma_offset_l0[i][0]);
+            va_TraceMsg(idx, "\t\t%d ", p->chroma_weight_l0[i][1]);
+            va_TraceMsg(idx, "\t\t%d ", p->chroma_offset_l0[i][1]);
+        }
+    }
+
+    va_TraceMsg(idx, "\tluma_weight_l1_flag = %d\n", p->luma_weight_l1_flag);
+    if (p->luma_weight_l1_flag && p->num_ref_idx_l1_active_minus1 < 32) {
+        for (i = 0; i <=  p->num_ref_idx_l1_active_minus1; i++) {
+            va_TraceMsg(idx, "\t\t%d ", p->luma_weight_l1[i]);
+            va_TraceMsg(idx, "\t\t%d ", p->luma_offset_l1[i]);
+        }
+    }
+
+    va_TraceMsg(idx, "\tchroma_weight_l1_flag = %d\n", p->chroma_weight_l1_flag);
+    if (p->chroma_weight_l1_flag && p->num_ref_idx_l1_active_minus1 < 32) {
+        for (i = 0; i <= p->num_ref_idx_l1_active_minus1; i++) {
+            va_TraceMsg(idx, "\t\t%d ", p->chroma_weight_l1[i][0]);
+            va_TraceMsg(idx, "\t\t%d ", p->chroma_offset_l1[i][0]);
+            va_TraceMsg(idx, "\t\t%d ", p->chroma_weight_l1[i][1]);
+            va_TraceMsg(idx, "\t\t%d ", p->chroma_offset_l1[i][1]);
+        }
+        va_TraceMsg(idx, "\n");
+    }
+    va_TraceMsg(idx, NULL);
+
+    va_TraceMsg(idx, "\tcabac_init_idc = %d\n", p->cabac_init_idc);
+    va_TraceMsg(idx, "\tslice_qp_delta = %d\n", p->slice_qp_delta);
+    va_TraceMsg(idx, "\tdisable_deblocking_filter_idc = %d\n", p->disable_deblocking_filter_idc);
+    va_TraceMsg(idx, "\tslice_alpha_c0_offset_div2 = %d\n", p->slice_alpha_c0_offset_div2);
+    va_TraceMsg(idx, "\tslice_beta_offset_div2 = %d\n", p->slice_beta_offset_div2);
+    va_TraceMsg(idx, NULL);
+
+    return;
+}
+
+
+static void va_TraceVAEncPackedHeaderParameterBufferType(
+    VADisplay dpy,
+    VAContextID context,
+    VABufferID buffer,
+    VABufferType type,
+    unsigned int size,
+    unsigned int num_elements,
+    void *data)
+{
+    VAEncPackedHeaderParameterBuffer* p = (VAEncPackedHeaderParameterBuffer*)data;
+    DPY2INDEX(dpy);
+    int i;
+
+    if (!p)
+        return;
+    va_TraceMsg(idx, "VAEncPackedHeaderParameterBuffer\n");
+    va_TraceMsg(idx, "\ttype = 0x%08x\n", p->type);
+    va_TraceMsg(idx, "\tbit_length = %d\n", p->bit_length);
+    va_TraceMsg(idx, "\thas_emulation_bytes = %d\n", p->has_emulation_bytes);
+    va_TraceMsg(idx, NULL);
+
+    return;
+}
+
 static void va_TraceVAEncMiscParameterBuffer(
     VADisplay dpy,
     VAContextID context,
@@ -1231,9 +1761,14 @@ static void va_TraceVAEncMiscParameterBuffer(
 
         va_TraceMsg(idx, "VAEncMiscParameterRateControl\n");
         va_TraceMsg(idx, "\tbits_per_second = %d\n", p->bits_per_second);
+        va_TraceMsg(idx, "\ttarget_percentage = %d\n", p->target_percentage);
         va_TraceMsg(idx, "\twindow_size = %d\n", p->window_size);
         va_TraceMsg(idx, "\tinitial_qp = %d\n", p->initial_qp);
         va_TraceMsg(idx, "\tmin_qp = %d\n", p->min_qp);
+        va_TraceMsg(idx, "\tbasic_unit_size = %d\n", p->basic_unit_size);
+        va_TraceMsg(idx, "\trc_flags.reset = %d \n", p->rc_flags.bits.reset);
+        va_TraceMsg(idx, "\trc_flags.disable_frame_skip = %d\n", p->rc_flags.bits.disable_frame_skip);
+        va_TraceMsg(idx, "\trc_flags.disable_bit_stuffing = %d\n", p->rc_flags.bits.disable_bit_stuffing);
         break;
     }
     case VAEncMiscParameterTypeMaxSliceSize:
@@ -1254,8 +1789,18 @@ static void va_TraceVAEncMiscParameterBuffer(
         va_TraceMsg(idx, "\tair_auto = %d\n", p->air_auto);
         break;
     }
+    case VAEncMiscParameterTypeHRD:
+    {
+        VAEncMiscParameterHRD *p = (VAEncMiscParameterHRD *)tmp->data;
+
+        va_TraceMsg(idx, "VAEncMiscParameterHRD\n");
+        va_TraceMsg(idx, "\tinitial_buffer_fullness = %d\n", p->initial_buffer_fullness);
+        va_TraceMsg(idx, "\tbuffer_size = %d\n", p->buffer_size);
+        break;
+    }
     default:
-        va_TraceMsg(idx, "invalid VAEncMiscParameterBuffer type = %d\n", tmp->type);
+        va_TraceMsg(idx, "Unknown VAEncMiscParameterBuffer(type = %d):", tmp->type);
+        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, data);
         break;
     }
     va_TraceMsg(idx, NULL);
@@ -1466,10 +2011,6 @@ static void va_TraceMPEG2Buf(
         break;
     case VAEncSliceParameterBufferType:
         break;
-    case VAEncH264VUIBufferType:
-        break;
-    case VAEncH264SEIBufferType:
-        break;
     default:
         break;
     }
@@ -1529,6 +2070,71 @@ static void va_TraceVAEncPictureParameterBufferH263(
     return;
 }
 
+static void va_TraceVAEncPictureParameterBufferJPEG(
+    VADisplay dpy,
+    VAContextID context,
+    VABufferID buffer,
+    VABufferType type,
+    unsigned int size,
+    unsigned int num_elements,
+    void *data)
+{
+    VAEncPictureParameterBufferJPEG *p = (VAEncPictureParameterBufferJPEG *)data;
+    int i;
+    
+    DPY2INDEX(dpy);
+    
+    va_TraceMsg(idx, "VAEncPictureParameterBufferJPEG\n");
+    va_TraceMsg(idx, "\treconstructed_picture = 0x%08x\n", p->reconstructed_picture);
+    va_TraceMsg(idx, "\tcoded_buf = %08x\n", p->coded_buf);
+    va_TraceMsg(idx, "\tpicture_width = %d\n", p->picture_width);
+    va_TraceMsg(idx, "\tpicture_height = %d\n", p->picture_height);
+    va_TraceMsg(idx, NULL);
+
+    trace_context[idx].trace_codedbuf =  p->coded_buf;
+    
+    return;
+}
+
+static void va_TraceVAEncQMatrixBufferJPEG(
+    VADisplay dpy,
+    VAContextID context,
+    VABufferID buffer,
+    VABufferType type,
+    unsigned int size,
+    unsigned int num_elements,
+    void *data)
+{
+    VAQMatrixBufferJPEG *p = (VAQMatrixBufferJPEG *)data;
+    DPY2INDEX(dpy);
+    
+    va_TraceMsg(idx, "VAQMatrixBufferJPEG\n");
+    va_TraceMsg(idx, "\tload_lum_quantiser_matrix = %d", p->load_lum_quantiser_matrix);
+    if (p->load_lum_quantiser_matrix) {
+        int i;
+        for (i = 0; i < 64; i++) {
+            if ((i % 8) == 0)
+                va_TraceMsg(idx, "\n\t");
+            va_TraceMsg(idx, "\t0x%02x", p->lum_quantiser_matrix[i]);
+        }
+        va_TraceMsg(idx, "\n");
+    }
+    va_TraceMsg(idx, "\tload_chroma_quantiser_matrix = %08x\n", p->load_chroma_quantiser_matrix);
+    if (p->load_chroma_quantiser_matrix) {
+        int i;
+        for (i = 0; i < 64; i++) {
+            if ((i % 8) == 0)
+                va_TraceMsg(idx, "\n\t");
+            va_TraceMsg(idx, "\t0x%02x", p->chroma_quantiser_matrix[i]);
+        }
+        va_TraceMsg(idx, "\n");
+    }
+    
+    va_TraceMsg(idx, NULL);
+    
+    return;
+}
+
 
 static void va_TraceH263Buf(
     VADisplay dpy,
@@ -1583,7 +2189,62 @@ static void va_TraceH263Buf(
     case VAEncSliceParameterBufferType:
         va_TraceVAEncSliceParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
+    case VAEncPackedHeaderParameterBufferType:
+        va_TraceVAEncPackedHeaderParameterBufferType(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
+    default:
+        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
+    }
+}
+
+
+static void va_TraceJPEGBuf(
+    VADisplay dpy,
+    VAContextID context,
+    VABufferID buffer,
+    VABufferType type,
+    unsigned int size,
+    unsigned int num_elements,
+    void *pbuf
+)
+{
+    switch (type) {
+    case VABitPlaneBufferType:
+    case VASliceGroupMapBufferType:
+    case VASliceDataBufferType:
+    case VAMacroblockParameterBufferType:
+    case VAResidualDataBufferType:
+    case VADeblockingParameterBufferType:
+    case VAImageBufferType:
+    case VAProtectedSliceDataBufferType:
+    case VAEncCodedBufferType:
+    case VAEncSequenceParameterBufferType:
+        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
+    case VAEncSliceParameterBufferType:
+        va_TraceVAEncPictureParameterBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
+    case VAPictureParameterBufferType:
+        va_TraceVAPictureParameterBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
+    case VAIQMatrixBufferType:
+        va_TraceVAIQMatrixBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
+    case VASliceParameterBufferType:
+        va_TraceVASliceParameterBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
+    case VAHuffmanTableBufferType:
+        va_TraceVAHuffmanTableBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
+    case VAEncPictureParameterBufferType:
+        va_TraceVAEncPictureParameterBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
+    case VAQMatrixBufferType:
+        va_TraceVAEncQMatrixBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
+        break;
     default:
+        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     }
 }
@@ -1641,11 +2302,8 @@ static void va_TraceMPEG4Buf(
     case VAEncSliceParameterBufferType:
         va_TraceVAEncSliceParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
-    case VAEncH264VUIBufferType:
-        break;
-    case VAEncH264SEIBufferType:
-        break;
     default:
+        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     }
 }
@@ -1705,18 +2363,20 @@ static void va_TraceH264Buf(
         va_TraceVAEncPictureParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     case VAEncSliceParameterBufferType:
-        va_TraceVAEncSliceParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
+        if (size == sizeof(VAEncSliceParameterBuffer))
+            va_TraceVAEncSliceParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
+        else
+            va_TraceVAEncSliceParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
-    case VAEncH264VUIBufferType:
-        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
-        break;
-    case VAEncH264SEIBufferType:
-        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
+    case VAEncPackedHeaderParameterBufferType:
+        va_TraceVAEncPackedHeaderParameterBufferType(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
+        
     case VAEncMiscParameterBufferType:
         va_TraceVAEncMiscParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     default:
+        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     }
 }
@@ -1778,6 +2438,7 @@ static void va_TraceVC1Buf(
         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     default:
+        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     }
 }
@@ -1799,8 +2460,11 @@ void va_TraceRenderPicture(
     
     va_TraceMsg(idx, "\tcontext = 0x%08x\n", context);
     va_TraceMsg(idx, "\tnum_buffers = %d\n", num_buffers);
+    if (buffers == NULL)
+        return;
+    
     for (i = 0; i < num_buffers; i++) {
-        void *pbuf;
+        unsigned char *pbuf = NULL;
         unsigned int j;
         
         /* get buffer type information */
@@ -1812,13 +2476,14 @@ void va_TraceRenderPicture(
         va_TraceMsg(idx, "\t  size = %d\n", size);
         va_TraceMsg(idx, "\t  num_elements = %d\n", num_elements);
 
-        vaMapBuffer(dpy, buffers[i], &pbuf);
-
+        vaMapBuffer(dpy, buffers[i], (void **)&pbuf);
+        if (pbuf == NULL)
+            continue;
+        
         switch (trace_context[idx].trace_profile) {
         case VAProfileMPEG2Simple:
         case VAProfileMPEG2Main:
             for (j=0; j<num_elements; j++) {
-                va_TraceMsg(idx, "\t---------------------------\n", j);
                 va_TraceMsg(idx, "\telement[%d] = ", j);
                 va_TraceMPEG2Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
             }
@@ -1827,7 +2492,6 @@ void va_TraceRenderPicture(
         case VAProfileMPEG4AdvancedSimple:
         case VAProfileMPEG4Main:
             for (j=0; j<num_elements; j++) {
-                va_TraceMsg(idx, "\t---------------------------\n", j);
                 va_TraceMsg(idx, "\telement[%d] = ", j);
                 va_TraceMPEG4Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
             }
@@ -1837,7 +2501,6 @@ void va_TraceRenderPicture(
         case VAProfileH264High:
         case VAProfileH264ConstrainedBaseline:
             for (j=0; j<num_elements; j++) {
-                va_TraceMsg(idx, "\t---------------------------\n", j);
                 va_TraceMsg(idx, "\telement[%d] = ", j);
                 
                 va_TraceH264Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
@@ -1847,7 +2510,6 @@ void va_TraceRenderPicture(
         case VAProfileVC1Main:
         case VAProfileVC1Advanced:
             for (j=0; j<num_elements; j++) {
-                va_TraceMsg(idx, "\t---------------------------\n", j);
                 va_TraceMsg(idx, "\telement[%d] = ", j);
                 
                 va_TraceVC1Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
@@ -1855,12 +2517,18 @@ void va_TraceRenderPicture(
             break;
         case VAProfileH263Baseline:
             for (j=0; j<num_elements; j++) {
-                va_TraceMsg(idx, "\t---------------------------\n", j);
                 va_TraceMsg(idx, "\telement[%d] = ", j);
                 
                 va_TraceH263Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
             }
             break;
+        case VAProfileJPEGBaseline:
+            for (j=0; j<num_elements; j++) {
+                va_TraceMsg(idx, "\telement[%d] = ", j);
+                
+                va_TraceJPEGBuf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
+            }
+            break;
         default:
             break;
         }
@@ -1871,39 +2539,46 @@ void va_TraceRenderPicture(
     va_TraceMsg(idx, NULL);
 }
 
-
 void va_TraceEndPicture(
     VADisplay dpy,
-    VAContextID context
+    VAContextID context,
+    int endpic_done
 )
 {
+    int encode, decode, jpeg;
     DPY2INDEX(dpy);
 
     TRACE_FUNCNAME(idx);
-    
+
     va_TraceMsg(idx, "\tcontext = 0x%08x\n", context);
     va_TraceMsg(idx, "\trender_targets = 0x%08x\n", trace_context[idx].trace_rendertarget);
 
-    /* want to trace codedbuf, and it is encode */
-    if (trace_context[idx].trace_fp_codedbuf &&
-        ((trace_context[idx].trace_entrypoint == VAEntrypointEncSlice) ||
-         (trace_context[idx].trace_entrypoint == VAEntrypointEncPicture))) {
-        /* force the pipleline finish rendering */
+    /* avoid to create so many empty files */
+    encode = (trace_context[idx].trace_entrypoint == VAEntrypointEncSlice);
+    decode = (trace_context[idx].trace_entrypoint == VAEntrypointVLD);
+    jpeg = (trace_context[idx].trace_entrypoint == VAEntrypointEncPicture);
+
+    /* trace encode source surface, can do it before HW completes rendering */
+    if ((encode && (trace_flag & VA_TRACE_FLAG_SURFACE_ENCODE))||
+           (jpeg && (trace_flag & VA_TRACE_FLAG_SURFACE_JPEG)))
+        va_TraceSurface(dpy);
+    
+    /* trace coded buffer, do it after HW completes rendering */
+    if ((encode || jpeg) && (trace_flag & VA_TRACE_FLAG_CODEDBUF)) {
         vaSyncSurface(dpy, trace_context[idx].trace_rendertarget);
         va_TraceCodedBuf(dpy);
     }
 
-    /* trace decoded surface for decoding, or the source sourface for encoding */
-    if (trace_context[idx].trace_fp_surface) {
-        /* force the pipleline finish rendering */
+    /* trace decoded surface, do it after HW completes rendering */
+    if (decode && ((trace_flag & VA_TRACE_FLAG_SURFACE_DECODE))) {
         vaSyncSurface(dpy, trace_context[idx].trace_rendertarget);
-        
         va_TraceSurface(dpy);
     }
 
     va_TraceMsg(idx, NULL);
 }
 
+
 void va_TraceSyncSurface(
     VADisplay dpy,
     VASurfaceID render_target
@@ -1917,6 +2592,23 @@ void va_TraceSyncSurface(
     va_TraceMsg(idx, NULL);
 }
 
+void va_TraceQuerySurfaceAttributes(
+    VADisplay           dpy,
+    VAConfigID          config,
+    VASurfaceAttrib    *attrib_list,
+    unsigned int       *num_attribs
+)
+{
+    DPY2INDEX(dpy);
+
+    TRACE_FUNCNAME(idx);
+    va_TraceMsg(idx, "\tconfig = 0x%08x\n", config);
+    va_TraceSurfaceAttributes(idx, attrib_list, num_attribs);
+    
+    va_TraceMsg(idx, NULL);
+
+}
+
 
 void va_TraceQuerySurfaceStatus(
     VADisplay dpy,
@@ -1929,7 +2621,8 @@ void va_TraceQuerySurfaceStatus(
     TRACE_FUNCNAME(idx);
 
     va_TraceMsg(idx, "\trender_target = 0x%08x\n", render_target);
-    va_TraceMsg(idx, "\tstatus = 0x%08x\n", *status);
+    if (status)
+        va_TraceMsg(idx, "\tstatus = 0x%08x\n", *status);
     va_TraceMsg(idx, NULL);
 }
 
@@ -1946,9 +2639,9 @@ void va_TraceQuerySurfaceError(
     TRACE_FUNCNAME(idx);
     va_TraceMsg(idx, "\tsurface = 0x%08x\n", surface);
     va_TraceMsg(idx, "\terror_status = 0x%08x\n", error_status);
-    if (error_status == VA_STATUS_ERROR_DECODING_ERROR) {
+    if (error_info && (error_status == VA_STATUS_ERROR_DECODING_ERROR)) {
         VASurfaceDecodeMBErrors *p = *error_info;
-        while (p->status != -1) {
+        while (p && (p->status != -1)) {
             va_TraceMsg(idx, "\t\tstatus = %d\n", p->status);
             va_TraceMsg(idx, "\t\tstart_mb = %d\n", p->start_mb);
             va_TraceMsg(idx, "\t\tend_mb = %d\n", p->end_mb);
@@ -1981,8 +2674,11 @@ void va_TraceQueryDisplayAttributes (
     
     DPY2INDEX(dpy);
     
-    va_TraceMsg(idx, "\tnum_attributes = %d\n", *num_attributes);
+    if (attr_list == NULL || num_attributes == NULL)
+        return;
 
+    va_TraceMsg(idx, "\tnum_attributes = %d\n", *num_attributes);
+    
     for (i=0; i<*num_attributes; i++) {
         va_TraceMsg(idx, "\tattr_list[%d] =\n");
         va_TraceMsg(idx, "\t  typ = 0x%08x\n", attr_list[i].type);
@@ -2006,6 +2702,9 @@ static void va_TraceDisplayAttributes (
     DPY2INDEX(dpy);
     
     va_TraceMsg(idx, "\tnum_attributes = %d\n", num_attributes);
+    if (attr_list == NULL)
+        return;
+    
     for (i=0; i<num_attributes; i++) {
         va_TraceMsg(idx, "\tattr_list[%d] =\n");
         va_TraceMsg(idx, "\t  typ = 0x%08x\n", attr_list[i].type);