OSDN Git Service

va_trace: avoid to dereference a NULL pointer
[android-x86/hardware-intel-common-libva.git] / va / va_trace.c
index be5f57c..5c4b468 100644 (file)
@@ -28,7 +28,7 @@
 #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>
@@ -475,9 +475,11 @@ 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);
 
@@ -519,6 +521,41 @@ void va_TraceCreateConfig(
     }
 }
 
+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_TraceCreateSurfaces(
     VADisplay dpy,
@@ -541,13 +578,37 @@ void va_TraceCreateSurfaces(
     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);
+}
+
+
 void va_TraceCreateContext(
     VADisplay dpy,
     VAConfigID config_id,
@@ -563,18 +624,22 @@ 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;
 
@@ -602,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 */
@@ -627,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) {
@@ -668,13 +797,13 @@ 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_flag & VA_TRACE_FLAG_BUFDATA) && ((i%16) == 0))
-            va_TraceMsg(idx, "\n0x%08x:", i);
+            va_TraceMsg(idx, "\n\t0x%08x:", i);
 
         if (trace_flag & VA_TRACE_FLAG_BUFDATA)
             va_TraceMsg(idx, " %02x", value);
@@ -682,7 +811,7 @@ static void va_TraceVABuffers(
         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;
@@ -788,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,
@@ -926,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);
@@ -1005,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");
     
@@ -1090,13 +1347,13 @@ 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 < 32); 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);
+            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 < 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);
             }
         }
     }
@@ -1268,17 +1525,20 @@ static void va_TraceVAEncPictureParameterBufferH264(
     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:\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, "\tcoded_buf = %08x\n", p->coded_buf);
     va_TraceMsg(idx, "\tpic_parameter_set_id = %d\n", p->pic_parameter_set_id);
@@ -1367,19 +1627,38 @@ static void va_TraceVAEncSliceParameterBufferH264(
     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 =");
-        for (i = 0; i < p->num_ref_idx_l0_active_minus1 + 1 && i < 32; 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);
+        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 =");
-            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);
-            }
+    }
+    
+    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);
@@ -1430,6 +1709,31 @@ static void va_TraceVAEncSliceParameterBufferH264(
     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,
@@ -1457,13 +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.reset);
-        va_TraceMsg(idx, "\trc_flags.disable_frame_skip = %d\n", p->rc_flags.disable_frame_skip);
-        va_TraceMsg(idx, "\trc_flags.disable_bit_stuffing = %d\n", p->rc_flags.disable_bit_stuffing);
+        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:
@@ -1494,7 +1799,8 @@ static void va_TraceVAEncMiscParameterBuffer(
         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);
@@ -1774,6 +2080,8 @@ static void va_TraceVAEncPictureParameterBufferJPEG(
     void *data)
 {
     VAEncPictureParameterBufferJPEG *p = (VAEncPictureParameterBufferJPEG *)data;
+    int i;
+    
     DPY2INDEX(dpy);
     
     va_TraceMsg(idx, "VAEncPictureParameterBufferJPEG\n");
@@ -1827,6 +2135,7 @@ static void va_TraceVAEncQMatrixBufferJPEG(
     return;
 }
 
+
 static void va_TraceH263Buf(
     VADisplay dpy,
     VAContextID context,
@@ -1880,7 +2189,11 @@ 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;
     }
 }
@@ -1897,11 +2210,8 @@ static void va_TraceJPEGBuf(
 )
 {
     switch (type) {
-    case VAPictureParameterBufferType:/* print MPEG4 buffer */
-    case VAIQMatrixBufferType:/* print MPEG4 buffer */
-    case VABitPlaneBufferType:/* print MPEG4 buffer */
+    case VABitPlaneBufferType:
     case VASliceGroupMapBufferType:
-    case VASliceParameterBufferType:/* print MPEG4 buffer */
     case VASliceDataBufferType:
     case VAMacroblockParameterBufferType:
     case VAResidualDataBufferType:
@@ -1910,9 +2220,23 @@ static void va_TraceJPEGBuf(
     case VAProtectedSliceDataBufferType:
     case VAEncCodedBufferType:
     case VAEncSequenceParameterBufferType:
-    case VAEncSliceParameterBufferType:
         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;
@@ -1920,6 +2244,7 @@ static void va_TraceJPEGBuf(
         va_TraceVAEncQMatrixBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     default:
+        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     }
 }
@@ -1978,6 +2303,7 @@ static void va_TraceMPEG4Buf(
         va_TraceVAEncSliceParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     default:
+        va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
     }
 }
@@ -2042,10 +2368,15 @@ static void va_TraceH264Buf(
         else
             va_TraceVAEncSliceParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf);
         break;
+    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;
     }
 }
@@ -2107,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;
     }
 }
@@ -2128,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++) {
-        unsigned char *pbuf;
+        unsigned char *pbuf = NULL;
         unsigned int j;
         
         /* get buffer type information */
@@ -2142,12 +2477,13 @@ void va_TraceRenderPicture(
         va_TraceMsg(idx, "\t  num_elements = %d\n", num_elements);
 
         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);
             }
@@ -2156,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);
             }
@@ -2166,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);
@@ -2176,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);
@@ -2184,7 +2517,6 @@ 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);
@@ -2192,7 +2524,6 @@ void va_TraceRenderPicture(
             break;
         case VAProfileJPEGBaseline:
             for (j=0; j<num_elements; j++) {
-                va_TraceMsg(idx, "\t---------------------------\n", j);
                 va_TraceMsg(idx, "\telement[%d] = ", j);
                 
                 va_TraceJPEGBuf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
@@ -2261,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,
@@ -2273,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);
 }
 
@@ -2290,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);
@@ -2325,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);
@@ -2350,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);